wok rev 20634

linld: fix open()
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 08 17:51:51 2019 +0100 (2019-01-08)
parents 251d56fab8e3
children 2c334466695f
files linld/stuff/src/CRTL.ASM linld/stuff/src/LOAD.CPP linld/stuff/src/pipehole.awk
line diff
     1.1 --- a/linld/stuff/src/CRTL.ASM	Sat Jan 05 17:29:09 2019 +0100
     1.2 +++ b/linld/stuff/src/CRTL.ASM	Tue Jan 08 17:51:51 2019 +0100
     1.3 @@ -204,6 +204,7 @@
     1.4  		xor	cx,cx			; attributes
     1.5  		xor	di,di			; alias hint
     1.6  		cwd				; action = open
     1.7 +		stc
     1.8                  int	21h
     1.9  		pop	si di bx
    1.10                  jnc	doret
    1.11 @@ -338,7 +339,7 @@
    1.12  isolseek:
    1.13  		extrn	_isostate:isostate
    1.14  		mov	ax,[_isostate.fd]
    1.15 -	global	@lseekset2$qipul
    1.16 +	global	@lseekset2$qipul:near
    1.17  @lseekset2$qipul:
    1.18  		mov	dx,[bx]
    1.19  		mov	cx,[bx+2]
     2.1 --- a/linld/stuff/src/LOAD.CPP	Sat Jan 05 17:29:09 2019 +0100
     2.2 +++ b/linld/stuff/src/LOAD.CPP	Tue Jan 08 17:51:51 2019 +0100
     2.3 @@ -114,7 +114,6 @@
     2.4  u16 rm_size;
     2.5  static u8 pm_high;	// @ = @rm_size + 2, see JUMP.ASM
     2.6  static u8* rm_buf;	// @ = @rm_size + 3, see JUMP.ASM
     2.7 -u32 base_himem = _1m+_64k;
     2.8  struct image_himem imgs[2];
     2.9  
    2.10  // register value to launch the kernel real mode code
    2.11 @@ -125,15 +124,15 @@
    2.12  u32 csip=0x90200000;
    2.13  #define topseg() 0x9000
    2.14  #endif
    2.15 +u32 base_himem = _1m+_64k;
    2.16  
    2.17  static const char kernel_file_error[] = "Can't use kernel file";
    2.18  char* load_kernel() {
    2.19  
    2.20      struct	image_himem *m = &pm;
    2.21 -#define _base_himem	(((u32*)(m))[-1])
    2.22 -#define _rm_buf(m)	(((u8**)(m))[-3])
    2.23 -#define _pm_high	(((u8*)(m))[-7])
    2.24 -#define _rm_size	(*(u16*)((u8*)(m)-9))
    2.25 +#define _rm_buf(m)	(((u8**)(m))[-1])
    2.26 +#define _pm_high	(((u8*)(m))[-3])
    2.27 +#define _rm_size	(*(u16*)((u8*)(m)-5))
    2.28  #ifdef NO386
    2.29  #define _csip		(*(u32*)(m+2))
    2.30      *((u16 *)&csip+1)=topseg()+0x20;
    2.31 @@ -229,7 +228,7 @@
    2.32      struct image_himem *m = &pm;
    2.33      if((u16)(((m->fallback=(u32((u16(_CS)+0x1FFF)&0xF000)<<4))+m->size)>>4) >
    2.34  		 topseg() || _pm_high) {
    2.35 -        m->fallback = _base_himem;
    2.36 +        m->fallback = base_himem;
    2.37      }
    2.38  
    2.39      load_image(m);
    2.40 @@ -237,8 +236,22 @@
    2.41      return version_string;
    2.42  }
    2.43  
    2.44 +struct initrdparams_t {
    2.45 +    u32     header;         // 0202 Magic signature "HdrS"
    2.46 +    u16     version;        // 0206 Boot protocol version supported
    2.47 +    u16     realmode_switch_ofs; // 0208 Hook called just before rm->pm
    2.48 +    u16     realmode_switch_seg;
    2.49 +    u16     start_sys_seg;  // 020E
    2.50 +    u16     kernel_version; // 020C Points to kernel version string
    2.51 +    u8      type_of_loader; // 0210 Boot loader identifier
    2.52 +    u8      loadflags;      // 0211 Boot protocol option flags
    2.53 +    u16     setup_move_size;// 0212 Move to high memory size (used with hooks)
    2.54 +    u32     code32_start;   // 0214 Boot loader hook (see below)
    2.55 +    u32     initrd_buf;     // 0218 initrd load address (set by boot loader)
    2.56 +    u32     initrd_size;    // 021C initrd size (set by boot loader)
    2.57 +};
    2.58 +
    2.59  // Read initrd if needed
    2.60 -
    2.61  void load_initrd() {
    2.62      struct image_himem *m = &initrd;
    2.63      if (!initrd_name && !m->fd) return;
    2.64 @@ -259,9 +272,10 @@
    2.65      }
    2.66  
    2.67      load_image(m);
    2.68 -    struct kernelparams_t *kernelparams = &(((first1k_t*) _rm_buf(m-1))->params);
    2.69 -    if(kernelparams->header == HdrS) {
    2.70 -        kernelparams->initrd_buf  = m->fallback;
    2.71 -        kernelparams->initrd_size = m->size;
    2.72 +
    2.73 +    struct initrdparams_t *initrdparams = ((struct initrdparams_t *)&(((first1k_t*) _rm_buf(m-1))->params.header));
    2.74 +    if(initrdparams->header == HdrS) {
    2.75 +        initrdparams->initrd_buf  = m->fallback;
    2.76 +        initrdparams->initrd_size = m->size;
    2.77      }
    2.78  }
     3.1 --- a/linld/stuff/src/pipehole.awk	Sat Jan 05 17:29:09 2019 +0100
     3.2 +++ b/linld/stuff/src/pipehole.awk	Tue Jan 08 17:51:51 2019 +0100
     3.3 @@ -2,6 +2,7 @@
     3.4  function isnum(n) { return match(n,/^[0-9+-]/) }
     3.5  {
     3.6  	sub(/segment word public/,"segment byte public")
     3.7 +
     3.8  	if (hold == 0) {
     3.9  		s=$0
    3.10  		if (/^	mov	.[ix],bx$/ || /^	mov	.[ix],.i$/) {
    3.11 @@ -27,6 +28,13 @@
    3.12  		if (/^	cmp	word ptr DGROUP:.*,0$/)  {
    3.13  			hold=8; split($2,regs,","); next
    3.14  		}
    3.15 +		if (/^	cbw/)		  { hold=11; kept=0; next }
    3.16 +		if (/^	add	[abcds][ix],2$/) {
    3.17 +			split($2,regs,","); hold=12; next
    3.18 +		}
    3.19 +		if (/^	sub	[abcds][ix],2$/) {
    3.20 +			split($2,regs,","); hold=13; next
    3.21 +		}
    3.22  	}
    3.23  	else if (hold == 1) {
    3.24  		if (/^   ;/) { line[kept++]=$0; next }
    3.25 @@ -130,6 +138,39 @@
    3.26  		}
    3.27  		for (i = 0; i < kept; i++) print line[i]
    3.28  	}
    3.29 +	else if (hold == 11) {
    3.30 +		if (/^	inc	ax$/ || /^	dec	ax$/) {
    3.31 +			line[kept++]=$0; next
    3.32 +		}
    3.33 +		split($2,args,",")
    3.34 +		if (/^	mov	cl,/) {
    3.35 +			split($2,args,",")
    3.36 +			if (args[2] >= 8) {
    3.37 +				line[kept++]=$0; next
    3.38 +			}
    3.39 +		}
    3.40 +		if (!/^	shl	ax,/ || (args[2] != "cl" && args[2] < 8)) {
    3.41 +			print "	cbw	"
    3.42 +		}
    3.43 +		for (i = 0; i < kept; i++) print line[i]
    3.44 +		hold=kept=0
    3.45 +	}
    3.46 +	else if (hold == 12) {
    3.47 +		hold=0
    3.48 +		if ($1 != "adc" && $1 != "sbb" && ! /^	jn?[abc]/) {
    3.49 +			print "	inc	" regs[1]
    3.50 +			print "	inc	" regs[1]
    3.51 +		}
    3.52 +		else	print "	add	" regs[1] ",2"
    3.53 +	}
    3.54 +	else if (hold == 13) {
    3.55 +		hold=0
    3.56 +		if ($1 != "adc" && $1 != "sbb" && ! /^	jn?[abc]/) {
    3.57 +			print "	dec	" regs[1]
    3.58 +			print "	dec	" regs[1]
    3.59 +		}
    3.60 +		else	print "	sub	" regs[1] ",2"
    3.61 +	}
    3.62  	s=$0
    3.63  	# These optimisation may break ZF or CF
    3.64  	if (/^	sub	sp,2$/) { print "	push	ax"; next }