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

polkit: CVE-2021-4034
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 28 11:07:11 2022 +0000 (2022-01-28)
parents e4805f18eb64
children
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT,_DATA,_BSS
19 assume cs:DGROUP,ds:DGROUP
21 segment _DATA byte public use16 'DATA'
23 loaderr db "Load failure",0
24 msg_hang db "Himem broken",0
25 ifdef VCPI
26 vcpi_alloc_err db "VCPI"
27 endif
28 global overflow:byte
29 overflow db "/"
30 msg_malloc db "Out of memory"
31 isorootofs dd 16*2048
33 ends _DATA
35 segment _BSS byte public use16 'BSS'
37 ifdef ISO9660
38 global _buf2k:byte
39 label _buf2k byte
40 db 2048 dup (?)
41 endif
42 global _buf4k:byte
43 label _buf4k byte
44 db 4096 dup (?)
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 ;***************************************************************
52 struc data_himem ;struct data_himem {
53 first dd ? ; 0 u32 first; *must* be the first one assume zero'd in bss
54 cacheidx dw ? ; 4 int cacheidx; byte * assume zero'd in bss
55 pageidx dw ? ; 6 int pageidx; byte * assume zero'd in bss
56 cache dd 1024 dup(?) ; 8 int cache;
57 page dd 1024 dup(?) ;4104 int page;
58 ends data_himem ;};
60 include "himem.inc"
63 ifdef NO386
64 p8086
65 endif
67 ifndef ISO9660
68 ;***************************************************************
69 ;_fastcall int:C open(bx:const char* name, const flags=O_RDONLY);
70 ;_fastcall int:C openargs(bx:const char* name, const flags=O_RDONLY);
71 ;***************************************************************
72 global openargs:near ; openargs(bx)
73 openargs:
74 cmp [byte bx],'@'
75 jne fail
76 inc bx
78 global @open$qpxzc:near
79 @open$qpxzc:
80 endif
81 opendos:
82 ifdef LONG_FILENAME
83 mov ax,716Ch
84 push bx si
85 mov si,bx
86 xor bx,bx ; R/O
87 cwd ; action = open
88 stc
89 int 21h
90 pop si dx
91 ifdef ISO9660
92 jnc @@openok
93 else
94 jnc dosret
95 endif
96 else
97 mov dx,bx ; open(DS:DX=filename,al=access,cl=attributes)
98 endif
99 mov ax,3d00h ; read-only+compatibility
100 ifdef ISO9660
101 call dos
102 jc @@openret
103 @@openok:
104 xchg ax,bx
105 mov ax,4202h
106 cwd
107 xor cx,cx
108 int 21h
109 mov [word _isostate.filesize],ax
110 mov [(word _isostate.filesize)+2],dx
111 xchg ax,bx
112 ;xor cx,cx
113 cwd
114 call seeksetpos0 ; filepos = 0
115 xchg ax,bx ; fd
116 @@openret:
117 ret
118 else
119 jmp dos
120 endif
122 ifdef ISO9660
124 include "isostate.inc"
125 extrn _isostate:isostate
127 ;***************************************************************
128 ;_fastcall int:C open(bx:const char* name, const flags=O_RDONLY);
129 ;_fastcall int:C openargs(bx:const char* name, const flags=O_RDONLY);
130 ;***************************************************************
131 global openargs:near ; openargs(bx)
132 openargs:
133 cmp [byte bx],'@'
134 jne fail
135 inc bx
137 global @open$qpxzc:near
138 @open$qpxzc:
139 mov ax,[_isostate.fd]
140 or ax,ax
141 jz opendos
142 ifdef ISOHOOK
143 cmp [byte bx],'!'
144 je @readmenu$qv
145 endif
146 extrn @_isoopen$qv:near
147 mov [word _isostate.filename2open],bx
148 jmp @_isoopen$qv ; filepos = 0
149 endif
152 ;***************************************************************
153 ;_fastcall int fileexist(bx:const char* name);
154 ;***************************************************************
155 global @fileexist$qpxzc:near
156 @fileexist$qpxzc:
157 call @open$qpxzc
158 jc failifc
160 ;***************************************************************
161 ;_fastcall int close(ax:int fd);
162 ;***************************************************************
163 global @close$qi:near
164 proc @close$qi near
166 global close:near ; close(ax)
167 close:
168 mov bh,3Eh ; close(AX:handle)
169 ifdef ISO9660
170 mov cx,[_isostate.fd]
171 jcxz dosbx
172 ret
173 else
174 jmp dosbx
175 endif
177 endp @close$qi
180 ;***************************************************************
181 ;_fastcall int readrm(si:struct himem *m, ax:int sz);
182 ;***************************************************************
183 global @readrm$qp11image_himemi:near
184 @readrm$qp11image_himemi:
185 xchg ax,dx ; sz
186 mov ax,[si] ; fd
187 mov bx,[si-2] ; data
188 proc @read$qipvi near
190 @read$dxbxax: ; dx:size bx:data ax:fd
191 xchg ax,bx ; fd
192 @read$dxaxbx: ; dx:size ax:data bx:fd
193 xchg ax,dx ; data
194 xchg ax,cx ; sz
195 global @read$cxdxbx:near
196 @read$cxdxbx: ; cx:size dx:data bx:fd
197 ifdef ISO9660
198 push bx
199 mov bx,offset _isostate.filepos
200 push cx
201 les cx,[bx-4] ; filesize
202 sub cx,[bx] ; filepos
203 mov ax,es
204 sbb ax,[bx+2]
205 pop ax
206 ;jb fail ; filepos > filesize ???
207 jne @@axok
208 cmp cx,ax
209 jb @@cxok
210 @@axok:
211 xchg ax,cx
212 @@cxok:
213 add [bx],cx
214 adc [(word bx)+2],0
215 pop bx
216 endif
217 readfd:
218 mov ah,3Fh ; read(BX=handle,DS:DX=to,CX=count)
219 ;jcxz fail
220 dos:
221 int 21h
222 jnc dosret
223 fail:
224 stc
225 failifc:
226 sbb ax,ax ; ax=-1 CF
227 dosret:
228 ret
230 endp @read$qipvi
232 ;***************************************************************
233 ;_fastcall long rewind(ax:int fd);
234 ;***************************************************************
236 global @rewind$qi:near ; fd=ax
237 proc @rewind$qi near
239 rewind:
240 ifdef ISO9660
241 mov bx,offset _isostate.fileofs
242 jmp lseek
243 else
244 mov bl,0
245 lseek0:
246 xor cx,cx
247 xor dx,dx
248 jmp lseek
249 endif
251 endp @rewind$qi
254 ifdef ISOHOOK
255 ;***************************************************************
256 ;_fastcall int:bx readmenu(void);
257 ;***************************************************************
258 proc @readmenu$qv near
260 mov dx,20
261 xor cx,cx
262 call seeksetpos0 ; filepos = 0
263 mov dx,offset _isostate.fileofs
264 mov cl,8
265 push dx
266 call readfd ; // read x->fileofs & x->filesize
267 pop bx
268 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
269 mov ax,7FF0h ; old way : up to md5 signature
270 @@oldway:
271 xor ax,6FF0h ; new way : between Apple partitions = up to 1000h
272 neg [word bx+4] ; fix x->filesize
273 js @@oldway
274 cwd
275 mov [word bx+6],dx
276 sub ax,[bx+4]
277 mov [word bx+2],dx
278 mov [bx],ax
279 call isolseek ; filepos = 0
280 xchg ax,bx ; fd
281 ret
283 endp @readmenu$qv
284 endif
286 ;***************************************************************
287 ;_fastcall void isolseek(bx:const unsigned long *offset);
288 ;***************************************************************
289 global @isolseek$qpxul:near
290 proc @isolseek$qpxul near
292 ifdef ISO9660
293 isolseek:
294 mov ax,[_isostate.fd]
295 lseek:
296 les dx,[dword bx]
297 mov cx,es
298 seeksetpos0:
299 xor bx,bx
300 mov [word _isostate.filepos],bx
301 mov [(word _isostate.filepos)+2],bx
302 else
303 lseek:
304 endif
305 mov bh,42h ; bx=fd cx:dx=offset al=whence
306 dosbx:
307 xchg ax,bx
308 or bx,bx
309 jne dos ; bx = fd
310 ret
312 endp @isolseek$qpxul
314 ifdef ISO9660
315 ;***************************************************************
316 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
317 ;_fastcall int isoreadrootsector(void);
318 ;***************************************************************
319 global @isoreadrootsector$qv:near
320 @isoreadrootsector$qv:
321 mov bx,offset isorootofs
322 global @isoreadsector$qpxul:near
323 proc @isoreadsector$qpxul near
325 call isolseek ; filepos = 0
326 jc failifc
327 mov cx,2048
328 mov dx,offset _buf2k
329 jmp readfd ; read(fd,buf2k,2048)
331 endp @isoreadsector$qpxul
332 endif
335 ifdef ISO9660
336 ifdef ISOHOOK
337 ;***************************************************************
338 ;_fastcall int strhead(ax:const char* a, bx:const char* b);
339 ;***************************************************************
340 global @strhead$qpxzct1:near
341 proc @strhead$qpxzct1 near
343 @@loop:
344 mov dh,[bx] ; dh = *b++
345 inc bx
346 xchg ax,bx
347 or dh,dh ; clear C
348 jz failifc ; return 0, bx=a tail, dh=0
349 xor dh,[bx] ; dh -= *a++
350 jne fail ; return -1
351 inc bx
352 xchg ax,bx
353 jmp @@loop
355 endp @strhead$qpxzct1
358 ;***************************************************************
359 ;_fastcall int strcmp(ax:const char* a, bx:const char* b);
360 ;***************************************************************
361 global @strcmp$qpxzct1:near
362 proc @strcmp$qpxzct1 near
364 call @strhead$qpxzct1
365 or dh,[bx] ; clear C
366 jne fail ; return -1
367 jmp failifc ; return 0, dh=0
369 endp @strcmp$qpxzct1
371 else
373 ;***************************************************************
374 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
375 ;***************************************************************
376 global @strcmp$qpxzct1:near
377 proc @strcmp$qpxzct1 near
379 @@loop:
380 xchg ax,bx
381 mov dl,[bx] ; dl = *b++
382 inc bx
383 xchg ax,bx
384 xor dl,[bx] ; dl ^= *a++
385 ifndef RAW_ISO9660
386 ifndef ROCKRIDGE
387 and dl,0dfh ; case insensitive
388 endif
389 endif
390 jne fail ; return -1
391 inc bx
392 or dl,dl ; clear C
393 jz failifc ; return 0
394 jmp @@loop
396 endp @strcmp$qpxzct1
397 endif
398 endif
400 ;***************************************************************
401 ;_fastcall void puts(bx:const char* s):
402 ;***************************************************************
403 global @puts$qpxzc:near
405 ; global puts:near ; puts(bx)
406 @putsz:
407 call @putc
408 @puts$qpxzc:
409 puts:
410 mov dl,[bx]
411 inc bx
412 or dl,dl
413 jne @putsz
414 mov dl,10
415 @putc:
416 cmp dl,10
417 jne @putcz
418 call @putcz2
419 @putcz2:
420 xor dl,7 ; 10^13 1010^1101
421 @putcz:
422 mov ah,2
423 do_int21h:
424 int 21h
425 ret
427 ;***************************************************************
428 ;_fastcall char* malloc_or_die(ax:unsigned size);
429 ;***************************************************************
430 xchg_heap_top:
431 xchg ax,[bx]
432 ret
434 proc @malloc_or_die$qui near
436 malloc_or_die: ; ax = malloc_or_die(ax)
437 extrn _heap_top
438 mov bx,offset _heap_top
439 add ax,[bx]
440 jnc xchg_heap_top
441 mov bx,offset msg_malloc
443 endp @malloc_or_die$qui
446 ;***************************************************************
447 ;_fastcall int die(bx:const char* msg);
448 ;int exit(ax:int status);
449 ;int abort(void);
450 ;***************************************************************
451 global @die$qpxzc:near
452 proc @die$qpxzc near
453 @die$qpxzc:
454 global die:near ; die(bx)
455 die:
456 call puts
457 global @exit$qv:near
458 @exit$qv:
459 _exit:
460 extrn _imgs:image_himem
461 mov cx,[(word _imgs.buf)+2] ; no_exit ?
462 mov ah,4Ch
463 jcxz do_int21h
464 mov bx, offset msg_hang
465 call puts
466 ; global _abort:near
467 _abort:
468 cli
469 hlt
470 jmp _abort
472 endp @die$qpxzc
474 ;***************************************************************
475 ;_fastcall void open_image(si:struct image_himem *m, ax:const char *name);
476 ;***************************************************************
478 global @open_image$qp11image_himempxzc:near
479 proc @open_image$qp11image_himempxzc near
481 mov [(image_himem si).state],ax
482 push ax
483 @@next:
484 call next_chunk
485 ifndef NO386
486 add eax,3
487 and al,0FCh
488 add [(image_himem si).size],eax ; m->size += m->chunk_size size zero'd in bss
489 or eax,eax
490 else
491 add ax,3
492 adc dx,0
493 and al,0FCh
494 add [word (image_himem si).size],ax ; m->size += m->chunk_size size zero'd in bss
495 adc [word ((image_himem si).size)+2],dx
496 or ax,dx
497 endif
498 jnz @@next
499 pop [(image_himem si).state]
501 endp @open_image$qp11image_himempxzc
503 ;***************************************************************
504 ;static long next_chunk(struct image_himem *si);
505 ;***************************************************************
506 proc next_chunk near
508 ifndef NO_CLOSE
509 mov ax,[(image_himem si).fd]
510 call close
511 endif
512 ifndef NO386
513 xor eax,eax
514 else
515 xor ax,ax
516 cwd
517 endif
518 mov [(image_himem si).fd],ax
519 mov bx,[(image_himem si).state]
520 cmp al,[bx] ; ""
521 jz @@end
522 push di
523 @@scan:
524 mov al,[bx]
525 mov di,bx
526 or al,al
527 jz @@eos
528 inc bx
529 sub al,','
530 jnz @@scan
531 @@eos:
532 xchg [(image_himem si).state],bx ; set start of string
533 mov [current_file],bx
534 xchg [di],ax ; set temp eos (ax == 0)
535 push ax
536 call @open$qpxzc
537 pop [word di] ; restore string
538 pop di
539 jnc @@opened
540 loadfailure:
541 ;***************************************************************
542 ;_fastcall void loadfailure(void);
543 ;***************************************************************
544 global @loadfailure$qv:near
545 @loadfailure$qv:
546 mov bx,0
547 org $-2
548 current_file dw ?
549 call puts
550 mov bx,offset loaderr
551 jmpdie:
552 jmp die
553 @@opened:
554 mov [(image_himem si).fd],ax
555 ifndef NO_CLOSE
556 mov [(image_himem si).fd2close],ax
557 endif
558 ifdef ISO9660
559 ifndef NO386
560 mov eax,[_isostate.filesize]
561 else
562 les ax,[_isostate.filesize]
563 mov dx,es
564 endif
565 else
566 mov bl,02h ; SEEK_END
567 call lseek0
568 ifndef NO386
569 push eax
570 mov ax,[(image_himem si).fd]
571 call rewind
572 pop eax
573 else
574 push ax
575 push dx
576 mov ax,[(image_himem si).fd]
577 call rewind
578 pop dx
579 pop ax
580 endif
581 endif
582 @@end:
583 ifndef NO386
584 mov [(image_himem si).chunk_size],eax
585 else
586 mov [word (image_himem si).chunk_size],ax
587 mov [word ((image_himem si).chunk_size)+2],dx
588 endif
589 ret
591 endp next_chunk
593 ifdef VCPI
594 p386
595 ;***************************************************************
596 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
597 ;***************************************************************
598 global @malloc_bufv_or_die$qp11image_himem:near
599 proc @malloc_bufv_or_die$qp11image_himem near
601 p386
602 ;mov ecx,[(image_himem si).size]
603 ;shr ecx,20 ; pages index size = size >> 20
604 ;mov ax,cx
605 ;add ax,size data_himem-4096
606 mov ax,size data_himem
607 call malloc_or_die
608 ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
609 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
610 add ecx,[(image_himem si).size]
611 shr ecx,12
612 mov [(image_himem si).bufv],ax ; update m->bufv
613 xchg ax,di
614 @@vcpi_alloc:
615 mov ax,0DE04h ; allocate a 4K page => EDX
616 int 67h
617 or ah,ah
618 mov bx,offset vcpi_alloc_err
619 jnz jmpdie
620 ; for (i = cnt-1; i >= 0; i--)
621 ; if (edx < pm.fallback+pm.size) again
622 mov bx,offset _imgs.fallback+size image_himem
623 mov eax,[bx-2+6-size image_himem] ; pm.size
624 add eax,[bx-2+2-size image_himem]
625 cmp eax,edx ; pm.fallback+pm.size <= edx ?
626 ja @@vcpi_alloc
627 mov eax,ecx
628 dec eax
629 shl eax,12 ; i*_4k
630 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
631 add eax,[bx-2+2] ; +initrd.fallback
632 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
633 ja @@initrdok
634 mov eax,[bx-2+6] ; initrd.size
635 add eax,[bx-2+2] ; +initrd.fallback
636 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
637 ja @@vcpi_alloc
638 @@initrdok:
639 cmp [(data_himem di).first],0 ; zero'd in bss
640 jne @@notfirst
641 mov [(data_himem di).first],edx
642 @@notfirst:
643 mov bx,[(data_himem di).cacheidx] ; zero'd in bss
644 cmp bh,10h
645 jae @@nextpage
646 add [(data_himem di).cacheidx],4
647 mov [(data_himem bx+di).cache],edx ; cache[cacheidx++] = edx
648 loopd @@vcpi_alloc
649 mov [(data_himem bx+di).cache],ecx ; last is 0
650 @@nextpage:
651 and [(data_himem di).cacheidx],0
652 mov bx,[(data_himem di).pageidx] ; zero'd in bss
653 mov [(data_himem bx+di).page],edx
654 add [(data_himem di).pageidx],4
655 push cx
656 lea cx,[(data_himem di).cache]
657 ifdef NO386
658 push edx
659 pop ax ; to es:ax
660 pop es
661 endif
662 call storepage ; storepage(edx/es:ax,cx)
663 pop cx
664 or ecx,ecx ; clear C
665 jnz @@vcpi_alloc
667 endp @malloc_bufv_or_die$qp11image_himem
669 ;***************************************************************
670 ;_fastcall void reset_bufv(di:u32 *p);
671 ;***************************************************************
672 global @reset_bufv$qpul:near
673 proc @reset_bufv$qpul near
675 mov [curdata],di
676 and [dword (data_himem di).cacheidx],0 ; and pageidx=0
677 ret
679 endp @reset_bufv$qpul
680 p8086
681 endif
683 ;===============================================================
685 ifdef VCPI
686 p386
687 ;***************************************************************
688 ;u32* di=prev_bufv();
689 ;u32* di=prev_bufv();
690 ;***************************************************************
691 global _prev_bufv:near
692 global _next_bufv:near
693 proc _prev_bufv near
695 mov al,-4
696 db 0A9h ; test ax,imm
697 _next_bufv:
698 mov al,4
699 cbw
700 push si
701 mov bx,0
702 org $-2
703 curdata dw ?
704 add ax,[(data_himem bx).cacheidx] ; -4/+4
705 mov si,0fffh
706 and si,ax
707 mov [(data_himem bx).cacheidx],si
708 xor ecx,ecx
709 sar ax,12-2
710 test al,4
711 jz @@gotpage ; neither -4 nor 4 ?
712 add [(data_himem bx).pageidx],ax
713 mov di,[(data_himem bx).pageidx]
714 lea di,[(data_himem bx+di).page]
715 mov edx,ds
716 shl edx,4
717 lea cx,[(data_himem bx).cache]
718 add edx,ecx
719 mov eax,[di]
720 or eax,eax
721 jz @@ret
722 mov cx,4096 ; get page
723 call memcpy_imagez ; memcpy_imagez(edx,eax,ecx)
724 @@gotpage:
725 lea ax,[(data_himem bx+si).cache]
726 or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
727 jnz @@notfirst2
728 xchg ax,bx ; &first
729 @@notfirst2:
730 xchg ax,di
731 @@ret:
732 pop si
733 ret
735 endp _prev_bufv
736 endif
738 ;===============================================================
740 ifdef NO386
741 p8086
742 endif
744 ;***************************************************************
745 ;_fastcall void memcpy_image_initrd(si:struct image_himem *m);
746 ;_fastcall void memcpy_image_kernel(si:struct image_himem *m);
747 ;_fastcall void memcpy_image(bx:struct image_himem *m);
748 ;***************************************************************
749 global @memcpy_image_initrd$qv:near
750 @memcpy_image_initrd$qv:
751 lea bx,[si+size image_himem]
752 db 0A9h ; test ax,imm
753 global @memcpy_image_kernel$qv:near
754 @memcpy_image_kernel$qv:
755 mov bx,si
756 proc @memcpy_image$qp11image_himem near
758 ifndef NO386
759 mov edx,[(image_himem bx).fallback]
760 mov eax,[(image_himem bx).buf]
761 cmp eax,edx ; if (m->fallback != m->buf)
762 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
763 mov ecx,[(image_himem bx).size]
764 else
765 les cx,[((image_himem bx).buf)]
766 mov dx,es
767 les ax,[((image_himem bx).fallback)]
768 ;cmp ax,cx ; if (m->fallback != m->buf)
769 ;jnz @@do
770 ;cmp dx,[word ((image_himem bx).fallback)+2]
771 ;jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
772 @@do:
773 push [((image_himem bx).size)]
774 xor bx,bx
775 call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
776 push dx ; [word ((image_himem bx).buf)+2]
777 push cx ; [word ((image_himem bx).buf)]
778 push bx
779 push es ; push es:ax
780 push ax
781 jmp @@memcpy
782 endif
783 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
784 p386
785 push ecx
786 push eax
787 push 0
788 ifndef NO386
789 call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size)
790 endif
791 push edx
792 ifdef NO386
793 p8086
794 endif
795 @@memcpy:
796 extrn memcpy32:near
797 call near memcpy32
798 @@skip:
799 ret
801 global movedend:near
802 movedend:
804 endp @memcpy_image$qp11image_himem
806 ;***************************************************************
807 ;_fastcall void storepage(di:u32 *dst);
808 ;***************************************************************
809 global @storepage$qpul:near
810 proc @storepage$qpul near
812 ifndef NO386
813 mov edx,[di]
814 else
815 les ax,[dword di]
816 endif
817 mov cx,offset _buf4k
818 storepage: ; storepage(edx,cx)
819 ifndef NO386
820 push 0
821 push 4096
822 push 0
823 push cx
824 push ds ; call_memcpy32(to=edx,fromseg,fromofs,size)
825 else
826 xor dx,dx
827 push dx ; 0
828 mov bx,4096
829 push bx ; 4096
830 mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
831 endif
832 jmp call_memcpy32
834 endp @storepage$qpul
836 ;===============================================================
838 ;***************************************************************
839 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
840 ;***************************************************************
841 global @strcatb$qpxzct1:near
842 proc @strcatb$qpxzct1 near
844 push si
845 xchg ax,si ; b
846 dec bx
847 @@catlp:
848 inc bx
849 cmp [byte bx],0 ; a=bx
850 jne @@catlp
851 db 0b8h,20h ; mov ax,??20h
852 @@cpylp:
853 lodsb
854 mov [bx],al
855 inc bx
856 or al,al
857 jne @@cpylp
858 pop si
859 ret
861 endp @strcatb$qpxzct1
863 ;***************************************************************
864 ;_fastcall int read_image(si:struct image_himem *m);
865 ;***************************************************************
866 global @read_image$qp11image_himem:near
867 proc @read_image$qp11image_himem near
869 push di
870 xor di,di
871 @@loop:
872 ifndef NO386
873 xor ecx,ecx
874 mov ch,4096/256
875 sub cx,di
876 mov eax,[(image_himem si).chunk_size]
877 cmp ecx,eax
878 jb @@szok
879 else
880 mov cx,4096
881 sub cx,di
882 mov ax,[word (image_himem si).chunk_size]
883 cmp cx,ax
884 jb @@szok
885 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
886 jne @@szok
887 endif
888 xchg ax,cx
889 @@szok:
890 jcxz @@image_done
891 lea dx,[di+_buf4k]
892 mov bx,[(image_himem si).fd]
893 call @read$cxdxbx
894 jb @@image_done
895 add di,ax
896 ifndef NO386
897 cwde ; ax < 8000h
898 cdq
899 sub [(image_himem si).chunk_size],eax
900 else
901 cwd ; ax < 8000h
902 sub [word (image_himem si).chunk_size],ax
903 sbb [word ((image_himem si).chunk_size)+2],dx
904 endif
905 @@fill:
906 test al,3
907 je @@filled
908 mov [di+_buf4k],dl
909 inc di
910 inc ax
911 jmp @@fill
912 @@filled:
913 ifndef NO386
914 sub [(image_himem si).remaining],eax
915 or edx,[word (image_himem si).chunk_size]
916 else
917 sub [word (image_himem si).remaining],ax
918 sbb [word ((image_himem si).remaining)+2],dx
919 mov ax,[word (image_himem si).chunk_size]
920 or ax,[word ((image_himem si).chunk_size)+2]
921 endif
922 jnz @@same_chunk
923 call next_chunk
924 @@same_chunk:
925 jmp @@loop
926 @@image_done:
927 xchg ax,di
928 pop di
929 ret
931 endp @read_image$qp11image_himem
933 ;===============================================================
935 ;***************************************************************
936 ;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
937 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
938 ;***************************************************************
939 global @argstr$qpxzcxt1ppxzc:near
940 proc @argstr$qpxzcxt1ppxzc near
942 mov cl,2
943 db 0a9h ; test ax,#
944 global @argnum$qpzcxpxzcpul:near
945 @argnum$qpzcxpxzcpul:
946 mov cl,4
947 push bx
948 xchg ax,bx ; keywords -> bx
949 xchg ax,cx ; s -> cx
950 cbw ; argstr:0002 argnum:0004
951 xchg ax,dx ; vars -> ax
952 push si di
953 xchg ax,di ; vars => di
954 dec bx
955 sub di,dx
956 @@loop:
957 add di,dx
958 mov si,cx ; s
959 @@match:
960 lodsb ; *s++
961 or al,20h ; locase
962 ;ifdef DOS_SWITCH
963 cmp al,'/' ; 2f
964 jne @@notopt
965 mov al,'-'
966 ;endif
967 @@notopt:
968 inc bx ; keywords++
969 cmp al,[bx]
970 je @@match
971 cmp [byte bx],dh
972 je @@lastal
973 cmp [byte bx],'|'
974 je @@testal
975 jl @@notsw ; } ~ <del>
976 ;mov dl,1
977 cmp al,20h ; EOS or 20h
978 jne @@loop ; assume [bx] = '|'
979 @@notsw:
980 mov al,-1
981 jne @@notopt
982 jmp @@setnum2
983 @@testal:
984 cmp al,-1
985 jz @@loop
986 @@lastal:
987 cmp al,'='
988 xchg ax,cx ; return s if failure
989 jne @@nokeyword
990 dec dx
991 dec dx
992 je @@done
993 @strtol$qpxzc:
994 ifndef NO386
995 xor ecx,ecx
996 xor ebx,ebx
997 else
998 xor bx,bx
999 xor cx,cx
1000 xor dx,dx
1001 endif
1002 lodsb
1003 or al,20h
1004 cmp al,'a'
1005 jb @@notvga
1006 sub al,'o'
1007 @@vgaloop:
1008 dec cx
1009 add al,6
1010 jnb @@vgaloop ; vga=normal,extended,ask
1011 @@vga:
1012 xchg ax,cx
1013 ;cwd
1014 jmp @@end
1015 @@endstrtol:
1016 mov cl,10
1017 cmp al,'k'-'a'+10
1018 je @@shift
1019 mov cl,20
1020 cmp al,'m'-'a'+10
1021 je @@shift
1022 mov cl,30
1023 cmp al,'g'-'a'+10
1024 ifndef NO386
1025 jne @@noshift
1026 @@shift:
1027 shl ebx,cl
1028 @@noshift:
1029 popf
1030 jnc @@end2
1031 neg ebx
1032 @@end2:
1033 push ebx
1034 pop ax
1035 pop dx
1036 else
1037 @@shift:
1038 xchg ax,bx
1039 jne @@noshift
1040 extrn N_LXLSH@:near
1041 call N_LXLSH@
1042 @@noshift:
1043 popf
1044 jne @@end
1045 not dx
1046 neg ax
1047 jne @@end
1048 inc dx
1049 endif
1050 @@end:
1051 @@setnum:
1052 mov [di+2],dx
1053 @@setnum2:
1054 xchg ax,si
1055 @@done:
1056 mov [di],si
1057 xchg ax,di
1058 @@nokeyword:
1059 pop di si bx
1060 ret
1062 @@notvga:
1063 mov cl,10 ; radix
1064 cmp al,'-'
1065 jne @@radixkeep
1066 lodsb
1067 @@radixkeep:
1068 pushf
1069 cmp al,'0'
1070 jne @@radixok
1071 mov cl,8
1072 lodsb
1073 or al,20h
1074 cmp al,'x'
1075 jne @@radixok
1076 mov cl,16
1077 @@strtollp:
1078 lodsb
1079 @@radixok:
1080 or al,20h
1081 sub al,'0'
1082 jb @@endstrtol
1083 cmp al,9
1084 jbe @@digitok
1085 cmp al,'a'-'0'
1086 jb @@endstrtol
1087 sub al,'a'-'0'-10
1088 @@digitok:
1089 cmp al,cl
1090 jae @@endstrtol
1091 cbw
1092 ifndef NO386
1093 cwde
1094 xchg eax,ebx
1095 mul ecx
1096 add ebx,eax
1097 else
1098 push ax
1099 xchg ax,dx
1100 mul cx
1101 xchg ax,bx
1102 mul cx
1103 add dx,bx
1104 pop bx
1105 add bx,ax
1106 adc dx,0
1107 endif
1108 jmp @@strtollp
1110 endp @argstr$qpxzcxt1ppxzc
1112 ;===============================================================
1114 ends _TEXT
1116 end
1118 ;###### END OF FILE ############################################