wok view linld/stuff/src/CRTL.ASM @ rev 21712
get-LibreOffice: fix menu entries
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jun 09 10:58:25 2019 +0200 (2019-06-09) |
parents | 93f070d4d2d7 |
children | 6460d542c35a |
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 push di
956 call [(image_himem di).next_chunk] ; m->next_chunk()
957 pop di
958 else
959 @@next:
960 call next_chunk
961 endif
962 ifndef NO386
963 add eax,3
964 and al,0FCh
965 add [(image_himem di).size],eax ; m->size += m->chunk_size
966 or eax,eax
967 else
968 add ax,3
969 adc dx,0
970 and al,0FCh
971 add [word (image_himem di).size],ax ; m->size += m->chunk_size
972 adc [word ((image_himem di).size)+2],dx
973 or ax,dx
974 endif
975 jnz @@next
976 pop [(image_himem di).state]
977 ifdef EXTRA
978 push di
979 call [(image_himem di).next_chunk] ; m->next_chunk()
980 pop di
981 else
982 call next_chunk
983 endif
984 @@alreadydone:
985 pop di
986 ret
988 endp @open_image$qp11image_himempxzc
991 ;***************************************************************
992 ;_fastcall int read_image(bx:struct image_himem *m);
993 ;***************************************************************
994 global @read_image$qp11image_himem:near
995 proc @read_image$qp11image_himem near
997 push si di
998 mov di,bx
999 mov si,4096
1000 push si ; original size
1001 @@loop:
1002 ifndef NO386
1003 movzx ecx,si
1004 mov eax,[(image_himem di).chunk_size]
1005 cmp ecx,eax
1006 jb @@szok
1007 else
1008 mov cx,si
1009 mov ax,[word (image_himem di).chunk_size]
1010 cmp cx,ax
1011 jb @@szok
1012 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
1013 jne @@szok
1014 endif
1015 xchg ax,cx
1016 @@szok:
1017 jcxz image_done
1018 mov dx,offset _xfer_buf+4096
1019 sub dx,si
1020 mov bx,[di]
1021 call @read$cxdxbx
1022 jc image_done
1023 xor cx,cx
1024 cwd ; ax < 8000h
1025 ifndef NO386
1026 cwde ; ax < 8000h
1027 sub [(image_himem di).chunk_size],eax
1028 xchg eax,ebx
1029 else
1030 sub [word (image_himem di).chunk_size],ax
1031 xchg ax,bx
1032 sbb [word ((image_himem di).chunk_size)+2],dx
1033 jnz @@fill
1034 cmp [word (image_himem di).chunk_size],dx
1035 endif
1036 jnz @@fill
1037 dec cx
1038 @@fill:
1039 test bl,3
1040 je @@filled
1041 mov [bx+_xfer_buf],dh
1042 inc bx
1043 jmp @@fill
1044 @@filled:
1045 ifndef NO386
1046 sub [(image_himem di).remaining],ebx
1047 else
1048 sub [word (image_himem di).remaining],bx
1049 sbb [word ((image_himem di).remaining)+2],dx
1050 endif
1051 sub si,bx
1052 pushf
1053 ifdef EXTRA
1054 and cx,[(image_himem di).next_chunk]
1055 jcxz @@same_chunk
1056 push di
1057 call cx
1058 pop cx
1059 else
1060 jcxz @@same_chunk
1061 call next_chunk
1062 endif
1063 @@same_chunk:
1064 popf
1065 jnz @@loop
1066 image_done:
1067 pop ax ; original size
1068 sub ax,si
1069 pop di si
1070 ret
1072 endp @read_image$qp11image_himem
1075 ;***************************************************************
1076 ;_fastcall unsigned long strtol(const char *s);
1077 ;***************************************************************
1078 global @strtol$qpxzc:near
1079 proc @strtol$qpxzc near
1081 ifndef NO386
1082 push si
1083 mov si,bx
1084 xor ecx,ecx
1085 xor eax,eax
1086 xor ebx,ebx
1087 or si,si
1088 jz @@end
1089 lodsb
1090 mov dx,ax
1091 or al,20h
1092 cmp al,'n' ; vga=normal
1093 je @@vga
1094 dec cx
1095 cmp al,'e' ; vga=extended
1096 je @@vga
1097 dec cx
1098 cmp al,'a' ; vga=ask
1099 jne @@notvga
1100 @@vga:
1101 dec cx
1102 xchg ax,cx
1103 cwd
1104 jmp @@popsiret
1105 @@notvga:
1106 mov cx,10 ; radix
1107 xchg ax,dx
1108 cmp al,'+'
1109 je @@radixskip
1110 cmp al,'-'
1111 clc
1112 jne @@radixkeep
1113 stc
1114 @@radixskip:
1115 lodsb
1116 @@radixkeep:
1117 pushf
1118 cmp al,'0'
1119 jne @@radixok
1120 mov cl,8
1121 lodsb
1122 or al,20h
1123 cmp al,'x'
1124 jne @@radixok
1125 mov cl,16
1126 @@strtollp:
1127 lodsb
1128 @@radixok:
1129 or al,20h
1130 sub al,'0'
1131 jb @@endstrtol
1132 cmp al,9
1133 jbe @@digitok
1134 cmp al,'a'-'0'
1135 jb @@endstrtol
1136 sub al,'a'-'0'-10
1137 @@digitok:
1138 cmp al,cl
1139 jae @@endstrtol
1140 xchg eax,ebx
1141 mul ecx
1142 add eax,ebx
1143 xchg eax,ebx
1144 jmp @@strtollp
1145 @@endstrtol:
1146 mov cl,10
1147 cmp al,'k'-'a'+10
1148 je @@shift
1149 mov cl,20
1150 cmp al,'m'-'a'+10
1151 je @@shift
1152 mov cl,30
1153 cmp al,'g'-'a'+10
1154 jne @@noshift
1155 @@shift:
1156 shl ebx,cl
1157 @@noshift:
1158 popf
1159 jnc @@end
1160 neg ebx
1161 @@end:
1162 push ebx
1163 pop ax
1164 pop dx
1165 @@popsiret:
1166 pop si
1167 else
1168 push si
1169 push di
1170 xor ax,ax
1171 cwd
1172 or bx,bx
1173 jz @@goend
1174 xchg ax,di
1175 mov si,bx
1176 lodsb
1177 mov bx,ax
1178 or al,20h
1179 mov cx,-1
1180 cmp al,'n' ; vga=normal
1181 je @@vga
1182 dec cx
1183 cmp al,'e' ; vga=extended
1184 je @@vga
1185 dec cx
1186 cmp al,'a' ; vga=ask
1187 jne @@notvga
1188 @@vga:
1189 xchg ax,cx
1190 @@goend:
1191 jmp @@popdisiret
1192 @@notvga:
1193 mov cx,10 ; radix
1194 xchg ax,bx
1195 cmp al,'+'
1196 je @@radixskip
1197 cmp al,'-'
1198 clc
1199 jne @@radixkeep
1200 stc
1201 @@radixskip:
1202 lodsb
1203 @@radixkeep:
1204 pushf
1205 cmp al,'0'
1206 jne @@radixok
1207 mov cl,8
1208 lodsb
1209 or al,20h
1210 cmp al,'x'
1211 jne @@radixok
1212 mov cl,16
1213 @@strtollp:
1214 lodsb
1215 @@radixok:
1216 or al,20h
1217 sub al,'0'
1218 jb @@endstrtol
1219 cmp al,9
1220 jbe @@digitok
1221 cmp al,'a'-'0'
1222 jb @@endstrtol
1223 sub al,'a'-'0'-10
1224 @@digitok:
1225 cmp al,cl
1226 jae @@endstrtol
1228 push ax
1229 push si
1230 push dx
1231 xchg ax,di
1232 mul cx
1233 xchg ax,di
1234 xchg ax,dx
1235 xchg ax,si
1236 pop ax
1237 mul cx
1238 add ax,si
1239 pop si
1240 xchg ax,dx
1241 pop ax
1242 mov ah,0
1243 add di,ax
1244 adc dx,0
1246 jmp @@strtollp
1247 @@endstrtol:
1248 mov cl,10
1249 cmp al,'k'-'a'+10
1250 je @@shift
1251 mov cl,20
1252 cmp al,'m'-'a'+10
1253 je @@shift
1254 mov cl,30
1255 cmp al,'g'-'a'+10
1256 jne @@noshift
1257 @@shift:
1258 rcl di,1
1259 shl dx,1
1260 loop @@shift
1261 @@noshift:
1262 popf
1263 jnc @@end
1264 not dx
1265 neg di
1266 jne @@end
1267 inc dx
1268 @@end:
1269 xchg ax,di
1270 @@popdisiret:
1271 pop di
1272 pop si
1273 endif
1274 strtol_ret:
1275 ret
1277 endp @strtol$qpxzc
1280 ifdef USE_ARGSTR
1281 ;***************************************************************
1282 ;_fastcall void set_cmdline(bx:const char *filename);
1283 ;***************************************************************
1284 global @set_cmdline$qpxzc:near
1285 proc @set_cmdline$qpxzc near
1286 call openargs
1287 jc strtol_ret
1288 mov cx,4096
1289 mov di,[_heap_top]
1290 extrn read_cmdline:near
1291 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1293 endp @set_cmdline$qpxzc
1294 endif
1297 ifdef NO386
1298 ;***************************************************************
1299 ;u16 topseg();
1300 ;***************************************************************
1301 global _topseg:near
1302 proc _topseg near
1304 int 12h
1305 jnc @@max640k
1306 mov ax,640 ; 9000
1307 @@max640k:
1308 dec ax
1309 and al,0C0h
1310 mov cl,6
1311 shl ax,cl
1312 ret
1314 endp _topseg
1315 endif
1317 ifdef EXTRA
1318 p8086
1319 ;***************************************************************
1320 ;char *progname(void)
1321 ;***************************************************************
1322 global _progname:near
1323 proc _progname near
1325 push si di es
1326 mov ah,30h
1327 int 21h
1328 xor di,di
1329 cmp al,3
1330 mov ax,di
1331 jb @@skip
1332 ;mov es,[cs:2Ch]
1333 mov es,[di+2Ch]
1334 mov cx,sp ; big enough
1335 @@loop:
1336 repne
1337 scasb
1338 scasb
1339 jne @@loop
1340 inc di
1341 inc di
1342 mov si,di ; progname @es:di
1343 repne
1344 scasb
1345 mov cx,di
1346 sub cx,si ; progname len
1347 call malloc_or_die ; keep cx
1348 mov di,ax
1349 push ds
1350 push es
1351 pop ds
1352 pop es
1353 rep
1354 movsb
1355 push es
1356 pop ds
1357 @@skip:
1358 pop es di si
1359 ret
1361 endp _progname
1364 ;***************************************************************
1365 ;_fastcall void chdirname(bx:char *path)
1366 ;***************************************************************
1367 global @chdirname$qpzc:near
1368 proc @chdirname$qpzc near
1370 cmp [byte bx+1],3Ah ; ':'
1371 jne @@nodisk
1372 mov dl,20h
1373 or dl,[bx]
1374 sub dl,61h
1375 mov ah,0Eh
1376 int 21h
1377 inc bx
1378 inc bx
1379 @@nodisk:
1380 xor cx,cx
1381 @@next:
1382 mov al,[bx]
1383 cmp al,5Ch
1384 jne @@tsteos
1385 mov dx,bx
1386 inc cx
1387 @@tsteos:
1388 inc bx
1389 or al,al
1390 jnz @@next
1391 jcxz @@end
1392 mov bx,dx
1393 push [word bx]
1394 mov [bx],al
1395 ifdef LONG_FILENAME
1396 stc
1397 mov ax,713Bh ; chdir long filename (ds:dx)
1398 int 21h
1399 jnc @@chdirdone
1400 endif
1401 mov ah,3Bh ; chdir(ds:dx)
1402 int 21h
1403 @@chdirdone:
1404 pop [word bx]
1405 @@end:
1406 ret
1408 endp @chdirname$qpzc
1411 ;***************************************************************
1412 ;_fastcall char *ultoa(axdx:unsigned long n);
1413 ;***************************************************************
1414 global @ultoa$qul:near
1415 proc @ultoa$qul near
1417 xchg ax,cx
1418 xchg ax,dx ; AX:CX = n
1419 push si
1420 mov si,10
1421 mov bx,offset ultoabuf+11
1422 @@loop:
1423 dec bx
1424 xor dx,dx
1425 div si ; DX:AX = 0000:hi(n)
1426 xchg ax,cx ; CX = hi(n)/10
1427 div si ; DX:AX = hi(n)%10:lo(n)
1428 xchg ax,cx ; CX = lo(n/10)
1429 ; AX = hi(n)/10 = hi(n/10)
1430 mov [byte bx],'0'
1431 add [bx],dl ; DL = n%10
1432 mov dx,ax
1433 or dx,cx
1434 jnz @@loop
1435 xchg ax,bx
1436 pop si
1437 ret
1439 endp @ultoa$qul
1442 ;***************************************************************
1443 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1444 ;***************************************************************
1445 global @kver2ul$qpzc:near
1446 proc @kver2ul$qpzc near
1448 push si
1449 mov si,bx
1450 xor bx,bx
1451 mov cx,304h
1452 @@number:
1453 xor ax,ax
1454 cwd
1455 @@digit:
1456 shl al,cl
1457 shl ax,cl
1458 lodsb
1459 sub al,30h
1460 cmp al,9
1461 jbe @@digit
1462 mov dl,bh
1463 mov bh,bl
1464 mov bl,ah
1465 dec ch
1466 jnz @@number
1467 xchg ax,bx
1468 pop si
1469 kver2ulret:
1470 ret
1472 endp @kver2ul$qpzc
1474 endif
1476 ;***************************************************************
1477 ;void try_default_args();
1478 ;***************************************************************
1479 ifdef EXTRA
1481 global _try_default_args:near
1482 proc _try_default_args near
1484 mov bx,offset tazboot_cmd
1485 call open
1486 jc kver2ulret
1487 mov cx,4096
1488 mov di,[_heap_top]
1489 extrn read_cmdline:near
1490 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1492 endp _try_default_args
1494 endif
1496 ends _TEXT
1498 end
1500 ;###### END OF FILE ############################################