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

linld: fix iso9660/64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Mar 06 18:15:05 2021 +0000 (2021-03-06)
parents 61df94a0fa43
children 217c02cbbe8d
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT,_DATA,_BSS
19 assume cs:DGROUP,ds:DGROUP
21 segment _DATA byte public use16 'DATA'
23 loaderr db "Load failure",0
24 msg_hang db "Himem broken",0
25 ifdef VCPI
26 vcpi_alloc_err db "VCPI"
27 endif
28 global overflow:byte
29 overflow db "/"
30 msg_malloc db "Out of memory"
31 isorootofs dd 16*2048
33 ends _DATA
35 segment _BSS byte public use16 'BSS'
37 ifdef ISO9660
38 include "isostate.inc"
39 public _isostate
40 _isostate isostate <?>
41 org $-7
42 endif
43 global buf4k:byte
44 label buf4k byte
45 _xfer_buf db 4096 dup (?)
46 filecnt db ? ; in fact 0 minus file count...
47 nextfilename dw ?
49 ends _BSS
51 segment _TEXT byte public use16 'CODE'
53 ;***************************************************************
54 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
55 ;***************************************************************
56 global @strcatb$qpxzct1:near
57 proc @strcatb$qpxzct1 near
59 push si
60 xchg ax,si ; b
61 dec bx
62 @@catlp:
63 inc bx
64 cmp [byte bx],0 ; a=bx
65 jne @@catlp
66 db 0b8h,20h ; mov ax,??20h
67 @@cpylp:
68 lodsb
69 mov [bx],al
70 inc bx
71 or al,al
72 jne @@cpylp
73 pop si
74 catret:
75 ret
77 endp @strcatb$qpxzct1
80 ifdef NO386
81 p8086
82 endif
84 ifndef ISO9660
85 ;***************************************************************
86 ;_fastcall int:C open(bx:const char* name, int flags=O_RDONLY);
87 ;_fastcall int:C openargs(bx:const char* name, int flags=O_RDONLY);
88 ;***************************************************************
89 global openargs:near ; openargs(bx)
90 openargs:
91 cmp [byte bx],'@'
92 jne fail
93 inc bx
95 global @open$qpxzc:near
96 @open$qpxzc:
97 endif
98 opendos:
99 ifdef LONG_FILENAME
100 ;xchg ax,cx ; attributes
101 mov ax,716Ch
102 push bx si
103 mov si,bx
104 xor bx,bx ; R/O
105 cwd ; action = open
106 stc
107 int 21h
108 pop si dx
109 jnc openok
110 mov ax,3d00h ; read-only+compatibility
111 else
112 mov ah,3dh ; read-only+compatibility
113 mov dx,bx
114 endif
115 ;mov cl,0 ; attribute mask
116 call dos
117 ifdef ISO9660
118 jc catret
119 openok:
120 xchg ax,bx
121 mov ax,4202h
122 cwd
123 xor cx,cx
124 int 21h
125 mov [word _isostate.filesize],ax
126 mov [(word _isostate.filesize)+2],dx
127 xchg ax,bx
128 ;xor cx,cx
129 cwd
130 call seeksetpos0 ; filepos = 0
131 else
132 openok:
133 endif
134 xchg ax,bx ; fd
135 ret
137 ifdef ISO9660
138 ;***************************************************************
139 ;_fastcall int:C open(bx:const char* name, int flags=O_RDONLY);
140 ;_fastcall int:C openargs(bx:const char* name, int flags=O_RDONLY);
141 ;***************************************************************
142 global openargs:near ; openargs(bx)
143 openargs:
144 cmp [byte bx],'@'
145 jne fail
146 inc bx
148 global @open$qpxzc:near
149 @open$qpxzc:
150 ifdef LONG_FILENAME
151 mov cx,[_isostate.fd]
152 jcxz opendos
153 xchg ax,cx
154 else
155 mov ax,[_isostate.fd]
156 or ax,ax
157 je opendos
158 endif
159 ifdef ISOHOOK
160 cmp [byte bx],'!'
161 je @readmenu$qv
162 endif
163 extrn @_isoopen$qv:near
164 mov [word _isostate.filename2open],bx
165 jmp @_isoopen$qv ; filepos = 0
166 endif
169 ;***************************************************************
170 ;_fastcall int fileexist(bx:const char* name);
171 ;***************************************************************
172 global @fileexist$qpxzc:near
173 @fileexist$qpxzc:
174 call @open$qpxzc
175 jc fail
177 ;***************************************************************
178 ;_fastcall int close(ax:int fd);
179 ;***************************************************************
180 global @close$qi:near
181 proc @close$qi near
183 global close:near ; close(ax)
184 close:
185 mov bh,3Eh
186 ifdef ISO9660
187 mov cx,[_isostate.fd]
188 jcxz dosbx
189 endif
190 jmp fail
192 endp @close$qi
195 ;***************************************************************
196 ;_fastcall int readrm(si:struct himem *m, ax:int sz);
197 ;***************************************************************
198 global @readrm$qp11image_himemi:near
199 @readrm$qp11image_himemi:
200 xchg ax,dx ; sz
201 mov ax,[si] ; fd
202 mov bx,[si-2] ; data
203 proc @read$qipvi near
205 @read$dxbxax:
206 xchg ax,bx ; fd
207 @read$dxaxbx:
208 xchg ax,dx ; data
209 xchg ax,cx ; sz
210 global @read$cxdxbx:near
211 @read$cxdxbx:
212 ifdef ISO9660
213 push bx
214 mov bx,offset _isostate.filepos
215 push cx
216 mov cx,[bx-4] ; filesize
217 sub cx,[bx] ; filepos
218 mov ax,[bx-2]
219 sbb ax,[bx+2]
220 pop ax
221 ja @@axok
222 ;je @@rem
223 ;xor ax,ax
224 @@rem:
225 cmp cx,ax
226 jb @@cxok
227 @@axok:
228 xchg ax,cx
229 @@cxok:
230 add [bx],cx
231 adc [(word bx)+2],0
232 pop bx
233 endif
234 readfd:
235 mov ah,3Fh
236 ;jcxz fail
237 dos:
238 int 21h
239 jnc doret
240 fail:
241 stc
242 failifc:
243 sbb ax,ax ; ax=-1 CF
244 doret:
245 ret
247 endp @read$qipvi
249 ;***************************************************************
250 ;_fastcall long rewind(ax:int fd);
251 ;***************************************************************
253 global @rewind$qi:near ; fd=ax
254 proc @rewind$qi near
256 rewind:
257 ifdef ISO9660
258 mov bx,offset _isostate.fileofs
259 jmp lseek
260 else
261 mov bl,0
262 lseek0:
263 xor cx,cx
264 xor dx,dx
265 jmp lseek
266 endif
268 endp @rewind$qi
271 ifdef ISOHOOK
272 ;***************************************************************
273 ;_fastcall int:bx readmenu(void);
274 ;***************************************************************
275 proc @readmenu$qv near
277 mov dx,18
278 xor cx,cx
279 call seeksetpos0 ; filepos = 0
280 mov dx,offset _isostate.filemod
281 ; //magic = x->filemod;
282 mov cl,10
283 call readfd ; // read x->filemod + x->fileofs & x->filesize
284 mov bx,offset _isostate.fileofs
285 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
286 mov ax,7FF0h
287 cwd
288 mov [word bx+6],dx
289 sub ax,[bx+4]
290 mov [word bx+2],dx
291 mov [bx],ax
292 call isolseek ; filepos = 0
293 xchg ax,bx ; fd
294 ret
296 endp @readmenu$qv
297 endif
299 ;***************************************************************
300 ;_fastcall void isolseek(bx:const unsigned long *offset);
301 ;***************************************************************
302 global @isolseek$qpxul:near
303 proc @isolseek$qpxul near
305 ifdef ISO9660
306 isolseek:
307 mov ax,[_isostate.fd]
308 lseek:
309 les dx,[dword bx]
310 mov cx,es
311 seeksetpos0:
312 xor bx,bx
313 mov [word _isostate.filepos],bx
314 mov [(word _isostate.filepos)+2],bx
315 else
316 lseek:
317 endif
318 mov bh,42h ; bx=fd cx:dx=offset al=whence
319 dosbx:
320 xchg ax,bx
321 jmp dos ; bx = fd
323 endp @isolseek$qpxul
325 ifdef ISO9660
326 ;***************************************************************
327 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
328 ;_fastcall int isoreadrootsector(void);
329 ;***************************************************************
330 global @isoreadrootsector$qv:near
331 @isoreadrootsector$qv:
332 mov bx,offset isorootofs
333 global @isoreadsector$qpxul:near
334 proc @isoreadsector$qpxul near
336 call isolseek ; filepos = 0
337 jc fail
338 mov dh,10
339 mov ax,offset _isostate.buffer
340 jmp @read$dxaxbx ; read(fd,buffer,2560+)
342 endp @isoreadsector$qpxul
343 endif
346 ifdef ISO9660
347 ifdef ISOHOOK
348 ;***************************************************************
349 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
350 ;***************************************************************
351 global @strhead$qpxzct1:near
352 proc @strhead$qpxzct1 near
354 @@loop:
355 xchg ax,bx
356 mov dl,[bx] ; dl = *b++
357 inc bx
358 xchg ax,bx
359 or dl,dl ; clear C
360 jz failifc ; return 0, bx=a tail
361 xor dl,[bx] ; dl -= *a++
362 jne fail ; return -1
363 inc bx
364 jmp @@loop
366 endp @strhead$qpxzct1
369 ;***************************************************************
370 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
371 ;***************************************************************
372 global @strcmp$qpxzct1:near
373 proc @strcmp$qpxzct1 near
375 call @strhead$qpxzct1
376 jne fail ; return -1
377 xor dl,[bx] ; clear C
378 jne fail ; return -1
379 jmp failifc ; return 0
381 endp @strcmp$qpxzct1
383 else
385 ;***************************************************************
386 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
387 ;***************************************************************
388 global @strcmp$qpxzct1:near
389 proc @strcmp$qpxzct1 near
391 @@loop:
392 xchg ax,bx
393 mov dl,[bx] ; dl = *b++
394 inc bx
395 xchg ax,bx
396 xor dl,[bx] ; dl ^= *a++
397 ifndef ROCKRIDGE
398 and dl,0dfh ; case insensitive
399 endif
400 jne fail ; return -1
401 inc bx
402 or dl,dl ; clear C
403 jz failifc ; return 0
404 jmp @@loop
406 endp @strcmp$qpxzct1
407 endif
408 endif
410 ;***************************************************************
411 ;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
412 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
413 ;***************************************************************
414 global @argstr$qpxzcxt1ppxzc:near
415 proc @argstr$qpxzcxt1ppxzc near
417 mov cl,2
418 db 0a9h ; test ax,#
419 global @argnum$qpzcxpxzcpul:near
420 @argnum$qpzcxpxzcpul:
421 mov cl,4
422 push bx
423 xchg ax,bx ; keywords -> bx
424 xchg ax,cx ; s -> cx
425 cbw ; argstr:0002 argnum:0004
426 xchg ax,dx ; vars -> ax
427 push si di
428 xchg ax,di ; vars => di
429 dec bx
430 sub di,dx
431 @@loop:
432 mov si,cx ; s
433 add di,dx
434 @@match:
435 lodsb ; *s++
436 or al,20h ; locase
437 cmp al,'/' ; 2f
438 jne @@notopt
439 mov al,'-'
440 @@notopt:
441 inc bx ; keywords++
442 cmp al,[bx]
443 je @@match
444 cmp [byte bx],dh
445 je @@lastal
446 cmp [byte bx],'|'
447 je @@testal
448 jl @@notsw ; } ~ <del>
449 cmp al,20h ; EOS or 20h
450 jne @@loop ; assume [bx] = '|'
451 @@notsw:
452 mov al,-1
453 jne @@notopt
454 jmp @@setnum
455 @@testal:
456 cmp al,-1
457 jz @@loop
458 @@lastal:
459 cmp al,'='
460 xchg ax,cx ; return s if failure
461 jne @@nokeyword
462 dec dx
463 dec dx
464 je @@done
465 @strtol$qpxzc:
466 ifndef NO386
467 xor ecx,ecx
468 xor ebx,ebx
469 else
470 xor bx,bx
471 xor cx,cx
472 xor dx,dx
473 endif
474 lodsb
475 or al,20h
476 cmp al,'a'
477 jb @@notvga
478 sub al,'o'
479 @@vgaloop:
480 dec cx
481 add al,6
482 jnb @@vgaloop ; vga=normal,extended,ask
483 @@vga:
484 xchg ax,cx
485 ;cwd
486 jmp @@end
487 @@endstrtol:
488 mov cl,10
489 cmp al,'k'-'a'+10
490 je @@shift
491 mov cl,20
492 cmp al,'m'-'a'+10
493 je @@shift
494 mov cl,30
495 cmp al,'g'-'a'+10
496 ifndef NO386
497 jne @@noshift
498 @@shift:
499 shl ebx,cl
500 @@noshift:
501 popf
502 jnc @@end2
503 neg ebx
504 @@end2:
505 push ebx
506 pop ax
507 pop dx
508 else
509 @@shift:
510 xchg ax,bx
511 jne @@noshift
512 extrn N_LXLSH@:near
513 call N_LXLSH@
514 @@noshift:
515 popf
516 jne @@end
517 not dx
518 neg ax
519 jne @@end
520 inc dx
521 endif
522 @@end:
523 @@setnum:
524 xchg ax,si
525 mov [di+2],dx
526 @@done:
527 mov [di],si
528 xchg ax,di
529 @@nokeyword:
530 pop di si bx
531 ret
533 @@notvga:
534 mov cl,10 ; radix
535 cmp al,'-'
536 jne @@radixkeep
537 lodsb
538 @@radixkeep:
539 pushf
540 cmp al,'0'
541 jne @@radixok
542 mov cl,8
543 lodsb
544 or al,20h
545 cmp al,'x'
546 jne @@radixok
547 mov cl,16
548 @@strtollp:
549 lodsb
550 @@radixok:
551 or al,20h
552 sub al,'0'
553 jb @@endstrtol
554 cmp al,9
555 jbe @@digitok
556 cmp al,'a'-'0'
557 jb @@endstrtol
558 sub al,'a'-'0'-10
559 @@digitok:
560 cmp al,cl
561 jae @@endstrtol
562 cbw
563 ifndef NO386
564 cwde
565 xchg eax,ebx
566 mul ecx
567 add ebx,eax
568 else
569 push ax
570 xchg ax,dx
571 mul cx
572 xchg ax,bx
573 mul cx
574 add dx,bx
575 pop bx
576 add bx,ax
577 adc dx,0
578 endif
579 jmp @@strtollp
581 endp @argstr$qpxzcxt1ppxzc
583 ;***************************************************************
584 ;_fastcall void puts(bx:const char* s):
585 ;***************************************************************
586 global @puts$qpxzc:near
588 ; global puts:near ; puts(bx)
589 @putsz:
590 call @putc
591 @puts$qpxzc:
592 puts:
593 mov dl,[bx]
594 inc bx
595 or dl,dl
596 jne @putsz
597 mov dl,10
598 @putc:
599 cmp dl,10
600 jne @putcz
601 call @putcz2
602 @putcz2:
603 xor dl,7 ; 10^13 1010^1101
604 @putcz:
605 mov ah,2
606 do_int21h:
607 int 21h
608 ret
611 include "himem.inc"
613 ;***************************************************************
614 ;_fastcall char* malloc_or_die(ax:unsigned size);
615 ;***************************************************************
616 xchg_heap_top:
617 xchg ax,[bx]
618 ret
620 proc @malloc_or_die$qui near
622 malloc_or_die: ; ax = malloc_or_die(ax)
623 extrn _heap_top
624 mov bx,offset _heap_top
625 add ax,[bx]
626 jnc xchg_heap_top
627 mov bx,offset msg_malloc
629 endp @malloc_or_die$qui
632 ;***************************************************************
633 ;_fastcall int die(bx:const char* msg);
634 ;int exit(ax:int status);
635 ;int abort(void);
636 ;***************************************************************
637 global @die$qpxzc:near
638 proc @die$qpxzc near
639 @die$qpxzc:
640 global die:near ; die(bx)
641 die:
642 call puts
643 global @exit$qv:near
644 @exit$qv:
645 _exit:
646 extrn _imgs:image_himem
647 mov cx,[(word _imgs.buf)+2] ; no_exit ?
648 mov ah,4Ch
649 jcxz do_int21h
650 mov bx, offset msg_hang
651 call puts
652 ; global _abort:near
653 _abort:
654 cli
655 hlt
656 jmp _abort
658 endp @die$qpxzc
660 ;***************************************************************
661 ;_fastcall void open_image(si:struct image_himem *m, ax:const char *name);
662 ;***************************************************************
664 global @open_image$qp11image_himempxzc:near
665 proc @open_image$qp11image_himempxzc near
667 mov [(image_himem si).state],ax
668 push ax
669 @@next:
670 call next_chunk
671 ifndef NO386
672 add eax,3
673 and al,0FCh
674 add [(image_himem si).size],eax ; m->size += m->chunk_size
675 or eax,eax
676 else
677 add ax,3
678 adc dx,0
679 and al,0FCh
680 add [word (image_himem si).size],ax ; m->size += m->chunk_size
681 adc [word ((image_himem si).size)+2],dx
682 or ax,dx
683 endif
684 jnz @@next
685 pop [(image_himem si).state]
687 endp @open_image$qp11image_himempxzc
690 ;***************************************************************
691 ;static long next_chunk(struct image_himem *si);
692 ;***************************************************************
693 proc next_chunk near
695 ifndef NO_CLOSE
696 mov ax,[(image_himem si).fd]
697 call close
698 endif
699 ifndef NO386
700 xor eax,eax
701 else
702 xor ax,ax
703 cwd
704 endif
705 mov [(image_himem si).fd],ax
706 mov bx,[(image_himem si).state]
707 cmp al,[bx] ; ""
708 jz @@end
709 dec bx
710 push di
711 @@scan:
712 inc bx
713 mov al,[bx]
714 mov di,bx
715 or al,al
716 jz @@eos
717 sub al,','
718 jnz @@scan
719 inc bx
720 @@eos:
721 xchg [(image_himem si).state],bx ; set start of string
722 mov [current_file],bx
723 xchg [di],ax ; set temp eos (ax == 0)
724 push ax
725 call @open$qpxzc
726 pop [word di] ; restore string
727 pop di
728 jnc @@opened
729 loadfailure:
730 ;***************************************************************
731 ;_fastcall void loadfailure(void);
732 ;***************************************************************
733 global @loadfailure$qv:near
734 @loadfailure$qv:
735 mov bx,0
736 org $-2
737 current_file dw ?
738 call puts
739 mov bx,offset loaderr
740 jmpdie:
741 jmp die
742 @@opened:
743 mov [(image_himem si).fd],ax
744 ifndef NO_CLOSE
745 mov [(image_himem si).fd2close],ax
746 endif
747 ifdef ISO9660
748 ifndef NO386
749 mov eax,[_isostate.filesize]
750 else
751 mov ax,[word _isostate.filesize]
752 mov dx,[(word _isostate.filesize)+2]
753 endif
754 else
755 mov bl,02h ; SEEK_END
756 call lseek0
757 ifndef NO386
758 push eax
759 mov ax,[(image_himem si).fd]
760 call rewind
761 pop eax
762 else
763 push ax
764 push dx
765 mov ax,[(image_himem si).fd]
766 call rewind
767 pop dx
768 pop ax
769 endif
770 endif
771 @@end:
772 ifndef NO386
773 mov [(image_himem si).chunk_size],eax
774 else
775 mov [word (image_himem si).chunk_size],ax
776 mov [word ((image_himem si).chunk_size)+2],dx
777 endif
778 ret
780 endp next_chunk
782 ifdef VCPI
783 ;***************************************************************
785 struc data_himem ;struct data_himem {
786 first dd ? ; 0 u32 first; *must* be the first one
787 cacheidx dw ? ; 4 int cacheidx; quad *
788 pageidx dw ? ; 6 int pageidx; byte *
789 cache dd 1024 dup(?) ; 8 int cache;
790 page dd 1024 dup(?) ;4104 int page;
791 ends data_himem ;};
793 ;***************************************************************
794 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
795 ;***************************************************************
796 global @malloc_bufv_or_die$qp11image_himem:near
797 proc @malloc_bufv_or_die$qp11image_himem near
799 p386
800 push si
801 ;mov ecx,[(image_himem si).size]
802 ;shr ecx,20 ; pages index size = size >> 20
803 ;mov ax,cx
804 ;add ax,size data_himem-4096
805 mov ax,size data_himem
806 call malloc_or_die
807 ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
808 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
809 add ecx,[(image_himem si).size]
810 shr ecx,12
811 mov [curdata],ax
812 mov [(image_himem si).bufv],ax ; update m->bufv
813 xchg ax,si
814 @@vcpi_alloc:
815 mov ax,0DE04h ; allocate a 4K page => EDX
816 int 67h
817 or ah,ah
818 mov bx,offset vcpi_alloc_err
819 jnz jmpdie
820 ; for (i = cnt-1; i >= 0; i--)
821 ; if (edx < pm.fallback+pm.size) again
822 mov bx,offset _imgs.fallback+size image_himem
823 mov eax,[bx-2+6-size image_himem] ; pm.size
824 add eax,[bx-2+2-size image_himem]
825 cmp eax,edx ; pm.fallback+pm.size <= edx ?
826 ja @@vcpi_alloc
827 mov eax,ecx
828 dec eax
829 shl eax,12 ; i*_4k
830 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
831 add eax,[bx-2+2] ; +initrd.fallback
832 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
833 ja @@initrdok
834 mov eax,[bx-2+6] ; initrd.size
835 add eax,[bx-2+2] ; +initrd.fallback
836 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
837 @@ja_vcpi_alloc:
838 ja @@vcpi_alloc
839 @@initrdok:
840 cmp [(data_himem si).first],0
841 jne @@notfirst
842 mov [(data_himem si).first],edx
843 @@notfirst:
844 mov bx,[(data_himem si).cacheidx]
845 cmp bh,4
846 jae @@nextpage
847 shl bx,2
848 inc [(data_himem si).cacheidx]
849 mov [(data_himem bx+si).cache],edx ; cache[cacheidx++] = edx
850 loopd @@vcpi_alloc
851 mov [(data_himem bx+si).cache],ecx ; last is 0
852 @@nextpage:
853 and [(data_himem si).cacheidx],0
854 mov bx,[(data_himem si).pageidx]
855 mov [(data_himem bx+si).page],edx
856 add [(data_himem si).pageidx],4
857 push cx
858 lea cx,[(data_himem si).cache]
859 ifdef NO386
860 push edx
861 pop ax ; to es:ax
862 pop es
863 endif
864 call storepage ; storepage(edx/es:ax,cx)
865 pop cx
866 or ecx,ecx ; clear C
867 jnz @@ja_vcpi_alloc
868 mov [dword (data_himem si).cacheidx],ecx
869 xchg ax,si
870 pop si
871 ret
872 ifdef NO386
873 p8086
874 endif
876 endp @malloc_bufv_or_die$qp11image_himem
877 endif
880 ;***************************************************************
881 ;_fastcall void memcpy_image_initrd(si:struct image_himem *m);
882 ;_fastcall void memcpy_image_kernel(si:struct image_himem *m);
883 ;_fastcall void memcpy_image(bx:struct image_himem *m);
884 ;***************************************************************
885 global @memcpy_image_initrd$qv:near
886 @memcpy_image_initrd$qv:
887 lea bx,[si+size image_himem]
888 db 0A9h ; test ax,imm
889 global @memcpy_image_kernel$qv:near
890 @memcpy_image_kernel$qv:
891 mov bx,si
892 proc @memcpy_image$qp11image_himem near
894 ifndef NO386
895 mov edx,[(image_himem bx).fallback]
896 mov eax,[(image_himem bx).buf]
897 cmp eax,edx ; if (m->fallback != m->buf)
898 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
899 mov ecx,[(image_himem bx).size]
900 else
901 les cx,[((image_himem bx).buf)]
902 mov dx,es
903 les ax,[((image_himem bx).fallback)]
904 cmp ax,cx ; if (m->fallback != m->buf)
905 jnz @@do
906 cmp dx,[word ((image_himem bx).fallback)+2]
907 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
908 @@do:
909 push [((image_himem bx).size)]
910 xor bx,bx
911 call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
912 push dx ; [word ((image_himem bx).buf)+2]
913 push cx ; [word ((image_himem bx).buf)]
914 push bx
915 push es ; push es:ax
916 push ax
917 jmp @@memcpy
918 endif
919 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
920 p386
921 push ecx
922 push eax
923 push 0
924 ifndef NO386
925 call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size)
926 endif
927 push edx
928 ifdef NO386
929 p8086
930 endif
931 @@memcpy:
932 extrn memcpy32:near
933 call near memcpy32
934 @@skip:
935 ret
937 endp @memcpy_image$qp11image_himem
939 ;***************************************************************
940 ;_fastcall void storepage(di:u32 *dst);
941 ;***************************************************************
942 global @storepage$qpul:near
943 proc @storepage$qpul near
945 ifndef NO386
946 mov edx,[di]
947 else
948 les ax,[dword di]
949 endif
950 mov cx,offset _xfer_buf
951 storepage: ; storepage(edx,cx)
952 ifndef NO386
953 push 0
954 push 4096
955 push 0
956 push cx
957 push ds ; call_memcpy32(to=edx,fromseg,fromofs,size)
958 else
959 xor dx,dx
960 push dx ; 0
961 mov bx,4096
962 push bx ; 4096
963 mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
964 endif
965 jmp call_memcpy32
967 endp @storepage$qpul
969 ifdef VCPI
970 p386
971 ;***************************************************************
972 ;_fastcall void reset_bufv(di:u32 *p);
973 ;***************************************************************
974 global @reset_bufv$qpul:near
975 proc @reset_bufv$qpul near
977 mov [curdata],di
978 and [dword (data_himem di).cacheidx],0 ; and pageidx=0
979 ret
981 endp @reset_bufv$qpul
983 ;***************************************************************
984 ;u32* di=prev_bufv();
985 ;u32* di=prev_bufv();
986 ;***************************************************************
987 global _prev_bufv:near
988 global _next_bufv:near
989 proc _prev_bufv near
991 stc
992 db 73h ; jnc
993 _next_bufv:
994 clc
995 push si
996 mov bx,0
997 org $-2
998 curdata dw ?
999 sbb ax,ax
1000 cmc
1001 adc ax,[(data_himem bx).cacheidx] ; -1/+1
1002 mov si,3ffh
1003 and si,ax
1004 mov [(data_himem bx).cacheidx],si
1005 shl si,2
1006 xor ecx,ecx
1007 test ax,0fc00h
1008 jz @@gotpage ; FFFF / 0400
1009 xchg al,ah ; FFFC / 0004
1010 and al,0fch
1011 add [(data_himem bx).pageidx],ax
1012 mov di,[(data_himem bx).pageidx]
1013 lea di,[(data_himem bx+di).page]
1014 mov edx,ds
1015 shl edx,4
1016 lea cx,[(data_himem bx).cache]
1017 add edx,ecx
1018 mov eax,[di]
1019 or eax,eax
1020 jz @@ret
1021 mov cx,4096 ; get page
1022 call memcpy_imagez ; memcpy_imagez(edx,eax,ecx)
1023 @@gotpage:
1024 lea ax,[(data_himem bx+si).cache]
1025 or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
1026 jnz @@notfirst2
1027 xchg ax,bx ; &first
1028 @@notfirst2:
1029 xchg ax,di
1030 @@ret:
1031 pop si
1032 ret
1034 endp _prev_bufv
1035 endif
1037 ifdef NO386
1038 p8086
1039 endif
1041 ;***************************************************************
1042 ;_fastcall int read_image(si:struct image_himem *m);
1043 ;***************************************************************
1044 global @read_image$qp11image_himem:near
1045 proc @read_image$qp11image_himem near
1047 push di
1048 xor di,di
1049 @@loop:
1050 ifndef NO386
1051 xor ecx,ecx
1052 mov ch,4096/256
1053 sub cx,di
1054 mov eax,[(image_himem si).chunk_size]
1055 cmp ecx,eax
1056 jb @@szok
1057 else
1058 mov cx,4096
1059 sub cx,di
1060 mov ax,[word (image_himem si).chunk_size]
1061 cmp cx,ax
1062 jb @@szok
1063 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
1064 jne @@szok
1065 endif
1066 xchg ax,cx
1067 @@szok:
1068 jcxz image_done
1069 lea dx,[di+_xfer_buf]
1070 mov bx,[(image_himem si).fd]
1071 call @read$cxdxbx
1072 jb image_done
1073 add di,ax
1074 ifndef NO386
1075 cwde ; ax < 8000h
1076 cdq
1077 sub [(image_himem si).chunk_size],eax
1078 else
1079 cwd ; ax < 8000h
1080 sub [word (image_himem si).chunk_size],ax
1081 sbb [word ((image_himem si).chunk_size)+2],dx
1082 endif
1083 @@fill:
1084 test al,3
1085 je @@filled
1086 mov [di+_xfer_buf],dl
1087 inc di
1088 inc ax
1089 jmp @@fill
1090 @@filled:
1091 ifndef NO386
1092 sub [(image_himem si).remaining],eax
1093 or edx,[word (image_himem si).chunk_size]
1094 else
1095 sub [word (image_himem si).remaining],ax
1096 sbb [word ((image_himem si).remaining)+2],dx
1097 mov ax,[word (image_himem si).chunk_size]
1098 or ax,[word ((image_himem si).chunk_size)+2]
1099 endif
1100 jnz @@same_chunk
1101 call next_chunk
1102 @@same_chunk:
1103 jmp @@loop
1104 image_done:
1105 xchg ax,di
1106 pop di
1107 ret
1109 endp @read_image$qp11image_himem
1112 ends _TEXT
1114 end
1116 ;###### END OF FILE ############################################