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