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

syslinux: fix build
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 28 16:32:57 2021 +0000 (2021-02-28)
parents 14ca5e18cfd9
children 42b4b9d947f3
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
361 xor dl,[bx] ; dl -= *a++
362 ifdef BASIC_ISO9660
363 and dl,0dfh ; upcase
364 endif
365 jne fail ; return -1
366 inc bx
367 jmp @@loop
369 endp @strhead$qpxzct1
372 ;***************************************************************
373 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
374 ;***************************************************************
375 global @strcmp$qpxzct1:near
376 proc @strcmp$qpxzct1 near
378 call @strhead$qpxzct1
379 jne fail ; return -1
380 xor dl,[bx] ; clear C
381 jne fail ; return -1
382 jmp failifc ; return 0
384 endp @strcmp$qpxzct1
386 else
388 ;***************************************************************
389 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
390 ;***************************************************************
391 global @strcmp$qpxzct1:near
392 proc @strcmp$qpxzct1 near
394 @@loop:
395 xchg ax,bx
396 mov dl,[bx] ; dl = *b++
397 inc bx
398 xchg ax,bx
399 xor dl,[bx] ; dl ^= *a++
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 @@end:
751 mov [(image_himem si).chunk_size],eax
752 else
753 mov ax,[word _isostate.filesize]
754 mov dx,[(word _isostate.filesize)+2]
755 @@end:
756 mov [word (image_himem si).chunk_size],ax
757 mov [word ((image_himem si).chunk_size)+2],dx
758 endif
759 else
760 mov bl,02h ; SEEK_END
761 call lseek0
762 ifndef NO386
763 push eax
764 mov ax,[(image_himem si).fd]
765 call rewind
766 pop eax
767 @@end:
768 mov [(image_himem si).chunk_size],eax
769 else
770 push ax
771 push dx
772 mov ax,[(image_himem si).fd]
773 call rewind
774 pop dx
775 pop ax
776 @@end:
777 mov [word (image_himem si).chunk_size],ax
778 mov [word ((image_himem si).chunk_size)+2],dx
779 endif
780 endif
781 ret
783 endp next_chunk
785 ifdef VCPI
786 ;***************************************************************
788 struc data_himem ;struct data_himem {
789 first dd ? ; 0 u32 first; *must* be the first one
790 cacheidx dw ? ; 4 int cacheidx; quad *
791 pageidx dw ? ; 6 int pageidx; byte *
792 cache dd 1024 dup(?) ; 8 int cache;
793 page dd 1024 dup(?) ;4104 int page;
794 ends data_himem ;};
796 ;***************************************************************
797 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
798 ;***************************************************************
799 global @malloc_bufv_or_die$qp11image_himem:near
800 proc @malloc_bufv_or_die$qp11image_himem near
802 p386
803 push si
804 ;mov ecx,[(image_himem si).size]
805 ;shr ecx,20 ; pages index size = size >> 20
806 ;mov ax,cx
807 ;add ax,size data_himem-4096
808 mov ax,size data_himem
809 call malloc_or_die
810 ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
811 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
812 add ecx,[(image_himem si).size]
813 shr ecx,12
814 mov [curdata],ax
815 mov [(image_himem si).bufv],ax ; update m->bufv
816 xchg ax,si
817 @@vcpi_alloc:
818 mov ax,0DE04h ; allocate a 4K page => EDX
819 int 67h
820 or ah,ah
821 mov bx,offset vcpi_alloc_err
822 jnz jmpdie
823 ; for (i = cnt-1; i >= 0; i--)
824 ; if (edx < pm.fallback+pm.size) again
825 mov bx,offset _imgs.fallback+size image_himem
826 mov eax,[bx-2+6-size image_himem] ; pm.size
827 add eax,[bx-2+2-size image_himem]
828 cmp eax,edx ; pm.fallback+pm.size <= edx ?
829 ja @@vcpi_alloc
830 mov eax,ecx
831 dec eax
832 shl eax,12 ; i*_4k
833 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
834 add eax,[bx-2+2] ; +initrd.fallback
835 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
836 ja @@initrdok
837 mov eax,[bx-2+6] ; initrd.size
838 add eax,[bx-2+2] ; +initrd.fallback
839 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
840 @@ja_vcpi_alloc:
841 ja @@vcpi_alloc
842 @@initrdok:
843 cmp [(data_himem si).first],0
844 jne @@notfirst
845 mov [(data_himem si).first],edx
846 @@notfirst:
847 mov bx,[(data_himem si).cacheidx]
848 cmp bh,4
849 jae @@nextpage
850 shl bx,2
851 inc [(data_himem si).cacheidx]
852 mov [(data_himem bx+si).cache],edx ; cache[cacheidx++] = edx
853 loopd @@vcpi_alloc
854 mov [(data_himem bx+si).cache],ecx ; last is 0
855 @@nextpage:
856 and [(data_himem si).cacheidx],0
857 mov bx,[(data_himem si).pageidx]
858 mov [(data_himem bx+si).page],edx
859 add [(data_himem si).pageidx],4
860 push cx
861 lea cx,[(data_himem si).cache]
862 ifdef NO386
863 push edx
864 pop ax ; to es:ax
865 pop es
866 endif
867 call storepage ; storepage(edx/es:ax,cx)
868 pop cx
869 or ecx,ecx ; clear C
870 jnz @@ja_vcpi_alloc
871 mov [dword (data_himem si).cacheidx],ecx
872 xchg ax,si
873 pop si
874 ret
875 ifdef NO386
876 p8086
877 endif
879 endp @malloc_bufv_or_die$qp11image_himem
880 endif
883 ;***************************************************************
884 ;_fastcall void memcpy_image_initrd(si:struct image_himem *m);
885 ;_fastcall void memcpy_image_kernel(si:struct image_himem *m);
886 ;_fastcall void memcpy_image(bx:struct image_himem *m);
887 ;***************************************************************
888 global @memcpy_image_initrd$qv:near
889 @memcpy_image_initrd$qv:
890 lea bx,[si+size image_himem]
891 db 0A9h ; test ax,imm
892 global @memcpy_image_kernel$qv:near
893 @memcpy_image_kernel$qv:
894 mov bx,si
895 proc @memcpy_image$qp11image_himem near
897 ifndef NO386
898 mov edx,[(image_himem bx).fallback]
899 mov eax,[(image_himem bx).buf]
900 cmp eax,edx ; if (m->fallback != m->buf)
901 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
902 mov ecx,[(image_himem bx).size]
903 else
904 les cx,[((image_himem bx).buf)]
905 mov dx,es
906 les ax,[((image_himem bx).fallback)]
907 cmp ax,cx ; if (m->fallback != m->buf)
908 jnz @@do
909 cmp dx,[word ((image_himem bx).fallback)+2]
910 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
911 @@do:
912 push [((image_himem bx).size)]
913 xor bx,bx
914 call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
915 push dx ; [word ((image_himem bx).buf)+2]
916 push cx ; [word ((image_himem bx).buf)]
917 push bx
918 push es ; push es:ax
919 push ax
920 jmp @@memcpy
921 endif
922 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
923 p386
924 push ecx
925 push eax
926 push 0
927 ifndef NO386
928 call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size)
929 endif
930 push edx
931 ifdef NO386
932 p8086
933 endif
934 @@memcpy:
935 extrn memcpy32:near
936 call near memcpy32
937 @@skip:
938 ret
940 endp @memcpy_image$qp11image_himem
942 ;***************************************************************
943 ;_fastcall void storepage(di:u32 *dst);
944 ;***************************************************************
945 global @storepage$qpul:near
946 proc @storepage$qpul near
948 ifndef NO386
949 mov edx,[di]
950 else
951 les ax,[dword di]
952 endif
953 mov cx,offset _xfer_buf
954 storepage: ; storepage(edx,cx)
955 ifndef NO386
956 push 0
957 push 4096
958 push 0
959 push cx
960 push ds ; call_memcpy32(to=edx,fromseg,fromofs,size)
961 else
962 xor dx,dx
963 push dx ; 0
964 mov bx,4096
965 push bx ; 4096
966 mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
967 endif
968 jmp call_memcpy32
970 endp @storepage$qpul
972 ifdef VCPI
973 p386
974 ;***************************************************************
975 ;_fastcall void reset_bufv(di:u32 *p);
976 ;***************************************************************
977 global @reset_bufv$qpul:near
978 proc @reset_bufv$qpul near
980 mov [curdata],di
981 and [dword (data_himem di).cacheidx],0 ; and pageidx=0
982 ret
984 endp @reset_bufv$qpul
986 ;***************************************************************
987 ;u32* di=prev_bufv();
988 ;u32* di=prev_bufv();
989 ;***************************************************************
990 global _prev_bufv:near
991 global _next_bufv:near
992 proc _prev_bufv near
994 stc
995 db 73h ; jnc
996 _next_bufv:
997 clc
998 push si
999 mov bx,0
1000 org $-2
1001 curdata dw ?
1002 sbb ax,ax
1003 cmc
1004 adc ax,[(data_himem bx).cacheidx] ; -1/+1
1005 mov si,3ffh
1006 and si,ax
1007 mov [(data_himem bx).cacheidx],si
1008 shl si,2
1009 xor ecx,ecx
1010 test ax,0fc00h
1011 jz @@gotpage ; FFFF / 0400
1012 xchg al,ah ; FFFC / 0004
1013 and al,0fch
1014 add [(data_himem bx).pageidx],ax
1015 mov di,[(data_himem bx).pageidx]
1016 lea di,[(data_himem bx+di).page]
1017 mov edx,ds
1018 shl edx,4
1019 lea cx,[(data_himem bx).cache]
1020 add edx,ecx
1021 mov eax,[di]
1022 or eax,eax
1023 jz @@ret
1024 mov cx,4096 ; get page
1025 call memcpy_imagez ; memcpy_imagez(edx,eax,ecx)
1026 @@gotpage:
1027 lea ax,[(data_himem bx+si).cache]
1028 or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
1029 jnz @@notfirst2
1030 xchg ax,bx ; &first
1031 @@notfirst2:
1032 xchg ax,di
1033 @@ret:
1034 pop si
1035 ret
1037 endp _prev_bufv
1038 endif
1040 ifdef NO386
1041 p8086
1042 endif
1044 ;***************************************************************
1045 ;_fastcall int read_image(si:struct image_himem *m);
1046 ;***************************************************************
1047 global @read_image$qp11image_himem:near
1048 proc @read_image$qp11image_himem near
1050 push di
1051 mov di,4096
1052 push di ; original size
1053 @@loop:
1054 ifndef NO386
1055 movzx ecx,di
1056 mov eax,[(image_himem si).chunk_size]
1057 cmp ecx,eax
1058 jb @@szok
1059 else
1060 mov cx,di
1061 mov ax,[word (image_himem si).chunk_size]
1062 cmp cx,ax
1063 jb @@szok
1064 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
1065 jne @@szok
1066 endif
1067 xchg ax,cx
1068 @@szok:
1069 jcxz image_done
1070 mov dx,offset _xfer_buf+4096
1071 sub dx,di
1072 mov bx,[si]
1073 call @read$cxdxbx
1074 jb image_done
1075 xor cx,cx
1076 cwd ; ax < 8000h
1077 ifndef NO386
1078 cwde ; ax < 8000h
1079 sub [(image_himem si).chunk_size],eax
1080 xchg eax,ebx
1081 else
1082 sub [word (image_himem si).chunk_size],ax
1083 xchg ax,bx
1084 sbb [word ((image_himem si).chunk_size)+2],dx
1085 jnz @@fill
1086 cmp [word (image_himem si).chunk_size],dx
1087 endif
1088 jnz @@fill
1089 dec cx
1090 @@fill:
1091 test bl,3
1092 je @@filled
1093 mov [bx+_xfer_buf],dh
1094 inc bx
1095 jmp @@fill
1096 @@filled:
1097 ifndef NO386
1098 sub [(image_himem si).remaining],ebx
1099 else
1100 sub [word (image_himem si).remaining],bx
1101 sbb [word ((image_himem si).remaining)+2],dx
1102 endif
1103 sub di,bx
1104 pushf
1105 jcxz @@same_chunk
1106 call next_chunk
1107 @@same_chunk:
1108 popf
1109 jnz @@loop
1110 image_done:
1111 pop ax ; original size
1112 sub ax,di
1113 pop di
1114 ret
1116 endp @read_image$qp11image_himem
1119 ends _TEXT
1121 end
1123 ;###### END OF FILE ############################################