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

linld: fix strdup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 11 12:50:44 2019 +0200 (2019-07-11)
parents 2373992ff751
children de6c5f0bf7ea
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 call xchg_heap_top
515 call @strcpy$qpxzct1
516 xchg ax,bx
517 xchg_heap_top:
518 xchg ax,[_heap_top]
519 xchg ax,bx
520 ret
522 global @malloc_or_die$qui:near
523 proc @malloc_or_die$qui near
525 xchg ax,cx ; size
526 global malloc_or_die:near ; malloc_or_die(cx)
527 malloc_or_die:
528 mov ax,[_heap_top] ; return value
529 mov bx,sp
530 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
531 sub bx,ax ; can't overflow
532 add ax,cx
533 cmp bx,cx
534 mov bx,offset msg_malloc
535 ja xchg_heap_top
537 endp @malloc_or_die$qui
540 ;***************************************************************
541 ;_fastcall int die(bx:const char* msg);
542 ;int exit();
543 ;int abort();
544 ;***************************************************************
545 global @die$qpxzc:near
546 proc @die$qpxzc near
547 @die$qpxzc:
548 global die:near ; die(bx)
549 die:
550 call puts
551 ; global _exit:near
552 _exit:
553 mov al,[_no_exit]
554 or al,al
555 jne @@hang
556 mov ah,4Ch
557 int 21h
558 @@hang:
559 mov bx, offset msg_hang
560 call puts
561 ; global _abort:near
562 _abort:
563 cli
564 hlt
565 jmp _abort
567 endp @die$qpxzc
569 struc image_himem ;struct image_himem {
570 fd dw ? ; 0 int fd;
571 fallback dd ? ; 2 u32 fallback;
572 size dd ? ; 6 u32 size;
573 remaining dd ? ;10 u32 remaining;
574 buf dd ? ;14 u32 buf;
575 bufv dw ? ;18 u32 *bufv;
576 errmsg dw ? ;20 char *errmsg;
577 chunk_size dd ? ;22 u32 chunk_size;
578 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
579 state dw ? ;28 u16 state;
580 fd2close dw ? ;30 u16 fd2close;
581 ends ;};
583 ;***************************************************************
584 ;static long next_chunk(struct image_himem *di);
585 ;***************************************************************
586 proc next_chunk near
588 push si
589 mov ax,[(image_himem di).fd]
590 call close
591 ifndef NO386
592 xor eax,eax
593 else
594 xor ax,ax
595 cwd
596 endif
597 mov [(image_himem di).fd],ax
598 mov bx,[(image_himem di).state]
599 cmp al,[bx] ; ""
600 jz @@end
601 mov si,bx
602 @@scan:
603 lodsb
604 mov cx,si
605 cmp al,','
606 jz @@eos
607 or al,al
608 jnz @@scan
609 dec cx
610 @@eos:
611 mov [(image_himem di).state],cx
612 dec si
613 push [word si]
614 mov [byte si],ah ; set temp eos
615 call open
616 pop [word si] ; restore string
617 jc @@die
618 mov [(image_himem di).fd],ax
619 mov [(image_himem di).fd2close],ax
620 mov bl,02h ; SEEK_END
621 call lseek0
622 @@die:
623 mov bx,[(image_himem di).errmsg]
624 jc die
625 ifndef NO386
626 push eax
627 mov ax,[(image_himem di).fd]
628 call rewind
629 pop eax
630 @@end:
631 mov [(image_himem di).chunk_size],eax
632 else
633 push ax
634 push dx
635 mov ax,[(image_himem di).fd]
636 call rewind
637 pop dx
638 pop ax
639 @@end:
640 mov [word (image_himem di).chunk_size],ax
641 mov [word ((image_himem di).chunk_size)+2],dx
642 endif
643 pop si
644 ret
646 endp next_chunk
649 ifdef LARGE_IMAGES
650 struc data_himem ;struct data_himem {
651 first dd ? ; 0 u32 first;
652 cacheidx dw ? ; 4 int cacheidx;
653 pageidx dw ? ; 6 int pageidx;
654 cache dd 1024 dup(?) ; 8 int cache;
655 page dd 1024 dup(?) ;4104 int page;
656 ends ;}; // size=8200
657 endif
659 ;***************************************************************
660 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
661 ;***************************************************************
662 global @malloc_bufv_or_die$qp11image_himem:near
663 proc @malloc_bufv_or_die$qp11image_himem near
665 p386
666 push si
667 mov si,bx
668 ifdef LARGE_IMAGES
669 movzx ecx,[word ((image_himem si).size) + 2]
670 shr cx,4 ; pages index size = size >> 20
671 add cx,8+4096+8
672 call malloc_or_die
673 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
674 add ecx,[(image_himem si).size]
675 shr ecx,12
676 mov [curdata],ax
677 else
678 mov ecx,[(image_himem si).size]
679 dec ecx
680 shr ecx,12
681 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
682 push cx
683 inc cx ; cnt+1
684 shl cx,2 ; bufv => vcpi => vm86
685 ; our malloc zeroes allocated mem: bufv[cnt]=0;
686 ; Allocate pages, storing addrs in addrbuf
687 call malloc_or_die
688 pop cx
689 push ax
690 endif
691 mov [(image_himem si).bufv],ax
692 xchg ax,si
693 @@vcpi_alloc:
694 xor edx,edx
695 mov ax,0DE04h
696 int 67h
697 or ah,ah
698 mov bx,offset vcpi_alloc_err
699 jnz die
700 ; for (i = cnt-1; i >= 0; i--)
701 ifdef LARGE_IMAGES
702 mov eax,ecx
703 dec eax
704 else
705 mov ax,cx
706 dec ax
707 cwde
708 endif
709 shl eax,12 ; i*_4k
710 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
711 extrn _imgs
712 mov bx,offset _imgs+2
713 push eax
714 add eax,[bx-2+2]
715 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
716 pop eax ; i*_4k
717 jbe @@pmok
718 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
719 jae @@vcpi_alloc
720 @@pmok:
721 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
722 extrn _imgs
723 mov bx,offset _imgs+32+2
724 add eax,[bx-2+2] ; +initrd.fallback
725 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
726 ja @@initrdok
727 mov eax,[bx-2+6] ; initrd.size
728 add eax,[bx-2+2] ; +initrd.fallback
729 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
730 @@jnc_vcpi_alloc:
731 ja @@vcpi_alloc
732 @@initrdok:
733 ifdef LARGE_IMAGES
734 cmp [(data_himem si).first],0
735 jne @@notfirst
736 mov [(data_himem si).first],edx
737 @@notfirst:
738 mov bx,[(data_himem si).cacheidx]
739 cmp bh,4
740 jae @@nextpage
741 shl bx,2
742 inc [(data_himem si).cacheidx]
743 mov [(data_himem bx+si).cache],edx
744 loopd @@vcpi_alloc
745 mov [(data_himem bx+si).cache],ecx ; last is 0
746 @@nextpage:
747 and [(data_himem si).cacheidx],0
748 mov bx,[(data_himem si).pageidx]
749 mov [(data_himem bx+si).page],edx
750 add [(data_himem si).pageidx],4
751 push cx
752 lea cx,[(data_himem si).cache]
753 ifdef NO386
754 push edx
755 pop dx
756 pop ax
757 endif
758 call storepage ; storepage(edx,cx)
759 pop cx
760 or ecx,ecx ; clear C
761 jnz @@jnc_vcpi_alloc
762 mov [dword (data_himem si).cacheidx],ecx
763 xchg ax,si
764 else
765 mov [si],edx
766 lodsd ; si=+4
767 loop @@vcpi_alloc
768 pop ax
769 endif
770 pop si
771 ret
772 ifdef NO386
773 p8086
774 endif
776 endp @malloc_bufv_or_die$qp11image_himem
779 ;***************************************************************
780 ;_fastcall void memcpy_image(bx:struct image_himem *m);
781 ;***************************************************************
782 global @memcpy_image$qp11image_himem:near
783 proc @memcpy_image$qp11image_himem near
785 ifndef NO386
786 mov edx,[(image_himem bx).fallback]
787 mov eax,[(image_himem bx).buf]
788 cmp eax,edx ; if (m->fallback != m->buf)
789 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
790 ifdef LARGE_IMAGES
791 mov ecx,[(image_himem bx).size]
792 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
793 push ecx
794 else
795 push [(image_himem bx).size]
796 endif
797 push eax
798 push 0
799 call_memcpy32:
800 push edx
801 else
802 mov ax,[word ((image_himem bx).fallback)]
803 mov dx,[word ((image_himem bx).fallback)+2]
804 mov cx,[word ((image_himem bx).buf)]
805 cmp ax,cx ; if (m->fallback != m->buf)
806 jnz @@do
807 cmp dx,[word ((image_himem bx).buf)+2]
808 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
809 @@do:
810 push [word ((image_himem bx).size)+2]
811 push [word ((image_himem bx).size)]
812 push [word ((image_himem bx).buf)+2]
813 push cx
814 xor cx,cx
815 push cx
816 call_memcpy32:
817 push dx
818 push ax
819 ifdef LARGE_IMAGES
820 jmp @@memcpy
821 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
822 p386
823 push ecx
824 push eax
825 push 0
826 push edx
827 ifdef NO386
828 p8086
829 endif
830 endif
831 endif
832 @@memcpy:
833 extrn memcpy32:near
834 call near memcpy32
835 @@skip:
836 ret
838 endp @memcpy_image$qp11image_himem
840 ;***************************************************************
841 ;_fastcall void storepage(bx:u32 *dst);
842 ;***************************************************************
843 global @storepage$qpul:near
844 proc @storepage$qpul near
846 ifndef NO386
847 mov edx,[bx]
848 else
849 mov ax,[bx]
850 mov dx,[bx+2]
851 endif
852 mov cx,offset _xfer_buf
853 storepage: ; storepage(edx,cx)
854 ifndef NO386
855 push 0
856 push 4096
857 push 0
858 else
859 xor bx,bx
860 push bx
861 mov bh,4096/256
862 push bx
863 xor bx,bx
864 push bx
865 endif
866 push cx
867 push ds
868 jmp call_memcpy32
870 endp @storepage$qpul
873 ifdef LARGE_IMAGES
874 p386
875 ;***************************************************************
876 ;_fastcall void reset_bufv(bx:u32 *p);
877 ;***************************************************************
878 global @reset_bufv$qpul:near
879 proc @reset_bufv$qpul near
881 mov [curdata],bx
882 and [dword (data_himem bx).cacheidx],0
883 ret
885 endp @reset_bufv$qpul
887 ;***************************************************************
888 ;u32* prev_bufv();
889 ;u32* prev_bufv();
890 ;***************************************************************
891 global _prev_bufv:near
892 global _next_bufv:near
893 proc _prev_bufv near
895 stc
896 db 73h ; jnc
897 _next_bufv:
898 clc
899 push si
900 mov si,[curdata]
901 sbb ax,ax
902 cmc
903 adc ax,[(data_himem si).cacheidx] ; -1/+1
904 xor ecx,ecx
905 test ax,0fc00h
906 jz @@gotpage
907 push ax ; FFFF / 0400
908 sar ax,8 ; FFFC / 0004
909 and al,0fch
910 add [(data_himem si).pageidx],ax
911 mov bx,[(data_himem si).pageidx]
912 lea bx,[(data_himem bx+si).page]
913 mov edx,ds
914 shl edx,4
915 lea cx,[(data_himem si).cache]
916 add edx,ecx
917 mov eax,[bx]
918 or eax,eax
919 jnz @@pageok
920 pop ax
921 xchg ax,bx
922 pop si
923 ret
924 @@pageok:
925 mov cx,4096
926 call memcpy_imagez ; get page
927 pop ax ; FFFF / 0400
928 cbw
929 shr ax,6 ; 03FF / 0000
930 @@gotpage:
931 mov [(data_himem si).cacheidx],ax
932 shl ax,2
933 xchg ax,bx
934 lea ax,[(data_himem bx+si).cache]
935 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
936 jnz @@notfirst2
937 xchg ax,si ; &first
938 @@notfirst2:
939 pop si
940 ret
942 endp _prev_bufv
943 endif
945 ifdef NO386
946 p8086
947 endif
949 ;***************************************************************
950 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
951 ;***************************************************************
953 global @open_image$qp11image_himempxzc:near
954 proc @open_image$qp11image_himempxzc near
956 push di
957 xchg ax,bx
958 xchg ax,di
959 ifdef EXTRA
960 cmp [(image_himem di).fd],0 ; iso image/kernel ?
961 jnz @@alreadydone
962 endif
963 mov [(image_himem di).state],bx
964 push bx
965 ifdef EXTRA
966 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
967 jnz @@next
968 mov [(image_himem di).next_chunk],offset next_chunk
969 @@next:
970 ;push di
971 call [(image_himem di).next_chunk] ; m->next_chunk()
972 ;pop di
973 else
974 @@next:
975 call next_chunk
976 endif
977 ifndef NO386
978 add eax,3
979 and al,0FCh
980 add [(image_himem di).size],eax ; m->size += m->chunk_size
981 or eax,eax
982 else
983 add ax,3
984 adc dx,0
985 and al,0FCh
986 add [word (image_himem di).size],ax ; m->size += m->chunk_size
987 adc [word ((image_himem di).size)+2],dx
988 or ax,dx
989 endif
990 jnz @@next
991 pop [(image_himem di).state]
992 ifdef EXTRA
993 ;push di
994 call [(image_himem di).next_chunk] ; m->next_chunk()
995 ;pop di
996 else
997 call next_chunk
998 endif
999 @@alreadydone:
1000 pop di
1001 ret
1003 endp @open_image$qp11image_himempxzc
1006 ;***************************************************************
1007 ;_fastcall int read_image(bx:struct image_himem *m);
1008 ;***************************************************************
1009 global @read_image$qp11image_himem:near
1010 proc @read_image$qp11image_himem near
1012 push si di
1013 mov di,bx
1014 mov si,4096
1015 push si ; original size
1016 @@loop:
1017 ifndef NO386
1018 movzx ecx,si
1019 mov eax,[(image_himem di).chunk_size]
1020 cmp ecx,eax
1021 jb @@szok
1022 else
1023 mov cx,si
1024 mov ax,[word (image_himem di).chunk_size]
1025 cmp cx,ax
1026 jb @@szok
1027 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1028 jne @@szok
1029 endif
1030 xchg ax,cx
1031 @@szok:
1032 jcxz image_done
1033 mov dx,offset _xfer_buf+4096
1034 sub dx,si
1035 mov bx,[di]
1036 call @read$cxdxbx
1037 jbe image_done
1038 xor cx,cx
1039 cwd ; ax < 8000h
1040 ifndef NO386
1041 cwde ; ax < 8000h
1042 sub [(image_himem di).chunk_size],eax
1043 xchg eax,ebx
1044 else
1045 sub [word (image_himem di).chunk_size],ax
1046 xchg ax,bx
1047 sbb [word ((image_himem di).chunk_size)+2],dx
1048 jnz @@fill
1049 cmp [word (image_himem di).chunk_size],dx
1050 endif
1051 jnz @@fill
1052 dec cx
1053 @@fill:
1054 test bl,3
1055 je @@filled
1056 mov [bx+_xfer_buf],dh
1057 inc bx
1058 jmp @@fill
1059 @@filled:
1060 ifndef NO386
1061 sub [(image_himem di).remaining],ebx
1062 else
1063 sub [word (image_himem di).remaining],bx
1064 sbb [word ((image_himem di).remaining)+2],dx
1065 endif
1066 sub si,bx
1067 pushf
1068 ifdef EXTRA
1069 and cx,[(image_himem di).next_chunk]
1070 jcxz @@same_chunk
1071 push di
1072 call cx
1073 pop cx
1074 else
1075 jcxz @@same_chunk
1076 call next_chunk
1077 endif
1078 @@same_chunk:
1079 popf
1080 jnz @@loop
1081 image_done:
1082 pop ax ; original size
1083 sub ax,si
1084 pop di si
1085 ret
1087 endp @read_image$qp11image_himem
1090 ;***************************************************************
1091 ;_fastcall unsigned long strtol(const char *s);
1092 ;***************************************************************
1093 global @strtol$qpxzc:near
1094 proc @strtol$qpxzc near
1096 ifndef NO386
1097 push si
1098 mov si,bx
1099 xor ecx,ecx
1100 xor eax,eax
1101 xor ebx,ebx
1102 or si,si
1103 jz @@end
1104 lodsb
1105 mov dx,ax
1106 or al,20h
1107 cmp al,'n' ; vga=normal
1108 je @@vga
1109 dec cx
1110 cmp al,'e' ; vga=extended
1111 je @@vga
1112 dec cx
1113 cmp al,'a' ; vga=ask
1114 jne @@notvga
1115 @@vga:
1116 dec cx
1117 xchg ax,cx
1118 cwd
1119 jmp @@popsiret
1120 @@notvga:
1121 mov cx,10 ; radix
1122 xchg ax,dx
1123 cmp al,'+'
1124 je @@radixskip
1125 cmp al,'-'
1126 clc
1127 jne @@radixkeep
1128 stc
1129 @@radixskip:
1130 lodsb
1131 @@radixkeep:
1132 pushf
1133 cmp al,'0'
1134 jne @@radixok
1135 mov cl,8
1136 lodsb
1137 or al,20h
1138 cmp al,'x'
1139 jne @@radixok
1140 mov cl,16
1141 @@strtollp:
1142 lodsb
1143 @@radixok:
1144 or al,20h
1145 sub al,'0'
1146 jb @@endstrtol
1147 cmp al,9
1148 jbe @@digitok
1149 cmp al,'a'-'0'
1150 jb @@endstrtol
1151 sub al,'a'-'0'-10
1152 @@digitok:
1153 cmp al,cl
1154 jae @@endstrtol
1155 xchg eax,ebx
1156 mul ecx
1157 add eax,ebx
1158 xchg eax,ebx
1159 jmp @@strtollp
1160 @@endstrtol:
1161 mov cl,10
1162 cmp al,'k'-'a'+10
1163 je @@shift
1164 mov cl,20
1165 cmp al,'m'-'a'+10
1166 je @@shift
1167 mov cl,30
1168 cmp al,'g'-'a'+10
1169 jne @@noshift
1170 @@shift:
1171 shl ebx,cl
1172 @@noshift:
1173 popf
1174 jnc @@end
1175 neg ebx
1176 @@end:
1177 push ebx
1178 pop ax
1179 pop dx
1180 @@popsiret:
1181 pop si
1182 else
1183 push si
1184 push di
1185 xor ax,ax
1186 cwd
1187 or bx,bx
1188 jz @@goend
1189 xchg ax,di
1190 mov si,bx
1191 lodsb
1192 mov bx,ax
1193 or al,20h
1194 mov cx,-1
1195 cmp al,'n' ; vga=normal
1196 je @@vga
1197 dec cx
1198 cmp al,'e' ; vga=extended
1199 je @@vga
1200 dec cx
1201 cmp al,'a' ; vga=ask
1202 jne @@notvga
1203 @@vga:
1204 xchg ax,cx
1205 @@goend:
1206 jmp @@popdisiret
1207 @@notvga:
1208 mov cx,10 ; radix
1209 xchg ax,bx
1210 cmp al,'+'
1211 je @@radixskip
1212 cmp al,'-'
1213 clc
1214 jne @@radixkeep
1215 stc
1216 @@radixskip:
1217 lodsb
1218 @@radixkeep:
1219 pushf
1220 cmp al,'0'
1221 jne @@radixok
1222 mov cl,8
1223 lodsb
1224 or al,20h
1225 cmp al,'x'
1226 jne @@radixok
1227 mov cl,16
1228 @@strtollp:
1229 lodsb
1230 @@radixok:
1231 or al,20h
1232 sub al,'0'
1233 jb @@endstrtol
1234 cmp al,9
1235 jbe @@digitok
1236 cmp al,'a'-'0'
1237 jb @@endstrtol
1238 sub al,'a'-'0'-10
1239 @@digitok:
1240 cmp al,cl
1241 jae @@endstrtol
1243 push ax
1244 push si
1245 push dx
1246 xchg ax,di
1247 mul cx
1248 xchg ax,di
1249 xchg ax,dx
1250 xchg ax,si
1251 pop ax
1252 mul cx
1253 add ax,si
1254 pop si
1255 xchg ax,dx
1256 pop ax
1257 mov ah,0
1258 add di,ax
1259 adc dx,0
1261 jmp @@strtollp
1262 @@endstrtol:
1263 mov cl,10
1264 cmp al,'k'-'a'+10
1265 je @@shift
1266 mov cl,20
1267 cmp al,'m'-'a'+10
1268 je @@shift
1269 mov cl,30
1270 cmp al,'g'-'a'+10
1271 jne @@noshift
1272 @@shift:
1273 rcl di,1
1274 shl dx,1
1275 loop @@shift
1276 @@noshift:
1277 popf
1278 jnc @@end
1279 not dx
1280 neg di
1281 jne @@end
1282 inc dx
1283 @@end:
1284 xchg ax,di
1285 @@popdisiret:
1286 pop di
1287 pop si
1288 endif
1289 strtol_ret:
1290 ret
1292 endp @strtol$qpxzc
1295 ifdef USE_ARGSTR
1296 ;***************************************************************
1297 ;_fastcall void set_cmdline(bx:const char *filename);
1298 ;***************************************************************
1299 global @set_cmdline$qpxzc:near
1300 proc @set_cmdline$qpxzc near
1301 call openargs
1302 jc strtol_ret
1303 mov cx,4096
1304 mov di,[_heap_top]
1305 extrn read_cmdline:near
1306 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1308 endp @set_cmdline$qpxzc
1309 endif
1312 ifdef NO386
1313 ;***************************************************************
1314 ;u16 topseg();
1315 ;***************************************************************
1316 global _topseg:near
1317 proc _topseg near
1319 int 12h
1320 jnc @@max640k
1321 mov ax,640 ; 9000
1322 @@max640k:
1323 dec ax
1324 and al,0C0h
1325 mov cl,6
1326 shl ax,cl
1327 ret
1329 endp _topseg
1330 endif
1332 ifdef EXTRA
1333 p8086
1334 ;***************************************************************
1335 ;char *progname(void)
1336 ;***************************************************************
1337 global _progname:near
1338 proc _progname near
1340 push si di
1341 mov ah,30h
1342 int 21h
1343 xor di,di
1344 cmp al,3
1345 mov ax,di
1346 jb @@skip
1347 ;mov es,[cs:2Ch]
1348 mov es,[di+2Ch]
1349 mov cx,sp ; big enough
1350 @@loop:
1351 repne
1352 scasb
1353 scasb
1354 jne @@loop
1355 inc di
1356 inc di
1357 mov si,di ; progname @es:di
1358 repne
1359 scasb
1360 mov cx,di
1361 sub cx,si ; progname len
1362 call malloc_or_die ; keep cx
1363 mov di,ax
1364 push ds
1365 push es
1366 pop ds
1367 pop es
1368 rep
1369 movsb
1370 push es
1371 pop ds
1372 @@skip:
1373 pop di si
1374 ret
1376 endp _progname
1379 ;***************************************************************
1380 ;_fastcall void chdirname(bx:char *path)
1381 ;***************************************************************
1382 global @chdirname$qpzc:near
1383 proc @chdirname$qpzc near
1385 cmp [byte bx+1],3Ah ; ':'
1386 jne @@nodisk
1387 mov dl,20h
1388 or dl,[bx]
1389 sub dl,61h
1390 mov ah,0Eh
1391 int 21h
1392 inc bx
1393 inc bx
1394 @@nodisk:
1395 xor cx,cx
1396 @@next:
1397 mov al,[bx]
1398 cmp al,5Ch
1399 jne @@tsteos
1400 mov dx,bx
1401 inc cx
1402 @@tsteos:
1403 inc bx
1404 or al,al
1405 jnz @@next
1406 jcxz @@end
1407 mov bx,dx
1408 push [word bx]
1409 mov [bx],al
1410 ifdef LONG_FILENAME
1411 stc
1412 mov ax,713Bh ; chdir long filename (ds:dx)
1413 int 21h
1414 jnc @@chdirdone
1415 endif
1416 mov ah,3Bh ; chdir(ds:dx)
1417 int 21h
1418 @@chdirdone:
1419 pop [word bx]
1420 @@end:
1421 ret
1423 endp @chdirname$qpzc
1426 ;***************************************************************
1427 ;_fastcall char *ultoa(axdx:unsigned long n);
1428 ;***************************************************************
1429 global @ultoa$qul:near
1430 proc @ultoa$qul near
1432 xchg ax,cx
1433 xchg ax,dx ; AX:CX = n
1434 push si
1435 mov si,10
1436 mov bx,offset ultoabuf+11
1437 @@loop:
1438 dec bx
1439 xor dx,dx
1440 div si ; DX:AX = 0000:hi(n)
1441 xchg ax,cx ; CX = hi(n)/10
1442 div si ; DX:AX = hi(n)%10:lo(n)
1443 xchg ax,cx ; CX = lo(n/10)
1444 ; AX = hi(n)/10 = hi(n/10)
1445 mov [byte bx],'0'
1446 add [bx],dl ; DL = n%10
1447 mov dx,ax
1448 or dx,cx
1449 jnz @@loop
1450 xchg ax,bx
1451 pop si
1452 ret
1454 endp @ultoa$qul
1457 ;***************************************************************
1458 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1459 ;***************************************************************
1460 global @kver2ul$qpzc:near
1461 proc @kver2ul$qpzc near
1463 push si
1464 mov si,bx
1465 xor bx,bx
1466 mov cx,304h
1467 @@number:
1468 xor ax,ax
1469 cwd
1470 @@digit:
1471 shl al,cl
1472 shl ax,cl
1473 lodsb
1474 sub al,30h
1475 cmp al,9
1476 jbe @@digit
1477 mov dl,bh
1478 mov bh,bl
1479 mov bl,ah
1480 dec ch
1481 jnz @@number
1482 xchg ax,bx
1483 pop si
1484 kver2ulret:
1485 ret
1487 endp @kver2ul$qpzc
1489 endif
1491 ;***************************************************************
1492 ;void try_default_args();
1493 ;***************************************************************
1494 ifdef EXTRA
1496 global _try_default_args:near
1497 proc _try_default_args near
1499 mov bx,offset tazboot_cmd
1500 call open
1501 jc kver2ulret
1502 mov cx,4096
1503 mov di,[_heap_top]
1504 extrn read_cmdline:near
1505 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1507 endp _try_default_args
1509 endif
1511 ends _TEXT
1513 end
1515 ;###### END OF FILE ############################################