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

linld: remove dead code
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 14 22:18:05 2018 +0200 (2018-08-14)
parents 7547eb83cc06
children bcdfc23ee041
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:word
20 extrn _bss_end
21 _heap_top dw _bss_end
22 msg_hang db "High mem corrupted - not exiting to DOS"
23 msg_crlf db 13,10,0
24 vcpi_alloc_err db "vcpi "
25 msg_malloc db "malloc failure",0
26 ifdef EXTRA
27 tazboot_cmd db "tazboot.cmd",0
28 endif
30 ends _DATA
32 segment _BSS byte public use16 'BSS'
34 global _no_exit:byte
35 _no_exit db ?
36 filecnt db ? ; in fact 0 minus file count...
37 nextfilename dw ?
38 ifdef LARGE_IMAGES
39 curdata dw ?
40 endif
41 ifdef EXTRA
42 ultoabuf db 12 dup (?)
43 endif
45 ends _BSS
47 segment _TEXT byte public use16 'CODE'
49 ;***************************************************************
50 ;char* strcpy(const char* a, const char* b);
51 ;char* strcat(const char* a, const char* b);
52 ;char* strcatb(const char* a, const char* b);
53 ;***************************************************************
54 global _strcatb:near
55 proc _strcatb near
57 ifdef EXTRA
58 mov cl,7Fh
59 db 0bbh ; mov bx,imm opcode
60 global _strcat:near
61 _strcat:
62 mov cl,80h
63 db 0bbh ; mov bx,imm opcode
64 global _strcpy:near
65 _strcpy:
66 xor cx,cx
67 endif
68 pop ax ;caller return address
69 pop dx ; a
70 pop bx ; b
71 push bx
72 push dx
73 push ax
74 push si
75 mov si,dx
76 ifdef EXTRA
77 jcxz @@nocat
78 endif
79 @@catlp:
80 lodsb
81 cmp al,0
82 jne @@catlp
83 dec si
84 ifdef EXTRA
85 cmp dx,si
86 adc al,cl ; set S when dx != si or cl = 80
87 mov al,20h
88 jns @@cpyhead
89 endif
90 @@nocat:
91 @@cpylp:
92 mov al,[bx]
93 inc bx
94 @@cpyhead:
95 mov [si],al
96 inc si
97 cmp al,0
98 jne @@cpylp
99 strfound:
100 xchg ax,dx
101 strend:
102 pop si
103 ret
105 endp _strcatb
108 ifdef EXTRA
109 p8086
110 ;***************************************************************
111 ;char strstr(const char* a,const char* b);
112 ;***************************************************************
113 global _strstr:near
114 proc _strstr near
116 pop ax ;caller return address
117 pop dx ; a
118 pop cx ; b
119 push cx
120 push dx
121 push ax
122 push si
123 @@loop:
124 xor ax,ax
125 mov si,dx
126 cmp [si],al ; *a
127 jz strend ; return ax = NULL
128 mov bx,cx
129 @@match:
130 or ah,[bx] ; *b
131 jz strfound
132 inc bx
133 lodsb
134 sub ah,al
135 jz @@match
136 inc dx
137 jmp @@loop
139 endp _strstr
142 ;***************************************************************
143 ;int strcmp(const char* a,const char* b);
144 ;***************************************************************
145 global _strcmp:near
146 proc _strcmp near
148 pop cx ;caller return address
149 pop bx ; a
150 pop ax ; b
151 push ax
152 push bx
153 push cx
154 push si
155 xchg ax,si
156 dec bx
157 @@lp:
158 inc bx
159 lodsb
160 sub al,[bx]
161 jnz @@out
162 sub al,[bx]
163 jnz @@lp
164 @@out:
165 cbw
166 pop si
167 ret
169 endp _strcmp
170 endif
173 ;***************************************************************
174 ;void* malloc(unsigned sz);
175 ;***************************************************************
176 global _malloc:near
177 proc _malloc near
179 pop ax ;caller return address
180 pop cx ; sz
181 push cx
182 push ax
183 global malloc:near ; malloc(cx)
184 malloc: ; keep CX, use AX,BX
185 mov ax,[_heap_top]
186 mov bx,-1400h ; MIN_STACK=_1k+PAGE_SIZE
187 add bx,sp
188 sub bx,ax ; can't overflow
189 cmp bx,cx
190 mov bx,offset msg_malloc
191 jb puts
192 add [_heap_top],cx ; _BEG has zero'd heap
193 ;mov bx,ax
194 @@zalloc:
195 ;mov [byte bx],0
196 ;inc bx ; ZF=0
197 ;loop @@zalloc
198 ret
200 endp _malloc
203 ;***************************************************************
204 ;void puts(const char* s):
205 ;***************************************************************
206 global _puts:near
207 proc _puts near
209 pop ax ;caller return address
210 pop bx ; s
211 push bx
212 push ax
213 global puts:near ; puts(bx)
214 puts:
215 call putsz
216 mov bx,offset msg_crlf
217 jmp putsz
218 putcz:
219 mov ah,2
220 int 21h
221 global putsz:near ; putsz(bx)
222 putsz:
223 mov dl,[bx]
224 inc bx
225 or dl,dl
226 jne putcz ; ZF=1 (for malloc failure)
227 ret
229 endp _puts
232 ;***************************************************************
233 ;int fileattr(const char* name);
234 ;***************************************************************
235 global _fileattr:near
236 proc _fileattr near
238 pop ax ;caller return address
239 pop dx ; name
240 push dx
241 push ax
242 mov ax,4300h
243 int 21h
244 xchg ax,cx
245 jmp chkc
247 endp _fileattr
250 ;***************************************************************
251 ;int open(const char* name, int flags=O_RDONLY);
252 ;***************************************************************
253 global _open:near
254 proc _open near
256 pop ax ;caller return address
257 pop bx ; name
258 push bx
259 push ax
260 global open:near ; open(bx)
261 open:
262 mov dx,bx
263 ;mov cl,0 ; attribute mask
264 mov ax,3d00h ; read-only+compatibility
265 dos:
266 int 21h
267 chkc:
268 jnc doret
269 fail:
270 sbb ax,ax ; ax=-1 CF
271 cwd
272 doret:
273 ifndef NO386
274 push dx ; see next_chunk:lseek
275 push ax
276 pop eax
277 endif
278 ret
280 endp _open
283 ;***************************************************************
284 ;int close(int fd);
285 ;***************************************************************
286 global _close:near
287 proc _close near
289 pop ax ;caller return address
290 pop bx ; fd
291 push bx
292 push ax
293 global close:near ; close(bx)
294 close:
295 mov ah,3Eh
296 or bx,bx
297 jnz dos
298 ret
300 endp _close
303 ;***************************************************************
304 ;int read(int fd, void* data, int sz);
305 ;int write(int fd, const void* data, int sz);
306 ;***************************************************************
307 global _read:near
308 proc _read near
310 ifdef WRITE
311 stc
312 db 0B0h ; mov al,im
313 global _write:near
314 clc
315 endif
316 pop ax ;caller return address
317 pop bx ; fd
318 pop dx ; data
319 pop cx ; sz
320 push cx
321 push dx
322 push bx
323 push ax
324 ifdef WRITE
325 mov ah,40h
326 sbb ah,0
327 else
328 mov ah,3Fh
329 endif
330 jcxz fail
331 jmp dos
333 endp _read
335 proc _lseekset near
336 ;ifdef EXTRA
337 ;***************************************************************
338 ;long lseekset(int fd, unsigned long sz);
339 ;***************************************************************
341 global _lseekset:near
343 pop ax ;caller return address
344 pop bx ; fd
345 pop dx ; sz lo
346 pop cx ; sz hi
347 push cx
348 push dx
349 push bx
350 push ax
351 ;endif
352 global lseekset:near
353 lseekset:
354 clc
355 db 0B0h ; mov al,im
356 global rewind:near
357 rewind: ; rewind(bx)
358 stc
359 mov ax,4200h
360 jnc dos
361 lseek0: ; lseek0(bx,ax=dir)
362 cwd
363 xor cx,cx
364 jmp dos
366 endp _lseekset
368 ifdef EXTRA
369 struc isostate ; struct isostate {
370 fd dw ? ; 0 int fd;
371 fileofs dd ? ; 2 unsigned long fileofs;
372 filesize dd ? ; 6 unsigned long filesize;
373 filemod dw ? ;10 unsigned short filemod;
374 filename dw ? ;12 char *filename;
375 dirofs dd ? ;14 unsigned long dirofs;
376 dirsize dd ? ;16 unsigned long dirsize;
377 curdirofs dd ? ;20 unsigned long curdirofs;
378 curdirsize dd ? ;24 unsigned long curdirsize;
379 curpos dd ? ;28 unsigned long curpos;
380 ends ; } isostate;
381 ;***************************************************************
382 ;unsigned long isolseek(const unsigned long *offset);
383 ;***************************************************************
384 global _isolseek:near
385 proc _isolseek near
387 pop ax
388 pop bx
389 push bx
390 push ax
391 mov dx,[bx]
392 mov cx,[bx+2]
393 extrn _isostate:isostate
394 mov bx,[_isostate.fd]
395 jmp lseekset ; (bx=fd, sz=cx:dx)
397 endp _isolseek
398 endif
401 ;***************************************************************
402 ;int strhead(const char* a,const char* b);
403 ;***************************************************************
404 global _strhead:near
405 proc _strhead near
407 pop cx ;caller return address
408 pop bx ; a
409 pop ax ; b
410 push ax
411 push bx
412 push cx
413 @@loop:
414 xchg ax,bx
415 mov cl,[bx] ; cl = *b++
416 inc bx
417 or cl,cl ; clear C
418 jz fail ; return 0
419 xchg ax,bx
420 xor cl,[bx] ; cl -= *a++
421 inc bx
422 and cl,0dfh ; case insensitive
423 jz @@loop
424 ret ; return b (is not 0)
426 endp _strhead
429 ;***************************************************************
430 ;char* malloc_or_die(unsigned size);
431 ;***************************************************************
432 global _malloc_or_die:near
433 proc _malloc_or_die near
435 pop ax ;caller return address
436 pop cx ; size
437 push cx
438 push ax
439 global malloc_or_die:near ; malloc_or_die(cx)
440 malloc_or_die:
441 call malloc
442 jz _exit
443 ret
445 endp _malloc_or_die
448 ;***************************************************************
449 ;int die(const char* msg);
450 ;int exit();
451 ;int abort();
452 ;***************************************************************
453 global _die:near
454 proc _die near
456 pop ax ;caller return address
457 pop bx ; s
458 push bx
459 push ax
460 global die:near ; die(bx)
461 die:
462 call puts
463 global _exit:near
464 _exit:
465 mov al,[_no_exit]
466 cmp al,0
467 jne @@hang
468 extrn exit:near
469 inc ax
470 jmp near exit
471 @@hang:
472 mov bx, offset msg_hang
473 call puts
474 global _abort:near
475 _abort:
476 cli
477 @@stop:
478 hlt
479 jmp @@stop
481 endp _die
483 struc image_himem ;struct image_himem {
484 fd dw ? ; 0 int fd;
485 fallback dd ? ; 2 u32 fallback;
486 size dd ? ; 6 u32 size;
487 remaining dd ? ;10 u32 remaining;
488 buf dd ? ;14 u32 buf;
489 bufv dw ? ;18 u32 *bufv;
490 errmsg dw ? ;20 char *errmsg;
491 chunk_size dd ? ;22 u32 chunk_size;
492 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
493 state dw ? ;28 u16 state;
494 fd2close dw ? ;30 u16 fd2close;
495 ends ;};
497 ;***************************************************************
498 ;void next_chunk(struct image_himem *di);
499 ;***************************************************************
500 proc next_chunk near
502 push si
503 mov bx,[(image_himem di).fd]
504 call close
505 ifndef NO386
506 xor eax,eax
507 else
508 xor ax,ax
509 endif
510 cwd
511 mov [(image_himem di).fd],ax
512 mov bx,[(image_himem di).state]
513 cmp al,[bx] ; ""
514 jz @@end
515 mov si,bx
516 @@scan:
517 lodsb
518 mov cx,si
519 cmp al,','
520 jz @@eos
521 cmp al,0
522 jnz @@scan
523 dec cx
524 @@eos:
525 mov [(image_himem di).state],cx
526 dec si
527 push [word si]
528 mov [byte si],dl ; set temp eos
529 call open
530 pop [word si] ; restore string
531 jc @@die
532 mov [(image_himem di).fd],ax
533 mov [(image_himem di).fd2close],ax
534 xchg ax,bx
535 mov ax,4202h ; SEEK_END
536 call lseek0
537 @@die:
538 mov bx,[(image_himem di).errmsg]
539 jc die
540 mov bx,[(image_himem di).fd]
541 ifndef NO386
542 push eax
543 call rewind
544 pop eax
545 @@end:
546 mov [(image_himem di).chunk_size],eax
547 else
548 push ax
549 push dx
550 call rewind
551 pop dx
552 pop ax
553 @@end:
554 mov [word (image_himem di).chunk_size],ax
555 mov [word ((image_himem di).chunk_size)+2],dx
556 endif
557 pop si
558 ret
560 endp next_chunk
563 ifdef LARGE_IMAGES
564 struc data_himem ;struct data_himem {
565 first dd ? ; 0 u32 first;
566 cacheidx dw ? ; 4 int cacheidx;
567 pageidx dw ? ; 6 int pageidx;
568 cache dd 1024 dup(?) ; 8 int cache;
569 page dd 1024 dup(?) ;4104 int page;
570 ends ;}; // size=8200
571 endif
573 ;***************************************************************
574 ;u32* malloc_bufv_or_die(struct image_himem *m);
575 ;***************************************************************
576 global _malloc_bufv_or_die:near
577 proc _malloc_bufv_or_die near
579 p386
580 pop bx ;caller return address
581 pop ax
582 push ax
583 push bx
584 push si
585 xchg ax,si
586 ifdef LARGE_IMAGES
587 mov cx,[word ((image_himem si).size) + 2]
588 shr cx,4 ; pages index size = size >> 20
589 add cx,8+4096+8
590 call malloc_or_die
591 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
592 add ecx,[(image_himem si).size]
593 shr ecx,12
594 mov [curdata],ax
595 else
596 mov ecx,[(image_himem si).size]
597 dec ecx
598 shr ecx,12
599 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
600 push cx
601 inc cx ; cnt+1
602 shl cx,2 ; bufv => vcpi => vm86
603 ; our malloc zeroes allocated mem: bufv[cnt]=0;
604 ; Allocate pages, storing addrs in addrbuf
605 call malloc_or_die
606 pop cx
607 push ax
608 endif
609 mov [(image_himem si).bufv],ax
610 xchg ax,si
611 @@vcpi_alloc:
612 xor edx,edx
613 mov ax,0DE04h
614 int 67h
615 or ah,ah
616 mov bx,offset vcpi_alloc_err
617 jnz die
618 ; for (i = cnt-1; i >= 0; i--)
619 ifdef LARGE_IMAGES
620 mov eax,ecx
621 dec eax
622 else
623 mov ax,cx
624 dec ax
625 cwde
626 endif
627 shl eax,12 ; i*_4k
628 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
629 extrn _imgs
630 mov bx,offset _imgs+2
631 push eax
632 add eax,[bx-2+2]
633 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
634 pop eax ; i*_4k
635 jbe @@pmok
636 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
637 jae @@vcpi_alloc
638 @@pmok:
639 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
640 extrn _imgs
641 mov bx,offset _imgs+32+2
642 add eax,[bx-2+2] ; +initrd.fallback
643 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
644 ja @@initrdok
645 mov eax,[bx-2+6] ; initrd.size
646 add eax,[bx-2+2] ; +initrd.fallback
647 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
648 @@jnc_vcpi_alloc:
649 ja @@vcpi_alloc
650 @@initrdok:
651 ifdef LARGE_IMAGES
652 cmp [(data_himem si).first],0
653 jne @@notfirst
654 mov [(data_himem si).first],edx
655 @@notfirst:
656 mov bx,[(data_himem si).cacheidx]
657 cmp bh,4
658 jae @@nextpage
659 shl bx,2
660 inc [(data_himem si).cacheidx]
661 mov [(data_himem bx+si).cache],edx
662 loopd @@vcpi_alloc
663 mov [(data_himem bx+si).cache],ecx ; last is 0
664 @@nextpage:
665 and [(data_himem si).cacheidx],0
666 mov bx,[(data_himem si).pageidx]
667 mov [(data_himem bx+si).page],edx
668 add [(data_himem si).pageidx],4
669 push cx
670 lea cx,[(data_himem si).cache]
671 ifdef NO386
672 push edx
673 pop dx
674 pop ax
675 endif
676 call storepage ; storepage(edx,cx)
677 pop cx
678 or ecx,ecx ; clear C
679 jnz @@jnc_vcpi_alloc
680 mov [dword (data_himem si).cacheidx],ecx
681 xchg ax,si
682 else
683 mov [si],edx
684 lodsd ; si=+4
685 loop @@vcpi_alloc
686 pop ax
687 endif
688 pop si
689 ret
690 ifdef NO386
691 p8086
692 endif
694 endp _malloc_bufv_or_die
697 ;***************************************************************
698 ; void memcpy_image(struct image_himem *m);
699 ;***************************************************************
700 global _memcpy_image:near
701 proc _memcpy_image near
703 pop ax ;caller return address
704 pop bx
705 push bx
706 push ax
707 ifndef NO386
708 mov edx,[(image_himem bx).fallback]
709 mov eax,[(image_himem bx).buf]
710 cmp eax,edx ; if (m->fallback != m->buf)
711 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
712 ifdef LARGE_IMAGES
713 mov ecx,[(image_himem bx).size]
714 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
715 push ecx
716 else
717 push [(image_himem bx).size]
718 endif
719 push eax
720 push 0
721 call_memcpy32:
722 push edx
723 else
724 mov ax,[word ((image_himem bx).fallback)]
725 mov dx,[word ((image_himem bx).fallback)+2]
726 mov cx,[word ((image_himem bx).buf)]
727 cmp ax,cx ; if (m->fallback != m->buf)
728 jnz @@do
729 cmp dx,[word ((image_himem bx).buf)+2]
730 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
731 @@do:
732 push [word ((image_himem bx).size)+2]
733 push [word ((image_himem bx).size)]
734 push [word ((image_himem bx).buf)+2]
735 push cx
736 xor cx,cx
737 push cx
738 call_memcpy32:
739 push dx
740 push ax
741 ifdef LARGE_IMAGES
742 jmp @@memcpy
743 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
744 p386
745 push ecx
746 push eax
747 push 0
748 push edx
749 ifdef NO386
750 p8086
751 endif
752 endif
753 endif
754 @@memcpy:
755 extrn _memcpy32:near
756 call near _memcpy32
757 add sp,14
758 @@skip:
759 ret
761 endp _memcpy_image
763 ;***************************************************************
764 ;void storepage(u32 *dst, u16 src);
765 ;***************************************************************
766 global _storepage:near
767 proc _storepage near
769 pop ax ;caller return address
770 pop bx
771 pop cx
772 push cx
773 push bx
774 push ax
775 ifndef NO386
776 mov edx,[bx]
777 else
778 mov ax,[bx]
779 mov dx,[bx+2]
780 endif
781 storepage: ; storepage(edx,cx)
782 ifndef NO386
783 push 0
784 push 4096
785 push 0
786 else
787 xor bx,bx
788 push bx
789 mov bh,4096/256
790 push bx
791 xor bx,bx
792 push bx
793 endif
794 push cx
795 push ds
796 jmp call_memcpy32
798 endp _storepage
801 ifdef LARGE_IMAGES
802 p386
803 ;***************************************************************
804 ;void reset_bufv(u32 *p);
805 ;***************************************************************
806 global _reset_bufv:near
807 proc _reset_bufv near
809 pop ax ;caller return address
810 pop bx
811 push bx
812 push ax
813 mov [curdata],bx
814 and [dword (data_himem bx).cacheidx],0
815 ret
817 endp _reset_bufv
819 ;***************************************************************
820 ;u32* prev_bufv();
821 ;u32* prev_bufv();
822 ;***************************************************************
823 global _prev_bufv:near
824 global _next_bufv:near
825 proc _prev_bufv near
827 stc
828 db 73h ; jnc
829 _next_bufv:
830 clc
831 sbb ax,ax
832 stc
833 rcl ax,1 ; -1/+1
834 xor ecx,ecx
835 push si
836 mov si,[curdata]
837 add ax,[(data_himem si).cacheidx]
838 test ax,0fc00h
839 jz @@gotpage
840 push ax ; FFFF / 0400
841 sar ax,8 ; FFFC / 0004
842 and al,0fch
843 add [(data_himem si).pageidx],ax
844 mov bx,[(data_himem si).pageidx]
845 lea bx,[(data_himem bx+si).page]
846 mov edx,ds
847 shl edx,4
848 lea cx,[(data_himem si).cache]
849 add edx,ecx
850 mov eax,[bx]
851 or eax,eax
852 jnz @@pageok
853 pop ax
854 xchg ax,bx
855 pop si
856 ret
857 @@pageok:
858 mov cx,4096
859 call memcpy_imagez ; get page
860 pop ax ; FFFF / 0400
861 cbw
862 shr ax,6 ; 03FF / 0000
863 @@gotpage:
864 mov [(data_himem si).cacheidx],ax
865 shl ax,2
866 xchg ax,bx
867 lea ax,[(data_himem bx+si).cache]
868 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
869 jnz @@notfirst2
870 xchg ax,si ; &first
871 @@notfirst2:
872 pop si
873 ret
875 endp _prev_bufv
876 endif
878 ifdef NO386
879 p8086
880 endif
882 ;***************************************************************
883 ;void open_image(const char *name, struct image_himem *m);
884 ;***************************************************************
885 global _open_image:near
886 proc _open_image near
888 arg fname :word, \
889 m :word = PARAM_SIZE
891 push bp
892 mov bp,sp
893 push si di
894 ifndef NO386
895 xor eax,eax ; 1st loop flag + eos
896 else
897 xor ax,ax ; 1st loop flag + eos
898 endif
899 mov di,[m]
900 cmp [(image_himem di).fd],ax
901 jnz @@alreadydone
902 ifndef NO386
903 mov [(image_himem di).size],eax ; m->size = 0L
904 else
905 mov [word (image_himem di).size],ax ; m->size = 0L
906 mov [word ((image_himem di).size)+2],ax
907 endif
908 mov [(image_himem di).next_chunk],offset next_chunk
909 mov si,[fname]
910 mov [(image_himem di).state],si
911 @@next:
912 push di
913 call [(image_himem di).next_chunk] ; m->next_chunk()
914 pop di
915 ifndef NO386
916 add eax,3
917 and al,0FCh
918 add [(image_himem di).size],eax ; m->size += m->chunk_size
919 or eax,eax
920 jnz @@next
921 else
922 mov cx,ax
923 or cx,dx
924 add ax,3
925 adc dx,0
926 and al,0FCh
927 add [word (image_himem di).size],ax ; m->size += m->chunk_size
928 adc [word ((image_himem di).size)+2],dx
929 inc cx ; jcxnz
930 loop @@next
931 endif
932 mov [(image_himem di).state],si
933 push di
934 call [(image_himem di).next_chunk] ; m->next_chunk()
935 pop di
936 @@alreadydone:
937 push ax
938 image_done:
939 pop ax
940 pop di si bp
941 ret
943 endp _open_image
946 ;***************************************************************
947 ;int read_image(struct image_himem *m, void* data, int sz);
948 ;***************************************************************
949 global _read_image:near
950 proc _read_image near
952 arg m :word, \
953 data :word, \
954 sz :word = PARAM_SIZE
956 push bp
957 mov bp,sp
958 push si di
959 ifndef NO386
960 push 0 ; return value
961 else
962 xor ax,ax
963 push ax
964 endif
965 mov di,[m]
966 @@loop:
967 ifndef NO386
968 xor ecx,ecx
969 mov cx,[word sz]
970 @@chksz:
971 mov eax,[(image_himem di).chunk_size]
972 cmp ecx,eax
973 jb @@szok
974 xchg eax,ecx
975 else
976 mov cx,[word sz]
977 @@chksz:
978 mov ax,[word (image_himem di).chunk_size]
979 cmp cx,ax
980 jb @@szok
981 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
982 jne @@szok
983 xchg ax,cx
984 endif
985 @@szok:
986 jcxz image_done
987 push cx
988 push [word data]
989 push [word di]
990 call _read
991 pop dx
992 pop bx
993 pop dx
994 jc image_done
995 add bx,ax
996 xor cx,cx
997 ifndef NO386
998 cwde ; ax < 8000h
999 sub [(image_himem di).chunk_size],eax
1000 else
1001 cwd ; ax < 8000h
1002 sub [word (image_himem di).chunk_size],ax
1003 sbb [word ((image_himem di).chunk_size)+2],dx
1004 jnz @@fill
1005 cmp [word (image_himem di).chunk_size],dx
1006 endif
1007 jnz @@fill
1008 dec cx
1009 @@fill:
1010 test al,3
1011 je @@filled
1012 mov [bx],dl
1013 inc bx
1014 inc ax
1015 jmp @@fill
1016 @@filled:
1017 ifndef NO386
1018 sub [(image_himem di).remaining],eax
1019 else
1020 sub [word (image_himem di).remaining],ax
1021 sbb [word ((image_himem di).remaining)+2],dx
1022 endif
1023 add [bp-4-2],ax
1024 add [word data],ax
1025 sub [word sz],ax
1026 pushf
1027 and cx,[(image_himem di).next_chunk]
1028 jz @@same_chunk
1029 push di
1030 call cx ; m->next_chunk()
1031 pop di
1032 @@same_chunk:
1033 popf
1034 jnz @@loop
1035 jmp image_done
1037 endp _read_image
1040 ;***************************************************************
1041 ;unsigned long strtol(const char *s);
1042 ;***************************************************************
1043 global _strtol:near
1044 proc _strtol near
1046 ifndef NO386
1047 pop ax ;caller return address
1048 pop cx ; s
1049 push cx
1050 push ax
1051 xor ebx,ebx
1052 push si
1053 jcxz @@end
1054 mov si,cx
1055 xor ecx,ecx
1056 xor eax,eax
1057 lodsb
1058 mov dx,ax
1059 or al,20h
1060 cmp al,'n' ; vga=normal
1061 je @@vga
1062 dec cx
1063 cmp al,'e' ; vga=extended
1064 je @@vga
1065 dec cx
1066 cmp al,'a' ; vga=ask
1067 jne @@notvga
1068 @@vga:
1069 dec cx
1070 xchg ax,cx
1071 cwd
1072 jmp @@popsiret
1073 @@notvga:
1074 mov cx,10 ; radix
1075 xchg ax,dx
1076 cmp al,'+'
1077 je @@radixskip
1078 cmp al,'-'
1079 clc
1080 jne @@radixkeep
1081 stc
1082 @@radixskip:
1083 lodsb
1084 @@radixkeep:
1085 pushf
1086 cmp al,'0'
1087 jne @@radixok
1088 mov cl,8
1089 lodsb
1090 or al,20h
1091 cmp al,'x'
1092 jne @@radixok
1093 mov cl,16
1094 @@strtollp:
1095 lodsb
1096 @@radixok:
1097 or al,20h
1098 sub al,'0'
1099 jb @@endstrtol
1100 cmp al,9
1101 jbe @@digitok
1102 cmp al,'a'-'0'
1103 jb @@endstrtol
1104 sub al,'a'-'0'-10
1105 @@digitok:
1106 cmp al,cl
1107 jae @@endstrtol
1108 xchg eax,ebx
1109 mul ecx
1110 add eax,ebx
1111 xchg eax,ebx
1112 jmp @@strtollp
1113 @@endstrtol:
1114 mov cl,10
1115 cmp al,'k'-'a'+10
1116 je @@shift
1117 mov cl,20
1118 cmp al,'m'-'a'+10
1119 je @@shift
1120 mov cl,30
1121 cmp al,'g'-'a'+10
1122 jne @@noshift
1123 @@shift:
1124 shl ebx,cl
1125 @@noshift:
1126 popf
1127 jnc @@end
1128 neg ebx
1129 @@end:
1130 push ebx
1131 pop ax
1132 pop dx
1133 @@popsiret:
1134 pop si
1135 else
1136 pop ax ;caller return address
1137 pop cx ; s
1138 push cx
1139 push ax
1140 push si
1141 push di
1142 xor ax,ax
1143 cwd
1144 jcxz @@goend
1145 xchg ax,di
1146 mov si,cx
1147 lodsb
1148 mov bx,ax
1149 or al,20h
1150 mov cx,-1
1151 cmp al,'n' ; vga=normal
1152 je @@vga
1153 dec cx
1154 cmp al,'e' ; vga=extended
1155 je @@vga
1156 dec cx
1157 cmp al,'a' ; vga=ask
1158 jne @@notvga
1159 @@vga:
1160 xchg ax,cx
1161 @@goend:
1162 jmp @@popdisiret
1163 @@notvga:
1164 mov cx,10 ; radix
1165 xchg ax,bx
1166 cmp al,'+'
1167 je @@radixskip
1168 cmp al,'-'
1169 clc
1170 jne @@radixkeep
1171 stc
1172 @@radixskip:
1173 lodsb
1174 @@radixkeep:
1175 pushf
1176 cmp al,'0'
1177 jne @@radixok
1178 mov cl,8
1179 lodsb
1180 or al,20h
1181 cmp al,'x'
1182 jne @@radixok
1183 mov cl,16
1184 @@strtollp:
1185 lodsb
1186 @@radixok:
1187 or al,20h
1188 sub al,'0'
1189 jb @@endstrtol
1190 cmp al,9
1191 jbe @@digitok
1192 cmp al,'a'-'0'
1193 jb @@endstrtol
1194 sub al,'a'-'0'-10
1195 @@digitok:
1196 cmp al,cl
1197 jae @@endstrtol
1199 push ax
1200 push si
1201 push dx
1202 xchg ax,di
1203 mul cx
1204 xchg ax,di
1205 xchg ax,dx
1206 xchg ax,si
1207 pop ax
1208 mul cx
1209 add ax,si
1210 pop si
1211 xchg ax,dx
1212 pop ax
1213 mov ah,0
1214 add di,ax
1215 adc dx,0
1217 jmp @@strtollp
1218 @@endstrtol:
1219 mov cl,10
1220 cmp al,'k'-'a'+10
1221 je @@shift
1222 mov cl,20
1223 cmp al,'m'-'a'+10
1224 je @@shift
1225 mov cl,30
1226 cmp al,'g'-'a'+10
1227 jne @@noshift
1228 @@shift:
1229 rcl di,1
1230 shl dx,1
1231 loop @@shift
1232 @@noshift:
1233 popf
1234 jnc @@end
1235 not dx
1236 neg di
1237 jne @@end
1238 inc dx
1239 @@end:
1240 xchg ax,di
1241 @@popdisiret:
1242 pop di
1243 pop si
1244 endif
1245 ret
1247 endp _strtol
1250 ifdef NO386
1251 ;***************************************************************
1252 ;u16 topseg();
1253 ;***************************************************************
1254 global _topseg:near
1255 proc _topseg near
1257 int 12h
1258 jnc @@max640k
1259 mov ax,640 ; 9000
1260 @@max640k:
1261 dec ax
1262 and al,0C0h
1263 mov cl,6
1264 shl ax,cl
1265 ret
1267 endp _topseg
1268 endif
1270 ifdef EXTRA
1271 p8086
1272 ;***************************************************************
1273 ;char *progname(void)
1274 ;***************************************************************
1275 global _progname:near
1276 proc _progname near
1278 push si di es
1279 mov ah,30h
1280 int 21h
1281 xor di,di
1282 cmp al,3
1283 mov ax,di
1284 jb @@skip
1285 ;mov es,[cs:2Ch]
1286 mov es,[di+2Ch]
1287 mov cx,sp ; big enough
1288 @@loop:
1289 repne
1290 scasb
1291 scasb
1292 jne @@loop
1293 inc di
1294 inc di
1295 mov si,di ; progname @es:di
1296 repne
1297 scasb
1298 mov cx,di
1299 sub cx,si ; progname len
1300 call malloc_or_die ; keep cx
1301 mov di,ax
1302 push ds
1303 push es
1304 pop ds
1305 pop es
1306 rep
1307 movsb
1308 push es
1309 pop ds
1310 @@skip:
1311 pop es di si
1312 ret
1314 endp _progname
1317 ;***************************************************************
1318 ;void chdirname(char *path)
1319 ;***************************************************************
1320 global _chdirname:near
1321 proc _chdirname near
1323 pop ax
1324 pop bx
1325 push bx
1326 push ax
1328 cmp [byte bx+1],3Ah ; ':'
1329 jne @@nodisk
1330 mov dl,20h
1331 or dl,[bx]
1332 sub dl,61h
1333 mov ah,0Eh
1334 int 21h
1335 inc bx
1336 inc bx
1337 @@nodisk:
1338 xor cx,cx
1339 @@next:
1340 mov al,[bx]
1341 cmp al,5Ch
1342 jne @@tsteos
1343 mov dx,bx
1344 inc cx
1345 @@tsteos:
1346 inc bx
1347 or al,al
1348 jnz @@next
1349 jcxz @@end
1350 mov bx,dx
1351 push [word bx]
1352 mov [bx],al
1353 stc
1354 mov ax,713Bh ; chdir long filename (ds:dx)
1355 int 21h
1356 mov ah,3Bh ; chdir(ds:dx)
1357 jnc chdirdone
1358 int 21h
1359 chdirdone:
1360 pop [word bx]
1361 @@end:
1362 ret
1364 endp _chdirname
1367 ;***************************************************************
1368 ;char *ultoa(unsigned long n);
1369 ;***************************************************************
1370 global _ultoa:near
1371 proc _ultoa near
1373 pop ax
1374 pop cx
1375 pop dx
1376 push dx
1377 push cx
1378 push ax ; DX:CX = n
1379 push si
1380 mov si,10
1381 mov bx,offset ultoabuf+11
1382 @@loop:
1383 dec bx
1384 xchg ax,dx
1385 xor dx,dx
1386 div si ; DX:AX = 0000:hi(n)
1387 xchg ax,cx ; CX = hi(n)/10
1388 div si ; DX:AX = hi(n)%10:lo(n)
1389 xchg ax,cx ; CX = lo(n/10)
1390 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
1391 add al,'0'
1392 mov [bx],al
1393 mov ax,cx
1394 or ax,dx
1395 jnz @@loop
1396 xchg ax,bx
1397 pop si
1398 ret
1400 endp _ultoa
1403 ;***************************************************************
1404 ;unsigned long kver2ul(char *kernel_version);
1405 ;***************************************************************
1406 global _kver2ul:near
1407 proc _kver2ul near
1409 pop bx
1410 pop ax
1411 push ax
1412 push bx
1413 push si
1414 xchg ax,si
1415 xor bx,bx
1416 mov cx,304h
1417 @@number:
1418 xor ax,ax
1419 cwd
1420 @@digit:
1421 shl al,cl
1422 shl ax,cl
1423 lodsb
1424 sub al,30h
1425 cmp al,9
1426 jbe @@digit
1427 mov dl,bh
1428 mov bh,bl
1429 mov bl,ah
1430 dec ch
1431 jnz @@number
1432 xchg ax,bx
1433 pop si
1434 kver2ulret:
1435 ret
1437 endp _kver2ul
1440 ;***************************************************************
1441 ;void try_default_args();
1442 ;***************************************************************
1443 global _try_default_args:near
1444 proc _try_default_args near
1446 mov bx,offset tazboot_cmd
1447 call open
1448 jc kver2ulret
1449 mov cx,4096
1450 mov di,[_heap_top]
1451 push cx
1452 extrn read_cmdline:near
1453 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1455 endp _try_default_args
1457 endif
1459 ends _TEXT
1461 end
1463 ;###### END OF FILE ############################################