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

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