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

sylpheed: update $WGET_URL
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Oct 17 10:59:42 2019 +0200 (2019-10-17)
parents 6e3d30b3031f
children 5b6c86ca3faa
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT,_DATA,_BSS
16 assume cs:DGROUP,ds:DGROUP
18 segment _DATA byte public use16 'DATA'
20 global _heap_top
21 extrn _bss_end
22 _heap_top dw _bss_end
23 msg_hang db "High mem corrupted - not exiting to DOS",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 ifdef EXTRA
35 ;typedef unsigned dirsizetype;
36 struc isostate ; struct isostate {
37 curpos dw ? ; 0 unsigned curpos;
38 filename2open dw ? ; 2 char *filename2open;
39 fd dw ? ; 4 int fd;
40 filemod dw ? ; 6 unsigned short filemod;
41 fileofs dd ? ; 8 unsigned long fileofs;
42 filesize dd ? ;12 unsigned long filesize;
43 filename dw ? ;16 char *filename;
44 curdirsize dw ? ;18 dirsizetype curdirsize;
45 dirsize dw ? ;20 dirsizetype dirsize;
46 curdirofs dd ? ;22 unsigned long curdirofs;
47 dirofs dd ? ;26 unsigned long dirofs;
48 ;overlap
49 entrysize dw ? ;30 int entrysize;
50 tmp dw ? ;32 const char *tmp;
51 c db ? ;34 char c;
52 _64bits db ? ;35 char _64bits;
53 buffer db ? ;36 char buffer[2048+512];
54 ends ; } isostate;
55 public _isostate
56 _isostate isostate <?>
57 org $-7
58 endif
59 _xfer_buf db 4096 dup (?)
60 global _no_exit:byte
61 _no_exit db ?
62 filecnt db ? ; in fact 0 minus file count...
63 nextfilename dw ?
64 ifdef LARGE_IMAGES
65 curdata dw ?
66 endif
67 ifdef EXTRA
68 ultoabuf db 12 dup (?)
69 endif
71 ends _BSS
73 segment _TEXT byte public use16 'CODE'
75 ;***************************************************************
76 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
77 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
78 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
79 ;***************************************************************
80 ifdef EXTRA
81 global @strcat$qpxzct1:near
82 @strcat$qpxzct1:
83 mov cx,1h
84 db 0bah ; mov dx,imm opcode
85 endif
86 global @strcatb$qpxzct1:near
87 proc @strcatb$qpxzct1 near
89 mov cl,7Fh
90 db 0bah ; mov dx,imm opcode
91 global @strcpy$qpxzct1:near
92 @strcpy$qpxzct1:
93 xor cx,cx
94 push si
95 xchg ax,si ; b
96 jcxz @@nocat
97 dec bx
98 @@catlp:
99 inc bx
100 cmp [byte bx],0 ; a=bx
101 jne @@catlp
102 ifdef EXTRA
103 mov al,20h
104 loop @@cpyhead
105 else
106 db 0b8h,20h ; mov ax,??20h
107 endif
108 @@nocat:
109 @@cpylp:
110 lodsb
111 @@cpyhead:
112 mov [bx],al
113 inc bx
114 or al,al
115 jne @@cpylp
116 strfound:
117 xchg ax,dx
118 strend:
119 pop si
120 ret
122 endp @strcatb$qpxzct1
125 ifdef EXTRA
126 p8086
127 ;***************************************************************
128 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
129 ;***************************************************************
130 global @strstr$qpxzct1:near
131 proc @strstr$qpxzct1 near
133 xchg ax,cx ; b
134 mov dx,bx ; a
135 push si
136 @@loop:
137 xor ax,ax
138 mov si,dx
139 cmp [si],al ; *a
140 jz strend ; return ax = NULL
141 mov bx,cx
142 @@match:
143 or ah,[bx] ; *b
144 jz strfound
145 inc bx
146 lodsb
147 sub ah,al
148 jz @@match
149 inc dx
150 jmp @@loop
152 endp @strstr$qpxzct1
155 ;***************************************************************
156 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
157 ;***************************************************************
158 global @strcmp$qpxzct1:near
159 proc @strcmp$qpxzct1 near
161 push si
162 xchg ax,si
163 dec bx
164 @@lp:
165 inc bx
166 lodsb
167 sub al,[bx]
168 jnz @@out
169 or al,[bx]
170 jnz @@lp
171 @@out:
172 cbw
173 pop si
174 ret
176 endp @strcmp$qpxzct1
177 endif
180 ;***************************************************************
181 ;_fastcall void puts(bx:const char* s):
182 ;***************************************************************
183 global @puts$qpxzc:near
185 ; global puts:near ; puts(bx)
186 @putsz:
187 call @putc
188 @puts$qpxzc:
189 puts:
190 mov dl,[bx]
191 inc bx
192 or dl,dl
193 jne @putsz
194 mov dl,10
195 @putc:
196 cmp dl,10
197 jne @putcz
198 call @putcz2
199 @putcz2:
200 xor dl,7 ; 10^13 1010^1101
201 @putcz:
202 mov ah,2
203 int 21h
204 ret
207 ;***************************************************************
208 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
209 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
210 ;***************************************************************
211 global openargs:near ; openargs(bx)
212 openargs:
213 cmp [byte bx],'@'
214 jne fail
215 inc bx
217 global @open$qpxzc:near
218 proc @open$qpxzc near
220 open: ; open(bx)
221 ifdef LONG_FILENAME
222 mov ax,716Ch
223 push bx si di
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 di si 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 les dx,[dword bx]
359 mov cx,es
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 inc bx
460 cmp [byte bx-1],0
461 jne @@notopt
462 stc
463 jmp @@nokeyword
464 @@found:
465 mov [di],si
466 dec dx
467 dec dx
468 je @@done
469 ;mov bx,si
470 call @strtol$qpxzc
471 mov [di],ax
472 mov [di+2],dx
473 @@done:
474 clc
475 @@nokeyword:
476 sbb ax,ax
477 pop di si
478 ret
480 endp @argstr$qpxzcxt1ppxzc
482 else
484 ;***************************************************************
485 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
486 ;***************************************************************
487 global @strhead$qpxzct1:near
488 proc @strhead$qpxzct1 near
490 @@loop:
491 xchg ax,bx
492 mov cl,[bx] ; cl = *b++
493 inc bx
494 or cl,cl ; clear C
495 jz failifc ; return 0
496 xchg ax,bx
497 xor cl,[bx] ; cl -= *a++
498 inc bx
499 and cl,0dfh ; case insensitive
500 jne fail ; return -1
501 jmp @@loop
503 endp @strhead$qpxzct1
505 endif
507 ;***************************************************************
508 ;_fastcall char* strdup(bx:const char* a);
509 ;_fastcall char* malloc_or_die(ax:unsigned size);
510 ;***************************************************************
511 global @strdup$qpxzc:near
512 @strdup$qpxzc:
513 strdup: ; ax = strdup(bx)
514 mov ax,[_heap_top]
515 xchg ax,bx
516 call @strcpy$qpxzct1 ; bx = strcpy(bx, ax) end +1
517 xchg ax,bx
518 xchg_heap_top:
519 xchg ax,[_heap_top]
520 ret
522 global @malloc_or_die$qui:near
523 proc @malloc_or_die$qui near
525 global malloc_or_die:near ; ax = malloc_or_die(ax)
526 malloc_or_die:
527 mov bx,offset msg_malloc
528 add ax,[_heap_top]
529 jnc xchg_heap_top
531 endp @malloc_or_die$qui
534 ;***************************************************************
535 ;_fastcall int die(bx:const char* msg);
536 ;int exit();
537 ;int abort();
538 ;***************************************************************
539 global @die$qpxzc:near
540 proc @die$qpxzc near
541 @die$qpxzc:
542 global die:near ; die(bx)
543 die:
544 call puts
545 global @exit$qv:near
546 @exit$qv:
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 les ax,[dword ((image_himem bx).fallback)]
798 mov dx,es
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 les ax,[dword bx]
845 mov dx,es
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 ifndef USE_ARGSTR
1089 global @strtol$qpxzc:near
1090 endif
1091 proc @strtol$qpxzc near
1093 ifndef NO386
1094 ifndef USE_ARGSTR
1095 push si
1096 mov si,bx
1097 endif
1098 xor ecx,ecx
1099 xor eax,eax
1100 xor ebx,ebx
1101 or si,si
1102 jz @@end
1103 lodsb
1104 or al,20h
1105 cmp al,'a'
1106 jb @@notvga
1107 sub al,'n'
1108 @@vgaloop:
1109 dec cx
1110 add al,6
1111 jb @@vgaloop ; vga=normal,extended,ask
1112 @@vga:
1113 dec cx
1114 xchg ax,cx
1115 cwd
1116 jmp @@popsiret
1117 @@notvga:
1118 mov cx,10 ; radix
1119 cmp al,'-'
1120 ja @@radixkeep
1121 cmc ; '+'=2B:C=0 '-'=2D:C=1
1122 lodsb
1123 @@radixkeep:
1124 pushf
1125 cmp al,'0'
1126 jne @@radixok
1127 mov cl,8
1128 lodsb
1129 or al,20h
1130 cmp al,'x'
1131 jne @@radixok
1132 mov cl,16
1133 @@strtollp:
1134 lodsb
1135 @@radixok:
1136 or al,20h
1137 sub al,'0'
1138 jb @@endstrtol
1139 cmp al,9
1140 jbe @@digitok
1141 cmp al,'a'-'0'
1142 jb @@endstrtol
1143 sub al,'a'-'0'-10
1144 @@digitok:
1145 cmp al,cl
1146 jae @@endstrtol
1147 xchg eax,ebx
1148 mul ecx
1149 add eax,ebx
1150 xchg eax,ebx
1151 jmp @@strtollp
1152 @@endstrtol:
1153 mov cl,10
1154 cmp al,'k'-'a'+10
1155 je @@shift
1156 mov cl,20
1157 cmp al,'m'-'a'+10
1158 je @@shift
1159 mov cl,30
1160 cmp al,'g'-'a'+10
1161 jne @@noshift
1162 @@shift:
1163 shl ebx,cl
1164 @@noshift:
1165 popf
1166 jnc @@end
1167 neg ebx
1168 @@end:
1169 push ebx
1170 pop ax
1171 pop dx
1172 @@popsiret:
1173 ifndef USE_ARGSTR
1174 pop si
1175 endif
1176 else
1177 ifndef USE_ARGSTR
1178 push si di
1179 xor ax,ax
1180 cwd
1181 or bx,bx
1182 else
1183 push di
1184 xor ax,ax
1185 cwd
1186 or si,si
1187 endif
1188 jz @@goend
1189 xchg ax,di
1190 ifndef USE_ARGSTR
1191 mov si,bx
1192 endif
1193 lodsb
1194 or al,20h
1195 cmp al,'a'
1196 jb @@notvga
1197 xor cx,cx
1198 sub al,'n'
1199 @@vgaloop:
1200 dec cx
1201 add al,6
1202 jb @@vgaloop ; vga=normal,extended,ask
1203 @@vga:
1204 xchg ax,cx
1205 @@goend:
1206 jmp @@popdisiret
1207 @@notvga:
1208 mov cx,10 ; radix
1209 cmp al,'-'
1210 ja @@radixkeep
1211 cmc ; '+'=2B:C=0 '-'=2D:C=1
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 dx
1240 xchg ax,bx
1241 mul cx
1242 xchg ax,bx
1243 xchg ax,dx
1244 xchg ax,di
1245 pop ax
1246 mul cx
1247 add ax,di
1248 xchg ax,dx
1249 pop ax
1250 mov ah,0
1251 add bx,ax
1252 adc dx,0
1254 jmp @@strtollp
1255 @@endstrtol:
1256 mov cl,10
1257 cmp al,'k'-'a'+10
1258 je @@shift
1259 mov cl,20
1260 cmp al,'m'-'a'+10
1261 je @@shift
1262 mov cl,30
1263 cmp al,'g'-'a'+10
1264 jne @@noshift
1265 @@shift:
1266 rcl di,1
1267 shl dx,1
1268 loop @@shift
1269 @@noshift:
1270 popf
1271 jnc @@end
1272 not dx
1273 neg bx
1274 jne @@end
1275 inc dx
1276 @@end:
1277 xchg ax,bx
1278 @@popdisiret:
1279 ifndef USE_ARGSTR
1280 pop di si
1281 else
1282 pop di
1283 endif
1284 endif
1285 strtol_ret:
1286 ret
1288 endp @strtol$qpxzc
1291 ifdef USE_ARGSTR
1292 ;***************************************************************
1293 ;_fastcall void set_cmdline(bx:const char *filename);
1294 ;***************************************************************
1295 global @set_cmdline$qpxzc:near
1296 proc @set_cmdline$qpxzc near
1297 call openargs
1298 jc strtol_ret
1299 mov cx,4096
1300 mov di,[_heap_top]
1301 extrn read_cmdline:near
1302 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1304 endp @set_cmdline$qpxzc
1305 endif
1308 ifdef NO386
1309 ;***************************************************************
1310 ;u16 topseg();
1311 ;***************************************************************
1312 global _topseg:near
1313 proc _topseg near
1315 int 12h
1316 jnc @@max640k
1317 mov ax,640 ; 9000
1318 @@max640k:
1319 dec ax
1320 and al,0C0h
1321 mov cl,6
1322 shl ax,cl
1323 ret
1325 endp _topseg
1326 endif
1328 ifdef EXTRA
1329 p8086
1330 ;***************************************************************
1331 ;_fastcall char *ultoa(axdx:unsigned long n);
1332 ;***************************************************************
1333 global @ultoa$qul:near
1334 proc @ultoa$qul near
1336 xchg ax,cx
1337 xchg ax,dx ; AX:CX = n
1338 push si
1339 mov si,10
1340 mov bx,offset ultoabuf+11
1341 @@loop:
1342 dec bx
1343 xor dx,dx
1344 div si ; DX:AX = 0000:hi(n)
1345 xchg ax,cx ; CX = hi(n)/10
1346 div si ; DX:AX = hi(n)%10:lo(n)
1347 xchg ax,cx ; CX = lo(n/10)
1348 ; AX = hi(n)/10 = hi(n/10)
1349 mov [byte bx],'0'
1350 add [bx],dl ; DL = n%10
1351 mov dx,ax
1352 or dx,cx
1353 jnz @@loop
1354 xchg ax,bx
1355 pop si
1356 ret
1358 endp @ultoa$qul
1361 ;***************************************************************
1362 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1363 ;***************************************************************
1364 global @kver2ul$qpzc:near
1365 proc @kver2ul$qpzc near
1367 push si
1368 mov si,bx
1369 xor bx,bx
1370 mov cx,304h
1371 @@number:
1372 xor ax,ax
1373 cwd
1374 @@digit:
1375 shl al,cl
1376 shl ax,cl
1377 lodsb
1378 sub al,30h
1379 cmp al,9
1380 jbe @@digit
1381 mov dl,bh
1382 mov bh,bl
1383 mov bl,ah
1384 dec ch
1385 jnz @@number
1386 xchg ax,bx
1387 pop si
1388 kver2ulret:
1389 ret
1391 endp @kver2ul$qpzc
1393 endif
1395 ;***************************************************************
1396 ;void try_default_args();
1397 ;***************************************************************
1398 ifdef EXTRA
1400 global _try_default_args:near
1401 proc _try_default_args near
1403 mov bx,offset tazboot_cmd
1404 call open
1405 jc kver2ulret
1406 mov cx,4096
1407 mov di,[_heap_top]
1408 extrn read_cmdline:near
1409 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1411 endp _try_default_args
1413 endif
1415 ends _TEXT
1417 end
1419 ;###### END OF FILE ############################################