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

linld: hide -b=<base_himem> argument
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 12 17:26:44 2020 +0000 (2020-12-12)
parents 3d19917d3a03
children a946c1651082
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 msg_hang db "Himem broken",0
21 vcpi_alloc_err db "VCPI"
22 global overflow:byte
23 overflow db "/"
24 msg_malloc db "Out of memory",0
26 ends _DATA
28 segment _BSS byte public use16 'BSS'
30 ifdef EXTRA
31 include "isostate.inc"
32 public _isostate
33 _isostate isostate <?>
34 org $-7
35 endif
36 _xfer_buf db 4096 dup (?)
37 filecnt db ? ; in fact 0 minus file count...
38 nextfilename dw ?
39 ifdef EXTRA
40 utoabuf db 6 dup (?)
41 endif
43 ends _BSS
45 segment _TEXT byte public use16 'CODE'
47 ;***************************************************************
48 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
49 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
50 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
51 ;***************************************************************
52 ifdef EXTRA
53 global @strcat$qpxzct1:near
54 @strcat$qpxzct1:
55 mov cx,1h
56 db 0bah ; mov dx,imm opcode
57 endif
58 global @strcatb$qpxzct1:near
59 proc @strcatb$qpxzct1 near
61 ifdef EXTRA
62 mov cl,7Fh
63 db 0bah ; mov dx,imm opcode
64 global @strcpy$qpxzct1:near
65 @strcpy$qpxzct1:
66 xor cx,cx
67 endif
68 push si
69 xchg ax,si ; b
70 ifdef EXTRA
71 jcxz @@nocat
72 endif
73 dec bx
74 @@catlp:
75 inc bx
76 cmp [byte bx],0 ; a=bx
77 jne @@catlp
78 ifdef EXTRA
79 mov al,20h
80 loop @@cpyhead
81 else
82 db 0b8h,20h ; mov ax,??20h
83 endif
84 @@nocat:
85 @@cpylp:
86 lodsb
87 @@cpyhead:
88 mov [bx],al
89 inc bx
90 or al,al
91 jne @@cpylp
92 ifdef EXTRA
93 strfound:
94 xchg ax,dx
95 endif
96 strend:
97 pop si
98 global @ret:near
99 @ret:
100 ret
102 endp @strcatb$qpxzct1
105 ifdef EXTRA
106 p8086
107 ;***************************************************************
108 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
109 ;***************************************************************
110 global @strstr$qpxzct1:near
111 proc @strstr$qpxzct1 near
113 xchg ax,cx ; b
114 mov dx,bx ; a
115 push si
116 @@loop:
117 xor ax,ax
118 mov si,dx
119 cmp [si],al ; *a
120 jz strend ; return ax = NULL
121 mov bx,cx
122 @@match:
123 or ah,[bx] ; *b
124 jz strfound
125 inc bx
126 lodsb
127 sub ah,al
128 jz @@match
129 inc dx
130 jmp @@loop
132 endp @strstr$qpxzct1
135 ;***************************************************************
136 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
137 ;***************************************************************
138 global @strcmp$qpxzct1:near
139 proc @strcmp$qpxzct1 near
141 ifdef USE_ARGSTR
142 @@loop:
143 xchg ax,bx
144 mov cl,[bx] ; cl = *b++
145 inc bx
146 xchg ax,bx
147 cmp cl,[bx] ; cl ?= *a++
148 jnz fail ; return -1
149 inc bx
150 or cl,cl ; clear C
151 jz failifc ; return 0
152 jmp @@loop
154 else
156 call @strhead$qpxzct1
157 jne closeret ; return -1
158 cmp cl,[bx]
159 jmp failifc ; return 0 or -1
161 endif
163 endp @strcmp$qpxzct1
164 endif
167 ;***************************************************************
168 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
169 ;_fastcall int openargs(bx:const char* name, int flags=O_RDONLY);
170 ;***************************************************************
171 global openargs:near ; openargs(bx)
172 openargs:
173 cmp [byte bx],'@'
174 jne fail
175 inc bx
177 global @open$qpxzc:near
178 proc @open$qpxzc near
180 open: ; open(bx)
181 ifdef ISOHOOK
182 extrn iso_open_hack:word
183 jmp [iso_open_hack]
184 global __open:near
185 __open:
186 endif
187 ifdef LONG_FILENAME
188 mov ax,716Ch
189 push bx si
190 mov si,bx
191 xor bx,bx ; R/O
192 xor cx,cx ; attributes
193 cwd ; action = open
194 stc
195 int 21h
196 pop si dx
197 jnc doret
198 else
199 mov dx,bx
200 endif
201 mov ax,3d00h ; read-only+compatibility
202 ;mov cl,0 ; attribute mask
203 jmp dos
205 endp @open$qpxzc
208 ;***************************************************************
209 ;_fastcall int fileexist(bx:const char* name);
210 ;***************************************************************
211 global @fileexist$qpxzc:near
212 @fileexist$qpxzc:
213 call @open$qpxzc
214 jc fail
216 ;***************************************************************
217 ;_fastcall int close(ax:int fd);
218 ;***************************************************************
219 global @close$qi:near
220 proc @close$qi near
222 global close:near ; close(ax)
223 close:
224 mov bh,3Eh
225 ifdef ISOHOOK
226 extrn iso_close_hack:word
227 jmp [iso_close_hack]
228 endif
229 global dosbx:near
230 dosbx:
231 xchg ax,bx
232 or bx,bx
233 jnz dos
234 closeret:
235 ret
237 endp @close$qi
240 ;***************************************************************
241 ;_fastcall int readrm(di:struct himem *m, ax:int sz);
242 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
243 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
244 ;***************************************************************
245 global @readrm$qp11image_himemi:near
246 @readrm$qp11image_himemi:
247 xchg ax,dx ; sz
248 mov ax,[di] ; fd
249 mov bx,[di-2] ; data
250 global @read$qipvi:near
251 proc @read$qipvi near
253 ifdef WRITE
254 stc
255 db 0B0h ; mov al,im
256 global @write$qipvi:near
257 @write$qipvi:
258 clc
259 endif
260 @read$dxbxax:
261 xchg ax,bx ; fd
262 xchg ax,dx ; data
263 xchg ax,cx ; sz
264 ifdef WRITE
265 mov ah,40h
266 sbb ah,0
267 else
268 global @read$cxdxbx:near
269 @read$cxdxbx:
270 mov ah,3Fh
271 endif
272 jcxz fail
273 ifdef ISOHOOK
274 ;_fastcall int read(bx:int fd, dx:void* data, cx:int sz, ah=3Fh);
275 extrn iso_read_hack:word
276 jmp [iso_read_hack] ; or ret
277 endif
278 global dos:near
279 dos:
280 int 21h
281 jnc doret
282 fail:
283 stc
284 failifc:
285 sbb ax,ax ; ax=-1 CF
286 cwd
287 doret:
288 ifndef NO386
289 push dx ; see next_chunk:lseek
290 push ax
291 pop eax
292 endif
293 ret
295 endp @read$qipvi
297 ;***************************************************************
298 ;_fastcall long rewind(ax:int fd);
299 ;***************************************************************
301 global @rewind$qi:near ; fd=ax
302 proc @rewind$qi near
304 ifdef EXTRA ; catch ISO image case
305 stc
306 mov dx,-512 ; curpos = 512, see LOAD.CPP
307 mov bl,1
308 jmp lseekword
309 endif
310 rewind: ; rewind(ax)
311 mov bl,0
312 lseek0: ; lseek0(ax,bl=dir)
313 xor dx,dx ; clear C
314 lseekword:
315 sbb cx,cx
316 lseekset:
317 mov bh,42h ; bx=fd cx:dx=offset al=whence
318 ifdef ISOHOOK
319 ;_fastcall long lseek(ax:int fd, cxdx:unsigned long offset, bl:whence, bh=42h);
320 extrn iso_lseek_hack:word
321 jmp [iso_lseek_hack]
322 else
323 jmp dosbx
324 endif
326 endp @rewind$qi
328 ifdef EXTRA
329 ;***************************************************************
330 ;_fastcall void isolseek(bx:const unsigned long *offset);
331 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* offset);
332 ;***************************************************************
333 global @isolseek$qpxul:near
334 proc @isolseek$qpxul near
336 isolseek:
337 mov ax,[_isostate.fd]
338 global @lseekset2$qipul:near
339 @lseekset2$qipul:
340 les dx,[dword bx]
341 mov cx,es
342 mov bl,0
343 jmp lseekset
345 endp @isolseek$qpxul
347 ;***************************************************************
348 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
349 ;***************************************************************
350 global @isoreadsector$qpxul:near
351 proc @isoreadsector$qpxul near
353 call isolseek
354 jc fail
355 mov dx,2560
356 mov bx,offset _isostate.buffer
357 mov ax,[_isostate.fd]
358 jmp @read$dxbxax ; read(fd,buffer,2560)
360 endp @isoreadsector$qpxul
363 ;***************************************************************
364 ;_fastcall int isoreset(bx:const char *name);
365 ;***************************************************************
366 global @isoreset$qpzc:near
367 proc @isoreset$qpzc near
369 or bx,bx
370 jz fail
371 call near ptr @open$qpxzc
372 mov [_isostate.fd],ax
373 extrn @isoroot$qv:near
374 jmp @isoroot$qv
376 endp @isoreset$qpzc
379 ;***************************************************************
380 ;_fastcall int isoopen(bx:const char *name);
381 ;***************************************************************
382 global @isoopen$qpxzc:near
383 proc @isoopen$qpxzc near
385 extrn @_isoopen$qv:near
386 mov [_isostate.filename2open],bx
387 jmp @_isoopen$qv
389 endp @isoopen$qpxzc
391 endif
394 ifdef USE_ARGSTR
395 ;***************************************************************
396 ;_fastcall const char ** argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
397 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
398 ;***************************************************************
399 global @argstr$qpxzcxt1ppxzc:near
400 proc @argstr$qpxzcxt1ppxzc near
402 mov cl,2
403 db 0a9h ; test ax,#
404 global @argnum$qpzcxpxzcpul:near
405 @argnum$qpzcxpxzcpul:
406 mov cl,4
407 push bx
408 xchg ax,bx ; keywords -> bx
409 xchg ax,cx ; s -> cx
410 cbw ; argstr:0002 argnum:0004
411 xchg ax,dx ; vars -> ax
412 push si di
413 xchg ax,di ; vars => di
414 dec bx
415 @@testalt:
416 sub di,dx
417 @@loop:
418 mov si,cx ; s
419 add di,dx
420 @@match:
421 inc bx ; keywords++
422 lodsb ; *s++
423 or al,20h
424 cmp al,[bx]
425 je @@match
426 cmp al,'/' ; 2f
427 jne @@notopt
428 cmp [byte bx],'-'
429 je @@match
430 @@notopt:
431 ifdef EXTRA
432 cmp [byte bx],'/'
433 jne @@notalt
434 or al,al ; 1st loop ?
435 js @@testalt
436 @@notalt:
437 endif
438 cmp [byte bx],'|'
439 je @@test
440 cmp [byte bx],dh
441 je @@test
442 mov al,-1
443 inc bx
444 jmp @@notopt
445 @@test:
446 or al,al ; 1st loop ?
447 jns @@testal
448 cmp [byte bx],dh
449 jne @@loop
450 @@testal:
451 cmp al,'='
452 ;je @@found
453 ;cmp al,0 ; eos, si=next argv
454 mov ax,-1
455 jne @@nokeyword
456 @@found:
457 dec dx
458 dec dx
459 je @@done
460 ;mov bx,si
461 call @strtol$qpxzc
462 xchg ax,si
463 mov [di+2],dx
464 @@done:
465 mov [di],si
466 xchg ax,di
467 @@nokeyword:
468 pop di si bx
469 ret
471 endp @argstr$qpxzcxt1ppxzc
473 else
475 ;***************************************************************
476 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
477 ;***************************************************************
478 global @strhead$qpxzct1:near
479 proc @strhead$qpxzct1 near
481 @@loop:
482 xchg ax,bx
483 mov cl,[bx] ; cl = *b++
484 inc bx
485 xchg ax,bx
486 or cl,cl ; clear C
487 jz failifc ; return 0
488 xor cl,[bx] ; cl -= *a++
489 inc bx
490 and cl,0dfh ; case insensitive
491 jne fail ; return -1
492 jmp @@loop
494 endp @strhead$qpxzct1
496 endif
498 include "himem.inc"
500 ;***************************************************************
501 ;_fastcall char* malloc_or_die(ax:unsigned size);
502 ;***************************************************************
503 xchg_heap_top:
504 xchg ax,[bx]
505 ret
507 global @malloc_or_die$qui:near
508 proc @malloc_or_die$qui near
510 global malloc_or_die:near ; ax = malloc_or_die(ax)
511 malloc_or_die:
512 extrn _heap_top
513 mov bx,offset _heap_top
514 add ax,[bx]
515 jnc xchg_heap_top
516 mov bx,offset msg_malloc
518 endp @malloc_or_die$qui
521 ;***************************************************************
522 ;_fastcall int die(bx:const char* msg);
523 ;int exit(ax:int status);
524 ;int abort(void);
525 ;***************************************************************
526 global @die$qpxzc:near
527 proc @die$qpxzc near
528 @die$qpxzc:
529 global die:near ; die(bx)
530 die:
531 call puts
532 global @exit$qv:near
533 @exit$qv:
534 _exit:
535 extrn _imgs:image_himem
536 mov cx,[(word _imgs.buf)+2] ; no_exit ?
537 mov ah,4Ch
538 jcxz do_int21h
539 mov bx, offset msg_hang
540 call puts
541 ; global _abort:near
542 _abort:
543 cli
544 hlt
545 jmp _abort
547 endp @die$qpxzc
549 ;***************************************************************
550 ;_fastcall void puts(bx:const char* s):
551 ;***************************************************************
552 global @puts$qpxzc:near
554 ; global puts:near ; puts(bx)
555 @putsz:
556 call @putc
557 @puts$qpxzc:
558 puts:
559 mov dl,[bx]
560 inc bx
561 or dl,dl
562 jne @putsz
563 mov dl,10
564 @putc:
565 cmp dl,10
566 jne @putcz
567 call @putcz2
568 @putcz2:
569 xor dl,7 ; 10^13 1010^1101
570 @putcz:
571 mov ah,2
572 do_int21h:
573 int 21h
574 ret
577 ;***************************************************************
578 ;static long next_chunk(struct image_himem *di);
579 ;***************************************************************
580 proc next_chunk near
582 push si
583 mov ax,[(image_himem di).fd]
584 call close
585 ifndef NO386
586 xor eax,eax
587 else
588 xor ax,ax
589 cwd
590 endif
591 mov [(image_himem di).fd],ax
592 mov bx,[(image_himem di).state]
593 cmp al,[bx] ; ""
594 jz @@end
595 mov si,bx
596 @@scan:
597 lodsb
598 mov cx,si
599 cmp al,','
600 jz @@eos
601 or al,al
602 jnz @@scan
603 dec cx ; blocked to eos
604 @@eos:
605 mov [(image_himem di).state],cx
606 dec si
607 push [word si]
608 mov [byte si],ah ; set temp eos
609 call open
610 pop [word si] ; restore string
611 jc jcdie
612 mov [(image_himem di).fd],ax
613 mov [(image_himem di).fd2close],ax
614 mov bl,02h ; SEEK_END
615 call lseek0
616 jcdie:
617 mov bx,[(image_himem di).errmsg]
618 jc die
619 ifndef NO386
620 push eax
621 mov ax,[(image_himem di).fd]
622 call rewind
623 pop eax
624 @@end:
625 mov [(image_himem di).chunk_size],eax
626 else
627 push ax
628 push dx
629 mov ax,[(image_himem di).fd]
630 call rewind
631 pop dx
632 pop ax
633 @@end:
634 mov [word (image_himem di).chunk_size],ax
635 mov [word ((image_himem di).chunk_size)+2],dx
636 endif
637 pop si
638 ret
640 endp next_chunk
643 ifdef LARGE_IMAGES
644 struc data_himem ;struct data_himem {
645 first dd ? ; 0 u32 first;
646 cacheidx dw ? ; 4 int cacheidx;
647 pageidx dw ? ; 6 int pageidx;
648 cache dd 1024 dup(?) ; 8 int cache;
649 page dd 1024 dup(?) ;4104 int page;
650 ends data_himem ;}; // size=8200
651 endif
653 ;***************************************************************
654 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
655 ;***************************************************************
656 global @malloc_bufv_or_die$qp11image_himem:near
657 proc @malloc_bufv_or_die$qp11image_himem near
659 p386
660 push si
661 mov bx,si
662 ifdef LARGE_IMAGES
663 movzx eax,[word ((image_himem si).size) + 2]
664 shr ax,4 ; pages index size = size >> 20
665 add ax,8+4096+8
666 call malloc_or_die
667 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
668 add ecx,[(image_himem si).size]
669 shr ecx,12
670 mov [curdata],ax
671 else
672 mov eax,[(image_himem si).size]
673 dec eax
674 shr eax,12
675 inc ax ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
676 push ax
677 inc ax ; cnt+1
678 shl ax,2 ; bufv => vcpi => vm86
679 ; our malloc zeroes allocated mem: bufv[cnt]=0;
680 ; Allocate pages, storing addrs in addrbuf
681 call malloc_or_die
682 pop cx
683 push ax
684 endif
685 mov [(image_himem si).bufv],ax
686 xchg ax,si
687 @@vcpi_alloc:
688 mov ax,0DE04h
689 int 67h
690 or ah,ah
691 stc
692 mov bx,offset vcpi_alloc_err
693 jnz jcdie
694 ; for (i = cnt-1; i >= 0; i--)
695 ifdef LARGE_IMAGES
696 mov eax,ecx
697 dec eax
698 else
699 mov ax,cx
700 dec ax
701 cwde
702 endif
703 shl eax,12 ; i*_4k
704 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
705 mov bx,offset _imgs.fallback
706 push eax
707 add eax,[bx-2+2]
708 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
709 pop eax ; i*_4k
710 jbe @@pmok
711 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
712 jae @@vcpi_alloc
713 @@pmok:
714 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
715 mov bx,offset _imgs.fallback+32
716 add eax,[bx-2+2] ; +initrd.fallback
717 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
718 ja @@initrdok
719 mov eax,[bx-2+6] ; initrd.size
720 add eax,[bx-2+2] ; +initrd.fallback
721 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
722 @@jnc_vcpi_alloc:
723 ja @@vcpi_alloc
724 @@initrdok:
725 ifdef LARGE_IMAGES
726 cmp [(data_himem si).first],0
727 jne @@notfirst
728 mov [(data_himem si).first],edx
729 @@notfirst:
730 mov bx,[(data_himem si).cacheidx]
731 cmp bh,4
732 jae @@nextpage
733 shl bx,2
734 inc [(data_himem si).cacheidx]
735 mov [(data_himem bx+si).cache],edx
736 loopd @@vcpi_alloc
737 mov [(data_himem bx+si).cache],ecx ; last is 0
738 @@nextpage:
739 and [(data_himem si).cacheidx],0
740 mov bx,[(data_himem si).pageidx]
741 mov [(data_himem bx+si).page],edx
742 add [(data_himem si).pageidx],4
743 push cx
744 lea cx,[(data_himem si).cache]
745 ifdef NO386
746 push edx
747 pop dx
748 pop ax
749 endif
750 call storepage ; storepage(edx,cx)
751 pop cx
752 or ecx,ecx ; clear C
753 jnz @@jnc_vcpi_alloc
754 mov [dword (data_himem si).cacheidx],ecx
755 xchg ax,si
756 else
757 mov [si],edx
758 lodsd ; si=+4
759 loop @@vcpi_alloc
760 pop ax
761 endif
762 pop si
763 ret
764 ifdef NO386
765 p8086
766 endif
768 endp @malloc_bufv_or_die$qp11image_himem
771 ;***************************************************************
772 ;_fastcall void memcpy_image(bx:struct image_himem *m);
773 ;***************************************************************
774 global memcpy_image_initrd:near
775 memcpy_image_initrd:
776 lea bx,[si+32]
777 db 0A9h ; test ax,imm
778 global memcpy_image_kernel:near
779 memcpy_image_kernel:
780 mov bx,si
781 global @memcpy_image$qp11image_himem:near
782 proc @memcpy_image$qp11image_himem near
784 ifndef NO386
785 mov edx,[(image_himem bx).fallback]
786 mov eax,[(image_himem bx).buf]
787 cmp eax,edx ; if (m->fallback != m->buf)
788 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
789 ifdef LARGE_IMAGES
790 mov ecx,[(image_himem bx).size]
791 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
792 push ecx
793 else
794 push [(image_himem bx).size]
795 endif
796 push eax
797 push 0
798 call_memcpy32:
799 push edx
800 else
801 les ax,[dword ((image_himem bx).fallback)]
802 mov dx,es
803 mov cx,[word ((image_himem bx).buf)]
804 cmp ax,cx ; if (m->fallback != m->buf)
805 jnz @@do
806 cmp dx,[word ((image_himem bx).buf)+2]
807 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
808 @@do:
809 push [word ((image_himem bx).size)+2]
810 push [word ((image_himem bx).size)]
811 push [word ((image_himem bx).buf)+2]
812 push cx
813 xor cx,cx
814 push cx
815 call_memcpy32:
816 push dx
817 push ax
818 ifdef LARGE_IMAGES
819 jmp @@memcpy
820 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
821 p386
822 push ecx
823 push eax
824 push 0
825 push edx
826 ifdef NO386
827 p8086
828 endif
829 endif
830 endif
831 @@memcpy:
832 extrn memcpy32:near
833 call near memcpy32
834 @@skip:
835 ret
837 endp @memcpy_image$qp11image_himem
839 ;***************************************************************
840 ;_fastcall void storepage(di:u32 *dst);
841 ;***************************************************************
842 global @storepage$qpul:near
843 proc @storepage$qpul near
845 ifndef NO386
846 mov edx,[di]
847 else
848 les ax,[dword di]
849 mov dx,es
850 endif
851 mov cx,offset _xfer_buf
852 storepage: ; storepage(edx,cx)
853 ifndef NO386
854 push 0
855 push 4096
856 push 0
857 else
858 xor bx,bx
859 push bx
860 mov bh,4096/256
861 push bx
862 xor bx,bx
863 push bx
864 endif
865 push cx
866 push ds
867 jmp call_memcpy32
869 endp @storepage$qpul
872 ifdef LARGE_IMAGES
873 p386
874 ;***************************************************************
875 ;_fastcall void reset_bufv(di:u32 *p);
876 ;***************************************************************
877 global @reset_bufv$qpul:near
878 proc @reset_bufv$qpul near
880 mov [curdata],di
881 and [dword (data_himem di).cacheidx],0
882 ret
884 endp @reset_bufv$qpul
886 ;***************************************************************
887 ;u32* di=prev_bufv();
888 ;u32* di=prev_bufv();
889 ;***************************************************************
890 global _prev_bufv:near
891 global _next_bufv:near
892 proc _prev_bufv near
894 stc
895 db 73h ; jnc
896 _next_bufv:
897 clc
898 mov bx,0
899 org $-2
900 curdata dw ?
901 sbb ax,ax
902 cmc
903 adc ax,[(data_himem bx).cacheidx] ; -1/+1
904 xor ecx,ecx
905 test ax,0fc00h
906 jz @@gotpage
907 push ax ; FFFF / 0400
908 sar ax,8 ; FFFC / 0004
909 and al,0fch
910 add [(data_himem bx).pageidx],ax
911 mov di,[(data_himem bx).pageidx]
912 lea di,[(data_himem bx+di).page]
913 mov edx,ds
914 shl edx,4
915 lea cx,[(data_himem bx).cache]
916 add edx,ecx
917 mov eax,[di]
918 or eax,eax
919 jnz @@pageok
920 pop ax
921 ret
922 @@pageok:
923 mov cx,4096
924 call memcpy_imagez ; get page
925 pop ax ; FFFF / 0400
926 cbw
927 shr ax,6 ; 03FF / 0000
928 @@gotpage:
929 mov [(data_himem bx).cacheidx],ax
930 shl ax,2
931 xchg ax,di
932 lea ax,[(data_himem bx+di).cache]
933 or di,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
934 jnz @@notfirst2
935 xchg ax,bx ; &first
936 @@notfirst2:
937 xchg ax,di
938 ret
940 endp _prev_bufv
941 endif
943 ifdef NO386
944 p8086
945 endif
947 ;***************************************************************
948 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
949 ;***************************************************************
951 global @open_image$qp11image_himempxzc:near
952 proc @open_image$qp11image_himempxzc near
954 push di
955 xchg ax,bx
956 xchg ax,di
957 ifdef EXTRA
958 cmp [(image_himem di).fd],0 ; iso image/kernel ?
959 jnz @@alreadydone
960 endif
961 mov [(image_himem di).state],bx
962 push bx
963 ifdef EXTRA
964 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
965 jnz @@next
966 mov [(image_himem di).next_chunk],offset next_chunk
967 @@next:
968 ;push di
969 call [(image_himem di).next_chunk] ; m->next_chunk()
970 ;pop di
971 else
972 @@next:
973 call next_chunk
974 endif
975 ifndef NO386
976 add eax,3
977 and al,0FCh
978 add [(image_himem di).size],eax ; m->size += m->chunk_size
979 or eax,eax
980 else
981 add ax,3
982 adc dx,0
983 and al,0FCh
984 add [word (image_himem di).size],ax ; m->size += m->chunk_size
985 adc [word ((image_himem di).size)+2],dx
986 or ax,dx
987 endif
988 jnz @@next
989 pop [(image_himem di).state]
990 ifdef EXTRA
991 ;push di
992 call [(image_himem di).next_chunk] ; m->next_chunk()
993 ;pop di
994 else
995 call next_chunk
996 endif
997 @@alreadydone:
998 pop di
999 ret
1001 endp @open_image$qp11image_himempxzc
1004 ;***************************************************************
1005 ;_fastcall int read_image(bx:struct image_himem *m);
1006 ;***************************************************************
1007 global @read_image$qp11image_himem:near
1008 proc @read_image$qp11image_himem near
1010 push si di
1011 mov di,bx
1012 mov si,4096
1013 push si ; original size
1014 @@loop:
1015 ifndef NO386
1016 movzx ecx,si
1017 mov eax,[(image_himem di).chunk_size]
1018 cmp ecx,eax
1019 jb @@szok
1020 else
1021 mov cx,si
1022 mov ax,[word (image_himem di).chunk_size]
1023 cmp cx,ax
1024 jb @@szok
1025 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1026 jne @@szok
1027 endif
1028 xchg ax,cx
1029 @@szok:
1030 jcxz image_done
1031 mov dx,offset _xfer_buf+4096
1032 sub dx,si
1033 mov bx,[di]
1034 call @read$cxdxbx
1035 jb image_done
1036 xor cx,cx
1037 cwd ; ax < 8000h
1038 ifndef NO386
1039 cwde ; ax < 8000h
1040 sub [(image_himem di).chunk_size],eax
1041 xchg eax,ebx
1042 else
1043 sub [word (image_himem di).chunk_size],ax
1044 xchg ax,bx
1045 sbb [word ((image_himem di).chunk_size)+2],dx
1046 jnz @@fill
1047 cmp [word (image_himem di).chunk_size],dx
1048 endif
1049 jnz @@fill
1050 dec cx
1051 @@fill:
1052 test bl,3
1053 je @@filled
1054 mov [bx+_xfer_buf],dh
1055 inc bx
1056 jmp @@fill
1057 @@filled:
1058 ifndef NO386
1059 sub [(image_himem di).remaining],ebx
1060 else
1061 sub [word (image_himem di).remaining],bx
1062 sbb [word ((image_himem di).remaining)+2],dx
1063 endif
1064 sub si,bx
1065 pushf
1066 ifdef EXTRA
1067 and cx,[(image_himem di).next_chunk]
1068 jcxz @@same_chunk
1069 push di
1070 call cx
1071 pop cx
1072 else
1073 jcxz @@same_chunk
1074 call next_chunk
1075 endif
1076 @@same_chunk:
1077 popf
1078 jnz @@loop
1079 image_done:
1080 pop ax ; original size
1081 sub ax,si
1082 pop di si
1083 ret
1085 endp @read_image$qp11image_himem
1088 ;***************************************************************
1089 ;_fastcall unsigned long strtol(const char *s);
1090 ;***************************************************************
1091 ifndef USE_ARGSTR
1092 global @strtol$qpxzc:near
1093 endif
1094 proc @strtol$qpxzc near
1096 ifndef NO386
1097 ifndef USE_ARGSTR
1098 push si
1099 mov si,bx
1100 endif
1101 xor ecx,ecx
1102 xor eax,eax
1103 xor ebx,ebx
1104 or si,si
1105 jz @@end
1106 lodsb
1107 or al,20h
1108 cmp al,'a'
1109 jb @@notvga
1110 sub al,'o'
1111 @@vgaloop:
1112 dec cx
1113 add al,6
1114 jnb @@vgaloop ; vga=normal,extended,ask
1115 @@vga:
1116 dec cx
1117 xchg ax,cx
1118 cwd
1119 jmp @@popsiret
1120 @@notvga:
1121 mov cl,10 ; radix
1122 cmp al,'-'
1123 jne @@radixkeep
1124 lodsb
1125 @@radixkeep:
1126 pushf
1127 cmp al,'0'
1128 jne @@radixok
1129 mov cl,8
1130 lodsb
1131 or al,20h
1132 cmp al,'x'
1133 jne @@radixok
1134 mov cl,16
1135 @@strtollp:
1136 lodsb
1137 @@radixok:
1138 or al,20h
1139 sub al,'0'
1140 jb @@endstrtol
1141 cmp al,9
1142 jbe @@digitok
1143 cmp al,'a'-'0'
1144 jb @@endstrtol
1145 sub al,'a'-'0'-10
1146 @@digitok:
1147 cmp al,cl
1148 jae @@endstrtol
1149 cbw
1150 cwde
1151 xchg eax,ebx
1152 mul ecx
1153 add ebx,eax
1154 jmp @@strtollp
1155 @@endstrtol:
1156 mov cl,10
1157 cmp al,'k'-'a'+10
1158 je @@shift
1159 mov cl,20
1160 cmp al,'m'-'a'+10
1161 je @@shift
1162 mov cl,30
1163 cmp al,'g'-'a'+10
1164 jne @@noshift
1165 @@shift:
1166 shl ebx,cl
1167 @@noshift:
1168 popf
1169 jnc @@end
1170 neg ebx
1171 @@end:
1172 push ebx
1173 pop ax
1174 pop dx
1175 @@popsiret:
1176 ifndef USE_ARGSTR
1177 pop si
1178 endif
1179 else
1180 ifndef USE_ARGSTR
1181 push si
1182 mov si,bx
1183 endif
1184 or si,si
1185 jz @@goend
1186 xor bx,bx
1187 xor cx,cx
1188 xor dx,dx
1189 lodsb
1190 or al,20h
1191 cmp al,'a'
1192 jb @@notvga
1193 sub al,'o'
1194 @@vgaloop:
1195 dec cx
1196 add al,6
1197 jnb @@vgaloop ; vga=normal,extended,ask
1198 @@vga:
1199 xchg ax,cx
1200 ;cwd
1201 @@goend:
1202 jmp @@end
1203 @@notvga:
1204 mov cl,10 ; radix
1205 cmp al,'-'
1206 jne @@radixkeep
1207 lodsb
1208 @@radixkeep:
1209 pushf
1210 cmp al,'0'
1211 jne @@radixok
1212 mov cl,8
1213 lodsb
1214 or al,20h
1215 cmp al,'x'
1216 jne @@radixok
1217 mov cl,16
1218 @@strtollp:
1219 lodsb
1220 @@radixok:
1221 or al,20h
1222 sub al,'0'
1223 jb @@endstrtol
1224 cmp al,9
1225 jbe @@digitok
1226 cmp al,'a'-'0'
1227 jb @@endstrtol
1228 sub al,'a'-'0'-10
1229 @@digitok:
1230 cmp al,cl
1231 jae @@endstrtol
1232 cbw
1234 push ax
1235 xchg ax,dx
1236 mul cx
1237 xchg ax,bx
1238 mul cx
1239 add dx,bx
1240 pop bx
1241 add bx,ax
1242 adc dx,0
1244 jmp @@strtollp
1245 @@endstrtol:
1246 mov cl,10
1247 cmp al,'k'-'a'+10
1248 je @@shift
1249 mov cl,20
1250 cmp al,'m'-'a'+10
1251 je @@shift
1252 mov cl,30
1253 cmp al,'g'-'a'+10
1254 @@shift:
1255 xchg ax,bx
1256 jne @@noshift
1257 extrn N_LXLSH@:near
1258 call N_LXLSH@
1259 @@noshift:
1260 popf
1261 jne @@end
1262 not dx
1263 neg ax
1264 jne @@end
1265 inc dx
1266 @@end:
1267 ifndef USE_ARGSTR
1268 pop si
1269 endif
1270 endif
1271 strtol_ret:
1272 ret
1274 endp @strtol$qpxzc
1277 ifdef EXTRA
1278 p8086
1279 ;***************************************************************
1280 ;_fastcall char *utoa(ax:unsigned n);
1281 ;***************************************************************
1282 global @utoa$qui:near
1283 proc @utoa$qui near
1285 mov cx,10
1286 mov bx,offset utoabuf+5
1287 @@loop:
1288 dec bx
1289 xor dx,dx
1290 div cx ; DX:AX = n%10:n/10
1291 mov [byte bx],'0'
1292 add [bx],dl ; DL = n%10
1293 or ax,ax
1294 jnz @@loop
1295 xchg ax,bx
1296 ret
1298 endp @utoa$qui
1301 ;***************************************************************
1302 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1303 ;***************************************************************
1304 global @kver2ul$qpzc:near
1305 proc @kver2ul$qpzc near
1307 push si
1308 mov si,bx
1309 xor bx,bx
1310 mov cx,304h
1311 @@number:
1312 xor ax,ax
1313 cwd
1314 @@digit:
1315 shl al,cl
1316 shl ax,cl
1317 lodsb
1318 sub al,30h
1319 cmp al,9
1320 jbe @@digit
1321 mov dl,bh
1322 mov bh,bl
1323 mov bl,ah
1324 dec ch
1325 jnz @@number
1326 xchg ax,bx
1327 pop si
1328 kver2ulret:
1329 ret
1331 endp @kver2ul$qpzc
1333 endif
1335 ends _TEXT
1337 end
1339 ;###### END OF FILE ############################################