wok-current view linld/stuff/src/CRTL.ASM @ rev 20634
linld: fix open()
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jan 08 17:51:51 2019 +0100 (2019-01-08) |
parents | ab907169f156 |
children | cbcb33ee9044 |
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
184 ;***************************************************************
185 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
186 ;***************************************************************
187 global openargs:near ; openargs(bx)
188 openargs:
189 cmp [byte bx],'@'
190 stc
191 jne fail
192 inc bx
194 global @open$qpxzc:near
195 proc @open$qpxzc near
197 global open:near ; open(bx)
198 open:
199 ifdef LONG_FILENAME
200 mov ax,716Ch
201 push bx di si
202 mov si,bx
203 xor bx,bx ; R/O
204 xor cx,cx ; attributes
205 xor di,di ; alias hint
206 cwd ; action = open
207 stc
208 int 21h
209 pop si di bx
210 jnc doret
211 endif
212 mov ax,3d00h ; read-only+compatibility
213 ;mov cl,0 ; attribute mask
214 mov dx,bx
215 dos:
216 int 21h
217 chkc:
218 jnc doret
219 fail:
220 sbb ax,ax ; ax=-1 CF
221 cwd
222 doret:
223 ifndef NO386
224 push dx ; see next_chunk:lseek
225 push ax
226 pop eax
227 endif
228 ret
230 endp @open$qpxzc
233 ;***************************************************************
234 ;_fastcall int fileexist(bx:const char* name);
235 ;***************************************************************
236 global @fileexist$qpxzc:near
237 @fileexist$qpxzc:
238 call @open$qpxzc
239 jc fail
241 ;***************************************************************
242 ;_fastcall int close(ax:int fd);
243 ;***************************************************************
244 global @close$qi:near
245 proc @close$qi near
247 global close:near ; close(ax)
248 close:
249 xchg ax,bx
250 mov ah,3Eh
251 or bx,bx
252 jnz dos
253 ret
255 endp @close$qi
258 ;***************************************************************
259 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
260 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
261 ;***************************************************************
262 global @read$qipvi:near
263 proc @read$qipvi near
265 ifdef WRITE
266 stc
267 db 0B0h ; mov al,im
268 global @write$qipvi:near
269 @write$qipvi:
270 clc
271 endif
272 @read$dxbxax:
273 xchg ax,bx ; fd
274 xchg ax,dx ; data
275 xchg ax,cx ; sz
276 ifdef WRITE
277 mov ah,40h
278 sbb ah,0
279 else
280 global @read$cxdxbx:near
281 @read$cxdxbx:
282 mov ah,3Fh
283 endif
284 jcxz fail
285 jmp dos
287 endp @read$qipvi
289 ;***************************************************************
290 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
291 ;***************************************************************
293 global @lseekcur$qii:near ; fd=ax whence=dx
294 proc @lseekcur$qii near
296 mov cl,1
297 xchg ax,bx
298 xchg ax,dx
299 cwd
300 xchg ax,dx
301 xchg ax,cx
302 jmp lseek
303 rewind: ; rewind(ax)
304 mov bl,0
305 lseek0: ; lseek0(ax,bl=dir)
306 xor dx,dx
307 xor cx,cx
308 lseekset:
309 xchg ax,bx
310 lseek:
311 mov ah,42h ; bx=fd cx:dx=offset al=whence
312 jmp dos
314 endp @lseekcur$qii
316 ifdef EXTRA
318 ;typedef unsigned dirsizetype;
319 struc isostate ; struct isostate {
320 fd dw ? ; 0 int fd;
321 filemod dw ? ; 2 unsigned short filemod;
322 fileofs dd ? ; 4 unsigned long fileofs;
323 filesize dd ? ; 8 unsigned long filesize;
324 filename dw ? ;12 char *filename;
325 curdirsize dw ? ;14 dirsizetype curdirsize;
326 dirsize dw ? ;16 dirsizetype dirsize;
327 curdirofs dd ? ;18 unsigned long curdirofs;
328 dirofs dd ? ;22 unsigned long dirofs;
329 curpos dw ? ;26 unsigned curpos;
330 buffer db 2560 dup(?) ;28 char buffer[2048+512];
331 ends ; } isostate;
332 ;***************************************************************
333 ;_fastcall long isolseek(bx:const unsigned long *offset);
334 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
335 ;***************************************************************
336 global @isolseek$qpxul:near
337 proc @isolseek$qpxul near
339 isolseek:
340 extrn _isostate:isostate
341 mov ax,[_isostate.fd]
342 global @lseekset2$qipul:near
343 @lseekset2$qipul:
344 mov dx,[bx]
345 mov cx,[bx+2]
346 mov bl,0
347 jmp lseekset
349 endp @isolseek$qpxul
351 ;***************************************************************
352 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
353 ;***************************************************************
354 global @isoreadsector$qpxul:near
355 proc @isoreadsector$qpxul near
357 call isolseek
358 jc doret
359 mov dx,2560
360 mov bx,offset _isostate.buffer
361 mov ax,[_isostate.fd]
362 jmp @read$dxbxax ; read(fd,buffer,2560)
364 endp @isoreadsector$qpxul
366 endif
369 ;***************************************************************
370 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
371 ;***************************************************************
372 global @strhead$qpxzct1:near
373 proc @strhead$qpxzct1 near
375 @@loop:
376 xchg ax,bx
377 mov cl,[bx] ; cl = *b++
378 inc bx
379 or cl,cl ; clear C
380 jz fail ; return 0
381 xchg ax,bx
382 xor cl,[bx] ; cl -= *a++
383 inc bx
384 and cl,0dfh ; case insensitive
385 jz @@loop
386 ret ; return b (is not 0)
388 endp @strhead$qpxzct1
391 ;***************************************************************
392 ;_fastcall char* malloc_or_die(ax:unsigned size);
393 ;***************************************************************
394 global @malloc_or_die$qui:near
395 proc @malloc_or_die$qui near
397 xchg ax,cx ; size
398 global malloc_or_die:near ; malloc_or_die(cx)
399 malloc_or_die:
400 mov ax,[_heap_top] ; return value
401 mov bx,sp
402 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
403 sub bx,ax ; can't overflow
404 cmp bx,cx
405 mov bx,offset msg_malloc
406 jb die
407 add [_heap_top],cx ; _BEG has zero'd heap
408 ret
410 endp @malloc_or_die$qui
413 ;***************************************************************
414 ;_fastcall int die(bx:const char* msg);
415 ;int exit();
416 ;int abort();
417 ;***************************************************************
418 global @die$qpxzc:near
419 proc @die$qpxzc near
420 @die$qpxzc:
421 global die:near ; die(bx)
422 die:
423 call puts
424 ; global _exit:near
425 _exit:
426 mov al,[_no_exit]
427 or al,al
428 jne @@hang
429 extrn exit:near
430 inc ax
431 jmp near exit
432 @@hang:
433 mov bx, offset msg_hang
434 call puts
435 ; global _abort:near
436 _abort:
437 cli
438 @@stop:
439 hlt
440 jmp @@stop
442 endp @die$qpxzc
444 struc image_himem ;struct image_himem {
445 fd dw ? ; 0 int fd;
446 fallback dd ? ; 2 u32 fallback;
447 size dd ? ; 6 u32 size;
448 remaining dd ? ;10 u32 remaining;
449 buf dd ? ;14 u32 buf;
450 bufv dw ? ;18 u32 *bufv;
451 errmsg dw ? ;20 char *errmsg;
452 chunk_size dd ? ;22 u32 chunk_size;
453 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
454 state dw ? ;28 u16 state;
455 fd2close dw ? ;30 u16 fd2close;
456 ends ;};
458 ;***************************************************************
459 ;static long next_chunk(struct image_himem *di);
460 ;***************************************************************
461 proc next_chunk near
463 push si
464 mov ax,[(image_himem di).fd]
465 call close
466 ifndef NO386
467 xor eax,eax
468 else
469 xor ax,ax
470 cwd
471 endif
472 mov [(image_himem di).fd],ax
473 mov bx,[(image_himem di).state]
474 cmp al,[bx] ; ""
475 jz @@end
476 mov si,bx
477 @@scan:
478 lodsb
479 mov cx,si
480 cmp al,','
481 jz @@eos
482 or al,al
483 jnz @@scan
484 dec cx
485 @@eos:
486 mov [(image_himem di).state],cx
487 dec si
488 push [word si]
489 mov [byte si],ah ; set temp eos
490 call open
491 pop [word si] ; restore string
492 jc @@die
493 mov [(image_himem di).fd],ax
494 mov [(image_himem di).fd2close],ax
495 mov bl,02h ; SEEK_END
496 call lseek0
497 @@die:
498 mov bx,[(image_himem di).errmsg]
499 jc die
500 ifndef NO386
501 push eax
502 mov ax,[(image_himem di).fd]
503 call rewind
504 pop eax
505 @@end:
506 mov [(image_himem di).chunk_size],eax
507 else
508 push ax
509 push dx
510 mov ax,[(image_himem di).fd]
511 call rewind
512 pop dx
513 pop ax
514 @@end:
515 mov [word (image_himem di).chunk_size],ax
516 mov [word ((image_himem di).chunk_size)+2],dx
517 endif
518 pop si
519 ret
521 endp next_chunk
524 ifdef LARGE_IMAGES
525 struc data_himem ;struct data_himem {
526 first dd ? ; 0 u32 first;
527 cacheidx dw ? ; 4 int cacheidx;
528 pageidx dw ? ; 6 int pageidx;
529 cache dd 1024 dup(?) ; 8 int cache;
530 page dd 1024 dup(?) ;4104 int page;
531 ends ;}; // size=8200
532 endif
534 ;***************************************************************
535 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
536 ;***************************************************************
537 global @malloc_bufv_or_die$qp11image_himem:near
538 proc @malloc_bufv_or_die$qp11image_himem near
540 p386
541 push si
542 mov si,bx
543 ifdef LARGE_IMAGES
544 movzx ecx,[word ((image_himem si).size) + 2]
545 shr cx,4 ; pages index size = size >> 20
546 add cx,8+4096+8
547 call malloc_or_die
548 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
549 add ecx,[(image_himem si).size]
550 shr ecx,12
551 mov [curdata],ax
552 else
553 mov ecx,[(image_himem si).size]
554 dec ecx
555 shr ecx,12
556 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
557 push cx
558 inc cx ; cnt+1
559 shl cx,2 ; bufv => vcpi => vm86
560 ; our malloc zeroes allocated mem: bufv[cnt]=0;
561 ; Allocate pages, storing addrs in addrbuf
562 call malloc_or_die
563 pop cx
564 push ax
565 endif
566 mov [(image_himem si).bufv],ax
567 xchg ax,si
568 @@vcpi_alloc:
569 xor edx,edx
570 mov ax,0DE04h
571 int 67h
572 or ah,ah
573 mov bx,offset vcpi_alloc_err
574 jnz die
575 ; for (i = cnt-1; i >= 0; i--)
576 ifdef LARGE_IMAGES
577 mov eax,ecx
578 dec eax
579 else
580 mov ax,cx
581 dec ax
582 cwde
583 endif
584 shl eax,12 ; i*_4k
585 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
586 extrn _imgs
587 mov bx,offset _imgs+2
588 push eax
589 add eax,[bx-2+2]
590 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
591 pop eax ; i*_4k
592 jbe @@pmok
593 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
594 jae @@vcpi_alloc
595 @@pmok:
596 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
597 extrn _imgs
598 mov bx,offset _imgs+32+2
599 add eax,[bx-2+2] ; +initrd.fallback
600 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
601 ja @@initrdok
602 mov eax,[bx-2+6] ; initrd.size
603 add eax,[bx-2+2] ; +initrd.fallback
604 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
605 @@jnc_vcpi_alloc:
606 ja @@vcpi_alloc
607 @@initrdok:
608 ifdef LARGE_IMAGES
609 cmp [(data_himem si).first],0
610 jne @@notfirst
611 mov [(data_himem si).first],edx
612 @@notfirst:
613 mov bx,[(data_himem si).cacheidx]
614 cmp bh,4
615 jae @@nextpage
616 shl bx,2
617 inc [(data_himem si).cacheidx]
618 mov [(data_himem bx+si).cache],edx
619 loopd @@vcpi_alloc
620 mov [(data_himem bx+si).cache],ecx ; last is 0
621 @@nextpage:
622 and [(data_himem si).cacheidx],0
623 mov bx,[(data_himem si).pageidx]
624 mov [(data_himem bx+si).page],edx
625 add [(data_himem si).pageidx],4
626 push cx
627 lea cx,[(data_himem si).cache]
628 ifdef NO386
629 push edx
630 pop dx
631 pop ax
632 endif
633 call storepage ; storepage(edx,cx)
634 pop cx
635 or ecx,ecx ; clear C
636 jnz @@jnc_vcpi_alloc
637 mov [dword (data_himem si).cacheidx],ecx
638 xchg ax,si
639 else
640 mov [si],edx
641 lodsd ; si=+4
642 loop @@vcpi_alloc
643 pop ax
644 endif
645 pop si
646 ret
647 ifdef NO386
648 p8086
649 endif
651 endp @malloc_bufv_or_die$qp11image_himem
654 ;***************************************************************
655 ;_fastcall void memcpy_image(bx:struct image_himem *m);
656 ;***************************************************************
657 global @memcpy_image$qp11image_himem:near
658 proc @memcpy_image$qp11image_himem near
660 ifndef NO386
661 mov edx,[(image_himem bx).fallback]
662 mov eax,[(image_himem bx).buf]
663 cmp eax,edx ; if (m->fallback != m->buf)
664 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
665 ifdef LARGE_IMAGES
666 mov ecx,[(image_himem bx).size]
667 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
668 push ecx
669 else
670 push [(image_himem bx).size]
671 endif
672 push eax
673 push 0
674 call_memcpy32:
675 push edx
676 else
677 mov ax,[word ((image_himem bx).fallback)]
678 mov dx,[word ((image_himem bx).fallback)+2]
679 mov cx,[word ((image_himem bx).buf)]
680 cmp ax,cx ; if (m->fallback != m->buf)
681 jnz @@do
682 cmp dx,[word ((image_himem bx).buf)+2]
683 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
684 @@do:
685 push [word ((image_himem bx).size)+2]
686 push [word ((image_himem bx).size)]
687 push [word ((image_himem bx).buf)+2]
688 push cx
689 xor cx,cx
690 push cx
691 call_memcpy32:
692 push dx
693 push ax
694 ifdef LARGE_IMAGES
695 jmp @@memcpy
696 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
697 p386
698 push ecx
699 push eax
700 push 0
701 push edx
702 ifdef NO386
703 p8086
704 endif
705 endif
706 endif
707 @@memcpy:
708 extrn memcpy32:near
709 call near memcpy32
710 @@skip:
711 ret
713 endp @memcpy_image$qp11image_himem
715 ;***************************************************************
716 ;_fastcall void storepage(bx:u32 *dst);
717 ;***************************************************************
718 global @storepage$qpul:near
719 proc @storepage$qpul near
721 ifndef NO386
722 mov edx,[bx]
723 else
724 mov ax,[bx]
725 mov dx,[bx+2]
726 endif
727 mov cx,offset _xfer_buf
728 storepage: ; storepage(edx,cx)
729 ifndef NO386
730 push 0
731 push 4096
732 push 0
733 else
734 xor bx,bx
735 push bx
736 mov bh,4096/256
737 push bx
738 xor bx,bx
739 push bx
740 endif
741 push cx
742 push ds
743 jmp call_memcpy32
745 endp @storepage$qpul
748 ifdef LARGE_IMAGES
749 p386
750 ;***************************************************************
751 ;_fastcall void reset_bufv(bx:u32 *p);
752 ;***************************************************************
753 global @reset_bufv$qpul:near
754 proc @reset_bufv$qpul near
756 mov [curdata],bx
757 and [dword (data_himem bx).cacheidx],0
758 ret
760 endp @reset_bufv$qpul
762 ;***************************************************************
763 ;u32* prev_bufv();
764 ;u32* prev_bufv();
765 ;***************************************************************
766 global _prev_bufv:near
767 global _next_bufv:near
768 proc _prev_bufv near
770 stc
771 db 73h ; jnc
772 _next_bufv:
773 clc
774 push si
775 mov si,[curdata]
776 sbb ax,ax
777 cmc
778 adc ax,[(data_himem si).cacheidx] ; -1/+1
779 xor ecx,ecx
780 test ax,0fc00h
781 jz @@gotpage
782 push ax ; FFFF / 0400
783 sar ax,8 ; FFFC / 0004
784 and al,0fch
785 add [(data_himem si).pageidx],ax
786 mov bx,[(data_himem si).pageidx]
787 lea bx,[(data_himem bx+si).page]
788 mov edx,ds
789 shl edx,4
790 lea cx,[(data_himem si).cache]
791 add edx,ecx
792 mov eax,[bx]
793 or eax,eax
794 jnz @@pageok
795 pop ax
796 xchg ax,bx
797 pop si
798 ret
799 @@pageok:
800 mov cx,4096
801 call memcpy_imagez ; get page
802 pop ax ; FFFF / 0400
803 cbw
804 shr ax,6 ; 03FF / 0000
805 @@gotpage:
806 mov [(data_himem si).cacheidx],ax
807 shl ax,2
808 xchg ax,bx
809 lea ax,[(data_himem bx+si).cache]
810 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
811 jnz @@notfirst2
812 xchg ax,si ; &first
813 @@notfirst2:
814 pop si
815 ret
817 endp _prev_bufv
818 endif
820 ifdef NO386
821 p8086
822 endif
824 ;***************************************************************
825 ;_fastcall void open_image(bx:const char *name, ax:struct image_himem *m);
826 ;***************************************************************
827 global @open_image$qpxzcp11image_himem:near
828 proc @open_image$qpxzcp11image_himem near
830 push di
831 xchg ax,di
832 ifdef EXTRA
833 cmp [(image_himem di).fd],0 ; iso image/kernel ?
834 jnz @@alreadydone
835 endif
836 mov [(image_himem di).state],bx
837 push bx
838 ifdef EXTRA
839 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
840 jnz @@next
841 endif
842 mov [(image_himem di).next_chunk],offset next_chunk
843 @@next:
844 call [(image_himem di).next_chunk] ; m->next_chunk()
845 ifndef NO386
846 add eax,3
847 and al,0FCh
848 add [(image_himem di).size],eax ; m->size += m->chunk_size
849 or eax,eax
850 else
851 add ax,3
852 adc dx,0
853 and al,0FCh
854 add [word (image_himem di).size],ax ; m->size += m->chunk_size
855 adc [word ((image_himem di).size)+2],dx
856 or ax,dx
857 endif
858 jnz @@next
859 pop [(image_himem di).state]
860 call [(image_himem di).next_chunk] ; m->next_chunk()
861 @@alreadydone:
862 pop di
863 ret
865 endp @open_image$qpxzcp11image_himem
868 ;***************************************************************
869 ;_fastcall int read_image(bx:struct image_himem *m);
870 ;***************************************************************
871 global @read_image$qp11image_himem:near
872 proc @read_image$qp11image_himem near
874 push si di
875 mov di,bx
876 mov si,4096
877 push si ; original size
878 @@loop:
879 ifndef NO386
880 movzx ecx,si
881 mov eax,[(image_himem di).chunk_size]
882 cmp ecx,eax
883 jb @@szok
884 else
885 mov cx,si
886 mov ax,[word (image_himem di).chunk_size]
887 cmp cx,ax
888 jb @@szok
889 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
890 jne @@szok
891 endif
892 xchg ax,cx
893 @@szok:
894 jcxz image_done
895 mov dx,offset _xfer_buf
896 mov bx,[di]
897 call @read$cxdxbx
898 jc image_done
899 xor cx,cx
900 cwd ; ax < 8000h
901 ifndef NO386
902 cwde ; ax < 8000h
903 sub [(image_himem di).chunk_size],eax
904 xchg eax,ebx
905 else
906 sub [word (image_himem di).chunk_size],ax
907 xchg ax,bx
908 sbb [word ((image_himem di).chunk_size)+2],dx
909 jnz @@fill
910 cmp [word (image_himem di).chunk_size],dx
911 endif
912 jnz @@fill
913 dec cx
914 @@fill:
915 test bl,3
916 je @@filled
917 mov [bx+_xfer_buf],dh
918 inc bx
919 jmp @@fill
920 @@filled:
921 ifndef NO386
922 sub [(image_himem di).remaining],ebx
923 else
924 sub [word (image_himem di).remaining],bx
925 sbb [word ((image_himem di).remaining)+2],dx
926 endif
927 sub si,bx
928 pushf
929 and cx,[(image_himem di).next_chunk]
930 jcxz @@same_chunk
931 call cx
932 @@same_chunk:
933 popf
934 jnz @@loop
935 image_done:
936 pop ax ; original size
937 sub ax,si
938 pop di si
939 ret
941 endp @read_image$qp11image_himem
944 ;***************************************************************
945 ;pascal unsigned long strtol(const char *s);
946 ;***************************************************************
947 global @strtol$qpxzc:near
948 proc @strtol$qpxzc near
950 pop ax
951 pop bx ; s
952 push ax
953 ifndef NO386
954 xor ebx,ebx
955 push si
956 jcxz @@end
957 mov si,cx
958 xor ecx,ecx
959 xor eax,eax
960 lodsb
961 mov dx,ax
962 or al,20h
963 cmp al,'n' ; vga=normal
964 je @@vga
965 dec cx
966 cmp al,'e' ; vga=extended
967 je @@vga
968 dec cx
969 cmp al,'a' ; vga=ask
970 jne @@notvga
971 @@vga:
972 dec cx
973 xchg ax,cx
974 cwd
975 jmp @@popsiret
976 @@notvga:
977 mov cx,10 ; radix
978 xchg ax,dx
979 cmp al,'+'
980 je @@radixskip
981 cmp al,'-'
982 clc
983 jne @@radixkeep
984 stc
985 @@radixskip:
986 lodsb
987 @@radixkeep:
988 pushf
989 cmp al,'0'
990 jne @@radixok
991 mov cl,8
992 lodsb
993 or al,20h
994 cmp al,'x'
995 jne @@radixok
996 mov cl,16
997 @@strtollp:
998 lodsb
999 @@radixok:
1000 or al,20h
1001 sub al,'0'
1002 jb @@endstrtol
1003 cmp al,9
1004 jbe @@digitok
1005 cmp al,'a'-'0'
1006 jb @@endstrtol
1007 sub al,'a'-'0'-10
1008 @@digitok:
1009 cmp al,cl
1010 jae @@endstrtol
1011 xchg eax,ebx
1012 mul ecx
1013 add eax,ebx
1014 xchg eax,ebx
1015 jmp @@strtollp
1016 @@endstrtol:
1017 mov cl,10
1018 cmp al,'k'-'a'+10
1019 je @@shift
1020 mov cl,20
1021 cmp al,'m'-'a'+10
1022 je @@shift
1023 mov cl,30
1024 cmp al,'g'-'a'+10
1025 jne @@noshift
1026 @@shift:
1027 shl ebx,cl
1028 @@noshift:
1029 popf
1030 jnc @@end
1031 neg ebx
1032 @@end:
1033 push ebx
1034 pop ax
1035 pop dx
1036 @@popsiret:
1037 pop si
1038 else
1039 push si
1040 push di
1041 xor ax,ax
1042 cwd
1043 jcxz @@goend
1044 xchg ax,di
1045 mov si,cx
1046 lodsb
1047 mov bx,ax
1048 or al,20h
1049 mov cx,-1
1050 cmp al,'n' ; vga=normal
1051 je @@vga
1052 dec cx
1053 cmp al,'e' ; vga=extended
1054 je @@vga
1055 dec cx
1056 cmp al,'a' ; vga=ask
1057 jne @@notvga
1058 @@vga:
1059 xchg ax,cx
1060 @@goend:
1061 jmp @@popdisiret
1062 @@notvga:
1063 mov cx,10 ; radix
1064 xchg ax,bx
1065 cmp al,'+'
1066 je @@radixskip
1067 cmp al,'-'
1068 clc
1069 jne @@radixkeep
1070 stc
1071 @@radixskip:
1072 lodsb
1073 @@radixkeep:
1074 pushf
1075 cmp al,'0'
1076 jne @@radixok
1077 mov cl,8
1078 lodsb
1079 or al,20h
1080 cmp al,'x'
1081 jne @@radixok
1082 mov cl,16
1083 @@strtollp:
1084 lodsb
1085 @@radixok:
1086 or al,20h
1087 sub al,'0'
1088 jb @@endstrtol
1089 cmp al,9
1090 jbe @@digitok
1091 cmp al,'a'-'0'
1092 jb @@endstrtol
1093 sub al,'a'-'0'-10
1094 @@digitok:
1095 cmp al,cl
1096 jae @@endstrtol
1098 push ax
1099 push si
1100 push dx
1101 xchg ax,di
1102 mul cx
1103 xchg ax,di
1104 xchg ax,dx
1105 xchg ax,si
1106 pop ax
1107 mul cx
1108 add ax,si
1109 pop si
1110 xchg ax,dx
1111 pop ax
1112 mov ah,0
1113 add di,ax
1114 adc dx,0
1116 jmp @@strtollp
1117 @@endstrtol:
1118 mov cl,10
1119 cmp al,'k'-'a'+10
1120 je @@shift
1121 mov cl,20
1122 cmp al,'m'-'a'+10
1123 je @@shift
1124 mov cl,30
1125 cmp al,'g'-'a'+10
1126 jne @@noshift
1127 @@shift:
1128 rcl di,1
1129 shl dx,1
1130 loop @@shift
1131 @@noshift:
1132 popf
1133 jnc @@end
1134 not dx
1135 neg di
1136 jne @@end
1137 inc dx
1138 @@end:
1139 xchg ax,di
1140 @@popdisiret:
1141 pop di
1142 pop si
1143 endif
1144 strtol_ret:
1145 ret
1147 endp @strtol$qpxzc
1150 ifdef NO386
1151 ;***************************************************************
1152 ;u16 topseg();
1153 ;***************************************************************
1154 global _topseg:near
1155 proc _topseg near
1157 int 12h
1158 jnc @@max640k
1159 mov ax,640 ; 9000
1160 @@max640k:
1161 dec ax
1162 and al,0C0h
1163 mov cl,6
1164 shl ax,cl
1165 ret
1167 endp _topseg
1168 endif
1170 ifdef EXTRA
1171 p8086
1172 ;***************************************************************
1173 ;char *progname(void)
1174 ;***************************************************************
1175 global _progname:near
1176 proc _progname near
1178 push si di es
1179 mov ah,30h
1180 int 21h
1181 xor di,di
1182 cmp al,3
1183 mov ax,di
1184 jb @@skip
1185 ;mov es,[cs:2Ch]
1186 mov es,[di+2Ch]
1187 mov cx,sp ; big enough
1188 @@loop:
1189 repne
1190 scasb
1191 scasb
1192 jne @@loop
1193 inc di
1194 inc di
1195 mov si,di ; progname @es:di
1196 repne
1197 scasb
1198 mov cx,di
1199 sub cx,si ; progname len
1200 call malloc_or_die ; keep cx
1201 mov di,ax
1202 push ds
1203 push es
1204 pop ds
1205 pop es
1206 rep
1207 movsb
1208 push es
1209 pop ds
1210 @@skip:
1211 pop es di si
1212 ret
1214 endp _progname
1217 ;***************************************************************
1218 ;_fastcall void chdirname(bx:char *path)
1219 ;***************************************************************
1220 global @chdirname$qpzc:near
1221 proc @chdirname$qpzc near
1223 cmp [byte bx+1],3Ah ; ':'
1224 jne @@nodisk
1225 mov dl,20h
1226 or dl,[bx]
1227 sub dl,61h
1228 mov ah,0Eh
1229 int 21h
1230 inc bx
1231 inc bx
1232 @@nodisk:
1233 xor cx,cx
1234 @@next:
1235 mov al,[bx]
1236 cmp al,5Ch
1237 jne @@tsteos
1238 mov dx,bx
1239 inc cx
1240 @@tsteos:
1241 inc bx
1242 or al,al
1243 jnz @@next
1244 jcxz @@end
1245 mov bx,dx
1246 push [word bx]
1247 mov [bx],al
1248 ifdef LONG_FILENAME
1249 stc
1250 mov ax,713Bh ; chdir long filename (ds:dx)
1251 int 21h
1252 jnc @@chdirdone
1253 endif
1254 mov ah,3Bh ; chdir(ds:dx)
1255 int 21h
1256 @@chdirdone:
1257 pop [word bx]
1258 @@end:
1259 ret
1261 endp @chdirname$qpzc
1264 ;***************************************************************
1265 ;_fastcall char *ultoa(axdx:unsigned long n);
1266 ;***************************************************************
1267 global @ultoa$qul:near
1268 proc @ultoa$qul near
1270 xchg ax,cx
1271 xchg ax,dx ; AX:CX = n
1272 push si
1273 mov si,10
1274 mov bx,offset ultoabuf+11
1275 @@loop:
1276 dec bx
1277 xor dx,dx
1278 div si ; DX:AX = 0000:hi(n)
1279 xchg ax,cx ; CX = hi(n)/10
1280 div si ; DX:AX = hi(n)%10:lo(n)
1281 xchg ax,cx ; CX = lo(n/10)
1282 ; AX = hi(n)/10 = hi(n/10)
1283 mov [byte bx],'0'
1284 add [bx],dl ; DL = n%10
1285 mov dx,ax
1286 or dx,cx
1287 jnz @@loop
1288 xchg ax,bx
1289 pop si
1290 ret
1292 endp @ultoa$qul
1295 ;***************************************************************
1296 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1297 ;***************************************************************
1298 global @kver2ul$qpzc:near
1299 proc @kver2ul$qpzc near
1301 push si
1302 mov si,bx
1303 xor bx,bx
1304 mov cx,304h
1305 @@number:
1306 xor ax,ax
1307 cwd
1308 @@digit:
1309 shl al,cl
1310 shl ax,cl
1311 lodsb
1312 sub al,30h
1313 cmp al,9
1314 jbe @@digit
1315 mov dl,bh
1316 mov bh,bl
1317 mov bl,ah
1318 dec ch
1319 jnz @@number
1320 xchg ax,bx
1321 pop si
1322 kver2ulret:
1323 ret
1325 endp @kver2ul$qpzc
1327 endif
1329 ;***************************************************************
1330 ;void try_default_args();
1331 ;***************************************************************
1332 ifdef EXTRA
1334 global _try_default_args:near
1335 proc _try_default_args near
1337 mov bx,offset tazboot_cmd
1338 call open
1339 jc kver2ulret
1340 mov cx,4096
1341 mov di,[_heap_top]
1342 extrn read_cmdline:near
1343 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1345 endp _try_default_args
1347 endif
1349 ends _TEXT
1351 end
1353 ;###### END OF FILE ############################################