# HG changeset patch # User Pascal Bellard # Date 1573317583 -3600 # Node ID ee7d4644eb132cd5ddbb8b4ef53405a427195e12 # Parent 65ea21135647a2d55691555c46c50fa5f674108f linld: spare up to 30k more for zImage (again) diff -r 65ea21135647 -r ee7d4644eb13 linld/stuff/src/A20.ASM --- a/linld/stuff/src/A20.ASM Sat Nov 09 13:26:32 2019 +0100 +++ b/linld/stuff/src/A20.ASM Sat Nov 09 17:39:43 2019 +0100 @@ -17,7 +17,7 @@ enable_a20_methods: dw _enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die msg_a20 db "Can't use A20",0 -overflow db "Loaded too close to 9000:0",0 +overflow db "Out of memory",0 global sssp:dword global _initrd_desc:dword _initrd_desc dd 90000218h @@ -90,6 +90,8 @@ endp _enable_a20_fast + include "himem.inc" + ;*************************************************************** ;_fastcall void moverm(bx:struct himem *m); ;*************************************************************** @@ -97,6 +99,14 @@ global @moverm$qp11image_himem:near @moverm$qp11image_himem: push si di + extrn _pm_high:byte + mov si,offset _pm_high + ifdef MOVE_SETUP + mov di,8000h + sub di,[bx-4] ; rm size + extrn _rm_offset:word + mov [_rm_offset],di + endif extrn _heap_top:word ifdef NO386 mov ax,[_heap_top] @@ -104,36 +114,75 @@ shr ax,cl mov dx,cs add dx,ax + mov cx,0fffh + test [byte si],cl + jne @bzimage + xchg ax,dx + cmp ax,cx + jae @sys@ok + xchg ax,cx +@sys@ok: + inc ax + extrn N_LXLSH@4:near + call N_LXLSH@4 + mov [word ((image_himem bx).fallback)],ax + mov [word ((image_himem bx).fallback)+2],dx + add ax,[word ((image_himem bx).size)] + adc dx,[word ((image_himem bx).size)+2] + ifdef MOVE_SETUP + sub ax,di ; -rm_offset + sbb dx,cx + endif + mov cl,12 + shl dx,cl + jc @overflow +@bzimage: extrn _topseg:near call near _topseg mov [word sssp+2],ax else p386 - mov ax,[_heap_top] + movzx eax,[word _heap_top] shr ax,4 mov dx,cs - add dx,ax + add ax,dx + mov cx,0fffh + test [byte si],cl + jne @bzimage + cmp ax,cx + jae @sys@ok + xchg ax,cx +@sys@ok: + inc ax + shl eax,4 + mov [(image_himem bx).fallback],eax + add eax,[(image_himem bx).size] + ifdef MOVE_SETUP + extrn _rm_offset:word + movzx ecx,di ; -rm_offset + sub eax,ecx + endif + shl eax,4 +@bzimage: + xchg ax,dx mov ax,9000h endif mov es,ax cmp dx,ax - jb @@nooverflow + jb @nooverflow +@overflow: ; Oops! We can stomp on our toes... better stop now mov bx,offset overflow call near die -@@nooverflow: - mov cx,[bx-4] ; size - mov si,[bx-2] ; data +@nooverflow: + ifdef MOVE_SETUP + cmp [si],al + je @@do_move + endif xor di,di - ifdef MOVE_SETUP - extrn _pm_high:byte - cmp [_pm_high],al - jne @@move_clear - mov di,8000h - sub di,cx - extrn _rm_offset:word - mov [_rm_offset],di - endif +@@do_move: + mov si,[bx-2] ; rm data + mov cx,[bx-4] ; rm size @@move_clear: movsb mov [byte si-1],al diff -r 65ea21135647 -r ee7d4644eb13 linld/stuff/src/LOAD.CPP --- a/linld/stuff/src/LOAD.CPP Sat Nov 09 13:26:32 2019 +0100 +++ b/linld/stuff/src/LOAD.CPP Sat Nov 09 17:39:43 2019 +0100 @@ -175,6 +175,7 @@ extern void far last_ditch(); kernelparams->realmode_switch_ofs = (u16) last_ditch; kernelparams->realmode_switch_seg = _CS; + m->fallback = base_himem; pm_high++; // Hook on int15 to work around fn 88 DOS breakage @@ -209,21 +210,6 @@ // Try to load kernel high, maybe even blindly storing it // in unallocated memory as a last resort -#ifdef MOVE_SETUP - extern unsigned rm_offset; - if((u16)(((m->fallback=(u32(u16(_CS)+(u16(heap_top)>>4)+1)<<4)) - +m->size-rm_offset)>>16) >= -#else - if((u16)(((m->fallback=(u32(u16(_CS)+(u16(heap_top)>>4)+1)<<4))+m->size)>>16) >= -#endif - (u16)(topseg()>>12) || pm_high) { - m->fallback = base_himem; - } - if (((u16 *)&m->fallback)[1] == 0) { - ((u16 *)&m->fallback)[0] &= 0; - ((u16 *)&m->fallback)[1]++; // m->fallback = _64k; - } - load_image(m); } diff -r 65ea21135647 -r ee7d4644eb13 linld/stuff/src/pipehole.awk --- a/linld/stuff/src/pipehole.awk Sat Nov 09 13:26:32 2019 +0100 +++ b/linld/stuff/src/pipehole.awk Sat Nov 09 17:39:43 2019 +0100 @@ -162,53 +162,14 @@ if (/_version_string,/) isload=0 if (/mov bx,ax/) next } - if (/topseg\(\)>>12/) isload=4 - if (isload == 4 && is386 == 0) { # LOAD.LST - if (/push/ || /pop/) next - if (/ax,cs/) { - sub(/ax,cs/,"bx,cs") + if (/_base_himem\+2/ && is386 == 0) isload=4 + if (isload == 4) { # LOAD.LST + if (/_base_himem\+2/) next + if (/_base_himem$/) { + sub(/mov dx,/,"les dx,d") } - if (/dx,dx/) next - sub(/ax,dx/,"ax,bx") - if (/call/) { - print " cmp ax,0fffh" - print " jae @sys@ok" - print " mov ax,0fffh" - print "@sys@ok:" - isload=400 - } - } - if (isload == 400) { - if (/call/) { - print " extrn N_LXLSH@4:near" - sub(/N_LXLSH@/,"N_LXLSH@4") - } - sub(/pm_high,0/,"pm_high,dh") - if (/_base_himem\+2/ || /pop/ || /push/) next - if (/_base_himem$/) { - sub(/mov dx,/,"les ax,d") - isload++ - } - } - if (isload == 401) { sub(/,ax/,",es") - sub(/,dx/,",ax") - if (/load_image/) isload=0 - } - if (isload == 4 && is386) { # LOAD.LST - sub(/dx,cs/,"edx,cs") - sub(/eax/,"edx") - if (/shl/) { - print " mov ax,0fffh" - print " cmp dx,ax" - print " jae @sys@ok" - print " xchg ax,dx" - print "@sys@ok:" - } - sub(/ax,9/,"dx,9") - if (/,0$/) sub(/,0/,",dh") - if (/movzx/) next - if (/fallback = base_himem/) { isload=0 } + if (/,dx/) isload=0 } if (/void load_initrd\(\)/) isload=3 if (isload == 3) { # LOAD.LST