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

Up firefox-official (64.0), again
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jan 03 12:04:23 2019 +0100 (2019-01-03)
parents cb4579b9835b
children ab907169f156
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 _xfer_buf db 4096 dup (?)
35 global _no_exit:byte
36 _no_exit db ?
37 filecnt db ? ; in fact 0 minus file count...
38 nextfilename dw ?
39 ifdef LARGE_IMAGES
40 curdata dw ?
41 endif
42 ifdef EXTRA
43 ultoabuf db 12 dup (?)
44 endif
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 ;***************************************************************
51 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
52 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
53 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
54 ;***************************************************************
55 global @strcatb$qpxzct1:near
56 proc @strcatb$qpxzct1 near
58 ifdef EXTRA
59 mov cl,7Fh
60 db 0bah ; mov dx,imm opcode
61 global @strcat$qpxzct1:near
62 @strcat$qpxzct1:
63 mov cl,80h
64 db 0bah ; mov dx,imm opcode
65 global @strcpy$qpxzct1:near
66 @strcpy$qpxzct1:
67 xor cx,cx
68 endif
69 push si
70 xchg ax,bx ; b
71 xchg ax,si ; a
72 ifdef EXTRA
73 jcxz @@nocat
74 endif
75 @@catlp:
76 lodsb ; a=si
77 or al,al
78 jne @@catlp
79 dec si
80 ifdef EXTRA
81 cmp bx,si
82 adc al,cl ; set S when bx != si or cl = 80
83 mov al,20h
84 jns @@cpyhead
85 endif
86 @@nocat:
87 @@cpylp:
88 mov al,[bx]
89 inc bx
90 @@cpyhead:
91 mov [si],al
92 inc si
93 or al,al
94 jne @@cpylp
95 strfound:
96 xchg ax,dx
97 strend:
98 pop si
99 ret
101 endp @strcatb$qpxzct1
104 ifdef EXTRA
105 p8086
106 ;***************************************************************
107 ;_fastcall char strstr(bx:const char* a, ax:const char* b);
108 ;***************************************************************
109 global @strstr$qpxzct1:near
110 proc @strstr$qpxzct1 near
112 xchg ax,cx ; b
113 mov dx,bx ; a
114 push si
115 @@loop:
116 xor ax,ax
117 mov si,dx
118 cmp [si],al ; *a
119 jz strend ; return ax = NULL
120 mov bx,cx
121 @@match:
122 or ah,[bx] ; *b
123 jz strfound
124 inc bx
125 lodsb
126 sub ah,al
127 jz @@match
128 inc dx
129 jmp @@loop
131 endp @strstr$qpxzct1
134 ;***************************************************************
135 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
136 ;***************************************************************
137 global @strcmp$qpxzct1:near
138 proc @strcmp$qpxzct1 near
140 push si
141 xchg ax,si
142 dec bx
143 @@lp:
144 inc bx
145 lodsb
146 sub al,[bx]
147 jnz @@out
148 or al,[bx]
149 jnz @@lp
150 @@out:
151 cbw
152 pop si
153 ret
155 endp @strcmp$qpxzct1
156 endif
159 ;***************************************************************
160 ;_fastcall void puts(bx:const char* s):
161 ;***************************************************************
162 global @puts$qpxzc:near
163 proc @puts$qpxzc near
165 ; global puts:near ; puts(bx)
166 puts:
167 call @@putsz
168 mov bx,offset msg_lf
169 mov dl,13
170 @@putcz:
171 mov ah,2
172 int 21h
173 @@putsz:
174 mov dl,[bx]
175 inc bx
176 or dl,dl
177 jne @@putcz ; ZF=1 (for malloc failure)
178 ret
180 endp @puts$qpxzc
183 ;***************************************************************
184 ;_fastcall int fileattr(bx:const char* name);
185 ;***************************************************************
186 global @fileattr$qpxzc:near
187 proc @fileattr$qpxzc near
189 mov ax,4300h
190 call dos_filename
191 xchg ax,cx
192 jmp chkc
194 endp @fileattr$qpxzc
197 ;***************************************************************
198 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
199 ;***************************************************************
200 global openargs:near ; openargs(bx)
201 openargs:
202 cmp [byte bx],'@'
203 stc
204 jne fail
205 inc bx
207 global @open$qpxzc:near
208 proc @open$qpxzc near
210 global open:near ; open(bx)
211 open:
212 ifdef LONG_FILENAME
213 mov ax,716Ch
214 push bx si di
215 mov di,di ; alias hint
216 mov si,bx
217 xor bx,bx ; R/O
218 xor cx,cx ; attributes
219 cwd ; action = open
220 int 21h
221 pop di si bx
222 jnc doret
223 endif
224 mov ax,3d00h ; read-only+compatibility
225 ;mov cl,0 ; attribute mask
226 dos_filename:
227 mov dx,bx
228 dos:
229 int 21h
230 chkc:
231 jnc doret
232 fail:
233 sbb ax,ax ; ax=-1 CF
234 cwd
235 doret:
236 ifndef NO386
237 push dx ; see next_chunk:lseek
238 push ax
239 pop eax
240 endif
241 ret
243 endp @open$qpxzc
246 ;***************************************************************
247 ;_fastcall int close(ax:int fd);
248 ;***************************************************************
249 global @close$qi:near
250 proc @close$qi near
252 global close:near ; close(ax)
253 close:
254 xchg ax,bx
255 mov ah,3Eh
256 or bx,bx
257 jnz dos
258 ret
260 endp @close$qi
263 ;***************************************************************
264 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
265 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
266 ;***************************************************************
267 global @read$qipvi:near
268 proc @read$qipvi near
270 ifdef WRITE
271 stc
272 db 0B0h ; mov al,im
273 global @write$qipvi:near
274 @write$qipvi:
275 clc
276 endif
277 xchg ax,bx ; fd
278 xchg ax,dx ; data
279 xchg ax,cx ; sz
280 ifdef WRITE
281 mov ah,40h
282 sbb ah,0
283 else
284 global @read$cxdxbx:near
285 @read$cxdxbx:
286 mov ah,3Fh
287 endif
288 jcxz fail
289 jmp dos
291 endp @read$qipvi
293 ;***************************************************************
294 ;_fastcall long lseekset(ax:int fd, dx:unsigned whence);
295 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
296 ;***************************************************************
298 global @lseekcur$qii:near ; fd=ax whence=dx
299 proc @lseekcur$qii near
301 xchg ax,bx
302 xchg ax,dx
303 cwd
304 xchg ax,dx
305 xchg ax,cx
306 mov al,1
307 jmp lseek
308 ifdef EXTRA
309 global @lseekset$qiui:near
310 @lseekset$qiui:
311 mov bl,0
312 jmp lseek0x
313 lseekset:
314 mov bl,0
315 jmp lseekx
316 endif
317 rewind: ; rewind(ax)
318 mov bl,0
319 lseek0: ; lseek0(bx,ax=dir)
320 xor dx,dx
321 lseek0x:
322 xor cx,cx
323 lseekx:
324 xchg ax,bx
325 lseek:
326 mov ah,42h ; bx=fd cx:dx=offset al=whence
327 jmp dos
329 endp @lseekcur$qii
331 ifdef EXTRA
333 ;typedef unsigned dirsizetype;
334 struc isostate ; struct isostate {
335 fd dw ? ; 0 int fd;
336 filemod dw ? ; 2 unsigned short filemod;
337 fileofs dd ? ; 4 unsigned long fileofs;
338 filesize dd ? ; 8 unsigned long filesize;
339 filename dw ? ;12 char *filename;
340 curdirsize dw ? ;14 dirsizetype curdirsize;
341 dirsize dw ? ;16 dirsizetype dirsize;
342 curdirofs dd ? ;18 unsigned long curdirofs;
343 dirofs dd ? ;22 unsigned long dirofs;
344 curpos dw ? ;26 unsigned curpos;
345 buffer db 2560 dup(?) ;28 char buffer[2048+512];
346 ends ; } isostate;
347 ;***************************************************************
348 ;_fastcall long isolseek(bx:const unsigned long *offset);
349 ;***************************************************************
350 global @isolseek$qpxul:near
351 proc @isolseek$qpxul near
353 isolseek:
354 mov dx,[bx]
355 mov cx,[bx+2]
356 extrn _isostate:isostate
357 mov ax,[_isostate.fd]
358 jmp lseekset
360 endp @isolseek$qpxul
362 ;***************************************************************
363 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
364 ;***************************************************************
365 global @isoreadsector$qpxul:near
366 proc @isoreadsector$qpxul near
368 call isolseek
369 and ax,dx
370 inc ax
371 jz @@fail
372 mov cx,2560
373 mov dx,offset _isostate.buffer
374 mov bx,[_isostate.fd]
375 call @read$cxdxbx ; read(fd,buffer,2560)
376 @@fail:
377 cmp ax,2048
378 sbb ax,ax
379 ret
381 endp @isoreadsector$qpxul
383 endif
386 ;***************************************************************
387 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
388 ;***************************************************************
389 global @strhead$qpxzct1:near
390 proc @strhead$qpxzct1 near
392 @@loop:
393 xchg ax,bx
394 mov cl,[bx] ; cl = *b++
395 inc bx
396 or cl,cl ; clear C
397 jz fail ; return 0
398 xchg ax,bx
399 xor cl,[bx] ; cl -= *a++
400 inc bx
401 and cl,0dfh ; case insensitive
402 jz @@loop
403 ret ; return b (is not 0)
405 endp @strhead$qpxzct1
408 ;***************************************************************
409 ;_fastcall char* malloc_or_die(ax:unsigned size);
410 ;***************************************************************
411 global @malloc_or_die$qui:near
412 proc @malloc_or_die$qui near
414 xchg ax,cx ; size
415 global malloc_or_die:near ; malloc_or_die(cx)
416 malloc_or_die:
417 mov ax,[_heap_top] ; return value
418 mov bx,sp
419 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
420 sub bx,ax ; can't overflow
421 cmp bx,cx
422 mov bx,offset msg_malloc
423 jb die
424 add [_heap_top],cx ; _BEG has zero'd heap
425 ret
427 endp @malloc_or_die$qui
430 ;***************************************************************
431 ;_fastcall int die(bx:const char* msg);
432 ;int exit();
433 ;int abort();
434 ;***************************************************************
435 global @die$qpxzc:near
436 proc @die$qpxzc near
437 @die$qpxzc:
438 global die:near ; die(bx)
439 die:
440 call puts
441 ; global _exit:near
442 _exit:
443 mov al,[_no_exit]
444 or al,al
445 jne @@hang
446 extrn exit:near
447 inc ax
448 jmp near exit
449 @@hang:
450 mov bx, offset msg_hang
451 call puts
452 ; global _abort:near
453 _abort:
454 cli
455 @@stop:
456 hlt
457 jmp @@stop
459 endp @die$qpxzc
461 struc image_himem ;struct image_himem {
462 fd dw ? ; 0 int fd;
463 fallback dd ? ; 2 u32 fallback;
464 size dd ? ; 6 u32 size;
465 remaining dd ? ;10 u32 remaining;
466 buf dd ? ;14 u32 buf;
467 bufv dw ? ;18 u32 *bufv;
468 errmsg dw ? ;20 char *errmsg;
469 chunk_size dd ? ;22 u32 chunk_size;
470 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
471 state dw ? ;28 u16 state;
472 fd2close dw ? ;30 u16 fd2close;
473 ends ;};
475 ;***************************************************************
476 ;static long next_chunk(struct image_himem *di);
477 ;***************************************************************
478 proc next_chunk near
480 push si
481 mov ax,[(image_himem di).fd]
482 call close
483 ifndef NO386
484 xor eax,eax
485 else
486 xor ax,ax
487 cwd
488 endif
489 mov [(image_himem di).fd],ax
490 mov bx,[(image_himem di).state]
491 cmp al,[bx] ; ""
492 jz @@end
493 mov si,bx
494 @@scan:
495 lodsb
496 mov cx,si
497 cmp al,','
498 jz @@eos
499 or al,al
500 jnz @@scan
501 dec cx
502 @@eos:
503 mov [(image_himem di).state],cx
504 dec si
505 push [word si]
506 mov [byte si],ah ; set temp eos
507 call open
508 pop [word si] ; restore string
509 jc @@die
510 mov [(image_himem di).fd],ax
511 mov [(image_himem di).fd2close],ax
512 mov bl,02h ; SEEK_END
513 call lseek0
514 @@die:
515 mov bx,[(image_himem di).errmsg]
516 jc die
517 ifndef NO386
518 push eax
519 mov ax,[(image_himem di).fd]
520 call rewind
521 pop eax
522 @@end:
523 mov [(image_himem di).chunk_size],eax
524 else
525 push ax
526 push dx
527 mov ax,[(image_himem di).fd]
528 call rewind
529 pop dx
530 pop ax
531 @@end:
532 mov [word (image_himem di).chunk_size],ax
533 mov [word ((image_himem di).chunk_size)+2],dx
534 endif
535 pop si
536 ret
538 endp next_chunk
541 ifdef LARGE_IMAGES
542 struc data_himem ;struct data_himem {
543 first dd ? ; 0 u32 first;
544 cacheidx dw ? ; 4 int cacheidx;
545 pageidx dw ? ; 6 int pageidx;
546 cache dd 1024 dup(?) ; 8 int cache;
547 page dd 1024 dup(?) ;4104 int page;
548 ends ;}; // size=8200
549 endif
551 ;***************************************************************
552 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
553 ;***************************************************************
554 global @malloc_bufv_or_die$qp11image_himem:near
555 proc @malloc_bufv_or_die$qp11image_himem near
557 p386
558 push si
559 mov si,bx
560 ifdef LARGE_IMAGES
561 movzx ecx,[word ((image_himem si).size) + 2]
562 shr cx,4 ; pages index size = size >> 20
563 add cx,8+4096+8
564 call malloc_or_die
565 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
566 add ecx,[(image_himem si).size]
567 shr ecx,12
568 mov [curdata],ax
569 else
570 mov ecx,[(image_himem si).size]
571 dec ecx
572 shr ecx,12
573 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
574 push cx
575 inc cx ; cnt+1
576 shl cx,2 ; bufv => vcpi => vm86
577 ; our malloc zeroes allocated mem: bufv[cnt]=0;
578 ; Allocate pages, storing addrs in addrbuf
579 call malloc_or_die
580 pop cx
581 push ax
582 endif
583 mov [(image_himem si).bufv],ax
584 xchg ax,si
585 @@vcpi_alloc:
586 xor edx,edx
587 mov ax,0DE04h
588 int 67h
589 or ah,ah
590 mov bx,offset vcpi_alloc_err
591 jnz die
592 ; for (i = cnt-1; i >= 0; i--)
593 ifdef LARGE_IMAGES
594 mov eax,ecx
595 dec eax
596 else
597 mov ax,cx
598 dec ax
599 cwde
600 endif
601 shl eax,12 ; i*_4k
602 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
603 extrn _imgs
604 mov bx,offset _imgs+2
605 push eax
606 add eax,[bx-2+2]
607 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
608 pop eax ; i*_4k
609 jbe @@pmok
610 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
611 jae @@vcpi_alloc
612 @@pmok:
613 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
614 extrn _imgs
615 mov bx,offset _imgs+32+2
616 add eax,[bx-2+2] ; +initrd.fallback
617 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
618 ja @@initrdok
619 mov eax,[bx-2+6] ; initrd.size
620 add eax,[bx-2+2] ; +initrd.fallback
621 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
622 @@jnc_vcpi_alloc:
623 ja @@vcpi_alloc
624 @@initrdok:
625 ifdef LARGE_IMAGES
626 cmp [(data_himem si).first],0
627 jne @@notfirst
628 mov [(data_himem si).first],edx
629 @@notfirst:
630 mov bx,[(data_himem si).cacheidx]
631 cmp bh,4
632 jae @@nextpage
633 shl bx,2
634 inc [(data_himem si).cacheidx]
635 mov [(data_himem bx+si).cache],edx
636 loopd @@vcpi_alloc
637 mov [(data_himem bx+si).cache],ecx ; last is 0
638 @@nextpage:
639 and [(data_himem si).cacheidx],0
640 mov bx,[(data_himem si).pageidx]
641 mov [(data_himem bx+si).page],edx
642 add [(data_himem si).pageidx],4
643 push cx
644 lea cx,[(data_himem si).cache]
645 ifdef NO386
646 push edx
647 pop dx
648 pop ax
649 endif
650 call storepage ; storepage(edx,cx)
651 pop cx
652 or ecx,ecx ; clear C
653 jnz @@jnc_vcpi_alloc
654 mov [dword (data_himem si).cacheidx],ecx
655 xchg ax,si
656 else
657 mov [si],edx
658 lodsd ; si=+4
659 loop @@vcpi_alloc
660 pop ax
661 endif
662 pop si
663 ret
664 ifdef NO386
665 p8086
666 endif
668 endp @malloc_bufv_or_die$qp11image_himem
671 ;***************************************************************
672 ;_fastcall void memcpy_image(bx:struct image_himem *m);
673 ;***************************************************************
674 global @memcpy_image$qp11image_himem:near
675 proc @memcpy_image$qp11image_himem near
677 ifndef NO386
678 mov edx,[(image_himem bx).fallback]
679 mov eax,[(image_himem bx).buf]
680 cmp eax,edx ; if (m->fallback != m->buf)
681 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
682 ifdef LARGE_IMAGES
683 mov ecx,[(image_himem bx).size]
684 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
685 push ecx
686 else
687 push [(image_himem bx).size]
688 endif
689 push eax
690 push 0
691 call_memcpy32:
692 push edx
693 else
694 mov ax,[word ((image_himem bx).fallback)]
695 mov dx,[word ((image_himem bx).fallback)+2]
696 mov cx,[word ((image_himem bx).buf)]
697 cmp ax,cx ; if (m->fallback != m->buf)
698 jnz @@do
699 cmp dx,[word ((image_himem bx).buf)+2]
700 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
701 @@do:
702 push [word ((image_himem bx).size)+2]
703 push [word ((image_himem bx).size)]
704 push [word ((image_himem bx).buf)+2]
705 push cx
706 xor cx,cx
707 push cx
708 call_memcpy32:
709 push dx
710 push ax
711 ifdef LARGE_IMAGES
712 jmp @@memcpy
713 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
714 p386
715 push ecx
716 push eax
717 push 0
718 push edx
719 ifdef NO386
720 p8086
721 endif
722 endif
723 endif
724 @@memcpy:
725 extrn memcpy32:near
726 call near memcpy32
727 @@skip:
728 ret
730 endp @memcpy_image$qp11image_himem
732 ;***************************************************************
733 ;_fastcall void storepage(bx:u32 *dst);
734 ;***************************************************************
735 global @storepage$qpul:near
736 proc @storepage$qpul near
738 ifndef NO386
739 mov edx,[bx]
740 else
741 mov ax,[bx]
742 mov dx,[bx+2]
743 endif
744 mov cx,offset _xfer_buf
745 storepage: ; storepage(edx,cx)
746 ifndef NO386
747 push 0
748 push 4096
749 push 0
750 else
751 xor bx,bx
752 push bx
753 mov bh,4096/256
754 push bx
755 xor bx,bx
756 push bx
757 endif
758 push cx
759 push ds
760 jmp call_memcpy32
762 endp @storepage$qpul
765 ifdef LARGE_IMAGES
766 p386
767 ;***************************************************************
768 ;_fastcall void reset_bufv(bx:u32 *p);
769 ;***************************************************************
770 global @reset_bufv$qpul:near
771 proc @reset_bufv$qpul near
773 mov [curdata],bx
774 and [dword (data_himem bx).cacheidx],0
775 ret
777 endp @reset_bufv$qpul
779 ;***************************************************************
780 ;u32* prev_bufv();
781 ;u32* prev_bufv();
782 ;***************************************************************
783 global _prev_bufv:near
784 global _next_bufv:near
785 proc _prev_bufv near
787 stc
788 db 73h ; jnc
789 _next_bufv:
790 clc
791 push si
792 mov si,[curdata]
793 sbb ax,ax
794 cmc
795 adc ax,[(data_himem si).cacheidx] ; -1/+1
796 xor ecx,ecx
797 test ax,0fc00h
798 jz @@gotpage
799 push ax ; FFFF / 0400
800 sar ax,8 ; FFFC / 0004
801 and al,0fch
802 add [(data_himem si).pageidx],ax
803 mov bx,[(data_himem si).pageidx]
804 lea bx,[(data_himem bx+si).page]
805 mov edx,ds
806 shl edx,4
807 lea cx,[(data_himem si).cache]
808 add edx,ecx
809 mov eax,[bx]
810 or eax,eax
811 jnz @@pageok
812 pop ax
813 xchg ax,bx
814 pop si
815 ret
816 @@pageok:
817 mov cx,4096
818 call memcpy_imagez ; get page
819 pop ax ; FFFF / 0400
820 cbw
821 shr ax,6 ; 03FF / 0000
822 @@gotpage:
823 mov [(data_himem si).cacheidx],ax
824 shl ax,2
825 xchg ax,bx
826 lea ax,[(data_himem bx+si).cache]
827 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
828 jnz @@notfirst2
829 xchg ax,si ; &first
830 @@notfirst2:
831 pop si
832 ret
834 endp _prev_bufv
835 endif
837 ifdef NO386
838 p8086
839 endif
841 ;***************************************************************
842 ;_fastcall void open_image(bx:const char *name, ax:struct image_himem *m);
843 ;***************************************************************
844 global @open_image$qpxzcp11image_himem:near
845 proc @open_image$qpxzcp11image_himem near
847 push di
848 xchg ax,di
849 ifdef EXTRA
850 cmp [(image_himem di).fd],0 ; iso image/kernel ?
851 jnz @@alreadydone
852 endif
853 mov [(image_himem di).state],bx
854 push bx
855 ifdef EXTRA
856 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
857 jnz @@next
858 endif
859 mov [(image_himem di).next_chunk],offset next_chunk
860 @@next:
861 call [(image_himem di).next_chunk] ; m->next_chunk()
862 ifndef NO386
863 add eax,3
864 and al,0FCh
865 add [(image_himem di).size],eax ; m->size += m->chunk_size
866 or eax,eax
867 else
868 add ax,3
869 adc dx,0
870 and al,0FCh
871 add [word (image_himem di).size],ax ; m->size += m->chunk_size
872 adc [word ((image_himem di).size)+2],dx
873 or ax,dx
874 endif
875 jnz @@next
876 pop [(image_himem di).state]
877 call [(image_himem di).next_chunk] ; m->next_chunk()
878 @@alreadydone:
879 pop di
880 ret
882 endp @open_image$qpxzcp11image_himem
885 ;***************************************************************
886 ;_fastcall int read_image(bx:struct image_himem *m);
887 ;***************************************************************
888 global @read_image$qp11image_himem:near
889 proc @read_image$qp11image_himem near
891 push si di
892 mov di,bx
893 mov si,4096
894 push si ; original size
895 @@loop:
896 ifndef NO386
897 movzx ecx,si
898 mov eax,[(image_himem di).chunk_size]
899 cmp ecx,eax
900 jb @@szok
901 else
902 mov cx,si
903 mov ax,[word (image_himem di).chunk_size]
904 cmp cx,ax
905 jb @@szok
906 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
907 jne @@szok
908 endif
909 xchg ax,cx
910 @@szok:
911 jcxz image_done
912 mov dx,offset _xfer_buf
913 mov bx,[di]
914 call @read$cxdxbx
915 jc image_done
916 xor cx,cx
917 cwd ; ax < 8000h
918 ifndef NO386
919 cwde ; ax < 8000h
920 sub [(image_himem di).chunk_size],eax
921 xchg eax,ebx
922 else
923 sub [word (image_himem di).chunk_size],ax
924 xchg ax,bx
925 sbb [word ((image_himem di).chunk_size)+2],dx
926 jnz @@fill
927 cmp [word (image_himem di).chunk_size],dx
928 endif
929 jnz @@fill
930 dec cx
931 @@fill:
932 test bl,3
933 je @@filled
934 mov [bx+_xfer_buf],dh
935 inc bx
936 jmp @@fill
937 @@filled:
938 ifndef NO386
939 sub [(image_himem di).remaining],ebx
940 else
941 sub [word (image_himem di).remaining],bx
942 sbb [word ((image_himem di).remaining)+2],dx
943 endif
944 sub si,bx
945 pushf
946 and cx,[(image_himem di).next_chunk]
947 jcxz @@same_chunk
948 call cx
949 @@same_chunk:
950 popf
951 jnz @@loop
952 image_done:
953 pop ax ; original size
954 sub ax,si
955 pop di si
956 ret
958 endp @read_image$qp11image_himem
961 ;***************************************************************
962 ;pascal unsigned long strtol(const char *s);
963 ;***************************************************************
964 global @strtol$qpxzc:near
965 proc @strtol$qpxzc near
967 pop ax
968 pop bx ; s
969 push ax
970 ifndef NO386
971 xor ebx,ebx
972 push si
973 jcxz @@end
974 mov si,cx
975 xor ecx,ecx
976 xor eax,eax
977 lodsb
978 mov dx,ax
979 or al,20h
980 cmp al,'n' ; vga=normal
981 je @@vga
982 dec cx
983 cmp al,'e' ; vga=extended
984 je @@vga
985 dec cx
986 cmp al,'a' ; vga=ask
987 jne @@notvga
988 @@vga:
989 dec cx
990 xchg ax,cx
991 cwd
992 jmp @@popsiret
993 @@notvga:
994 mov cx,10 ; radix
995 xchg ax,dx
996 cmp al,'+'
997 je @@radixskip
998 cmp al,'-'
999 clc
1000 jne @@radixkeep
1001 stc
1002 @@radixskip:
1003 lodsb
1004 @@radixkeep:
1005 pushf
1006 cmp al,'0'
1007 jne @@radixok
1008 mov cl,8
1009 lodsb
1010 or al,20h
1011 cmp al,'x'
1012 jne @@radixok
1013 mov cl,16
1014 @@strtollp:
1015 lodsb
1016 @@radixok:
1017 or al,20h
1018 sub al,'0'
1019 jb @@endstrtol
1020 cmp al,9
1021 jbe @@digitok
1022 cmp al,'a'-'0'
1023 jb @@endstrtol
1024 sub al,'a'-'0'-10
1025 @@digitok:
1026 cmp al,cl
1027 jae @@endstrtol
1028 xchg eax,ebx
1029 mul ecx
1030 add eax,ebx
1031 xchg eax,ebx
1032 jmp @@strtollp
1033 @@endstrtol:
1034 mov cl,10
1035 cmp al,'k'-'a'+10
1036 je @@shift
1037 mov cl,20
1038 cmp al,'m'-'a'+10
1039 je @@shift
1040 mov cl,30
1041 cmp al,'g'-'a'+10
1042 jne @@noshift
1043 @@shift:
1044 shl ebx,cl
1045 @@noshift:
1046 popf
1047 jnc @@end
1048 neg ebx
1049 @@end:
1050 push ebx
1051 pop ax
1052 pop dx
1053 @@popsiret:
1054 pop si
1055 else
1056 push si
1057 push di
1058 xor ax,ax
1059 cwd
1060 jcxz @@goend
1061 xchg ax,di
1062 mov si,cx
1063 lodsb
1064 mov bx,ax
1065 or al,20h
1066 mov cx,-1
1067 cmp al,'n' ; vga=normal
1068 je @@vga
1069 dec cx
1070 cmp al,'e' ; vga=extended
1071 je @@vga
1072 dec cx
1073 cmp al,'a' ; vga=ask
1074 jne @@notvga
1075 @@vga:
1076 xchg ax,cx
1077 @@goend:
1078 jmp @@popdisiret
1079 @@notvga:
1080 mov cx,10 ; radix
1081 xchg ax,bx
1082 cmp al,'+'
1083 je @@radixskip
1084 cmp al,'-'
1085 clc
1086 jne @@radixkeep
1087 stc
1088 @@radixskip:
1089 lodsb
1090 @@radixkeep:
1091 pushf
1092 cmp al,'0'
1093 jne @@radixok
1094 mov cl,8
1095 lodsb
1096 or al,20h
1097 cmp al,'x'
1098 jne @@radixok
1099 mov cl,16
1100 @@strtollp:
1101 lodsb
1102 @@radixok:
1103 or al,20h
1104 sub al,'0'
1105 jb @@endstrtol
1106 cmp al,9
1107 jbe @@digitok
1108 cmp al,'a'-'0'
1109 jb @@endstrtol
1110 sub al,'a'-'0'-10
1111 @@digitok:
1112 cmp al,cl
1113 jae @@endstrtol
1115 push ax
1116 push si
1117 push dx
1118 xchg ax,di
1119 mul cx
1120 xchg ax,di
1121 xchg ax,dx
1122 xchg ax,si
1123 pop ax
1124 mul cx
1125 add ax,si
1126 pop si
1127 xchg ax,dx
1128 pop ax
1129 mov ah,0
1130 add di,ax
1131 adc dx,0
1133 jmp @@strtollp
1134 @@endstrtol:
1135 mov cl,10
1136 cmp al,'k'-'a'+10
1137 je @@shift
1138 mov cl,20
1139 cmp al,'m'-'a'+10
1140 je @@shift
1141 mov cl,30
1142 cmp al,'g'-'a'+10
1143 jne @@noshift
1144 @@shift:
1145 rcl di,1
1146 shl dx,1
1147 loop @@shift
1148 @@noshift:
1149 popf
1150 jnc @@end
1151 not dx
1152 neg di
1153 jne @@end
1154 inc dx
1155 @@end:
1156 xchg ax,di
1157 @@popdisiret:
1158 pop di
1159 pop si
1160 endif
1161 strtol_ret:
1162 ret
1164 endp @strtol$qpxzc
1167 ifdef NO386
1168 ;***************************************************************
1169 ;u16 topseg();
1170 ;***************************************************************
1171 global _topseg:near
1172 proc _topseg near
1174 int 12h
1175 jnc @@max640k
1176 mov ax,640 ; 9000
1177 @@max640k:
1178 dec ax
1179 and al,0C0h
1180 mov cl,6
1181 shl ax,cl
1182 ret
1184 endp _topseg
1185 endif
1187 ifdef EXTRA
1188 p8086
1189 ;***************************************************************
1190 ;char *progname(void)
1191 ;***************************************************************
1192 global _progname:near
1193 proc _progname near
1195 push si di es
1196 mov ah,30h
1197 int 21h
1198 xor di,di
1199 cmp al,3
1200 mov ax,di
1201 jb @@skip
1202 ;mov es,[cs:2Ch]
1203 mov es,[di+2Ch]
1204 mov cx,sp ; big enough
1205 @@loop:
1206 repne
1207 scasb
1208 scasb
1209 jne @@loop
1210 inc di
1211 inc di
1212 mov si,di ; progname @es:di
1213 repne
1214 scasb
1215 mov cx,di
1216 sub cx,si ; progname len
1217 call malloc_or_die ; keep cx
1218 mov di,ax
1219 push ds
1220 push es
1221 pop ds
1222 pop es
1223 rep
1224 movsb
1225 push es
1226 pop ds
1227 @@skip:
1228 pop es di si
1229 ret
1231 endp _progname
1234 ;***************************************************************
1235 ;_fastcall void chdirname(bx:char *path)
1236 ;***************************************************************
1237 global @chdirname$qpzc:near
1238 proc @chdirname$qpzc near
1240 cmp [byte bx+1],3Ah ; ':'
1241 jne @@nodisk
1242 mov dl,20h
1243 or dl,[bx]
1244 sub dl,61h
1245 mov ah,0Eh
1246 int 21h
1247 inc bx
1248 inc bx
1249 @@nodisk:
1250 xor cx,cx
1251 @@next:
1252 mov al,[bx]
1253 cmp al,5Ch
1254 jne @@tsteos
1255 mov dx,bx
1256 inc cx
1257 @@tsteos:
1258 inc bx
1259 or al,al
1260 jnz @@next
1261 jcxz @@end
1262 mov bx,dx
1263 push [word bx]
1264 mov [bx],al
1265 ifdef LONG_FILENAME
1266 stc
1267 mov ax,713Bh ; chdir long filename (ds:dx)
1268 int 21h
1269 jnc @@chdirdone
1270 endif
1271 mov ah,3Bh ; chdir(ds:dx)
1272 int 21h
1273 @@chdirdone:
1274 pop [word bx]
1275 @@end:
1276 ret
1278 endp @chdirname$qpzc
1281 ;***************************************************************
1282 ;_fastcall char *ultoa(axdx:unsigned long n);
1283 ;***************************************************************
1284 global @ultoa$qul:near
1285 proc @ultoa$qul near
1287 xchg ax,cx
1288 xchg ax,dx ; AX:CX = n
1289 push si
1290 mov si,10
1291 mov bx,offset ultoabuf+11
1292 @@loop:
1293 dec bx
1294 xor dx,dx
1295 div si ; DX:AX = 0000:hi(n)
1296 xchg ax,cx ; CX = hi(n)/10
1297 div si ; DX:AX = hi(n)%10:lo(n)
1298 xchg ax,cx ; CX = lo(n/10)
1299 ; AX = hi(n)/10 = hi(n/10)
1300 mov [byte bx],'0'
1301 add [bx],dl ; DL = n%10
1302 mov dx,ax
1303 or dx,cx
1304 jnz @@loop
1305 xchg ax,bx
1306 pop si
1307 ret
1309 endp @ultoa$qul
1312 ;***************************************************************
1313 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1314 ;***************************************************************
1315 global @kver2ul$qpzc:near
1316 proc @kver2ul$qpzc near
1318 push si
1319 mov si,bx
1320 xor bx,bx
1321 mov cx,304h
1322 @@number:
1323 xor ax,ax
1324 cwd
1325 @@digit:
1326 shl al,cl
1327 shl ax,cl
1328 lodsb
1329 sub al,30h
1330 cmp al,9
1331 jbe @@digit
1332 mov dl,bh
1333 mov bh,bl
1334 mov bl,ah
1335 dec ch
1336 jnz @@number
1337 xchg ax,bx
1338 pop si
1339 kver2ulret:
1340 ret
1342 endp @kver2ul$qpzc
1344 endif
1346 ;***************************************************************
1347 ;void try_default_args();
1348 ;***************************************************************
1349 ifdef EXTRA
1351 global _try_default_args:near
1352 proc _try_default_args near
1354 mov bx,offset tazboot_cmd
1355 call open
1356 jc kver2ulret
1357 mov cx,4096
1358 mov di,[_heap_top]
1359 extrn read_cmdline:near
1360 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1362 endp _try_default_args
1364 endif
1366 ends _TEXT
1368 end
1370 ;###### END OF FILE ############################################