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

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