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

Up firefox-official (67.0.3), tinyproxy (1.10.0)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jun 19 17:26:14 2019 +0200 (2019-06-19)
parents f9e283da869a
children 2373992ff751
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
19 global _heap_top
20 extrn _bss_end
21 _heap_top dw _bss_end
22 msg_hang db "High mem corrupted - not exiting to DOS"
23 msg_lf db 10,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;
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 ifdef EXTRA
90 mov cl,7Fh
91 db 0bah ; mov dx,imm opcode
92 global @strcpy$qpxzct1:near
93 @strcpy$qpxzct1:
94 xor cx,cx
95 endif
96 push si
97 xchg ax,si ; b
98 ifdef EXTRA
99 jcxz @@nocat
100 endif
101 dec bx
102 @@catlp:
103 inc bx
104 cmp [byte bx],0 ; a=bx
105 jne @@catlp
106 ifdef EXTRA
107 mov al,20h
108 loop @@cpyhead
109 else
110 db 0b8h,20h ; mov ax,??20h
111 endif
112 @@nocat:
113 @@cpylp:
114 lodsb
115 @@cpyhead:
116 mov [bx],al
117 inc bx
118 or al,al
119 jne @@cpylp
120 strfound:
121 xchg ax,dx
122 strend:
123 pop si
124 ret
126 endp @strcatb$qpxzct1
129 ifdef EXTRA
130 p8086
131 ;***************************************************************
132 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
133 ;***************************************************************
134 global @strstr$qpxzct1:near
135 proc @strstr$qpxzct1 near
137 xchg ax,cx ; b
138 mov dx,bx ; a
139 push si
140 @@loop:
141 xor ax,ax
142 mov si,dx
143 cmp [si],al ; *a
144 jz strend ; return ax = NULL
145 mov bx,cx
146 @@match:
147 or ah,[bx] ; *b
148 jz strfound
149 inc bx
150 lodsb
151 sub ah,al
152 jz @@match
153 inc dx
154 jmp @@loop
156 endp @strstr$qpxzct1
159 ;***************************************************************
160 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
161 ;***************************************************************
162 global @strcmp$qpxzct1:near
163 proc @strcmp$qpxzct1 near
165 push si
166 xchg ax,si
167 dec bx
168 @@lp:
169 inc bx
170 lodsb
171 sub al,[bx]
172 jnz @@out
173 or al,[bx]
174 jnz @@lp
175 @@out:
176 cbw
177 pop si
178 ret
180 endp @strcmp$qpxzct1
181 endif
184 ;***************************************************************
185 ;_fastcall void puts(bx:const char* s):
186 ;***************************************************************
187 global @puts$qpxzc:near
188 proc @puts$qpxzc near
190 ; global puts:near ; puts(bx)
191 puts:
192 call @@putsz
193 mov bx,offset msg_lf
194 mov dl,13
195 @@putcz:
196 mov ah,2
197 int 21h
198 @@putsz:
199 mov dl,[bx]
200 inc bx
201 or dl,dl
202 jne @@putcz ; ZF=1 (for malloc failure)
203 ret
205 endp @puts$qpxzc
209 ;***************************************************************
210 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
211 ;***************************************************************
212 global openargs:near ; openargs(bx)
213 openargs:
214 cmp [byte bx],'@'
215 jne fail
216 inc bx
218 global @open$qpxzc:near
219 proc @open$qpxzc near
221 global open:near ; open(bx)
222 open:
223 ifdef LONG_FILENAME
224 mov ax,716Ch
225 push bx di si
226 mov si,bx
227 xor bx,bx ; R/O
228 xor cx,cx ; attributes
229 xor di,di ; alias hint
230 cwd ; action = open
231 stc
232 int 21h
233 pop si di bx
234 jnc doret
235 endif
236 mov ax,3d00h ; read-only+compatibility
237 ;mov cl,0 ; attribute mask
238 mov dx,bx
239 jmp dos
241 endp @open$qpxzc
244 ;***************************************************************
245 ;_fastcall int fileexist(bx:const char* name);
246 ;***************************************************************
247 global @fileexist$qpxzc:near
248 @fileexist$qpxzc:
249 call @open$qpxzc
250 jc fail
252 ;***************************************************************
253 ;_fastcall int close(ax:int fd);
254 ;***************************************************************
255 global @close$qi:near
256 proc @close$qi near
258 global close:near ; close(ax)
259 close:
260 xchg ax,bx
261 mov ah,3Eh
262 or bx,bx
263 jnz dos
264 ret
266 endp @close$qi
269 ;***************************************************************
270 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
271 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
272 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
273 ;***************************************************************
274 global @readrm$qp11image_himemi:near
275 @readrm$qp11image_himemi:
276 xchg ax,dx ; sz
277 mov ax,[bx] ; fd
278 mov bx,[bx-2] ; data
279 global @read$qipvi:near
280 proc @read$qipvi near
282 ifdef WRITE
283 stc
284 db 0B0h ; mov al,im
285 global @write$qipvi:near
286 @write$qipvi:
287 clc
288 endif
289 @read$dxbxax:
290 xchg ax,bx ; fd
291 xchg ax,dx ; data
292 xchg ax,cx ; sz
293 ifdef WRITE
294 mov ah,40h
295 sbb ah,0
296 else
297 global @read$cxdxbx:near
298 @read$cxdxbx:
299 mov ah,3Fh
300 endif
301 jcxz fail
302 dos:
303 int 21h
304 chkc:
305 jnc doret
306 fail:
307 stc
308 failifc:
309 sbb ax,ax ; ax=-1 CF
310 cwd
311 doret:
312 ifndef NO386
313 push dx ; see next_chunk:lseek
314 push ax
315 pop eax
316 endif
317 ret
319 endp @read$qipvi
321 ;***************************************************************
322 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
323 ;***************************************************************
325 global @lseekcur$qii:near ; fd=ax whence=dx
326 proc @lseekcur$qii near
328 mov cl,1
329 xchg ax,bx
330 xchg ax,dx
331 cwd
332 xchg ax,dx
333 xchg ax,cx
334 jmp lseek
335 rewind: ; rewind(ax)
336 mov bl,0
337 lseek0: ; lseek0(ax,bl=dir)
338 xor dx,dx
339 xor cx,cx
340 lseekset:
341 xchg ax,bx
342 lseek:
343 mov ah,42h ; bx=fd cx:dx=offset al=whence
344 jmp dos
346 endp @lseekcur$qii
348 ifdef EXTRA
349 ;***************************************************************
350 ;_fastcall long isolseek(bx:const unsigned long *offset);
351 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
352 ;***************************************************************
353 global @isolseek$qpxul:near
354 proc @isolseek$qpxul near
356 isolseek:
357 mov ax,[_isostate.fd]
358 global @lseekset2$qipul:near
359 @lseekset2$qipul:
360 mov dx,[bx]
361 mov cx,[bx+2]
362 mov bl,0
363 jmp lseekset
365 endp @isolseek$qpxul
367 ;***************************************************************
368 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
369 ;***************************************************************
370 global @isoreadsector$qpxul:near
371 proc @isoreadsector$qpxul near
373 call isolseek
374 jc doret
375 mov dx,2560
376 mov bx,offset _isostate.buffer
377 mov ax,[_isostate.fd]
378 jmp @read$dxbxax ; read(fd,buffer,2560)
380 endp @isoreadsector$qpxul
383 ;***************************************************************
384 ;_fastcall int isoreset(bx:const char *name);
385 ;***************************************************************
386 global @isoreset$qpzc:near
387 proc @isoreset$qpzc near
389 or bx,bx
390 jz fail
391 call near ptr @open$qpxzc
392 mov [_isostate.fd],ax
393 extrn @isoroot$qv:near
394 jmp @isoroot$qv
396 endp @isoreset$qpzc
399 ;***************************************************************
400 ;_fastcall int isoopen(bx:const char *name);
401 ;***************************************************************
402 global @isoopen$qpxzc:near
403 proc @isoopen$qpxzc near
405 extrn @_isoopen$qv:near
406 mov [_isostate.filename2open],bx
407 jmp @_isoopen$qv
409 endp @isoopen$qpxzc
411 endif
414 ifdef USE_ARGSTR
415 ;***************************************************************
416 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
417 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
418 ;***************************************************************
419 global @argstr$qpxzcxt1ppxzc:near
420 proc @argstr$qpxzcxt1ppxzc near
422 mov cl,2
423 db 0a9h ; test ax,#
424 global @argnum$qpzcxpxzcpul:near
425 @argnum$qpzcxpxzcpul:
426 mov cl,4
427 xchg ax,bx ; keywords -> bx
428 xchg ax,cx ; s -> cx
429 cbw ; argstr:0002 argnum:0004
430 xchg ax,dx ; vars -> ax
431 push si di
432 xchg ax,di ; vars => di
433 dec bx
434 @@testalt:
435 mov al,-1
436 sub di,dx
437 @@test:
438 cmp al,'='
439 je @@found
440 cmp al,0 ; eos, si=next argv
441 je @@found
442 mov si,cx ; s
443 add di,dx
444 @@match:
445 inc bx ; keywords++
446 lodsb ; *s++
447 or al,20h
448 cmp al,[bx]
449 je @@match
450 cmp al,'/' ; 2f
451 jne @@notopt
452 cmp [byte bx],'-'
453 je @@match
454 @@notopt:
455 ifdef EXTRA
456 cmp [byte bx],'/'
457 je @@testalt
458 endif
459 cmp [byte bx],'|'
460 je @@test
461 mov al,0
462 inc bx
463 cmp [bx-1],al
464 jne @@notopt
465 stc
466 jmp @@nokeyword
467 @@found:
468 mov [di],si
469 dec dx
470 dec dx
471 je @@done
472 mov bx,si
473 call @strtol$qpxzc
474 mov [di],ax
475 mov [di+2],dx
476 @@done:
477 clc
478 @@nokeyword:
479 sbb ax,ax
480 pop di si
481 ret
483 endp @argstr$qpxzcxt1ppxzc
485 else
487 ;***************************************************************
488 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
489 ;***************************************************************
490 global @strhead$qpxzct1:near
491 proc @strhead$qpxzct1 near
493 @@loop:
494 xchg ax,bx
495 mov cl,[bx] ; cl = *b++
496 inc bx
497 or cl,cl ; clear C
498 jz failifc ; return 0
499 xchg ax,bx
500 xor cl,[bx] ; cl -= *a++
501 inc bx
502 and cl,0dfh ; case insensitive
503 jne fail ; return -1
504 jmp @@loop
506 endp @strhead$qpxzct1
508 endif
510 ;***************************************************************
511 ;_fastcall char* malloc_or_die(ax:unsigned size);
512 ;***************************************************************
513 global @malloc_or_die$qui:near
514 proc @malloc_or_die$qui near
516 xchg ax,cx ; size
517 global malloc_or_die:near ; malloc_or_die(cx)
518 malloc_or_die:
519 mov ax,[_heap_top] ; return value
520 mov bx,sp
521 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
522 sub bx,ax ; can't overflow
523 cmp bx,cx
524 mov bx,offset msg_malloc
525 jb die
526 add [_heap_top],cx ; _BEG has zero'd heap
527 ret
529 endp @malloc_or_die$qui
532 ;***************************************************************
533 ;_fastcall int die(bx:const char* msg);
534 ;int exit();
535 ;int abort();
536 ;***************************************************************
537 global @die$qpxzc:near
538 proc @die$qpxzc near
539 @die$qpxzc:
540 global die:near ; die(bx)
541 die:
542 call puts
543 ; global _exit:near
544 _exit:
545 mov al,[_no_exit]
546 or al,al
547 jne @@hang
548 extrn exit:near
549 inc ax
550 jmp near exit
551 @@hang:
552 mov bx, offset msg_hang
553 call puts
554 ; global _abort:near
555 _abort:
556 cli
557 hlt
558 jmp _abort
560 endp @die$qpxzc
562 struc image_himem ;struct image_himem {
563 fd dw ? ; 0 int fd;
564 fallback dd ? ; 2 u32 fallback;
565 size dd ? ; 6 u32 size;
566 remaining dd ? ;10 u32 remaining;
567 buf dd ? ;14 u32 buf;
568 bufv dw ? ;18 u32 *bufv;
569 errmsg dw ? ;20 char *errmsg;
570 chunk_size dd ? ;22 u32 chunk_size;
571 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
572 state dw ? ;28 u16 state;
573 fd2close dw ? ;30 u16 fd2close;
574 ends ;};
576 ;***************************************************************
577 ;static long next_chunk(struct image_himem *di);
578 ;***************************************************************
579 proc next_chunk near
581 push si
582 mov ax,[(image_himem di).fd]
583 call close
584 ifndef NO386
585 xor eax,eax
586 else
587 xor ax,ax
588 cwd
589 endif
590 mov [(image_himem di).fd],ax
591 mov bx,[(image_himem di).state]
592 cmp al,[bx] ; ""
593 jz @@end
594 mov si,bx
595 @@scan:
596 lodsb
597 mov cx,si
598 cmp al,','
599 jz @@eos
600 or al,al
601 jnz @@scan
602 dec cx
603 @@eos:
604 mov [(image_himem di).state],cx
605 dec si
606 push [word si]
607 mov [byte si],ah ; set temp eos
608 call open
609 pop [word si] ; restore string
610 jc @@die
611 mov [(image_himem di).fd],ax
612 mov [(image_himem di).fd2close],ax
613 mov bl,02h ; SEEK_END
614 call lseek0
615 @@die:
616 mov bx,[(image_himem di).errmsg]
617 jc die
618 ifndef NO386
619 push eax
620 mov ax,[(image_himem di).fd]
621 call rewind
622 pop eax
623 @@end:
624 mov [(image_himem di).chunk_size],eax
625 else
626 push ax
627 push dx
628 mov ax,[(image_himem di).fd]
629 call rewind
630 pop dx
631 pop ax
632 @@end:
633 mov [word (image_himem di).chunk_size],ax
634 mov [word ((image_himem di).chunk_size)+2],dx
635 endif
636 pop si
637 ret
639 endp next_chunk
642 ifdef LARGE_IMAGES
643 struc data_himem ;struct data_himem {
644 first dd ? ; 0 u32 first;
645 cacheidx dw ? ; 4 int cacheidx;
646 pageidx dw ? ; 6 int pageidx;
647 cache dd 1024 dup(?) ; 8 int cache;
648 page dd 1024 dup(?) ;4104 int page;
649 ends ;}; // size=8200
650 endif
652 ;***************************************************************
653 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
654 ;***************************************************************
655 global @malloc_bufv_or_die$qp11image_himem:near
656 proc @malloc_bufv_or_die$qp11image_himem near
658 p386
659 push si
660 mov si,bx
661 ifdef LARGE_IMAGES
662 movzx ecx,[word ((image_himem si).size) + 2]
663 shr cx,4 ; pages index size = size >> 20
664 add cx,8+4096+8
665 call malloc_or_die
666 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
667 add ecx,[(image_himem si).size]
668 shr ecx,12
669 mov [curdata],ax
670 else
671 mov ecx,[(image_himem si).size]
672 dec ecx
673 shr ecx,12
674 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
675 push cx
676 inc cx ; cnt+1
677 shl cx,2 ; bufv => vcpi => vm86
678 ; our malloc zeroes allocated mem: bufv[cnt]=0;
679 ; Allocate pages, storing addrs in addrbuf
680 call malloc_or_die
681 pop cx
682 push ax
683 endif
684 mov [(image_himem si).bufv],ax
685 xchg ax,si
686 @@vcpi_alloc:
687 xor edx,edx
688 mov ax,0DE04h
689 int 67h
690 or ah,ah
691 mov bx,offset vcpi_alloc_err
692 jnz die
693 ; for (i = cnt-1; i >= 0; i--)
694 ifdef LARGE_IMAGES
695 mov eax,ecx
696 dec eax
697 else
698 mov ax,cx
699 dec ax
700 cwde
701 endif
702 shl eax,12 ; i*_4k
703 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
704 extrn _imgs
705 mov bx,offset _imgs+2
706 push eax
707 add eax,[bx-2+2]
708 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
709 pop eax ; i*_4k
710 jbe @@pmok
711 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
712 jae @@vcpi_alloc
713 @@pmok:
714 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
715 extrn _imgs
716 mov bx,offset _imgs+32+2
717 add eax,[bx-2+2] ; +initrd.fallback
718 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
719 ja @@initrdok
720 mov eax,[bx-2+6] ; initrd.size
721 add eax,[bx-2+2] ; +initrd.fallback
722 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
723 @@jnc_vcpi_alloc:
724 ja @@vcpi_alloc
725 @@initrdok:
726 ifdef LARGE_IMAGES
727 cmp [(data_himem si).first],0
728 jne @@notfirst
729 mov [(data_himem si).first],edx
730 @@notfirst:
731 mov bx,[(data_himem si).cacheidx]
732 cmp bh,4
733 jae @@nextpage
734 shl bx,2
735 inc [(data_himem si).cacheidx]
736 mov [(data_himem bx+si).cache],edx
737 loopd @@vcpi_alloc
738 mov [(data_himem bx+si).cache],ecx ; last is 0
739 @@nextpage:
740 and [(data_himem si).cacheidx],0
741 mov bx,[(data_himem si).pageidx]
742 mov [(data_himem bx+si).page],edx
743 add [(data_himem si).pageidx],4
744 push cx
745 lea cx,[(data_himem si).cache]
746 ifdef NO386
747 push edx
748 pop dx
749 pop ax
750 endif
751 call storepage ; storepage(edx,cx)
752 pop cx
753 or ecx,ecx ; clear C
754 jnz @@jnc_vcpi_alloc
755 mov [dword (data_himem si).cacheidx],ecx
756 xchg ax,si
757 else
758 mov [si],edx
759 lodsd ; si=+4
760 loop @@vcpi_alloc
761 pop ax
762 endif
763 pop si
764 ret
765 ifdef NO386
766 p8086
767 endif
769 endp @malloc_bufv_or_die$qp11image_himem
772 ;***************************************************************
773 ;_fastcall void memcpy_image(bx:struct image_himem *m);
774 ;***************************************************************
775 global @memcpy_image$qp11image_himem:near
776 proc @memcpy_image$qp11image_himem near
778 ifndef NO386
779 mov edx,[(image_himem bx).fallback]
780 mov eax,[(image_himem bx).buf]
781 cmp eax,edx ; if (m->fallback != m->buf)
782 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
783 ifdef LARGE_IMAGES
784 mov ecx,[(image_himem bx).size]
785 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
786 push ecx
787 else
788 push [(image_himem bx).size]
789 endif
790 push eax
791 push 0
792 call_memcpy32:
793 push edx
794 else
795 mov ax,[word ((image_himem bx).fallback)]
796 mov dx,[word ((image_himem bx).fallback)+2]
797 mov cx,[word ((image_himem bx).buf)]
798 cmp ax,cx ; if (m->fallback != m->buf)
799 jnz @@do
800 cmp dx,[word ((image_himem bx).buf)+2]
801 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
802 @@do:
803 push [word ((image_himem bx).size)+2]
804 push [word ((image_himem bx).size)]
805 push [word ((image_himem bx).buf)+2]
806 push cx
807 xor cx,cx
808 push cx
809 call_memcpy32:
810 push dx
811 push ax
812 ifdef LARGE_IMAGES
813 jmp @@memcpy
814 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
815 p386
816 push ecx
817 push eax
818 push 0
819 push edx
820 ifdef NO386
821 p8086
822 endif
823 endif
824 endif
825 @@memcpy:
826 extrn memcpy32:near
827 call near memcpy32
828 @@skip:
829 ret
831 endp @memcpy_image$qp11image_himem
833 ;***************************************************************
834 ;_fastcall void storepage(bx:u32 *dst);
835 ;***************************************************************
836 global @storepage$qpul:near
837 proc @storepage$qpul near
839 ifndef NO386
840 mov edx,[bx]
841 else
842 mov ax,[bx]
843 mov dx,[bx+2]
844 endif
845 mov cx,offset _xfer_buf
846 storepage: ; storepage(edx,cx)
847 ifndef NO386
848 push 0
849 push 4096
850 push 0
851 else
852 xor bx,bx
853 push bx
854 mov bh,4096/256
855 push bx
856 xor bx,bx
857 push bx
858 endif
859 push cx
860 push ds
861 jmp call_memcpy32
863 endp @storepage$qpul
866 ifdef LARGE_IMAGES
867 p386
868 ;***************************************************************
869 ;_fastcall void reset_bufv(bx:u32 *p);
870 ;***************************************************************
871 global @reset_bufv$qpul:near
872 proc @reset_bufv$qpul near
874 mov [curdata],bx
875 and [dword (data_himem bx).cacheidx],0
876 ret
878 endp @reset_bufv$qpul
880 ;***************************************************************
881 ;u32* prev_bufv();
882 ;u32* prev_bufv();
883 ;***************************************************************
884 global _prev_bufv:near
885 global _next_bufv:near
886 proc _prev_bufv near
888 stc
889 db 73h ; jnc
890 _next_bufv:
891 clc
892 push si
893 mov si,[curdata]
894 sbb ax,ax
895 cmc
896 adc ax,[(data_himem si).cacheidx] ; -1/+1
897 xor ecx,ecx
898 test ax,0fc00h
899 jz @@gotpage
900 push ax ; FFFF / 0400
901 sar ax,8 ; FFFC / 0004
902 and al,0fch
903 add [(data_himem si).pageidx],ax
904 mov bx,[(data_himem si).pageidx]
905 lea bx,[(data_himem bx+si).page]
906 mov edx,ds
907 shl edx,4
908 lea cx,[(data_himem si).cache]
909 add edx,ecx
910 mov eax,[bx]
911 or eax,eax
912 jnz @@pageok
913 pop ax
914 xchg ax,bx
915 pop si
916 ret
917 @@pageok:
918 mov cx,4096
919 call memcpy_imagez ; get page
920 pop ax ; FFFF / 0400
921 cbw
922 shr ax,6 ; 03FF / 0000
923 @@gotpage:
924 mov [(data_himem si).cacheidx],ax
925 shl ax,2
926 xchg ax,bx
927 lea ax,[(data_himem bx+si).cache]
928 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
929 jnz @@notfirst2
930 xchg ax,si ; &first
931 @@notfirst2:
932 pop si
933 ret
935 endp _prev_bufv
936 endif
938 ifdef NO386
939 p8086
940 endif
942 ;***************************************************************
943 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
944 ;***************************************************************
946 global @open_image$qp11image_himempxzc:near
947 proc @open_image$qp11image_himempxzc near
949 push di
950 xchg ax,bx
951 xchg ax,di
952 ifdef EXTRA
953 cmp [(image_himem di).fd],0 ; iso image/kernel ?
954 jnz @@alreadydone
955 endif
956 mov [(image_himem di).state],bx
957 push bx
958 ifdef EXTRA
959 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
960 jnz @@next
961 mov [(image_himem di).next_chunk],offset next_chunk
962 @@next:
963 ;push di
964 call [(image_himem di).next_chunk] ; m->next_chunk()
965 ;pop di
966 else
967 @@next:
968 call next_chunk
969 endif
970 ifndef NO386
971 add eax,3
972 and al,0FCh
973 add [(image_himem di).size],eax ; m->size += m->chunk_size
974 or eax,eax
975 else
976 add ax,3
977 adc dx,0
978 and al,0FCh
979 add [word (image_himem di).size],ax ; m->size += m->chunk_size
980 adc [word ((image_himem di).size)+2],dx
981 or ax,dx
982 endif
983 jnz @@next
984 pop [(image_himem di).state]
985 ifdef EXTRA
986 ;push di
987 call [(image_himem di).next_chunk] ; m->next_chunk()
988 ;pop di
989 else
990 call next_chunk
991 endif
992 @@alreadydone:
993 pop di
994 ret
996 endp @open_image$qp11image_himempxzc
999 ;***************************************************************
1000 ;_fastcall int read_image(bx:struct image_himem *m);
1001 ;***************************************************************
1002 global @read_image$qp11image_himem:near
1003 proc @read_image$qp11image_himem near
1005 push si di
1006 mov di,bx
1007 mov si,4096
1008 push si ; original size
1009 @@loop:
1010 ifndef NO386
1011 movzx ecx,si
1012 mov eax,[(image_himem di).chunk_size]
1013 cmp ecx,eax
1014 jb @@szok
1015 else
1016 mov cx,si
1017 mov ax,[word (image_himem di).chunk_size]
1018 cmp cx,ax
1019 jb @@szok
1020 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1021 jne @@szok
1022 endif
1023 xchg ax,cx
1024 @@szok:
1025 jcxz image_done
1026 mov dx,offset _xfer_buf+4096
1027 sub dx,si
1028 mov bx,[di]
1029 call @read$cxdxbx
1030 jbe image_done
1031 xor cx,cx
1032 cwd ; ax < 8000h
1033 ifndef NO386
1034 cwde ; ax < 8000h
1035 sub [(image_himem di).chunk_size],eax
1036 xchg eax,ebx
1037 else
1038 sub [word (image_himem di).chunk_size],ax
1039 xchg ax,bx
1040 sbb [word ((image_himem di).chunk_size)+2],dx
1041 jnz @@fill
1042 cmp [word (image_himem di).chunk_size],dx
1043 endif
1044 jnz @@fill
1045 dec cx
1046 @@fill:
1047 test bl,3
1048 je @@filled
1049 mov [bx+_xfer_buf],dh
1050 inc bx
1051 jmp @@fill
1052 @@filled:
1053 ifndef NO386
1054 sub [(image_himem di).remaining],ebx
1055 else
1056 sub [word (image_himem di).remaining],bx
1057 sbb [word ((image_himem di).remaining)+2],dx
1058 endif
1059 sub si,bx
1060 pushf
1061 ifdef EXTRA
1062 and cx,[(image_himem di).next_chunk]
1063 jcxz @@same_chunk
1064 push di
1065 call cx
1066 pop cx
1067 else
1068 jcxz @@same_chunk
1069 call next_chunk
1070 endif
1071 @@same_chunk:
1072 popf
1073 jnz @@loop
1074 image_done:
1075 pop ax ; original size
1076 sub ax,si
1077 pop di si
1078 ret
1080 endp @read_image$qp11image_himem
1083 ;***************************************************************
1084 ;_fastcall unsigned long strtol(const char *s);
1085 ;***************************************************************
1086 global @strtol$qpxzc:near
1087 proc @strtol$qpxzc near
1089 ifndef NO386
1090 push si
1091 mov si,bx
1092 xor ecx,ecx
1093 xor eax,eax
1094 xor ebx,ebx
1095 or si,si
1096 jz @@end
1097 lodsb
1098 mov dx,ax
1099 or al,20h
1100 cmp al,'n' ; vga=normal
1101 je @@vga
1102 dec cx
1103 cmp al,'e' ; vga=extended
1104 je @@vga
1105 dec cx
1106 cmp al,'a' ; vga=ask
1107 jne @@notvga
1108 @@vga:
1109 dec cx
1110 xchg ax,cx
1111 cwd
1112 jmp @@popsiret
1113 @@notvga:
1114 mov cx,10 ; radix
1115 xchg ax,dx
1116 cmp al,'+'
1117 je @@radixskip
1118 cmp al,'-'
1119 clc
1120 jne @@radixkeep
1121 stc
1122 @@radixskip:
1123 lodsb
1124 @@radixkeep:
1125 pushf
1126 cmp al,'0'
1127 jne @@radixok
1128 mov cl,8
1129 lodsb
1130 or al,20h
1131 cmp al,'x'
1132 jne @@radixok
1133 mov cl,16
1134 @@strtollp:
1135 lodsb
1136 @@radixok:
1137 or al,20h
1138 sub al,'0'
1139 jb @@endstrtol
1140 cmp al,9
1141 jbe @@digitok
1142 cmp al,'a'-'0'
1143 jb @@endstrtol
1144 sub al,'a'-'0'-10
1145 @@digitok:
1146 cmp al,cl
1147 jae @@endstrtol
1148 xchg eax,ebx
1149 mul ecx
1150 add eax,ebx
1151 xchg eax,ebx
1152 jmp @@strtollp
1153 @@endstrtol:
1154 mov cl,10
1155 cmp al,'k'-'a'+10
1156 je @@shift
1157 mov cl,20
1158 cmp al,'m'-'a'+10
1159 je @@shift
1160 mov cl,30
1161 cmp al,'g'-'a'+10
1162 jne @@noshift
1163 @@shift:
1164 shl ebx,cl
1165 @@noshift:
1166 popf
1167 jnc @@end
1168 neg ebx
1169 @@end:
1170 push ebx
1171 pop ax
1172 pop dx
1173 @@popsiret:
1174 pop si
1175 else
1176 push si
1177 push di
1178 xor ax,ax
1179 cwd
1180 or bx,bx
1181 jz @@goend
1182 xchg ax,di
1183 mov si,bx
1184 lodsb
1185 mov bx,ax
1186 or al,20h
1187 mov cx,-1
1188 cmp al,'n' ; vga=normal
1189 je @@vga
1190 dec cx
1191 cmp al,'e' ; vga=extended
1192 je @@vga
1193 dec cx
1194 cmp al,'a' ; vga=ask
1195 jne @@notvga
1196 @@vga:
1197 xchg ax,cx
1198 @@goend:
1199 jmp @@popdisiret
1200 @@notvga:
1201 mov cx,10 ; radix
1202 xchg ax,bx
1203 cmp al,'+'
1204 je @@radixskip
1205 cmp al,'-'
1206 clc
1207 jne @@radixkeep
1208 stc
1209 @@radixskip:
1210 lodsb
1211 @@radixkeep:
1212 pushf
1213 cmp al,'0'
1214 jne @@radixok
1215 mov cl,8
1216 lodsb
1217 or al,20h
1218 cmp al,'x'
1219 jne @@radixok
1220 mov cl,16
1221 @@strtollp:
1222 lodsb
1223 @@radixok:
1224 or al,20h
1225 sub al,'0'
1226 jb @@endstrtol
1227 cmp al,9
1228 jbe @@digitok
1229 cmp al,'a'-'0'
1230 jb @@endstrtol
1231 sub al,'a'-'0'-10
1232 @@digitok:
1233 cmp al,cl
1234 jae @@endstrtol
1236 push ax
1237 push si
1238 push dx
1239 xchg ax,di
1240 mul cx
1241 xchg ax,di
1242 xchg ax,dx
1243 xchg ax,si
1244 pop ax
1245 mul cx
1246 add ax,si
1247 pop si
1248 xchg ax,dx
1249 pop ax
1250 mov ah,0
1251 add di,ax
1252 adc dx,0
1254 jmp @@strtollp
1255 @@endstrtol:
1256 mov cl,10
1257 cmp al,'k'-'a'+10
1258 je @@shift
1259 mov cl,20
1260 cmp al,'m'-'a'+10
1261 je @@shift
1262 mov cl,30
1263 cmp al,'g'-'a'+10
1264 jne @@noshift
1265 @@shift:
1266 rcl di,1
1267 shl dx,1
1268 loop @@shift
1269 @@noshift:
1270 popf
1271 jnc @@end
1272 not dx
1273 neg di
1274 jne @@end
1275 inc dx
1276 @@end:
1277 xchg ax,di
1278 @@popdisiret:
1279 pop di
1280 pop si
1281 endif
1282 strtol_ret:
1283 ret
1285 endp @strtol$qpxzc
1288 ifdef USE_ARGSTR
1289 ;***************************************************************
1290 ;_fastcall void set_cmdline(bx:const char *filename);
1291 ;***************************************************************
1292 global @set_cmdline$qpxzc:near
1293 proc @set_cmdline$qpxzc near
1294 call openargs
1295 jc strtol_ret
1296 mov cx,4096
1297 mov di,[_heap_top]
1298 extrn read_cmdline:near
1299 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1301 endp @set_cmdline$qpxzc
1302 endif
1305 ifdef NO386
1306 ;***************************************************************
1307 ;u16 topseg();
1308 ;***************************************************************
1309 global _topseg:near
1310 proc _topseg near
1312 int 12h
1313 jnc @@max640k
1314 mov ax,640 ; 9000
1315 @@max640k:
1316 dec ax
1317 and al,0C0h
1318 mov cl,6
1319 shl ax,cl
1320 ret
1322 endp _topseg
1323 endif
1325 ifdef EXTRA
1326 p8086
1327 ;***************************************************************
1328 ;char *progname(void)
1329 ;***************************************************************
1330 global _progname:near
1331 proc _progname near
1333 push si di es
1334 mov ah,30h
1335 int 21h
1336 xor di,di
1337 cmp al,3
1338 mov ax,di
1339 jb @@skip
1340 ;mov es,[cs:2Ch]
1341 mov es,[di+2Ch]
1342 mov cx,sp ; big enough
1343 @@loop:
1344 repne
1345 scasb
1346 scasb
1347 jne @@loop
1348 inc di
1349 inc di
1350 mov si,di ; progname @es:di
1351 repne
1352 scasb
1353 mov cx,di
1354 sub cx,si ; progname len
1355 call malloc_or_die ; keep cx
1356 mov di,ax
1357 push ds
1358 push es
1359 pop ds
1360 pop es
1361 rep
1362 movsb
1363 push es
1364 pop ds
1365 @@skip:
1366 pop es di si
1367 ret
1369 endp _progname
1372 ;***************************************************************
1373 ;_fastcall void chdirname(bx:char *path)
1374 ;***************************************************************
1375 global @chdirname$qpzc:near
1376 proc @chdirname$qpzc near
1378 cmp [byte bx+1],3Ah ; ':'
1379 jne @@nodisk
1380 mov dl,20h
1381 or dl,[bx]
1382 sub dl,61h
1383 mov ah,0Eh
1384 int 21h
1385 inc bx
1386 inc bx
1387 @@nodisk:
1388 xor cx,cx
1389 @@next:
1390 mov al,[bx]
1391 cmp al,5Ch
1392 jne @@tsteos
1393 mov dx,bx
1394 inc cx
1395 @@tsteos:
1396 inc bx
1397 or al,al
1398 jnz @@next
1399 jcxz @@end
1400 mov bx,dx
1401 push [word bx]
1402 mov [bx],al
1403 ifdef LONG_FILENAME
1404 stc
1405 mov ax,713Bh ; chdir long filename (ds:dx)
1406 int 21h
1407 jnc @@chdirdone
1408 endif
1409 mov ah,3Bh ; chdir(ds:dx)
1410 int 21h
1411 @@chdirdone:
1412 pop [word bx]
1413 @@end:
1414 ret
1416 endp @chdirname$qpzc
1419 ;***************************************************************
1420 ;_fastcall char *ultoa(axdx:unsigned long n);
1421 ;***************************************************************
1422 global @ultoa$qul:near
1423 proc @ultoa$qul near
1425 xchg ax,cx
1426 xchg ax,dx ; AX:CX = n
1427 push si
1428 mov si,10
1429 mov bx,offset ultoabuf+11
1430 @@loop:
1431 dec bx
1432 xor dx,dx
1433 div si ; DX:AX = 0000:hi(n)
1434 xchg ax,cx ; CX = hi(n)/10
1435 div si ; DX:AX = hi(n)%10:lo(n)
1436 xchg ax,cx ; CX = lo(n/10)
1437 ; AX = hi(n)/10 = hi(n/10)
1438 mov [byte bx],'0'
1439 add [bx],dl ; DL = n%10
1440 mov dx,ax
1441 or dx,cx
1442 jnz @@loop
1443 xchg ax,bx
1444 pop si
1445 ret
1447 endp @ultoa$qul
1450 ;***************************************************************
1451 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1452 ;***************************************************************
1453 global @kver2ul$qpzc:near
1454 proc @kver2ul$qpzc near
1456 push si
1457 mov si,bx
1458 xor bx,bx
1459 mov cx,304h
1460 @@number:
1461 xor ax,ax
1462 cwd
1463 @@digit:
1464 shl al,cl
1465 shl ax,cl
1466 lodsb
1467 sub al,30h
1468 cmp al,9
1469 jbe @@digit
1470 mov dl,bh
1471 mov bh,bl
1472 mov bl,ah
1473 dec ch
1474 jnz @@number
1475 xchg ax,bx
1476 pop si
1477 kver2ulret:
1478 ret
1480 endp @kver2ul$qpzc
1482 endif
1484 ;***************************************************************
1485 ;void try_default_args();
1486 ;***************************************************************
1487 ifdef EXTRA
1489 global _try_default_args:near
1490 proc _try_default_args near
1492 mov bx,offset tazboot_cmd
1493 call open
1494 jc kver2ulret
1495 mov cx,4096
1496 mov di,[_heap_top]
1497 extrn read_cmdline:near
1498 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1500 endp _try_default_args
1502 endif
1504 ends _TEXT
1506 end
1508 ;###### END OF FILE ############################################