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

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