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

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