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

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