# HG changeset patch # User Pascal Bellard # Date 1482437177 -3600 # Node ID e428345df29a562501ff2bcca6207480feab9d4f # Parent bb506432c82c0357fcf83c9b4ed67d3f9abb4772 linld: large image support with VCPI diff -r bb506432c82c -r e428345df29a linld/stuff/src/!COMPILE.BAT --- a/linld/stuff/src/!COMPILE.BAT Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/!COMPILE.BAT Thu Dec 22 21:06:17 2016 +0100 @@ -3,14 +3,17 @@ tasm /h > helptasm.log bcc > helpbcc.log tlink > helptlink.log -tasm /la /m *.asm > asm.log +rem tasm /la /m *.asm > asm.log +tasm /la /m /dLARGE_IMAGES *.asm > asm.log rem @pause -bcc @bccopt.opt -S -mt *.cpp +rem bcc @bccopt.opt -S -mt *.cpp +bcc @bccopt.opt -S -mt -DLARGE_IMAGES *.cpp tasm /l /m load.asm tasm /l /m himem.asm tasm /l /m linld.asm tasm /l /m iso9660.asm -bcc @bccopt.opt -c -mt *.cpp > cpp.log +rem bcc @bccopt.opt -c -mt *.cpp > cpp.log +bcc @bccopt.opt -c -mt -DLARGE_IMAGES *.cpp > cpp.log rem @pause tlink /m /s /t @link.cmd > lnk.log rem @pause diff -r bb506432c82c -r e428345df29a linld/stuff/src/!COMPILEX.BAT --- a/linld/stuff/src/!COMPILEX.BAT Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/!COMPILEX.BAT Thu Dec 22 21:06:17 2016 +0100 @@ -1,13 +1,16 @@ path ..\BC31;%PATH% call !clean.bat -tasm /la /m /dNO386 *.asm > asm.log +rem tasm /la /m /dNO386 *.asm > asm.log +tasm /la /m /dNO386 /dLARGE_IMAGES *.asm > asm.log rem @pause -bcc @bccopt.opt -S -mt *.cpp +rem bcc @bccopt.opt -S -mt *.cpp +bcc @bccopt.opt -S -mt -DLARGE_IMAGES *.cpp tasm /l /m load.asm tasm /l /m himem.asm tasm /l /m tazboot.asm tasm /l /m iso9660.asm -bcc @bccopt.opt -c -mt *.cpp > cpp.log +rem bcc @bccopt.opt -c -mt *.cpp > cpp.log +bcc @bccopt.opt -c -mt -DLARGE_IMAGES *.cpp > cpp.log rem @pause tlink /m /s /t @linkx.cmd > lnk.log rem @pause diff -r bb506432c82c -r e428345df29a linld/stuff/src/COMMON.H --- a/linld/stuff/src/COMMON.H Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/COMMON.H Thu Dec 22 21:06:17 2016 +0100 @@ -49,6 +49,19 @@ u16 fd2close; } pm, initrd; +extern "C" void memcpy_image(struct image_himem *m); +extern "C" void storepage(u32 *dst, u16 src); +#ifdef LARGE_IMAGES +extern "C" void reset_bufv(unsigned long *p); +extern "C" unsigned long* prev_bufv(); +extern "C" unsigned long* next_bufv(); +#define next(p) p = next_bufv() +#define prev(p) p = prev_bufv() +#else +#define reset_bufv(p) +#define next(p) ++p +#define prev(p) --p +#endif extern char vcpi; extern const char* kernel_name; extern const char* initrd_name; @@ -57,8 +70,8 @@ extern u16 vid_mode; // External asm helpers extern "C" void memcpy32(u32, u16,u32, u32); -extern "C" void rmcpy(void* rmbuf, u16 rmsize); -extern "C" void set_sregs_jump_seg_ofs(u32 csip, u32 sssp); +extern "C" void rmcpy(); +extern "C" void set_sregs_jump_seg_ofs(u32 csip); extern "C" void xmm_alloc(struct image_himem *m); extern u32 topmem; extern "C" u32 memtopz(); diff -r bb506432c82c -r e428345df29a linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/CRTL.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -18,7 +18,7 @@ msg_hang db "High mem corrupted - not exiting to DOS" msg_crlf db 13,10,0 vcpi_alloc_err db "vcpi " -msg_malloc db "malloc() failure",0 +msg_malloc db "malloc failure",0 ends _DATA @@ -28,6 +28,9 @@ _no_exit db ? filecnt db ? ; in fact 0 minus file count... nextfilename dw ? + ifdef LARGE_IMAGES +curdata dw ? + endif ends _BSS @@ -112,13 +115,13 @@ push cx push ax global malloc:near ; malloc(cx) -malloc: +malloc: ; keep CX, use AX,BX mov ax,[_heap_top] + mov bx,-1400h ; MIN_STACK=_1k+PAGE_SIZE + add bx,sp + sub bx,ax ; can't overflow + cmp bx,cx mov bx,offset msg_malloc - mov dx,-1400h ; MIN_STACK=_1k+PAGE_SIZE - add dx,sp - sub dx,ax ; can't overflow - cmp dx,cx jb puts add [_heap_top],cx ; _BEG has zero'd heap ;mov bx,ax @@ -286,38 +289,32 @@ ;*************************************************************** -;long lseek(int fd, long sz, int dir); +;long lseekset(int fd, long sz); ;*************************************************************** - global _lseek:near - proc _lseek near + global _lseekset:near + proc _lseekset near - ifndef NO386 pop ax ;caller return address pop bx ; fd - pop ecx ; sz - pop dx ; dir + pop dx ; sz lo + pop cx ; sz hi + push cx push dx - push ecx push bx push ax - else - mov bx,sp - mov dx,[bx+8] - mov cx,[bx+6] - mov ax,[bx+4] - mov bx,[bx+2] - endif -lseek: - xchg ax,dx ; dir - mov ah,42h - ifndef NO386 - push ecx - pop dx - pop cx - endif + global lseekset:near +lseekset: + clc + global rewind:near +rewind: ; rewind(bx,C=1) + mov ax,4200h + jnc dos +lseek0: ; lseek0(bx,ax=dir) + cwd + xor cx,cx jmp dos - endp _lseek + endp _lseekset ;*************************************************************** @@ -444,6 +441,16 @@ fd2close dw ? ;30 u16 fd2close; ends ;}; + ifdef LARGE_IMAGES +struc data_himem ;struct data_himem { +first dd ? ; 0 u32 first; +cacheidx dw ? ; 4 int cacheidx; +pageidx dw ? ; 6 int pageidx; +cache dd 1024 dup(?) ; 8 int cache; +page dd 1024 dup(?) ;4104 int page; +ends ;}; // size=8200 + endif + ;*************************************************************** ;u32* malloc_bufv_or_die(struct image_himem *m); ;*************************************************************** @@ -456,6 +463,16 @@ push bx push si xchg ax,si + ifdef LARGE_IMAGES + mov cx,[word ((image_himem si).size) + 2] + shr cx,4 ; pages index size = size >> 20 + add cx,8+4096+8 + call malloc_or_die + mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE; + add ecx,[(image_himem si).size] + shr ecx,12 + mov [curdata],ax + else mov ecx,[(image_himem si).size] dec ecx shr ecx,12 @@ -466,59 +483,88 @@ ; our malloc zeroes allocated mem: bufv[cnt]=0; ; Allocate pages, storing addrs in addrbuf call malloc_or_die - pop cx - push cx ; _sort:nel - push ax ; _sort:base + pop cx + push ax + endif mov [(image_himem si).bufv],ax - xchg ax,bx + xchg ax,si @@vcpi_alloc: xor edx,edx mov ax,0DE04h int 67h or ah,ah - jz @@ok mov bx,offset vcpi_alloc_err - jmp die -@@ok: - mov [bx],edx - add bx,4 + jnz die +; for (i = cnt-1; i >= 0; i--) + ifdef LARGE_IMAGES + mov eax,ecx + dec eax + else + mov ax,cx + dec ax + cwde + endif + shl eax,12 ; i*_4k +; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again + extrn _pm + mov bx,offset _pm+2 + push eax + add eax,[bx-2+2] + cmp eax,edx ; pm.fallback+i*_4k <= edx ? + pop eax ; i*_4k + jbe @@pmok + cmp edx,[bx-2+2] ; edx >= pm.fallback ? + jae @@vcpi_alloc +@@pmok: +; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again + extrn _initrd + mov bx,offset _initrd+2 + add eax,[bx-2+2] ; +initrd.fallback + cmp eax,edx ; initrd.fallback+i*_4k > edx ? + ja @@initrdok + mov eax,[bx-2+6] ; initrd.size + add eax,[bx-2+2] ; +initrd.fallback + cmp eax,edx ; initrd.fallback+initrd.size > edx ? +@@jnc_vcpi_alloc: + ja @@vcpi_alloc +@@initrdok: + ifdef LARGE_IMAGES + cmp [(data_himem si).first],0 + jne @@notfirst + mov [(data_himem si).first],edx +@@notfirst: + mov bx,[(data_himem si).cacheidx] + cmp bh,4 + jae @@nextpage + shl bx,2 + inc [(data_himem si).cacheidx] + mov [(data_himem bx+si).cache],edx + loopd @@vcpi_alloc + mov [(data_himem bx+si).cache],ecx ; last is 0 +@@nextpage: + and [(data_himem si).cacheidx],0 + mov bx,[(data_himem si).pageidx] + mov [(data_himem bx+si).page],edx + add [(data_himem si).pageidx],4 + push cx + lea cx,[(data_himem si).cache] + ifdef NO386 + push edx + pop dx + pop ax + endif + call storepage ; storepage(edx,cx) + pop cx + or ecx,ecx ; clear C + jnz @@jnc_vcpi_alloc + mov [dword (data_himem si).cacheidx],ecx + xchg ax,si + else + mov [si],edx + lodsd ; si=+4 loop @@vcpi_alloc -@@again: - call _sort - extrn _initrd - cmp si,offset _initrd - jne @@quit pop ax - pop cx - push cx ; _sort:nel - push ax ; _sort:base = m->bufv -;again: -; for (i = cnt-1; i >= 0; i--) { -@@chkloop: - mov bx,cx - dec bx -; if (m->bufv[i] > m->fallback+i*_4k && m->bufv[i] < m->fallback+m->size) { - shl bx,2 - add bx,ax ; m->bufv - mov edx,[bx] ; m->bufv[i] - sub edx,[(image_himem si).fallback] - cmp edx,[(image_himem si).size] - jae @@chknext - shr edx,12 - cmp dx,cx - jb @@chknext -; m->bufv[i] = vcpi_alloc_or_die(); -; sort(m->bufv,cnt); -; goto again; - mov cx,1 - jmp @@vcpi_alloc -; } -; } -@@chknext: - loop @@chkloop -@@quit: - pop ax - pop cx + endif pop si ret @@ -526,16 +572,189 @@ ;*************************************************************** -;void next_chunk(struct image_himem *m); +; void memcpy_image(struct image_himem *m); ;*************************************************************** - proc _next_chunk near + global _memcpy_image:near + proc _memcpy_image near + pop ax ;caller return address pop bx + push bx + push ax + ifndef NO386 + mov edx,[(image_himem bx).fallback] + mov eax,[(image_himem bx).buf] + cmp eax,edx ; if (m->fallback != m->buf) + jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) + ifdef LARGE_IMAGES + mov ecx,[(image_himem bx).size] +memcpy_imagez: + push ecx + else + push [(image_himem bx).size] + endif + push eax + push 0 +call_memcpy32: + push edx + else + mov ax,[word ((image_himem bx).fallback)] + mov dx,[word ((image_himem bx).fallback)+2] + mov cx,[word ((image_himem bx).buf)] + cmp ax,cx ; if (m->fallback != m->buf) + jnz @@do + cmp dx,[word ((image_himem bx).buf)+2] + jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size) +@@do: + push [word ((image_himem bx).size)+2] + push [word ((image_himem bx).size)] + push [word ((image_himem bx).buf)+2] + push cx + xor cx,cx + push cx +call_memcpy32: + push dx + push ax + ifdef LARGE_IMAGES + jmp @@memcpy +memcpy_imagez: + push ecx + push eax + push 0 + push edx + endif + endif +@@memcpy: + extrn _memcpy32:near + call near _memcpy32 + add sp,14 +@@skip: + ret + + endp _memcpy_image + +;*************************************************************** +;void storepage(u32 *dst, u16 src); +;*************************************************************** + global _storepage:near + proc _storepage near + + pop ax ;caller return address + pop bx + pop cx + push cx + push bx + push ax + ifndef NO386 + mov edx,[bx] + else + mov ax,[bx] + mov dx,[bx+2] + endif +storepage: + ifndef NO386 + push 0 + push 4096 + push 0 + else + xor bx,bx + push bx + mov bh,4096/256 + push bx + xor bx,bx + push bx + endif + push cx + push ds + jmp call_memcpy32 + + endp _storepage + + + ifdef LARGE_IMAGES +;*************************************************************** +;void reset_bufv(u32 *p); +;*************************************************************** + global _reset_bufv:near + proc _reset_bufv near + + pop bx ;caller return address pop ax push ax push bx - push si di - xchg ax,di + mov [curdata],ax + xchg ax,bx + and [dword (data_himem bx).cacheidx],0 + ret + + endp _reset_bufv + +;*************************************************************** +;u32* prev_bufv(); +;u32* prev_bufv(); +;*************************************************************** + global _prev_bufv:near + global _next_bufv:near + proc _prev_bufv near + + stc + db 73h ; jnc +_next_bufv: + clc + sbb ax,ax + stc + rcl ax,1 ; -1/+1 + xor ecx,ecx + push si + mov si,[curdata] + add ax,[(data_himem si).cacheidx] + test ax,0fc00h + jz @@gotpage + push ax ; FFFF / 0400 + sar ax,8 ; FFFC / 0004 + and al,0fch + add [(data_himem si).pageidx],ax + mov bx,[(data_himem si).pageidx] + lea bx,[(data_himem bx+si).page] + mov edx,ds + shl edx,4 + lea cx,[(data_himem si).cache] + add edx,ecx + mov eax,[bx] + or eax,eax + jnz @@pageok + pop ax + xchg ax,bx + pop si + ret +@@pageok: + mov cx,4096 + call memcpy_imagez ; get page + pop ax ; FFFF / 0400 + cbw + shr ax,6 ; 03FF / 0000 +@@gotpage: + mov [(data_himem si).cacheidx],ax + shl ax,2 + xchg ax,bx + lea ax,[(data_himem bx+si).cache] + or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx + jnz @@notfirst2 + xchg ax,si ; &first +@@notfirst2: + pop si + ret + + endp _prev_bufv + endif + + +;*************************************************************** +;void next_chunk(struct image_himem *m); +;*************************************************************** + proc next_chunk near + + push si mov bx,[(image_himem di).fd] call close ifndef NO386 @@ -567,44 +786,35 @@ jc @@die mov [(image_himem di).fd],ax mov [(image_himem di).fd2close],ax - mov dx,2 ; SEEK_END xchg ax,bx - ifndef NO386 - xor ecx,ecx - else - xor ax,ax - xor cx,cx - endif - call lseek + mov ax,4202h ; SEEK_END + call lseek0 @@die: mov bx,[(image_himem di).errmsg] jc die mov bx,[(image_himem di).fd] ifndef NO386 push eax - xor ecx,ecx - xor dx,dx - call lseek ; rewind + stc + call rewind pop eax @@end: mov [(image_himem di).chunk_size],eax else push ax push dx - xor ax,ax - xor cx,cx - cwd - call lseek ; rewind + stc + call rewind pop dx pop ax @@end: mov [word (image_himem di).chunk_size],ax mov [word ((image_himem di).chunk_size)+2],dx endif - pop di si + pop si ret - endp _next_chunk + endp next_chunk ;*************************************************************** @@ -633,7 +843,7 @@ mov [word (image_himem di).size],ax ; m->size = 0L mov [word ((image_himem di).size)+2],ax endif - mov [(image_himem di).next_chunk],offset _next_chunk + mov [(image_himem di).next_chunk],offset next_chunk mov si,[fname] mov [(image_himem di).state],si @@next: @@ -979,130 +1189,6 @@ endp _strtol -;*************************************************************** -;>void sort(unsigned long *base:BX!, size_t nel:CX) -;NO386 safe: only used by VCPI -;*************************************************************** - global _sort:near - proc _sort near - - pop ax ;caller return address - pop bx ; base - pop cx ; nel - push cx - push bx - push ax - global sort:near -sort: - ifndef fastsort -; bubble sort - push si - shl cx,2 -@@loop: - xor ax,ax - mov si,4 - cmp cx,si - jbe popsiret -@@next: - mov edx,[bx+si-4] - cmp edx,[bx+si] - jbe @@ok - xchg edx,[bx+si] - mov [bx+si-4],edx - mov ax,si -@@ok: - add si,4 - cmp si,cx - jb @@next - xchg ax,cx - jmp @@loop - else -; shell sort (c) uclibc GPL - push si di -; { -;> size_t wgap:SI; -; -; if (nel > 1) { - cmp cx,1 - jbe @@end -; wgap = 0; - xor ax,ax -; do { -@@wgaplp: - mov si,ax -; wgap = 3 * wgap + 1; - mov dx,3 - mul dx - inc ax -; } while (wgap < (nel-1)/3); - cmp ax,cx - jb @@wgaplp -; /* From the above, we know that either wgap == 1 < nel or */ -; /* ((wgap-1)/3 < (int) ((nel-1)/3) <= (nel-1)/3 ==> wgap < nel. */ -; wgap *= 4; /* So this can not overflow if wnel doesn't. */ - shl si,2 -; nel *= 4; /* Convert nel to 'wnel' */ - shl cx,2 -; do { -@@lp1: -;> size_t i:DI; -; i = wgap; - mov di,si -; do { -@@lp2: -;> size_t j:DX; -; j = i; - mov dx,di -; do { -@@lp3: -;> register char *a:BX!; -; -; j -= wgap; - sub dx,si -; a = j + ((char *)base); - push bx - add bx,dx -; if (cmp(a, a + wgap) <= 0) { - mov eax,[bx] - cmp eax,[bx+si] - jbe @@brk3 -; break; -; } - xchg eax,[bx+si] - mov [bx],eax -; swap(a, a + wgap); - pop bx -; } while (j >= wgap); - cmp dx,si - jae @@lp3 - push bx -@@brk3: - pop bx -; i += 4; - add di,4 -; } while (i < nel); - cmp di,cx - jb @@lp2 -; wgap = (wgap - 4)/3; - sub si,4 - xchg ax,si - cwd - mov si,3 - div si ; kill dx - xchg ax,si -; } while (wgap); - or si,si - jnz @@lp1 -@@end: -; } -;} - pop di si - ret -endif - - endp _sort - - ifdef NO386 ;*************************************************************** ;u16 topseg(); @@ -1123,42 +1209,6 @@ endp _topseg endif -;*************************************************************** -;void rmcpy(void* rmbuf, u16 rmsize); -;*************************************************************** - global _rmcpy:near - proc _rmcpy near - - pop bx ;caller return address - pop ax ; rmbuf - pop cx ; rmsize - push cx - push ax - push bx - push si di es - xchg ax,si - xor di,di - ifdef NO386 - call _topseg - mov es,ax - else - push 9000h - pop es - endif - cld - rep - movsb - extrn _cmdline:word - mov si,[_cmdline] - mov di,8000h - mov ch,10h ; 4k - rep - movsb - pop es di si - ret - - endp _rmcpy - ends _TEXT end diff -r bb506432c82c -r e428345df29a linld/stuff/src/CRTL.H --- a/linld/stuff/src/CRTL.H Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/CRTL.H Thu Dec 22 21:06:17 2016 +0100 @@ -20,10 +20,6 @@ const O_RDONLY = 0; // for open() const O_BINARY = 0; -const SEEK_SET = 0; // for lseek() -const SEEK_CUR = 1; -const SEEK_END = 2; - extern char text_start; extern char text_end; extern char data_start; extern char data_end; extern char bss_start; extern char bss_end; @@ -44,7 +40,7 @@ extern "C" void abort(); extern "C" int read(int fd, void* data, int sz); extern "C" int write(int fd, const void* data, int sz); -extern "C" long lseek(int fd, long sz, int dir); +extern "C" long lseekset(int fd, long sz); extern "C" void* malloc(unsigned sz); extern "C" void puts(const char* s); extern "C" void putsz(const char* s); diff -r bb506432c82c -r e428345df29a linld/stuff/src/CRTLX.ASM --- a/linld/stuff/src/CRTLX.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/CRTLX.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -141,12 +141,11 @@ mov ah,30h int 21h cmp al,3 - mov ax,0 jb @@skip + xor di,di mov es,[cs:2Ch] mov cx,-1 - xor di,di - xor al,al + mov ax,di @@loop1: repne scasb @@ -349,6 +348,38 @@ endp _try_default_args +struc isostate ; struct isostate { +fd dw ? ; 0 int fd; +fileofs dd ? ; 2 unsigned long fileofs; +filesize dd ? ; 6 unsigned long filesize; +filemod dw ? ;10 unsigned short filemod; +filename dw ? ;12 char *filename; +dirofs dd ? ;14 unsigned long dirofs; +dirsize dd ? ;16 unsigned long dirsize; +curdirofs dd ? ;20 unsigned long curdirofs; +curdirsize dd ? ;24 unsigned long curdirsize; +curpos dd ? ;28 unsigned long curpos; +ends ; } isostate; +;*************************************************************** +;unsigned long isolseek(unsigned long offset); +;*************************************************************** + global _isolseek:near + proc _isolseek near + + pop ax + pop dx + pop cx + push cx + push dx + push ax + xor ax,ax + extrn _isostate:isostate + mov bx,[_isostate.fd] + extrn lseekset:near + jmp near lseekset ; (bx=fd, sz=cx:dx) + + endp _isolseek + ends _TEXT end diff -r bb506432c82c -r e428345df29a linld/stuff/src/HIMEM.CPP --- a/linld/stuff/src/HIMEM.CPP Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/HIMEM.CPP Thu Dec 22 21:06:17 2016 +0100 @@ -6,6 +6,81 @@ #include "crtl.h" #include "common.h" +struct image_himem pm; +struct image_himem initrd; + +// Called from inside kernel just before rm->pm +// _loadds _saveregs: done by hand +void far last_ditch() { + cli(); // we start doing *really* destructive things to DOS/BIOS + // it means: do not even try to enable ints + // or call BIOS services after this + asm { + push ds + push cs + pop ds +#ifndef NO386 + pusha +#else + push ax + push bx + push cx + push dx +#endif + } + struct image_himem *m = ± + if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ? + if(vcpi==0) { + // Move kernel + memcpy_image(m); + // Move initrd + memcpy_image(&initrd); + } else { //vcpi + vm2rm(); + // Move kernel + // 'Gathering' copy in chunks of PAGE_SIZE + // No risk of overlapping: kernel is copied from above to 1m mark + m->size = initrd.size = PAGE_SIZE; + u32 *p = m->bufv; + reset_bufv(p); + if (p) do { + m->buf = *p; + memcpy_image(m); + next(p); m->fallback+=PAGE_SIZE; + } while(*p); + // Move initrd + m = &initrd; + if(m->fallback) { + // This is tricky: copy initrd backwards to reduce + // risk of overlapping: use the fact that initrd is copied + // to the very top of ram + // (overlapping still can happen with more than 256mb ram) + // (generic solution for this overwrite problem, anyone?) + p=m->bufv; + reset_bufv(p); + do { + next(p); m->fallback+=PAGE_SIZE; + } while(*p); + do { + prev(p); m->fallback-=PAGE_SIZE; + m->buf = *p; + memcpy_image(m); + } while(p != m->bufv); + } + } + asm { +#ifndef NO386 + popa +#else + pop dx + pop cx + pop bx + pop ax +#endif + pop ds + } +} + int skip_xmmalloc; void load_image(struct image_himem *m) { no_exit++; // die() won't return to DOS @@ -13,7 +88,7 @@ m->buf = m->fallback; u32 buf; u32* bufv= &buf; - if(m->fallback >= _1m) { + if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ? if(vcpi) { bufv = malloc_bufv_or_die(m); // update m->bufv } @@ -24,13 +99,12 @@ buf = m->buf; do { u8 xfer_buf[PAGE_SIZE]; - u16 size = read_image(m, xfer_buf, PAGE_SIZE); - if(s16(size) <= 0) break; - memcpy32(*bufv, seg(xfer_buf), ofs(xfer_buf), PAGE_SIZE); - if (bufv != &buf) bufv++; + u16 size; + if(s16(size = read_image(m, xfer_buf, PAGE_SIZE)) <= 0) break; + storepage(bufv, ofs(xfer_buf)); + if (bufv != &buf) next(bufv); buf += size; } while (*bufv); if(m->remaining) die("Read error"); close(m->fd2close); } - diff -r bb506432c82c -r e428345df29a linld/stuff/src/ISO9660.CPP --- a/linld/stuff/src/ISO9660.CPP Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/ISO9660.CPP Thu Dec 22 21:06:17 2016 +0100 @@ -3,123 +3,120 @@ #include "iso9660.h" #define __ROCKRIDGE -char *isofilename; -unsigned long isofileofs, isofilesize; -unsigned short isofilemod; -int isofd; - #define SECTORSZ 2048 #define SECTORBITS 11 static char buffer[SECTORSZ]; +struct isostate isostate; static int readsector(unsigned long offset) { - return (lseek(isofd, offset, SEEK_SET) != -1 - && read(isofd, buffer, SECTORSZ) == SECTORSZ); + return (isolseek(offset) != -1 + && read(isostate.fd, buffer, SECTORSZ) == SECTORSZ); } int isoread(char *data, unsigned size) { int get, n; - if (size > isofilesize) - size = isofilesize; - if (lseek(isofd, isofileofs, SEEK_SET) == -1) + struct isostate *x=&isostate; + if (size > x->filesize) + size = x->filesize; + if (isolseek(x->fileofs) == -1) return -1; for (get = size; get; get -= n, data += n) { - n = read(isofd,data,get); + n = read(x->fd,data,get); if (n < 0) return n; if (n == 0) break; - isofileofs += n; - isofilesize -= n; + x->fileofs += n; + x->filesize -= n; } return size - get; } -static unsigned long isodirofs, isodirsize; int isoreset(char *name) { + struct isostate *x=&isostate; if (name) - //isofd = open(name, O_RDONLY); - isofd = open(name); + //x->fd = open(name, O_RDONLY); + x->fd = open(name); if (!readsector(16UL * 2048) || strhead(buffer+1,"CD001")) { - //close(isofd); + //close(x->fd); return -1; } - isodirofs = * (unsigned long *) (buffer + 0x9E); - isodirofs <<= SECTORBITS; - isodirsize = * (unsigned long *) (buffer + 0xA6); + x->dirofs = * (unsigned long *) (buffer + 0x9E); + x->dirofs <<= SECTORBITS; + x->dirsize = * (unsigned long *) (buffer + 0xA6); return 0; } int isoreaddir(int restart) { - static unsigned long pos, dirofs, dirsize; static char dots[] = ".."; int size, n; #ifdef __ROCKRIDGE char *endname; #endif + struct isostate *x=&isostate; if (restart) { - dirofs = isodirofs; - dirsize = isodirsize; - pos = SECTORSZ; + x->curdirofs = x->dirofs; + x->curdirsize = x->dirsize; + x->curpos = SECTORSZ; } - if (pos >= SECTORSZ || * (short *) (buffer + pos) == 0) { - if (dirsize < SECTORSZ) return -1; - readsector(dirofs); - dirofs += SECTORSZ; - dirsize -= SECTORSZ; - pos = 0; + if (x->curpos >= SECTORSZ || * (short *) (buffer + x->curpos) == 0) { + if (x->curdirsize < SECTORSZ) return -1; + readsector(x->curdirofs); + x->curdirofs += SECTORSZ; + x->curdirsize -= SECTORSZ; + x->curpos = 0; } - size = * (short *) (buffer + pos); + size = * (short *) (buffer + x->curpos); if (size == 0) return -1; - isofileofs = (* (unsigned long *) (buffer + pos + 2)) << SECTORBITS; - isofilesize = * (unsigned long *) (buffer + pos + 10); - isofilemod = (buffer[pos + 25] & 2) ? 0040755 : 0100755; + x->fileofs = (* (unsigned long *) (buffer + x->curpos + 2)) << SECTORBITS; + x->filesize = * (unsigned long *) (buffer + x->curpos + 10); + x->filemod = (buffer[x->curpos + 25] & 2) ? 0040755 : 0100755; #ifdef __ROCKRIDGE endname = NULL; - n = (buffer[pos + 32] + pos + 34) & -2; + n = (buffer[x->curpos + 32] + x->curpos + 34) & -2; do { int len = buffer[n + 2]; switch (* (short *) (buffer + n)) { case 0x4D4E: // NM - isofilename = buffer + n + 5; + x->filename = buffer + n + 5; endname = buffer + n + len; break; case 0x5850: // PX - isofilemod = * (short *) (buffer + n + 4); + x->filemod = * (short *) (buffer + n + 4); break; } n += len; } - while (n + 2 < pos + size); + while (n + 2 < x->curpos + size); if (endname) *endname = 0; else #endif { - isofilename = buffer + pos + 33; - switch (* (short *) (isofilename - 1)) { + x->filename = buffer + x->curpos + 33; + switch (* (short *) (x->filename - 1)) { case 0x0101: - isofilename = dots; + x->filename = dots; break; case 0x0001: - isofilename = dots + 1; + x->filename = dots + 1; break; default: - n = isofilename[-1]; - if (* (short *) (isofilename + n - 2) == 0x313B) + n = x->filename[-1]; + if (* (short *) (x->filename + n - 2) == 0x313B) n -= 2; // remove ;1 - if (isofilename[n - 1] == '.') n--; - isofilename[n] = 0; + if (x->filename[n - 1] == '.') n--; + x->filename[n] = 0; } } - pos += size; + x->curpos += size; return 0; } @@ -129,6 +126,7 @@ int restart; char *name, *s, c; int _64bits = cpuhaslm(); + struct isostate *x=&isostate; retry32: name = filename; @@ -142,24 +140,24 @@ c = *s; *s = 0; for (restart = 1; isoreaddir(restart) == 0; restart = 0) { - char *n = name, *i = isofilename; + char *n = name, *i = x->filename; if (_64bits) { int len = strlen(name); - if (strhead(isofilename, name)) continue; + if (strhead(x->filename, name)) continue; n = "64"; i += len; } if (strcmp(n, i)) continue; - if (IS_DIR(isofilemod)) { - isodirofs = isofileofs; - isodirsize = isofilesize; + if (IS_DIR(x->filemod)) { + x->dirofs = x->fileofs; + x->dirsize = x->filesize; if (c) { *s++ = c; name = s; goto next; } } - lseek(isofd, isofileofs, SEEK_SET); + isolseek(x->fileofs); return 0; } if (_64bits) { diff -r bb506432c82c -r e428345df29a linld/stuff/src/ISO9660.H --- a/linld/stuff/src/ISO9660.H Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/ISO9660.H Thu Dec 22 21:06:17 2016 +0100 @@ -1,9 +1,21 @@ #ifndef __ISO9660_H #define __ISO9660_H -extern char *isofilename; -extern unsigned long isofileofs, isofilesize; -extern unsigned short isofilemod; -extern int isofd; +extern struct isostate { + int fd; + unsigned long fileofs; + unsigned long filesize; + unsigned short filemod; + char *filename; +//private + unsigned long dirofs, dirsize; + unsigned long curdirofs, curdirsize, curpos; +} isostate; +#define isofd isostate.fd +#define isofileofs isostate.fileofs +#define isofilesize isostate.filesize +#define isofilemod isostate.filemod +#define isofilename isostate.filename +extern "C" int unsigned long isolseek(unsigned long offset); extern int isoreset(char *name); extern int isoopen(char *name); extern int isoreaddir(int restart); diff -r bb506432c82c -r e428345df29a linld/stuff/src/JUMP.ASM --- a/linld/stuff/src/JUMP.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/JUMP.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -21,7 +21,7 @@ segment _TEXT byte public use16 'CODE' ;*************************************************************** -;void set_sregs_jump_seg_ofs(u32 csip, u32 sssp); +;void set_sregs_jump_seg_ofs(u32 csip); ;****** Never returns ;*************************************************************** global _set_sregs_jump_seg_ofs:near @@ -30,15 +30,43 @@ extrn dos_shutdown:near pop ax ;caller return address - test [byte _pm_high],-1 ; load high ? clear CF + ifdef NO386 + extrn _topseg:near + call near _topseg + mov es,ax + else + push 9000h + pop es + endif + pop cx ; ip + pop dx ; cs + push es + pop ss + mov sp,0A000h + push dx cx + extrn _rm_buf:word + mov si,[_rm_buf] + xor di,di + extrn _rm_size:word + mov cx,[_rm_size] + ;cld + rep + movsb + extrn _cmdline:word + mov si,[_cmdline] + mov di,8000h + mov ch,10h ; 4k + rep + movsb + cmp [_pm_high],cl ; load high ? jne isbzimage ; finish loading extrn @last_ditch$qv:near push cs call @last_ditch$qv - mov bx,[word _pm+2+2] ; get pm->fallback high word + mov ax,[word _pm+2+2] ; get pm->fallback high word ; self move - cld + ;cld push 9900h ; 4096 bytes for cmdline ;push 9820h ; 512 bytes for cmdline pop es ; min 2048 bytes for stack @@ -51,18 +79,11 @@ movsb push es call near doretf ; mov cs,es - stc -isbzimage: - pop cx ; ip - pop dx ; cs - pop ax ; sp - pop ss ; ss - xchg sp,ax - push dx cx - jnc nomove + push ss + pop es push cs pop ds - push bx + push ax call near dos_shutdown ;in al,70h ;or al,80h ; disable NMI @@ -112,11 +133,11 @@ notelks: endif -nomove: +isbzimage: push ss pop ds - push ss - pop es + ;push ss + ;pop es push ss pop fs push ss diff -r bb506432c82c -r e428345df29a linld/stuff/src/LINLD.CPP --- a/linld/stuff/src/LINLD.CPP Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/LINLD.CPP Thu Dec 22 21:06:17 2016 +0100 @@ -36,18 +36,18 @@ static char _cmdline[256]; int main(int argc, char *argv[]) { + + (void) argc; + // Believe it or not - this enables A20 // on my box! Must be DOS in HMA... -vda puts("LINLD v" VERSION_STR "+"); - if(argc<2) { -dosyntax: - syntax(); - } - // Parse command line - {for (char i=0;;) { - char *s=*++argv; + if (argv[1]) {for (char i=0;;) { + char *s; + argv++; + s=*argv; i++; if (!s) { puts(load_kernel()); @@ -113,9 +113,10 @@ cmdline = (const char *) _cmdline; } else - goto dosyntax; + break; }} + syntax(); // Let compiler be happy - // return _AX; + return _AX; } diff -r bb506432c82c -r e428345df29a linld/stuff/src/LOAD.CPP --- a/linld/stuff/src/LOAD.CPP Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/LOAD.CPP Thu Dec 22 21:06:17 2016 +0100 @@ -44,7 +44,6 @@ */ struct kernelparams_t { - u8 pad0; u8 setup_sects; // 01F1 The size of the setup in sectors // boot sector is NOT included here u16 ro_flag; // 01F2 If set, the root is mounted readonly @@ -101,7 +100,7 @@ u8 pad20[0x01e0-0xa0]; // this is set by rm setup: u32 alt_mem_size; // 01E0 extended memory size in Kb (from int 0x15 fn 0xe801) - u8 pad28[0x01f0-0x1e4]; + u8 pad28[0x01f1-0x1e4]; struct kernelparams_t params; }; //__attribute((packed)); @@ -112,95 +111,15 @@ const u32 HdrS = 'H' + ('d'<<8) + (u32('r')<<16) + (u32('S')<<24); u8* rm_buf; -static u16 rm_size; +u16 rm_size; u8 pm_high; -struct image_himem pm; -struct image_himem initrd; - -static void memcpy_image(struct image_himem *m) { - if (m->fallback != m->buf) - memcpy32( - m->fallback, // dst seg,ofs - 0, m->buf, // src seg,ofs - m->size // size - ); -} - -// Called from inside kernel just before rm->pm -// _loadds _saveregs: done by hand -void far last_ditch() { - cli(); // we start doing *really* destructive things to DOS/BIOS - // it means: do not even try to enable ints - // or call BIOS services after this - asm { - push ds - push cs - pop ds -#ifndef NO386 - pusha -#else - push ax - push bx - push cx - push dx -#endif - } - if(pm.fallback > _1m) pm.fallback = _1m; - if(vcpi==0) { - // Move kernel - memcpy_image(&pm); - // Move initrd - memcpy_image(&initrd); - } else { //vcpi - vm2rm(); - // Move kernel - // 'Gathering' copy in chunks of PAGE_SIZE - // No risk of overlapping: kernel is copied from above to 1m mark - pm.size = initrd.size = PAGE_SIZE; - u32 *p = pm.bufv; - if (p) while(*p) { - pm.buf = *p; - memcpy_image(&pm); - p++; pm.fallback+=PAGE_SIZE; - } - // Move initrd - if(initrd.fallback) { - // This is tricky: copy initrd backwards to reduce - // risk of overlapping: use the fact that initrd is copied - // to the very top of ram - // (overlapping still can happen with more than 256mb ram) - // (generic solution for this overwrite problem, anyone?) - p=initrd.bufv; - do { - p++; initrd.fallback+=PAGE_SIZE; - } while(*p); - do { - p--; initrd.fallback-=PAGE_SIZE; - initrd.buf = *p; - memcpy_image(&initrd); - } while(p != initrd.bufv); - } - } - asm { -#ifndef NO386 - popa -#else - pop dx - pop cx - pop bx - pop ax -#endif - pop ds - } -} +extern struct image_himem pm, initrd; // register value to launch the kernel real mode code #ifdef NO386 -static u32 sssp; static u32 csip; extern "C" u16 topseg(); #else -const u32 sssp=0x9000A000; static u32 csip=0x90200000; #define topseg() 0x9000 #endif @@ -209,7 +128,6 @@ char* load_kernel() { #ifdef NO386 - sssp=((u32)topseg()<<16)+0xA000; csip=((u32)(topseg()+0x20)<<16); #endif // Open kernel, read first kb, check it @@ -231,10 +149,10 @@ die(kernel_file_error); } - if(!kernelparams->setup_sects) { + if(kernelparams->setup_sects == 0) { #if 1 if(* (int *) &first1k->pad10[0x3F-0x24] == 0x3AE8) { - lseek(pm.fd,rm_seek=0x200,SEEK_SET); + lseekset(pm.fd,rm_seek=0x200); csip=((u32)topseg()<<16)+0x0042; } else @@ -275,7 +193,8 @@ hook_int15_88(); // * will be called just before rm -> pm - kernelparams->realmode_switch_ofs = ofs(last_ditch); + extern void far last_ditch(); + kernelparams->realmode_switch_ofs = ofs((void *)last_ditch); kernelparams->realmode_switch_seg = seg(last_ditch); } if(kernelparams->kernel_version) @@ -307,14 +226,17 @@ // Try to load kernel high, maybe even blindly storing it // in unallocated memory as a last resort - pm.fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4); - pm.size -= rm_size; - pm.chunk_size -= rm_size; - if(pm.fallback+pm.size > (((u32)topseg())<<4) || pm_high) { - pm.fallback = _1m+_64k; + { + struct image_himem *m = ± + m->fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4); + m->size -= rm_size; + m->chunk_size -= rm_size; + if(m->fallback+m->size > (((u32)topseg())<<4) || pm_high) { + m->fallback = _1m+_64k; } - load_image(&pm); + load_image(m); + } return version_string; } @@ -322,7 +244,7 @@ void load_initrd() { struct image_himem *m = &initrd; - if (!initrd_name && !initrd.fd) return; + if (!initrd_name && !m->fd) return; m->errmsg = "Can't use initrd file"; if (!pm.errmsg) { noinitrd: @@ -338,7 +260,7 @@ } load_image(m); - struct kernelparams_t *kernelparams = (kernelparams_t *)(rm_buf+0x1F0); + struct kernelparams_t *kernelparams = &(((first1k_t*) rm_buf)->params); if(kernelparams->header == HdrS) { kernelparams->initrd_buf = m->fallback; kernelparams->initrd_size = m->size; @@ -352,17 +274,13 @@ u16 new_SP=u16(heap_top)+0x100; if(_SP>new_SP) _SP=new_SP; } - if( u16(_CS)+(u16(_SP)>>4) >= topseg() ) { + if( (u16(_SP)>>4)+u16(_CS) >= topseg() ) { // Oops! We can stomp on our toes... better stop now die("Loaded too close to 9000:0"); } cli(); // we start doing destructive things to DOS - // Move rm loader & commandline to 0x90000 - // overkill: copy PAGE_SIZE bytes - rmcpy(rm_buf, rm_size); - - // Jump to kernel rm code - set_sregs_jump_seg_ofs(csip, sssp); + // Move rm loader & commandline to 0x90000, Jump to kernel rm code + set_sregs_jump_seg_ofs(csip); } diff -r bb506432c82c -r e428345df29a linld/stuff/src/MEMCPY32.ASM --- a/linld/stuff/src/MEMCPY32.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/MEMCPY32.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -116,34 +116,34 @@ push bp mov bp,sp sub sp,TEMP_SIZE + ;cld pushf - cld push ds es ifndef NO386 pushad + mov cl,4 movzx esi,[srcseg] - shl esi,4 - add [srcofs],esi - mov esi,[srcofs] + shl esi,cl + add esi,[srcofs] + mov [srcofs],esi ; for memcpy_vcpi mov edi,[dstofs] ifndef pm_only mov eax,esi - or eax,edi - shr eax,20 ; >1mb ? - jnz pmcopy - mov eax,esi - shr eax,4 + shr eax,cl mov edx,edi - shr edx,4 + shr edx,cl + mov ecx,esi + or ecx,edi + shr ecx,20 ; >1mb ? + jnz @@pmcopy @@movlp: mov ds,ax mov es,dx inc ax inc dx - xor ecx,ecx mov cl,0Fh and si,cx and di,cx @@ -151,19 +151,19 @@ sub [sz],ecx rep movsb ja @@movlp - jmp done + jmp @@done endif -pmcopy: +@@pmcopy: else push si xor bx,bx xor dx,dx xor si,si - mov ax,[bp+si+8] ; srcseg + mov ax,[bp+8] ; srcseg call near N_LXLSH@4 - add [bp+si+10],ax ; srcofs lo - adc [bp+si+10+2],dx ; srcofs hi + add [bp+10],ax ; srcofs lo + adc [bp+10+2],dx ; srcofs hi @@2flat: mov ax,[bp+si+10] ; srcofs, dstofs lo mov dx,[bp+si+10+2] ; srcofs, dstofs hi @@ -174,8 +174,8 @@ jnz @@2flat pop dx ; dstseg pop ax ; srcseg - or bx,bx ; <1mb ? - jnz pmcopy + test bx,bx ; <1mb ? (clear C) + jnz @@pmcopy push di @@movlp: mov ds,ax @@ -190,13 +190,13 @@ inc cx sub [word sz],cx rep movsb - jae @@movlp + ja @@movlp dec [word sz+2] - jns @@movlp ; mov 1-16 more bytes... - pop di si - jmp done16 -pmcopy: + jns @@movlp ; mov 1-16 more bytes... + pop di +@@pmcopy: pop si + js @@done16 pushad mov esi,[srcofs] mov edi,[dstofs] @@ -204,7 +204,7 @@ endif mov ecx,[sz] - jecxz done + jecxz @@done smsw ax test al,1 @@ -216,11 +216,8 @@ extrn call_pm_routine:near call near call_pm_routine ; Call pm copy routine via vcpi pm pop ax - jmp done + jmp @@done @@real_mode: - mov dx,-1 - -with_movsw: cmp esi,edi jae @@do_copy add esi,ecx ;src - mov [word GDTR],dx ;GDT limit = 0FFFFh + mov [word GDTR],-1 ;GDT limit = 0FFFFh mov [dword GDTR+2],eax ;GDT base lgdt [GDTR] ;****** Go into pm ********************************************* mov eax,cr0 - or al,01h ;CR0_PE on + inc ax ;CR0_PE on mov cr0,eax jmp short $+2 ;*Required*! ;3+ NOPs also work fine (chkd on 386) @@ -254,6 +251,7 @@ db 66h ;operand width override for ecx db 67h ;address width override for esi/edi rep movsb + cld ;****** Return to rm ******************************************* dec ax ;CR0_PE off @@ -263,9 +261,9 @@ ;****** Return ************************************************* lgdt [oldGDTR] -done: +@@done: popad -done16: +@@done16: pop es ds popf mov sp,bp diff -r bb506432c82c -r e428345df29a linld/stuff/src/MEMTOP.ASM --- a/linld/stuff/src/MEMTOP.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/MEMTOP.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -38,7 +38,7 @@ ;*************************************************************** ; proc _memtop_e801 near - push cx bx + ;push cx bx xor cx,cx ;fix to work around buggy xor dx,dx ; BIOSes which dont clear/set stc ; carry on pass/error of @@ -54,7 +54,7 @@ @@use_cxdx: xchg ax,cx @@end_kludge: ;now: dx=64k units above 16m ; ax=1k units above 1m below 16m (max 3c00h) - pop bx cx + ;pop bx cx test dx,dx jz tokb ;dx=0 here, ax=kbs above 1m xor ax,ax ;ignore info on low 16M (assume full) @@ -169,17 +169,22 @@ ifndef xmm_hook mov ax,4300h + ifdef NO386 + cwd + endif int 2fh - cmp al,80h + cmp al,80h ; 80h = XMS driver installed je @@skip endif + ifndef NO386 push 0 pop es mov bx,15*4 - ifndef NO386 mov eax,[bx] mov [saved15],eax else + mov es,dx + mov bx,15*4 mov ax,[bx] mov [word saved15],ax mov ax,[bx+2] diff -r bb506432c82c -r e428345df29a linld/stuff/src/TAZBOOT.CPP --- a/linld/stuff/src/TAZBOOT.CPP Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/TAZBOOT.CPP Thu Dec 22 21:06:17 2016 +0100 @@ -18,7 +18,7 @@ { m->chunk_size = 0; if (m->state >= initrd_state.cnt) return; - lseek(m->fd,initrd_state.ofs[m->state],SEEK_SET); + lseekset(m->fd,initrd_state.ofs[m->state]); m->chunk_size = initrd_state.size[m->state]; m->state++; } @@ -63,9 +63,10 @@ static void bootiso(char **iso) { char *init = " rdinit=/init.exe", *mode="menu"; - char *s, c, rootfs[16], fallback[16]; + char c, rootfs[16], fallback[16]; int restart, isknoppix = 0; unsigned long magic; + struct isostate *x=&isostate; if (!*iso || isoreset(*iso) < 0) return; skip_xmmalloc++; @@ -85,12 +86,12 @@ } while (isoopen("isolinux") >= 0); // Knoppix fallback[0] = 0; for (c = 0, restart = 1; isoreaddir(restart) == 0; restart = 0) { - if (strstr(isofilename, ".gz")) - strcpy(fallback, isofilename); - if (strhead(isofilename, "rootfs") - || c > isofilename[6]) continue; - strcpy(rootfs, isofilename); - c = isofilename[6]; + if (strstr(x->filename, ".gz")) + strcpy(fallback, x->filename); + if (strhead(x->filename, "rootfs") + || c > x->filename[6]) continue; + strcpy(rootfs, x->filename); + c = x->filename[6]; } strcpy(_cmdline,"rw root=/dev/null autologin bootfrom="); @@ -109,13 +110,13 @@ if (isoopen(initrd) >= 0) { addinitrd(); } - if (*init && lseek(isofd, 20L, SEEK_SET) != -1) { - read(isofd, &isofileofs, 4); - read(isofd, &magic, 4); - isofileofs &= 0xFFFFL; - isofilesize = magic & 0xFFFFL; - isofileofs -= 0xC0L + isofilesize; - if (isofilesize) addinitrd(); + if (*init && isolseek(20L) != -1) { + read(x->fd, &x->fileofs, 4); + read(x->fd, &magic, 4); + x->fileofs &= 0xFFFFL; + x->filesize = magic & 0xFFFFL; + x->fileofs -= 0xC0L + x->filesize; + if (x->filesize) addinitrd(); else init=""; } load_initrds(); @@ -126,12 +127,13 @@ strcat(_cmdline,ultoa(magic)); } if (isknoppix) { + char *s; if (iso[0][1] == ':') *iso += 2; for (s = *iso; *s; s++) if (*s == '\\') *s = '/'; } - close(isofd); + close(x->fd); boot_kernel(); } diff -r bb506432c82c -r e428345df29a linld/stuff/src/VCPI.ASM --- a/linld/stuff/src/VCPI.ASM Thu Dec 22 20:43:12 2016 +0100 +++ b/linld/stuff/src/VCPI.ASM Thu Dec 22 21:06:17 2016 +0100 @@ -240,7 +240,7 @@ ; Check that mapping for low 640k is 1:1 mov si,[page0_ofs] xor bx,bx - cld + ;cld @@map_chk: lodsd shr eax,12 @@ -373,7 +373,7 @@ ; Do copying mov ecx,4096/2 - cld + ;cld ;; cmp esi,edi ;; jae @@do_copy ;; add esi,ecx ;src