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

tazboot: spare 2k
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 14 17:17:16 2019 +0200 (4 months ago)
parents 6460d542c35a
children 8b9f768b711e
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
19 global _heap_top
20 extrn _bss_end
21 _heap_top dw _bss_end
22 msg_hang db "High mem corrupted - not exiting to DOS"
23 msg_lf db 10,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 fd dw ? ; 0 int fd;
38 filemod dw ? ; 2 unsigned short filemod;
39 fileofs dd ? ; 4 unsigned long fileofs;
40 filesize dd ? ; 8 unsigned long filesize;
41 filename dw ? ;12 char *filename;
42 curdirsize dw ? ;14 dirsizetype curdirsize;
43 dirsize dw ? ;16 dirsizetype dirsize;
44 curdirofs dd ? ;18 unsigned long curdirofs;
45 dirofs dd ? ;22 unsigned long dirofs;
46 curpos dw ? ;26 unsigned curpos;
47 filename2open dw ? ;28 char *filename2open;
48 entrysize dw ? ;30 int entrysize;
49 tmp dw ? ;32 const char *tmp;
50 ;buffer label ;34 char buffer[2048+512];
51 ends ; } isostate;
52 public _isostate
53 _isostate isostate <?>
54 endif
55 _xfer_buf db 4096 dup (?)
56 global _no_exit:byte
57 _no_exit db ?
58 filecnt db ? ; in fact 0 minus file count...
59 nextfilename dw ?
60 ifdef LARGE_IMAGES
61 curdata dw ?
62 endif
63 ifdef EXTRA
64 ultoabuf db 12 dup (?)
65 endif
67 ends _BSS
69 segment _TEXT byte public use16 'CODE'
71 ;***************************************************************
72 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
73 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
74 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
75 ;***************************************************************
76 ifdef EXTRA
77 global @strcat$qpxzct1:near
78 @strcat$qpxzct1:
79 mov cx,1h
80 db 0bah ; mov dx,imm opcode
81 endif
82 global @strcatb$qpxzct1:near
83 proc @strcatb$qpxzct1 near
85 ifdef EXTRA
86 mov cl,7Fh
87 db 0bah ; mov dx,imm opcode
88 global @strcpy$qpxzct1:near
89 @strcpy$qpxzct1:
90 xor cx,cx
91 endif
92 push si
93 xchg ax,si ; b
94 ifdef EXTRA
95 jcxz @@nocat
96 endif
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
184 proc @puts$qpxzc near
186 ; global puts:near ; puts(bx)
187 puts:
188 call @@putsz
189 mov bx,offset msg_lf
190 mov dl,13
191 @@putcz:
192 mov ah,2
193 int 21h
194 @@putsz:
195 mov dl,[bx]
196 inc bx
197 or dl,dl
198 jne @@putcz ; ZF=1 (for malloc failure)
199 ret
201 endp @puts$qpxzc
205 ;***************************************************************
206 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
207 ;***************************************************************
208 global openargs:near ; openargs(bx)
209 openargs:
210 cmp [byte bx],'@'
211 jne fail
212 inc bx
214 global @open$qpxzc:near
215 proc @open$qpxzc near
217 global open:near ; open(bx)
218 open:
219 ifdef LONG_FILENAME
220 mov ax,716Ch
221 push bx di si
222 mov si,bx
223 xor bx,bx ; R/O
224 xor cx,cx ; attributes
225 xor di,di ; alias hint
226 cwd ; action = open
227 stc
228 int 21h
229 pop si di bx
230 jnc doret
231 endif
232 mov ax,3d00h ; read-only+compatibility
233 ;mov cl,0 ; attribute mask
234 mov dx,bx
235 jmp dos
237 endp @open$qpxzc
240 ;***************************************************************
241 ;_fastcall int fileexist(bx:const char* name);
242 ;***************************************************************
243 global @fileexist$qpxzc:near
244 @fileexist$qpxzc:
245 call @open$qpxzc
246 jc fail
248 ;***************************************************************
249 ;_fastcall int close(ax:int fd);
250 ;***************************************************************
251 global @close$qi:near
252 proc @close$qi near
254 global close:near ; close(ax)
255 close:
256 xchg ax,bx
257 mov ah,3Eh
258 or bx,bx
259 jnz dos
260 ret
262 endp @close$qi
265 ;***************************************************************
266 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
267 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
268 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
269 ;***************************************************************
270 global @readrm$qp11image_himemi:near
271 @readrm$qp11image_himemi:
272 xchg ax,dx ; sz
273 mov ax,[bx] ; fd
274 mov bx,[bx-2] ; data
275 global @read$qipvi:near
276 proc @read$qipvi near
278 ifdef WRITE
279 stc
280 db 0B0h ; mov al,im
281 global @write$qipvi:near
282 @write$qipvi:
283 clc
284 endif
285 @read$dxbxax:
286 xchg ax,bx ; fd
287 xchg ax,dx ; data
288 xchg ax,cx ; sz
289 ifdef WRITE
290 mov ah,40h
291 sbb ah,0
292 else
293 global @read$cxdxbx:near
294 @read$cxdxbx:
295 mov ah,3Fh
296 endif
297 jcxz fail
298 dos:
299 int 21h
300 chkc:
301 jnc doret
302 fail:
303 stc
304 failifc:
305 sbb ax,ax ; ax=-1 CF
306 cwd
307 doret:
308 ifndef NO386
309 push dx ; see next_chunk:lseek
310 push ax
311 pop eax
312 endif
313 ret
315 endp @read$qipvi
317 ;***************************************************************
318 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
319 ;***************************************************************
321 global @lseekcur$qii:near ; fd=ax whence=dx
322 proc @lseekcur$qii near
324 mov cl,1
325 xchg ax,bx
326 xchg ax,dx
327 cwd
328 xchg ax,dx
329 xchg ax,cx
330 jmp lseek
331 rewind: ; rewind(ax)
332 mov bl,0
333 lseek0: ; lseek0(ax,bl=dir)
334 xor dx,dx
335 xor cx,cx
336 lseekset:
337 xchg ax,bx
338 lseek:
339 mov ah,42h ; bx=fd cx:dx=offset al=whence
340 jmp dos
342 endp @lseekcur$qii
344 ifdef EXTRA
345 ;***************************************************************
346 ;_fastcall long isolseek(bx:const unsigned long *offset);
347 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
348 ;***************************************************************
349 global @isolseek$qpxul:near
350 proc @isolseek$qpxul near
352 isolseek:
353 mov ax,[_isostate.fd]
354 global @lseekset2$qipul:near
355 @lseekset2$qipul:
356 mov dx,[bx]
357 mov cx,[bx+2]
358 mov bl,0
359 jmp lseekset
361 endp @isolseek$qpxul
363 ;***************************************************************
364 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
365 ;***************************************************************
366 global @isoreadsector$qpxul:near
367 proc @isoreadsector$qpxul near
369 call isolseek
370 jc doret
371 mov dx,2560
372 ;mov bx,offset _isostate.buffer
373 mov bx,offset _xfer_buf
374 mov ax,[_isostate.fd]
375 jmp @read$dxbxax ; read(fd,buffer,2560)
377 endp @isoreadsector$qpxul
380 ;***************************************************************
381 ;_fastcall int isoreset(bx:const char *name);
382 ;***************************************************************
383 global @isoreset$qpzc:near
384 proc @isoreset$qpzc near
386 or bx,bx
387 jz fail
388 call near ptr @open$qpxzc
389 mov [_isostate.fd],ax
390 extrn @isoroot$qv:near
391 jmp @isoroot$qv
393 endp @isoreset$qpzc
396 ;***************************************************************
397 ;_fastcall int isoopen(bx:const char *name);
398 ;***************************************************************
399 global @isoopen$qpxzc:near
400 proc @isoopen$qpxzc near
402 extrn @_isoopen$qv:near
403 mov [_isostate.filename2open],bx
404 jmp @_isoopen$qv
406 endp @isoopen$qpxzc
408 endif
411 ifdef USE_ARGSTR
412 ;***************************************************************
413 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
414 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
415 ;***************************************************************
416 global @argstr$qpxzcxt1ppxzc:near
417 proc @argstr$qpxzcxt1ppxzc near
419 mov cl,2
420 db 0a9h ; test ax,#
421 global @argnum$qpzcxpxzcpul:near
422 @argnum$qpzcxpxzcpul:
423 mov cl,4
424 xchg ax,bx ; keywords -> bx
425 xchg ax,cx ; s -> cx
426 cbw ; argstr:0002 argnum:0004
427 xchg ax,dx ; vars -> ax
428 push si di
429 xchg ax,di ; vars => di
430 dec bx
431 @@testalt:
432 mov al,-1
433 sub di,dx
434 @@test:
435 cmp al,'='
436 je @@found
437 cmp al,0 ; eos, si=next argv
438 je @@found
439 mov si,cx ; s
440 add di,dx
441 @@match:
442 inc bx ; keywords++
443 lodsb ; *s++
444 or al,20h
445 cmp al,[bx]
446 je @@match
447 cmp al,'/' ; 2f
448 jne @@notopt
449 cmp [byte bx],'-'
450 je @@match
451 @@notopt:
452 ifdef EXTRA
453 cmp [byte bx],'/'
454 je @@testalt
455 endif
456 cmp [byte bx],'|'
457 je @@test
458 mov al,0
459 inc bx
460 cmp [bx-1],al
461 jne @@notopt
462 stc
463 jmp @@nokeyword
464 @@found:
465 mov [di],si
466 dec dx
467 dec dx
468 je @@done
469 mov bx,si
470 call @strtol$qpxzc
471 mov [di],ax
472 mov [di+2],dx
473 @@done:
474 clc
475 @@nokeyword:
476 sbb ax,ax
477 pop di si
478 ret
480 endp @argstr$qpxzcxt1ppxzc
482 else
484 ;***************************************************************
485 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
486 ;***************************************************************
487 global @strhead$qpxzct1:near
488 proc @strhead$qpxzct1 near
490 @@loop:
491 xchg ax,bx
492 mov cl,[bx] ; cl = *b++
493 inc bx
494 or cl,cl ; clear C
495 jz failifc ; return 0
496 xchg ax,bx
497 xor cl,[bx] ; cl -= *a++
498 inc bx
499 and cl,0dfh ; case insensitive
500 jne fail ; return -1
501 jmp @@loop
503 endp @strhead$qpxzct1
505 endif
507 ;***************************************************************
508 ;_fastcall char* malloc_or_die(ax:unsigned size);
509 ;***************************************************************
510 global @malloc_or_die$qui:near
511 proc @malloc_or_die$qui near
513 xchg ax,cx ; size
514 global malloc_or_die:near ; malloc_or_die(cx)
515 malloc_or_die:
516 mov ax,[_heap_top] ; return value
517 mov bx,sp
518 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
519 sub bx,ax ; can't overflow
520 cmp bx,cx
521 mov bx,offset msg_malloc
522 jb die
523 add [_heap_top],cx ; _BEG has zero'd heap
524 ret
526 endp @malloc_or_die$qui
529 ;***************************************************************
530 ;_fastcall int die(bx:const char* msg);
531 ;int exit();
532 ;int abort();
533 ;***************************************************************
534 global @die$qpxzc:near
535 proc @die$qpxzc near
536 @die$qpxzc:
537 global die:near ; die(bx)
538 die:
539 call puts
540 ; global _exit:near
541 _exit:
542 mov al,[_no_exit]
543 or al,al
544 jne @@hang
545 extrn exit:near
546 inc ax
547 jmp near exit
548 @@hang:
549 mov bx, offset msg_hang
550 call puts
551 ; global _abort:near
552 _abort:
553 cli
554 hlt
555 jmp _abort
557 endp @die$qpxzc
559 struc image_himem ;struct image_himem {
560 fd dw ? ; 0 int fd;
561 fallback dd ? ; 2 u32 fallback;
562 size dd ? ; 6 u32 size;
563 remaining dd ? ;10 u32 remaining;
564 buf dd ? ;14 u32 buf;
565 bufv dw ? ;18 u32 *bufv;
566 errmsg dw ? ;20 char *errmsg;
567 chunk_size dd ? ;22 u32 chunk_size;
568 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
569 state dw ? ;28 u16 state;
570 fd2close dw ? ;30 u16 fd2close;
571 ends ;};
573 ;***************************************************************
574 ;static long next_chunk(struct image_himem *di);
575 ;***************************************************************
576 proc next_chunk near
578 push si
579 mov ax,[(image_himem di).fd]
580 call close
581 ifndef NO386
582 xor eax,eax
583 else
584 xor ax,ax
585 cwd
586 endif
587 mov [(image_himem di).fd],ax
588 mov bx,[(image_himem di).state]
589 cmp al,[bx] ; ""
590 jz @@end
591 mov si,bx
592 @@scan:
593 lodsb
594 mov cx,si
595 cmp al,','
596 jz @@eos
597 or al,al
598 jnz @@scan
599 dec cx
600 @@eos:
601 mov [(image_himem di).state],cx
602 dec si
603 push [word si]
604 mov [byte si],ah ; set temp eos
605 call open
606 pop [word si] ; restore string
607 jc @@die
608 mov [(image_himem di).fd],ax
609 mov [(image_himem di).fd2close],ax
610 mov bl,02h ; SEEK_END
611 call lseek0
612 @@die:
613 mov bx,[(image_himem di).errmsg]
614 jc die
615 ifndef NO386
616 push eax
617 mov ax,[(image_himem di).fd]
618 call rewind
619 pop eax
620 @@end:
621 mov [(image_himem di).chunk_size],eax
622 else
623 push ax
624 push dx
625 mov ax,[(image_himem di).fd]
626 call rewind
627 pop dx
628 pop ax
629 @@end:
630 mov [word (image_himem di).chunk_size],ax
631 mov [word ((image_himem di).chunk_size)+2],dx
632 endif
633 pop si
634 ret
636 endp next_chunk
639 ifdef LARGE_IMAGES
640 struc data_himem ;struct data_himem {
641 first dd ? ; 0 u32 first;
642 cacheidx dw ? ; 4 int cacheidx;
643 pageidx dw ? ; 6 int pageidx;
644 cache dd 1024 dup(?) ; 8 int cache;
645 page dd 1024 dup(?) ;4104 int page;
646 ends ;}; // size=8200
647 endif
649 ;***************************************************************
650 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
651 ;***************************************************************
652 global @malloc_bufv_or_die$qp11image_himem:near
653 proc @malloc_bufv_or_die$qp11image_himem near
655 p386
656 push si
657 mov si,bx
658 ifdef LARGE_IMAGES
659 movzx ecx,[word ((image_himem si).size) + 2]
660 shr cx,4 ; pages index size = size >> 20
661 add cx,8+4096+8
662 call malloc_or_die
663 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
664 add ecx,[(image_himem si).size]
665 shr ecx,12
666 mov [curdata],ax
667 else
668 mov ecx,[(image_himem si).size]
669 dec ecx
670 shr ecx,12
671 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
672 push cx
673 inc cx ; cnt+1
674 shl cx,2 ; bufv => vcpi => vm86
675 ; our malloc zeroes allocated mem: bufv[cnt]=0;
676 ; Allocate pages, storing addrs in addrbuf
677 call malloc_or_die
678 pop cx
679 push ax
680 endif
681 mov [(image_himem si).bufv],ax
682 xchg ax,si
683 @@vcpi_alloc:
684 xor edx,edx
685 mov ax,0DE04h
686 int 67h
687 or ah,ah
688 mov bx,offset vcpi_alloc_err
689 jnz die
690 ; for (i = cnt-1; i >= 0; i--)
691 ifdef LARGE_IMAGES
692 mov eax,ecx
693 dec eax
694 else
695 mov ax,cx
696 dec ax
697 cwde
698 endif
699 shl eax,12 ; i*_4k
700 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
701 extrn _imgs
702 mov bx,offset _imgs+2
703 push eax
704 add eax,[bx-2+2]
705 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
706 pop eax ; i*_4k
707 jbe @@pmok
708 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
709 jae @@vcpi_alloc
710 @@pmok:
711 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
712 extrn _imgs
713 mov bx,offset _imgs+32+2
714 add eax,[bx-2+2] ; +initrd.fallback
715 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
716 ja @@initrdok
717 mov eax,[bx-2+6] ; initrd.size
718 add eax,[bx-2+2] ; +initrd.fallback
719 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
720 @@jnc_vcpi_alloc:
721 ja @@vcpi_alloc
722 @@initrdok:
723 ifdef LARGE_IMAGES
724 cmp [(data_himem si).first],0
725 jne @@notfirst
726 mov [(data_himem si).first],edx
727 @@notfirst:
728 mov bx,[(data_himem si).cacheidx]
729 cmp bh,4
730 jae @@nextpage
731 shl bx,2
732 inc [(data_himem si).cacheidx]
733 mov [(data_himem bx+si).cache],edx
734 loopd @@vcpi_alloc
735 mov [(data_himem bx+si).cache],ecx ; last is 0
736 @@nextpage:
737 and [(data_himem si).cacheidx],0
738 mov bx,[(data_himem si).pageidx]
739 mov [(data_himem bx+si).page],edx
740 add [(data_himem si).pageidx],4
741 push cx
742 lea cx,[(data_himem si).cache]
743 ifdef NO386
744 push edx
745 pop dx
746 pop ax
747 endif
748 call storepage ; storepage(edx,cx)
749 pop cx
750 or ecx,ecx ; clear C
751 jnz @@jnc_vcpi_alloc
752 mov [dword (data_himem si).cacheidx],ecx
753 xchg ax,si
754 else
755 mov [si],edx
756 lodsd ; si=+4
757 loop @@vcpi_alloc
758 pop ax
759 endif
760 pop si
761 ret
762 ifdef NO386
763 p8086
764 endif
766 endp @malloc_bufv_or_die$qp11image_himem
769 ;***************************************************************
770 ;_fastcall void memcpy_image(bx:struct image_himem *m);
771 ;***************************************************************
772 global @memcpy_image$qp11image_himem:near
773 proc @memcpy_image$qp11image_himem near
775 ifndef NO386
776 mov edx,[(image_himem bx).fallback]
777 mov eax,[(image_himem bx).buf]
778 cmp eax,edx ; if (m->fallback != m->buf)
779 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
780 ifdef LARGE_IMAGES
781 mov ecx,[(image_himem bx).size]
782 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
783 push ecx
784 else
785 push [(image_himem bx).size]
786 endif
787 push eax
788 push 0
789 call_memcpy32:
790 push edx
791 else
792 mov ax,[word ((image_himem bx).fallback)]
793 mov dx,[word ((image_himem bx).fallback)+2]
794 mov cx,[word ((image_himem bx).buf)]
795 cmp ax,cx ; if (m->fallback != m->buf)
796 jnz @@do
797 cmp dx,[word ((image_himem bx).buf)+2]
798 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
799 @@do:
800 push [word ((image_himem bx).size)+2]
801 push [word ((image_himem bx).size)]
802 push [word ((image_himem bx).buf)+2]
803 push cx
804 xor cx,cx
805 push cx
806 call_memcpy32:
807 push dx
808 push ax
809 ifdef LARGE_IMAGES
810 jmp @@memcpy
811 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
812 p386
813 push ecx
814 push eax
815 push 0
816 push edx
817 ifdef NO386
818 p8086
819 endif
820 endif
821 endif
822 @@memcpy:
823 extrn memcpy32:near
824 call near memcpy32
825 @@skip:
826 ret
828 endp @memcpy_image$qp11image_himem
830 ;***************************************************************
831 ;_fastcall void storepage(bx:u32 *dst);
832 ;***************************************************************
833 global @storepage$qpul:near
834 proc @storepage$qpul near
836 ifndef NO386
837 mov edx,[bx]
838 else
839 mov ax,[bx]
840 mov dx,[bx+2]
841 endif
842 mov cx,offset _xfer_buf
843 storepage: ; storepage(edx,cx)
844 ifndef NO386
845 push 0
846 push 4096
847 push 0
848 else
849 xor bx,bx
850 push bx
851 mov bh,4096/256
852 push bx
853 xor bx,bx
854 push bx
855 endif
856 push cx
857 push ds
858 jmp call_memcpy32
860 endp @storepage$qpul
863 ifdef LARGE_IMAGES
864 p386
865 ;***************************************************************
866 ;_fastcall void reset_bufv(bx:u32 *p);
867 ;***************************************************************
868 global @reset_bufv$qpul:near
869 proc @reset_bufv$qpul near
871 mov [curdata],bx
872 and [dword (data_himem bx).cacheidx],0
873 ret
875 endp @reset_bufv$qpul
877 ;***************************************************************
878 ;u32* prev_bufv();
879 ;u32* prev_bufv();
880 ;***************************************************************
881 global _prev_bufv:near
882 global _next_bufv:near
883 proc _prev_bufv near
885 stc
886 db 73h ; jnc
887 _next_bufv:
888 clc
889 push si
890 mov si,[curdata]
891 sbb ax,ax
892 cmc
893 adc ax,[(data_himem si).cacheidx] ; -1/+1
894 xor ecx,ecx
895 test ax,0fc00h
896 jz @@gotpage
897 push ax ; FFFF / 0400
898 sar ax,8 ; FFFC / 0004
899 and al,0fch
900 add [(data_himem si).pageidx],ax
901 mov bx,[(data_himem si).pageidx]
902 lea bx,[(data_himem bx+si).page]
903 mov edx,ds
904 shl edx,4
905 lea cx,[(data_himem si).cache]
906 add edx,ecx
907 mov eax,[bx]
908 or eax,eax
909 jnz @@pageok
910 pop ax
911 xchg ax,bx
912 pop si
913 ret
914 @@pageok:
915 mov cx,4096
916 call memcpy_imagez ; get page
917 pop ax ; FFFF / 0400
918 cbw
919 shr ax,6 ; 03FF / 0000
920 @@gotpage:
921 mov [(data_himem si).cacheidx],ax
922 shl ax,2
923 xchg ax,bx
924 lea ax,[(data_himem bx+si).cache]
925 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
926 jnz @@notfirst2
927 xchg ax,si ; &first
928 @@notfirst2:
929 pop si
930 ret
932 endp _prev_bufv
933 endif
935 ifdef NO386
936 p8086
937 endif
939 ;***************************************************************
940 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
941 ;***************************************************************
943 global @open_image$qp11image_himempxzc:near
944 proc @open_image$qp11image_himempxzc near
946 push di
947 xchg ax,bx
948 xchg ax,di
949 ifdef EXTRA
950 cmp [(image_himem di).fd],0 ; iso image/kernel ?
951 jnz @@alreadydone
952 endif
953 mov [(image_himem di).state],bx
954 push bx
955 ifdef EXTRA
956 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
957 jnz @@next
958 mov [(image_himem di).next_chunk],offset next_chunk
959 @@next:
960 push di
961 call [(image_himem di).next_chunk] ; m->next_chunk()
962 pop di
963 else
964 @@next:
965 call next_chunk
966 endif
967 ifndef NO386
968 add eax,3
969 and al,0FCh
970 add [(image_himem di).size],eax ; m->size += m->chunk_size
971 or eax,eax
972 else
973 add ax,3
974 adc dx,0
975 and al,0FCh
976 add [word (image_himem di).size],ax ; m->size += m->chunk_size
977 adc [word ((image_himem di).size)+2],dx
978 or ax,dx
979 endif
980 jnz @@next
981 pop [(image_himem di).state]
982 ifdef EXTRA
983 push di
984 call [(image_himem di).next_chunk] ; m->next_chunk()
985 pop di
986 else
987 call next_chunk
988 endif
989 @@alreadydone:
990 pop di
991 ret
993 endp @open_image$qp11image_himempxzc
996 ;***************************************************************
997 ;_fastcall int read_image(bx:struct image_himem *m);
998 ;***************************************************************
999 global @read_image$qp11image_himem:near
1000 proc @read_image$qp11image_himem near
1002 push si di
1003 mov di,bx
1004 mov si,4096
1005 push si ; original size
1006 @@loop:
1007 ifndef NO386
1008 movzx ecx,si
1009 mov eax,[(image_himem di).chunk_size]
1010 cmp ecx,eax
1011 jb @@szok
1012 else
1013 mov cx,si
1014 mov ax,[word (image_himem di).chunk_size]
1015 cmp cx,ax
1016 jb @@szok
1017 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1018 jne @@szok
1019 endif
1020 xchg ax,cx
1021 @@szok:
1022 jcxz image_done
1023 mov dx,offset _xfer_buf+4096
1024 sub dx,si
1025 mov bx,[di]
1026 call @read$cxdxbx
1027 jc image_done
1028 xor cx,cx
1029 cwd ; ax < 8000h
1030 ifndef NO386
1031 cwde ; ax < 8000h
1032 sub [(image_himem di).chunk_size],eax
1033 xchg eax,ebx
1034 else
1035 sub [word (image_himem di).chunk_size],ax
1036 xchg ax,bx
1037 sbb [word ((image_himem di).chunk_size)+2],dx
1038 jnz @@fill
1039 cmp [word (image_himem di).chunk_size],dx
1040 endif
1041 jnz @@fill
1042 dec cx
1043 @@fill:
1044 test bl,3
1045 je @@filled
1046 mov [bx+_xfer_buf],dh
1047 inc bx
1048 jmp @@fill
1049 @@filled:
1050 ifndef NO386
1051 sub [(image_himem di).remaining],ebx
1052 else
1053 sub [word (image_himem di).remaining],bx
1054 sbb [word ((image_himem di).remaining)+2],dx
1055 endif
1056 sub si,bx
1057 pushf
1058 ifdef EXTRA
1059 and cx,[(image_himem di).next_chunk]
1060 jcxz @@same_chunk
1061 push di
1062 call cx
1063 pop cx
1064 else
1065 jcxz @@same_chunk
1066 call next_chunk
1067 endif
1068 @@same_chunk:
1069 popf
1070 jnz @@loop
1071 image_done:
1072 pop ax ; original size
1073 sub ax,si
1074 pop di si
1075 ret
1077 endp @read_image$qp11image_himem
1080 ;***************************************************************
1081 ;_fastcall unsigned long strtol(const char *s);
1082 ;***************************************************************
1083 global @strtol$qpxzc:near
1084 proc @strtol$qpxzc near
1086 ifndef NO386
1087 push si
1088 mov si,bx
1089 xor ecx,ecx
1090 xor eax,eax
1091 xor ebx,ebx
1092 or si,si
1093 jz @@end
1094 lodsb
1095 mov dx,ax
1096 or al,20h
1097 cmp al,'n' ; vga=normal
1098 je @@vga
1099 dec cx
1100 cmp al,'e' ; vga=extended
1101 je @@vga
1102 dec cx
1103 cmp al,'a' ; vga=ask
1104 jne @@notvga
1105 @@vga:
1106 dec cx
1107 xchg ax,cx
1108 cwd
1109 jmp @@popsiret
1110 @@notvga:
1111 mov cx,10 ; radix
1112 xchg ax,dx
1113 cmp al,'+'
1114 je @@radixskip
1115 cmp al,'-'
1116 clc
1117 jne @@radixkeep
1118 stc
1119 @@radixskip:
1120 lodsb
1121 @@radixkeep:
1122 pushf
1123 cmp al,'0'
1124 jne @@radixok
1125 mov cl,8
1126 lodsb
1127 or al,20h
1128 cmp al,'x'
1129 jne @@radixok
1130 mov cl,16
1131 @@strtollp:
1132 lodsb
1133 @@radixok:
1134 or al,20h
1135 sub al,'0'
1136 jb @@endstrtol
1137 cmp al,9
1138 jbe @@digitok
1139 cmp al,'a'-'0'
1140 jb @@endstrtol
1141 sub al,'a'-'0'-10
1142 @@digitok:
1143 cmp al,cl
1144 jae @@endstrtol
1145 xchg eax,ebx
1146 mul ecx
1147 add eax,ebx
1148 xchg eax,ebx
1149 jmp @@strtollp
1150 @@endstrtol:
1151 mov cl,10
1152 cmp al,'k'-'a'+10
1153 je @@shift
1154 mov cl,20
1155 cmp al,'m'-'a'+10
1156 je @@shift
1157 mov cl,30
1158 cmp al,'g'-'a'+10
1159 jne @@noshift
1160 @@shift:
1161 shl ebx,cl
1162 @@noshift:
1163 popf
1164 jnc @@end
1165 neg ebx
1166 @@end:
1167 push ebx
1168 pop ax
1169 pop dx
1170 @@popsiret:
1171 pop si
1172 else
1173 push si
1174 push di
1175 xor ax,ax
1176 cwd
1177 or bx,bx
1178 jz @@goend
1179 xchg ax,di
1180 mov si,bx
1181 lodsb
1182 mov bx,ax
1183 or al,20h
1184 mov cx,-1
1185 cmp al,'n' ; vga=normal
1186 je @@vga
1187 dec cx
1188 cmp al,'e' ; vga=extended
1189 je @@vga
1190 dec cx
1191 cmp al,'a' ; vga=ask
1192 jne @@notvga
1193 @@vga:
1194 xchg ax,cx
1195 @@goend:
1196 jmp @@popdisiret
1197 @@notvga:
1198 mov cx,10 ; radix
1199 xchg ax,bx
1200 cmp al,'+'
1201 je @@radixskip
1202 cmp al,'-'
1203 clc
1204 jne @@radixkeep
1205 stc
1206 @@radixskip:
1207 lodsb
1208 @@radixkeep:
1209 pushf
1210 cmp al,'0'
1211 jne @@radixok
1212 mov cl,8
1213 lodsb
1214 or al,20h
1215 cmp al,'x'
1216 jne @@radixok
1217 mov cl,16
1218 @@strtollp:
1219 lodsb
1220 @@radixok:
1221 or al,20h
1222 sub al,'0'
1223 jb @@endstrtol
1224 cmp al,9
1225 jbe @@digitok
1226 cmp al,'a'-'0'
1227 jb @@endstrtol
1228 sub al,'a'-'0'-10
1229 @@digitok:
1230 cmp al,cl
1231 jae @@endstrtol
1233 push ax
1234 push si
1235 push dx
1236 xchg ax,di
1237 mul cx
1238 xchg ax,di
1239 xchg ax,dx
1240 xchg ax,si
1241 pop ax
1242 mul cx
1243 add ax,si
1244 pop si
1245 xchg ax,dx
1246 pop ax
1247 mov ah,0
1248 add di,ax
1249 adc dx,0
1251 jmp @@strtollp
1252 @@endstrtol:
1253 mov cl,10
1254 cmp al,'k'-'a'+10
1255 je @@shift
1256 mov cl,20
1257 cmp al,'m'-'a'+10
1258 je @@shift
1259 mov cl,30
1260 cmp al,'g'-'a'+10
1261 jne @@noshift
1262 @@shift:
1263 rcl di,1
1264 shl dx,1
1265 loop @@shift
1266 @@noshift:
1267 popf
1268 jnc @@end
1269 not dx
1270 neg di
1271 jne @@end
1272 inc dx
1273 @@end:
1274 xchg ax,di
1275 @@popdisiret:
1276 pop di
1277 pop si
1278 endif
1279 strtol_ret:
1280 ret
1282 endp @strtol$qpxzc
1285 ifdef USE_ARGSTR
1286 ;***************************************************************
1287 ;_fastcall void set_cmdline(bx:const char *filename);
1288 ;***************************************************************
1289 global @set_cmdline$qpxzc:near
1290 proc @set_cmdline$qpxzc near
1291 call openargs
1292 jc strtol_ret
1293 mov cx,4096
1294 mov di,[_heap_top]
1295 extrn read_cmdline:near
1296 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1298 endp @set_cmdline$qpxzc
1299 endif
1302 ifdef NO386
1303 ;***************************************************************
1304 ;u16 topseg();
1305 ;***************************************************************
1306 global _topseg:near
1307 proc _topseg near
1309 int 12h
1310 jnc @@max640k
1311 mov ax,640 ; 9000
1312 @@max640k:
1313 dec ax
1314 and al,0C0h
1315 mov cl,6
1316 shl ax,cl
1317 ret
1319 endp _topseg
1320 endif
1322 ifdef EXTRA
1323 p8086
1324 ;***************************************************************
1325 ;char *progname(void)
1326 ;***************************************************************
1327 global _progname:near
1328 proc _progname near
1330 push si di es
1331 mov ah,30h
1332 int 21h
1333 xor di,di
1334 cmp al,3
1335 mov ax,di
1336 jb @@skip
1337 ;mov es,[cs:2Ch]
1338 mov es,[di+2Ch]
1339 mov cx,sp ; big enough
1340 @@loop:
1341 repne
1342 scasb
1343 scasb
1344 jne @@loop
1345 inc di
1346 inc di
1347 mov si,di ; progname @es:di
1348 repne
1349 scasb
1350 mov cx,di
1351 sub cx,si ; progname len
1352 call malloc_or_die ; keep cx
1353 mov di,ax
1354 push ds
1355 push es
1356 pop ds
1357 pop es
1358 rep
1359 movsb
1360 push es
1361 pop ds
1362 @@skip:
1363 pop es di si
1364 ret
1366 endp _progname
1369 ;***************************************************************
1370 ;_fastcall void chdirname(bx:char *path)
1371 ;***************************************************************
1372 global @chdirname$qpzc:near
1373 proc @chdirname$qpzc near
1375 cmp [byte bx+1],3Ah ; ':'
1376 jne @@nodisk
1377 mov dl,20h
1378 or dl,[bx]
1379 sub dl,61h
1380 mov ah,0Eh
1381 int 21h
1382 inc bx
1383 inc bx
1384 @@nodisk:
1385 xor cx,cx
1386 @@next:
1387 mov al,[bx]
1388 cmp al,5Ch
1389 jne @@tsteos
1390 mov dx,bx
1391 inc cx
1392 @@tsteos:
1393 inc bx
1394 or al,al
1395 jnz @@next
1396 jcxz @@end
1397 mov bx,dx
1398 push [word bx]
1399 mov [bx],al
1400 ifdef LONG_FILENAME
1401 stc
1402 mov ax,713Bh ; chdir long filename (ds:dx)
1403 int 21h
1404 jnc @@chdirdone
1405 endif
1406 mov ah,3Bh ; chdir(ds:dx)
1407 int 21h
1408 @@chdirdone:
1409 pop [word bx]
1410 @@end:
1411 ret
1413 endp @chdirname$qpzc
1416 ;***************************************************************
1417 ;_fastcall char *ultoa(axdx:unsigned long n);
1418 ;***************************************************************
1419 global @ultoa$qul:near
1420 proc @ultoa$qul near
1422 xchg ax,cx
1423 xchg ax,dx ; AX:CX = n
1424 push si
1425 mov si,10
1426 mov bx,offset ultoabuf+11
1427 @@loop:
1428 dec bx
1429 xor dx,dx
1430 div si ; DX:AX = 0000:hi(n)
1431 xchg ax,cx ; CX = hi(n)/10
1432 div si ; DX:AX = hi(n)%10:lo(n)
1433 xchg ax,cx ; CX = lo(n/10)
1434 ; AX = hi(n)/10 = hi(n/10)
1435 mov [byte bx],'0'
1436 add [bx],dl ; DL = n%10
1437 mov dx,ax
1438 or dx,cx
1439 jnz @@loop
1440 xchg ax,bx
1441 pop si
1442 ret
1444 endp @ultoa$qul
1447 ;***************************************************************
1448 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1449 ;***************************************************************
1450 global @kver2ul$qpzc:near
1451 proc @kver2ul$qpzc near
1453 push si
1454 mov si,bx
1455 xor bx,bx
1456 mov cx,304h
1457 @@number:
1458 xor ax,ax
1459 cwd
1460 @@digit:
1461 shl al,cl
1462 shl ax,cl
1463 lodsb
1464 sub al,30h
1465 cmp al,9
1466 jbe @@digit
1467 mov dl,bh
1468 mov bh,bl
1469 mov bl,ah
1470 dec ch
1471 jnz @@number
1472 xchg ax,bx
1473 pop si
1474 kver2ulret:
1475 ret
1477 endp @kver2ul$qpzc
1479 endif
1481 ;***************************************************************
1482 ;void try_default_args();
1483 ;***************************************************************
1484 ifdef EXTRA
1486 global _try_default_args:near
1487 proc _try_default_args near
1489 mov bx,offset tazboot_cmd
1490 call open
1491 jc kver2ulret
1492 mov cx,4096
1493 mov di,[_heap_top]
1494 extrn read_cmdline:near
1495 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1497 endp _try_default_args
1499 endif
1501 ends _TEXT
1503 end
1505 ;###### END OF FILE ############################################