wok-current view linld/stuff/src/CRTL.ASM @ rev 22170

linld: clear heap in moverm
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 08 10:47:52 2019 +0100 (2019-11-08)
parents 306a4bbdee7d
children 10fa26e4c60d
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* malloc_or_die(ax:unsigned size);
482 ;***************************************************************
483 xchg_heap_top:
484 xchg ax,[_heap_top]
485 ret
487 global @malloc_or_die$qui:near
488 proc @malloc_or_die$qui near
490 global malloc_or_die:near ; ax = malloc_or_die(ax)
491 malloc_or_die:
492 mov bx,offset msg_malloc
493 add ax,[_heap_top]
494 jnc xchg_heap_top
496 endp @malloc_or_die$qui
499 ;***************************************************************
500 ;_fastcall int die(bx:const char* msg);
501 ;int exit(ax:int status);
502 ;int abort(void);
503 ;***************************************************************
504 global @die$qpxzc:near
505 proc @die$qpxzc near
506 @die$qpxzc:
507 global die:near ; die(bx)
508 die:
509 call puts
510 global @exit$qv:near
511 @exit$qv:
512 _exit:
513 extrn _imgs:image_himem
514 mov cx,[(word _imgs.buf)+2] ; no_exit ?
515 mov ah,4Ch
516 jcxz do_int21h
517 mov bx, offset msg_hang
518 call puts
519 ; global _abort:near
520 _abort:
521 cli
522 hlt
523 jmp _abort
525 endp @die$qpxzc
527 ;***************************************************************
528 ;_fastcall void puts(bx:const char* s):
529 ;***************************************************************
530 global @puts$qpxzc:near
532 ; global puts:near ; puts(bx)
533 @putsz:
534 call @putc
535 @puts$qpxzc:
536 puts:
537 mov dl,[bx]
538 inc bx
539 or dl,dl
540 jne @putsz
541 mov dl,10
542 @putc:
543 cmp dl,10
544 jne @putcz
545 call @putcz2
546 @putcz2:
547 xor dl,7 ; 10^13 1010^1101
548 @putcz:
549 mov ah,2
550 do_int21h:
551 int 21h
552 ret
555 ;***************************************************************
556 ;static long next_chunk(struct image_himem *di);
557 ;***************************************************************
558 proc next_chunk near
560 push si
561 mov ax,[(image_himem di).fd]
562 call close
563 ifndef NO386
564 xor eax,eax
565 else
566 xor ax,ax
567 cwd
568 endif
569 mov [(image_himem di).fd],ax
570 mov bx,[(image_himem di).state]
571 cmp al,[bx] ; ""
572 jz @@end
573 mov si,bx
574 @@scan:
575 lodsb
576 mov cx,si
577 cmp al,','
578 jz @@eos
579 or al,al
580 jnz @@scan
581 dec cx
582 @@eos:
583 mov [(image_himem di).state],cx
584 dec si
585 push [word si]
586 mov [byte si],ah ; set temp eos
587 call open
588 pop [word si] ; restore string
589 jc @@die
590 mov [(image_himem di).fd],ax
591 mov [(image_himem di).fd2close],ax
592 mov bl,02h ; SEEK_END
593 call lseek0
594 @@die:
595 mov bx,[(image_himem di).errmsg]
596 jc die
597 ifndef NO386
598 push eax
599 mov ax,[(image_himem di).fd]
600 call rewind
601 pop eax
602 @@end:
603 mov [(image_himem di).chunk_size],eax
604 else
605 push ax
606 push dx
607 mov ax,[(image_himem di).fd]
608 call rewind
609 pop dx
610 pop ax
611 @@end:
612 mov [word (image_himem di).chunk_size],ax
613 mov [word ((image_himem di).chunk_size)+2],dx
614 endif
615 pop si
616 ret
618 endp next_chunk
621 ifdef LARGE_IMAGES
622 struc data_himem ;struct data_himem {
623 first dd ? ; 0 u32 first;
624 cacheidx dw ? ; 4 int cacheidx;
625 pageidx dw ? ; 6 int pageidx;
626 cache dd 1024 dup(?) ; 8 int cache;
627 page dd 1024 dup(?) ;4104 int page;
628 ends data_himem ;}; // size=8200
629 endif
631 ;***************************************************************
632 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
633 ;***************************************************************
634 global @malloc_bufv_or_die$qp11image_himem:near
635 proc @malloc_bufv_or_die$qp11image_himem near
637 p386
638 push si
639 mov si,bx
640 ifdef LARGE_IMAGES
641 movzx eax,[word ((image_himem si).size) + 2]
642 shr ax,4 ; pages index size = size >> 20
643 add ax,8+4096+8
644 call malloc_or_die
645 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
646 add ecx,[(image_himem si).size]
647 shr ecx,12
648 mov [curdata],ax
649 else
650 mov eax,[(image_himem si).size]
651 dec eax
652 shr eax,12
653 inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
654 push ax
655 inc ax ; cnt+1
656 shl ax,2 ; bufv => vcpi => vm86
657 ; our malloc zeroes allocated mem: bufv[cnt]=0;
658 ; Allocate pages, storing addrs in addrbuf
659 call malloc_or_die
660 pop cx
661 push ax
662 endif
663 mov [(image_himem si).bufv],ax
664 xchg ax,si
665 @@vcpi_alloc:
666 xor edx,edx
667 mov ax,0DE04h
668 int 67h
669 or ah,ah
670 mov bx,offset vcpi_alloc_err
671 jnz die
672 ; for (i = cnt-1; i >= 0; i--)
673 ifdef LARGE_IMAGES
674 mov eax,ecx
675 dec eax
676 else
677 mov ax,cx
678 dec ax
679 cwde
680 endif
681 shl eax,12 ; i*_4k
682 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
683 mov bx,offset _imgs.fallback
684 push eax
685 add eax,[bx-2+2]
686 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
687 pop eax ; i*_4k
688 jbe @@pmok
689 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
690 jae @@vcpi_alloc
691 @@pmok:
692 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
693 mov bx,offset _imgs.fallback+32
694 add eax,[bx-2+2] ; +initrd.fallback
695 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
696 ja @@initrdok
697 mov eax,[bx-2+6] ; initrd.size
698 add eax,[bx-2+2] ; +initrd.fallback
699 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
700 @@jnc_vcpi_alloc:
701 ja @@vcpi_alloc
702 @@initrdok:
703 ifdef LARGE_IMAGES
704 cmp [(data_himem si).first],0
705 jne @@notfirst
706 mov [(data_himem si).first],edx
707 @@notfirst:
708 mov bx,[(data_himem si).cacheidx]
709 cmp bh,4
710 jae @@nextpage
711 shl bx,2
712 inc [(data_himem si).cacheidx]
713 mov [(data_himem bx+si).cache],edx
714 loopd @@vcpi_alloc
715 mov [(data_himem bx+si).cache],ecx ; last is 0
716 @@nextpage:
717 and [(data_himem si).cacheidx],0
718 mov bx,[(data_himem si).pageidx]
719 mov [(data_himem bx+si).page],edx
720 add [(data_himem si).pageidx],4
721 push cx
722 lea cx,[(data_himem si).cache]
723 ifdef NO386
724 push edx
725 pop dx
726 pop ax
727 endif
728 call storepage ; storepage(edx,cx)
729 pop cx
730 or ecx,ecx ; clear C
731 jnz @@jnc_vcpi_alloc
732 mov [dword (data_himem si).cacheidx],ecx
733 xchg ax,si
734 else
735 mov [si],edx
736 lodsd ; si=+4
737 loop @@vcpi_alloc
738 pop ax
739 endif
740 pop si
741 ret
742 ifdef NO386
743 p8086
744 endif
746 endp @malloc_bufv_or_die$qp11image_himem
749 ;***************************************************************
750 ;_fastcall void memcpy_image(bx:struct image_himem *m);
751 ;***************************************************************
752 global @memcpy_image$qp11image_himem:near
753 proc @memcpy_image$qp11image_himem near
755 ifndef NO386
756 mov edx,[(image_himem bx).fallback]
757 mov eax,[(image_himem bx).buf]
758 cmp eax,edx ; if (m->fallback != m->buf)
759 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
760 ifdef LARGE_IMAGES
761 mov ecx,[(image_himem bx).size]
762 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
763 push ecx
764 else
765 push [(image_himem bx).size]
766 endif
767 push eax
768 push 0
769 call_memcpy32:
770 push edx
771 else
772 les ax,[dword ((image_himem bx).fallback)]
773 mov dx,es
774 mov cx,[word ((image_himem bx).buf)]
775 cmp ax,cx ; if (m->fallback != m->buf)
776 jnz @@do
777 cmp dx,[word ((image_himem bx).buf)+2]
778 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
779 @@do:
780 push [word ((image_himem bx).size)+2]
781 push [word ((image_himem bx).size)]
782 push [word ((image_himem bx).buf)+2]
783 push cx
784 xor cx,cx
785 push cx
786 call_memcpy32:
787 push dx
788 push ax
789 ifdef LARGE_IMAGES
790 jmp @@memcpy
791 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
792 p386
793 push ecx
794 push eax
795 push 0
796 push edx
797 ifdef NO386
798 p8086
799 endif
800 endif
801 endif
802 @@memcpy:
803 extrn memcpy32:near
804 call near memcpy32
805 @@skip:
806 ret
808 endp @memcpy_image$qp11image_himem
810 ;***************************************************************
811 ;_fastcall void storepage(bx:u32 *dst);
812 ;***************************************************************
813 global @storepage$qpul:near
814 proc @storepage$qpul near
816 ifndef NO386
817 mov edx,[bx]
818 else
819 les ax,[dword bx]
820 mov dx,es
821 endif
822 mov cx,offset _xfer_buf
823 storepage: ; storepage(edx,cx)
824 ifndef NO386
825 push 0
826 push 4096
827 push 0
828 else
829 xor bx,bx
830 push bx
831 mov bh,4096/256
832 push bx
833 xor bx,bx
834 push bx
835 endif
836 push cx
837 push ds
838 jmp call_memcpy32
840 endp @storepage$qpul
843 ifdef LARGE_IMAGES
844 p386
845 ;***************************************************************
846 ;_fastcall void reset_bufv(bx:u32 *p);
847 ;***************************************************************
848 global @reset_bufv$qpul:near
849 proc @reset_bufv$qpul near
851 mov [curdata],bx
852 and [dword (data_himem bx).cacheidx],0
853 ret
855 endp @reset_bufv$qpul
857 ;***************************************************************
858 ;u32* prev_bufv();
859 ;u32* prev_bufv();
860 ;***************************************************************
861 global _prev_bufv:near
862 global _next_bufv:near
863 proc _prev_bufv near
865 stc
866 db 73h ; jnc
867 _next_bufv:
868 clc
869 push si
870 mov si,[curdata]
871 sbb ax,ax
872 cmc
873 adc ax,[(data_himem si).cacheidx] ; -1/+1
874 xor ecx,ecx
875 test ax,0fc00h
876 jz @@gotpage
877 push ax ; FFFF / 0400
878 sar ax,8 ; FFFC / 0004
879 and al,0fch
880 add [(data_himem si).pageidx],ax
881 mov bx,[(data_himem si).pageidx]
882 lea bx,[(data_himem bx+si).page]
883 mov edx,ds
884 shl edx,4
885 lea cx,[(data_himem si).cache]
886 add edx,ecx
887 mov eax,[bx]
888 or eax,eax
889 jnz @@pageok
890 pop ax
891 xchg ax,bx
892 pop si
893 ret
894 @@pageok:
895 mov cx,4096
896 call memcpy_imagez ; get page
897 pop ax ; FFFF / 0400
898 cbw
899 shr ax,6 ; 03FF / 0000
900 @@gotpage:
901 mov [(data_himem si).cacheidx],ax
902 shl ax,2
903 xchg ax,bx
904 lea ax,[(data_himem bx+si).cache]
905 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
906 jnz @@notfirst2
907 xchg ax,si ; &first
908 @@notfirst2:
909 pop si
910 ret
912 endp _prev_bufv
913 endif
915 ifdef NO386
916 p8086
917 endif
919 ;***************************************************************
920 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
921 ;***************************************************************
923 global @open_image$qp11image_himempxzc:near
924 proc @open_image$qp11image_himempxzc near
926 push di
927 xchg ax,bx
928 xchg ax,di
929 ifdef EXTRA
930 cmp [(image_himem di).fd],0 ; iso image/kernel ?
931 jnz @@alreadydone
932 endif
933 mov [(image_himem di).state],bx
934 push bx
935 ifdef EXTRA
936 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
937 jnz @@next
938 mov [(image_himem di).next_chunk],offset next_chunk
939 @@next:
940 ;push di
941 call [(image_himem di).next_chunk] ; m->next_chunk()
942 ;pop di
943 else
944 @@next:
945 call next_chunk
946 endif
947 ifndef NO386
948 add eax,3
949 and al,0FCh
950 add [(image_himem di).size],eax ; m->size += m->chunk_size
951 or eax,eax
952 else
953 add ax,3
954 adc dx,0
955 and al,0FCh
956 add [word (image_himem di).size],ax ; m->size += m->chunk_size
957 adc [word ((image_himem di).size)+2],dx
958 or ax,dx
959 endif
960 jnz @@next
961 pop [(image_himem di).state]
962 ifdef EXTRA
963 ;push di
964 call [(image_himem di).next_chunk] ; m->next_chunk()
965 ;pop di
966 else
967 call next_chunk
968 endif
969 @@alreadydone:
970 pop di
971 ret
973 endp @open_image$qp11image_himempxzc
976 ;***************************************************************
977 ;_fastcall int read_image(bx:struct image_himem *m);
978 ;***************************************************************
979 global @read_image$qp11image_himem:near
980 proc @read_image$qp11image_himem near
982 push si di
983 mov di,bx
984 mov si,4096
985 push si ; original size
986 @@loop:
987 ifndef NO386
988 movzx ecx,si
989 mov eax,[(image_himem di).chunk_size]
990 cmp ecx,eax
991 jb @@szok
992 else
993 mov cx,si
994 mov ax,[word (image_himem di).chunk_size]
995 cmp cx,ax
996 jb @@szok
997 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
998 jne @@szok
999 endif
1000 xchg ax,cx
1001 @@szok:
1002 jcxz image_done
1003 mov dx,offset _xfer_buf+4096
1004 sub dx,si
1005 mov bx,[di]
1006 call @read$cxdxbx
1007 jbe image_done
1008 xor cx,cx
1009 cwd ; ax < 8000h
1010 ifndef NO386
1011 cwde ; ax < 8000h
1012 sub [(image_himem di).chunk_size],eax
1013 xchg eax,ebx
1014 else
1015 sub [word (image_himem di).chunk_size],ax
1016 xchg ax,bx
1017 sbb [word ((image_himem di).chunk_size)+2],dx
1018 jnz @@fill
1019 cmp [word (image_himem di).chunk_size],dx
1020 endif
1021 jnz @@fill
1022 dec cx
1023 @@fill:
1024 test bl,3
1025 je @@filled
1026 mov [bx+_xfer_buf],dh
1027 inc bx
1028 jmp @@fill
1029 @@filled:
1030 ifndef NO386
1031 sub [(image_himem di).remaining],ebx
1032 else
1033 sub [word (image_himem di).remaining],bx
1034 sbb [word ((image_himem di).remaining)+2],dx
1035 endif
1036 sub si,bx
1037 pushf
1038 ifdef EXTRA
1039 and cx,[(image_himem di).next_chunk]
1040 jcxz @@same_chunk
1041 push di
1042 call cx
1043 pop cx
1044 else
1045 jcxz @@same_chunk
1046 call next_chunk
1047 endif
1048 @@same_chunk:
1049 popf
1050 jnz @@loop
1051 image_done:
1052 pop ax ; original size
1053 sub ax,si
1054 pop di si
1055 ret
1057 endp @read_image$qp11image_himem
1060 ;***************************************************************
1061 ;_fastcall unsigned long strtol(const char *s);
1062 ;***************************************************************
1063 ifndef USE_ARGSTR
1064 global @strtol$qpxzc:near
1065 endif
1066 proc @strtol$qpxzc near
1068 ifndef NO386
1069 ifndef USE_ARGSTR
1070 push si
1071 mov si,bx
1072 endif
1073 xor ecx,ecx
1074 xor eax,eax
1075 xor ebx,ebx
1076 or si,si
1077 jz @@end
1078 lodsb
1079 or al,20h
1080 cmp al,'a'
1081 jb @@notvga
1082 sub al,'n'
1083 @@vgaloop:
1084 dec cx
1085 add al,6
1086 jb @@vgaloop ; vga=normal,extended,ask
1087 @@vga:
1088 dec cx
1089 xchg ax,cx
1090 cwd
1091 jmp @@popsiret
1092 @@notvga:
1093 mov cx,10 ; radix
1094 cmp al,'-'
1095 ja @@radixkeep
1096 cmc ; '+'=2B:C=0 '-'=2D:C=1
1097 lodsb
1098 @@radixkeep:
1099 pushf
1100 cmp al,'0'
1101 jne @@radixok
1102 mov cl,8
1103 lodsb
1104 or al,20h
1105 cmp al,'x'
1106 jne @@radixok
1107 mov cl,16
1108 @@strtollp:
1109 lodsb
1110 @@radixok:
1111 or al,20h
1112 sub al,'0'
1113 jb @@endstrtol
1114 cmp al,9
1115 jbe @@digitok
1116 cmp al,'a'-'0'
1117 jb @@endstrtol
1118 sub al,'a'-'0'-10
1119 @@digitok:
1120 cmp al,cl
1121 jae @@endstrtol
1122 xchg eax,ebx
1123 mul ecx
1124 add eax,ebx
1125 xchg eax,ebx
1126 jmp @@strtollp
1127 @@endstrtol:
1128 mov cl,10
1129 cmp al,'k'-'a'+10
1130 je @@shift
1131 mov cl,20
1132 cmp al,'m'-'a'+10
1133 je @@shift
1134 mov cl,30
1135 cmp al,'g'-'a'+10
1136 jne @@noshift
1137 @@shift:
1138 shl ebx,cl
1139 @@noshift:
1140 popf
1141 jnc @@end
1142 neg ebx
1143 @@end:
1144 push ebx
1145 pop ax
1146 pop dx
1147 @@popsiret:
1148 ifndef USE_ARGSTR
1149 pop si
1150 endif
1151 else
1152 ifndef USE_ARGSTR
1153 push si di
1154 xor ax,ax
1155 cwd
1156 or bx,bx
1157 else
1158 push di
1159 xor ax,ax
1160 cwd
1161 or si,si
1162 endif
1163 jz @@goend
1164 xchg ax,di
1165 ifndef USE_ARGSTR
1166 mov si,bx
1167 endif
1168 lodsb
1169 or al,20h
1170 cmp al,'a'
1171 jb @@notvga
1172 xor cx,cx
1173 sub al,'n'
1174 @@vgaloop:
1175 dec cx
1176 add al,6
1177 jb @@vgaloop ; vga=normal,extended,ask
1178 @@vga:
1179 xchg ax,cx
1180 @@goend:
1181 jmp @@popdisiret
1182 @@notvga:
1183 mov cx,10 ; radix
1184 cmp al,'-'
1185 ja @@radixkeep
1186 cmc ; '+'=2B:C=0 '-'=2D:C=1
1187 lodsb
1188 @@radixkeep:
1189 pushf
1190 cmp al,'0'
1191 jne @@radixok
1192 mov cl,8
1193 lodsb
1194 or al,20h
1195 cmp al,'x'
1196 jne @@radixok
1197 mov cl,16
1198 @@strtollp:
1199 lodsb
1200 @@radixok:
1201 or al,20h
1202 sub al,'0'
1203 jb @@endstrtol
1204 cmp al,9
1205 jbe @@digitok
1206 cmp al,'a'-'0'
1207 jb @@endstrtol
1208 sub al,'a'-'0'-10
1209 @@digitok:
1210 cmp al,cl
1211 jae @@endstrtol
1213 push ax
1214 push dx
1215 xchg ax,bx
1216 mul cx
1217 xchg ax,bx
1218 xchg ax,dx
1219 xchg ax,di
1220 pop ax
1221 mul cx
1222 add ax,di
1223 xchg ax,dx
1224 pop ax
1225 mov ah,0
1226 add bx,ax
1227 adc dx,0
1229 jmp @@strtollp
1230 @@endstrtol:
1231 mov cl,10
1232 cmp al,'k'-'a'+10
1233 je @@shift
1234 mov cl,20
1235 cmp al,'m'-'a'+10
1236 je @@shift
1237 mov cl,30
1238 cmp al,'g'-'a'+10
1239 jne @@noshift
1240 @@shift:
1241 rcl di,1
1242 shl dx,1
1243 loop @@shift
1244 @@noshift:
1245 popf
1246 jnc @@end
1247 not dx
1248 neg bx
1249 jne @@end
1250 inc dx
1251 @@end:
1252 xchg ax,bx
1253 @@popdisiret:
1254 ifndef USE_ARGSTR
1255 pop di si
1256 else
1257 pop di
1258 endif
1259 endif
1260 strtol_ret:
1261 ret
1263 endp @strtol$qpxzc
1266 ifdef USE_ARGSTR
1267 ;***************************************************************
1268 ;_fastcall void set_cmdline(bx:const char *filename);
1269 ;***************************************************************
1270 global @set_cmdline$qpxzc:near
1271 proc @set_cmdline$qpxzc near
1272 call openargs
1273 jc strtol_ret
1274 mov cx,4096
1275 mov di,[_heap_top]
1276 extrn read_cmdline:near
1277 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1279 endp @set_cmdline$qpxzc
1280 endif
1283 ifdef NO386
1284 ;***************************************************************
1285 ;u16 topseg();
1286 ;***************************************************************
1287 global _topseg:near
1288 proc _topseg near
1290 int 12h
1291 jnc @@max640k
1292 mov ax,640 ; 9000
1293 @@max640k:
1294 dec ax
1295 and al,0C0h
1296 mov cl,6
1297 shl ax,cl
1298 ret
1300 endp _topseg
1301 endif
1303 ifdef EXTRA
1304 p8086
1305 ;***************************************************************
1306 ;_fastcall char *ultoa(axdx:unsigned long n);
1307 ;***************************************************************
1308 global @ultoa$qul:near
1309 proc @ultoa$qul near
1311 xchg ax,cx
1312 xchg ax,dx ; AX:CX = n
1313 push si
1314 mov si,10
1315 mov bx,offset ultoabuf+11
1316 @@loop:
1317 dec bx
1318 xor dx,dx
1319 div si ; DX:AX = 0000:hi(n)
1320 xchg ax,cx ; CX = hi(n)/10
1321 div si ; DX:AX = hi(n)%10:lo(n)
1322 xchg ax,cx ; CX = lo(n/10)
1323 ; AX = hi(n)/10 = hi(n/10)
1324 mov [byte bx],'0'
1325 add [bx],dl ; DL = n%10
1326 mov dx,ax
1327 or dx,cx
1328 jnz @@loop
1329 xchg ax,bx
1330 pop si
1331 ret
1333 endp @ultoa$qul
1336 ;***************************************************************
1337 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1338 ;***************************************************************
1339 global @kver2ul$qpzc:near
1340 proc @kver2ul$qpzc near
1342 push si
1343 mov si,bx
1344 xor bx,bx
1345 mov cx,304h
1346 @@number:
1347 xor ax,ax
1348 cwd
1349 @@digit:
1350 shl al,cl
1351 shl ax,cl
1352 lodsb
1353 sub al,30h
1354 cmp al,9
1355 jbe @@digit
1356 mov dl,bh
1357 mov bh,bl
1358 mov bl,ah
1359 dec ch
1360 jnz @@number
1361 xchg ax,bx
1362 pop si
1363 kver2ulret:
1364 ret
1366 endp @kver2ul$qpzc
1368 endif
1370 ;***************************************************************
1371 ;void try_default_args();
1372 ;***************************************************************
1373 ifdef EXTRA
1375 global _try_default_args:near
1376 proc _try_default_args near
1378 mov bx,offset tazboot_cmd
1379 call open
1380 jc kver2ulret
1381 mov cx,4096
1382 mov di,[_heap_top]
1383 extrn read_cmdline:near
1384 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1386 endp _try_default_args
1388 endif
1390 ends _TEXT
1392 end
1394 ;###### END OF FILE ############################################