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

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