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

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