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

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