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

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