wok-current view linld/stuff/src/CRTL.ASM @ rev 21628

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