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

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