wok diff linld/stuff/src/CRTL.ASM @ rev 24034
Openssh (8.5p1)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 08 09:21:26 2021 +0000 (2021-04-08) |
parents | 217c02cbbe8d |
children | 06547d8cf241 |
line diff
1.1 --- a/linld/stuff/src/CRTL.ASM Sun Mar 14 19:55:20 2021 +0000 1.2 +++ b/linld/stuff/src/CRTL.ASM Thu Apr 08 09:21:26 2021 +0000 1.3 @@ -2,7 +2,7 @@ 1.4 ;****** This file is distributed under GPL 1.5 ;*************************************************************** 1.6 ideal 1.7 - %PAGESIZE 1000 1.8 + %PAGESIZE 255 1.9 %crefref 1.10 %noincl 1.11 %nomacs 1.12 @@ -47,6 +47,258 @@ 1.13 1.14 segment _TEXT byte public use16 'CODE' 1.15 1.16 + ifdef VCPI 1.17 + p386 1.18 +;*************************************************************** 1.19 + 1.20 +struc data_himem ;struct data_himem { 1.21 +first dd ? ; 0 u32 first; *must* be the first one assume zero'd in bss 1.22 +cacheidx dw ? ; 4 int cacheidx; quad * assume zero'd in bss 1.23 +pageidx dw ? ; 6 int pageidx; byte * assume zero'd in bss 1.24 +cache dd 1024 dup(?) ; 8 int cache; 1.25 +page dd 1024 dup(?) ;4104 int page; 1.26 +ends data_himem ;}; 1.27 + 1.28 + include "himem.inc" 1.29 + 1.30 +;*************************************************************** 1.31 +;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m); 1.32 +;*************************************************************** 1.33 + global @malloc_bufv_or_die$qp11image_himem:near 1.34 + proc @malloc_bufv_or_die$qp11image_himem near 1.35 + 1.36 + p386 1.37 + ;mov ecx,[(image_himem si).size] 1.38 + ;shr ecx,20 ; pages index size = size >> 20 1.39 + ;mov ax,cx 1.40 + ;add ax,size data_himem-4096 1.41 + mov ax,size data_himem 1.42 + call malloc_or_die 1.43 + ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; 1.44 + mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; 1.45 + add ecx,[(image_himem si).size] 1.46 + shr ecx,12 1.47 + mov [(image_himem si).bufv],ax ; update m->bufv 1.48 + xchg ax,di 1.49 +@@vcpi_alloc: 1.50 + mov ax,0DE04h ; allocate a 4K page => EDX 1.51 + int 67h 1.52 + or ah,ah 1.53 + mov bx,offset vcpi_alloc_err 1.54 + jnz jmpdie 1.55 +; for (i = cnt-1; i >= 0; i--) 1.56 +; if (edx < pm.fallback+pm.size) again 1.57 + mov bx,offset _imgs.fallback+size image_himem 1.58 + mov eax,[bx-2+6-size image_himem] ; pm.size 1.59 + add eax,[bx-2+2-size image_himem] 1.60 + cmp eax,edx ; pm.fallback+pm.size <= edx ? 1.61 + ja @@vcpi_alloc 1.62 + mov eax,ecx 1.63 + dec eax 1.64 + shl eax,12 ; i*_4k 1.65 +; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again 1.66 + add eax,[bx-2+2] ; +initrd.fallback 1.67 + cmp eax,edx ; initrd.fallback+i*_4k > edx ? 1.68 + ja @@initrdok 1.69 + mov eax,[bx-2+6] ; initrd.size 1.70 + add eax,[bx-2+2] ; +initrd.fallback 1.71 + cmp eax,edx ; initrd.fallback+initrd.size > edx ? 1.72 +@@ja_vcpi_alloc: 1.73 + ja @@vcpi_alloc 1.74 +@@initrdok: 1.75 + cmp [(data_himem di).first],0 ; zero'd in bss 1.76 + jne @@notfirst 1.77 + mov [(data_himem di).first],edx 1.78 +@@notfirst: 1.79 + mov bx,[(data_himem di).cacheidx] ; zero'd in bss 1.80 + cmp bh,4 1.81 + jae @@nextpage 1.82 + shl bx,2 1.83 + inc [(data_himem di).cacheidx] 1.84 + mov [(data_himem bx+di).cache],edx ; cache[cacheidx++] = edx 1.85 + loopd @@vcpi_alloc 1.86 + mov [(data_himem bx+di).cache],ecx ; last is 0 1.87 +@@nextpage: 1.88 + and [(data_himem di).cacheidx],0 1.89 + mov bx,[(data_himem di).pageidx] ; zero'd in bss 1.90 + mov [(data_himem bx+di).page],edx 1.91 + add [(data_himem di).pageidx],4 1.92 + push cx 1.93 + lea cx,[(data_himem di).cache] 1.94 + ifdef NO386 1.95 + push edx 1.96 + pop ax ; to es:ax 1.97 + pop es 1.98 + endif 1.99 + call storepage ; storepage(edx/es:ax,cx) 1.100 + pop cx 1.101 + or ecx,ecx ; clear C 1.102 + jnz @@ja_vcpi_alloc 1.103 + 1.104 + endp @malloc_bufv_or_die$qp11image_himem 1.105 + 1.106 +;*************************************************************** 1.107 +;_fastcall void reset_bufv(di:u32 *p); 1.108 +;*************************************************************** 1.109 + global @reset_bufv$qpul:near 1.110 + proc @reset_bufv$qpul near 1.111 + 1.112 + mov [curdata],di 1.113 + and [dword (data_himem di).cacheidx],0 ; and pageidx=0 1.114 + ret 1.115 + 1.116 + endp @reset_bufv$qpul 1.117 + 1.118 +;*************************************************************** 1.119 +;u32* di=prev_bufv(); 1.120 +;u32* di=prev_bufv(); 1.121 +;*************************************************************** 1.122 + global _prev_bufv:near 1.123 + global _next_bufv:near 1.124 + proc _prev_bufv near 1.125 + 1.126 + stc 1.127 + db 73h ; jnc 1.128 +_next_bufv: 1.129 + clc 1.130 + push si 1.131 + mov bx,0 1.132 + org $-2 1.133 +curdata dw ? 1.134 + sbb ax,ax 1.135 + cmc 1.136 + adc ax,[(data_himem bx).cacheidx] ; -1/+1 1.137 + mov si,3ffh 1.138 + and si,ax 1.139 + mov [(data_himem bx).cacheidx],si 1.140 + shl si,2 1.141 + xor ecx,ecx 1.142 + test ax,0fc00h 1.143 + jz @@gotpage ; FFFF / 0400 1.144 + xchg al,ah ; FFFC / 0004 1.145 + and al,0fch 1.146 + add [(data_himem bx).pageidx],ax 1.147 + mov di,[(data_himem bx).pageidx] 1.148 + lea di,[(data_himem bx+di).page] 1.149 + mov edx,ds 1.150 + shl edx,4 1.151 + lea cx,[(data_himem bx).cache] 1.152 + add edx,ecx 1.153 + mov eax,[di] 1.154 + or eax,eax 1.155 + jz @@ret 1.156 + mov cx,4096 ; get page 1.157 + call memcpy_imagez ; memcpy_imagez(edx,eax,ecx) 1.158 +@@gotpage: 1.159 + lea ax,[(data_himem bx+si).cache] 1.160 + or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx 1.161 + jnz @@notfirst2 1.162 + xchg ax,bx ; &first 1.163 +@@notfirst2: 1.164 + xchg ax,di 1.165 +@@ret: 1.166 + pop si 1.167 + ret 1.168 + 1.169 + endp _prev_bufv 1.170 + endif 1.171 + 1.172 + ifdef NO386 1.173 + p8086 1.174 + endif 1.175 + 1.176 +;*************************************************************** 1.177 +;_fastcall void memcpy_image_initrd(si:struct image_himem *m); 1.178 +;_fastcall void memcpy_image_kernel(si:struct image_himem *m); 1.179 +;_fastcall void memcpy_image(bx:struct image_himem *m); 1.180 +;*************************************************************** 1.181 + global @memcpy_image_initrd$qv:near 1.182 +@memcpy_image_initrd$qv: 1.183 + lea bx,[si+size image_himem] 1.184 + db 0A9h ; test ax,imm 1.185 + global @memcpy_image_kernel$qv:near 1.186 +@memcpy_image_kernel$qv: 1.187 + mov bx,si 1.188 + proc @memcpy_image$qp11image_himem near 1.189 + 1.190 + ifndef NO386 1.191 + mov edx,[(image_himem bx).fallback] 1.192 + mov eax,[(image_himem bx).buf] 1.193 + cmp eax,edx ; if (m->fallback != m->buf) 1.194 + jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) 1.195 + mov ecx,[(image_himem bx).size] 1.196 + else 1.197 + les cx,[((image_himem bx).buf)] 1.198 + mov dx,es 1.199 + les ax,[((image_himem bx).fallback)] 1.200 + cmp ax,cx ; if (m->fallback != m->buf) 1.201 + jnz @@do 1.202 + cmp dx,[word ((image_himem bx).fallback)+2] 1.203 + jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) 1.204 +@@do: 1.205 + push [((image_himem bx).size)] 1.206 + xor bx,bx 1.207 +call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size) 1.208 + push dx ; [word ((image_himem bx).buf)+2] 1.209 + push cx ; [word ((image_himem bx).buf)] 1.210 + push bx 1.211 + push es ; push es:ax 1.212 + push ax 1.213 + jmp @@memcpy 1.214 + endif 1.215 +memcpy_imagez: ; memcpy_imagez(edx,eax,ecx) 1.216 + p386 1.217 + push ecx 1.218 + push eax 1.219 + push 0 1.220 + ifndef NO386 1.221 +call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size) 1.222 + endif 1.223 + push edx 1.224 + ifdef NO386 1.225 + p8086 1.226 + endif 1.227 +@@memcpy: 1.228 + extrn memcpy32:near 1.229 + call near memcpy32 1.230 +@@skip: 1.231 + ret 1.232 + 1.233 + global movedend:near 1.234 +movedend: 1.235 + 1.236 + endp @memcpy_image$qp11image_himem 1.237 + 1.238 +;*************************************************************** 1.239 +;_fastcall void storepage(di:u32 *dst); 1.240 +;*************************************************************** 1.241 + global @storepage$qpul:near 1.242 + proc @storepage$qpul near 1.243 + 1.244 + ifndef NO386 1.245 + mov edx,[di] 1.246 + else 1.247 + les ax,[dword di] 1.248 + endif 1.249 + mov cx,offset _buf4k 1.250 +storepage: ; storepage(edx,cx) 1.251 + ifndef NO386 1.252 + push 0 1.253 + push 4096 1.254 + push 0 1.255 + push cx 1.256 + push ds ; call_memcpy32(to=edx,fromseg,fromofs,size) 1.257 + else 1.258 + xor dx,dx 1.259 + push dx ; 0 1.260 + mov bx,4096 1.261 + push bx ; 4096 1.262 + mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size) 1.263 + endif 1.264 + jmp call_memcpy32 1.265 + 1.266 + endp @storepage$qpul 1.267 + 1.268 ;*************************************************************** 1.269 ;_fastcall void strcatb(bx:const char* a, ax:const char* b); 1.270 ;*************************************************************** 1.271 @@ -347,37 +599,37 @@ 1.272 ifdef ISO9660 1.273 ifdef ISOHOOK 1.274 ;*************************************************************** 1.275 -;_fastcall int strhead(bx:const char* a, ax:const char* b); 1.276 +;_fastcall int strhead(ax:const char* a, bx:const char* b); 1.277 ;*************************************************************** 1.278 global @strhead$qpxzct1:near 1.279 proc @strhead$qpxzct1 near 1.280 1.281 @@loop: 1.282 - xchg ax,bx 1.283 - mov dl,[bx] ; dl = *b++ 1.284 + mov dh,[bx] ; dh = *b++ 1.285 inc bx 1.286 xchg ax,bx 1.287 - or dl,dl ; clear C 1.288 - jz failifc ; return 0, bx=a tail 1.289 - xor dl,[bx] ; dl -= *a++ 1.290 + or dh,dh ; clear C 1.291 + jz failifc ; return 0, bx=a tail, dh=0 1.292 + xor dh,[bx] ; dh -= *a++ 1.293 jne fail ; return -1 1.294 inc bx 1.295 + xchg ax,bx 1.296 jmp @@loop 1.297 1.298 endp @strhead$qpxzct1 1.299 1.300 1.301 ;*************************************************************** 1.302 -;_fastcall int strcmp(bx:const char* a, ax:const char* b); 1.303 +;_fastcall int strcmp(ax:const char* a, bx:const char* b); 1.304 ;*************************************************************** 1.305 global @strcmp$qpxzct1:near 1.306 proc @strcmp$qpxzct1 near 1.307 1.308 call @strhead$qpxzct1 1.309 jne fail ; return -1 1.310 - xor dl,[bx] ; clear C 1.311 + xor dh,[bx] ; clear C 1.312 jne fail ; return -1 1.313 - jmp failifc ; return 0 1.314 + jmp failifc ; return 0, dh=0 1.315 1.316 endp @strcmp$qpxzct1 1.317 1.318 @@ -411,6 +663,274 @@ 1.319 endif 1.320 1.321 ;*************************************************************** 1.322 +;_fastcall void puts(bx:const char* s): 1.323 +;*************************************************************** 1.324 + global @puts$qpxzc:near 1.325 + 1.326 +; global puts:near ; puts(bx) 1.327 +@putsz: 1.328 + call @putc 1.329 +@puts$qpxzc: 1.330 +puts: 1.331 + mov dl,[bx] 1.332 + inc bx 1.333 + or dl,dl 1.334 + jne @putsz 1.335 + mov dl,10 1.336 +@putc: 1.337 + cmp dl,10 1.338 + jne @putcz 1.339 + call @putcz2 1.340 +@putcz2: 1.341 + xor dl,7 ; 10^13 1010^1101 1.342 +@putcz: 1.343 + mov ah,2 1.344 +do_int21h: 1.345 + int 21h 1.346 + ret 1.347 + 1.348 + 1.349 +;*************************************************************** 1.350 +;_fastcall char* malloc_or_die(ax:unsigned size); 1.351 +;*************************************************************** 1.352 +xchg_heap_top: 1.353 + xchg ax,[bx] 1.354 + ret 1.355 + 1.356 + proc @malloc_or_die$qui near 1.357 + 1.358 +malloc_or_die: ; ax = malloc_or_die(ax) 1.359 + extrn _heap_top 1.360 + mov bx,offset _heap_top 1.361 + add ax,[bx] 1.362 + jnc xchg_heap_top 1.363 + mov bx,offset msg_malloc 1.364 + 1.365 + endp @malloc_or_die$qui 1.366 + 1.367 + 1.368 +;*************************************************************** 1.369 +;_fastcall int die(bx:const char* msg); 1.370 +;int exit(ax:int status); 1.371 +;int abort(void); 1.372 +;*************************************************************** 1.373 + global @die$qpxzc:near 1.374 + proc @die$qpxzc near 1.375 +@die$qpxzc: 1.376 + global die:near ; die(bx) 1.377 +die: 1.378 + call puts 1.379 + global @exit$qv:near 1.380 +@exit$qv: 1.381 +_exit: 1.382 + extrn _imgs:image_himem 1.383 + mov cx,[(word _imgs.buf)+2] ; no_exit ? 1.384 + mov ah,4Ch 1.385 + jcxz do_int21h 1.386 + mov bx, offset msg_hang 1.387 + call puts 1.388 +; global _abort:near 1.389 +_abort: 1.390 + cli 1.391 + hlt 1.392 + jmp _abort 1.393 + 1.394 + endp @die$qpxzc 1.395 + 1.396 +;*************************************************************** 1.397 +;_fastcall void open_image(si:struct image_himem *m, ax:const char *name); 1.398 +;*************************************************************** 1.399 + 1.400 + global @open_image$qp11image_himempxzc:near 1.401 + proc @open_image$qp11image_himempxzc near 1.402 + 1.403 + mov [(image_himem si).state],ax 1.404 + push ax 1.405 +@@next: 1.406 + call next_chunk 1.407 + ifndef NO386 1.408 + add eax,3 1.409 + and al,0FCh 1.410 + add [(image_himem si).size],eax ; m->size += m->chunk_size size zero'd in bss 1.411 + or eax,eax 1.412 + else 1.413 + add ax,3 1.414 + adc dx,0 1.415 + and al,0FCh 1.416 + add [word (image_himem si).size],ax ; m->size += m->chunk_size size zero'd in bss 1.417 + adc [word ((image_himem si).size)+2],dx 1.418 + or ax,dx 1.419 + endif 1.420 + jnz @@next 1.421 + pop [(image_himem si).state] 1.422 + 1.423 + endp @open_image$qp11image_himempxzc 1.424 + 1.425 + 1.426 +;*************************************************************** 1.427 +;static long next_chunk(struct image_himem *si); 1.428 +;*************************************************************** 1.429 + proc next_chunk near 1.430 + 1.431 + ifndef NO_CLOSE 1.432 + mov ax,[(image_himem si).fd] 1.433 + call close 1.434 + endif 1.435 + ifndef NO386 1.436 + xor eax,eax 1.437 + else 1.438 + xor ax,ax 1.439 + cwd 1.440 + endif 1.441 + mov [(image_himem si).fd],ax 1.442 + mov bx,[(image_himem si).state] 1.443 + cmp al,[bx] ; "" 1.444 + jz @@end 1.445 + dec bx 1.446 + push di 1.447 +@@scan: 1.448 + inc bx 1.449 + mov al,[bx] 1.450 + mov di,bx 1.451 + or al,al 1.452 + jz @@eos 1.453 + sub al,',' 1.454 + jnz @@scan 1.455 + inc bx 1.456 +@@eos: 1.457 + xchg [(image_himem si).state],bx ; set start of string 1.458 + mov [current_file],bx 1.459 + xchg [di],ax ; set temp eos (ax == 0) 1.460 + push ax 1.461 + call @open$qpxzc 1.462 + pop [word di] ; restore string 1.463 + pop di 1.464 + jnc @@opened 1.465 +loadfailure: 1.466 +;*************************************************************** 1.467 +;_fastcall void loadfailure(void); 1.468 +;*************************************************************** 1.469 + global @loadfailure$qv:near 1.470 +@loadfailure$qv: 1.471 + mov bx,0 1.472 + org $-2 1.473 +current_file dw ? 1.474 + call puts 1.475 + mov bx,offset loaderr 1.476 +jmpdie: 1.477 + jmp die 1.478 +@@opened: 1.479 + mov [(image_himem si).fd],ax 1.480 + ifndef NO_CLOSE 1.481 + mov [(image_himem si).fd2close],ax 1.482 + endif 1.483 + ifdef ISO9660 1.484 + ifndef NO386 1.485 + mov eax,[_isostate.filesize] 1.486 + else 1.487 + les ax,[_isostate.filesize] 1.488 + mov dx,es 1.489 + endif 1.490 + else 1.491 + mov bl,02h ; SEEK_END 1.492 + call lseek0 1.493 + ifndef NO386 1.494 + push eax 1.495 + mov ax,[(image_himem si).fd] 1.496 + call rewind 1.497 + pop eax 1.498 + else 1.499 + push ax 1.500 + push dx 1.501 + mov ax,[(image_himem si).fd] 1.502 + call rewind 1.503 + pop dx 1.504 + pop ax 1.505 + endif 1.506 + endif 1.507 +@@end: 1.508 + ifndef NO386 1.509 + mov [(image_himem si).chunk_size],eax 1.510 + else 1.511 + mov [word (image_himem si).chunk_size],ax 1.512 + mov [word ((image_himem si).chunk_size)+2],dx 1.513 + endif 1.514 + ret 1.515 + 1.516 + endp next_chunk 1.517 + 1.518 + 1.519 +;*************************************************************** 1.520 +;_fastcall int read_image(si:struct image_himem *m); 1.521 +;*************************************************************** 1.522 + global @read_image$qp11image_himem:near 1.523 + proc @read_image$qp11image_himem near 1.524 + 1.525 + push di 1.526 + xor di,di 1.527 +@@loop: 1.528 + ifndef NO386 1.529 + xor ecx,ecx 1.530 + mov ch,4096/256 1.531 + sub cx,di 1.532 + mov eax,[(image_himem si).chunk_size] 1.533 + cmp ecx,eax 1.534 + jb @@szok 1.535 + else 1.536 + mov cx,4096 1.537 + sub cx,di 1.538 + mov ax,[word (image_himem si).chunk_size] 1.539 + cmp cx,ax 1.540 + jb @@szok 1.541 + cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size 1.542 + jne @@szok 1.543 + endif 1.544 + xchg ax,cx 1.545 +@@szok: 1.546 + jcxz image_done 1.547 + lea dx,[di+_buf4k] 1.548 + mov bx,[(image_himem si).fd] 1.549 + call @read$cxdxbx 1.550 + jb image_done 1.551 + add di,ax 1.552 + ifndef NO386 1.553 + cwde ; ax < 8000h 1.554 + cdq 1.555 + sub [(image_himem si).chunk_size],eax 1.556 + else 1.557 + cwd ; ax < 8000h 1.558 + sub [word (image_himem si).chunk_size],ax 1.559 + sbb [word ((image_himem si).chunk_size)+2],dx 1.560 + endif 1.561 +@@fill: 1.562 + test al,3 1.563 + je @@filled 1.564 + mov [di+_buf4k],dl 1.565 + inc di 1.566 + inc ax 1.567 + jmp @@fill 1.568 +@@filled: 1.569 + ifndef NO386 1.570 + sub [(image_himem si).remaining],eax 1.571 + or edx,[word (image_himem si).chunk_size] 1.572 + else 1.573 + sub [word (image_himem si).remaining],ax 1.574 + sbb [word ((image_himem si).remaining)+2],dx 1.575 + mov ax,[word (image_himem si).chunk_size] 1.576 + or ax,[word ((image_himem si).chunk_size)+2] 1.577 + endif 1.578 + jnz @@same_chunk 1.579 + call next_chunk 1.580 +@@same_chunk: 1.581 + jmp @@loop 1.582 +image_done: 1.583 + xchg ax,di 1.584 + pop di 1.585 + ret 1.586 + 1.587 + endp @read_image$qp11image_himem 1.588 + 1.589 +;*************************************************************** 1.590 ;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var); 1.591 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var); 1.592 ;*************************************************************** 1.593 @@ -583,534 +1103,6 @@ 1.594 1.595 endp @argstr$qpxzcxt1ppxzc 1.596 1.597 -;*************************************************************** 1.598 -;_fastcall void puts(bx:const char* s): 1.599 -;*************************************************************** 1.600 - global @puts$qpxzc:near 1.601 - 1.602 -; global puts:near ; puts(bx) 1.603 -@putsz: 1.604 - call @putc 1.605 -@puts$qpxzc: 1.606 -puts: 1.607 - mov dl,[bx] 1.608 - inc bx 1.609 - or dl,dl 1.610 - jne @putsz 1.611 - mov dl,10 1.612 -@putc: 1.613 - cmp dl,10 1.614 - jne @putcz 1.615 - call @putcz2 1.616 -@putcz2: 1.617 - xor dl,7 ; 10^13 1010^1101 1.618 -@putcz: 1.619 - mov ah,2 1.620 -do_int21h: 1.621 - int 21h 1.622 - ret 1.623 - 1.624 - 1.625 - include "himem.inc" 1.626 - 1.627 -;*************************************************************** 1.628 -;_fastcall char* malloc_or_die(ax:unsigned size); 1.629 -;*************************************************************** 1.630 -xchg_heap_top: 1.631 - xchg ax,[bx] 1.632 - ret 1.633 - 1.634 - proc @malloc_or_die$qui near 1.635 - 1.636 -malloc_or_die: ; ax = malloc_or_die(ax) 1.637 - extrn _heap_top 1.638 - mov bx,offset _heap_top 1.639 - add ax,[bx] 1.640 - jnc xchg_heap_top 1.641 - mov bx,offset msg_malloc 1.642 - 1.643 - endp @malloc_or_die$qui 1.644 - 1.645 - 1.646 -;*************************************************************** 1.647 -;_fastcall int die(bx:const char* msg); 1.648 -;int exit(ax:int status); 1.649 -;int abort(void); 1.650 -;*************************************************************** 1.651 - global @die$qpxzc:near 1.652 - proc @die$qpxzc near 1.653 -@die$qpxzc: 1.654 - global die:near ; die(bx) 1.655 -die: 1.656 - call puts 1.657 - global @exit$qv:near 1.658 -@exit$qv: 1.659 -_exit: 1.660 - extrn _imgs:image_himem 1.661 - mov cx,[(word _imgs.buf)+2] ; no_exit ? 1.662 - mov ah,4Ch 1.663 - jcxz do_int21h 1.664 - mov bx, offset msg_hang 1.665 - call puts 1.666 -; global _abort:near 1.667 -_abort: 1.668 - cli 1.669 - hlt 1.670 - jmp _abort 1.671 - 1.672 - endp @die$qpxzc 1.673 - 1.674 -;*************************************************************** 1.675 -;_fastcall void open_image(si:struct image_himem *m, ax:const char *name); 1.676 -;*************************************************************** 1.677 - 1.678 - global @open_image$qp11image_himempxzc:near 1.679 - proc @open_image$qp11image_himempxzc near 1.680 - 1.681 - mov [(image_himem si).state],ax 1.682 - push ax 1.683 -@@next: 1.684 - call next_chunk 1.685 - ifndef NO386 1.686 - add eax,3 1.687 - and al,0FCh 1.688 - add [(image_himem si).size],eax ; m->size += m->chunk_size 1.689 - or eax,eax 1.690 - else 1.691 - add ax,3 1.692 - adc dx,0 1.693 - and al,0FCh 1.694 - add [word (image_himem si).size],ax ; m->size += m->chunk_size 1.695 - adc [word ((image_himem si).size)+2],dx 1.696 - or ax,dx 1.697 - endif 1.698 - jnz @@next 1.699 - pop [(image_himem si).state] 1.700 - 1.701 - endp @open_image$qp11image_himempxzc 1.702 - 1.703 - 1.704 -;*************************************************************** 1.705 -;static long next_chunk(struct image_himem *si); 1.706 -;*************************************************************** 1.707 - proc next_chunk near 1.708 - 1.709 - ifndef NO_CLOSE 1.710 - mov ax,[(image_himem si).fd] 1.711 - call close 1.712 - endif 1.713 - ifndef NO386 1.714 - xor eax,eax 1.715 - else 1.716 - xor ax,ax 1.717 - cwd 1.718 - endif 1.719 - mov [(image_himem si).fd],ax 1.720 - mov bx,[(image_himem si).state] 1.721 - cmp al,[bx] ; "" 1.722 - jz @@end 1.723 - dec bx 1.724 - push di 1.725 -@@scan: 1.726 - inc bx 1.727 - mov al,[bx] 1.728 - mov di,bx 1.729 - or al,al 1.730 - jz @@eos 1.731 - sub al,',' 1.732 - jnz @@scan 1.733 - inc bx 1.734 -@@eos: 1.735 - xchg [(image_himem si).state],bx ; set start of string 1.736 - mov [current_file],bx 1.737 - xchg [di],ax ; set temp eos (ax == 0) 1.738 - push ax 1.739 - call @open$qpxzc 1.740 - pop [word di] ; restore string 1.741 - pop di 1.742 - jnc @@opened 1.743 -loadfailure: 1.744 -;*************************************************************** 1.745 -;_fastcall void loadfailure(void); 1.746 -;*************************************************************** 1.747 - global @loadfailure$qv:near 1.748 -@loadfailure$qv: 1.749 - mov bx,0 1.750 - org $-2 1.751 -current_file dw ? 1.752 - call puts 1.753 - mov bx,offset loaderr 1.754 -jmpdie: 1.755 - jmp die 1.756 -@@opened: 1.757 - mov [(image_himem si).fd],ax 1.758 - ifndef NO_CLOSE 1.759 - mov [(image_himem si).fd2close],ax 1.760 - endif 1.761 - ifdef ISO9660 1.762 - ifndef NO386 1.763 - mov eax,[_isostate.filesize] 1.764 - else 1.765 - mov ax,[word _isostate.filesize] 1.766 - mov dx,[(word _isostate.filesize)+2] 1.767 - endif 1.768 - else 1.769 - mov bl,02h ; SEEK_END 1.770 - call lseek0 1.771 - ifndef NO386 1.772 - push eax 1.773 - mov ax,[(image_himem si).fd] 1.774 - call rewind 1.775 - pop eax 1.776 - else 1.777 - push ax 1.778 - push dx 1.779 - mov ax,[(image_himem si).fd] 1.780 - call rewind 1.781 - pop dx 1.782 - pop ax 1.783 - endif 1.784 - endif 1.785 -@@end: 1.786 - ifndef NO386 1.787 - mov [(image_himem si).chunk_size],eax 1.788 - else 1.789 - mov [word (image_himem si).chunk_size],ax 1.790 - mov [word ((image_himem si).chunk_size)+2],dx 1.791 - endif 1.792 - ret 1.793 - 1.794 - endp next_chunk 1.795 - 1.796 - ifdef VCPI 1.797 -;*************************************************************** 1.798 - 1.799 -struc data_himem ;struct data_himem { 1.800 -first dd ? ; 0 u32 first; *must* be the first one 1.801 -cacheidx dw ? ; 4 int cacheidx; quad * 1.802 -pageidx dw ? ; 6 int pageidx; byte * 1.803 -cache dd 1024 dup(?) ; 8 int cache; 1.804 -page dd 1024 dup(?) ;4104 int page; 1.805 -ends data_himem ;}; 1.806 - 1.807 -;*************************************************************** 1.808 -;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m); 1.809 -;*************************************************************** 1.810 - global @malloc_bufv_or_die$qp11image_himem:near 1.811 - proc @malloc_bufv_or_die$qp11image_himem near 1.812 - 1.813 - p386 1.814 - push si 1.815 - ;mov ecx,[(image_himem si).size] 1.816 - ;shr ecx,20 ; pages index size = size >> 20 1.817 - ;mov ax,cx 1.818 - ;add ax,size data_himem-4096 1.819 - mov ax,size data_himem 1.820 - call malloc_or_die 1.821 - ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; 1.822 - mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; 1.823 - add ecx,[(image_himem si).size] 1.824 - shr ecx,12 1.825 - mov [curdata],ax 1.826 - mov [(image_himem si).bufv],ax ; update m->bufv 1.827 - xchg ax,si 1.828 -@@vcpi_alloc: 1.829 - mov ax,0DE04h ; allocate a 4K page => EDX 1.830 - int 67h 1.831 - or ah,ah 1.832 - mov bx,offset vcpi_alloc_err 1.833 - jnz jmpdie 1.834 -; for (i = cnt-1; i >= 0; i--) 1.835 -; if (edx < pm.fallback+pm.size) again 1.836 - mov bx,offset _imgs.fallback+size image_himem 1.837 - mov eax,[bx-2+6-size image_himem] ; pm.size 1.838 - add eax,[bx-2+2-size image_himem] 1.839 - cmp eax,edx ; pm.fallback+pm.size <= edx ? 1.840 - ja @@vcpi_alloc 1.841 - mov eax,ecx 1.842 - dec eax 1.843 - shl eax,12 ; i*_4k 1.844 -; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again 1.845 - add eax,[bx-2+2] ; +initrd.fallback 1.846 - cmp eax,edx ; initrd.fallback+i*_4k > edx ? 1.847 - ja @@initrdok 1.848 - mov eax,[bx-2+6] ; initrd.size 1.849 - add eax,[bx-2+2] ; +initrd.fallback 1.850 - cmp eax,edx ; initrd.fallback+initrd.size > edx ? 1.851 -@@ja_vcpi_alloc: 1.852 - ja @@vcpi_alloc 1.853 -@@initrdok: 1.854 - cmp [(data_himem si).first],0 1.855 - jne @@notfirst 1.856 - mov [(data_himem si).first],edx 1.857 -@@notfirst: 1.858 - mov bx,[(data_himem si).cacheidx] 1.859 - cmp bh,4 1.860 - jae @@nextpage 1.861 - shl bx,2 1.862 - inc [(data_himem si).cacheidx] 1.863 - mov [(data_himem bx+si).cache],edx ; cache[cacheidx++] = edx 1.864 - loopd @@vcpi_alloc 1.865 - mov [(data_himem bx+si).cache],ecx ; last is 0 1.866 -@@nextpage: 1.867 - and [(data_himem si).cacheidx],0 1.868 - mov bx,[(data_himem si).pageidx] 1.869 - mov [(data_himem bx+si).page],edx 1.870 - add [(data_himem si).pageidx],4 1.871 - push cx 1.872 - lea cx,[(data_himem si).cache] 1.873 - ifdef NO386 1.874 - push edx 1.875 - pop ax ; to es:ax 1.876 - pop es 1.877 - endif 1.878 - call storepage ; storepage(edx/es:ax,cx) 1.879 - pop cx 1.880 - or ecx,ecx ; clear C 1.881 - jnz @@ja_vcpi_alloc 1.882 - mov [dword (data_himem si).cacheidx],ecx 1.883 - xchg ax,si 1.884 - pop si 1.885 - ret 1.886 - ifdef NO386 1.887 - p8086 1.888 - endif 1.889 - 1.890 - endp @malloc_bufv_or_die$qp11image_himem 1.891 - endif 1.892 - 1.893 - 1.894 -;*************************************************************** 1.895 -;_fastcall void memcpy_image_initrd(si:struct image_himem *m); 1.896 -;_fastcall void memcpy_image_kernel(si:struct image_himem *m); 1.897 -;_fastcall void memcpy_image(bx:struct image_himem *m); 1.898 -;*************************************************************** 1.899 - global @memcpy_image_initrd$qv:near 1.900 -@memcpy_image_initrd$qv: 1.901 - lea bx,[si+size image_himem] 1.902 - db 0A9h ; test ax,imm 1.903 - global @memcpy_image_kernel$qv:near 1.904 -@memcpy_image_kernel$qv: 1.905 - mov bx,si 1.906 - proc @memcpy_image$qp11image_himem near 1.907 - 1.908 - ifndef NO386 1.909 - mov edx,[(image_himem bx).fallback] 1.910 - mov eax,[(image_himem bx).buf] 1.911 - cmp eax,edx ; if (m->fallback != m->buf) 1.912 - jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) 1.913 - mov ecx,[(image_himem bx).size] 1.914 - else 1.915 - les cx,[((image_himem bx).buf)] 1.916 - mov dx,es 1.917 - les ax,[((image_himem bx).fallback)] 1.918 - cmp ax,cx ; if (m->fallback != m->buf) 1.919 - jnz @@do 1.920 - cmp dx,[word ((image_himem bx).fallback)+2] 1.921 - jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) 1.922 -@@do: 1.923 - push [((image_himem bx).size)] 1.924 - xor bx,bx 1.925 -call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size) 1.926 - push dx ; [word ((image_himem bx).buf)+2] 1.927 - push cx ; [word ((image_himem bx).buf)] 1.928 - push bx 1.929 - push es ; push es:ax 1.930 - push ax 1.931 - jmp @@memcpy 1.932 - endif 1.933 -memcpy_imagez: ; memcpy_imagez(edx,eax,ecx) 1.934 - p386 1.935 - push ecx 1.936 - push eax 1.937 - push 0 1.938 - ifndef NO386 1.939 -call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size) 1.940 - endif 1.941 - push edx 1.942 - ifdef NO386 1.943 - p8086 1.944 - endif 1.945 -@@memcpy: 1.946 - extrn memcpy32:near 1.947 - call near memcpy32 1.948 -@@skip: 1.949 - ret 1.950 - 1.951 - endp @memcpy_image$qp11image_himem 1.952 - 1.953 -;*************************************************************** 1.954 -;_fastcall void storepage(di:u32 *dst); 1.955 -;*************************************************************** 1.956 - global @storepage$qpul:near 1.957 - proc @storepage$qpul near 1.958 - 1.959 - ifndef NO386 1.960 - mov edx,[di] 1.961 - else 1.962 - les ax,[dword di] 1.963 - endif 1.964 - mov cx,offset _buf4k 1.965 -storepage: ; storepage(edx,cx) 1.966 - ifndef NO386 1.967 - push 0 1.968 - push 4096 1.969 - push 0 1.970 - push cx 1.971 - push ds ; call_memcpy32(to=edx,fromseg,fromofs,size) 1.972 - else 1.973 - xor dx,dx 1.974 - push dx ; 0 1.975 - mov bx,4096 1.976 - push bx ; 4096 1.977 - mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size) 1.978 - endif 1.979 - jmp call_memcpy32 1.980 - 1.981 - endp @storepage$qpul 1.982 - 1.983 - ifdef VCPI 1.984 - p386 1.985 -;*************************************************************** 1.986 -;_fastcall void reset_bufv(di:u32 *p); 1.987 -;*************************************************************** 1.988 - global @reset_bufv$qpul:near 1.989 - proc @reset_bufv$qpul near 1.990 - 1.991 - mov [curdata],di 1.992 - and [dword (data_himem di).cacheidx],0 ; and pageidx=0 1.993 - ret 1.994 - 1.995 - endp @reset_bufv$qpul 1.996 - 1.997 -;*************************************************************** 1.998 -;u32* di=prev_bufv(); 1.999 -;u32* di=prev_bufv(); 1.1000 -;*************************************************************** 1.1001 - global _prev_bufv:near 1.1002 - global _next_bufv:near 1.1003 - proc _prev_bufv near 1.1004 - 1.1005 - stc 1.1006 - db 73h ; jnc 1.1007 -_next_bufv: 1.1008 - clc 1.1009 - push si 1.1010 - mov bx,0 1.1011 - org $-2 1.1012 -curdata dw ? 1.1013 - sbb ax,ax 1.1014 - cmc 1.1015 - adc ax,[(data_himem bx).cacheidx] ; -1/+1 1.1016 - mov si,3ffh 1.1017 - and si,ax 1.1018 - mov [(data_himem bx).cacheidx],si 1.1019 - shl si,2 1.1020 - xor ecx,ecx 1.1021 - test ax,0fc00h 1.1022 - jz @@gotpage ; FFFF / 0400 1.1023 - xchg al,ah ; FFFC / 0004 1.1024 - and al,0fch 1.1025 - add [(data_himem bx).pageidx],ax 1.1026 - mov di,[(data_himem bx).pageidx] 1.1027 - lea di,[(data_himem bx+di).page] 1.1028 - mov edx,ds 1.1029 - shl edx,4 1.1030 - lea cx,[(data_himem bx).cache] 1.1031 - add edx,ecx 1.1032 - mov eax,[di] 1.1033 - or eax,eax 1.1034 - jz @@ret 1.1035 - mov cx,4096 ; get page 1.1036 - call memcpy_imagez ; memcpy_imagez(edx,eax,ecx) 1.1037 -@@gotpage: 1.1038 - lea ax,[(data_himem bx+si).cache] 1.1039 - or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx 1.1040 - jnz @@notfirst2 1.1041 - xchg ax,bx ; &first 1.1042 -@@notfirst2: 1.1043 - xchg ax,di 1.1044 -@@ret: 1.1045 - pop si 1.1046 - ret 1.1047 - 1.1048 - endp _prev_bufv 1.1049 - endif 1.1050 - 1.1051 - ifdef NO386 1.1052 - p8086 1.1053 - endif 1.1054 - 1.1055 -;*************************************************************** 1.1056 -;_fastcall int read_image(si:struct image_himem *m); 1.1057 -;*************************************************************** 1.1058 - global @read_image$qp11image_himem:near 1.1059 - proc @read_image$qp11image_himem near 1.1060 - 1.1061 - push di 1.1062 - xor di,di 1.1063 -@@loop: 1.1064 - ifndef NO386 1.1065 - xor ecx,ecx 1.1066 - mov ch,4096/256 1.1067 - sub cx,di 1.1068 - mov eax,[(image_himem si).chunk_size] 1.1069 - cmp ecx,eax 1.1070 - jb @@szok 1.1071 - else 1.1072 - mov cx,4096 1.1073 - sub cx,di 1.1074 - mov ax,[word (image_himem si).chunk_size] 1.1075 - cmp cx,ax 1.1076 - jb @@szok 1.1077 - cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size 1.1078 - jne @@szok 1.1079 - endif 1.1080 - xchg ax,cx 1.1081 -@@szok: 1.1082 - jcxz image_done 1.1083 - lea dx,[di+_buf4k] 1.1084 - mov bx,[(image_himem si).fd] 1.1085 - call @read$cxdxbx 1.1086 - jb image_done 1.1087 - add di,ax 1.1088 - ifndef NO386 1.1089 - cwde ; ax < 8000h 1.1090 - cdq 1.1091 - sub [(image_himem si).chunk_size],eax 1.1092 - else 1.1093 - cwd ; ax < 8000h 1.1094 - sub [word (image_himem si).chunk_size],ax 1.1095 - sbb [word ((image_himem si).chunk_size)+2],dx 1.1096 - endif 1.1097 -@@fill: 1.1098 - test al,3 1.1099 - je @@filled 1.1100 - mov [di+_buf4k],dl 1.1101 - inc di 1.1102 - inc ax 1.1103 - jmp @@fill 1.1104 -@@filled: 1.1105 - ifndef NO386 1.1106 - sub [(image_himem si).remaining],eax 1.1107 - or edx,[word (image_himem si).chunk_size] 1.1108 - else 1.1109 - sub [word (image_himem si).remaining],ax 1.1110 - sbb [word ((image_himem si).remaining)+2],dx 1.1111 - mov ax,[word (image_himem si).chunk_size] 1.1112 - or ax,[word ((image_himem si).chunk_size)+2] 1.1113 - endif 1.1114 - jnz @@same_chunk 1.1115 - call next_chunk 1.1116 -@@same_chunk: 1.1117 - jmp @@loop 1.1118 -image_done: 1.1119 - xchg ax,di 1.1120 - pop di 1.1121 - ret 1.1122 - 1.1123 - endp @read_image$qp11image_himem 1.1124 - 1.1125 1.1126 ends _TEXT 1.1127