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

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