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

Up ffmpegthumbnailer-dev (2.2.0), lucene++-dev (3.0.7+git), xine-fonts (1.2.9)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 30 10:51:27 2019 +0200 (2019-05-30)
parents 0e811092e7bb
children 36cb14e87ba5
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
19 global _heap_top
20 extrn _bss_end
21 _heap_top dw _bss_end
22 msg_hang db "High mem corrupted - not exiting to DOS"
23 msg_lf db 10,0
24 vcpi_alloc_err db "VCPI "
25 msg_malloc db "malloc error",0
26 ifdef EXTRA
27 tazboot_cmd db "tazboot.cmd",0
28 endif
30 ends _DATA
32 segment _BSS byte public use16 'BSS'
34 _xfer_buf db 4096 dup (?)
35 global _no_exit:byte
36 _no_exit db ?
37 filecnt db ? ; in fact 0 minus file count...
38 nextfilename dw ?
39 ifdef LARGE_IMAGES
40 curdata dw ?
41 endif
42 ifdef EXTRA
43 ultoabuf db 12 dup (?)
44 endif
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 ;***************************************************************
51 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
52 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
53 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
54 ;***************************************************************
55 ifdef EXTRA
56 global @strcat$qpxzct1:near
57 @strcat$qpxzct1:
58 mov cx,1h
59 db 0bah ; mov dx,imm opcode
60 endif
61 global @strcatb$qpxzct1:near
62 proc @strcatb$qpxzct1 near
64 ifdef EXTRA
65 mov cl,7Fh
66 db 0bah ; mov dx,imm opcode
67 global @strcpy$qpxzct1:near
68 @strcpy$qpxzct1:
69 xor cx,cx
70 endif
71 push si
72 xchg ax,si ; b
73 ifdef EXTRA
74 jcxz @@nocat
75 endif
76 dec bx
77 @@catlp:
78 inc bx
79 cmp [byte bx],0 ; a=bx
80 jne @@catlp
81 ifdef EXTRA
82 mov al,20h
83 loop @@cpyhead
84 else
85 db 0b8h,20h ; mov ax,??20h
86 endif
87 @@nocat:
88 @@cpylp:
89 lodsb
90 @@cpyhead:
91 mov [bx],al
92 inc bx
93 or al,al
94 jne @@cpylp
95 strfound:
96 xchg ax,dx
97 strend:
98 pop si
99 ret
101 endp @strcatb$qpxzct1
104 ifdef EXTRA
105 p8086
106 ;***************************************************************
107 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
108 ;***************************************************************
109 global @strstr$qpxzct1:near
110 proc @strstr$qpxzct1 near
112 xchg ax,cx ; b
113 mov dx,bx ; a
114 push si
115 @@loop:
116 xor ax,ax
117 mov si,dx
118 cmp [si],al ; *a
119 jz strend ; return ax = NULL
120 mov bx,cx
121 @@match:
122 or ah,[bx] ; *b
123 jz strfound
124 inc bx
125 lodsb
126 sub ah,al
127 jz @@match
128 inc dx
129 jmp @@loop
131 endp @strstr$qpxzct1
134 ;***************************************************************
135 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
136 ;***************************************************************
137 global @strcmp$qpxzct1:near
138 proc @strcmp$qpxzct1 near
140 push si
141 xchg ax,si
142 dec bx
143 @@lp:
144 inc bx
145 lodsb
146 sub al,[bx]
147 jnz @@out
148 or al,[bx]
149 jnz @@lp
150 @@out:
151 cbw
152 pop si
153 ret
155 endp @strcmp$qpxzct1
156 endif
159 ;***************************************************************
160 ;_fastcall void puts(bx:const char* s):
161 ;***************************************************************
162 global @puts$qpxzc:near
163 proc @puts$qpxzc near
165 ; global puts:near ; puts(bx)
166 puts:
167 call @@putsz
168 mov bx,offset msg_lf
169 mov dl,13
170 @@putcz:
171 mov ah,2
172 int 21h
173 @@putsz:
174 mov dl,[bx]
175 inc bx
176 or dl,dl
177 jne @@putcz ; ZF=1 (for malloc failure)
178 ret
180 endp @puts$qpxzc
184 ;***************************************************************
185 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
186 ;***************************************************************
187 global openargs:near ; openargs(bx)
188 openargs:
189 cmp [byte bx],'@'
190 jne fail
191 inc bx
193 global @open$qpxzc:near
194 proc @open$qpxzc near
196 global open:near ; open(bx)
197 open:
198 ifdef LONG_FILENAME
199 mov ax,716Ch
200 push bx di si
201 mov si,bx
202 xor bx,bx ; R/O
203 xor cx,cx ; attributes
204 xor di,di ; alias hint
205 cwd ; action = open
206 stc
207 int 21h
208 pop si di bx
209 jnc doret
210 endif
211 mov ax,3d00h ; read-only+compatibility
212 ;mov cl,0 ; attribute mask
213 mov dx,bx
214 jmp dos
216 endp @open$qpxzc
219 ;***************************************************************
220 ;_fastcall int fileexist(bx:const char* name);
221 ;***************************************************************
222 global @fileexist$qpxzc:near
223 @fileexist$qpxzc:
224 call @open$qpxzc
225 jc fail
227 ;***************************************************************
228 ;_fastcall int close(ax:int fd);
229 ;***************************************************************
230 global @close$qi:near
231 proc @close$qi near
233 global close:near ; close(ax)
234 close:
235 xchg ax,bx
236 mov ah,3Eh
237 or bx,bx
238 jnz dos
239 ret
241 endp @close$qi
244 ;***************************************************************
245 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
246 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
247 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
248 ;***************************************************************
249 global @readrm$qp11image_himemi:near
250 @readrm$qp11image_himemi:
251 xchg ax,dx ; sz
252 mov ax,[bx] ; fd
253 mov bx,[bx-2] ; data
254 global @read$qipvi:near
255 proc @read$qipvi near
257 ifdef WRITE
258 stc
259 db 0B0h ; mov al,im
260 global @write$qipvi:near
261 @write$qipvi:
262 clc
263 endif
264 @read$dxbxax:
265 xchg ax,bx ; fd
266 xchg ax,dx ; data
267 xchg ax,cx ; sz
268 ifdef WRITE
269 mov ah,40h
270 sbb ah,0
271 else
272 global @read$cxdxbx:near
273 @read$cxdxbx:
274 mov ah,3Fh
275 endif
276 jcxz fail
277 dos:
278 int 21h
279 chkc:
280 jnc doret
281 fail:
282 stc
283 failifc:
284 sbb ax,ax ; ax=-1 CF
285 cwd
286 doret:
287 ifndef NO386
288 push dx ; see next_chunk:lseek
289 push ax
290 pop eax
291 endif
292 ret
294 endp @read$qipvi
296 ;***************************************************************
297 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
298 ;***************************************************************
300 global @lseekcur$qii:near ; fd=ax whence=dx
301 proc @lseekcur$qii near
303 mov cl,1
304 xchg ax,bx
305 xchg ax,dx
306 cwd
307 xchg ax,dx
308 xchg ax,cx
309 jmp lseek
310 rewind: ; rewind(ax)
311 mov bl,0
312 lseek0: ; lseek0(ax,bl=dir)
313 xor dx,dx
314 xor cx,cx
315 lseekset:
316 xchg ax,bx
317 lseek:
318 mov ah,42h ; bx=fd cx:dx=offset al=whence
319 jmp dos
321 endp @lseekcur$qii
323 ifdef EXTRA
325 ;typedef unsigned dirsizetype;
326 struc isostate ; struct isostate {
327 fd dw ? ; 0 int fd;
328 filemod dw ? ; 2 unsigned short filemod;
329 fileofs dd ? ; 4 unsigned long fileofs;
330 filesize dd ? ; 8 unsigned long filesize;
331 filename dw ? ;12 char *filename;
332 curdirsize dw ? ;14 dirsizetype curdirsize;
333 dirsize dw ? ;16 dirsizetype dirsize;
334 curdirofs dd ? ;18 unsigned long curdirofs;
335 dirofs dd ? ;22 unsigned long dirofs;
336 curpos dw ? ;26 unsigned curpos;
337 filename2open dw ? ;28 char *filename2open;
338 buffer db 2560 dup(?) ;30 char buffer[2048+512];
339 ends ; } isostate;
340 ;***************************************************************
341 ;_fastcall long isolseek(bx:const unsigned long *offset);
342 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
343 ;***************************************************************
344 global @isolseek$qpxul:near
345 proc @isolseek$qpxul near
347 isolseek:
348 extrn _isostate:isostate
349 mov ax,[_isostate.fd]
350 global @lseekset2$qipul:near
351 @lseekset2$qipul:
352 mov dx,[bx]
353 mov cx,[bx+2]
354 mov bl,0
355 jmp lseekset
357 endp @isolseek$qpxul
359 ;***************************************************************
360 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
361 ;***************************************************************
362 global @isoreadsector$qpxul:near
363 proc @isoreadsector$qpxul near
365 call isolseek
366 jc doret
367 mov dx,2560
368 mov bx,offset _isostate.buffer
369 mov ax,[_isostate.fd]
370 jmp @read$dxbxax ; read(fd,buffer,2560)
372 endp @isoreadsector$qpxul
375 ;***************************************************************
376 ;_fastcall int isoreset(bx:const char *name);
377 ;***************************************************************
378 global @isoreset$qpzc:near
379 proc @isoreset$qpzc near
381 or bx,bx
382 jz fail
383 call near ptr @open$qpxzc
384 mov [_isostate.fd],ax
385 extrn @isoroot$qv:near
386 jmp @isoroot$qv
388 endp @isoreset$qpzc
391 ;***************************************************************
392 ;_fastcall int isoopen(bx:const char *name);
393 ;***************************************************************
394 global @isoopen$qpxzc:near
395 proc @isoopen$qpxzc near
397 extrn @_isoopen$qv:near
398 mov [_isostate.filename2open],bx
399 jmp @_isoopen$qv
401 endp @isoopen$qpxzc
403 endif
406 ifdef USE_ARGSTR
407 ;***************************************************************
408 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
409 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
410 ;***************************************************************
411 global @argstr$qpxzcxt1ppxzc:near
412 proc @argstr$qpxzcxt1ppxzc near
414 mov cl,2
415 db 0a9h ; test ax,#
416 global @argnum$qpzcxpxzcpul:near
417 @argnum$qpzcxpxzcpul:
418 mov cl,4
419 xchg ax,bx ; keywords -> bx
420 xchg ax,cx ; s -> cx
421 cbw ; argstr:0002 argnum:0004
422 xchg ax,dx ; vars -> ax
423 push si di
424 xchg ax,di ; vars => di
425 dec bx
426 @@testalt:
427 mov al,-1
428 sub di,dx
429 @@test:
430 cmp al,'='
431 je @@found
432 cmp al,0 ; eos, si=next argv
433 je @@found
434 mov si,cx ; s
435 add di,dx
436 @@match:
437 inc bx ; keywords++
438 lodsb ; *s++
439 or al,20h
440 cmp al,[bx]
441 je @@match
442 cmp al,'/' ; 2f
443 jne @@notopt
444 cmp [byte bx],'-'
445 je @@match
446 @@notopt:
447 ifdef EXTRA
448 cmp [byte bx],'/'
449 je @@testalt
450 endif
451 cmp [byte bx],'|'
452 je @@test
453 mov al,0
454 inc bx
455 cmp [bx-1],al
456 jne @@notopt
457 stc
458 jmp @@nokeyword
459 @@found:
460 mov [di],si
461 dec dx
462 dec dx
463 je @@done
464 mov bx,si
465 call @strtol$qpxzc
466 mov [di],ax
467 mov [di+2],dx
468 @@done:
469 clc
470 @@nokeyword:
471 sbb ax,ax
472 pop di si
473 ret
475 endp @argstr$qpxzcxt1ppxzc
477 else
479 ;***************************************************************
480 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
481 ;***************************************************************
482 global @strhead$qpxzct1:near
483 proc @strhead$qpxzct1 near
485 @@loop:
486 xchg ax,bx
487 mov cl,[bx] ; cl = *b++
488 inc bx
489 or cl,cl ; clear C
490 jz failifc ; return 0
491 xchg ax,bx
492 xor cl,[bx] ; cl -= *a++
493 inc bx
494 and cl,0dfh ; case insensitive
495 jne fail ; return -1
496 jmp @@loop
498 endp @strhead$qpxzct1
500 endif
502 ;***************************************************************
503 ;_fastcall char* malloc_or_die(ax:unsigned size);
504 ;***************************************************************
505 global @malloc_or_die$qui:near
506 proc @malloc_or_die$qui near
508 xchg ax,cx ; size
509 global malloc_or_die:near ; malloc_or_die(cx)
510 malloc_or_die:
511 mov ax,[_heap_top] ; return value
512 mov bx,sp
513 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
514 sub bx,ax ; can't overflow
515 cmp bx,cx
516 mov bx,offset msg_malloc
517 jb die
518 add [_heap_top],cx ; _BEG has zero'd heap
519 ret
521 endp @malloc_or_die$qui
524 ;***************************************************************
525 ;_fastcall int die(bx:const char* msg);
526 ;int exit();
527 ;int abort();
528 ;***************************************************************
529 global @die$qpxzc:near
530 proc @die$qpxzc near
531 @die$qpxzc:
532 global die:near ; die(bx)
533 die:
534 call puts
535 ; global _exit:near
536 _exit:
537 mov al,[_no_exit]
538 or al,al
539 jne @@hang
540 extrn exit:near
541 inc ax
542 jmp near exit
543 @@hang:
544 mov bx, offset msg_hang
545 call puts
546 ; global _abort:near
547 _abort:
548 cli
549 hlt
550 jmp _abort
552 endp @die$qpxzc
554 struc image_himem ;struct image_himem {
555 fd dw ? ; 0 int fd;
556 fallback dd ? ; 2 u32 fallback;
557 size dd ? ; 6 u32 size;
558 remaining dd ? ;10 u32 remaining;
559 buf dd ? ;14 u32 buf;
560 bufv dw ? ;18 u32 *bufv;
561 errmsg dw ? ;20 char *errmsg;
562 chunk_size dd ? ;22 u32 chunk_size;
563 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
564 state dw ? ;28 u16 state;
565 fd2close dw ? ;30 u16 fd2close;
566 ends ;};
568 ;***************************************************************
569 ;static long next_chunk(struct image_himem *di);
570 ;***************************************************************
571 proc next_chunk near
573 push si
574 mov ax,[(image_himem di).fd]
575 call close
576 ifndef NO386
577 xor eax,eax
578 else
579 xor ax,ax
580 cwd
581 endif
582 mov [(image_himem di).fd],ax
583 mov bx,[(image_himem di).state]
584 cmp al,[bx] ; ""
585 jz @@end
586 mov si,bx
587 @@scan:
588 lodsb
589 mov cx,si
590 cmp al,','
591 jz @@eos
592 or al,al
593 jnz @@scan
594 dec cx
595 @@eos:
596 mov [(image_himem di).state],cx
597 dec si
598 push [word si]
599 mov [byte si],ah ; set temp eos
600 call open
601 pop [word si] ; restore string
602 jc @@die
603 mov [(image_himem di).fd],ax
604 mov [(image_himem di).fd2close],ax
605 mov bl,02h ; SEEK_END
606 call lseek0
607 @@die:
608 mov bx,[(image_himem di).errmsg]
609 jc die
610 ifndef NO386
611 push eax
612 mov ax,[(image_himem di).fd]
613 call rewind
614 pop eax
615 @@end:
616 mov [(image_himem di).chunk_size],eax
617 else
618 push ax
619 push dx
620 mov ax,[(image_himem di).fd]
621 call rewind
622 pop dx
623 pop ax
624 @@end:
625 mov [word (image_himem di).chunk_size],ax
626 mov [word ((image_himem di).chunk_size)+2],dx
627 endif
628 pop si
629 ret
631 endp next_chunk
634 ifdef LARGE_IMAGES
635 struc data_himem ;struct data_himem {
636 first dd ? ; 0 u32 first;
637 cacheidx dw ? ; 4 int cacheidx;
638 pageidx dw ? ; 6 int pageidx;
639 cache dd 1024 dup(?) ; 8 int cache;
640 page dd 1024 dup(?) ;4104 int page;
641 ends ;}; // size=8200
642 endif
644 ;***************************************************************
645 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
646 ;***************************************************************
647 global @malloc_bufv_or_die$qp11image_himem:near
648 proc @malloc_bufv_or_die$qp11image_himem near
650 p386
651 push si
652 mov si,bx
653 ifdef LARGE_IMAGES
654 movzx ecx,[word ((image_himem si).size) + 2]
655 shr cx,4 ; pages index size = size >> 20
656 add cx,8+4096+8
657 call malloc_or_die
658 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
659 add ecx,[(image_himem si).size]
660 shr ecx,12
661 mov [curdata],ax
662 else
663 mov ecx,[(image_himem si).size]
664 dec ecx
665 shr ecx,12
666 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
667 push cx
668 inc cx ; cnt+1
669 shl cx,2 ; bufv => vcpi => vm86
670 ; our malloc zeroes allocated mem: bufv[cnt]=0;
671 ; Allocate pages, storing addrs in addrbuf
672 call malloc_or_die
673 pop cx
674 push ax
675 endif
676 mov [(image_himem si).bufv],ax
677 xchg ax,si
678 @@vcpi_alloc:
679 xor edx,edx
680 mov ax,0DE04h
681 int 67h
682 or ah,ah
683 mov bx,offset vcpi_alloc_err
684 jnz die
685 ; for (i = cnt-1; i >= 0; i--)
686 ifdef LARGE_IMAGES
687 mov eax,ecx
688 dec eax
689 else
690 mov ax,cx
691 dec ax
692 cwde
693 endif
694 shl eax,12 ; i*_4k
695 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
696 extrn _imgs
697 mov bx,offset _imgs+2
698 push eax
699 add eax,[bx-2+2]
700 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
701 pop eax ; i*_4k
702 jbe @@pmok
703 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
704 jae @@vcpi_alloc
705 @@pmok:
706 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
707 extrn _imgs
708 mov bx,offset _imgs+32+2
709 add eax,[bx-2+2] ; +initrd.fallback
710 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
711 ja @@initrdok
712 mov eax,[bx-2+6] ; initrd.size
713 add eax,[bx-2+2] ; +initrd.fallback
714 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
715 @@jnc_vcpi_alloc:
716 ja @@vcpi_alloc
717 @@initrdok:
718 ifdef LARGE_IMAGES
719 cmp [(data_himem si).first],0
720 jne @@notfirst
721 mov [(data_himem si).first],edx
722 @@notfirst:
723 mov bx,[(data_himem si).cacheidx]
724 cmp bh,4
725 jae @@nextpage
726 shl bx,2
727 inc [(data_himem si).cacheidx]
728 mov [(data_himem bx+si).cache],edx
729 loopd @@vcpi_alloc
730 mov [(data_himem bx+si).cache],ecx ; last is 0
731 @@nextpage:
732 and [(data_himem si).cacheidx],0
733 mov bx,[(data_himem si).pageidx]
734 mov [(data_himem bx+si).page],edx
735 add [(data_himem si).pageidx],4
736 push cx
737 lea cx,[(data_himem si).cache]
738 ifdef NO386
739 push edx
740 pop dx
741 pop ax
742 endif
743 call storepage ; storepage(edx,cx)
744 pop cx
745 or ecx,ecx ; clear C
746 jnz @@jnc_vcpi_alloc
747 mov [dword (data_himem si).cacheidx],ecx
748 xchg ax,si
749 else
750 mov [si],edx
751 lodsd ; si=+4
752 loop @@vcpi_alloc
753 pop ax
754 endif
755 pop si
756 ret
757 ifdef NO386
758 p8086
759 endif
761 endp @malloc_bufv_or_die$qp11image_himem
764 ;***************************************************************
765 ;_fastcall void memcpy_image(bx:struct image_himem *m);
766 ;***************************************************************
767 global @memcpy_image$qp11image_himem:near
768 proc @memcpy_image$qp11image_himem near
770 ifndef NO386
771 mov edx,[(image_himem bx).fallback]
772 mov eax,[(image_himem bx).buf]
773 cmp eax,edx ; if (m->fallback != m->buf)
774 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
775 ifdef LARGE_IMAGES
776 mov ecx,[(image_himem bx).size]
777 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
778 push ecx
779 else
780 push [(image_himem bx).size]
781 endif
782 push eax
783 push 0
784 call_memcpy32:
785 push edx
786 else
787 mov ax,[word ((image_himem bx).fallback)]
788 mov dx,[word ((image_himem bx).fallback)+2]
789 mov cx,[word ((image_himem bx).buf)]
790 cmp ax,cx ; if (m->fallback != m->buf)
791 jnz @@do
792 cmp dx,[word ((image_himem bx).buf)+2]
793 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
794 @@do:
795 push [word ((image_himem bx).size)+2]
796 push [word ((image_himem bx).size)]
797 push [word ((image_himem bx).buf)+2]
798 push cx
799 xor cx,cx
800 push cx
801 call_memcpy32:
802 push dx
803 push ax
804 ifdef LARGE_IMAGES
805 jmp @@memcpy
806 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
807 p386
808 push ecx
809 push eax
810 push 0
811 push edx
812 ifdef NO386
813 p8086
814 endif
815 endif
816 endif
817 @@memcpy:
818 extrn memcpy32:near
819 call near memcpy32
820 @@skip:
821 ret
823 endp @memcpy_image$qp11image_himem
825 ;***************************************************************
826 ;_fastcall void storepage(bx:u32 *dst);
827 ;***************************************************************
828 global @storepage$qpul:near
829 proc @storepage$qpul near
831 ifndef NO386
832 mov edx,[bx]
833 else
834 mov ax,[bx]
835 mov dx,[bx+2]
836 endif
837 mov cx,offset _xfer_buf
838 storepage: ; storepage(edx,cx)
839 ifndef NO386
840 push 0
841 push 4096
842 push 0
843 else
844 xor bx,bx
845 push bx
846 mov bh,4096/256
847 push bx
848 xor bx,bx
849 push bx
850 endif
851 push cx
852 push ds
853 jmp call_memcpy32
855 endp @storepage$qpul
858 ifdef LARGE_IMAGES
859 p386
860 ;***************************************************************
861 ;_fastcall void reset_bufv(bx:u32 *p);
862 ;***************************************************************
863 global @reset_bufv$qpul:near
864 proc @reset_bufv$qpul near
866 mov [curdata],bx
867 and [dword (data_himem bx).cacheidx],0
868 ret
870 endp @reset_bufv$qpul
872 ;***************************************************************
873 ;u32* prev_bufv();
874 ;u32* prev_bufv();
875 ;***************************************************************
876 global _prev_bufv:near
877 global _next_bufv:near
878 proc _prev_bufv near
880 stc
881 db 73h ; jnc
882 _next_bufv:
883 clc
884 push si
885 mov si,[curdata]
886 sbb ax,ax
887 cmc
888 adc ax,[(data_himem si).cacheidx] ; -1/+1
889 xor ecx,ecx
890 test ax,0fc00h
891 jz @@gotpage
892 push ax ; FFFF / 0400
893 sar ax,8 ; FFFC / 0004
894 and al,0fch
895 add [(data_himem si).pageidx],ax
896 mov bx,[(data_himem si).pageidx]
897 lea bx,[(data_himem bx+si).page]
898 mov edx,ds
899 shl edx,4
900 lea cx,[(data_himem si).cache]
901 add edx,ecx
902 mov eax,[bx]
903 or eax,eax
904 jnz @@pageok
905 pop ax
906 xchg ax,bx
907 pop si
908 ret
909 @@pageok:
910 mov cx,4096
911 call memcpy_imagez ; get page
912 pop ax ; FFFF / 0400
913 cbw
914 shr ax,6 ; 03FF / 0000
915 @@gotpage:
916 mov [(data_himem si).cacheidx],ax
917 shl ax,2
918 xchg ax,bx
919 lea ax,[(data_himem bx+si).cache]
920 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
921 jnz @@notfirst2
922 xchg ax,si ; &first
923 @@notfirst2:
924 pop si
925 ret
927 endp _prev_bufv
928 endif
930 ifdef NO386
931 p8086
932 endif
934 ;***************************************************************
935 ;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name);
936 ;***************************************************************
938 global @open_image$qp11image_himempxzc:near
939 proc @open_image$qp11image_himempxzc near
941 push di
942 xchg ax,bx
943 xchg ax,di
944 ifdef EXTRA
945 cmp [(image_himem di).fd],0 ; iso image/kernel ?
946 jnz @@alreadydone
947 endif
948 mov [(image_himem di).state],bx
949 push bx
950 ifdef EXTRA
951 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
952 jnz @@next
953 mov [(image_himem di).next_chunk],offset next_chunk
954 @@next:
955 call [(image_himem di).next_chunk] ; m->next_chunk()
956 else
957 @@next:
958 call next_chunk
959 endif
960 ifndef NO386
961 add eax,3
962 and al,0FCh
963 add [(image_himem di).size],eax ; m->size += m->chunk_size
964 or eax,eax
965 else
966 add ax,3
967 adc dx,0
968 and al,0FCh
969 add [word (image_himem di).size],ax ; m->size += m->chunk_size
970 adc [word ((image_himem di).size)+2],dx
971 or ax,dx
972 endif
973 jnz @@next
974 pop [(image_himem di).state]
975 ifdef EXTRA
976 call [(image_himem di).next_chunk] ; m->next_chunk()
977 else
978 call next_chunk
979 endif
980 @@alreadydone:
981 pop di
982 ret
984 endp @open_image$qp11image_himempxzc
987 ;***************************************************************
988 ;_fastcall int read_image(bx:struct image_himem *m);
989 ;***************************************************************
990 global @read_image$qp11image_himem:near
991 proc @read_image$qp11image_himem near
993 push si di
994 mov di,bx
995 mov si,4096
996 push si ; original size
997 @@loop:
998 ifndef NO386
999 movzx ecx,si
1000 mov eax,[(image_himem di).chunk_size]
1001 cmp ecx,eax
1002 jb @@szok
1003 else
1004 mov cx,si
1005 mov ax,[word (image_himem di).chunk_size]
1006 cmp cx,ax
1007 jb @@szok
1008 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1009 jne @@szok
1010 endif
1011 xchg ax,cx
1012 @@szok:
1013 jcxz image_done
1014 mov dx,offset _xfer_buf+4096
1015 sub dx,si
1016 mov bx,[di]
1017 call @read$cxdxbx
1018 jc image_done
1019 xor cx,cx
1020 cwd ; ax < 8000h
1021 ifndef NO386
1022 cwde ; ax < 8000h
1023 sub [(image_himem di).chunk_size],eax
1024 xchg eax,ebx
1025 else
1026 sub [word (image_himem di).chunk_size],ax
1027 xchg ax,bx
1028 sbb [word ((image_himem di).chunk_size)+2],dx
1029 jnz @@fill
1030 cmp [word (image_himem di).chunk_size],dx
1031 endif
1032 jnz @@fill
1033 dec cx
1034 @@fill:
1035 test bl,3
1036 je @@filled
1037 mov [bx+_xfer_buf],dh
1038 inc bx
1039 jmp @@fill
1040 @@filled:
1041 ifndef NO386
1042 sub [(image_himem di).remaining],ebx
1043 else
1044 sub [word (image_himem di).remaining],bx
1045 sbb [word ((image_himem di).remaining)+2],dx
1046 endif
1047 sub si,bx
1048 pushf
1049 ifdef EXTRA
1050 and cx,[(image_himem di).next_chunk]
1051 jcxz @@same_chunk
1052 push di
1053 call cx
1054 pop cx
1055 else
1056 jcxz @@same_chunk
1057 call next_chunk
1058 endif
1059 @@same_chunk:
1060 popf
1061 jnz @@loop
1062 image_done:
1063 pop ax ; original size
1064 sub ax,si
1065 pop di si
1066 ret
1068 endp @read_image$qp11image_himem
1071 ;***************************************************************
1072 ;_fastcall unsigned long strtol(const char *s);
1073 ;***************************************************************
1074 global @strtol$qpxzc:near
1075 proc @strtol$qpxzc near
1077 ifndef NO386
1078 push si
1079 mov si,bx
1080 xor ecx,ecx
1081 xor eax,eax
1082 xor ebx,ebx
1083 or si,si
1084 jz @@end
1085 lodsb
1086 mov dx,ax
1087 or al,20h
1088 cmp al,'n' ; vga=normal
1089 je @@vga
1090 dec cx
1091 cmp al,'e' ; vga=extended
1092 je @@vga
1093 dec cx
1094 cmp al,'a' ; vga=ask
1095 jne @@notvga
1096 @@vga:
1097 dec cx
1098 xchg ax,cx
1099 cwd
1100 jmp @@popsiret
1101 @@notvga:
1102 mov cx,10 ; radix
1103 xchg ax,dx
1104 cmp al,'+'
1105 je @@radixskip
1106 cmp al,'-'
1107 clc
1108 jne @@radixkeep
1109 stc
1110 @@radixskip:
1111 lodsb
1112 @@radixkeep:
1113 pushf
1114 cmp al,'0'
1115 jne @@radixok
1116 mov cl,8
1117 lodsb
1118 or al,20h
1119 cmp al,'x'
1120 jne @@radixok
1121 mov cl,16
1122 @@strtollp:
1123 lodsb
1124 @@radixok:
1125 or al,20h
1126 sub al,'0'
1127 jb @@endstrtol
1128 cmp al,9
1129 jbe @@digitok
1130 cmp al,'a'-'0'
1131 jb @@endstrtol
1132 sub al,'a'-'0'-10
1133 @@digitok:
1134 cmp al,cl
1135 jae @@endstrtol
1136 xchg eax,ebx
1137 mul ecx
1138 add eax,ebx
1139 xchg eax,ebx
1140 jmp @@strtollp
1141 @@endstrtol:
1142 mov cl,10
1143 cmp al,'k'-'a'+10
1144 je @@shift
1145 mov cl,20
1146 cmp al,'m'-'a'+10
1147 je @@shift
1148 mov cl,30
1149 cmp al,'g'-'a'+10
1150 jne @@noshift
1151 @@shift:
1152 shl ebx,cl
1153 @@noshift:
1154 popf
1155 jnc @@end
1156 neg ebx
1157 @@end:
1158 push ebx
1159 pop ax
1160 pop dx
1161 @@popsiret:
1162 pop si
1163 else
1164 push si
1165 push di
1166 xor ax,ax
1167 cwd
1168 or bx,bx
1169 jz @@goend
1170 xchg ax,di
1171 mov si,bx
1172 lodsb
1173 mov bx,ax
1174 or al,20h
1175 mov cx,-1
1176 cmp al,'n' ; vga=normal
1177 je @@vga
1178 dec cx
1179 cmp al,'e' ; vga=extended
1180 je @@vga
1181 dec cx
1182 cmp al,'a' ; vga=ask
1183 jne @@notvga
1184 @@vga:
1185 xchg ax,cx
1186 @@goend:
1187 jmp @@popdisiret
1188 @@notvga:
1189 mov cx,10 ; radix
1190 xchg ax,bx
1191 cmp al,'+'
1192 je @@radixskip
1193 cmp al,'-'
1194 clc
1195 jne @@radixkeep
1196 stc
1197 @@radixskip:
1198 lodsb
1199 @@radixkeep:
1200 pushf
1201 cmp al,'0'
1202 jne @@radixok
1203 mov cl,8
1204 lodsb
1205 or al,20h
1206 cmp al,'x'
1207 jne @@radixok
1208 mov cl,16
1209 @@strtollp:
1210 lodsb
1211 @@radixok:
1212 or al,20h
1213 sub al,'0'
1214 jb @@endstrtol
1215 cmp al,9
1216 jbe @@digitok
1217 cmp al,'a'-'0'
1218 jb @@endstrtol
1219 sub al,'a'-'0'-10
1220 @@digitok:
1221 cmp al,cl
1222 jae @@endstrtol
1224 push ax
1225 push si
1226 push dx
1227 xchg ax,di
1228 mul cx
1229 xchg ax,di
1230 xchg ax,dx
1231 xchg ax,si
1232 pop ax
1233 mul cx
1234 add ax,si
1235 pop si
1236 xchg ax,dx
1237 pop ax
1238 mov ah,0
1239 add di,ax
1240 adc dx,0
1242 jmp @@strtollp
1243 @@endstrtol:
1244 mov cl,10
1245 cmp al,'k'-'a'+10
1246 je @@shift
1247 mov cl,20
1248 cmp al,'m'-'a'+10
1249 je @@shift
1250 mov cl,30
1251 cmp al,'g'-'a'+10
1252 jne @@noshift
1253 @@shift:
1254 rcl di,1
1255 shl dx,1
1256 loop @@shift
1257 @@noshift:
1258 popf
1259 jnc @@end
1260 not dx
1261 neg di
1262 jne @@end
1263 inc dx
1264 @@end:
1265 xchg ax,di
1266 @@popdisiret:
1267 pop di
1268 pop si
1269 endif
1270 strtol_ret:
1271 ret
1273 endp @strtol$qpxzc
1276 ifdef USE_ARGSTR
1277 ;***************************************************************
1278 ;_fastcall void set_cmdline(bx:const char *filename);
1279 ;***************************************************************
1280 global @set_cmdline$qpxzc:near
1281 proc @set_cmdline$qpxzc near
1282 call openargs
1283 jc strtol_ret
1284 mov cx,4096
1285 mov di,[_heap_top]
1286 extrn read_cmdline:near
1287 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1289 endp @set_cmdline$qpxzc
1290 endif
1293 ifdef NO386
1294 ;***************************************************************
1295 ;u16 topseg();
1296 ;***************************************************************
1297 global _topseg:near
1298 proc _topseg near
1300 int 12h
1301 jnc @@max640k
1302 mov ax,640 ; 9000
1303 @@max640k:
1304 dec ax
1305 and al,0C0h
1306 mov cl,6
1307 shl ax,cl
1308 ret
1310 endp _topseg
1311 endif
1313 ifdef EXTRA
1314 p8086
1315 ;***************************************************************
1316 ;char *progname(void)
1317 ;***************************************************************
1318 global _progname:near
1319 proc _progname near
1321 push si di es
1322 mov ah,30h
1323 int 21h
1324 xor di,di
1325 cmp al,3
1326 mov ax,di
1327 jb @@skip
1328 ;mov es,[cs:2Ch]
1329 mov es,[di+2Ch]
1330 mov cx,sp ; big enough
1331 @@loop:
1332 repne
1333 scasb
1334 scasb
1335 jne @@loop
1336 inc di
1337 inc di
1338 mov si,di ; progname @es:di
1339 repne
1340 scasb
1341 mov cx,di
1342 sub cx,si ; progname len
1343 call malloc_or_die ; keep cx
1344 mov di,ax
1345 push ds
1346 push es
1347 pop ds
1348 pop es
1349 rep
1350 movsb
1351 push es
1352 pop ds
1353 @@skip:
1354 pop es di si
1355 ret
1357 endp _progname
1360 ;***************************************************************
1361 ;_fastcall void chdirname(bx:char *path)
1362 ;***************************************************************
1363 global @chdirname$qpzc:near
1364 proc @chdirname$qpzc near
1366 cmp [byte bx+1],3Ah ; ':'
1367 jne @@nodisk
1368 mov dl,20h
1369 or dl,[bx]
1370 sub dl,61h
1371 mov ah,0Eh
1372 int 21h
1373 inc bx
1374 inc bx
1375 @@nodisk:
1376 xor cx,cx
1377 @@next:
1378 mov al,[bx]
1379 cmp al,5Ch
1380 jne @@tsteos
1381 mov dx,bx
1382 inc cx
1383 @@tsteos:
1384 inc bx
1385 or al,al
1386 jnz @@next
1387 jcxz @@end
1388 mov bx,dx
1389 push [word bx]
1390 mov [bx],al
1391 ifdef LONG_FILENAME
1392 stc
1393 mov ax,713Bh ; chdir long filename (ds:dx)
1394 int 21h
1395 jnc @@chdirdone
1396 endif
1397 mov ah,3Bh ; chdir(ds:dx)
1398 int 21h
1399 @@chdirdone:
1400 pop [word bx]
1401 @@end:
1402 ret
1404 endp @chdirname$qpzc
1407 ;***************************************************************
1408 ;_fastcall char *ultoa(axdx:unsigned long n);
1409 ;***************************************************************
1410 global @ultoa$qul:near
1411 proc @ultoa$qul near
1413 xchg ax,cx
1414 xchg ax,dx ; AX:CX = n
1415 push si
1416 mov si,10
1417 mov bx,offset ultoabuf+11
1418 @@loop:
1419 dec bx
1420 xor dx,dx
1421 div si ; DX:AX = 0000:hi(n)
1422 xchg ax,cx ; CX = hi(n)/10
1423 div si ; DX:AX = hi(n)%10:lo(n)
1424 xchg ax,cx ; CX = lo(n/10)
1425 ; AX = hi(n)/10 = hi(n/10)
1426 mov [byte bx],'0'
1427 add [bx],dl ; DL = n%10
1428 mov dx,ax
1429 or dx,cx
1430 jnz @@loop
1431 xchg ax,bx
1432 pop si
1433 ret
1435 endp @ultoa$qul
1438 ;***************************************************************
1439 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1440 ;***************************************************************
1441 global @kver2ul$qpzc:near
1442 proc @kver2ul$qpzc near
1444 push si
1445 mov si,bx
1446 xor bx,bx
1447 mov cx,304h
1448 @@number:
1449 xor ax,ax
1450 cwd
1451 @@digit:
1452 shl al,cl
1453 shl ax,cl
1454 lodsb
1455 sub al,30h
1456 cmp al,9
1457 jbe @@digit
1458 mov dl,bh
1459 mov bh,bl
1460 mov bl,ah
1461 dec ch
1462 jnz @@number
1463 xchg ax,bx
1464 pop si
1465 kver2ulret:
1466 ret
1468 endp @kver2ul$qpzc
1470 endif
1472 ;***************************************************************
1473 ;void try_default_args();
1474 ;***************************************************************
1475 ifdef EXTRA
1477 global _try_default_args:near
1478 proc _try_default_args near
1480 mov bx,offset tazboot_cmd
1481 call open
1482 jc kver2ulret
1483 mov cx,4096
1484 mov di,[_heap_top]
1485 extrn read_cmdline:near
1486 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1488 endp _try_default_args
1490 endif
1492 ends _TEXT
1494 end
1496 ;###### END OF FILE ############################################