wok view linld/stuff/src/CRTL.ASM @ rev 22007

yarock: fix FindTaglib.cmake
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 19 10:25:12 2019 +0200 (2019-10-19)
parents fcb1de9af8f7
children 306a4bbdee7d
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT,_DATA,_BSS
16 assume cs:DGROUP,ds:DGROUP
18 segment _DATA byte public use16 'DATA'
20 global _heap_top
21 extrn _bss_end
22 _heap_top dw _bss_end
23 msg_hang db "High mem corrupted - not exiting to DOS",0
24 vcpi_alloc_err db "VCPI "
25 msg_malloc db "malloc error",0
26 ifdef EXTRA
27 tazboot_cmd db "tazboot.cmd",0
28 endif
30 ends _DATA
32 segment _BSS byte public use16 'BSS'
34 ifdef EXTRA
35 ;typedef unsigned dirsizetype;
36 struc isostate ; struct isostate {
37 curpos dw ? ; 0 unsigned curpos;
38 filename2open dw ? ; 2 char *filename2open;
39 fd dw ? ; 4 int fd;
40 filemod dw ? ; 6 unsigned short filemod;
41 fileofs dd ? ; 8 unsigned long fileofs;
42 filesize dd ? ;12 unsigned long filesize;
43 filename dw ? ;16 char *filename;
44 curdirsize dw ? ;18 dirsizetype curdirsize;
45 dirsize dw ? ;20 dirsizetype dirsize;
46 curdirofs dd ? ;22 unsigned long curdirofs;
47 dirofs dd ? ;26 unsigned long dirofs;
48 ;overlap
49 entrysize dw ? ;30 int entrysize;
50 tmp dw ? ;32 const char *tmp;
51 c db ? ;34 char c;
52 _64bits db ? ;35 char _64bits;
53 buffer db ? ;36 char buffer[2048+512];
54 ends isostate ; } isostate;
55 public _isostate
56 _isostate isostate <?>
57 org $-7
58 endif
59 _xfer_buf db 4096 dup (?)
60 global _no_exit:byte
61 _no_exit db ?
62 filecnt db ? ; in fact 0 minus file count...
63 nextfilename dw ?
64 ifdef LARGE_IMAGES
65 curdata dw ?
66 endif
67 ifdef EXTRA
68 ultoabuf db 12 dup (?)
69 endif
71 ends _BSS
73 segment _TEXT byte public use16 'CODE'
75 ;***************************************************************
76 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
77 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
78 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
79 ;***************************************************************
80 ifdef EXTRA
81 global @strcat$qpxzct1:near
82 @strcat$qpxzct1:
83 mov cx,1h
84 db 0bah ; mov dx,imm opcode
85 endif
86 global @strcatb$qpxzct1:near
87 proc @strcatb$qpxzct1 near
89 mov cl,7Fh
90 db 0bah ; mov dx,imm opcode
91 global @strcpy$qpxzct1:near
92 @strcpy$qpxzct1:
93 xor cx,cx
94 push si
95 xchg ax,si ; b
96 jcxz @@nocat
97 dec bx
98 @@catlp:
99 inc bx
100 cmp [byte bx],0 ; a=bx
101 jne @@catlp
102 ifdef EXTRA
103 mov al,20h
104 loop @@cpyhead
105 else
106 db 0b8h,20h ; mov ax,??20h
107 endif
108 @@nocat:
109 @@cpylp:
110 lodsb
111 @@cpyhead:
112 mov [bx],al
113 inc bx
114 or al,al
115 jne @@cpylp
116 strfound:
117 xchg ax,dx
118 strend:
119 pop si
120 ret
122 endp @strcatb$qpxzct1
125 ifdef EXTRA
126 p8086
127 ;***************************************************************
128 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
129 ;***************************************************************
130 global @strstr$qpxzct1:near
131 proc @strstr$qpxzct1 near
133 xchg ax,cx ; b
134 mov dx,bx ; a
135 push si
136 @@loop:
137 xor ax,ax
138 mov si,dx
139 cmp [si],al ; *a
140 jz strend ; return ax = NULL
141 mov bx,cx
142 @@match:
143 or ah,[bx] ; *b
144 jz strfound
145 inc bx
146 lodsb
147 sub ah,al
148 jz @@match
149 inc dx
150 jmp @@loop
152 endp @strstr$qpxzct1
155 ;***************************************************************
156 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
157 ;***************************************************************
158 global @strcmp$qpxzct1:near
159 proc @strcmp$qpxzct1 near
161 push si
162 xchg ax,si
163 dec bx
164 @@lp:
165 inc bx
166 lodsb
167 sub al,[bx]
168 jnz @@out
169 or al,[bx]
170 jnz @@lp
171 @@out:
172 cbw
173 pop si
174 ret
176 endp @strcmp$qpxzct1
177 endif
180 ;***************************************************************
181 ;_fastcall void puts(bx:const char* s):
182 ;***************************************************************
183 global @puts$qpxzc:near
185 ; global puts:near ; puts(bx)
186 @putsz:
187 call @putc
188 @puts$qpxzc:
189 puts:
190 mov dl,[bx]
191 inc bx
192 or dl,dl
193 jne @putsz
194 mov dl,10
195 @putc:
196 cmp dl,10
197 jne @putcz
198 call @putcz2
199 @putcz2:
200 xor dl,7 ; 10^13 1010^1101
201 @putcz:
202 mov ah,2
203 int 21h
204 ret
207 ;***************************************************************
208 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
209 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
210 ;***************************************************************
211 global openargs:near ; openargs(bx)
212 openargs:
213 cmp [byte bx],'@'
214 jne fail
215 inc bx
217 global @open$qpxzc:near
218 proc @open$qpxzc near
220 open: ; open(bx)
221 ifdef LONG_FILENAME
222 mov ax,716Ch
223 push bx si di
224 mov si,bx
225 xor bx,bx ; R/O
226 xor cx,cx ; attributes
227 xor di,di ; alias hint
228 cwd ; action = open
229 stc
230 int 21h
231 pop di si bx
232 jnc doret
233 endif
234 mov ax,3d00h ; read-only+compatibility
235 ;mov cl,0 ; attribute mask
236 mov dx,bx
237 jmp dos
239 endp @open$qpxzc
242 ;***************************************************************
243 ;_fastcall int fileexist(bx:const char* name);
244 ;***************************************************************
245 global @fileexist$qpxzc:near
246 @fileexist$qpxzc:
247 call @open$qpxzc
248 jc fail
250 ;***************************************************************
251 ;_fastcall int close(ax:int fd);
252 ;***************************************************************
253 global @close$qi:near
254 proc @close$qi near
256 global close:near ; close(ax)
257 close:
258 xchg ax,bx
259 mov ah,3Eh
260 or bx,bx
261 jnz dos
262 ret
264 endp @close$qi
267 ;***************************************************************
268 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
269 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
270 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
271 ;***************************************************************
272 global @readrm$qp11image_himemi:near
273 @readrm$qp11image_himemi:
274 xchg ax,dx ; sz
275 mov ax,[bx] ; fd
276 mov bx,[bx-2] ; data
277 global @read$qipvi:near
278 proc @read$qipvi near
280 ifdef WRITE
281 stc
282 db 0B0h ; mov al,im
283 global @write$qipvi:near
284 @write$qipvi:
285 clc
286 endif
287 @read$dxbxax:
288 xchg ax,bx ; fd
289 xchg ax,dx ; data
290 xchg ax,cx ; sz
291 ifdef WRITE
292 mov ah,40h
293 sbb ah,0
294 else
295 global @read$cxdxbx:near
296 @read$cxdxbx:
297 mov ah,3Fh
298 endif
299 jcxz fail
300 dos:
301 int 21h
302 chkc:
303 jnc doret
304 fail:
305 stc
306 failifc:
307 sbb ax,ax ; ax=-1 CF
308 cwd
309 doret:
310 ifndef NO386
311 push dx ; see next_chunk:lseek
312 push ax
313 pop eax
314 endif
315 ret
317 endp @read$qipvi
319 ;***************************************************************
320 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
321 ;***************************************************************
323 global @lseekcur$qii:near ; fd=ax whence=dx
324 proc @lseekcur$qii near
326 mov cl,1
327 xchg ax,bx
328 xchg ax,dx
329 cwd
330 xchg ax,dx
331 xchg ax,cx
332 jmp lseek
333 rewind: ; rewind(ax)
334 mov bl,0
335 lseek0: ; lseek0(ax,bl=dir)
336 xor dx,dx
337 xor cx,cx
338 lseekset:
339 xchg ax,bx
340 lseek:
341 mov ah,42h ; bx=fd cx:dx=offset al=whence
342 jmp dos
344 endp @lseekcur$qii
346 ifdef EXTRA
347 ;***************************************************************
348 ;_fastcall long isolseek(bx:const unsigned long *offset);
349 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
350 ;***************************************************************
351 global @isolseek$qpxul:near
352 proc @isolseek$qpxul near
354 isolseek:
355 mov ax,[_isostate.fd]
356 global @lseekset2$qipul:near
357 @lseekset2$qipul:
358 les dx,[dword bx]
359 mov cx,es
360 mov bl,0
361 jmp lseekset
363 endp @isolseek$qpxul
365 ;***************************************************************
366 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
367 ;***************************************************************
368 global @isoreadsector$qpxul:near
369 proc @isoreadsector$qpxul near
371 call isolseek
372 jc doret
373 mov dx,2560
374 mov bx,offset _isostate.buffer
375 mov ax,[_isostate.fd]
376 jmp @read$dxbxax ; read(fd,buffer,2560)
378 endp @isoreadsector$qpxul
381 ;***************************************************************
382 ;_fastcall int isoreset(bx:const char *name);
383 ;***************************************************************
384 global @isoreset$qpzc:near
385 proc @isoreset$qpzc near
387 or bx,bx
388 jz fail
389 call near ptr @open$qpxzc
390 mov [_isostate.fd],ax
391 extrn @isoroot$qv:near
392 jmp @isoroot$qv
394 endp @isoreset$qpzc
397 ;***************************************************************
398 ;_fastcall int isoopen(bx:const char *name);
399 ;***************************************************************
400 global @isoopen$qpxzc:near
401 proc @isoopen$qpxzc near
403 extrn @_isoopen$qv:near
404 mov [_isostate.filename2open],bx
405 jmp @_isoopen$qv
407 endp @isoopen$qpxzc
409 endif
412 ifdef USE_ARGSTR
413 ;***************************************************************
414 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
415 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
416 ;***************************************************************
417 global @argstr$qpxzcxt1ppxzc:near
418 proc @argstr$qpxzcxt1ppxzc near
420 mov cl,2
421 db 0a9h ; test ax,#
422 global @argnum$qpzcxpxzcpul:near
423 @argnum$qpzcxpxzcpul:
424 mov cl,4
425 xchg ax,bx ; keywords -> bx
426 xchg ax,cx ; s -> cx
427 cbw ; argstr:0002 argnum:0004
428 xchg ax,dx ; vars -> ax
429 push si di
430 xchg ax,di ; vars => di
431 dec bx
432 @@testalt:
433 mov al,-1
434 sub di,dx
435 @@test:
436 cmp al,'='
437 je @@found
438 cmp al,0 ; eos, si=next argv
439 je @@found
440 mov si,cx ; s
441 add di,dx
442 @@match:
443 inc bx ; keywords++
444 lodsb ; *s++
445 or al,20h
446 cmp al,[bx]
447 je @@match
448 cmp al,'/' ; 2f
449 jne @@notopt
450 cmp [byte bx],'-'
451 je @@match
452 @@notopt:
453 ifdef EXTRA
454 cmp [byte bx],'/'
455 je @@testalt
456 endif
457 cmp [byte bx],'|'
458 je @@test
459 inc bx
460 cmp [byte bx-1],0
461 jne @@notopt
462 stc
463 jmp @@nokeyword
464 @@found:
465 mov [di],si
466 dec dx
467 dec dx
468 je @@done
469 ;mov bx,si
470 call @strtol$qpxzc
471 mov [di],ax
472 mov [di+2],dx
473 @@done:
474 clc
475 @@nokeyword:
476 sbb ax,ax
477 pop di si
478 ret
480 endp @argstr$qpxzcxt1ppxzc
482 else
484 ;***************************************************************
485 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
486 ;***************************************************************
487 global @strhead$qpxzct1:near
488 proc @strhead$qpxzct1 near
490 @@loop:
491 xchg ax,bx
492 mov cl,[bx] ; cl = *b++
493 inc bx
494 or cl,cl ; clear C
495 jz failifc ; return 0
496 xchg ax,bx
497 xor cl,[bx] ; cl -= *a++
498 inc bx
499 and cl,0dfh ; case insensitive
500 jne fail ; return -1
501 jmp @@loop
503 endp @strhead$qpxzct1
505 endif
507 ;***************************************************************
508 ;_fastcall char* strdup(bx:const char* a);
509 ;_fastcall char* malloc_or_die(ax:unsigned size);
510 ;***************************************************************
511 global @strdup$qpxzc:near
512 @strdup$qpxzc:
513 strdup: ; ax = strdup(bx)
514 mov ax,[_heap_top]
515 xchg ax,bx
516 call @strcpy$qpxzct1 ; bx = strcpy(bx, ax) end +1
517 xchg ax,bx
518 xchg_heap_top:
519 xchg ax,[_heap_top]
520 ret
522 global @malloc_or_die$qui:near
523 proc @malloc_or_die$qui near
525 global malloc_or_die:near ; ax = malloc_or_die(ax)
526 malloc_or_die:
527 mov bx,offset msg_malloc
528 add ax,[_heap_top]
529 jnc xchg_heap_top
531 endp @malloc_or_die$qui
534 ;***************************************************************
535 ;_fastcall int die(bx:const char* msg);
536 ;int exit();
537 ;int abort();
538 ;***************************************************************
539 global @die$qpxzc:near
540 proc @die$qpxzc near
541 @die$qpxzc:
542 global die:near ; die(bx)
543 die:
544 call puts
545 global @exit$qv:near
546 @exit$qv:
547 _exit:
548 mov al,[_no_exit]
549 or al,al
550 jne @@hang
551 mov ah,4Ch
552 int 21h
553 @@hang:
554 mov bx, offset msg_hang
555 call puts
556 ; global _abort:near
557 _abort:
558 cli
559 hlt
560 jmp _abort
562 endp @die$qpxzc
564 include "himem.inc"
566 ;***************************************************************
567 ;static long next_chunk(struct image_himem *di);
568 ;***************************************************************
569 proc next_chunk near
571 push si
572 mov ax,[(image_himem di).fd]
573 call close
574 ifndef NO386
575 xor eax,eax
576 else
577 xor ax,ax
578 cwd
579 endif
580 mov [(image_himem di).fd],ax
581 mov bx,[(image_himem di).state]
582 cmp al,[bx] ; ""
583 jz @@end
584 mov si,bx
585 @@scan:
586 lodsb
587 mov cx,si
588 cmp al,','
589 jz @@eos
590 or al,al
591 jnz @@scan
592 dec cx
593 @@eos:
594 mov [(image_himem di).state],cx
595 dec si
596 push [word si]
597 mov [byte si],ah ; set temp eos
598 call open
599 pop [word si] ; restore string
600 jc @@die
601 mov [(image_himem di).fd],ax
602 mov [(image_himem di).fd2close],ax
603 mov bl,02h ; SEEK_END
604 call lseek0
605 @@die:
606 mov bx,[(image_himem di).errmsg]
607 jc die
608 ifndef NO386
609 push eax
610 mov ax,[(image_himem di).fd]
611 call rewind
612 pop eax
613 @@end:
614 mov [(image_himem di).chunk_size],eax
615 else
616 push ax
617 push dx
618 mov ax,[(image_himem di).fd]
619 call rewind
620 pop dx
621 pop ax
622 @@end:
623 mov [word (image_himem di).chunk_size],ax
624 mov [word ((image_himem di).chunk_size)+2],dx
625 endif
626 pop si
627 ret
629 endp next_chunk
632 ifdef LARGE_IMAGES
633 struc data_himem ;struct data_himem {
634 first dd ? ; 0 u32 first;
635 cacheidx dw ? ; 4 int cacheidx;
636 pageidx dw ? ; 6 int pageidx;
637 cache dd 1024 dup(?) ; 8 int cache;
638 page dd 1024 dup(?) ;4104 int page;
639 ends data_himem ;}; // size=8200
640 endif
642 ;***************************************************************
643 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
644 ;***************************************************************
645 global @malloc_bufv_or_die$qp11image_himem:near
646 proc @malloc_bufv_or_die$qp11image_himem near
648 p386
649 push si
650 mov si,bx
651 ifdef LARGE_IMAGES
652 movzx eax,[word ((image_himem si).size) + 2]
653 shr ax,4 ; pages index size = size >> 20
654 add ax,8+4096+8
655 call malloc_or_die
656 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
657 add ecx,[(image_himem si).size]
658 shr ecx,12
659 mov [curdata],ax
660 else
661 mov eax,[(image_himem si).size]
662 dec eax
663 shr eax,12
664 inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
665 push ax
666 inc ax ; cnt+1
667 shl ax,2 ; bufv => vcpi => vm86
668 ; our malloc zeroes allocated mem: bufv[cnt]=0;
669 ; Allocate pages, storing addrs in addrbuf
670 call malloc_or_die
671 pop cx
672 push ax
673 endif
674 mov [(image_himem si).bufv],ax
675 xchg ax,si
676 @@vcpi_alloc:
677 xor edx,edx
678 mov ax,0DE04h
679 int 67h
680 or ah,ah
681 mov bx,offset vcpi_alloc_err
682 jnz die
683 ; for (i = cnt-1; i >= 0; i--)
684 ifdef LARGE_IMAGES
685 mov eax,ecx
686 dec eax
687 else
688 mov ax,cx
689 dec ax
690 cwde
691 endif
692 shl eax,12 ; i*_4k
693 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
694 extrn _imgs
695 mov bx,offset _imgs+2
696 push eax
697 add eax,[bx-2+2]
698 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
699 pop eax ; i*_4k
700 jbe @@pmok
701 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
702 jae @@vcpi_alloc
703 @@pmok:
704 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
705 extrn _imgs
706 mov bx,offset _imgs+32+2
707 add eax,[bx-2+2] ; +initrd.fallback
708 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
709 ja @@initrdok
710 mov eax,[bx-2+6] ; initrd.size
711 add eax,[bx-2+2] ; +initrd.fallback
712 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
713 @@jnc_vcpi_alloc:
714 ja @@vcpi_alloc
715 @@initrdok:
716 ifdef LARGE_IMAGES
717 cmp [(data_himem si).first],0
718 jne @@notfirst
719 mov [(data_himem si).first],edx
720 @@notfirst:
721 mov bx,[(data_himem si).cacheidx]
722 cmp bh,4
723 jae @@nextpage
724 shl bx,2
725 inc [(data_himem si).cacheidx]
726 mov [(data_himem bx+si).cache],edx
727 loopd @@vcpi_alloc
728 mov [(data_himem bx+si).cache],ecx ; last is 0
729 @@nextpage:
730 and [(data_himem si).cacheidx],0
731 mov bx,[(data_himem si).pageidx]
732 mov [(data_himem bx+si).page],edx
733 add [(data_himem si).pageidx],4
734 push cx
735 lea cx,[(data_himem si).cache]
736 ifdef NO386
737 push edx
738 pop dx
739 pop ax
740 endif
741 call storepage ; storepage(edx,cx)
742 pop cx
743 or ecx,ecx ; clear C
744 jnz @@jnc_vcpi_alloc
745 mov [dword (data_himem si).cacheidx],ecx
746 xchg ax,si
747 else
748 mov [si],edx
749 lodsd ; si=+4
750 loop @@vcpi_alloc
751 pop ax
752 endif
753 pop si
754 ret
755 ifdef NO386
756 p8086
757 endif
759 endp @malloc_bufv_or_die$qp11image_himem
762 ;***************************************************************
763 ;_fastcall void memcpy_image(bx:struct image_himem *m);
764 ;***************************************************************
765 global @memcpy_image$qp11image_himem:near
766 proc @memcpy_image$qp11image_himem near
768 ifndef NO386
769 mov edx,[(image_himem bx).fallback]
770 mov eax,[(image_himem bx).buf]
771 cmp eax,edx ; if (m->fallback != m->buf)
772 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
773 ifdef LARGE_IMAGES
774 mov ecx,[(image_himem bx).size]
775 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
776 push ecx
777 else
778 push [(image_himem bx).size]
779 endif
780 push eax
781 push 0
782 call_memcpy32:
783 push edx
784 else
785 les ax,[dword ((image_himem bx).fallback)]
786 mov dx,es
787 mov cx,[word ((image_himem bx).buf)]
788 cmp ax,cx ; if (m->fallback != m->buf)
789 jnz @@do
790 cmp dx,[word ((image_himem bx).buf)+2]
791 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
792 @@do:
793 push [word ((image_himem bx).size)+2]
794 push [word ((image_himem bx).size)]
795 push [word ((image_himem bx).buf)+2]
796 push cx
797 xor cx,cx
798 push cx
799 call_memcpy32:
800 push dx
801 push ax
802 ifdef LARGE_IMAGES
803 jmp @@memcpy
804 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
805 p386
806 push ecx
807 push eax
808 push 0
809 push edx
810 ifdef NO386
811 p8086
812 endif
813 endif
814 endif
815 @@memcpy:
816 extrn memcpy32:near
817 call near memcpy32
818 @@skip:
819 ret
821 endp @memcpy_image$qp11image_himem
823 ;***************************************************************
824 ;_fastcall void storepage(bx:u32 *dst);
825 ;***************************************************************
826 global @storepage$qpul:near
827 proc @storepage$qpul near
829 ifndef NO386
830 mov edx,[bx]
831 else
832 les ax,[dword bx]
833 mov dx,es
834 endif
835 mov cx,offset _xfer_buf
836 storepage: ; storepage(edx,cx)
837 ifndef NO386
838 push 0
839 push 4096
840 push 0
841 else
842 xor bx,bx
843 push bx
844 mov bh,4096/256
845 push bx
846 xor bx,bx
847 push bx
848 endif
849 push cx
850 push ds
851 jmp call_memcpy32
853 endp @storepage$qpul
856 ifdef LARGE_IMAGES
857 p386
858 ;***************************************************************
859 ;_fastcall void reset_bufv(bx:u32 *p);
860 ;***************************************************************
861 global @reset_bufv$qpul:near
862 proc @reset_bufv$qpul near
864 mov [curdata],bx
865 and [dword (data_himem bx).cacheidx],0
866 ret
868 endp @reset_bufv$qpul
870 ;***************************************************************
871 ;u32* prev_bufv();
872 ;u32* prev_bufv();
873 ;***************************************************************
874 global _prev_bufv:near
875 global _next_bufv:near
876 proc _prev_bufv near
878 stc
879 db 73h ; jnc
880 _next_bufv:
881 clc
882 push si
883 mov si,[curdata]
884 sbb ax,ax
885 cmc
886 adc ax,[(data_himem si).cacheidx] ; -1/+1
887 xor ecx,ecx
888 test ax,0fc00h
889 jz @@gotpage
890 push ax ; FFFF / 0400
891 sar ax,8 ; FFFC / 0004
892 and al,0fch
893 add [(data_himem si).pageidx],ax
894 mov bx,[(data_himem si).pageidx]
895 lea bx,[(data_himem bx+si).page]
896 mov edx,ds
897 shl edx,4
898 lea cx,[(data_himem si).cache]
899 add edx,ecx
900 mov eax,[bx]
901 or eax,eax
902 jnz @@pageok
903 pop ax
904 xchg ax,bx
905 pop si
906 ret
907 @@pageok:
908 mov cx,4096
909 call memcpy_imagez ; get page
910 pop ax ; FFFF / 0400
911 cbw
912 shr ax,6 ; 03FF / 0000
913 @@gotpage:
914 mov [(data_himem si).cacheidx],ax
915 shl ax,2
916 xchg ax,bx
917 lea ax,[(data_himem bx+si).cache]
918 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
919 jnz @@notfirst2
920 xchg ax,si ; &first
921 @@notfirst2:
922 pop si
923 ret
925 endp _prev_bufv
926 endif
928 ifdef NO386
929 p8086
930 endif
932 ;***************************************************************
933 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
934 ;***************************************************************
936 global @open_image$qp11image_himempxzc:near
937 proc @open_image$qp11image_himempxzc near
939 push di
940 xchg ax,bx
941 xchg ax,di
942 ifdef EXTRA
943 cmp [(image_himem di).fd],0 ; iso image/kernel ?
944 jnz @@alreadydone
945 endif
946 mov [(image_himem di).state],bx
947 push bx
948 ifdef EXTRA
949 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
950 jnz @@next
951 mov [(image_himem di).next_chunk],offset next_chunk
952 @@next:
953 ;push di
954 call [(image_himem di).next_chunk] ; m->next_chunk()
955 ;pop di
956 else
957 @@next:
958 call next_chunk
959 endif
960 ifndef NO386
961 add eax,3
962 and al,0FCh
963 add [(image_himem di).size],eax ; m->size += m->chunk_size
964 or eax,eax
965 else
966 add ax,3
967 adc dx,0
968 and al,0FCh
969 add [word (image_himem di).size],ax ; m->size += m->chunk_size
970 adc [word ((image_himem di).size)+2],dx
971 or ax,dx
972 endif
973 jnz @@next
974 pop [(image_himem di).state]
975 ifdef EXTRA
976 ;push di
977 call [(image_himem di).next_chunk] ; m->next_chunk()
978 ;pop di
979 else
980 call next_chunk
981 endif
982 @@alreadydone:
983 pop di
984 ret
986 endp @open_image$qp11image_himempxzc
989 ;***************************************************************
990 ;_fastcall int read_image(bx:struct image_himem *m);
991 ;***************************************************************
992 global @read_image$qp11image_himem:near
993 proc @read_image$qp11image_himem near
995 push si di
996 mov di,bx
997 mov si,4096
998 push si ; original size
999 @@loop:
1000 ifndef NO386
1001 movzx ecx,si
1002 mov eax,[(image_himem di).chunk_size]
1003 cmp ecx,eax
1004 jb @@szok
1005 else
1006 mov cx,si
1007 mov ax,[word (image_himem di).chunk_size]
1008 cmp cx,ax
1009 jb @@szok
1010 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1011 jne @@szok
1012 endif
1013 xchg ax,cx
1014 @@szok:
1015 jcxz image_done
1016 mov dx,offset _xfer_buf+4096
1017 sub dx,si
1018 mov bx,[di]
1019 call @read$cxdxbx
1020 jbe image_done
1021 xor cx,cx
1022 cwd ; ax < 8000h
1023 ifndef NO386
1024 cwde ; ax < 8000h
1025 sub [(image_himem di).chunk_size],eax
1026 xchg eax,ebx
1027 else
1028 sub [word (image_himem di).chunk_size],ax
1029 xchg ax,bx
1030 sbb [word ((image_himem di).chunk_size)+2],dx
1031 jnz @@fill
1032 cmp [word (image_himem di).chunk_size],dx
1033 endif
1034 jnz @@fill
1035 dec cx
1036 @@fill:
1037 test bl,3
1038 je @@filled
1039 mov [bx+_xfer_buf],dh
1040 inc bx
1041 jmp @@fill
1042 @@filled:
1043 ifndef NO386
1044 sub [(image_himem di).remaining],ebx
1045 else
1046 sub [word (image_himem di).remaining],bx
1047 sbb [word ((image_himem di).remaining)+2],dx
1048 endif
1049 sub si,bx
1050 pushf
1051 ifdef EXTRA
1052 and cx,[(image_himem di).next_chunk]
1053 jcxz @@same_chunk
1054 push di
1055 call cx
1056 pop cx
1057 else
1058 jcxz @@same_chunk
1059 call next_chunk
1060 endif
1061 @@same_chunk:
1062 popf
1063 jnz @@loop
1064 image_done:
1065 pop ax ; original size
1066 sub ax,si
1067 pop di si
1068 ret
1070 endp @read_image$qp11image_himem
1073 ;***************************************************************
1074 ;_fastcall unsigned long strtol(const char *s);
1075 ;***************************************************************
1076 ifndef USE_ARGSTR
1077 global @strtol$qpxzc:near
1078 endif
1079 proc @strtol$qpxzc near
1081 ifndef NO386
1082 ifndef USE_ARGSTR
1083 push si
1084 mov si,bx
1085 endif
1086 xor ecx,ecx
1087 xor eax,eax
1088 xor ebx,ebx
1089 or si,si
1090 jz @@end
1091 lodsb
1092 or al,20h
1093 cmp al,'a'
1094 jb @@notvga
1095 sub al,'n'
1096 @@vgaloop:
1097 dec cx
1098 add al,6
1099 jb @@vgaloop ; vga=normal,extended,ask
1100 @@vga:
1101 dec cx
1102 xchg ax,cx
1103 cwd
1104 jmp @@popsiret
1105 @@notvga:
1106 mov cx,10 ; radix
1107 cmp al,'-'
1108 ja @@radixkeep
1109 cmc ; '+'=2B:C=0 '-'=2D:C=1
1110 lodsb
1111 @@radixkeep:
1112 pushf
1113 cmp al,'0'
1114 jne @@radixok
1115 mov cl,8
1116 lodsb
1117 or al,20h
1118 cmp al,'x'
1119 jne @@radixok
1120 mov cl,16
1121 @@strtollp:
1122 lodsb
1123 @@radixok:
1124 or al,20h
1125 sub al,'0'
1126 jb @@endstrtol
1127 cmp al,9
1128 jbe @@digitok
1129 cmp al,'a'-'0'
1130 jb @@endstrtol
1131 sub al,'a'-'0'-10
1132 @@digitok:
1133 cmp al,cl
1134 jae @@endstrtol
1135 xchg eax,ebx
1136 mul ecx
1137 add eax,ebx
1138 xchg eax,ebx
1139 jmp @@strtollp
1140 @@endstrtol:
1141 mov cl,10
1142 cmp al,'k'-'a'+10
1143 je @@shift
1144 mov cl,20
1145 cmp al,'m'-'a'+10
1146 je @@shift
1147 mov cl,30
1148 cmp al,'g'-'a'+10
1149 jne @@noshift
1150 @@shift:
1151 shl ebx,cl
1152 @@noshift:
1153 popf
1154 jnc @@end
1155 neg ebx
1156 @@end:
1157 push ebx
1158 pop ax
1159 pop dx
1160 @@popsiret:
1161 ifndef USE_ARGSTR
1162 pop si
1163 endif
1164 else
1165 ifndef USE_ARGSTR
1166 push si di
1167 xor ax,ax
1168 cwd
1169 or bx,bx
1170 else
1171 push di
1172 xor ax,ax
1173 cwd
1174 or si,si
1175 endif
1176 jz @@goend
1177 xchg ax,di
1178 ifndef USE_ARGSTR
1179 mov si,bx
1180 endif
1181 lodsb
1182 or al,20h
1183 cmp al,'a'
1184 jb @@notvga
1185 xor cx,cx
1186 sub al,'n'
1187 @@vgaloop:
1188 dec cx
1189 add al,6
1190 jb @@vgaloop ; vga=normal,extended,ask
1191 @@vga:
1192 xchg ax,cx
1193 @@goend:
1194 jmp @@popdisiret
1195 @@notvga:
1196 mov cx,10 ; radix
1197 cmp al,'-'
1198 ja @@radixkeep
1199 cmc ; '+'=2B:C=0 '-'=2D:C=1
1200 lodsb
1201 @@radixkeep:
1202 pushf
1203 cmp al,'0'
1204 jne @@radixok
1205 mov cl,8
1206 lodsb
1207 or al,20h
1208 cmp al,'x'
1209 jne @@radixok
1210 mov cl,16
1211 @@strtollp:
1212 lodsb
1213 @@radixok:
1214 or al,20h
1215 sub al,'0'
1216 jb @@endstrtol
1217 cmp al,9
1218 jbe @@digitok
1219 cmp al,'a'-'0'
1220 jb @@endstrtol
1221 sub al,'a'-'0'-10
1222 @@digitok:
1223 cmp al,cl
1224 jae @@endstrtol
1226 push ax
1227 push dx
1228 xchg ax,bx
1229 mul cx
1230 xchg ax,bx
1231 xchg ax,dx
1232 xchg ax,di
1233 pop ax
1234 mul cx
1235 add ax,di
1236 xchg ax,dx
1237 pop ax
1238 mov ah,0
1239 add bx,ax
1240 adc dx,0
1242 jmp @@strtollp
1243 @@endstrtol:
1244 mov cl,10
1245 cmp al,'k'-'a'+10
1246 je @@shift
1247 mov cl,20
1248 cmp al,'m'-'a'+10
1249 je @@shift
1250 mov cl,30
1251 cmp al,'g'-'a'+10
1252 jne @@noshift
1253 @@shift:
1254 rcl di,1
1255 shl dx,1
1256 loop @@shift
1257 @@noshift:
1258 popf
1259 jnc @@end
1260 not dx
1261 neg bx
1262 jne @@end
1263 inc dx
1264 @@end:
1265 xchg ax,bx
1266 @@popdisiret:
1267 ifndef USE_ARGSTR
1268 pop di si
1269 else
1270 pop di
1271 endif
1272 endif
1273 strtol_ret:
1274 ret
1276 endp @strtol$qpxzc
1279 ifdef USE_ARGSTR
1280 ;***************************************************************
1281 ;_fastcall void set_cmdline(bx:const char *filename);
1282 ;***************************************************************
1283 global @set_cmdline$qpxzc:near
1284 proc @set_cmdline$qpxzc near
1285 call openargs
1286 jc strtol_ret
1287 mov cx,4096
1288 mov di,[_heap_top]
1289 extrn read_cmdline:near
1290 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1292 endp @set_cmdline$qpxzc
1293 endif
1296 ifdef NO386
1297 ;***************************************************************
1298 ;u16 topseg();
1299 ;***************************************************************
1300 global _topseg:near
1301 proc _topseg near
1303 int 12h
1304 jnc @@max640k
1305 mov ax,640 ; 9000
1306 @@max640k:
1307 dec ax
1308 and al,0C0h
1309 mov cl,6
1310 shl ax,cl
1311 ret
1313 endp _topseg
1314 endif
1316 ifdef EXTRA
1317 p8086
1318 ;***************************************************************
1319 ;_fastcall char *ultoa(axdx:unsigned long n);
1320 ;***************************************************************
1321 global @ultoa$qul:near
1322 proc @ultoa$qul near
1324 xchg ax,cx
1325 xchg ax,dx ; AX:CX = n
1326 push si
1327 mov si,10
1328 mov bx,offset ultoabuf+11
1329 @@loop:
1330 dec bx
1331 xor dx,dx
1332 div si ; DX:AX = 0000:hi(n)
1333 xchg ax,cx ; CX = hi(n)/10
1334 div si ; DX:AX = hi(n)%10:lo(n)
1335 xchg ax,cx ; CX = lo(n/10)
1336 ; AX = hi(n)/10 = hi(n/10)
1337 mov [byte bx],'0'
1338 add [bx],dl ; DL = n%10
1339 mov dx,ax
1340 or dx,cx
1341 jnz @@loop
1342 xchg ax,bx
1343 pop si
1344 ret
1346 endp @ultoa$qul
1349 ;***************************************************************
1350 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1351 ;***************************************************************
1352 global @kver2ul$qpzc:near
1353 proc @kver2ul$qpzc near
1355 push si
1356 mov si,bx
1357 xor bx,bx
1358 mov cx,304h
1359 @@number:
1360 xor ax,ax
1361 cwd
1362 @@digit:
1363 shl al,cl
1364 shl ax,cl
1365 lodsb
1366 sub al,30h
1367 cmp al,9
1368 jbe @@digit
1369 mov dl,bh
1370 mov bh,bl
1371 mov bl,ah
1372 dec ch
1373 jnz @@number
1374 xchg ax,bx
1375 pop si
1376 kver2ulret:
1377 ret
1379 endp @kver2ul$qpzc
1381 endif
1383 ;***************************************************************
1384 ;void try_default_args();
1385 ;***************************************************************
1386 ifdef EXTRA
1388 global _try_default_args:near
1389 proc _try_default_args near
1391 mov bx,offset tazboot_cmd
1392 call open
1393 jc kver2ulret
1394 mov cx,4096
1395 mov di,[_heap_top]
1396 extrn read_cmdline:near
1397 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1399 endp _try_default_args
1401 endif
1403 ends _TEXT
1405 end
1407 ;###### END OF FILE ############################################