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

linld: fix reset_bufv
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 06 13:32:05 2018 +0100 (2018-11-06)
parents d7919052f62f
children 17c0ad41f5bf
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_crlf db 13,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 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 or al,al
163 jnz @@lp
164 @@out:
165 cbw
166 pop si
167 ret
169 endp _strcmp
170 endif
173 ;***************************************************************
174 ;void puts(const char* s):
175 ;***************************************************************
176 global _puts:near
177 proc _puts near
179 pop ax ;caller return address
180 pop bx ; s
181 push bx
182 push ax
183 ; global puts:near ; puts(bx)
184 puts:
185 call @@putsz
186 mov bx,offset msg_crlf
187 jmp @@putsz
188 @@putcz:
189 mov ah,2
190 int 21h
191 @@putsz:
192 mov dl,[bx]
193 inc bx
194 or dl,dl
195 jne @@putcz ; ZF=1 (for malloc failure)
196 ret
198 endp _puts
201 ;***************************************************************
202 ;int fileattr(const char* name);
203 ;***************************************************************
204 global _fileattr:near
205 proc _fileattr near
207 pop ax ;caller return address
208 pop dx ; name
209 push dx
210 push ax
211 mov ax,4300h
212 int 21h
213 xchg ax,cx
214 jmp chkc
216 endp _fileattr
219 ;***************************************************************
220 ;int open(const char* name, int flags=O_RDONLY);
221 ;***************************************************************
222 global _open:near
223 proc _open near
225 pop ax ;caller return address
226 pop bx ; name
227 push bx
228 push ax
229 global open:near ; open(bx)
230 open:
231 mov dx,bx
232 ;mov cl,0 ; attribute mask
233 mov ax,3d00h ; read-only+compatibility
234 dos:
235 int 21h
236 chkc:
237 jnc doret
238 fail:
239 sbb ax,ax ; ax=-1 CF
240 cwd
241 doret:
242 ifndef NO386
243 push dx ; see next_chunk:lseek
244 push ax
245 pop eax
246 endif
247 ret
249 endp _open
252 ;***************************************************************
253 ;int close(int fd);
254 ;***************************************************************
255 global _close:near
256 proc _close near
258 pop ax ;caller return address
259 pop bx ; fd
260 push bx
261 push ax
262 global close:near ; close(bx)
263 close:
264 mov ah,3Eh
265 or bx,bx
266 jnz dos
267 ret
269 endp _close
272 ;***************************************************************
273 ;int read(int fd, void* data, int sz);
274 ;int write(int fd, const void* data, int sz);
275 ;***************************************************************
276 global _read:near
277 proc _read near
279 ifdef WRITE
280 stc
281 db 0B0h ; mov al,im
282 global _write:near
283 clc
284 endif
285 pop ax ;caller return address
286 pop bx ; fd
287 pop dx ; data
288 pop cx ; sz
289 push cx
290 push dx
291 push bx
292 push ax
293 ifdef WRITE
294 mov ah,40h
295 sbb ah,0
296 else
297 mov ah,3Fh
298 endif
299 jcxz fail
300 jmp dos
302 endp _read
304 proc _lseekset near
305 ;ifdef EXTRA
306 ;***************************************************************
307 ;long lseekset(int fd, unsigned long sz);
308 ;***************************************************************
310 global _lseekset:near
312 pop ax ;caller return address
313 pop bx ; fd
314 pop dx ; sz lo
315 pop cx ; sz hi
316 push cx
317 push dx
318 push bx
319 push ax
320 ;endif
321 ; global lseekset:near
322 lseekset:
323 clc
324 db 0B0h ; mov al,im
325 ; global rewind:near
326 rewind: ; rewind(bx)
327 stc
328 mov ax,4200h
329 jnc dos
330 lseek0: ; lseek0(bx,ax=dir)
331 cwd
332 xor cx,cx
333 jmp dos
335 endp _lseekset
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 strhead(const char* a,const char* b);
372 ;***************************************************************
373 global _strhead:near
374 proc _strhead near
376 pop cx ;caller return address
377 pop bx ; a
378 pop ax ; b
379 push ax
380 push bx
381 push cx
382 @@loop:
383 xchg ax,bx
384 mov cl,[bx] ; cl = *b++
385 inc bx
386 or cl,cl ; clear C
387 jz fail ; return 0
388 xchg ax,bx
389 xor cl,[bx] ; cl -= *a++
390 inc bx
391 and cl,0dfh ; case insensitive
392 jz @@loop
393 ret ; return b (is not 0)
395 endp _strhead
398 ;***************************************************************
399 ;char* malloc_or_die(unsigned size);
400 ;***************************************************************
401 global _malloc_or_die:near
402 proc _malloc_or_die near
404 pop ax ;caller return address
405 pop cx ; size
406 push cx
407 push ax
408 global malloc_or_die:near ; malloc_or_die(cx)
409 malloc_or_die:
410 mov ax,[_heap_top] ; return value
411 mov bx,sp
412 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
413 sub bx,ax ; can't overflow
414 cmp bx,cx
415 mov bx,offset msg_malloc
416 jb die
417 add [_heap_top],cx ; _BEG has zero'd heap
418 ret
420 endp _malloc_or_die
423 ;***************************************************************
424 ;int die(const char* msg);
425 ;int exit();
426 ;int abort();
427 ;***************************************************************
428 global _die:near
429 proc _die near
431 pop ax ;caller return address
432 pop bx ; s
433 ;push bx
434 ;push ax
435 global die:near ; die(bx)
436 die:
437 call puts
438 ; global _exit:near
439 _exit:
440 mov al,[_no_exit]
441 cmp al,0
442 jne @@hang
443 extrn exit:near
444 inc ax
445 jmp near exit
446 @@hang:
447 mov bx, offset msg_hang
448 call puts
449 ; global _abort:near
450 _abort:
451 cli
452 @@stop:
453 hlt
454 jmp @@stop
456 endp _die
458 struc image_himem ;struct image_himem {
459 fd dw ? ; 0 int fd;
460 fallback dd ? ; 2 u32 fallback;
461 size dd ? ; 6 u32 size;
462 remaining dd ? ;10 u32 remaining;
463 buf dd ? ;14 u32 buf;
464 bufv dw ? ;18 u32 *bufv;
465 errmsg dw ? ;20 char *errmsg;
466 chunk_size dd ? ;22 u32 chunk_size;
467 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
468 state dw ? ;28 u16 state;
469 fd2close dw ? ;30 u16 fd2close;
470 ends ;};
472 ;***************************************************************
473 ;long next_chunk(struct image_himem *di);
474 ;***************************************************************
475 proc next_chunk near
477 push si
478 mov bx,[(image_himem di).fd]
479 call close
480 ifndef NO386
481 xor eax,eax
482 else
483 xor ax,ax
484 cwd
485 endif
486 mov [(image_himem di).fd],ax
487 mov bx,[(image_himem di).state]
488 cmp al,[bx] ; ""
489 jz @@end
490 mov si,bx
491 @@scan:
492 lodsb
493 mov cx,si
494 cmp al,','
495 jz @@eos
496 cmp al,0
497 jnz @@scan
498 dec cx
499 @@eos:
500 mov [(image_himem di).state],cx
501 dec si
502 push [word si]
503 mov [byte si],ah ; set temp eos
504 call open
505 pop [word si] ; restore string
506 jc @@die
507 mov [(image_himem di).fd],ax
508 mov [(image_himem di).fd2close],ax
509 xchg ax,bx
510 mov ax,4202h ; SEEK_END
511 call lseek0
512 @@die:
513 mov bx,[(image_himem di).errmsg]
514 jc die
515 mov bx,[(image_himem di).fd]
516 ifndef NO386
517 push eax
518 call rewind
519 pop eax
520 @@end:
521 mov [(image_himem di).chunk_size],eax
522 else
523 push ax
524 push dx
525 call rewind
526 pop dx
527 pop ax
528 @@end:
529 mov [word (image_himem di).chunk_size],ax
530 mov [word ((image_himem di).chunk_size)+2],dx
531 endif
532 pop si
533 ret
535 endp next_chunk
538 ifdef LARGE_IMAGES
539 struc data_himem ;struct data_himem {
540 first dd ? ; 0 u32 first;
541 cacheidx dw ? ; 4 int cacheidx;
542 pageidx dw ? ; 6 int pageidx;
543 cache dd 1024 dup(?) ; 8 int cache;
544 page dd 1024 dup(?) ;4104 int page;
545 ends ;}; // size=8200
546 endif
548 ;***************************************************************
549 ;u32* malloc_bufv_or_die(struct image_himem *m);
550 ;***************************************************************
551 global _malloc_bufv_or_die:near
552 proc _malloc_bufv_or_die near
554 p386
555 pop bx ;caller return address
556 pop ax
557 push ax
558 push bx
559 push si
560 xchg ax,si
561 ifdef LARGE_IMAGES
562 mov cx,[word ((image_himem si).size) + 2]
563 shr cx,4 ; pages index size = size >> 20
564 add cx,8+4096+8
565 call malloc_or_die
566 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
567 add ecx,[(image_himem si).size]
568 shr ecx,12
569 mov [curdata],ax
570 else
571 mov ecx,[(image_himem si).size]
572 dec ecx
573 shr ecx,12
574 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
575 push cx
576 inc cx ; cnt+1
577 shl cx,2 ; bufv => vcpi => vm86
578 ; our malloc zeroes allocated mem: bufv[cnt]=0;
579 ; Allocate pages, storing addrs in addrbuf
580 call malloc_or_die
581 pop cx
582 push ax
583 endif
584 mov [(image_himem si).bufv],ax
585 xchg ax,si
586 @@vcpi_alloc:
587 xor edx,edx
588 mov ax,0DE04h
589 int 67h
590 or ah,ah
591 mov bx,offset vcpi_alloc_err
592 jnz die
593 ; for (i = cnt-1; i >= 0; i--)
594 ifdef LARGE_IMAGES
595 mov eax,ecx
596 dec eax
597 else
598 mov ax,cx
599 dec ax
600 cwde
601 endif
602 shl eax,12 ; i*_4k
603 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
604 extrn _imgs
605 mov bx,offset _imgs+2
606 push eax
607 add eax,[bx-2+2]
608 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
609 pop eax ; i*_4k
610 jbe @@pmok
611 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
612 jae @@vcpi_alloc
613 @@pmok:
614 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
615 extrn _imgs
616 mov bx,offset _imgs+32+2
617 add eax,[bx-2+2] ; +initrd.fallback
618 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
619 ja @@initrdok
620 mov eax,[bx-2+6] ; initrd.size
621 add eax,[bx-2+2] ; +initrd.fallback
622 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
623 @@jnc_vcpi_alloc:
624 ja @@vcpi_alloc
625 @@initrdok:
626 ifdef LARGE_IMAGES
627 cmp [(data_himem si).first],0
628 jne @@notfirst
629 mov [(data_himem si).first],edx
630 @@notfirst:
631 mov bx,[(data_himem si).cacheidx]
632 cmp bh,4
633 jae @@nextpage
634 shl bx,2
635 inc [(data_himem si).cacheidx]
636 mov [(data_himem bx+si).cache],edx
637 loopd @@vcpi_alloc
638 mov [(data_himem bx+si).cache],ecx ; last is 0
639 @@nextpage:
640 and [(data_himem si).cacheidx],0
641 mov bx,[(data_himem si).pageidx]
642 mov [(data_himem bx+si).page],edx
643 add [(data_himem si).pageidx],4
644 push cx
645 lea cx,[(data_himem si).cache]
646 ifdef NO386
647 push edx
648 pop dx
649 pop ax
650 endif
651 call storepage ; storepage(edx,cx)
652 pop cx
653 or ecx,ecx ; clear C
654 jnz @@jnc_vcpi_alloc
655 mov [dword (data_himem si).cacheidx],ecx
656 xchg ax,si
657 else
658 mov [si],edx
659 lodsd ; si=+4
660 loop @@vcpi_alloc
661 pop ax
662 endif
663 pop si
664 ret
665 ifdef NO386
666 p8086
667 endif
669 endp _malloc_bufv_or_die
672 ;***************************************************************
673 ; void memcpy_image(struct image_himem *m);
674 ;***************************************************************
675 global _memcpy_image:near
676 proc _memcpy_image near
678 pop ax ;caller return address
679 pop bx
680 push bx
681 push ax
682 ifndef NO386
683 mov edx,[(image_himem bx).fallback]
684 mov eax,[(image_himem bx).buf]
685 cmp eax,edx ; if (m->fallback != m->buf)
686 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
687 ifdef LARGE_IMAGES
688 mov ecx,[(image_himem bx).size]
689 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
690 push ecx
691 else
692 push [(image_himem bx).size]
693 endif
694 push eax
695 push 0
696 call_memcpy32:
697 push edx
698 else
699 mov ax,[word ((image_himem bx).fallback)]
700 mov dx,[word ((image_himem bx).fallback)+2]
701 mov cx,[word ((image_himem bx).buf)]
702 cmp ax,cx ; if (m->fallback != m->buf)
703 jnz @@do
704 cmp dx,[word ((image_himem bx).buf)+2]
705 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
706 @@do:
707 push [word ((image_himem bx).size)+2]
708 push [word ((image_himem bx).size)]
709 push [word ((image_himem bx).buf)+2]
710 push cx
711 xor cx,cx
712 push cx
713 call_memcpy32:
714 push dx
715 push ax
716 ifdef LARGE_IMAGES
717 jmp @@memcpy
718 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
719 p386
720 push ecx
721 push eax
722 push 0
723 push edx
724 ifdef NO386
725 p8086
726 endif
727 endif
728 endif
729 @@memcpy:
730 extrn _memcpy32:near
731 call near _memcpy32
732 add sp,14
733 @@skip:
734 ret
736 endp _memcpy_image
738 ;***************************************************************
739 ;void storepage(u32 *dst, u16 src);
740 ;***************************************************************
741 global _storepage:near
742 proc _storepage near
744 pop ax ;caller return address
745 pop bx
746 pop cx
747 push cx
748 push bx
749 push ax
750 ifndef NO386
751 mov edx,[bx]
752 else
753 mov ax,[bx]
754 mov dx,[bx+2]
755 endif
756 storepage: ; storepage(edx,cx)
757 ifndef NO386
758 push 0
759 push 4096
760 push 0
761 else
762 xor bx,bx
763 push bx
764 mov bh,4096/256
765 push bx
766 xor bx,bx
767 push bx
768 endif
769 push cx
770 push ds
771 jmp call_memcpy32
773 endp _storepage
776 ifdef LARGE_IMAGES
777 p386
778 ;***************************************************************
779 ;void reset_bufv(u32 *p);
780 ;***************************************************************
781 global _reset_bufv:near
782 proc _reset_bufv near
784 pop ax ;caller return address
785 pop bx
786 push bx
787 push ax
788 mov [curdata],bx
789 and [dword (data_himem bx).cacheidx],0
790 ret
792 endp _reset_bufv
794 ;***************************************************************
795 ;u32* prev_bufv();
796 ;u32* prev_bufv();
797 ;***************************************************************
798 global _prev_bufv:near
799 global _next_bufv:near
800 proc _prev_bufv near
802 stc
803 db 73h ; jnc
804 _next_bufv:
805 clc
806 sbb ax,ax
807 stc
808 rcl ax,1 ; -1/+1
809 xor ecx,ecx
810 push si
811 mov si,[curdata]
812 add ax,[(data_himem si).cacheidx]
813 test ax,0fc00h
814 jz @@gotpage
815 push ax ; FFFF / 0400
816 sar ax,8 ; FFFC / 0004
817 and al,0fch
818 add [(data_himem si).pageidx],ax
819 mov bx,[(data_himem si).pageidx]
820 lea bx,[(data_himem bx+si).page]
821 mov edx,ds
822 shl edx,4
823 lea cx,[(data_himem si).cache]
824 add edx,ecx
825 mov eax,[bx]
826 or eax,eax
827 jnz @@pageok
828 pop ax
829 xchg ax,bx
830 pop si
831 ret
832 @@pageok:
833 mov cx,4096
834 call memcpy_imagez ; get page
835 pop ax ; FFFF / 0400
836 cbw
837 shr ax,6 ; 03FF / 0000
838 @@gotpage:
839 mov [(data_himem si).cacheidx],ax
840 shl ax,2
841 xchg ax,bx
842 lea ax,[(data_himem bx+si).cache]
843 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
844 jnz @@notfirst2
845 xchg ax,si ; &first
846 @@notfirst2:
847 pop si
848 ret
850 endp _prev_bufv
851 endif
853 ifdef NO386
854 p8086
855 endif
857 ;***************************************************************
858 ;void open_image(const char *name, struct image_himem *m);
859 ;***************************************************************
860 global _open_image:near
861 proc _open_image near
863 pop cx ;caller return address
864 pop bx ; name
865 pop ax ; m
866 push ax
867 push bx
868 push cx
869 push di
870 xchg ax,di
871 mov [(image_himem di).next_chunk],offset next_chunk
872 mov [(image_himem di).state],bx
873 push bx
874 @@next:
875 call [(image_himem di).next_chunk] ; m->next_chunk()
876 ifndef NO386
877 add eax,3
878 and al,0FCh
879 add [(image_himem di).size],eax ; m->size += m->chunk_size
880 or eax,eax
881 else
882 add ax,3
883 adc dx,0
884 and al,0FCh
885 add [word (image_himem di).size],ax ; m->size += m->chunk_size
886 adc [word ((image_himem di).size)+2],dx
887 or ax,dx
888 endif
889 jnz @@next
890 pop [(image_himem di).state]
891 call [(image_himem di).next_chunk] ; m->next_chunk()
892 pop di
893 ret
895 endp _open_image
898 ;***************************************************************
899 ;int read_image(struct image_himem *m, char* data, int sz);
900 ;***************************************************************
901 global _read_image:near
902 proc _read_image near
904 arg m :word, \
905 data :word, \
906 sz :word = PARAM_SIZE
908 push bp
909 mov bp,sp
910 push di
911 ifndef NO386
912 push 0 ; return value
913 else
914 xor ax,ax
915 push ax
916 endif
917 mov di,[m]
918 @@loop:
919 ifndef NO386
920 movzx ecx,[word sz]
921 mov eax,[(image_himem di).chunk_size]
922 cmp ecx,eax
923 jb @@szok
924 else
925 mov cx,[word sz]
926 mov ax,[word (image_himem di).chunk_size]
927 cmp cx,ax
928 jb @@szok
929 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
930 jne @@szok
931 endif
932 xchg ax,cx
933 @@szok:
934 jcxz image_done
935 push cx
936 push [word data]
937 push [word di]
938 call _read
939 pop dx
940 pop bx
941 pop cx
942 jc image_done
943 add bx,ax
944 xor cx,cx
945 ifndef NO386
946 cwde ; ax < 8000h
947 sub [(image_himem di).chunk_size],eax
948 else
949 cwd ; ax < 8000h
950 sub [word (image_himem di).chunk_size],ax
951 sbb [word ((image_himem di).chunk_size)+2],dx
952 jnz @@fill
953 cmp [word (image_himem di).chunk_size],dx
954 endif
955 jnz @@fill
956 dec cx
957 @@fill:
958 test al,3
959 je @@filled
960 mov [bx],dh
961 inc bx
962 inc ax
963 jmp @@fill
964 @@filled:
965 ifndef NO386
966 sub [(image_himem di).remaining],eax
967 else
968 sub [word (image_himem di).remaining],ax
969 sbb [word ((image_himem di).remaining)+2],dx
970 endif
971 add [bp-2-2],ax
972 add [word data],ax
973 sub [word sz],ax
974 pushf
975 jcxz @@same_chunk
976 call [(image_himem di).next_chunk]
977 @@same_chunk:
978 popf
979 jnz @@loop
980 image_done:
981 pop ax
982 pop di bp
983 ret
985 endp _read_image
988 ;***************************************************************
989 ;unsigned long strtol(const char *s);
990 ;***************************************************************
991 global _strtol:near
992 proc _strtol near
994 ifndef NO386
995 pop ax ;caller return address
996 pop cx ; s
997 push cx
998 push ax
999 xor ebx,ebx
1000 push si
1001 jcxz @@end
1002 mov si,cx
1003 xor ecx,ecx
1004 xor eax,eax
1005 lodsb
1006 mov dx,ax
1007 or al,20h
1008 cmp al,'n' ; vga=normal
1009 je @@vga
1010 dec cx
1011 cmp al,'e' ; vga=extended
1012 je @@vga
1013 dec cx
1014 cmp al,'a' ; vga=ask
1015 jne @@notvga
1016 @@vga:
1017 dec cx
1018 xchg ax,cx
1019 cwd
1020 jmp @@popsiret
1021 @@notvga:
1022 mov cx,10 ; radix
1023 xchg ax,dx
1024 cmp al,'+'
1025 je @@radixskip
1026 cmp al,'-'
1027 clc
1028 jne @@radixkeep
1029 stc
1030 @@radixskip:
1031 lodsb
1032 @@radixkeep:
1033 pushf
1034 cmp al,'0'
1035 jne @@radixok
1036 mov cl,8
1037 lodsb
1038 or al,20h
1039 cmp al,'x'
1040 jne @@radixok
1041 mov cl,16
1042 @@strtollp:
1043 lodsb
1044 @@radixok:
1045 or al,20h
1046 sub al,'0'
1047 jb @@endstrtol
1048 cmp al,9
1049 jbe @@digitok
1050 cmp al,'a'-'0'
1051 jb @@endstrtol
1052 sub al,'a'-'0'-10
1053 @@digitok:
1054 cmp al,cl
1055 jae @@endstrtol
1056 xchg eax,ebx
1057 mul ecx
1058 add eax,ebx
1059 xchg eax,ebx
1060 jmp @@strtollp
1061 @@endstrtol:
1062 mov cl,10
1063 cmp al,'k'-'a'+10
1064 je @@shift
1065 mov cl,20
1066 cmp al,'m'-'a'+10
1067 je @@shift
1068 mov cl,30
1069 cmp al,'g'-'a'+10
1070 jne @@noshift
1071 @@shift:
1072 shl ebx,cl
1073 @@noshift:
1074 popf
1075 jnc @@end
1076 neg ebx
1077 @@end:
1078 push ebx
1079 pop ax
1080 pop dx
1081 @@popsiret:
1082 pop si
1083 else
1084 pop ax ;caller return address
1085 pop cx ; s
1086 push cx
1087 push ax
1088 push si
1089 push di
1090 xor ax,ax
1091 cwd
1092 jcxz @@goend
1093 xchg ax,di
1094 mov si,cx
1095 lodsb
1096 mov bx,ax
1097 or al,20h
1098 mov cx,-1
1099 cmp al,'n' ; vga=normal
1100 je @@vga
1101 dec cx
1102 cmp al,'e' ; vga=extended
1103 je @@vga
1104 dec cx
1105 cmp al,'a' ; vga=ask
1106 jne @@notvga
1107 @@vga:
1108 xchg ax,cx
1109 @@goend:
1110 jmp @@popdisiret
1111 @@notvga:
1112 mov cx,10 ; radix
1113 xchg ax,bx
1114 cmp al,'+'
1115 je @@radixskip
1116 cmp al,'-'
1117 clc
1118 jne @@radixkeep
1119 stc
1120 @@radixskip:
1121 lodsb
1122 @@radixkeep:
1123 pushf
1124 cmp al,'0'
1125 jne @@radixok
1126 mov cl,8
1127 lodsb
1128 or al,20h
1129 cmp al,'x'
1130 jne @@radixok
1131 mov cl,16
1132 @@strtollp:
1133 lodsb
1134 @@radixok:
1135 or al,20h
1136 sub al,'0'
1137 jb @@endstrtol
1138 cmp al,9
1139 jbe @@digitok
1140 cmp al,'a'-'0'
1141 jb @@endstrtol
1142 sub al,'a'-'0'-10
1143 @@digitok:
1144 cmp al,cl
1145 jae @@endstrtol
1147 push ax
1148 push si
1149 push dx
1150 xchg ax,di
1151 mul cx
1152 xchg ax,di
1153 xchg ax,dx
1154 xchg ax,si
1155 pop ax
1156 mul cx
1157 add ax,si
1158 pop si
1159 xchg ax,dx
1160 pop ax
1161 mov ah,0
1162 add di,ax
1163 adc dx,0
1165 jmp @@strtollp
1166 @@endstrtol:
1167 mov cl,10
1168 cmp al,'k'-'a'+10
1169 je @@shift
1170 mov cl,20
1171 cmp al,'m'-'a'+10
1172 je @@shift
1173 mov cl,30
1174 cmp al,'g'-'a'+10
1175 jne @@noshift
1176 @@shift:
1177 rcl di,1
1178 shl dx,1
1179 loop @@shift
1180 @@noshift:
1181 popf
1182 jnc @@end
1183 not dx
1184 neg di
1185 jne @@end
1186 inc dx
1187 @@end:
1188 xchg ax,di
1189 @@popdisiret:
1190 pop di
1191 pop si
1192 endif
1193 ret
1195 endp _strtol
1198 ifdef NO386
1199 ;***************************************************************
1200 ;u16 topseg();
1201 ;***************************************************************
1202 global _topseg:near
1203 proc _topseg near
1205 int 12h
1206 jnc @@max640k
1207 mov ax,640 ; 9000
1208 @@max640k:
1209 dec ax
1210 and al,0C0h
1211 mov cl,6
1212 shl ax,cl
1213 ret
1215 endp _topseg
1216 endif
1218 ifdef EXTRA
1219 p8086
1220 ;***************************************************************
1221 ;char *progname(void)
1222 ;***************************************************************
1223 global _progname:near
1224 proc _progname near
1226 push si di es
1227 mov ah,30h
1228 int 21h
1229 xor di,di
1230 cmp al,3
1231 mov ax,di
1232 jb @@skip
1233 ;mov es,[cs:2Ch]
1234 mov es,[di+2Ch]
1235 mov cx,sp ; big enough
1236 @@loop:
1237 repne
1238 scasb
1239 scasb
1240 jne @@loop
1241 inc di
1242 inc di
1243 mov si,di ; progname @es:di
1244 repne
1245 scasb
1246 mov cx,di
1247 sub cx,si ; progname len
1248 call malloc_or_die ; keep cx
1249 mov di,ax
1250 push ds
1251 push es
1252 pop ds
1253 pop es
1254 rep
1255 movsb
1256 push es
1257 pop ds
1258 @@skip:
1259 pop es di si
1260 ret
1262 endp _progname
1265 ;***************************************************************
1266 ;void chdirname(char *path)
1267 ;***************************************************************
1268 global _chdirname:near
1269 proc _chdirname near
1271 pop ax
1272 pop bx
1273 push bx
1274 push ax
1276 cmp [byte bx+1],3Ah ; ':'
1277 jne @@nodisk
1278 mov dl,20h
1279 or dl,[bx]
1280 sub dl,61h
1281 mov ah,0Eh
1282 int 21h
1283 inc bx
1284 inc bx
1285 @@nodisk:
1286 xor cx,cx
1287 @@next:
1288 mov al,[bx]
1289 cmp al,5Ch
1290 jne @@tsteos
1291 mov dx,bx
1292 inc cx
1293 @@tsteos:
1294 inc bx
1295 or al,al
1296 jnz @@next
1297 jcxz @@end
1298 mov bx,dx
1299 push [word bx]
1300 mov [bx],al
1301 stc
1302 mov ax,713Bh ; chdir long filename (ds:dx)
1303 int 21h
1304 mov ah,3Bh ; chdir(ds:dx)
1305 jnc @@chdirdone
1306 int 21h
1307 @@chdirdone:
1308 pop [word bx]
1309 @@end:
1310 ret
1312 endp _chdirname
1315 ;***************************************************************
1316 ;char *ultoa(unsigned long n);
1317 ;***************************************************************
1318 global _ultoa:near
1319 proc _ultoa near
1321 pop ax
1322 pop cx
1323 pop dx
1324 push dx
1325 push cx
1326 push ax ; DX:CX = n
1327 push si
1328 mov si,10
1329 mov bx,offset ultoabuf+11
1330 @@loop:
1331 dec bx
1332 xchg ax,dx
1333 xor dx,dx
1334 div si ; DX:AX = 0000:hi(n)
1335 xchg ax,cx ; CX = hi(n)/10
1336 div si ; DX:AX = hi(n)%10:lo(n)
1337 xchg ax,cx ; CX = lo(n/10)
1338 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
1339 add al,'0'
1340 mov [bx],al
1341 mov ax,cx
1342 or ax,dx
1343 jnz @@loop
1344 xchg ax,bx
1345 pop si
1346 ret
1348 endp _ultoa
1351 ;***************************************************************
1352 ;unsigned long kver2ul(char *kernel_version);
1353 ;***************************************************************
1354 global _kver2ul:near
1355 proc _kver2ul near
1357 pop bx
1358 pop ax
1359 push ax
1360 push bx
1361 push si
1362 xchg ax,si
1363 xor bx,bx
1364 mov cx,304h
1365 @@number:
1366 xor ax,ax
1367 cwd
1368 @@digit:
1369 shl al,cl
1370 shl ax,cl
1371 lodsb
1372 sub al,30h
1373 cmp al,9
1374 jbe @@digit
1375 mov dl,bh
1376 mov bh,bl
1377 mov bl,ah
1378 dec ch
1379 jnz @@number
1380 xchg ax,bx
1381 pop si
1382 kver2ulret:
1383 ret
1385 endp _kver2ul
1388 ;***************************************************************
1389 ;void try_default_args();
1390 ;***************************************************************
1391 global _try_default_args:near
1392 proc _try_default_args near
1394 mov bx,offset tazboot_cmd
1395 call open
1396 jc kver2ulret
1397 mov cx,4096
1398 mov di,[_heap_top]
1399 push cx
1400 extrn read_cmdline:near
1401 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1403 endp _try_default_args
1405 endif
1407 ends _TEXT
1409 end
1411 ;###### END OF FILE ############################################