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

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