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

linld: fix open_image
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 01 16:48:25 2018 +0100 (2018-12-01)
parents c836f6d2eff8
children d3d2a15d3d0d
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(const char* a, const char* b);
52 ;_fastcall void strcat(const char* a, const char* b);
53 ;_fastcall void strcatb(const char* a, const char* b);
54 ;***************************************************************
55 global @strcatb$qpxzct1:near
56 proc @strcatb$qpxzct1 near
58 ifdef EXTRA
59 mov cl,7Fh
60 db 0bah ; mov dx,imm opcode
61 global @strcat$qpxzct1:near
62 @strcat$qpxzct1:
63 mov cl,80h
64 db 0bah ; mov dx,imm opcode
65 global @strcpy$qpxzct1:near
66 @strcpy$qpxzct1:
67 xor cx,cx
68 endif
69 push si
70 mov si,bx ; a
71 xchg ax,dx ; b
72 ifdef EXTRA
73 jcxz @@nocat
74 endif
75 @@catlp:
76 lodsb
77 or al,al
78 jne @@catlp
79 dec si
80 ifdef EXTRA
81 cmp dx,si
82 adc al,cl ; set S when dx != si or cl = 80
83 mov al,20h
84 jns @@cpyhead
85 endif
86 @@nocat:
87 @@cpylp:
88 mov al,[bx]
89 inc bx
90 @@cpyhead:
91 mov [si],al
92 inc si
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 char strstr(const char* a,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(const char* a,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,al
149 jnz @@lp
150 @@out:
151 cbw
152 pop si
153 ret
155 endp @strcmp$qpxzct1
156 endif
159 ;***************************************************************
160 ;_fastcall void puts(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
183 ;***************************************************************
184 ;_fastcall int fileattr(const char* name);
185 ;***************************************************************
186 global @fileattr$qpxzc:near
187 proc @fileattr$qpxzc near
189 mov ax,4300h
190 call dos_filename
191 xchg ax,cx
192 jmp chkc
194 endp @fileattr$qpxzc
197 ;***************************************************************
198 ;_fastcall int open(const char* name, int flags=O_RDONLY);
199 ;***************************************************************
200 global openargs:near ; openargs(bx)
201 openargs:
202 cmp [byte bx],'@'
203 stc
204 jne fail
205 inc bx
207 global @open$qpxzc:near
208 proc @open$qpxzc near
210 global open:near ; open(bx)
211 open:
212 mov ax,3d00h ; read-only+compatibility
213 ;mov cl,0 ; attribute mask
214 dos_filename:
215 mov dx,bx
216 dos:
217 int 21h
218 chkc:
219 jnc doret
220 fail:
221 sbb ax,ax ; ax=-1 CF
222 cwd
223 doret:
224 ifndef NO386
225 push dx ; see next_chunk:lseek
226 push ax
227 pop eax
228 endif
229 ret
231 endp @open$qpxzc
234 ;***************************************************************
235 ;_fastcall int close(int fd);
236 ;***************************************************************
237 global @close$qi:near
238 proc @close$qi near
240 global close:near ; close(ax)
241 close:
242 xchg ax,bx
243 mov ah,3Eh
244 or bx,bx
245 jnz dos
246 ret
248 endp @close$qi
251 ;***************************************************************
252 ;_fastcall int read(int fd, void* data, int sz);
253 ;_fastcall int write(int fd, const void* data, int sz);
254 ;***************************************************************
255 global @read$qipvi:near
256 proc @read$qipvi near
258 ifdef WRITE
259 stc
260 db 0B0h ; mov al,im
261 global @write$qipvi:near
262 @write$qipvi:
263 clc
264 endif
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 jmp dos
279 endp @read$qipvi
281 ;***************************************************************
282 ;_fastcall long lseekset(int fd, unsigned whence);
283 ;_fastcall long lseekcur(int fd, int whence);
284 ;***************************************************************
286 global @lseekcur$qii:near ; fd=ax whence=dx
287 proc @lseekcur$qii near
289 xchg ax,bx
290 xchg ax,dx
291 cwd
292 xchg ax,dx
293 xchg ax,cx
294 mov al,1
295 jmp lseek
296 ifdef EXTRA
297 global @lseekset$qiui:near
298 @lseekset$qiui:
299 mov bl,0
300 jmp lseek0x
301 lseekset:
302 mov bl,0
303 jmp lseekx
304 endif
305 rewind: ; rewind(ax)
306 mov bl,0
307 lseek0: ; lseek0(bx,ax=dir)
308 xor dx,dx
309 lseek0x:
310 xor cx,cx
311 lseekx:
312 xchg ax,bx
313 lseek:
314 mov ah,42h ; bx=fd cx:dx=offset al=whence
315 jmp dos
317 endp @lseekcur$qii
319 ifdef EXTRA
321 ;typedef unsigned dirsizetype;
322 struc isostate ; struct isostate {
323 fd dw ? ; 0 int fd;
324 filemod dw ? ; 2 unsigned short filemod;
325 fileofs dd ? ; 4 unsigned long fileofs;
326 filesize dd ? ; 8 unsigned long filesize;
327 filename dw ? ;12 char *filename;
328 curdirsize dw ? ;14 dirsizetype curdirsize;
329 dirsize dw ? ;16 dirsizetype dirsize;
330 curdirofs dd ? ;18 unsigned long curdirofs;
331 dirofs dd ? ;22 unsigned long dirofs;
332 curpos dw ? ;26 unsigned curpos;
333 buffer db 2560 dup(?) ;28 char buffer[2048+512];
334 ends ; } isostate;
335 ;***************************************************************
336 ;_fastcall long isolseek(const unsigned long *offset);
337 ;***************************************************************
338 global @isolseek$qpxul:near
339 proc @isolseek$qpxul near
341 isolseek:
342 mov dx,[bx]
343 mov cx,[bx+2]
344 extrn _isostate:isostate
345 mov ax,[_isostate.fd]
346 jmp lseekset
348 endp @isolseek$qpxul
350 ;***************************************************************
351 ;_fastcall int isoreadsector(const unsigned long *offset);
352 ;***************************************************************
353 global @isoreadsector$qpxul:near
354 proc @isoreadsector$qpxul near
356 call isolseek
357 and ax,dx
358 inc ax
359 jz @@fail
360 mov cx,2560
361 mov dx,offset _isostate.buffer
362 mov bx,[_isostate.fd]
363 call @read$cxdxbx ; read(fd,buffer,2560)
364 @@fail:
365 cmp ax,2048
366 sbb ax,ax
367 ret
369 endp @isoreadsector$qpxul
371 endif
374 ;***************************************************************
375 ;_fastcall int strhead(const char* a,const char* b);
376 ;***************************************************************
377 global @strhead$qpxzct1:near
378 proc @strhead$qpxzct1 near
380 @@loop:
381 xchg ax,bx
382 mov cl,[bx] ; cl = *b++
383 inc bx
384 or cl,cl ; clear C
385 jz fail ; return 0
386 xchg ax,bx
387 xor cl,[bx] ; cl -= *a++
388 inc bx
389 and cl,0dfh ; case insensitive
390 jz @@loop
391 ret ; return b (is not 0)
393 endp @strhead$qpxzct1
396 ;***************************************************************
397 ;_fastcall char* malloc_or_die(unsigned size);
398 ;***************************************************************
399 global @malloc_or_die$qui:near
400 proc @malloc_or_die$qui near
402 xchg ax,cx ; size
403 global malloc_or_die:near ; malloc_or_die(cx)
404 malloc_or_die:
405 mov ax,[_heap_top] ; return value
406 mov bx,sp
407 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
408 sub bx,ax ; can't overflow
409 cmp bx,cx
410 mov bx,offset msg_malloc
411 jb die
412 add [_heap_top],cx ; _BEG has zero'd heap
413 ret
415 endp @malloc_or_die$qui
418 ;***************************************************************
419 ;_fastcall int die(const char* msg);
420 ;int exit();
421 ;int abort();
422 ;***************************************************************
423 global @die$qpxzc:near
424 proc @die$qpxzc near
425 @die$qpxzc:
426 global die:near ; die(bx)
427 die:
428 call puts
429 ; global _exit:near
430 _exit:
431 mov al,[_no_exit]
432 or al,al
433 jne @@hang
434 extrn exit:near
435 inc ax
436 jmp near exit
437 @@hang:
438 mov bx, offset msg_hang
439 call puts
440 ; global _abort:near
441 _abort:
442 cli
443 @@stop:
444 hlt
445 jmp @@stop
447 endp @die$qpxzc
449 struc image_himem ;struct image_himem {
450 fd dw ? ; 0 int fd;
451 fallback dd ? ; 2 u32 fallback;
452 size dd ? ; 6 u32 size;
453 remaining dd ? ;10 u32 remaining;
454 buf dd ? ;14 u32 buf;
455 bufv dw ? ;18 u32 *bufv;
456 errmsg dw ? ;20 char *errmsg;
457 chunk_size dd ? ;22 u32 chunk_size;
458 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
459 state dw ? ;28 u16 state;
460 fd2close dw ? ;30 u16 fd2close;
461 ends ;};
463 ;***************************************************************
464 ;long next_chunk(struct image_himem *di);
465 ;***************************************************************
466 proc next_chunk near
468 push si
469 mov ax,[(image_himem di).fd]
470 call close
471 ifndef NO386
472 xor eax,eax
473 else
474 xor ax,ax
475 cwd
476 endif
477 mov [(image_himem di).fd],ax
478 mov bx,[(image_himem di).state]
479 cmp al,[bx] ; ""
480 jz @@end
481 mov si,bx
482 @@scan:
483 lodsb
484 mov cx,si
485 cmp al,','
486 jz @@eos
487 or al,al
488 jnz @@scan
489 dec cx
490 @@eos:
491 mov [(image_himem di).state],cx
492 dec si
493 push [word si]
494 mov [byte si],ah ; set temp eos
495 call open
496 pop [word si] ; restore string
497 jc @@die
498 mov [(image_himem di).fd],ax
499 mov [(image_himem di).fd2close],ax
500 mov bl,02h ; SEEK_END
501 call lseek0
502 @@die:
503 mov bx,[(image_himem di).errmsg]
504 jc die
505 ifndef NO386
506 push eax
507 mov ax,[(image_himem di).fd]
508 call rewind
509 pop eax
510 @@end:
511 mov [(image_himem di).chunk_size],eax
512 else
513 push ax
514 push dx
515 mov ax,[(image_himem di).fd]
516 call rewind
517 pop dx
518 pop ax
519 @@end:
520 mov [word (image_himem di).chunk_size],ax
521 mov [word ((image_himem di).chunk_size)+2],dx
522 endif
523 pop si
524 ret
526 endp next_chunk
529 ifdef LARGE_IMAGES
530 struc data_himem ;struct data_himem {
531 first dd ? ; 0 u32 first;
532 cacheidx dw ? ; 4 int cacheidx;
533 pageidx dw ? ; 6 int pageidx;
534 cache dd 1024 dup(?) ; 8 int cache;
535 page dd 1024 dup(?) ;4104 int page;
536 ends ;}; // size=8200
537 endif
539 ;***************************************************************
540 ;_fastcall u32* malloc_bufv_or_die(struct image_himem *m);
541 ;***************************************************************
542 global @malloc_bufv_or_die$qp11image_himem:near
543 proc @malloc_bufv_or_die$qp11image_himem near
545 p386
546 push si
547 mov si,bx
548 ifdef LARGE_IMAGES
549 movzx ecx,[word ((image_himem si).size) + 2]
550 shr cx,4 ; pages index size = size >> 20
551 add cx,8+4096+8
552 call malloc_or_die
553 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
554 add ecx,[(image_himem si).size]
555 shr ecx,12
556 mov [curdata],ax
557 else
558 mov ecx,[(image_himem si).size]
559 dec ecx
560 shr ecx,12
561 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
562 push cx
563 inc cx ; cnt+1
564 shl cx,2 ; bufv => vcpi => vm86
565 ; our malloc zeroes allocated mem: bufv[cnt]=0;
566 ; Allocate pages, storing addrs in addrbuf
567 call malloc_or_die
568 pop cx
569 push ax
570 endif
571 mov [(image_himem si).bufv],ax
572 xchg ax,si
573 @@vcpi_alloc:
574 xor edx,edx
575 mov ax,0DE04h
576 int 67h
577 or ah,ah
578 mov bx,offset vcpi_alloc_err
579 jnz die
580 ; for (i = cnt-1; i >= 0; i--)
581 ifdef LARGE_IMAGES
582 mov eax,ecx
583 dec eax
584 else
585 mov ax,cx
586 dec ax
587 cwde
588 endif
589 shl eax,12 ; i*_4k
590 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
591 extrn _imgs
592 mov bx,offset _imgs+2
593 push eax
594 add eax,[bx-2+2]
595 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
596 pop eax ; i*_4k
597 jbe @@pmok
598 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
599 jae @@vcpi_alloc
600 @@pmok:
601 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
602 extrn _imgs
603 mov bx,offset _imgs+32+2
604 add eax,[bx-2+2] ; +initrd.fallback
605 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
606 ja @@initrdok
607 mov eax,[bx-2+6] ; initrd.size
608 add eax,[bx-2+2] ; +initrd.fallback
609 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
610 @@jnc_vcpi_alloc:
611 ja @@vcpi_alloc
612 @@initrdok:
613 ifdef LARGE_IMAGES
614 cmp [(data_himem si).first],0
615 jne @@notfirst
616 mov [(data_himem si).first],edx
617 @@notfirst:
618 mov bx,[(data_himem si).cacheidx]
619 cmp bh,4
620 jae @@nextpage
621 shl bx,2
622 inc [(data_himem si).cacheidx]
623 mov [(data_himem bx+si).cache],edx
624 loopd @@vcpi_alloc
625 mov [(data_himem bx+si).cache],ecx ; last is 0
626 @@nextpage:
627 and [(data_himem si).cacheidx],0
628 mov bx,[(data_himem si).pageidx]
629 mov [(data_himem bx+si).page],edx
630 add [(data_himem si).pageidx],4
631 push cx
632 lea cx,[(data_himem si).cache]
633 ifdef NO386
634 push edx
635 pop dx
636 pop ax
637 endif
638 call storepage ; storepage(edx,cx)
639 pop cx
640 or ecx,ecx ; clear C
641 jnz @@jnc_vcpi_alloc
642 mov [dword (data_himem si).cacheidx],ecx
643 xchg ax,si
644 else
645 mov [si],edx
646 lodsd ; si=+4
647 loop @@vcpi_alloc
648 pop ax
649 endif
650 pop si
651 ret
652 ifdef NO386
653 p8086
654 endif
656 endp @malloc_bufv_or_die$qp11image_himem
659 ;***************************************************************
660 ;_fastcall void memcpy_image(struct image_himem *m);
661 ;***************************************************************
662 global @memcpy_image$qp11image_himem:near
663 proc @memcpy_image$qp11image_himem near
665 ifndef NO386
666 mov edx,[(image_himem bx).fallback]
667 mov eax,[(image_himem bx).buf]
668 cmp eax,edx ; if (m->fallback != m->buf)
669 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
670 ifdef LARGE_IMAGES
671 mov ecx,[(image_himem bx).size]
672 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
673 push ecx
674 else
675 push [(image_himem bx).size]
676 endif
677 push eax
678 push 0
679 call_memcpy32:
680 push edx
681 else
682 mov ax,[word ((image_himem bx).fallback)]
683 mov dx,[word ((image_himem bx).fallback)+2]
684 mov cx,[word ((image_himem bx).buf)]
685 cmp ax,cx ; if (m->fallback != m->buf)
686 jnz @@do
687 cmp dx,[word ((image_himem bx).buf)+2]
688 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
689 @@do:
690 push [word ((image_himem bx).size)+2]
691 push [word ((image_himem bx).size)]
692 push [word ((image_himem bx).buf)+2]
693 push cx
694 xor cx,cx
695 push cx
696 call_memcpy32:
697 push dx
698 push ax
699 ifdef LARGE_IMAGES
700 jmp @@memcpy
701 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
702 p386
703 push ecx
704 push eax
705 push 0
706 push edx
707 ifdef NO386
708 p8086
709 endif
710 endif
711 endif
712 @@memcpy:
713 extrn memcpy32:near
714 call near memcpy32
715 @@skip:
716 ret
718 endp @memcpy_image$qp11image_himem
720 ;***************************************************************
721 ;_fastcall void storepage(u32 *dst);
722 ;***************************************************************
723 global @storepage$qpul:near
724 proc @storepage$qpul near
726 ifndef NO386
727 mov edx,[bx]
728 else
729 mov ax,[bx]
730 mov dx,[bx+2]
731 endif
732 mov cx,offset _xfer_buf
733 storepage: ; storepage(edx,cx)
734 ifndef NO386
735 push 0
736 push 4096
737 push 0
738 else
739 xor bx,bx
740 push bx
741 mov bh,4096/256
742 push bx
743 xor bx,bx
744 push bx
745 endif
746 push cx
747 push ds
748 jmp call_memcpy32
750 endp @storepage$qpul
753 ifdef LARGE_IMAGES
754 p386
755 ;***************************************************************
756 ;_fastcall void reset_bufv(u32 *p);
757 ;***************************************************************
758 global @reset_bufv$qpul:near
759 proc @reset_bufv$qpul near
761 mov [curdata],bx
762 and [dword (data_himem bx).cacheidx],0
763 ret
765 endp @reset_bufv$qpul
767 ;***************************************************************
768 ;u32* prev_bufv();
769 ;u32* prev_bufv();
770 ;***************************************************************
771 global _prev_bufv:near
772 global _next_bufv:near
773 proc _prev_bufv near
775 stc
776 db 73h ; jnc
777 _next_bufv:
778 clc
779 push si
780 mov si,[curdata]
781 sbb ax,ax
782 cmc
783 adc ax,[(data_himem si).cacheidx] ; -1/+1
784 xor ecx,ecx
785 test ax,0fc00h
786 jz @@gotpage
787 push ax ; FFFF / 0400
788 sar ax,8 ; FFFC / 0004
789 and al,0fch
790 add [(data_himem si).pageidx],ax
791 mov bx,[(data_himem si).pageidx]
792 lea bx,[(data_himem bx+si).page]
793 mov edx,ds
794 shl edx,4
795 lea cx,[(data_himem si).cache]
796 add edx,ecx
797 mov eax,[bx]
798 or eax,eax
799 jnz @@pageok
800 pop ax
801 xchg ax,bx
802 pop si
803 ret
804 @@pageok:
805 mov cx,4096
806 call memcpy_imagez ; get page
807 pop ax ; FFFF / 0400
808 cbw
809 shr ax,6 ; 03FF / 0000
810 @@gotpage:
811 mov [(data_himem si).cacheidx],ax
812 shl ax,2
813 xchg ax,bx
814 lea ax,[(data_himem bx+si).cache]
815 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
816 jnz @@notfirst2
817 xchg ax,si ; &first
818 @@notfirst2:
819 pop si
820 ret
822 endp _prev_bufv
823 endif
825 ifdef NO386
826 p8086
827 endif
829 ;***************************************************************
830 ;_fastcall void open_image(const char *name, struct image_himem *m);
831 ;***************************************************************
832 global @open_image$qpxzcp11image_himem:near
833 proc @open_image$qpxzcp11image_himem near
835 push di
836 xchg ax,di
837 ifdef EXTRA
838 cmp [(image_himem di).fd],0 ; iso image/kernel ?
839 jnz @@alreadydone
840 endif
841 mov [(image_himem di).state],bx
842 push bx
843 ifdef EXTRA
844 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
845 jnz @@next
846 endif
847 mov [(image_himem di).next_chunk],offset next_chunk
848 @@next:
849 call [(image_himem di).next_chunk] ; m->next_chunk()
850 ifndef NO386
851 add eax,3
852 and al,0FCh
853 add [(image_himem di).size],eax ; m->size += m->chunk_size
854 or eax,eax
855 else
856 add ax,3
857 adc dx,0
858 and al,0FCh
859 add [word (image_himem di).size],ax ; m->size += m->chunk_size
860 adc [word ((image_himem di).size)+2],dx
861 or ax,dx
862 endif
863 jnz @@next
864 pop [(image_himem di).state]
865 call [(image_himem di).next_chunk] ; m->next_chunk()
866 @@alreadydone:
867 pop di
868 ret
870 endp @open_image$qpxzcp11image_himem
873 ;***************************************************************
874 ;_fastcall int read_image(struct image_himem *m);
875 ;***************************************************************
876 global @read_image$qp11image_himem:near
877 proc @read_image$qp11image_himem near
879 push si di
880 mov di,bx
881 mov si,4096
882 push si ; original size
883 @@loop:
884 ifndef NO386
885 movzx ecx,si
886 mov eax,[(image_himem di).chunk_size]
887 cmp ecx,eax
888 jb @@szok
889 else
890 mov cx,si
891 mov ax,[word (image_himem di).chunk_size]
892 cmp cx,ax
893 jb @@szok
894 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
895 jne @@szok
896 endif
897 xchg ax,cx
898 @@szok:
899 jcxz image_done
900 mov dx,offset _xfer_buf
901 mov bx,[di]
902 call @read$cxdxbx
903 jc image_done
904 xor cx,cx
905 cwd ; ax < 8000h
906 ifndef NO386
907 cwde ; ax < 8000h
908 sub [(image_himem di).chunk_size],eax
909 xchg eax,ebx
910 else
911 sub [word (image_himem di).chunk_size],ax
912 xchg ax,bx
913 sbb [word ((image_himem di).chunk_size)+2],dx
914 jnz @@fill
915 cmp [word (image_himem di).chunk_size],dx
916 endif
917 jnz @@fill
918 dec cx
919 @@fill:
920 test bl,3
921 je @@filled
922 mov [bx+_xfer_buf],dh
923 inc bx
924 jmp @@fill
925 @@filled:
926 ifndef NO386
927 sub [(image_himem di).remaining],ebx
928 else
929 sub [word (image_himem di).remaining],bx
930 sbb [word ((image_himem di).remaining)+2],dx
931 endif
932 sub si,bx
933 pushf
934 and cx,[(image_himem di).next_chunk]
935 jcxz @@same_chunk
936 call cx
937 @@same_chunk:
938 popf
939 jnz @@loop
940 image_done:
941 pop ax ; original size
942 sub ax,si
943 pop di si
944 ret
946 endp @read_image$qp11image_himem
949 ;***************************************************************
950 ;pascal unsigned long strtol(const char *s);
951 ;***************************************************************
952 global @strtol$qpxzc:near
953 proc @strtol$qpxzc near
955 pop ax
956 pop bx ; s
957 push ax
958 ifndef NO386
959 xor ebx,ebx
960 push si
961 jcxz @@end
962 mov si,cx
963 xor ecx,ecx
964 xor eax,eax
965 lodsb
966 mov dx,ax
967 or al,20h
968 cmp al,'n' ; vga=normal
969 je @@vga
970 dec cx
971 cmp al,'e' ; vga=extended
972 je @@vga
973 dec cx
974 cmp al,'a' ; vga=ask
975 jne @@notvga
976 @@vga:
977 dec cx
978 xchg ax,cx
979 cwd
980 jmp @@popsiret
981 @@notvga:
982 mov cx,10 ; radix
983 xchg ax,dx
984 cmp al,'+'
985 je @@radixskip
986 cmp al,'-'
987 clc
988 jne @@radixkeep
989 stc
990 @@radixskip:
991 lodsb
992 @@radixkeep:
993 pushf
994 cmp al,'0'
995 jne @@radixok
996 mov cl,8
997 lodsb
998 or al,20h
999 cmp al,'x'
1000 jne @@radixok
1001 mov cl,16
1002 @@strtollp:
1003 lodsb
1004 @@radixok:
1005 or al,20h
1006 sub al,'0'
1007 jb @@endstrtol
1008 cmp al,9
1009 jbe @@digitok
1010 cmp al,'a'-'0'
1011 jb @@endstrtol
1012 sub al,'a'-'0'-10
1013 @@digitok:
1014 cmp al,cl
1015 jae @@endstrtol
1016 xchg eax,ebx
1017 mul ecx
1018 add eax,ebx
1019 xchg eax,ebx
1020 jmp @@strtollp
1021 @@endstrtol:
1022 mov cl,10
1023 cmp al,'k'-'a'+10
1024 je @@shift
1025 mov cl,20
1026 cmp al,'m'-'a'+10
1027 je @@shift
1028 mov cl,30
1029 cmp al,'g'-'a'+10
1030 jne @@noshift
1031 @@shift:
1032 shl ebx,cl
1033 @@noshift:
1034 popf
1035 jnc @@end
1036 neg ebx
1037 @@end:
1038 push ebx
1039 pop ax
1040 pop dx
1041 @@popsiret:
1042 pop si
1043 else
1044 push si
1045 push di
1046 xor ax,ax
1047 cwd
1048 jcxz @@goend
1049 xchg ax,di
1050 mov si,cx
1051 lodsb
1052 mov bx,ax
1053 or al,20h
1054 mov cx,-1
1055 cmp al,'n' ; vga=normal
1056 je @@vga
1057 dec cx
1058 cmp al,'e' ; vga=extended
1059 je @@vga
1060 dec cx
1061 cmp al,'a' ; vga=ask
1062 jne @@notvga
1063 @@vga:
1064 xchg ax,cx
1065 @@goend:
1066 jmp @@popdisiret
1067 @@notvga:
1068 mov cx,10 ; radix
1069 xchg ax,bx
1070 cmp al,'+'
1071 je @@radixskip
1072 cmp al,'-'
1073 clc
1074 jne @@radixkeep
1075 stc
1076 @@radixskip:
1077 lodsb
1078 @@radixkeep:
1079 pushf
1080 cmp al,'0'
1081 jne @@radixok
1082 mov cl,8
1083 lodsb
1084 or al,20h
1085 cmp al,'x'
1086 jne @@radixok
1087 mov cl,16
1088 @@strtollp:
1089 lodsb
1090 @@radixok:
1091 or al,20h
1092 sub al,'0'
1093 jb @@endstrtol
1094 cmp al,9
1095 jbe @@digitok
1096 cmp al,'a'-'0'
1097 jb @@endstrtol
1098 sub al,'a'-'0'-10
1099 @@digitok:
1100 cmp al,cl
1101 jae @@endstrtol
1103 push ax
1104 push si
1105 push dx
1106 xchg ax,di
1107 mul cx
1108 xchg ax,di
1109 xchg ax,dx
1110 xchg ax,si
1111 pop ax
1112 mul cx
1113 add ax,si
1114 pop si
1115 xchg ax,dx
1116 pop ax
1117 mov ah,0
1118 add di,ax
1119 adc dx,0
1121 jmp @@strtollp
1122 @@endstrtol:
1123 mov cl,10
1124 cmp al,'k'-'a'+10
1125 je @@shift
1126 mov cl,20
1127 cmp al,'m'-'a'+10
1128 je @@shift
1129 mov cl,30
1130 cmp al,'g'-'a'+10
1131 jne @@noshift
1132 @@shift:
1133 rcl di,1
1134 shl dx,1
1135 loop @@shift
1136 @@noshift:
1137 popf
1138 jnc @@end
1139 not dx
1140 neg di
1141 jne @@end
1142 inc dx
1143 @@end:
1144 xchg ax,di
1145 @@popdisiret:
1146 pop di
1147 pop si
1148 endif
1149 strtol_ret:
1150 ret
1152 endp @strtol$qpxzc
1155 ifdef NO386
1156 ;***************************************************************
1157 ;u16 topseg();
1158 ;***************************************************************
1159 global _topseg:near
1160 proc _topseg near
1162 int 12h
1163 jnc @@max640k
1164 mov ax,640 ; 9000
1165 @@max640k:
1166 dec ax
1167 and al,0C0h
1168 mov cl,6
1169 shl ax,cl
1170 ret
1172 endp _topseg
1173 endif
1175 ifdef EXTRA
1176 p8086
1177 ;***************************************************************
1178 ;char *progname(void)
1179 ;***************************************************************
1180 global _progname:near
1181 proc _progname near
1183 push si di es
1184 mov ah,30h
1185 int 21h
1186 xor di,di
1187 cmp al,3
1188 mov ax,di
1189 jb @@skip
1190 ;mov es,[cs:2Ch]
1191 mov es,[di+2Ch]
1192 mov cx,sp ; big enough
1193 @@loop:
1194 repne
1195 scasb
1196 scasb
1197 jne @@loop
1198 inc di
1199 inc di
1200 mov si,di ; progname @es:di
1201 repne
1202 scasb
1203 mov cx,di
1204 sub cx,si ; progname len
1205 call malloc_or_die ; keep cx
1206 mov di,ax
1207 push ds
1208 push es
1209 pop ds
1210 pop es
1211 rep
1212 movsb
1213 push es
1214 pop ds
1215 @@skip:
1216 pop es di si
1217 ret
1219 endp _progname
1222 ;***************************************************************
1223 ;_fastcall void chdirname(char *path)
1224 ;***************************************************************
1225 global @chdirname$qpzc:near
1226 proc @chdirname$qpzc near
1228 cmp [byte bx+1],3Ah ; ':'
1229 jne @@nodisk
1230 mov dl,20h
1231 or dl,[bx]
1232 sub dl,61h
1233 mov ah,0Eh
1234 int 21h
1235 inc bx
1236 inc bx
1237 @@nodisk:
1238 xor cx,cx
1239 @@next:
1240 mov al,[bx]
1241 cmp al,5Ch
1242 jne @@tsteos
1243 mov dx,bx
1244 inc cx
1245 @@tsteos:
1246 inc bx
1247 or al,al
1248 jnz @@next
1249 jcxz @@end
1250 mov bx,dx
1251 push [word bx]
1252 mov [bx],al
1253 stc
1254 mov ax,713Bh ; chdir long filename (ds:dx)
1255 int 21h
1256 mov ah,3Bh ; chdir(ds:dx)
1257 jnc @@chdirdone
1258 int 21h
1259 @@chdirdone:
1260 pop [word bx]
1261 @@end:
1262 ret
1264 endp @chdirname$qpzc
1267 ;***************************************************************
1268 ;_fastcall char *ultoa(unsigned long n);
1269 ;***************************************************************
1270 global @ultoa$qul:near
1271 proc @ultoa$qul near
1273 xchg ax,cx
1274 xchg ax,dx ; AX:CX = n
1275 push si
1276 mov si,10
1277 mov bx,offset ultoabuf+11
1278 @@loop:
1279 dec bx
1280 xor dx,dx
1281 div si ; DX:AX = 0000:hi(n)
1282 xchg ax,cx ; CX = hi(n)/10
1283 div si ; DX:AX = hi(n)%10:lo(n)
1284 xchg ax,cx ; CX = lo(n/10)
1285 ; AX = hi(n)/10 = hi(n/10)
1286 mov [byte bx],'0'
1287 add [bx],dl ; DL = n%10
1288 mov dx,ax
1289 or dx,cx
1290 jnz @@loop
1291 xchg ax,bx
1292 pop si
1293 ret
1295 endp @ultoa$qul
1298 ;***************************************************************
1299 ;_fastcall unsigned long kver2ul(char *kernel_version);
1300 ;***************************************************************
1301 global @kver2ul$qpzc:near
1302 proc @kver2ul$qpzc near
1304 push si
1305 mov si,bx
1306 xor bx,bx
1307 mov cx,304h
1308 @@number:
1309 xor ax,ax
1310 cwd
1311 @@digit:
1312 shl al,cl
1313 shl ax,cl
1314 lodsb
1315 sub al,30h
1316 cmp al,9
1317 jbe @@digit
1318 mov dl,bh
1319 mov bh,bl
1320 mov bl,ah
1321 dec ch
1322 jnz @@number
1323 xchg ax,bx
1324 pop si
1325 kver2ulret:
1326 ret
1328 endp @kver2ul$qpzc
1330 endif
1332 ;***************************************************************
1333 ;void try_default_args();
1334 ;_fastcall void set_cmdline(const char *filename);
1335 ;***************************************************************
1336 ifdef EXTRA
1338 global _try_default_args:near
1339 proc _try_default_args near
1341 mov bx,offset tazboot_cmd
1342 call open
1343 jc kver2ulret
1344 mov cx,4096
1345 mov di,[_heap_top]
1346 extrn read_cmdline:near
1347 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1349 endp _try_default_args
1351 endif
1353 ends _TEXT
1355 end
1357 ;###### END OF FILE ############################################