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

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