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

Up libcomerr (1.44.5)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 24 12:15:02 2020 +0100 (2020-01-24)
parents 526e82fe0471
children 56ee356284c6
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 mov bh,3Eh
225 dosbx:
226 xchg ax,bx
227 or bx,bx
228 jnz dos
229 ret
231 endp @close$qi
234 ;***************************************************************
235 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
236 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
237 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
238 ;***************************************************************
239 global @readrm$qp11image_himemi:near
240 @readrm$qp11image_himemi:
241 xchg ax,dx ; sz
242 mov ax,[bx] ; fd
243 mov bx,[bx-2] ; data
244 global @read$qipvi:near
245 proc @read$qipvi near
247 ifdef WRITE
248 stc
249 db 0B0h ; mov al,im
250 global @write$qipvi:near
251 @write$qipvi:
252 clc
253 endif
254 @read$dxbxax:
255 xchg ax,bx ; fd
256 xchg ax,dx ; data
257 xchg ax,cx ; sz
258 ifdef WRITE
259 mov ah,40h
260 sbb ah,0
261 else
262 global @read$cxdxbx:near
263 @read$cxdxbx:
264 mov ah,3Fh
265 endif
266 jcxz fail
267 dos:
268 int 21h
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 mov bh,42h ; bx=fd cx:dx=offset al=whence
306 jmp dosbx
308 endp @rewind$qi
310 ifdef EXTRA
311 ;***************************************************************
312 ;_fastcall void isolseek(bx:const unsigned long *offset);
313 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* offset);
314 ;***************************************************************
315 global @isolseek$qpxul:near
316 proc @isolseek$qpxul near
318 isolseek:
319 mov ax,[_isostate.fd]
320 global @lseekset2$qipul:near
321 @lseekset2$qipul:
322 les dx,[dword bx]
323 mov cx,es
324 mov bl,0
325 jmp lseekset
327 endp @isolseek$qpxul
329 ;***************************************************************
330 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
331 ;***************************************************************
332 global @isoreadsector$qpxul:near
333 proc @isoreadsector$qpxul near
335 call isolseek
336 jc fail
337 mov dx,2560
338 mov bx,offset _isostate.buffer
339 mov ax,[_isostate.fd]
340 jmp @read$dxbxax ; read(fd,buffer,2560)
342 endp @isoreadsector$qpxul
345 ;***************************************************************
346 ;_fastcall int isoreset(bx:const char *name);
347 ;***************************************************************
348 global @isoreset$qpzc:near
349 proc @isoreset$qpzc near
351 or bx,bx
352 jz fail
353 call near ptr @open$qpxzc
354 mov [_isostate.fd],ax
355 extrn @isoroot$qv:near
356 jmp @isoroot$qv
358 endp @isoreset$qpzc
361 ;***************************************************************
362 ;_fastcall int isoopen(bx:const char *name);
363 ;***************************************************************
364 global @isoopen$qpxzc:near
365 proc @isoopen$qpxzc near
367 extrn @_isoopen$qv:near
368 mov [_isostate.filename2open],bx
369 jmp @_isoopen$qv
371 endp @isoopen$qpxzc
373 endif
376 ifdef USE_ARGSTR
377 ;***************************************************************
378 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
379 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
380 ;***************************************************************
381 global @argstr$qpxzcxt1ppxzc:near
382 proc @argstr$qpxzcxt1ppxzc near
384 mov cl,2
385 db 0a9h ; test ax,#
386 global @argnum$qpzcxpxzcpul:near
387 @argnum$qpzcxpxzcpul:
388 mov cl,4
389 xchg ax,bx ; keywords -> bx
390 xchg ax,cx ; s -> cx
391 cbw ; argstr:0002 argnum:0004
392 xchg ax,dx ; vars -> ax
393 push si di
394 xchg ax,di ; vars => di
395 dec bx
396 @@testalt:
397 mov al,-1
398 sub di,dx
399 @@test:
400 cmp al,'='
401 je @@found
402 cmp al,0 ; eos, si=next argv
403 je @@found
404 mov si,cx ; s
405 add di,dx
406 @@match:
407 inc bx ; keywords++
408 lodsb ; *s++
409 or al,20h
410 cmp al,[bx]
411 je @@match
412 cmp al,'/' ; 2f
413 jne @@notopt
414 cmp [byte bx],'-'
415 je @@match
416 @@notopt:
417 ifdef EXTRA
418 cmp [byte bx],'/'
419 je @@testalt
420 endif
421 cmp [byte bx],'|'
422 je @@test
423 inc bx
424 cmp [byte bx-1],0
425 jne @@notopt
426 stc
427 jmp @@nokeyword
428 @@found:
429 mov [di],si
430 dec dx
431 dec dx
432 je @@done
433 ;mov bx,si
434 call @strtol$qpxzc
435 mov [di],ax
436 mov [di+2],dx
437 @@done:
438 clc
439 @@nokeyword:
440 sbb ax,ax
441 pop di si
442 ret
444 endp @argstr$qpxzcxt1ppxzc
446 else
448 ;***************************************************************
449 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
450 ;***************************************************************
451 global @strhead$qpxzct1:near
452 proc @strhead$qpxzct1 near
454 @@loop:
455 xchg ax,bx
456 mov cl,[bx] ; cl = *b++
457 inc bx
458 or cl,cl ; clear C
459 jz failifc ; return 0
460 xchg ax,bx
461 xor cl,[bx] ; cl -= *a++
462 inc bx
463 and cl,0dfh ; case insensitive
464 jne fail ; return -1
465 jmp @@loop
467 endp @strhead$qpxzct1
469 endif
471 include "himem.inc"
473 ;***************************************************************
474 ;_fastcall char* malloc_or_die(ax:unsigned size);
475 ;***************************************************************
476 xchg_heap_top:
477 xchg ax,[bx]
478 ret
480 global @malloc_or_die$qui:near
481 proc @malloc_or_die$qui near
483 global malloc_or_die:near ; ax = malloc_or_die(ax)
484 malloc_or_die:
485 extrn _heap_top
486 mov bx,offset _heap_top
487 add ax,[bx]
488 jnc xchg_heap_top
489 mov bx,offset msg_malloc
491 endp @malloc_or_die$qui
494 ;***************************************************************
495 ;_fastcall int die(bx:const char* msg);
496 ;int exit(ax:int status);
497 ;int abort(void);
498 ;***************************************************************
499 global @die$qpxzc:near
500 proc @die$qpxzc near
501 @die$qpxzc:
502 global die:near ; die(bx)
503 die:
504 call puts
505 global @exit$qv:near
506 @exit$qv:
507 _exit:
508 extrn _imgs:image_himem
509 mov cx,[(word _imgs.buf)+2] ; no_exit ?
510 mov ah,4Ch
511 jcxz do_int21h
512 mov bx, offset msg_hang
513 call puts
514 ; global _abort:near
515 _abort:
516 cli
517 hlt
518 jmp _abort
520 endp @die$qpxzc
522 ;***************************************************************
523 ;_fastcall void puts(bx:const char* s):
524 ;***************************************************************
525 global @puts$qpxzc:near
527 ; global puts:near ; puts(bx)
528 @putsz:
529 call @putc
530 @puts$qpxzc:
531 puts:
532 mov dl,[bx]
533 inc bx
534 or dl,dl
535 jne @putsz
536 mov dl,10
537 @putc:
538 cmp dl,10
539 jne @putcz
540 call @putcz2
541 @putcz2:
542 xor dl,7 ; 10^13 1010^1101
543 @putcz:
544 mov ah,2
545 do_int21h:
546 int 21h
547 ret
550 ;***************************************************************
551 ;static long next_chunk(struct image_himem *di);
552 ;***************************************************************
553 proc next_chunk near
555 push si
556 mov ax,[(image_himem di).fd]
557 call close
558 ifndef NO386
559 xor eax,eax
560 else
561 xor ax,ax
562 cwd
563 endif
564 mov [(image_himem di).fd],ax
565 mov bx,[(image_himem di).state]
566 cmp al,[bx] ; ""
567 jz @@end
568 mov si,bx
569 @@scan:
570 lodsb
571 mov cx,si
572 cmp al,','
573 jz @@eos
574 or al,al
575 jnz @@scan
576 dec cx
577 @@eos:
578 mov [(image_himem di).state],cx
579 dec si
580 push [word si]
581 mov [byte si],ah ; set temp eos
582 call open
583 pop [word si] ; restore string
584 jc jcdie
585 mov [(image_himem di).fd],ax
586 mov [(image_himem di).fd2close],ax
587 mov bl,02h ; SEEK_END
588 call lseek0
589 jcdie:
590 mov bx,[(image_himem di).errmsg]
591 jc die
592 ifndef NO386
593 push eax
594 mov ax,[(image_himem di).fd]
595 call rewind
596 pop eax
597 @@end:
598 mov [(image_himem di).chunk_size],eax
599 else
600 push ax
601 push dx
602 mov ax,[(image_himem di).fd]
603 call rewind
604 pop dx
605 pop ax
606 @@end:
607 mov [word (image_himem di).chunk_size],ax
608 mov [word ((image_himem di).chunk_size)+2],dx
609 endif
610 pop si
611 ret
613 endp next_chunk
616 ifdef LARGE_IMAGES
617 struc data_himem ;struct data_himem {
618 first dd ? ; 0 u32 first;
619 cacheidx dw ? ; 4 int cacheidx;
620 pageidx dw ? ; 6 int pageidx;
621 cache dd 1024 dup(?) ; 8 int cache;
622 page dd 1024 dup(?) ;4104 int page;
623 ends data_himem ;}; // size=8200
624 endif
626 ;***************************************************************
627 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
628 ;***************************************************************
629 global @malloc_bufv_or_die$qp11image_himem:near
630 proc @malloc_bufv_or_die$qp11image_himem near
632 p386
633 push si
634 mov si,bx
635 ifdef LARGE_IMAGES
636 movzx eax,[word ((image_himem si).size) + 2]
637 shr ax,4 ; pages index size = size >> 20
638 add ax,8+4096+8
639 call malloc_or_die
640 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
641 add ecx,[(image_himem si).size]
642 shr ecx,12
643 mov [curdata],ax
644 else
645 mov eax,[(image_himem si).size]
646 dec eax
647 shr eax,12
648 inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
649 push ax
650 inc ax ; cnt+1
651 shl ax,2 ; bufv => vcpi => vm86
652 ; our malloc zeroes allocated mem: bufv[cnt]=0;
653 ; Allocate pages, storing addrs in addrbuf
654 call malloc_or_die
655 pop cx
656 push ax
657 endif
658 mov [(image_himem si).bufv],ax
659 xchg ax,si
660 @@vcpi_alloc:
661 mov ax,0DE04h
662 int 67h
663 or ah,ah
664 stc
665 mov bx,offset vcpi_alloc_err
666 jnz jcdie
667 ; for (i = cnt-1; i >= 0; i--)
668 ifdef LARGE_IMAGES
669 mov eax,ecx
670 dec eax
671 else
672 mov ax,cx
673 dec ax
674 cwde
675 endif
676 shl eax,12 ; i*_4k
677 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
678 mov bx,offset _imgs.fallback
679 push eax
680 add eax,[bx-2+2]
681 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
682 pop eax ; i*_4k
683 jbe @@pmok
684 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
685 jae @@vcpi_alloc
686 @@pmok:
687 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
688 mov bx,offset _imgs.fallback+32
689 add eax,[bx-2+2] ; +initrd.fallback
690 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
691 ja @@initrdok
692 mov eax,[bx-2+6] ; initrd.size
693 add eax,[bx-2+2] ; +initrd.fallback
694 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
695 @@jnc_vcpi_alloc:
696 ja @@vcpi_alloc
697 @@initrdok:
698 ifdef LARGE_IMAGES
699 cmp [(data_himem si).first],0
700 jne @@notfirst
701 mov [(data_himem si).first],edx
702 @@notfirst:
703 mov bx,[(data_himem si).cacheidx]
704 cmp bh,4
705 jae @@nextpage
706 shl bx,2
707 inc [(data_himem si).cacheidx]
708 mov [(data_himem bx+si).cache],edx
709 loopd @@vcpi_alloc
710 mov [(data_himem bx+si).cache],ecx ; last is 0
711 @@nextpage:
712 and [(data_himem si).cacheidx],0
713 mov bx,[(data_himem si).pageidx]
714 mov [(data_himem bx+si).page],edx
715 add [(data_himem si).pageidx],4
716 push cx
717 lea cx,[(data_himem si).cache]
718 ifdef NO386
719 push edx
720 pop dx
721 pop ax
722 endif
723 call storepage ; storepage(edx,cx)
724 pop cx
725 or ecx,ecx ; clear C
726 jnz @@jnc_vcpi_alloc
727 mov [dword (data_himem si).cacheidx],ecx
728 xchg ax,si
729 else
730 mov [si],edx
731 lodsd ; si=+4
732 loop @@vcpi_alloc
733 pop ax
734 endif
735 pop si
736 ret
737 ifdef NO386
738 p8086
739 endif
741 endp @malloc_bufv_or_die$qp11image_himem
744 ;***************************************************************
745 ;_fastcall void memcpy_image(bx:struct image_himem *m);
746 ;***************************************************************
747 global @memcpy_image$qp11image_himem:near
748 proc @memcpy_image$qp11image_himem near
750 ifndef NO386
751 mov edx,[(image_himem bx).fallback]
752 mov eax,[(image_himem bx).buf]
753 cmp eax,edx ; if (m->fallback != m->buf)
754 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
755 ifdef LARGE_IMAGES
756 mov ecx,[(image_himem bx).size]
757 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
758 push ecx
759 else
760 push [(image_himem bx).size]
761 endif
762 push eax
763 push 0
764 call_memcpy32:
765 push edx
766 else
767 les ax,[dword ((image_himem bx).fallback)]
768 mov dx,es
769 mov cx,[word ((image_himem bx).buf)]
770 cmp ax,cx ; if (m->fallback != m->buf)
771 jnz @@do
772 cmp dx,[word ((image_himem bx).buf)+2]
773 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
774 @@do:
775 push [word ((image_himem bx).size)+2]
776 push [word ((image_himem bx).size)]
777 push [word ((image_himem bx).buf)+2]
778 push cx
779 xor cx,cx
780 push cx
781 call_memcpy32:
782 push dx
783 push ax
784 ifdef LARGE_IMAGES
785 jmp @@memcpy
786 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
787 p386
788 push ecx
789 push eax
790 push 0
791 push edx
792 ifdef NO386
793 p8086
794 endif
795 endif
796 endif
797 @@memcpy:
798 extrn memcpy32:near
799 call near memcpy32
800 @@skip:
801 ret
803 endp @memcpy_image$qp11image_himem
805 ;***************************************************************
806 ;_fastcall void storepage(bx:u32 *dst);
807 ;***************************************************************
808 global @storepage$qpul:near
809 proc @storepage$qpul near
811 ifndef NO386
812 mov edx,[bx]
813 else
814 les ax,[dword bx]
815 mov dx,es
816 endif
817 mov cx,offset _xfer_buf
818 storepage: ; storepage(edx,cx)
819 ifndef NO386
820 push 0
821 push 4096
822 push 0
823 else
824 xor bx,bx
825 push bx
826 mov bh,4096/256
827 push bx
828 xor bx,bx
829 push bx
830 endif
831 push cx
832 push ds
833 jmp call_memcpy32
835 endp @storepage$qpul
838 ifdef LARGE_IMAGES
839 p386
840 ;***************************************************************
841 ;_fastcall void reset_bufv(bx:u32 *p);
842 ;***************************************************************
843 global @reset_bufv$qpul:near
844 proc @reset_bufv$qpul near
846 mov [curdata],bx
847 and [dword (data_himem bx).cacheidx],0
848 ret
850 endp @reset_bufv$qpul
852 ;***************************************************************
853 ;u32* prev_bufv();
854 ;u32* prev_bufv();
855 ;***************************************************************
856 global _prev_bufv:near
857 global _next_bufv:near
858 proc _prev_bufv near
860 stc
861 db 73h ; jnc
862 _next_bufv:
863 clc
864 push si
865 mov si,0
866 org $-2
867 curdata dw ?
868 sbb ax,ax
869 cmc
870 adc ax,[(data_himem si).cacheidx] ; -1/+1
871 xor ecx,ecx
872 test ax,0fc00h
873 jz @@gotpage
874 push ax ; FFFF / 0400
875 sar ax,8 ; FFFC / 0004
876 and al,0fch
877 add [(data_himem si).pageidx],ax
878 mov bx,[(data_himem si).pageidx]
879 lea bx,[(data_himem bx+si).page]
880 mov edx,ds
881 shl edx,4
882 lea cx,[(data_himem si).cache]
883 add edx,ecx
884 mov eax,[bx]
885 or eax,eax
886 jnz @@pageok
887 pop ax
888 xchg ax,bx
889 pop si
890 ret
891 @@pageok:
892 mov cx,4096
893 call memcpy_imagez ; get page
894 pop ax ; FFFF / 0400
895 cbw
896 shr ax,6 ; 03FF / 0000
897 @@gotpage:
898 mov [(data_himem si).cacheidx],ax
899 shl ax,2
900 xchg ax,bx
901 lea ax,[(data_himem bx+si).cache]
902 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
903 jnz @@notfirst2
904 xchg ax,si ; &first
905 @@notfirst2:
906 pop si
907 ret
909 endp _prev_bufv
910 endif
912 ifdef NO386
913 p8086
914 endif
916 ;***************************************************************
917 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
918 ;***************************************************************
920 global @open_image$qp11image_himempxzc:near
921 proc @open_image$qp11image_himempxzc near
923 push di
924 xchg ax,bx
925 xchg ax,di
926 ifdef EXTRA
927 cmp [(image_himem di).fd],0 ; iso image/kernel ?
928 jnz @@alreadydone
929 endif
930 mov [(image_himem di).state],bx
931 push bx
932 ifdef EXTRA
933 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
934 jnz @@next
935 mov [(image_himem di).next_chunk],offset next_chunk
936 @@next:
937 ;push di
938 call [(image_himem di).next_chunk] ; m->next_chunk()
939 ;pop di
940 else
941 @@next:
942 call next_chunk
943 endif
944 ifndef NO386
945 add eax,3
946 and al,0FCh
947 add [(image_himem di).size],eax ; m->size += m->chunk_size
948 or eax,eax
949 else
950 add ax,3
951 adc dx,0
952 and al,0FCh
953 add [word (image_himem di).size],ax ; m->size += m->chunk_size
954 adc [word ((image_himem di).size)+2],dx
955 or ax,dx
956 endif
957 jnz @@next
958 pop [(image_himem di).state]
959 ifdef EXTRA
960 ;push di
961 call [(image_himem di).next_chunk] ; m->next_chunk()
962 ;pop di
963 else
964 call next_chunk
965 endif
966 @@alreadydone:
967 pop di
968 ret
970 endp @open_image$qp11image_himempxzc
973 ;***************************************************************
974 ;_fastcall int read_image(bx:struct image_himem *m);
975 ;***************************************************************
976 global @read_image$qp11image_himem:near
977 proc @read_image$qp11image_himem near
979 push si di
980 mov di,bx
981 mov si,4096
982 push si ; original size
983 @@loop:
984 ifndef NO386
985 movzx ecx,si
986 mov eax,[(image_himem di).chunk_size]
987 cmp ecx,eax
988 jb @@szok
989 else
990 mov cx,si
991 mov ax,[word (image_himem di).chunk_size]
992 cmp cx,ax
993 jb @@szok
994 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
995 jne @@szok
996 endif
997 xchg ax,cx
998 @@szok:
999 jcxz image_done
1000 mov dx,offset _xfer_buf+4096
1001 sub dx,si
1002 mov bx,[di]
1003 call @read$cxdxbx
1004 jbe image_done
1005 xor cx,cx
1006 cwd ; ax < 8000h
1007 ifndef NO386
1008 cwde ; ax < 8000h
1009 sub [(image_himem di).chunk_size],eax
1010 xchg eax,ebx
1011 else
1012 sub [word (image_himem di).chunk_size],ax
1013 xchg ax,bx
1014 sbb [word ((image_himem di).chunk_size)+2],dx
1015 jnz @@fill
1016 cmp [word (image_himem di).chunk_size],dx
1017 endif
1018 jnz @@fill
1019 dec cx
1020 @@fill:
1021 test bl,3
1022 je @@filled
1023 mov [bx+_xfer_buf],dh
1024 inc bx
1025 jmp @@fill
1026 @@filled:
1027 ifndef NO386
1028 sub [(image_himem di).remaining],ebx
1029 else
1030 sub [word (image_himem di).remaining],bx
1031 sbb [word ((image_himem di).remaining)+2],dx
1032 endif
1033 sub si,bx
1034 pushf
1035 ifdef EXTRA
1036 and cx,[(image_himem di).next_chunk]
1037 jcxz @@same_chunk
1038 push di
1039 call cx
1040 pop cx
1041 else
1042 jcxz @@same_chunk
1043 call next_chunk
1044 endif
1045 @@same_chunk:
1046 popf
1047 jnz @@loop
1048 image_done:
1049 pop ax ; original size
1050 sub ax,si
1051 pop di si
1052 ret
1054 endp @read_image$qp11image_himem
1057 ;***************************************************************
1058 ;_fastcall unsigned long strtol(const char *s);
1059 ;***************************************************************
1060 ifndef USE_ARGSTR
1061 global @strtol$qpxzc:near
1062 endif
1063 proc @strtol$qpxzc near
1065 ifndef NO386
1066 ifndef USE_ARGSTR
1067 push si
1068 mov si,bx
1069 endif
1070 xor ecx,ecx
1071 xor eax,eax
1072 xor ebx,ebx
1073 or si,si
1074 jz @@end
1075 lodsb
1076 or al,20h
1077 cmp al,'a'
1078 jb @@notvga
1079 sub al,'n'
1080 @@vgaloop:
1081 dec cx
1082 add al,6
1083 jb @@vgaloop ; vga=normal,extended,ask
1084 @@vga:
1085 dec cx
1086 xchg ax,cx
1087 cwd
1088 jmp @@popsiret
1089 @@notvga:
1090 mov cl,10 ; radix
1091 cmp al,'-'
1092 ja @@radixkeep
1093 cmc ; '+'=2B:C=0 '-'=2D:C=1
1094 lodsb
1095 @@radixkeep:
1096 pushf
1097 cmp al,'0'
1098 jne @@radixok
1099 mov cl,8
1100 lodsb
1101 or al,20h
1102 cmp al,'x'
1103 jne @@radixok
1104 mov cl,16
1105 @@strtollp:
1106 lodsb
1107 @@radixok:
1108 or al,20h
1109 sub al,'0'
1110 jb @@endstrtol
1111 cmp al,9
1112 jbe @@digitok
1113 cmp al,'a'-'0'
1114 jb @@endstrtol
1115 sub al,'a'-'0'-10
1116 @@digitok:
1117 cmp al,cl
1118 jae @@endstrtol
1119 xchg eax,ebx
1120 mul ecx
1121 add eax,ebx
1122 xchg eax,ebx
1123 jmp @@strtollp
1124 @@endstrtol:
1125 mov cl,10
1126 cmp al,'k'-'a'+10
1127 je @@shift
1128 mov cl,20
1129 cmp al,'m'-'a'+10
1130 je @@shift
1131 mov cl,30
1132 cmp al,'g'-'a'+10
1133 jne @@noshift
1134 @@shift:
1135 shl ebx,cl
1136 @@noshift:
1137 popf
1138 jnc @@end
1139 neg ebx
1140 @@end:
1141 push ebx
1142 pop ax
1143 pop dx
1144 @@popsiret:
1145 ifndef USE_ARGSTR
1146 pop si
1147 endif
1148 else
1149 ifndef USE_ARGSTR
1150 push si di
1151 xor ax,ax
1152 cwd
1153 or bx,bx
1154 else
1155 push di
1156 xor ax,ax
1157 cwd
1158 or si,si
1159 endif
1160 jz @@goend
1161 xchg ax,di
1162 ifndef USE_ARGSTR
1163 mov si,bx
1164 endif
1165 xor cx,cx
1166 lodsb
1167 or al,20h
1168 cmp al,'a'
1169 jb @@notvga
1170 sub al,'n'
1171 @@vgaloop:
1172 dec cx
1173 add al,6
1174 jb @@vgaloop ; vga=normal,extended,ask
1175 @@vga:
1176 xchg ax,cx
1177 @@goend:
1178 jmp @@popdisiret
1179 @@notvga:
1180 mov cl,10 ; radix
1181 cmp al,'-'
1182 ja @@radixkeep
1183 cmc ; '+'=2B:C=0 '-'=2D:C=1
1184 lodsb
1185 @@radixkeep:
1186 pushf
1187 cmp al,'0'
1188 jne @@radixok
1189 mov cl,8
1190 lodsb
1191 or al,20h
1192 cmp al,'x'
1193 jne @@radixok
1194 mov cl,16
1195 @@strtollp:
1196 lodsb
1197 @@radixok:
1198 or al,20h
1199 sub al,'0'
1200 jb @@endstrtol
1201 cmp al,9
1202 jbe @@digitok
1203 cmp al,'a'-'0'
1204 jb @@endstrtol
1205 sub al,'a'-'0'-10
1206 @@digitok:
1207 cmp al,cl
1208 jae @@endstrtol
1210 push ax
1211 push dx
1212 xchg ax,bx
1213 mul cx
1214 xchg ax,bx
1215 xchg ax,dx
1216 xchg ax,di
1217 pop ax
1218 mul cx
1219 add ax,di
1220 xchg ax,dx
1221 pop ax
1222 mov ah,0
1223 add bx,ax
1224 adc dx,0
1226 jmp @@strtollp
1227 @@endstrtol:
1228 mov cl,10
1229 cmp al,'k'-'a'+10
1230 je @@shift
1231 mov cl,20
1232 cmp al,'m'-'a'+10
1233 je @@shift
1234 mov cl,30
1235 cmp al,'g'-'a'+10
1236 jne @@noshift
1237 @@shift:
1238 rcl di,1
1239 shl dx,1
1240 loop @@shift
1241 @@noshift:
1242 popf
1243 jnc @@end
1244 not dx
1245 neg bx
1246 jne @@end
1247 inc dx
1248 @@end:
1249 xchg ax,bx
1250 @@popdisiret:
1251 ifndef USE_ARGSTR
1252 pop di si
1253 else
1254 pop di
1255 endif
1256 endif
1257 strtol_ret:
1258 ret
1260 endp @strtol$qpxzc
1263 ifdef USE_ARGSTR
1264 ;***************************************************************
1265 ;_fastcall void set_cmdline(bx:const char *filename);
1266 ;***************************************************************
1267 global @set_cmdline$qpxzc:near
1268 proc @set_cmdline$qpxzc near
1269 call openargs
1270 jc strtol_ret
1271 mov cx,4096
1272 mov di,[_heap_top]
1273 extrn read_cmdline:near
1274 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1276 endp @set_cmdline$qpxzc
1277 endif
1280 ifdef NO386
1281 ;***************************************************************
1282 ;u16 topseg();
1283 ;***************************************************************
1284 global _topseg:near
1285 proc _topseg near
1287 int 12h
1288 jnc @@max640k
1289 mov ax,640 ; 9000
1290 @@max640k:
1291 dec ax
1292 and al,0C0h
1293 mov cl,6
1294 shl ax,cl
1295 ret
1297 endp _topseg
1298 endif
1300 ifdef EXTRA
1301 p8086
1302 ;***************************************************************
1303 ;_fastcall char *ultoa(axdx:unsigned long n);
1304 ;***************************************************************
1305 global @ultoa$qul:near
1306 proc @ultoa$qul near
1308 xchg ax,cx
1309 xchg ax,dx ; AX:CX = n
1310 push si
1311 mov si,10
1312 mov bx,offset ultoabuf+11
1313 @@loop:
1314 dec bx
1315 xor dx,dx
1316 div si ; DX:AX = 0000:hi(n)
1317 xchg ax,cx ; CX = hi(n)/10
1318 div si ; DX:AX = hi(n)%10:lo(n)
1319 xchg ax,cx ; CX = lo(n/10)
1320 ; AX = hi(n)/10 = hi(n/10)
1321 mov [byte bx],'0'
1322 add [bx],dl ; DL = n%10
1323 mov dx,ax
1324 or dx,cx
1325 jnz @@loop
1326 xchg ax,bx
1327 pop si
1328 ret
1330 endp @ultoa$qul
1333 ;***************************************************************
1334 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1335 ;***************************************************************
1336 global @kver2ul$qpzc:near
1337 proc @kver2ul$qpzc near
1339 push si
1340 mov si,bx
1341 xor bx,bx
1342 mov cx,304h
1343 @@number:
1344 xor ax,ax
1345 cwd
1346 @@digit:
1347 shl al,cl
1348 shl ax,cl
1349 lodsb
1350 sub al,30h
1351 cmp al,9
1352 jbe @@digit
1353 mov dl,bh
1354 mov bh,bl
1355 mov bl,ah
1356 dec ch
1357 jnz @@number
1358 xchg ax,bx
1359 pop si
1360 kver2ulret:
1361 ret
1363 endp @kver2ul$qpzc
1365 endif
1367 ;***************************************************************
1368 ;void try_default_args();
1369 ;***************************************************************
1370 ifdef EXTRA
1372 global _try_default_args:near
1373 proc _try_default_args near
1375 mov bx,offset tazboot_cmd
1376 call open
1377 jc kver2ulret
1378 mov cx,4096
1379 mov di,[_heap_top]
1380 extrn read_cmdline:near
1381 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1383 endp _try_default_args
1385 endif
1387 ends _TEXT
1389 end
1391 ;###### END OF FILE ############################################