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

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