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

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