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

Up slitaz-icons-faenza* (1.3.1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jan 23 16:28:27 2020 +0100 (2020-01-23)
parents dab616728814
children 72e35f3c7aa1
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 "High mem corrupted",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 ;typedef unsigned dirsizetype;
35 struc isostate ; struct isostate {
36 curpos dw ? ; 0 unsigned curpos;
37 filename2open dw ? ; 2 char *filename2open;
38 fd dw ? ; 4 int fd;
39 filemod dw ? ; 6 unsigned short filemod;
40 fileofs dd ? ; 8 unsigned long fileofs;
41 filesize dd ? ;12 unsigned long filesize;
42 filename dw ? ;16 char *filename;
43 curdirsize dw ? ;18 dirsizetype curdirsize;
44 dirsize dw ? ;20 dirsizetype dirsize;
45 curdirofs dd ? ;22 unsigned long curdirofs;
46 dirofs dd ? ;26 unsigned long dirofs;
47 ;overlap
48 entrysize dw ? ;30 int entrysize;
49 tmp dw ? ;32 const char *tmp;
50 c db ? ;34 char c;
51 _64bits db ? ;35 char _64bits;
52 buffer db ? ;36 char buffer[2048+512];
53 ends isostate ; } isostate;
54 public _isostate
55 _isostate isostate <?>
56 org $-7
57 endif
58 _xfer_buf db 4096 dup (?)
59 filecnt db ? ; in fact 0 minus file count...
60 nextfilename dw ?
61 ifdef EXTRA
62 ultoabuf db 12 dup (?)
63 endif
65 ends _BSS
67 segment _TEXT byte public use16 'CODE'
69 ;***************************************************************
70 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
71 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
72 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
73 ;***************************************************************
74 ifdef EXTRA
75 global @strcat$qpxzct1:near
76 @strcat$qpxzct1:
77 mov cx,1h
78 db 0bah ; mov dx,imm opcode
79 endif
80 global @strcatb$qpxzct1:near
81 proc @strcatb$qpxzct1 near
83 mov cl,7Fh
84 db 0bah ; mov dx,imm opcode
85 global @strcpy$qpxzct1:near
86 @strcpy$qpxzct1:
87 xor cx,cx
88 push si
89 xchg ax,si ; b
90 jcxz @@nocat
91 dec bx
92 @@catlp:
93 inc bx
94 cmp [byte bx],0 ; a=bx
95 jne @@catlp
96 ifdef EXTRA
97 mov al,20h
98 loop @@cpyhead
99 else
100 db 0b8h,20h ; mov ax,??20h
101 endif
102 @@nocat:
103 @@cpylp:
104 lodsb
105 @@cpyhead:
106 mov [bx],al
107 inc bx
108 or al,al
109 jne @@cpylp
110 strfound:
111 xchg ax,dx
112 strend:
113 pop si
114 ret
116 endp @strcatb$qpxzct1
119 ifdef EXTRA
120 p8086
121 ;***************************************************************
122 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
123 ;***************************************************************
124 global @strstr$qpxzct1:near
125 proc @strstr$qpxzct1 near
127 xchg ax,cx ; b
128 mov dx,bx ; a
129 push si
130 @@loop:
131 xor ax,ax
132 mov si,dx
133 cmp [si],al ; *a
134 jz strend ; return ax = NULL
135 mov bx,cx
136 @@match:
137 or ah,[bx] ; *b
138 jz strfound
139 inc bx
140 lodsb
141 sub ah,al
142 jz @@match
143 inc dx
144 jmp @@loop
146 endp @strstr$qpxzct1
149 ;***************************************************************
150 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
151 ;***************************************************************
152 global @strcmp$qpxzct1:near
153 proc @strcmp$qpxzct1 near
155 push si
156 xchg ax,si
157 dec bx
158 @@lp:
159 inc bx
160 lodsb
161 sub al,[bx]
162 jnz @@out
163 or al,[bx]
164 jnz @@lp
165 @@out:
166 cbw
167 pop si
168 ret
170 endp @strcmp$qpxzct1
171 endif
174 ;***************************************************************
175 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
176 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
177 ;***************************************************************
178 global openargs:near ; openargs(bx)
179 openargs:
180 cmp [byte bx],'@'
181 jne fail
182 inc bx
184 global @open$qpxzc:near
185 proc @open$qpxzc near
187 open: ; open(bx)
188 ifdef LONG_FILENAME
189 mov ax,716Ch
190 push bx si
191 mov si,bx
192 xor bx,bx ; R/O
193 xor cx,cx ; attributes
194 cwd ; action = open
195 stc
196 int 21h
197 pop si bx
198 jnc doret
199 endif
200 mov ax,3d00h ; read-only+compatibility
201 ;mov cl,0 ; attribute mask
202 mov dx,bx
203 jmp dos
205 endp @open$qpxzc
208 ;***************************************************************
209 ;_fastcall int fileexist(bx:const char* name);
210 ;***************************************************************
211 global @fileexist$qpxzc:near
212 @fileexist$qpxzc:
213 call @open$qpxzc
214 jc fail
216 ;***************************************************************
217 ;_fastcall int close(ax:int fd);
218 ;***************************************************************
219 global @close$qi:near
220 proc @close$qi near
222 global close:near ; close(ax)
223 close:
224 xchg ax,bx
225 mov ah,3Eh
226 or bx,bx
227 jnz dos
228 ret
230 endp @close$qi
233 ;***************************************************************
234 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
235 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
236 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
237 ;***************************************************************
238 global @readrm$qp11image_himemi:near
239 @readrm$qp11image_himemi:
240 xchg ax,dx ; sz
241 mov ax,[bx] ; fd
242 mov bx,[bx-2] ; data
243 global @read$qipvi:near
244 proc @read$qipvi near
246 ifdef WRITE
247 stc
248 db 0B0h ; mov al,im
249 global @write$qipvi:near
250 @write$qipvi:
251 clc
252 endif
253 @read$dxbxax:
254 xchg ax,bx ; fd
255 xchg ax,dx ; data
256 xchg ax,cx ; sz
257 ifdef WRITE
258 mov ah,40h
259 sbb ah,0
260 else
261 global @read$cxdxbx:near
262 @read$cxdxbx:
263 mov ah,3Fh
264 endif
265 jcxz fail
266 dos:
267 int 21h
268 chkc:
269 jnc doret
270 fail:
271 stc
272 failifc:
273 sbb ax,ax ; ax=-1 CF
274 cwd
275 doret:
276 ifndef NO386
277 push dx ; see next_chunk:lseek
278 push ax
279 pop eax
280 endif
281 ret
283 endp @read$qipvi
285 ;***************************************************************
286 ;_fastcall long rewind(ax:int fd);
287 ;***************************************************************
289 global @rewind$qi:near ; fd=ax
290 proc @rewind$qi near
292 ifdef EXTRA ; catch ISO image case
293 stc
294 mov dx,-512 ; curpos = 512, see LOAD.CPP
295 mov bl,1
296 jmp lseekword
297 endif
298 rewind: ; rewind(ax)
299 mov bl,0
300 lseek0: ; lseek0(ax,bl=dir)
301 xor dx,dx ; clear C
302 lseekword:
303 sbb cx,cx
304 lseekset:
305 xchg ax,bx
306 lseek:
307 mov ah,42h ; bx=fd cx:dx=offset al=whence
308 jmp dos
310 endp @rewind$qi
312 ifdef EXTRA
313 ;***************************************************************
314 ;_fastcall long isolseek(bx:const unsigned long *offset);
315 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* offset);
316 ;***************************************************************
317 global @isolseek$qpxul:near
318 proc @isolseek$qpxul near
320 isolseek:
321 mov ax,[_isostate.fd]
322 global @lseekset2$qipul:near
323 @lseekset2$qipul:
324 les dx,[dword bx]
325 mov cx,es
326 mov bl,0
327 jmp lseekset
329 endp @isolseek$qpxul
331 ;***************************************************************
332 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
333 ;***************************************************************
334 global @isoreadsector$qpxul:near
335 proc @isoreadsector$qpxul near
337 call isolseek
338 jc doret
339 mov dx,2560
340 mov bx,offset _isostate.buffer
341 mov ax,[_isostate.fd]
342 jmp @read$dxbxax ; read(fd,buffer,2560)
344 endp @isoreadsector$qpxul
347 ;***************************************************************
348 ;_fastcall int isoreset(bx:const char *name);
349 ;***************************************************************
350 global @isoreset$qpzc:near
351 proc @isoreset$qpzc near
353 or bx,bx
354 jz fail
355 call near ptr @open$qpxzc
356 mov [_isostate.fd],ax
357 extrn @isoroot$qv:near
358 jmp @isoroot$qv
360 endp @isoreset$qpzc
363 ;***************************************************************
364 ;_fastcall int isoopen(bx:const char *name);
365 ;***************************************************************
366 global @isoopen$qpxzc:near
367 proc @isoopen$qpxzc near
369 extrn @_isoopen$qv:near
370 mov [_isostate.filename2open],bx
371 jmp @_isoopen$qv
373 endp @isoopen$qpxzc
375 endif
378 ifdef USE_ARGSTR
379 ;***************************************************************
380 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
381 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
382 ;***************************************************************
383 global @argstr$qpxzcxt1ppxzc:near
384 proc @argstr$qpxzcxt1ppxzc near
386 mov cl,2
387 db 0a9h ; test ax,#
388 global @argnum$qpzcxpxzcpul:near
389 @argnum$qpzcxpxzcpul:
390 mov cl,4
391 xchg ax,bx ; keywords -> bx
392 xchg ax,cx ; s -> cx
393 cbw ; argstr:0002 argnum:0004
394 xchg ax,dx ; vars -> ax
395 push si di
396 xchg ax,di ; vars => di
397 dec bx
398 @@testalt:
399 mov al,-1
400 sub di,dx
401 @@test:
402 cmp al,'='
403 je @@found
404 cmp al,0 ; eos, si=next argv
405 je @@found
406 mov si,cx ; s
407 add di,dx
408 @@match:
409 inc bx ; keywords++
410 lodsb ; *s++
411 or al,20h
412 cmp al,[bx]
413 je @@match
414 cmp al,'/' ; 2f
415 jne @@notopt
416 cmp [byte bx],'-'
417 je @@match
418 @@notopt:
419 ifdef EXTRA
420 cmp [byte bx],'/'
421 je @@testalt
422 endif
423 cmp [byte bx],'|'
424 je @@test
425 inc bx
426 cmp [byte bx-1],0
427 jne @@notopt
428 stc
429 jmp @@nokeyword
430 @@found:
431 mov [di],si
432 dec dx
433 dec dx
434 je @@done
435 ;mov bx,si
436 call @strtol$qpxzc
437 mov [di],ax
438 mov [di+2],dx
439 @@done:
440 clc
441 @@nokeyword:
442 sbb ax,ax
443 pop di si
444 ret
446 endp @argstr$qpxzcxt1ppxzc
448 else
450 ;***************************************************************
451 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
452 ;***************************************************************
453 global @strhead$qpxzct1:near
454 proc @strhead$qpxzct1 near
456 @@loop:
457 xchg ax,bx
458 mov cl,[bx] ; cl = *b++
459 inc bx
460 or cl,cl ; clear C
461 jz failifc ; return 0
462 xchg ax,bx
463 xor cl,[bx] ; cl -= *a++
464 inc bx
465 and cl,0dfh ; case insensitive
466 jne fail ; return -1
467 jmp @@loop
469 endp @strhead$qpxzct1
471 endif
473 include "himem.inc"
475 ;***************************************************************
476 ;_fastcall char* malloc_or_die(ax:unsigned size);
477 ;***************************************************************
478 xchg_heap_top:
479 xchg ax,[bx]
480 ret
482 global @malloc_or_die$qui:near
483 proc @malloc_or_die$qui near
485 global malloc_or_die:near ; ax = malloc_or_die(ax)
486 malloc_or_die:
487 extrn _heap_top
488 mov bx,offset _heap_top
489 add ax,[bx]
490 jnc xchg_heap_top
491 mov bx,offset msg_malloc
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 cl,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 xor cx,cx
1168 lodsb
1169 or al,20h
1170 cmp al,'a'
1171 jb @@notvga
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 cl,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 ############################################