wok-current view linld/stuff/src/CRTL.ASM @ rev 20542

linld: relative lseek for load.cpp
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 30 15:12:24 2018 +0100 (2018-11-30)
parents 25e3f390625a
children cb4579b9835b
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 sz);
283 ;_fastcall long lseekcur(int fd, int while);
284 ;***************************************************************
286 global @lseekcur$qii:near
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
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 bx,[_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 mov bx,[(image_himem di).fd]
506 ifndef NO386
507 push eax
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 call rewind
516 pop dx
517 pop ax
518 @@end:
519 mov [word (image_himem di).chunk_size],ax
520 mov [word ((image_himem di).chunk_size)+2],dx
521 endif
522 pop si
523 ret
525 endp next_chunk
528 ifdef LARGE_IMAGES
529 struc data_himem ;struct data_himem {
530 first dd ? ; 0 u32 first;
531 cacheidx dw ? ; 4 int cacheidx;
532 pageidx dw ? ; 6 int pageidx;
533 cache dd 1024 dup(?) ; 8 int cache;
534 page dd 1024 dup(?) ;4104 int page;
535 ends ;}; // size=8200
536 endif
538 ;***************************************************************
539 ;_fastcall u32* malloc_bufv_or_die(struct image_himem *m);
540 ;***************************************************************
541 global @malloc_bufv_or_die$qp11image_himem:near
542 proc @malloc_bufv_or_die$qp11image_himem near
544 p386
545 push si
546 mov si,bx
547 ifdef LARGE_IMAGES
548 movzx ecx,[word ((image_himem si).size) + 2]
549 shr cx,4 ; pages index size = size >> 20
550 add cx,8+4096+8
551 call malloc_or_die
552 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
553 add ecx,[(image_himem si).size]
554 shr ecx,12
555 mov [curdata],ax
556 else
557 mov ecx,[(image_himem si).size]
558 dec ecx
559 shr ecx,12
560 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
561 push cx
562 inc cx ; cnt+1
563 shl cx,2 ; bufv => vcpi => vm86
564 ; our malloc zeroes allocated mem: bufv[cnt]=0;
565 ; Allocate pages, storing addrs in addrbuf
566 call malloc_or_die
567 pop cx
568 push ax
569 endif
570 mov [(image_himem si).bufv],ax
571 xchg ax,si
572 @@vcpi_alloc:
573 xor edx,edx
574 mov ax,0DE04h
575 int 67h
576 or ah,ah
577 mov bx,offset vcpi_alloc_err
578 jnz die
579 ; for (i = cnt-1; i >= 0; i--)
580 ifdef LARGE_IMAGES
581 mov eax,ecx
582 dec eax
583 else
584 mov ax,cx
585 dec ax
586 cwde
587 endif
588 shl eax,12 ; i*_4k
589 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
590 extrn _imgs
591 mov bx,offset _imgs+2
592 push eax
593 add eax,[bx-2+2]
594 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
595 pop eax ; i*_4k
596 jbe @@pmok
597 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
598 jae @@vcpi_alloc
599 @@pmok:
600 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
601 extrn _imgs
602 mov bx,offset _imgs+32+2
603 add eax,[bx-2+2] ; +initrd.fallback
604 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
605 ja @@initrdok
606 mov eax,[bx-2+6] ; initrd.size
607 add eax,[bx-2+2] ; +initrd.fallback
608 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
609 @@jnc_vcpi_alloc:
610 ja @@vcpi_alloc
611 @@initrdok:
612 ifdef LARGE_IMAGES
613 cmp [(data_himem si).first],0
614 jne @@notfirst
615 mov [(data_himem si).first],edx
616 @@notfirst:
617 mov bx,[(data_himem si).cacheidx]
618 cmp bh,4
619 jae @@nextpage
620 shl bx,2
621 inc [(data_himem si).cacheidx]
622 mov [(data_himem bx+si).cache],edx
623 loopd @@vcpi_alloc
624 mov [(data_himem bx+si).cache],ecx ; last is 0
625 @@nextpage:
626 and [(data_himem si).cacheidx],0
627 mov bx,[(data_himem si).pageidx]
628 mov [(data_himem bx+si).page],edx
629 add [(data_himem si).pageidx],4
630 push cx
631 lea cx,[(data_himem si).cache]
632 ifdef NO386
633 push edx
634 pop dx
635 pop ax
636 endif
637 call storepage ; storepage(edx,cx)
638 pop cx
639 or ecx,ecx ; clear C
640 jnz @@jnc_vcpi_alloc
641 mov [dword (data_himem si).cacheidx],ecx
642 xchg ax,si
643 else
644 mov [si],edx
645 lodsd ; si=+4
646 loop @@vcpi_alloc
647 pop ax
648 endif
649 pop si
650 ret
651 ifdef NO386
652 p8086
653 endif
655 endp @malloc_bufv_or_die$qp11image_himem
658 ;***************************************************************
659 ;_fastcall void memcpy_image(struct image_himem *m);
660 ;***************************************************************
661 global @memcpy_image$qp11image_himem:near
662 proc @memcpy_image$qp11image_himem near
664 ifndef NO386
665 mov edx,[(image_himem bx).fallback]
666 mov eax,[(image_himem bx).buf]
667 cmp eax,edx ; if (m->fallback != m->buf)
668 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
669 ifdef LARGE_IMAGES
670 mov ecx,[(image_himem bx).size]
671 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
672 push ecx
673 else
674 push [(image_himem bx).size]
675 endif
676 push eax
677 push 0
678 call_memcpy32:
679 push edx
680 else
681 mov ax,[word ((image_himem bx).fallback)]
682 mov dx,[word ((image_himem bx).fallback)+2]
683 mov cx,[word ((image_himem bx).buf)]
684 cmp ax,cx ; if (m->fallback != m->buf)
685 jnz @@do
686 cmp dx,[word ((image_himem bx).buf)+2]
687 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
688 @@do:
689 push [word ((image_himem bx).size)+2]
690 push [word ((image_himem bx).size)]
691 push [word ((image_himem bx).buf)+2]
692 push cx
693 xor cx,cx
694 push cx
695 call_memcpy32:
696 push dx
697 push ax
698 ifdef LARGE_IMAGES
699 jmp @@memcpy
700 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
701 p386
702 push ecx
703 push eax
704 push 0
705 push edx
706 ifdef NO386
707 p8086
708 endif
709 endif
710 endif
711 @@memcpy:
712 extrn memcpy32:near
713 call near memcpy32
714 @@skip:
715 ret
717 endp @memcpy_image$qp11image_himem
719 ;***************************************************************
720 ;_fastcall void storepage(u32 *dst);
721 ;***************************************************************
722 global @storepage$qpul:near
723 proc @storepage$qpul near
725 ifndef NO386
726 mov edx,[bx]
727 else
728 mov ax,[bx]
729 mov dx,[bx+2]
730 endif
731 mov cx,offset _xfer_buf
732 storepage: ; storepage(edx,cx)
733 ifndef NO386
734 push 0
735 push 4096
736 push 0
737 else
738 xor bx,bx
739 push bx
740 mov bh,4096/256
741 push bx
742 xor bx,bx
743 push bx
744 endif
745 push cx
746 push ds
747 jmp call_memcpy32
749 endp @storepage$qpul
752 ifdef LARGE_IMAGES
753 p386
754 ;***************************************************************
755 ;_fastcall void reset_bufv(u32 *p);
756 ;***************************************************************
757 global @reset_bufv$qpul:near
758 proc @reset_bufv$qpul near
760 mov [curdata],bx
761 and [dword (data_himem bx).cacheidx],0
762 ret
764 endp @reset_bufv$qpul
766 ;***************************************************************
767 ;u32* prev_bufv();
768 ;u32* prev_bufv();
769 ;***************************************************************
770 global _prev_bufv:near
771 global _next_bufv:near
772 proc _prev_bufv near
774 stc
775 db 73h ; jnc
776 _next_bufv:
777 clc
778 push si
779 mov si,[curdata]
780 sbb ax,ax
781 cmc
782 adc ax,[(data_himem si).cacheidx] ; -1/+1
783 xor ecx,ecx
784 test ax,0fc00h
785 jz @@gotpage
786 push ax ; FFFF / 0400
787 sar ax,8 ; FFFC / 0004
788 and al,0fch
789 add [(data_himem si).pageidx],ax
790 mov bx,[(data_himem si).pageidx]
791 lea bx,[(data_himem bx+si).page]
792 mov edx,ds
793 shl edx,4
794 lea cx,[(data_himem si).cache]
795 add edx,ecx
796 mov eax,[bx]
797 or eax,eax
798 jnz @@pageok
799 pop ax
800 xchg ax,bx
801 pop si
802 ret
803 @@pageok:
804 mov cx,4096
805 call memcpy_imagez ; get page
806 pop ax ; FFFF / 0400
807 cbw
808 shr ax,6 ; 03FF / 0000
809 @@gotpage:
810 mov [(data_himem si).cacheidx],ax
811 shl ax,2
812 xchg ax,bx
813 lea ax,[(data_himem bx+si).cache]
814 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
815 jnz @@notfirst2
816 xchg ax,si ; &first
817 @@notfirst2:
818 pop si
819 ret
821 endp _prev_bufv
822 endif
824 ifdef NO386
825 p8086
826 endif
828 ;***************************************************************
829 ;_fastcall void open_image(const char *name, struct image_himem *m);
830 ;***************************************************************
831 global @open_image$qpxzcp11image_himem:near
832 proc @open_image$qpxzcp11image_himem near
834 push di
835 xchg ax,di
836 ifdef EXTRA
837 cmp [(image_himem di).fd],0 ; iso image/kernel ?
838 jnz @@alreadydone
839 endif
840 mov [(image_himem di).state],bx
841 push bx
842 ifdef EXTRA
843 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
844 jnz @@next
845 endif
846 mov [(image_himem di).next_chunk],offset next_chunk
847 @@next:
848 call [(image_himem di).next_chunk] ; m->next_chunk()
849 ifndef NO386
850 add eax,3
851 and al,0FCh
852 add [(image_himem di).size],eax ; m->size += m->chunk_size
853 or eax,eax
854 else
855 add ax,3
856 adc dx,0
857 and al,0FCh
858 add [word (image_himem di).size],ax ; m->size += m->chunk_size
859 adc [word ((image_himem di).size)+2],dx
860 or ax,dx
861 endif
862 jnz @@next
863 pop [(image_himem di).state]
864 call [(image_himem di).next_chunk] ; m->next_chunk()
865 @@alreadydone:
866 pop di
867 ret
869 endp @open_image$qpxzcp11image_himem
872 ;***************************************************************
873 ;_fastcall int read_image(struct image_himem *m);
874 ;***************************************************************
875 global @read_image$qp11image_himem:near
876 proc @read_image$qp11image_himem near
878 push si di
879 mov di,bx
880 mov si,4096
881 push si ; original size
882 @@loop:
883 ifndef NO386
884 movzx ecx,si
885 mov eax,[(image_himem di).chunk_size]
886 cmp ecx,eax
887 jb @@szok
888 else
889 mov cx,si
890 mov ax,[word (image_himem di).chunk_size]
891 cmp cx,ax
892 jb @@szok
893 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
894 jne @@szok
895 endif
896 xchg ax,cx
897 @@szok:
898 jcxz image_done
899 mov dx,offset _xfer_buf
900 mov bx,[di]
901 call @read$cxdxbx
902 jc image_done
903 xor cx,cx
904 cwd ; ax < 8000h
905 ifndef NO386
906 cwde ; ax < 8000h
907 sub [(image_himem di).chunk_size],eax
908 xchg eax,ebx
909 else
910 sub [word (image_himem di).chunk_size],ax
911 xchg ax,bx
912 sbb [word ((image_himem di).chunk_size)+2],dx
913 jnz @@fill
914 cmp [word (image_himem di).chunk_size],dx
915 endif
916 jnz @@fill
917 dec cx
918 @@fill:
919 test bl,3
920 je @@filled
921 mov [bx+_xfer_buf],dh
922 inc bx
923 jmp @@fill
924 @@filled:
925 ifndef NO386
926 sub [(image_himem di).remaining],ebx
927 else
928 sub [word (image_himem di).remaining],bx
929 sbb [word ((image_himem di).remaining)+2],dx
930 endif
931 sub si,bx
932 pushf
933 and cx,[(image_himem di).next_chunk]
934 jcxz @@same_chunk
935 call cx
936 @@same_chunk:
937 popf
938 jnz @@loop
939 image_done:
940 pop ax ; original size
941 sub ax,si
942 pop di si
943 ret
945 endp @read_image$qp11image_himem
948 ;***************************************************************
949 ;pascal unsigned long strtol(const char *s);
950 ;***************************************************************
951 global @strtol$qpxzc:near
952 proc @strtol$qpxzc near
954 pop ax
955 pop bx ; s
956 push ax
957 ifndef NO386
958 xor ebx,ebx
959 push si
960 jcxz @@end
961 mov si,cx
962 xor ecx,ecx
963 xor eax,eax
964 lodsb
965 mov dx,ax
966 or al,20h
967 cmp al,'n' ; vga=normal
968 je @@vga
969 dec cx
970 cmp al,'e' ; vga=extended
971 je @@vga
972 dec cx
973 cmp al,'a' ; vga=ask
974 jne @@notvga
975 @@vga:
976 dec cx
977 xchg ax,cx
978 cwd
979 jmp @@popsiret
980 @@notvga:
981 mov cx,10 ; radix
982 xchg ax,dx
983 cmp al,'+'
984 je @@radixskip
985 cmp al,'-'
986 clc
987 jne @@radixkeep
988 stc
989 @@radixskip:
990 lodsb
991 @@radixkeep:
992 pushf
993 cmp al,'0'
994 jne @@radixok
995 mov cl,8
996 lodsb
997 or al,20h
998 cmp al,'x'
999 jne @@radixok
1000 mov cl,16
1001 @@strtollp:
1002 lodsb
1003 @@radixok:
1004 or al,20h
1005 sub al,'0'
1006 jb @@endstrtol
1007 cmp al,9
1008 jbe @@digitok
1009 cmp al,'a'-'0'
1010 jb @@endstrtol
1011 sub al,'a'-'0'-10
1012 @@digitok:
1013 cmp al,cl
1014 jae @@endstrtol
1015 xchg eax,ebx
1016 mul ecx
1017 add eax,ebx
1018 xchg eax,ebx
1019 jmp @@strtollp
1020 @@endstrtol:
1021 mov cl,10
1022 cmp al,'k'-'a'+10
1023 je @@shift
1024 mov cl,20
1025 cmp al,'m'-'a'+10
1026 je @@shift
1027 mov cl,30
1028 cmp al,'g'-'a'+10
1029 jne @@noshift
1030 @@shift:
1031 shl ebx,cl
1032 @@noshift:
1033 popf
1034 jnc @@end
1035 neg ebx
1036 @@end:
1037 push ebx
1038 pop ax
1039 pop dx
1040 @@popsiret:
1041 pop si
1042 else
1043 push si
1044 push di
1045 xor ax,ax
1046 cwd
1047 jcxz @@goend
1048 xchg ax,di
1049 mov si,cx
1050 lodsb
1051 mov bx,ax
1052 or al,20h
1053 mov cx,-1
1054 cmp al,'n' ; vga=normal
1055 je @@vga
1056 dec cx
1057 cmp al,'e' ; vga=extended
1058 je @@vga
1059 dec cx
1060 cmp al,'a' ; vga=ask
1061 jne @@notvga
1062 @@vga:
1063 xchg ax,cx
1064 @@goend:
1065 jmp @@popdisiret
1066 @@notvga:
1067 mov cx,10 ; radix
1068 xchg ax,bx
1069 cmp al,'+'
1070 je @@radixskip
1071 cmp al,'-'
1072 clc
1073 jne @@radixkeep
1074 stc
1075 @@radixskip:
1076 lodsb
1077 @@radixkeep:
1078 pushf
1079 cmp al,'0'
1080 jne @@radixok
1081 mov cl,8
1082 lodsb
1083 or al,20h
1084 cmp al,'x'
1085 jne @@radixok
1086 mov cl,16
1087 @@strtollp:
1088 lodsb
1089 @@radixok:
1090 or al,20h
1091 sub al,'0'
1092 jb @@endstrtol
1093 cmp al,9
1094 jbe @@digitok
1095 cmp al,'a'-'0'
1096 jb @@endstrtol
1097 sub al,'a'-'0'-10
1098 @@digitok:
1099 cmp al,cl
1100 jae @@endstrtol
1102 push ax
1103 push si
1104 push dx
1105 xchg ax,di
1106 mul cx
1107 xchg ax,di
1108 xchg ax,dx
1109 xchg ax,si
1110 pop ax
1111 mul cx
1112 add ax,si
1113 pop si
1114 xchg ax,dx
1115 pop ax
1116 mov ah,0
1117 add di,ax
1118 adc dx,0
1120 jmp @@strtollp
1121 @@endstrtol:
1122 mov cl,10
1123 cmp al,'k'-'a'+10
1124 je @@shift
1125 mov cl,20
1126 cmp al,'m'-'a'+10
1127 je @@shift
1128 mov cl,30
1129 cmp al,'g'-'a'+10
1130 jne @@noshift
1131 @@shift:
1132 rcl di,1
1133 shl dx,1
1134 loop @@shift
1135 @@noshift:
1136 popf
1137 jnc @@end
1138 not dx
1139 neg di
1140 jne @@end
1141 inc dx
1142 @@end:
1143 xchg ax,di
1144 @@popdisiret:
1145 pop di
1146 pop si
1147 endif
1148 strtol_ret:
1149 ret
1151 endp @strtol$qpxzc
1154 ifdef NO386
1155 ;***************************************************************
1156 ;u16 topseg();
1157 ;***************************************************************
1158 global _topseg:near
1159 proc _topseg near
1161 int 12h
1162 jnc @@max640k
1163 mov ax,640 ; 9000
1164 @@max640k:
1165 dec ax
1166 and al,0C0h
1167 mov cl,6
1168 shl ax,cl
1169 ret
1171 endp _topseg
1172 endif
1174 ifdef EXTRA
1175 p8086
1176 ;***************************************************************
1177 ;char *progname(void)
1178 ;***************************************************************
1179 global _progname:near
1180 proc _progname near
1182 push si di es
1183 mov ah,30h
1184 int 21h
1185 xor di,di
1186 cmp al,3
1187 mov ax,di
1188 jb @@skip
1189 ;mov es,[cs:2Ch]
1190 mov es,[di+2Ch]
1191 mov cx,sp ; big enough
1192 @@loop:
1193 repne
1194 scasb
1195 scasb
1196 jne @@loop
1197 inc di
1198 inc di
1199 mov si,di ; progname @es:di
1200 repne
1201 scasb
1202 mov cx,di
1203 sub cx,si ; progname len
1204 call malloc_or_die ; keep cx
1205 mov di,ax
1206 push ds
1207 push es
1208 pop ds
1209 pop es
1210 rep
1211 movsb
1212 push es
1213 pop ds
1214 @@skip:
1215 pop es di si
1216 ret
1218 endp _progname
1221 ;***************************************************************
1222 ;_fastcall void chdirname(char *path)
1223 ;***************************************************************
1224 global @chdirname$qpzc:near
1225 proc @chdirname$qpzc near
1227 cmp [byte bx+1],3Ah ; ':'
1228 jne @@nodisk
1229 mov dl,20h
1230 or dl,[bx]
1231 sub dl,61h
1232 mov ah,0Eh
1233 int 21h
1234 inc bx
1235 inc bx
1236 @@nodisk:
1237 xor cx,cx
1238 @@next:
1239 mov al,[bx]
1240 cmp al,5Ch
1241 jne @@tsteos
1242 mov dx,bx
1243 inc cx
1244 @@tsteos:
1245 inc bx
1246 or al,al
1247 jnz @@next
1248 jcxz @@end
1249 mov bx,dx
1250 push [word bx]
1251 mov [bx],al
1252 stc
1253 mov ax,713Bh ; chdir long filename (ds:dx)
1254 int 21h
1255 mov ah,3Bh ; chdir(ds:dx)
1256 jnc @@chdirdone
1257 int 21h
1258 @@chdirdone:
1259 pop [word bx]
1260 @@end:
1261 ret
1263 endp @chdirname$qpzc
1266 ;***************************************************************
1267 ;_fastcall char *ultoa(unsigned long n);
1268 ;***************************************************************
1269 global @ultoa$qul:near
1270 proc @ultoa$qul near
1272 xchg ax,cx
1273 xchg ax,dx ; AX:CX = n
1274 push si
1275 mov si,10
1276 mov bx,offset ultoabuf+11
1277 @@loop:
1278 dec bx
1279 xor dx,dx
1280 div si ; DX:AX = 0000:hi(n)
1281 xchg ax,cx ; CX = hi(n)/10
1282 div si ; DX:AX = hi(n)%10:lo(n)
1283 xchg ax,cx ; CX = lo(n/10)
1284 ; AX = hi(n)/10 = hi(n/10)
1285 mov [byte bx],'0'
1286 add [bx],dl ; DL = n%10
1287 mov dx,ax
1288 or dx,cx
1289 jnz @@loop
1290 xchg ax,bx
1291 pop si
1292 ret
1294 endp @ultoa$qul
1297 ;***************************************************************
1298 ;_fastcall unsigned long kver2ul(char *kernel_version);
1299 ;***************************************************************
1300 global @kver2ul$qpzc:near
1301 proc @kver2ul$qpzc near
1303 push si
1304 mov si,bx
1305 xor bx,bx
1306 mov cx,304h
1307 @@number:
1308 xor ax,ax
1309 cwd
1310 @@digit:
1311 shl al,cl
1312 shl ax,cl
1313 lodsb
1314 sub al,30h
1315 cmp al,9
1316 jbe @@digit
1317 mov dl,bh
1318 mov bh,bl
1319 mov bl,ah
1320 dec ch
1321 jnz @@number
1322 xchg ax,bx
1323 pop si
1324 kver2ulret:
1325 ret
1327 endp @kver2ul$qpzc
1329 endif
1331 ;***************************************************************
1332 ;void try_default_args();
1333 ;_fastcall void set_cmdline(const char *filename);
1334 ;***************************************************************
1335 ifdef EXTRA
1337 global _try_default_args:near
1338 proc _try_default_args near
1340 mov bx,offset tazboot_cmd
1341 call open
1342 jc kver2ulret
1343 mov cx,4096
1344 mov di,[_heap_top]
1345 extrn read_cmdline:near
1346 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1348 endp _try_default_args
1350 endif
1352 ends _TEXT
1354 end
1356 ;###### END OF FILE ############################################