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

linld: fix bootiso/strhead
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Nov 25 20:41:41 2020 +0000 (2020-11-25)
parents fc88d0826de4
children 555bcdab610b
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 "Himem broken",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 @@loop:
139 xchg ax,bx
140 mov cl,[bx] ; cl = *b++
141 inc bx
142 xchg ax,bx
143 cmp cl,[bx] ; cl ?= *a++
144 jnz fail ; return -1
145 inc bx
146 or cl,cl ; clear C
147 jz failifc ; return 0
148 jmp @@loop
150 endp @strcmp$qpxzct1
151 endif
154 ;***************************************************************
155 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
156 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
157 ;***************************************************************
158 global openargs:near ; openargs(bx)
159 openargs:
160 cmp [byte bx],'@'
161 jne fail
162 inc bx
164 global @open$qpxzc:near
165 proc @open$qpxzc near
167 open: ; open(bx)
168 ifdef ISOHOOK
169 ;_fastcall int open(bx:const char* name);
170 extrn iso_open_hack:word
171 call [iso_open_hack] ; or ret
172 endif
173 ifdef LONG_FILENAME
174 mov ax,716Ch
175 push bx si
176 mov si,bx
177 xor bx,bx ; R/O
178 xor cx,cx ; attributes
179 cwd ; action = open
180 stc
181 int 21h
182 pop si bx
183 jnc doret
184 endif
185 mov ax,3d00h ; read-only+compatibility
186 ;mov cl,0 ; attribute mask
187 mov dx,bx
188 jmp dos
190 endp @open$qpxzc
193 ;***************************************************************
194 ;_fastcall int fileexist(bx:const char* name);
195 ;***************************************************************
196 global @fileexist$qpxzc:near
197 @fileexist$qpxzc:
198 call @open$qpxzc
199 jc fail
201 ;***************************************************************
202 ;_fastcall int close(ax:int fd);
203 ;***************************************************************
204 global @close$qi:near
205 proc @close$qi near
207 global close:near ; close(ax)
208 close:
209 ifdef ISOHOOK
210 extrn iso_close_hack:word
211 call [iso_close_hack] ; or ret
212 endif
213 mov bh,3Eh
214 dosbx:
215 xchg ax,bx
216 or bx,bx
217 jnz dos
218 ret
220 endp @close$qi
223 ;***************************************************************
224 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
225 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
226 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
227 ;***************************************************************
228 global @readrm$qp11image_himemi:near
229 @readrm$qp11image_himemi:
230 xchg ax,dx ; sz
231 mov ax,[bx] ; fd
232 mov bx,[bx-2] ; data
233 global @read$qipvi:near
234 proc @read$qipvi near
236 ifdef WRITE
237 stc
238 db 0B0h ; mov al,im
239 global @write$qipvi:near
240 @write$qipvi:
241 clc
242 endif
243 @read$dxbxax:
244 xchg ax,bx ; fd
245 xchg ax,dx ; data
246 xchg ax,cx ; sz
247 ifdef WRITE
248 mov ah,40h
249 sbb ah,0
250 else
251 global @read$cxdxbx:near
252 @read$cxdxbx:
253 mov ah,3Fh
254 endif
255 ifdef ISOHOOK
256 ;_fastcall int read(bx:int fd, dx:void* data, cx:int sz);
257 extrn iso_read_hack:word
258 call [iso_read_hack] ; or ret
259 endif
260 jcxz fail
261 dos:
262 int 21h
263 jnc doret
264 fail:
265 stc
266 failifc:
267 sbb ax,ax ; ax=-1 CF
268 cwd
269 doret:
270 ifndef NO386
271 push dx ; see next_chunk:lseek
272 push ax
273 pop eax
274 endif
275 ret
277 endp @read$qipvi
279 ;***************************************************************
280 ;_fastcall long rewind(ax:int fd);
281 ;***************************************************************
283 global @rewind$qi:near ; fd=ax
284 proc @rewind$qi near
286 ifdef EXTRA ; catch ISO image case
287 stc
288 mov dx,-512 ; curpos = 512, see LOAD.CPP
289 mov bl,1
290 jmp lseekword
291 endif
292 rewind: ; rewind(ax)
293 mov bl,0
294 lseek0: ; lseek0(ax,bl=dir)
295 xor dx,dx ; clear C
296 lseekword:
297 sbb cx,cx
298 lseekset:
299 ifdef ISOHOOK
300 ;_fastcall long lseek(ax:int fd, cxdx:unsigned long offset, bl:whence);
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],dh
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],dh
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 jb 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,'o'
1088 @@vgaloop:
1089 dec cx
1090 add al,6
1091 jnb @@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 jne @@radixkeep
1101 lodsb
1102 @@radixkeep:
1103 pushf
1104 cmp al,'0'
1105 jne @@radixok
1106 mov cl,8
1107 lodsb
1108 or al,20h
1109 cmp al,'x'
1110 jne @@radixok
1111 mov cl,16
1112 @@strtollp:
1113 lodsb
1114 @@radixok:
1115 or al,20h
1116 sub al,'0'
1117 jb @@endstrtol
1118 cmp al,9
1119 jbe @@digitok
1120 cmp al,'a'-'0'
1121 jb @@endstrtol
1122 sub al,'a'-'0'-10
1123 @@digitok:
1124 cmp al,cl
1125 jae @@endstrtol
1126 cbw
1127 cwde
1128 xchg eax,ebx
1129 mul ecx
1130 add ebx,eax
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
1159 mov si,bx
1160 endif
1161 or si,si
1162 jz @@goend
1163 xor bx,bx
1164 xor cx,cx
1165 xor dx,dx
1166 lodsb
1167 or al,20h
1168 cmp al,'a'
1169 jb @@notvga
1170 sub al,'o'
1171 @@vgaloop:
1172 dec cx
1173 add al,6
1174 jnb @@vgaloop ; vga=normal,extended,ask
1175 @@vga:
1176 xchg ax,cx
1177 ;cwd
1178 @@goend:
1179 jmp @@end
1180 @@notvga:
1181 mov cl,10 ; radix
1182 cmp al,'-'
1183 jne @@radixkeep
1184 lodsb
1185 @@radixkeep:
1186 pushf
1187 cmp al,'0'
1188 jne @@radixok
1189 mov cl,8
1190 lodsb
1191 or al,20h
1192 cmp al,'x'
1193 jne @@radixok
1194 mov cl,16
1195 @@strtollp:
1196 lodsb
1197 @@radixok:
1198 or al,20h
1199 sub al,'0'
1200 jb @@endstrtol
1201 cmp al,9
1202 jbe @@digitok
1203 cmp al,'a'-'0'
1204 jb @@endstrtol
1205 sub al,'a'-'0'-10
1206 @@digitok:
1207 cmp al,cl
1208 jae @@endstrtol
1209 cbw
1211 push ax
1212 xchg ax,dx
1213 mul cx
1214 xchg ax,bx
1215 mul cx
1216 add dx,bx
1217 pop bx
1218 add bx,ax
1219 adc dx,0
1221 jmp @@strtollp
1222 @@endstrtol:
1223 mov cl,10
1224 cmp al,'k'-'a'+10
1225 je @@shift
1226 mov cl,20
1227 cmp al,'m'-'a'+10
1228 je @@shift
1229 mov cl,30
1230 cmp al,'g'-'a'+10
1231 @@shift:
1232 xchg ax,bx
1233 jne @@noshift
1234 extrn N_LXLSH@:near
1235 call N_LXLSH@
1236 @@noshift:
1237 popf
1238 jne @@end
1239 not dx
1240 neg ax
1241 jne @@end
1242 inc dx
1243 @@end:
1244 ifndef USE_ARGSTR
1245 pop si
1246 endif
1247 endif
1248 strtol_ret:
1249 ret
1251 endp @strtol$qpxzc
1254 ifdef USE_ARGSTR
1255 ;***************************************************************
1256 ;_fastcall void set_cmdline(bx:const char *filename);
1257 ;***************************************************************
1258 global @set_cmdline$qpxzc:near
1259 proc @set_cmdline$qpxzc near
1260 call openargs
1261 jc strtol_ret
1262 mov ch,15 ; cx<4096
1263 mov di,[_heap_top]
1264 extrn read_cmdline:near
1265 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1267 endp @set_cmdline$qpxzc
1268 endif
1271 ifdef NO386
1272 ;***************************************************************
1273 ;u16 topseg();
1274 ;***************************************************************
1275 global _topseg:near
1276 proc _topseg near
1278 int 12h
1279 jnc @@max640k
1280 mov ax,640 ; 9000
1281 @@max640k:
1282 dec ax
1283 and al,0C0h
1284 mov cl,6
1285 shl ax,cl
1286 ret
1288 endp _topseg
1289 endif
1291 ifdef EXTRA
1292 p8086
1293 ;***************************************************************
1294 ;_fastcall char *utoa(ax:unsigned n);
1295 ;***************************************************************
1296 global @utoa$qui:near
1297 proc @utoa$qui near
1299 mov cx,10
1300 mov bx,offset utoabuf+5
1301 @@loop:
1302 dec bx
1303 xor dx,dx
1304 div cx ; DX:AX = n%10:n/10
1305 mov [byte bx],'0'
1306 add [bx],dl ; DL = n%10
1307 or ax,ax
1308 jnz @@loop
1309 xchg ax,bx
1310 ret
1312 endp @utoa$qui
1315 ;***************************************************************
1316 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1317 ;***************************************************************
1318 global @kver2ul$qpzc:near
1319 proc @kver2ul$qpzc near
1321 push si
1322 mov si,bx
1323 xor bx,bx
1324 mov cx,304h
1325 @@number:
1326 xor ax,ax
1327 cwd
1328 @@digit:
1329 shl al,cl
1330 shl ax,cl
1331 lodsb
1332 sub al,30h
1333 cmp al,9
1334 jbe @@digit
1335 mov dl,bh
1336 mov bh,bl
1337 mov bl,ah
1338 dec ch
1339 jnz @@number
1340 xchg ax,bx
1341 pop si
1342 kver2ulret:
1343 ret
1345 endp @kver2ul$qpzc
1347 endif
1349 ;***************************************************************
1350 ;void try_default_args();
1351 ;***************************************************************
1352 ifdef EXTRA
1354 global _try_default_args:near
1355 proc _try_default_args near
1357 mov bx,offset tazboot_cmd
1358 call open
1359 jc kver2ulret
1360 mov cx,4096
1361 mov di,[_heap_top]
1362 extrn read_cmdline:near
1363 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1365 endp _try_default_args
1367 endif
1369 ends _TEXT
1371 end
1373 ;###### END OF FILE ############################################