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