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