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

linld: fix argstr
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 23 18:02:24 2020 +0000 (7 weeks ago)
parents 72e35f3c7aa1
children d70f7cc6e3ac
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT,_DATA,_BSS
16 assume cs:DGROUP,ds:DGROUP
18 segment _DATA byte public use16 'DATA'
20 msg_hang db "High mem corrupted",0
21 vcpi_alloc_err db "VCPI"
22 global overflow:byte
23 overflow db "/"
24 msg_malloc db "Out of memory",0
25 ifdef EXTRA
26 tazboot_cmd db "tazboot.cmd",0
27 endif
29 ends _DATA
31 segment _BSS byte public use16 'BSS'
33 ifdef EXTRA
34 include "isostate.inc"
35 public _isostate
36 _isostate isostate <?>
37 org $-7
38 endif
39 _xfer_buf db 4096 dup (?)
40 filecnt db ? ; in fact 0 minus file count...
41 nextfilename dw ?
42 ifdef EXTRA
43 utoabuf db 6 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 ifdef EXTRA
56 global @strcat$qpxzct1:near
57 @strcat$qpxzct1:
58 mov cx,1h
59 db 0bah ; mov dx,imm opcode
60 endif
61 global @strcatb$qpxzct1:near
62 proc @strcatb$qpxzct1 near
64 mov cl,7Fh
65 db 0bah ; mov dx,imm opcode
66 global @strcpy$qpxzct1:near
67 @strcpy$qpxzct1:
68 xor cx,cx
69 push si
70 xchg ax,si ; b
71 jcxz @@nocat
72 dec bx
73 @@catlp:
74 inc bx
75 cmp [byte bx],0 ; a=bx
76 jne @@catlp
77 ifdef EXTRA
78 mov al,20h
79 loop @@cpyhead
80 else
81 db 0b8h,20h ; mov ax,??20h
82 endif
83 @@nocat:
84 @@cpylp:
85 lodsb
86 @@cpyhead:
87 mov [bx],al
88 inc bx
89 or al,al
90 jne @@cpylp
91 strfound:
92 xchg ax,dx
93 strend:
94 pop si
95 global @ret:near
96 @ret:
97 ret
99 endp @strcatb$qpxzct1
102 ifdef EXTRA
103 p8086
104 ;***************************************************************
105 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
106 ;***************************************************************
107 global @strstr$qpxzct1:near
108 proc @strstr$qpxzct1 near
110 xchg ax,cx ; b
111 mov dx,bx ; a
112 push si
113 @@loop:
114 xor ax,ax
115 mov si,dx
116 cmp [si],al ; *a
117 jz strend ; return ax = NULL
118 mov bx,cx
119 @@match:
120 or ah,[bx] ; *b
121 jz strfound
122 inc bx
123 lodsb
124 sub ah,al
125 jz @@match
126 inc dx
127 jmp @@loop
129 endp @strstr$qpxzct1
132 ;***************************************************************
133 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
134 ;***************************************************************
135 global @strcmp$qpxzct1:near
136 proc @strcmp$qpxzct1 near
138 push si
139 xchg ax,si
140 dec bx
141 @@lp:
142 inc bx
143 lodsb
144 sub al,[bx]
145 jnz @@out
146 or al,[bx]
147 jnz @@lp
148 @@out:
149 cbw
150 pop si
151 ret
153 endp @strcmp$qpxzct1
154 endif
157 ;***************************************************************
158 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
159 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
160 ;***************************************************************
161 global openargs:near ; openargs(bx)
162 openargs:
163 cmp [byte bx],'@'
164 jne fail
165 inc bx
167 global @open$qpxzc:near
168 proc @open$qpxzc near
170 open: ; open(bx)
171 ifdef ISOHOOK
172 extrn iso_open_hack:word
173 call [iso_open_hack] ; or ret
174 endif
175 ifdef LONG_FILENAME
176 mov ax,716Ch
177 push bx si
178 mov si,bx
179 xor bx,bx ; R/O
180 xor cx,cx ; attributes
181 cwd ; action = open
182 stc
183 int 21h
184 pop si bx
185 jnc doret
186 endif
187 mov ax,3d00h ; read-only+compatibility
188 ;mov cl,0 ; attribute mask
189 mov dx,bx
190 jmp dos
192 endp @open$qpxzc
195 ;***************************************************************
196 ;_fastcall int fileexist(bx:const char* name);
197 ;***************************************************************
198 global @fileexist$qpxzc:near
199 @fileexist$qpxzc:
200 call @open$qpxzc
201 jc fail
203 ;***************************************************************
204 ;_fastcall int close(ax:int fd);
205 ;***************************************************************
206 global @close$qi:near
207 proc @close$qi near
209 global close:near ; close(ax)
210 close:
211 ifdef ISOHOOK
212 extrn iso_close_hack:word
213 call [iso_close_hack] ; or ret
214 endif
215 mov bh,3Eh
216 dosbx:
217 xchg ax,bx
218 or bx,bx
219 jnz dos
220 ret
222 endp @close$qi
225 ;***************************************************************
226 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
227 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
228 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
229 ;***************************************************************
230 global @readrm$qp11image_himemi:near
231 @readrm$qp11image_himemi:
232 xchg ax,dx ; sz
233 mov ax,[bx] ; fd
234 mov bx,[bx-2] ; data
235 global @read$qipvi:near
236 proc @read$qipvi near
238 ifdef WRITE
239 stc
240 db 0B0h ; mov al,im
241 global @write$qipvi:near
242 @write$qipvi:
243 clc
244 endif
245 @read$dxbxax:
246 xchg ax,bx ; fd
247 xchg ax,dx ; data
248 xchg ax,cx ; sz
249 ifdef WRITE
250 mov ah,40h
251 sbb ah,0
252 else
253 global @read$cxdxbx:near
254 @read$cxdxbx:
255 mov ah,3Fh
256 endif
257 ifdef ISOHOOK
258 extrn iso_read_hack:word
259 call [iso_read_hack] ; or ret
260 endif
261 jcxz fail
262 dos:
263 int 21h
264 jnc doret
265 fail:
266 stc
267 failifc:
268 sbb ax,ax ; ax=-1 CF
269 cwd
270 doret:
271 ifndef NO386
272 push dx ; see next_chunk:lseek
273 push ax
274 pop eax
275 endif
276 ret
278 endp @read$qipvi
280 ;***************************************************************
281 ;_fastcall long rewind(ax:int fd);
282 ;***************************************************************
284 global @rewind$qi:near ; fd=ax
285 proc @rewind$qi near
287 ifdef EXTRA ; catch ISO image case
288 stc
289 mov dx,-512 ; curpos = 512, see LOAD.CPP
290 mov bl,1
291 jmp lseekword
292 endif
293 rewind: ; rewind(ax)
294 mov bl,0
295 lseek0: ; lseek0(ax,bl=dir)
296 xor dx,dx ; clear C
297 lseekword:
298 sbb cx,cx
299 lseekset:
300 ifdef ISOHOOK
301 extrn iso_lseek_hack:word
302 call [iso_lseek_hack] ; or ret
303 endif
304 mov bh,42h ; bx=fd cx:dx=offset al=whence
305 jmp dosbx
307 endp @rewind$qi
309 ifdef EXTRA
310 ;***************************************************************
311 ;_fastcall void isolseek(bx:const unsigned long *offset);
312 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* offset);
313 ;***************************************************************
314 global @isolseek$qpxul:near
315 proc @isolseek$qpxul near
317 isolseek:
318 mov ax,[_isostate.fd]
319 global @lseekset2$qipul:near
320 @lseekset2$qipul:
321 les dx,[dword bx]
322 mov cx,es
323 mov bl,0
324 jmp lseekset
326 endp @isolseek$qpxul
328 ;***************************************************************
329 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
330 ;***************************************************************
331 global @isoreadsector$qpxul:near
332 proc @isoreadsector$qpxul near
334 call isolseek
335 jc fail
336 mov dx,2560
337 mov bx,offset _isostate.buffer
338 mov ax,[_isostate.fd]
339 jmp @read$dxbxax ; read(fd,buffer,2560)
341 endp @isoreadsector$qpxul
344 ;***************************************************************
345 ;_fastcall int isoreset(bx:const char *name);
346 ;***************************************************************
347 global @isoreset$qpzc:near
348 proc @isoreset$qpzc near
350 or bx,bx
351 jz fail
352 call near ptr @open$qpxzc
353 mov [_isostate.fd],ax
354 extrn @isoroot$qv:near
355 jmp @isoroot$qv
357 endp @isoreset$qpzc
360 ;***************************************************************
361 ;_fastcall int isoopen(bx:const char *name);
362 ;***************************************************************
363 global @isoopen$qpxzc:near
364 proc @isoopen$qpxzc near
366 extrn @_isoopen$qv:near
367 mov [_isostate.filename2open],bx
368 jmp @_isoopen$qv
370 endp @isoopen$qpxzc
372 endif
375 ifdef USE_ARGSTR
376 ;***************************************************************
377 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
378 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
379 ;***************************************************************
380 global @argstr$qpxzcxt1ppxzc:near
381 proc @argstr$qpxzcxt1ppxzc near
383 mov cl,2
384 db 0a9h ; test ax,#
385 global @argnum$qpzcxpxzcpul:near
386 @argnum$qpzcxpxzcpul:
387 mov cl,4
388 xchg ax,bx ; keywords -> bx
389 xchg ax,cx ; s -> cx
390 cbw ; argstr:0002 argnum:0004
391 xchg ax,dx ; vars -> ax
392 push si di
393 xchg ax,di ; vars => di
394 dec bx
395 @@testalt:
396 sub di,dx
397 @@loop:
398 mov si,cx ; s
399 add di,dx
400 @@match:
401 inc bx ; keywords++
402 lodsb ; *s++
403 or al,20h
404 cmp al,[bx]
405 je @@match
406 cmp al,'/' ; 2f
407 jne @@notopt
408 cmp [byte bx],'-'
409 je @@match
410 @@notopt:
411 ifdef EXTRA
412 cmp [byte bx],'/'
413 jne @@notalt
414 or al,al ; 1st loop ?
415 js @@testalt
416 @@notalt:
417 endif
418 cmp [byte bx],'|'
419 je @@test
420 cmp [byte bx],0
421 je @@test
422 mov al,-1
423 inc bx
424 jmp @@notopt
425 @@test:
426 or al,al ; 1st loop ?
427 jns @@testal
428 cmp [byte bx],0
429 jne @@loop
430 @@testal:
431 cmp al,'='
432 ;je @@found
433 ;cmp al,0 ; eos, si=next argv
434 stc
435 jne @@nokeyword
436 @@found:
437 mov [di],si
438 dec dx
439 dec dx
440 je @@done
441 ;mov bx,si
442 call @strtol$qpxzc
443 mov [di],ax
444 mov [di+2],dx
445 @@done:
446 clc
447 @@nokeyword:
448 sbb ax,ax
449 pop di si
450 ret
452 endp @argstr$qpxzcxt1ppxzc
454 else
456 ;***************************************************************
457 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
458 ;***************************************************************
459 global @strhead$qpxzct1:near
460 proc @strhead$qpxzct1 near
462 @@loop:
463 xchg ax,bx
464 mov cl,[bx] ; cl = *b++
465 inc bx
466 or cl,cl ; clear C
467 jz failifc ; return 0
468 xchg ax,bx
469 xor cl,[bx] ; cl -= *a++
470 inc bx
471 and cl,0dfh ; case insensitive
472 jne fail ; return -1
473 jmp @@loop
475 endp @strhead$qpxzct1
477 endif
479 include "himem.inc"
481 ;***************************************************************
482 ;_fastcall char* malloc_or_die(ax:unsigned size);
483 ;***************************************************************
484 xchg_heap_top:
485 xchg ax,[bx]
486 ret
488 global @malloc_or_die$qui:near
489 proc @malloc_or_die$qui near
491 global malloc_or_die:near ; ax = malloc_or_die(ax)
492 malloc_or_die:
493 extrn _heap_top
494 mov bx,offset _heap_top
495 add ax,[bx]
496 jnc xchg_heap_top
497 mov bx,offset msg_malloc
499 endp @malloc_or_die$qui
502 ;***************************************************************
503 ;_fastcall int die(bx:const char* msg);
504 ;int exit(ax:int status);
505 ;int abort(void);
506 ;***************************************************************
507 global @die$qpxzc:near
508 proc @die$qpxzc near
509 @die$qpxzc:
510 global die:near ; die(bx)
511 die:
512 call puts
513 global @exit$qv:near
514 @exit$qv:
515 _exit:
516 extrn _imgs:image_himem
517 mov cx,[(word _imgs.buf)+2] ; no_exit ?
518 mov ah,4Ch
519 jcxz do_int21h
520 mov bx, offset msg_hang
521 call puts
522 ; global _abort:near
523 _abort:
524 cli
525 hlt
526 jmp _abort
528 endp @die$qpxzc
530 ;***************************************************************
531 ;_fastcall void puts(bx:const char* s):
532 ;***************************************************************
533 global @puts$qpxzc:near
535 ; global puts:near ; puts(bx)
536 @putsz:
537 call @putc
538 @puts$qpxzc:
539 puts:
540 mov dl,[bx]
541 inc bx
542 or dl,dl
543 jne @putsz
544 mov dl,10
545 @putc:
546 cmp dl,10
547 jne @putcz
548 call @putcz2
549 @putcz2:
550 xor dl,7 ; 10^13 1010^1101
551 @putcz:
552 mov ah,2
553 do_int21h:
554 int 21h
555 ret
558 ;***************************************************************
559 ;static long next_chunk(struct image_himem *di);
560 ;***************************************************************
561 proc next_chunk near
563 push si
564 mov ax,[(image_himem di).fd]
565 call close
566 ifndef NO386
567 xor eax,eax
568 else
569 xor ax,ax
570 cwd
571 endif
572 mov [(image_himem di).fd],ax
573 mov bx,[(image_himem di).state]
574 cmp al,[bx] ; ""
575 jz @@end
576 mov si,bx
577 @@scan:
578 lodsb
579 mov cx,si
580 cmp al,','
581 jz @@eos
582 or al,al
583 jnz @@scan
584 dec cx ; blocked to eos
585 @@eos:
586 mov [(image_himem di).state],cx
587 dec si
588 push [word si]
589 mov [byte si],ah ; set temp eos
590 call open
591 pop [word si] ; restore string
592 jc jcdie
593 mov [(image_himem di).fd],ax
594 mov [(image_himem di).fd2close],ax
595 mov bl,02h ; SEEK_END
596 call lseek0
597 jcdie:
598 mov bx,[(image_himem di).errmsg]
599 jc die
600 ifndef NO386
601 push eax
602 mov ax,[(image_himem di).fd]
603 call rewind
604 pop eax
605 @@end:
606 mov [(image_himem di).chunk_size],eax
607 else
608 push ax
609 push dx
610 mov ax,[(image_himem di).fd]
611 call rewind
612 pop dx
613 pop ax
614 @@end:
615 mov [word (image_himem di).chunk_size],ax
616 mov [word ((image_himem di).chunk_size)+2],dx
617 endif
618 pop si
619 ret
621 endp next_chunk
624 ifdef LARGE_IMAGES
625 struc data_himem ;struct data_himem {
626 first dd ? ; 0 u32 first;
627 cacheidx dw ? ; 4 int cacheidx;
628 pageidx dw ? ; 6 int pageidx;
629 cache dd 1024 dup(?) ; 8 int cache;
630 page dd 1024 dup(?) ;4104 int page;
631 ends data_himem ;}; // size=8200
632 endif
634 ;***************************************************************
635 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
636 ;***************************************************************
637 global @malloc_bufv_or_die$qp11image_himem:near
638 proc @malloc_bufv_or_die$qp11image_himem near
640 p386
641 push si
642 mov si,bx
643 ifdef LARGE_IMAGES
644 movzx eax,[word ((image_himem si).size) + 2]
645 shr ax,4 ; pages index size = size >> 20
646 add ax,8+4096+8
647 call malloc_or_die
648 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
649 add ecx,[(image_himem si).size]
650 shr ecx,12
651 mov [curdata],ax
652 else
653 mov eax,[(image_himem si).size]
654 dec eax
655 shr eax,12
656 inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
657 push ax
658 inc ax ; cnt+1
659 shl ax,2 ; bufv => vcpi => vm86
660 ; our malloc zeroes allocated mem: bufv[cnt]=0;
661 ; Allocate pages, storing addrs in addrbuf
662 call malloc_or_die
663 pop cx
664 push ax
665 endif
666 mov [(image_himem si).bufv],ax
667 xchg ax,si
668 @@vcpi_alloc:
669 mov ax,0DE04h
670 int 67h
671 or ah,ah
672 stc
673 mov bx,offset vcpi_alloc_err
674 jnz jcdie
675 ; for (i = cnt-1; i >= 0; i--)
676 ifdef LARGE_IMAGES
677 mov eax,ecx
678 dec eax
679 else
680 mov ax,cx
681 dec ax
682 cwde
683 endif
684 shl eax,12 ; i*_4k
685 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
686 mov bx,offset _imgs.fallback
687 push eax
688 add eax,[bx-2+2]
689 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
690 pop eax ; i*_4k
691 jbe @@pmok
692 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
693 jae @@vcpi_alloc
694 @@pmok:
695 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
696 mov bx,offset _imgs.fallback+32
697 add eax,[bx-2+2] ; +initrd.fallback
698 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
699 ja @@initrdok
700 mov eax,[bx-2+6] ; initrd.size
701 add eax,[bx-2+2] ; +initrd.fallback
702 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
703 @@jnc_vcpi_alloc:
704 ja @@vcpi_alloc
705 @@initrdok:
706 ifdef LARGE_IMAGES
707 cmp [(data_himem si).first],0
708 jne @@notfirst
709 mov [(data_himem si).first],edx
710 @@notfirst:
711 mov bx,[(data_himem si).cacheidx]
712 cmp bh,4
713 jae @@nextpage
714 shl bx,2
715 inc [(data_himem si).cacheidx]
716 mov [(data_himem bx+si).cache],edx
717 loopd @@vcpi_alloc
718 mov [(data_himem bx+si).cache],ecx ; last is 0
719 @@nextpage:
720 and [(data_himem si).cacheidx],0
721 mov bx,[(data_himem si).pageidx]
722 mov [(data_himem bx+si).page],edx
723 add [(data_himem si).pageidx],4
724 push cx
725 lea cx,[(data_himem si).cache]
726 ifdef NO386
727 push edx
728 pop dx
729 pop ax
730 endif
731 call storepage ; storepage(edx,cx)
732 pop cx
733 or ecx,ecx ; clear C
734 jnz @@jnc_vcpi_alloc
735 mov [dword (data_himem si).cacheidx],ecx
736 xchg ax,si
737 else
738 mov [si],edx
739 lodsd ; si=+4
740 loop @@vcpi_alloc
741 pop ax
742 endif
743 pop si
744 ret
745 ifdef NO386
746 p8086
747 endif
749 endp @malloc_bufv_or_die$qp11image_himem
752 ;***************************************************************
753 ;_fastcall void memcpy_image(bx:struct image_himem *m);
754 ;***************************************************************
755 global @memcpy_image$qp11image_himem:near
756 proc @memcpy_image$qp11image_himem near
758 ifndef NO386
759 mov edx,[(image_himem bx).fallback]
760 mov eax,[(image_himem bx).buf]
761 cmp eax,edx ; if (m->fallback != m->buf)
762 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
763 ifdef LARGE_IMAGES
764 mov ecx,[(image_himem bx).size]
765 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
766 push ecx
767 else
768 push [(image_himem bx).size]
769 endif
770 push eax
771 push 0
772 call_memcpy32:
773 push edx
774 else
775 les ax,[dword ((image_himem bx).fallback)]
776 mov dx,es
777 mov cx,[word ((image_himem bx).buf)]
778 cmp ax,cx ; if (m->fallback != m->buf)
779 jnz @@do
780 cmp dx,[word ((image_himem bx).buf)+2]
781 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
782 @@do:
783 push [word ((image_himem bx).size)+2]
784 push [word ((image_himem bx).size)]
785 push [word ((image_himem bx).buf)+2]
786 push cx
787 xor cx,cx
788 push cx
789 call_memcpy32:
790 push dx
791 push ax
792 ifdef LARGE_IMAGES
793 jmp @@memcpy
794 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
795 p386
796 push ecx
797 push eax
798 push 0
799 push edx
800 ifdef NO386
801 p8086
802 endif
803 endif
804 endif
805 @@memcpy:
806 extrn memcpy32:near
807 call near memcpy32
808 @@skip:
809 ret
811 endp @memcpy_image$qp11image_himem
813 ;***************************************************************
814 ;_fastcall void storepage(bx:u32 *dst);
815 ;***************************************************************
816 global @storepage$qpul:near
817 proc @storepage$qpul near
819 ifndef NO386
820 mov edx,[bx]
821 else
822 les ax,[dword bx]
823 mov dx,es
824 endif
825 mov cx,offset _xfer_buf
826 storepage: ; storepage(edx,cx)
827 ifndef NO386
828 push 0
829 push 4096
830 push 0
831 else
832 xor bx,bx
833 push bx
834 mov bh,4096/256
835 push bx
836 xor bx,bx
837 push bx
838 endif
839 push cx
840 push ds
841 jmp call_memcpy32
843 endp @storepage$qpul
846 ifdef LARGE_IMAGES
847 p386
848 ;***************************************************************
849 ;_fastcall void reset_bufv(bx:u32 *p);
850 ;***************************************************************
851 global @reset_bufv$qpul:near
852 proc @reset_bufv$qpul near
854 mov [curdata],bx
855 and [dword (data_himem bx).cacheidx],0
856 ret
858 endp @reset_bufv$qpul
860 ;***************************************************************
861 ;u32* prev_bufv();
862 ;u32* prev_bufv();
863 ;***************************************************************
864 global _prev_bufv:near
865 global _next_bufv:near
866 proc _prev_bufv near
868 stc
869 db 73h ; jnc
870 _next_bufv:
871 clc
872 push si
873 mov si,0
874 org $-2
875 curdata dw ?
876 sbb ax,ax
877 cmc
878 adc ax,[(data_himem si).cacheidx] ; -1/+1
879 xor ecx,ecx
880 test ax,0fc00h
881 jz @@gotpage
882 push ax ; FFFF / 0400
883 sar ax,8 ; FFFC / 0004
884 and al,0fch
885 add [(data_himem si).pageidx],ax
886 mov bx,[(data_himem si).pageidx]
887 lea bx,[(data_himem bx+si).page]
888 mov edx,ds
889 shl edx,4
890 lea cx,[(data_himem si).cache]
891 add edx,ecx
892 mov eax,[bx]
893 or eax,eax
894 jnz @@pageok
895 pop ax
896 xchg ax,bx
897 pop si
898 ret
899 @@pageok:
900 mov cx,4096
901 call memcpy_imagez ; get page
902 pop ax ; FFFF / 0400
903 cbw
904 shr ax,6 ; 03FF / 0000
905 @@gotpage:
906 mov [(data_himem si).cacheidx],ax
907 shl ax,2
908 xchg ax,bx
909 lea ax,[(data_himem bx+si).cache]
910 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
911 jnz @@notfirst2
912 xchg ax,si ; &first
913 @@notfirst2:
914 pop si
915 ret
917 endp _prev_bufv
918 endif
920 ifdef NO386
921 p8086
922 endif
924 ;***************************************************************
925 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
926 ;***************************************************************
928 global @open_image$qp11image_himempxzc:near
929 proc @open_image$qp11image_himempxzc near
931 push di
932 xchg ax,bx
933 xchg ax,di
934 ifdef EXTRA
935 cmp [(image_himem di).fd],0 ; iso image/kernel ?
936 jnz @@alreadydone
937 endif
938 mov [(image_himem di).state],bx
939 push bx
940 ifdef EXTRA
941 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
942 jnz @@next
943 mov [(image_himem di).next_chunk],offset next_chunk
944 @@next:
945 ;push di
946 call [(image_himem di).next_chunk] ; m->next_chunk()
947 ;pop di
948 else
949 @@next:
950 call next_chunk
951 endif
952 ifndef NO386
953 add eax,3
954 and al,0FCh
955 add [(image_himem di).size],eax ; m->size += m->chunk_size
956 or eax,eax
957 else
958 add ax,3
959 adc dx,0
960 and al,0FCh
961 add [word (image_himem di).size],ax ; m->size += m->chunk_size
962 adc [word ((image_himem di).size)+2],dx
963 or ax,dx
964 endif
965 jnz @@next
966 pop [(image_himem di).state]
967 ifdef EXTRA
968 ;push di
969 call [(image_himem di).next_chunk] ; m->next_chunk()
970 ;pop di
971 else
972 call next_chunk
973 endif
974 @@alreadydone:
975 pop di
976 ret
978 endp @open_image$qp11image_himempxzc
981 ;***************************************************************
982 ;_fastcall int read_image(bx:struct image_himem *m);
983 ;***************************************************************
984 global @read_image$qp11image_himem:near
985 proc @read_image$qp11image_himem near
987 push si di
988 mov di,bx
989 mov si,4096
990 push si ; original size
991 @@loop:
992 ifndef NO386
993 movzx ecx,si
994 mov eax,[(image_himem di).chunk_size]
995 cmp ecx,eax
996 jb @@szok
997 else
998 mov cx,si
999 mov ax,[word (image_himem di).chunk_size]
1000 cmp cx,ax
1001 jb @@szok
1002 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1003 jne @@szok
1004 endif
1005 xchg ax,cx
1006 @@szok:
1007 jcxz image_done
1008 mov dx,offset _xfer_buf+4096
1009 sub dx,si
1010 mov bx,[di]
1011 call @read$cxdxbx
1012 jbe image_done
1013 xor cx,cx
1014 cwd ; ax < 8000h
1015 ifndef NO386
1016 cwde ; ax < 8000h
1017 sub [(image_himem di).chunk_size],eax
1018 xchg eax,ebx
1019 else
1020 sub [word (image_himem di).chunk_size],ax
1021 xchg ax,bx
1022 sbb [word ((image_himem di).chunk_size)+2],dx
1023 jnz @@fill
1024 cmp [word (image_himem di).chunk_size],dx
1025 endif
1026 jnz @@fill
1027 dec cx
1028 @@fill:
1029 test bl,3
1030 je @@filled
1031 mov [bx+_xfer_buf],dh
1032 inc bx
1033 jmp @@fill
1034 @@filled:
1035 ifndef NO386
1036 sub [(image_himem di).remaining],ebx
1037 else
1038 sub [word (image_himem di).remaining],bx
1039 sbb [word ((image_himem di).remaining)+2],dx
1040 endif
1041 sub si,bx
1042 pushf
1043 ifdef EXTRA
1044 and cx,[(image_himem di).next_chunk]
1045 jcxz @@same_chunk
1046 push di
1047 call cx
1048 pop cx
1049 else
1050 jcxz @@same_chunk
1051 call next_chunk
1052 endif
1053 @@same_chunk:
1054 popf
1055 jnz @@loop
1056 image_done:
1057 pop ax ; original size
1058 sub ax,si
1059 pop di si
1060 ret
1062 endp @read_image$qp11image_himem
1065 ;***************************************************************
1066 ;_fastcall unsigned long strtol(const char *s);
1067 ;***************************************************************
1068 ifndef USE_ARGSTR
1069 global @strtol$qpxzc:near
1070 endif
1071 proc @strtol$qpxzc near
1073 ifndef NO386
1074 ifndef USE_ARGSTR
1075 push si
1076 mov si,bx
1077 endif
1078 xor ecx,ecx
1079 xor eax,eax
1080 xor ebx,ebx
1081 or si,si
1082 jz @@end
1083 lodsb
1084 or al,20h
1085 cmp al,'a'
1086 jb @@notvga
1087 sub al,'n'
1088 @@vgaloop:
1089 dec cx
1090 add al,6
1091 jb @@vgaloop ; vga=normal,extended,ask
1092 @@vga:
1093 dec cx
1094 xchg ax,cx
1095 cwd
1096 jmp @@popsiret
1097 @@notvga:
1098 mov cl,10 ; radix
1099 cmp al,'-'
1100 ja @@radixkeep
1101 cmc ; '+'=2B:C=0 '-'=2D:C=1
1102 lodsb
1103 @@radixkeep:
1104 pushf
1105 cmp al,'0'
1106 jne @@radixok
1107 mov cl,8
1108 lodsb
1109 or al,20h
1110 cmp al,'x'
1111 jne @@radixok
1112 mov cl,16
1113 @@strtollp:
1114 lodsb
1115 @@radixok:
1116 or al,20h
1117 sub al,'0'
1118 jb @@endstrtol
1119 cmp al,9
1120 jbe @@digitok
1121 cmp al,'a'-'0'
1122 jb @@endstrtol
1123 sub al,'a'-'0'-10
1124 @@digitok:
1125 cmp al,cl
1126 jae @@endstrtol
1127 xchg eax,ebx
1128 mul ecx
1129 add eax,ebx
1130 xchg eax,ebx
1131 jmp @@strtollp
1132 @@endstrtol:
1133 mov cl,10
1134 cmp al,'k'-'a'+10
1135 je @@shift
1136 mov cl,20
1137 cmp al,'m'-'a'+10
1138 je @@shift
1139 mov cl,30
1140 cmp al,'g'-'a'+10
1141 jne @@noshift
1142 @@shift:
1143 shl ebx,cl
1144 @@noshift:
1145 popf
1146 jnc @@end
1147 neg ebx
1148 @@end:
1149 push ebx
1150 pop ax
1151 pop dx
1152 @@popsiret:
1153 ifndef USE_ARGSTR
1154 pop si
1155 endif
1156 else
1157 ifndef USE_ARGSTR
1158 push si di
1159 xor ax,ax
1160 cwd
1161 or bx,bx
1162 else
1163 push di
1164 xor ax,ax
1165 cwd
1166 or si,si
1167 endif
1168 jz @@goend
1169 xchg ax,di
1170 ifndef USE_ARGSTR
1171 mov si,bx
1172 endif
1173 xor cx,cx
1174 lodsb
1175 or al,20h
1176 cmp al,'a'
1177 jb @@notvga
1178 sub al,'n'
1179 @@vgaloop:
1180 dec cx
1181 add al,6
1182 jb @@vgaloop ; vga=normal,extended,ask
1183 @@vga:
1184 xchg ax,cx
1185 @@goend:
1186 jmp @@popdisiret
1187 @@notvga:
1188 mov cl,10 ; radix
1189 cmp al,'-'
1190 ja @@radixkeep
1191 cmc ; '+'=2B:C=0 '-'=2D:C=1
1192 lodsb
1193 @@radixkeep:
1194 pushf
1195 cmp al,'0'
1196 jne @@radixok
1197 mov cl,8
1198 lodsb
1199 or al,20h
1200 cmp al,'x'
1201 jne @@radixok
1202 mov cl,16
1203 @@strtollp:
1204 lodsb
1205 @@radixok:
1206 or al,20h
1207 sub al,'0'
1208 jb @@endstrtol
1209 cmp al,9
1210 jbe @@digitok
1211 cmp al,'a'-'0'
1212 jb @@endstrtol
1213 sub al,'a'-'0'-10
1214 @@digitok:
1215 cmp al,cl
1216 jae @@endstrtol
1218 push ax
1219 push dx
1220 xchg ax,bx
1221 mul cx
1222 xchg ax,bx
1223 xchg ax,dx
1224 xchg ax,di
1225 pop ax
1226 mul cx
1227 add ax,di
1228 xchg ax,dx
1229 pop ax
1230 mov ah,0
1231 add bx,ax
1232 adc dx,0
1234 jmp @@strtollp
1235 @@endstrtol:
1236 mov cl,10
1237 cmp al,'k'-'a'+10
1238 je @@shift
1239 mov cl,20
1240 cmp al,'m'-'a'+10
1241 je @@shift
1242 mov cl,30
1243 cmp al,'g'-'a'+10
1244 jne @@noshift
1245 @@shift:
1246 rcl di,1
1247 shl dx,1
1248 loop @@shift
1249 @@noshift:
1250 popf
1251 jnc @@end
1252 not dx
1253 neg bx
1254 jne @@end
1255 inc dx
1256 @@end:
1257 xchg ax,bx
1258 @@popdisiret:
1259 ifndef USE_ARGSTR
1260 pop di si
1261 else
1262 pop di
1263 endif
1264 endif
1265 strtol_ret:
1266 ret
1268 endp @strtol$qpxzc
1271 ifdef USE_ARGSTR
1272 ;***************************************************************
1273 ;_fastcall void set_cmdline(bx:const char *filename);
1274 ;***************************************************************
1275 global @set_cmdline$qpxzc:near
1276 proc @set_cmdline$qpxzc near
1277 call openargs
1278 jc strtol_ret
1279 mov cx,4096
1280 mov di,[_heap_top]
1281 extrn read_cmdline:near
1282 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1284 endp @set_cmdline$qpxzc
1285 endif
1288 ifdef NO386
1289 ;***************************************************************
1290 ;u16 topseg();
1291 ;***************************************************************
1292 global _topseg:near
1293 proc _topseg near
1295 int 12h
1296 jnc @@max640k
1297 mov ax,640 ; 9000
1298 @@max640k:
1299 dec ax
1300 and al,0C0h
1301 mov cl,6
1302 shl ax,cl
1303 ret
1305 endp _topseg
1306 endif
1308 ifdef EXTRA
1309 p8086
1310 ;***************************************************************
1311 ;_fastcall char *utoa(ax:unsigned n);
1312 ;***************************************************************
1313 global @utoa$qui:near
1314 proc @utoa$qui near
1316 mov cx,10
1317 mov bx,offset utoabuf+5
1318 @@loop:
1319 dec bx
1320 xor dx,dx
1321 div cx ; DX:AX = n%10:n/10
1322 mov [byte bx],'0'
1323 add [bx],dl ; DL = n%10
1324 or ax,ax
1325 jnz @@loop
1326 xchg ax,bx
1327 ret
1329 endp @utoa$qui
1332 ;***************************************************************
1333 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1334 ;***************************************************************
1335 global @kver2ul$qpzc:near
1336 proc @kver2ul$qpzc near
1338 push si
1339 mov si,bx
1340 xor bx,bx
1341 mov cx,304h
1342 @@number:
1343 xor ax,ax
1344 cwd
1345 @@digit:
1346 shl al,cl
1347 shl ax,cl
1348 lodsb
1349 sub al,30h
1350 cmp al,9
1351 jbe @@digit
1352 mov dl,bh
1353 mov bh,bl
1354 mov bl,ah
1355 dec ch
1356 jnz @@number
1357 xchg ax,bx
1358 pop si
1359 kver2ulret:
1360 ret
1362 endp @kver2ul$qpzc
1364 endif
1366 ;***************************************************************
1367 ;void try_default_args();
1368 ;***************************************************************
1369 ifdef EXTRA
1371 global _try_default_args:near
1372 proc _try_default_args near
1374 mov bx,offset tazboot_cmd
1375 call open
1376 jc kver2ulret
1377 mov cx,4096
1378 mov di,[_heap_top]
1379 extrn read_cmdline:near
1380 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1382 endp _try_default_args
1384 endif
1386 ends _TEXT
1388 end
1390 ;###### END OF FILE ############################################