wok-current rev 22180

linld: spare up to 30k more for zImage (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 09 17:39:43 2019 +0100 (2019-11-09)
parents 65ea21135647
children 08212b207b25
files linld/stuff/src/A20.ASM linld/stuff/src/LOAD.CPP linld/stuff/src/pipehole.awk
line diff
     1.1 --- a/linld/stuff/src/A20.ASM	Sat Nov 09 13:26:32 2019 +0100
     1.2 +++ b/linld/stuff/src/A20.ASM	Sat Nov 09 17:39:43 2019 +0100
     1.3 @@ -17,7 +17,7 @@
     1.4  enable_a20_methods:
     1.5  		dw	_enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die
     1.6  msg_a20		db	"Can't use A20",0
     1.7 -overflow	db	"Loaded too close to 9000:0",0
     1.8 +overflow	db	"Out of memory",0
     1.9  	global	sssp:dword
    1.10  	global	_initrd_desc:dword
    1.11  _initrd_desc	dd	90000218h
    1.12 @@ -90,6 +90,8 @@
    1.13  
    1.14          endp    _enable_a20_fast
    1.15  
    1.16 +	include	"himem.inc"
    1.17 +
    1.18  ;***************************************************************
    1.19  ;_fastcall void moverm(bx:struct himem *m);
    1.20  ;***************************************************************
    1.21 @@ -97,6 +99,14 @@
    1.22  	global	@moverm$qp11image_himem:near
    1.23  @moverm$qp11image_himem:
    1.24  		push	si di
    1.25 +		extrn	_pm_high:byte
    1.26 +		mov	si,offset _pm_high
    1.27 +		ifdef	MOVE_SETUP
    1.28 +		mov	di,8000h
    1.29 +		sub	di,[bx-4]	; rm size
    1.30 +		extrn	_rm_offset:word
    1.31 +		mov	[_rm_offset],di
    1.32 +		endif
    1.33  		extrn	_heap_top:word
    1.34  		ifdef	NO386
    1.35  		mov	ax,[_heap_top]
    1.36 @@ -104,36 +114,75 @@
    1.37  		shr	ax,cl
    1.38  		mov	dx,cs
    1.39  		add	dx,ax
    1.40 +		mov	cx,0fffh
    1.41 +		test	[byte si],cl
    1.42 +		jne	@bzimage
    1.43 +		xchg	ax,dx
    1.44 +		cmp	ax,cx
    1.45 +		jae	@sys@ok
    1.46 +		xchg	ax,cx
    1.47 +@sys@ok:
    1.48 +		inc	ax
    1.49 +		extrn	N_LXLSH@4:near
    1.50 +		call	N_LXLSH@4
    1.51 +		mov	[word ((image_himem bx).fallback)],ax
    1.52 +		mov	[word ((image_himem bx).fallback)+2],dx
    1.53 +		add	ax,[word ((image_himem bx).size)]
    1.54 +		adc	dx,[word ((image_himem bx).size)+2]
    1.55 +		ifdef	MOVE_SETUP
    1.56 +		sub	ax,di	; -rm_offset
    1.57 +		sbb	dx,cx
    1.58 +		endif
    1.59 +		mov	cl,12
    1.60 +		shl	dx,cl
    1.61 +		jc	@overflow
    1.62 +@bzimage:
    1.63  		extrn	_topseg:near
    1.64  		call	near _topseg
    1.65  		mov	[word sssp+2],ax
    1.66  		else
    1.67                  p386
    1.68 -		mov	ax,[_heap_top]
    1.69 +		movzx	eax,[word _heap_top]
    1.70  		shr	ax,4
    1.71  		mov	dx,cs
    1.72 -		add	dx,ax
    1.73 +		add	ax,dx
    1.74 +		mov	cx,0fffh
    1.75 +		test	[byte si],cl
    1.76 +		jne	@bzimage
    1.77 +		cmp	ax,cx
    1.78 +		jae	@sys@ok
    1.79 +		xchg	ax,cx
    1.80 +@sys@ok:
    1.81 +		inc	ax
    1.82 +		shl	eax,4
    1.83 +		mov	[(image_himem bx).fallback],eax
    1.84 +		add	eax,[(image_himem bx).size]
    1.85 +		ifdef	MOVE_SETUP
    1.86 +		extrn	_rm_offset:word
    1.87 +		movzx	ecx,di			; -rm_offset
    1.88 +		sub	eax,ecx
    1.89 +		endif
    1.90 +		shl	eax,4
    1.91 +@bzimage:
    1.92 +		xchg	ax,dx
    1.93  		mov	ax,9000h
    1.94  		endif
    1.95  		mov	es,ax
    1.96  		cmp	dx,ax
    1.97 -		jb	@@nooverflow
    1.98 +		jb	@nooverflow
    1.99 +@overflow:
   1.100  ; Oops! We can stomp on our toes... better stop now
   1.101  		mov	bx,offset overflow
   1.102  		call	near die
   1.103 -@@nooverflow:
   1.104 -		mov	cx,[bx-4]	; size
   1.105 -		mov	si,[bx-2]	; data
   1.106 +@nooverflow:
   1.107 +		ifdef	MOVE_SETUP
   1.108 +		cmp	[si],al
   1.109 +		je	@@do_move
   1.110 +		endif
   1.111  		xor	di,di
   1.112 -		ifdef	MOVE_SETUP
   1.113 -		extrn	_pm_high:byte
   1.114 -		cmp	[_pm_high],al
   1.115 -		jne	@@move_clear
   1.116 -		mov	di,8000h
   1.117 -		sub	di,cx
   1.118 -		extrn	_rm_offset:word
   1.119 -		mov	[_rm_offset],di
   1.120 -		endif
   1.121 +@@do_move:
   1.122 +		mov	si,[bx-2]	; rm data
   1.123 +		mov	cx,[bx-4]	; rm size
   1.124  @@move_clear:
   1.125  		movsb
   1.126  		mov	[byte si-1],al
     2.1 --- a/linld/stuff/src/LOAD.CPP	Sat Nov 09 13:26:32 2019 +0100
     2.2 +++ b/linld/stuff/src/LOAD.CPP	Sat Nov 09 17:39:43 2019 +0100
     2.3 @@ -175,6 +175,7 @@
     2.4  	    extern void far last_ditch();
     2.5  	    kernelparams->realmode_switch_ofs = (u16) last_ditch;
     2.6  	    kernelparams->realmode_switch_seg = _CS;
     2.7 +	    m->fallback = base_himem;
     2.8              pm_high++;
     2.9  
    2.10              // Hook on int15 to work around fn 88 DOS breakage
    2.11 @@ -209,21 +210,6 @@
    2.12      // Try to load kernel high, maybe even blindly storing it
    2.13      // in unallocated memory as a last resort
    2.14  
    2.15 -#ifdef	MOVE_SETUP
    2.16 -    extern unsigned rm_offset;
    2.17 -    if((u16)(((m->fallback=(u32(u16(_CS)+(u16(heap_top)>>4)+1)<<4))
    2.18 -             +m->size-rm_offset)>>16) >=
    2.19 -#else
    2.20 -    if((u16)(((m->fallback=(u32(u16(_CS)+(u16(heap_top)>>4)+1)<<4))+m->size)>>16) >=
    2.21 -#endif
    2.22 -		 (u16)(topseg()>>12) || pm_high) {
    2.23 -        m->fallback = base_himem;
    2.24 -    }
    2.25 -    if (((u16 *)&m->fallback)[1] == 0) {
    2.26 -	((u16 *)&m->fallback)[0] &= 0;
    2.27 -	((u16 *)&m->fallback)[1]++;	// m->fallback = _64k;
    2.28 -    }
    2.29 -
    2.30      load_image(m);
    2.31  }
    2.32  
     3.1 --- a/linld/stuff/src/pipehole.awk	Sat Nov 09 13:26:32 2019 +0100
     3.2 +++ b/linld/stuff/src/pipehole.awk	Sat Nov 09 17:39:43 2019 +0100
     3.3 @@ -162,53 +162,14 @@
     3.4  		if (/_version_string,/) isload=0
     3.5  		if (/mov	bx,ax/) next
     3.6  	}
     3.7 -	if (/topseg\(\)>>12/) isload=4
     3.8 -	if (isload == 4 && is386 == 0) {  # LOAD.LST
     3.9 -		if (/push/ || /pop/) next
    3.10 -		if (/ax,cs/) {
    3.11 -			sub(/ax,cs/,"bx,cs")
    3.12 +	if (/_base_himem\+2/ && is386 == 0) isload=4
    3.13 +	if (isload == 4) {  # LOAD.LST
    3.14 +		if (/_base_himem\+2/) next
    3.15 +		if (/_base_himem$/) {
    3.16 +			sub(/mov	dx,/,"les	dx,d")
    3.17  		}
    3.18 -		if (/dx,dx/) next
    3.19 -		sub(/ax,dx/,"ax,bx")
    3.20 -		if (/call/) {
    3.21 -			print	"	cmp	ax,0fffh"
    3.22 -			print	"	jae	@sys@ok"
    3.23 -			print	"	mov	ax,0fffh"
    3.24 -			print	"@sys@ok:"
    3.25 -			isload=400
    3.26 -		}
    3.27 -	}
    3.28 -	if (isload == 400) {
    3.29 -		if (/call/) {
    3.30 -			print	"	extrn	N_LXLSH@4:near"
    3.31 -			sub(/N_LXLSH@/,"N_LXLSH@4")
    3.32 -		}
    3.33 -		sub(/pm_high,0/,"pm_high,dh")
    3.34 -		if (/_base_himem\+2/ || /pop/ || /push/) next
    3.35 -		if (/_base_himem$/) {
    3.36 -			sub(/mov	dx,/,"les	ax,d")
    3.37 -			isload++
    3.38 -		}
    3.39 -	}
    3.40 -	if (isload == 401) {
    3.41  		sub(/,ax/,",es")
    3.42 -		sub(/,dx/,",ax")
    3.43 -		if (/load_image/) isload=0
    3.44 -	}
    3.45 -	if (isload == 4 && is386) {  # LOAD.LST
    3.46 -		sub(/dx,cs/,"edx,cs")
    3.47 -		sub(/eax/,"edx")
    3.48 -		if (/shl/) {
    3.49 -			print	"	mov	ax,0fffh"
    3.50 -			print	"	cmp	dx,ax"
    3.51 -			print	"	jae	@sys@ok"
    3.52 -			print	"	xchg	ax,dx"
    3.53 -			print	"@sys@ok:"
    3.54 -		}
    3.55 -		sub(/ax,9/,"dx,9")
    3.56 -		if (/,0$/) sub(/,0/,",dh")
    3.57 -		if (/movzx/) next
    3.58 -		if (/fallback = base_himem/) { isload=0 }
    3.59 +		if (/,dx/) isload=0
    3.60  	}
    3.61  	if (/void load_initrd\(\)/) isload=3
    3.62  	if (isload == 3) {  # LOAD.LST