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

Up zstd (1.4.0), fix linld: base_himem/strtol
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 18 13:29:32 2019 +0200 (2019-05-18)
parents 8685ee90f6aa
children 0e811092e7bb
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 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 mov cl,2
384 db 0a9h ; test ax,#
385 global @argnum$qpzcxpxzcpul:near
386 @argnum$qpzcxpxzcpul:
387 mov cl,4
388 xchg ax,bx ; keywords -> bx
389 xchg ax,cx ; s -> cx
390 cbw ; argstr:0002 argnum:0004
391 xchg ax,dx ; vars -> ax
392 push si di
393 xchg ax,di ; vars => di
394 dec bx
395 @@testalt:
396 mov al,-1
397 sub di,dx
398 @@test:
399 cmp al,'='
400 je @@found
401 cmp al,0 ; eos, si=next argv
402 je @@found
403 mov si,cx ; s
404 add di,dx
405 @@match:
406 inc bx ; keywords++
407 lodsb ; *s++
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 cmp [byte bx],'/'
418 je @@testalt
419 endif
420 cmp [byte bx],'|'
421 je @@test
422 mov al,0
423 inc bx
424 cmp [bx-1],al
425 jne @@notopt
426 stc
427 jmp @@nokeyword
428 @@found:
429 mov [di],si
430 dec dx
431 dec dx
432 je @@done
433 mov bx,si
434 call @strtol$qpxzc
435 mov [di],ax
436 mov [di+2],dx
437 @@done:
438 clc
439 @@nokeyword:
440 sbb ax,ax
441 pop di si
442 ret
444 endp @argstr$qpxzcxt1ppxzc
446 else
448 ;***************************************************************
449 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
450 ;***************************************************************
451 global @strhead$qpxzct1:near
452 proc @strhead$qpxzct1 near
454 @@loop:
455 xchg ax,bx
456 mov cl,[bx] ; cl = *b++
457 inc bx
458 or cl,cl ; clear C
459 jz fail ; return 0
460 xchg ax,bx
461 xor cl,[bx] ; cl -= *a++
462 inc bx
463 and cl,0dfh ; case insensitive
464 jz @@loop
465 ret ; return b (is not 0)
467 endp @strhead$qpxzct1
469 endif
471 ;***************************************************************
472 ;_fastcall char* malloc_or_die(ax:unsigned size);
473 ;***************************************************************
474 global @malloc_or_die$qui:near
475 proc @malloc_or_die$qui near
477 xchg ax,cx ; size
478 global malloc_or_die:near ; malloc_or_die(cx)
479 malloc_or_die:
480 mov ax,[_heap_top] ; return value
481 mov bx,sp
482 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
483 sub bx,ax ; can't overflow
484 cmp bx,cx
485 mov bx,offset msg_malloc
486 jb die
487 add [_heap_top],cx ; _BEG has zero'd heap
488 ret
490 endp @malloc_or_die$qui
493 ;***************************************************************
494 ;_fastcall int die(bx:const char* msg);
495 ;int exit();
496 ;int abort();
497 ;***************************************************************
498 global @die$qpxzc:near
499 proc @die$qpxzc near
500 @die$qpxzc:
501 global die:near ; die(bx)
502 die:
503 call puts
504 ; global _exit:near
505 _exit:
506 mov al,[_no_exit]
507 or al,al
508 jne @@hang
509 extrn exit:near
510 inc ax
511 jmp near exit
512 @@hang:
513 mov bx, offset msg_hang
514 call puts
515 ; global _abort:near
516 _abort:
517 cli
518 hlt
519 jmp _abort
521 endp @die$qpxzc
523 struc image_himem ;struct image_himem {
524 fd dw ? ; 0 int fd;
525 fallback dd ? ; 2 u32 fallback;
526 size dd ? ; 6 u32 size;
527 remaining dd ? ;10 u32 remaining;
528 buf dd ? ;14 u32 buf;
529 bufv dw ? ;18 u32 *bufv;
530 errmsg dw ? ;20 char *errmsg;
531 chunk_size dd ? ;22 u32 chunk_size;
532 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
533 state dw ? ;28 u16 state;
534 fd2close dw ? ;30 u16 fd2close;
535 ends ;};
537 ;***************************************************************
538 ;static long next_chunk(struct image_himem *di);
539 ;***************************************************************
540 proc next_chunk near
542 push si
543 mov ax,[(image_himem di).fd]
544 call close
545 ifndef NO386
546 xor eax,eax
547 else
548 xor ax,ax
549 cwd
550 endif
551 mov [(image_himem di).fd],ax
552 mov bx,[(image_himem di).state]
553 cmp al,[bx] ; ""
554 jz @@end
555 mov si,bx
556 @@scan:
557 lodsb
558 mov cx,si
559 cmp al,','
560 jz @@eos
561 or al,al
562 jnz @@scan
563 dec cx
564 @@eos:
565 mov [(image_himem di).state],cx
566 dec si
567 push [word si]
568 mov [byte si],ah ; set temp eos
569 call open
570 pop [word si] ; restore string
571 jc @@die
572 mov [(image_himem di).fd],ax
573 mov [(image_himem di).fd2close],ax
574 mov bl,02h ; SEEK_END
575 call lseek0
576 @@die:
577 mov bx,[(image_himem di).errmsg]
578 jc die
579 ifndef NO386
580 push eax
581 mov ax,[(image_himem di).fd]
582 call rewind
583 pop eax
584 @@end:
585 mov [(image_himem di).chunk_size],eax
586 else
587 push ax
588 push dx
589 mov ax,[(image_himem di).fd]
590 call rewind
591 pop dx
592 pop ax
593 @@end:
594 mov [word (image_himem di).chunk_size],ax
595 mov [word ((image_himem di).chunk_size)+2],dx
596 endif
597 pop si
598 ret
600 endp next_chunk
603 ifdef LARGE_IMAGES
604 struc data_himem ;struct data_himem {
605 first dd ? ; 0 u32 first;
606 cacheidx dw ? ; 4 int cacheidx;
607 pageidx dw ? ; 6 int pageidx;
608 cache dd 1024 dup(?) ; 8 int cache;
609 page dd 1024 dup(?) ;4104 int page;
610 ends ;}; // size=8200
611 endif
613 ;***************************************************************
614 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
615 ;***************************************************************
616 global @malloc_bufv_or_die$qp11image_himem:near
617 proc @malloc_bufv_or_die$qp11image_himem near
619 p386
620 push si
621 mov si,bx
622 ifdef LARGE_IMAGES
623 movzx ecx,[word ((image_himem si).size) + 2]
624 shr cx,4 ; pages index size = size >> 20
625 add cx,8+4096+8
626 call malloc_or_die
627 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
628 add ecx,[(image_himem si).size]
629 shr ecx,12
630 mov [curdata],ax
631 else
632 mov ecx,[(image_himem si).size]
633 dec ecx
634 shr ecx,12
635 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
636 push cx
637 inc cx ; cnt+1
638 shl cx,2 ; bufv => vcpi => vm86
639 ; our malloc zeroes allocated mem: bufv[cnt]=0;
640 ; Allocate pages, storing addrs in addrbuf
641 call malloc_or_die
642 pop cx
643 push ax
644 endif
645 mov [(image_himem si).bufv],ax
646 xchg ax,si
647 @@vcpi_alloc:
648 xor edx,edx
649 mov ax,0DE04h
650 int 67h
651 or ah,ah
652 mov bx,offset vcpi_alloc_err
653 jnz die
654 ; for (i = cnt-1; i >= 0; i--)
655 ifdef LARGE_IMAGES
656 mov eax,ecx
657 dec eax
658 else
659 mov ax,cx
660 dec ax
661 cwde
662 endif
663 shl eax,12 ; i*_4k
664 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
665 extrn _imgs
666 mov bx,offset _imgs+2
667 push eax
668 add eax,[bx-2+2]
669 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
670 pop eax ; i*_4k
671 jbe @@pmok
672 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
673 jae @@vcpi_alloc
674 @@pmok:
675 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
676 extrn _imgs
677 mov bx,offset _imgs+32+2
678 add eax,[bx-2+2] ; +initrd.fallback
679 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
680 ja @@initrdok
681 mov eax,[bx-2+6] ; initrd.size
682 add eax,[bx-2+2] ; +initrd.fallback
683 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
684 @@jnc_vcpi_alloc:
685 ja @@vcpi_alloc
686 @@initrdok:
687 ifdef LARGE_IMAGES
688 cmp [(data_himem si).first],0
689 jne @@notfirst
690 mov [(data_himem si).first],edx
691 @@notfirst:
692 mov bx,[(data_himem si).cacheidx]
693 cmp bh,4
694 jae @@nextpage
695 shl bx,2
696 inc [(data_himem si).cacheidx]
697 mov [(data_himem bx+si).cache],edx
698 loopd @@vcpi_alloc
699 mov [(data_himem bx+si).cache],ecx ; last is 0
700 @@nextpage:
701 and [(data_himem si).cacheidx],0
702 mov bx,[(data_himem si).pageidx]
703 mov [(data_himem bx+si).page],edx
704 add [(data_himem si).pageidx],4
705 push cx
706 lea cx,[(data_himem si).cache]
707 ifdef NO386
708 push edx
709 pop dx
710 pop ax
711 endif
712 call storepage ; storepage(edx,cx)
713 pop cx
714 or ecx,ecx ; clear C
715 jnz @@jnc_vcpi_alloc
716 mov [dword (data_himem si).cacheidx],ecx
717 xchg ax,si
718 else
719 mov [si],edx
720 lodsd ; si=+4
721 loop @@vcpi_alloc
722 pop ax
723 endif
724 pop si
725 ret
726 ifdef NO386
727 p8086
728 endif
730 endp @malloc_bufv_or_die$qp11image_himem
733 ;***************************************************************
734 ;_fastcall void memcpy_image(bx:struct image_himem *m);
735 ;***************************************************************
736 global @memcpy_image$qp11image_himem:near
737 proc @memcpy_image$qp11image_himem near
739 ifndef NO386
740 mov edx,[(image_himem bx).fallback]
741 mov eax,[(image_himem bx).buf]
742 cmp eax,edx ; if (m->fallback != m->buf)
743 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
744 ifdef LARGE_IMAGES
745 mov ecx,[(image_himem bx).size]
746 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
747 push ecx
748 else
749 push [(image_himem bx).size]
750 endif
751 push eax
752 push 0
753 call_memcpy32:
754 push edx
755 else
756 mov ax,[word ((image_himem bx).fallback)]
757 mov dx,[word ((image_himem bx).fallback)+2]
758 mov cx,[word ((image_himem bx).buf)]
759 cmp ax,cx ; if (m->fallback != m->buf)
760 jnz @@do
761 cmp dx,[word ((image_himem bx).buf)+2]
762 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
763 @@do:
764 push [word ((image_himem bx).size)+2]
765 push [word ((image_himem bx).size)]
766 push [word ((image_himem bx).buf)+2]
767 push cx
768 xor cx,cx
769 push cx
770 call_memcpy32:
771 push dx
772 push ax
773 ifdef LARGE_IMAGES
774 jmp @@memcpy
775 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
776 p386
777 push ecx
778 push eax
779 push 0
780 push edx
781 ifdef NO386
782 p8086
783 endif
784 endif
785 endif
786 @@memcpy:
787 extrn memcpy32:near
788 call near memcpy32
789 @@skip:
790 ret
792 endp @memcpy_image$qp11image_himem
794 ;***************************************************************
795 ;_fastcall void storepage(bx:u32 *dst);
796 ;***************************************************************
797 global @storepage$qpul:near
798 proc @storepage$qpul near
800 ifndef NO386
801 mov edx,[bx]
802 else
803 mov ax,[bx]
804 mov dx,[bx+2]
805 endif
806 mov cx,offset _xfer_buf
807 storepage: ; storepage(edx,cx)
808 ifndef NO386
809 push 0
810 push 4096
811 push 0
812 else
813 xor bx,bx
814 push bx
815 mov bh,4096/256
816 push bx
817 xor bx,bx
818 push bx
819 endif
820 push cx
821 push ds
822 jmp call_memcpy32
824 endp @storepage$qpul
827 ifdef LARGE_IMAGES
828 p386
829 ;***************************************************************
830 ;_fastcall void reset_bufv(bx:u32 *p);
831 ;***************************************************************
832 global @reset_bufv$qpul:near
833 proc @reset_bufv$qpul near
835 mov [curdata],bx
836 and [dword (data_himem bx).cacheidx],0
837 ret
839 endp @reset_bufv$qpul
841 ;***************************************************************
842 ;u32* prev_bufv();
843 ;u32* prev_bufv();
844 ;***************************************************************
845 global _prev_bufv:near
846 global _next_bufv:near
847 proc _prev_bufv near
849 stc
850 db 73h ; jnc
851 _next_bufv:
852 clc
853 push si
854 mov si,[curdata]
855 sbb ax,ax
856 cmc
857 adc ax,[(data_himem si).cacheidx] ; -1/+1
858 xor ecx,ecx
859 test ax,0fc00h
860 jz @@gotpage
861 push ax ; FFFF / 0400
862 sar ax,8 ; FFFC / 0004
863 and al,0fch
864 add [(data_himem si).pageidx],ax
865 mov bx,[(data_himem si).pageidx]
866 lea bx,[(data_himem bx+si).page]
867 mov edx,ds
868 shl edx,4
869 lea cx,[(data_himem si).cache]
870 add edx,ecx
871 mov eax,[bx]
872 or eax,eax
873 jnz @@pageok
874 pop ax
875 xchg ax,bx
876 pop si
877 ret
878 @@pageok:
879 mov cx,4096
880 call memcpy_imagez ; get page
881 pop ax ; FFFF / 0400
882 cbw
883 shr ax,6 ; 03FF / 0000
884 @@gotpage:
885 mov [(data_himem si).cacheidx],ax
886 shl ax,2
887 xchg ax,bx
888 lea ax,[(data_himem bx+si).cache]
889 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
890 jnz @@notfirst2
891 xchg ax,si ; &first
892 @@notfirst2:
893 pop si
894 ret
896 endp _prev_bufv
897 endif
899 ifdef NO386
900 p8086
901 endif
903 ;***************************************************************
904 ;_fastcall void open_image(bx:const char *name, ax:struct image_himem *m);
905 ;***************************************************************
906 global @open_image$qpxzcp11image_himem:near
907 proc @open_image$qpxzcp11image_himem near
909 push di
910 xchg ax,di
911 ifdef EXTRA
912 cmp [(image_himem di).fd],0 ; iso image/kernel ?
913 jnz @@alreadydone
914 endif
915 mov [(image_himem di).state],bx
916 push bx
917 ifdef EXTRA
918 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
919 jnz @@next
920 mov [(image_himem di).next_chunk],offset next_chunk
921 @@next:
922 call [(image_himem di).next_chunk] ; m->next_chunk()
923 else
924 @@next:
925 call next_chunk
926 endif
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 ifdef EXTRA
943 call [(image_himem di).next_chunk] ; m->next_chunk()
944 else
945 call next_chunk
946 endif
947 @@alreadydone:
948 pop di
949 ret
951 endp @open_image$qpxzcp11image_himem
954 ;***************************************************************
955 ;_fastcall int read_image(bx:struct image_himem *m);
956 ;***************************************************************
957 global @read_image$qp11image_himem:near
958 proc @read_image$qp11image_himem near
960 push si di
961 mov di,bx
962 mov si,4096
963 push si ; original size
964 @@loop:
965 ifndef NO386
966 movzx ecx,si
967 mov eax,[(image_himem di).chunk_size]
968 cmp ecx,eax
969 jb @@szok
970 else
971 mov cx,si
972 mov ax,[word (image_himem di).chunk_size]
973 cmp cx,ax
974 jb @@szok
975 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
976 jne @@szok
977 endif
978 xchg ax,cx
979 @@szok:
980 jcxz image_done
981 mov dx,offset _xfer_buf+4096
982 sub dx,si
983 mov bx,[di]
984 call @read$cxdxbx
985 jc image_done
986 xor cx,cx
987 cwd ; ax < 8000h
988 ifndef NO386
989 cwde ; ax < 8000h
990 sub [(image_himem di).chunk_size],eax
991 xchg eax,ebx
992 else
993 sub [word (image_himem di).chunk_size],ax
994 xchg ax,bx
995 sbb [word ((image_himem di).chunk_size)+2],dx
996 jnz @@fill
997 cmp [word (image_himem di).chunk_size],dx
998 endif
999 jnz @@fill
1000 dec cx
1001 @@fill:
1002 test bl,3
1003 je @@filled
1004 mov [bx+_xfer_buf],dh
1005 inc bx
1006 jmp @@fill
1007 @@filled:
1008 ifndef NO386
1009 sub [(image_himem di).remaining],ebx
1010 else
1011 sub [word (image_himem di).remaining],bx
1012 sbb [word ((image_himem di).remaining)+2],dx
1013 endif
1014 sub si,bx
1015 pushf
1016 ifdef EXTRA
1017 and cx,[(image_himem di).next_chunk]
1018 jcxz @@same_chunk
1019 push di
1020 call cx
1021 pop cx
1022 else
1023 jcxz @@same_chunk
1024 call next_chunk
1025 endif
1026 @@same_chunk:
1027 popf
1028 jnz @@loop
1029 image_done:
1030 pop ax ; original size
1031 sub ax,si
1032 pop di si
1033 ret
1035 endp @read_image$qp11image_himem
1038 ;***************************************************************
1039 ;_fastcall unsigned long strtol(const char *s);
1040 ;***************************************************************
1041 global @strtol$qpxzc:near
1042 proc @strtol$qpxzc near
1044 ifndef NO386
1045 push si
1046 mov si,bx
1047 xor ecx,ecx
1048 xor eax,eax
1049 xor ebx,ebx
1050 or si,si
1051 jz @@end
1052 lodsb
1053 mov dx,ax
1054 or al,20h
1055 cmp al,'n' ; vga=normal
1056 je @@vga
1057 dec cx
1058 cmp al,'e' ; vga=extended
1059 je @@vga
1060 dec cx
1061 cmp al,'a' ; vga=ask
1062 jne @@notvga
1063 @@vga:
1064 dec cx
1065 xchg ax,cx
1066 cwd
1067 jmp @@popsiret
1068 @@notvga:
1069 mov cx,10 ; radix
1070 xchg ax,dx
1071 cmp al,'+'
1072 je @@radixskip
1073 cmp al,'-'
1074 clc
1075 jne @@radixkeep
1076 stc
1077 @@radixskip:
1078 lodsb
1079 @@radixkeep:
1080 pushf
1081 cmp al,'0'
1082 jne @@radixok
1083 mov cl,8
1084 lodsb
1085 or al,20h
1086 cmp al,'x'
1087 jne @@radixok
1088 mov cl,16
1089 @@strtollp:
1090 lodsb
1091 @@radixok:
1092 or al,20h
1093 sub al,'0'
1094 jb @@endstrtol
1095 cmp al,9
1096 jbe @@digitok
1097 cmp al,'a'-'0'
1098 jb @@endstrtol
1099 sub al,'a'-'0'-10
1100 @@digitok:
1101 cmp al,cl
1102 jae @@endstrtol
1103 xchg eax,ebx
1104 mul ecx
1105 add eax,ebx
1106 xchg eax,ebx
1107 jmp @@strtollp
1108 @@endstrtol:
1109 mov cl,10
1110 cmp al,'k'-'a'+10
1111 je @@shift
1112 mov cl,20
1113 cmp al,'m'-'a'+10
1114 je @@shift
1115 mov cl,30
1116 cmp al,'g'-'a'+10
1117 jne @@noshift
1118 @@shift:
1119 shl ebx,cl
1120 @@noshift:
1121 popf
1122 jnc @@end
1123 neg ebx
1124 @@end:
1125 push ebx
1126 pop ax
1127 pop dx
1128 @@popsiret:
1129 pop si
1130 else
1131 push si
1132 push di
1133 xor ax,ax
1134 cwd
1135 or bx,bx
1136 jz @@goend
1137 xchg ax,di
1138 mov si,bx
1139 lodsb
1140 mov bx,ax
1141 or al,20h
1142 mov cx,-1
1143 cmp al,'n' ; vga=normal
1144 je @@vga
1145 dec cx
1146 cmp al,'e' ; vga=extended
1147 je @@vga
1148 dec cx
1149 cmp al,'a' ; vga=ask
1150 jne @@notvga
1151 @@vga:
1152 xchg ax,cx
1153 @@goend:
1154 jmp @@popdisiret
1155 @@notvga:
1156 mov cx,10 ; radix
1157 xchg ax,bx
1158 cmp al,'+'
1159 je @@radixskip
1160 cmp al,'-'
1161 clc
1162 jne @@radixkeep
1163 stc
1164 @@radixskip:
1165 lodsb
1166 @@radixkeep:
1167 pushf
1168 cmp al,'0'
1169 jne @@radixok
1170 mov cl,8
1171 lodsb
1172 or al,20h
1173 cmp al,'x'
1174 jne @@radixok
1175 mov cl,16
1176 @@strtollp:
1177 lodsb
1178 @@radixok:
1179 or al,20h
1180 sub al,'0'
1181 jb @@endstrtol
1182 cmp al,9
1183 jbe @@digitok
1184 cmp al,'a'-'0'
1185 jb @@endstrtol
1186 sub al,'a'-'0'-10
1187 @@digitok:
1188 cmp al,cl
1189 jae @@endstrtol
1191 push ax
1192 push si
1193 push dx
1194 xchg ax,di
1195 mul cx
1196 xchg ax,di
1197 xchg ax,dx
1198 xchg ax,si
1199 pop ax
1200 mul cx
1201 add ax,si
1202 pop si
1203 xchg ax,dx
1204 pop ax
1205 mov ah,0
1206 add di,ax
1207 adc dx,0
1209 jmp @@strtollp
1210 @@endstrtol:
1211 mov cl,10
1212 cmp al,'k'-'a'+10
1213 je @@shift
1214 mov cl,20
1215 cmp al,'m'-'a'+10
1216 je @@shift
1217 mov cl,30
1218 cmp al,'g'-'a'+10
1219 jne @@noshift
1220 @@shift:
1221 rcl di,1
1222 shl dx,1
1223 loop @@shift
1224 @@noshift:
1225 popf
1226 jnc @@end
1227 not dx
1228 neg di
1229 jne @@end
1230 inc dx
1231 @@end:
1232 xchg ax,di
1233 @@popdisiret:
1234 pop di
1235 pop si
1236 endif
1237 strtol_ret:
1238 ret
1240 endp @strtol$qpxzc
1243 ifdef USE_ARGSTR
1244 ;***************************************************************
1245 ;_fastcall void set_cmdline(bx:const char *filename);
1246 ;***************************************************************
1247 global @set_cmdline$qpxzc:near
1248 proc @set_cmdline$qpxzc near
1249 call openargs
1250 jc strtol_ret
1251 mov cx,4096
1252 mov di,[_heap_top]
1253 extrn read_cmdline:near
1254 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1256 endp @set_cmdline$qpxzc
1257 endif
1260 ifdef NO386
1261 ;***************************************************************
1262 ;u16 topseg();
1263 ;***************************************************************
1264 global _topseg:near
1265 proc _topseg near
1267 int 12h
1268 jnc @@max640k
1269 mov ax,640 ; 9000
1270 @@max640k:
1271 dec ax
1272 and al,0C0h
1273 mov cl,6
1274 shl ax,cl
1275 ret
1277 endp _topseg
1278 endif
1280 ifdef EXTRA
1281 p8086
1282 ;***************************************************************
1283 ;char *progname(void)
1284 ;***************************************************************
1285 global _progname:near
1286 proc _progname near
1288 push si di es
1289 mov ah,30h
1290 int 21h
1291 xor di,di
1292 cmp al,3
1293 mov ax,di
1294 jb @@skip
1295 ;mov es,[cs:2Ch]
1296 mov es,[di+2Ch]
1297 mov cx,sp ; big enough
1298 @@loop:
1299 repne
1300 scasb
1301 scasb
1302 jne @@loop
1303 inc di
1304 inc di
1305 mov si,di ; progname @es:di
1306 repne
1307 scasb
1308 mov cx,di
1309 sub cx,si ; progname len
1310 call malloc_or_die ; keep cx
1311 mov di,ax
1312 push ds
1313 push es
1314 pop ds
1315 pop es
1316 rep
1317 movsb
1318 push es
1319 pop ds
1320 @@skip:
1321 pop es di si
1322 ret
1324 endp _progname
1327 ;***************************************************************
1328 ;_fastcall void chdirname(bx:char *path)
1329 ;***************************************************************
1330 global @chdirname$qpzc:near
1331 proc @chdirname$qpzc near
1333 cmp [byte bx+1],3Ah ; ':'
1334 jne @@nodisk
1335 mov dl,20h
1336 or dl,[bx]
1337 sub dl,61h
1338 mov ah,0Eh
1339 int 21h
1340 inc bx
1341 inc bx
1342 @@nodisk:
1343 xor cx,cx
1344 @@next:
1345 mov al,[bx]
1346 cmp al,5Ch
1347 jne @@tsteos
1348 mov dx,bx
1349 inc cx
1350 @@tsteos:
1351 inc bx
1352 or al,al
1353 jnz @@next
1354 jcxz @@end
1355 mov bx,dx
1356 push [word bx]
1357 mov [bx],al
1358 ifdef LONG_FILENAME
1359 stc
1360 mov ax,713Bh ; chdir long filename (ds:dx)
1361 int 21h
1362 jnc @@chdirdone
1363 endif
1364 mov ah,3Bh ; chdir(ds:dx)
1365 int 21h
1366 @@chdirdone:
1367 pop [word bx]
1368 @@end:
1369 ret
1371 endp @chdirname$qpzc
1374 ;***************************************************************
1375 ;_fastcall char *ultoa(axdx:unsigned long n);
1376 ;***************************************************************
1377 global @ultoa$qul:near
1378 proc @ultoa$qul near
1380 xchg ax,cx
1381 xchg ax,dx ; AX:CX = n
1382 push si
1383 mov si,10
1384 mov bx,offset ultoabuf+11
1385 @@loop:
1386 dec bx
1387 xor dx,dx
1388 div si ; DX:AX = 0000:hi(n)
1389 xchg ax,cx ; CX = hi(n)/10
1390 div si ; DX:AX = hi(n)%10:lo(n)
1391 xchg ax,cx ; CX = lo(n/10)
1392 ; AX = hi(n)/10 = hi(n/10)
1393 mov [byte bx],'0'
1394 add [bx],dl ; DL = n%10
1395 mov dx,ax
1396 or dx,cx
1397 jnz @@loop
1398 xchg ax,bx
1399 pop si
1400 ret
1402 endp @ultoa$qul
1405 ;***************************************************************
1406 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1407 ;***************************************************************
1408 global @kver2ul$qpzc:near
1409 proc @kver2ul$qpzc near
1411 push si
1412 mov si,bx
1413 xor bx,bx
1414 mov cx,304h
1415 @@number:
1416 xor ax,ax
1417 cwd
1418 @@digit:
1419 shl al,cl
1420 shl ax,cl
1421 lodsb
1422 sub al,30h
1423 cmp al,9
1424 jbe @@digit
1425 mov dl,bh
1426 mov bh,bl
1427 mov bl,ah
1428 dec ch
1429 jnz @@number
1430 xchg ax,bx
1431 pop si
1432 kver2ulret:
1433 ret
1435 endp @kver2ul$qpzc
1437 endif
1439 ;***************************************************************
1440 ;void try_default_args();
1441 ;***************************************************************
1442 ifdef EXTRA
1444 global _try_default_args:near
1445 proc _try_default_args near
1447 mov bx,offset tazboot_cmd
1448 call open
1449 jc kver2ulret
1450 mov cx,4096
1451 mov di,[_heap_top]
1452 extrn read_cmdline:near
1453 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1455 endp _try_default_args
1457 endif
1459 ends _TEXT
1461 end
1463 ;###### END OF FILE ############################################