wok-6.x rev 17450

syslinux/iso2exe: fix kernel_version
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Dec 16 18:59:28 2014 +0100 (2014-12-16)
parents a8ed437fce5b
children aca562aa836e
files syslinux/stuff/iso2exe/README syslinux/stuff/iso2exe/a20.c syslinux/stuff/iso2exe/bootlinux.c
line diff
     1.1 --- a/syslinux/stuff/iso2exe/README	Tue Dec 16 18:51:42 2014 +0100
     1.2 +++ b/syslinux/stuff/iso2exe/README	Tue Dec 16 18:59:28 2014 +0100
     1.3 @@ -50,7 +50,7 @@
     1.4  
     1.5  The iso2exe tool moves the isolinux boot sector, installs its own boot sector 
     1.6  with a DOS .EXE header, and adds a WIN32 .EXE installer, a DOS .COM Linux
     1.7 -loader and an initramfs in the end of the first 32Kb.
     1.8 +loader, a floppy bootstrap and an initramfs in the end of the first 32Kb.
     1.9  
    1.10      +-----------------+
    1.11      |    untouched    | ISO9660 files including /boot/bzImage and /boot/rootfs*
     2.1 --- a/syslinux/stuff/iso2exe/a20.c	Tue Dec 16 18:51:42 2014 +0100
     2.2 +++ b/syslinux/stuff/iso2exe/a20.c	Tue Dec 16 18:59:28 2014 +0100
     2.3 @@ -1,65 +1,39 @@
     2.4  #ifndef __A20
     2.5  #define __A20
     2.6  
     2.7 -#define A20HOLDBUFFER	0x80000
     2.8 -static int a20buffer = 0;
     2.9 -static void movehia20(void)
    2.10 -{
    2.11 -	if ((mem.base >> 16) != 0x10) {
    2.12 -		movehi();
    2.13 -		return;
    2.14 -	}
    2.15 -	a20buffer = 1;
    2.16 -#asm
    2.17 -		pusha			// more than 1Mb => 286+
    2.18 -		push	#A20HOLDBUFFER/16
    2.19 -		pop	es
    2.20 -		mov	di, _mem	// mem.base & 0xFFFF
    2.21 -		mov	si, #_buffer
    2.22 -		mov	cx, #BUFFERSZ/2
    2.23 -		cld
    2.24 -		rep
    2.25 -		  movsw
    2.26 -		popa
    2.27 -#endasm
    2.28 -}
    2.29 -#define movehi movehia20
    2.30 -
    2.31  static void dosshutdowna20(void)
    2.32  {
    2.33 -	if (a20buffer) {
    2.34  #asm
    2.35 +	call	_dosshutdown
    2.36 +	xor	ax, ax			// 30
    2.37 +	cmp	ax, _a20buffer
    2.38 +	je	no_a20buffer
    2.39  		pusha			// more than 1Mb => 286+
    2.40 -		xor	di, di		// 30
    2.41  		mov	cx, #9		// 2E..1E
    2.42  a20z1:
    2.43 -		push	di
    2.44 +		push	ax
    2.45  		loop	a20z1
    2.46 -		push	#0x10
    2.47 -		push	di		// 1A 0x100000
    2.48 +		push	#0x9310
    2.49 +		push	ax		// 1A 0x100000
    2.50  		push	#-1		// 18
    2.51 -		push	di		// 16
    2.52 -		push	#A20HOLDBUFFER/0x10000
    2.53 -		push	di		// 12 A20HOLDBUFFER
    2.54 +		push	ax		// 16
    2.55 +		push	#0x9300+A20HOLDBUFFER/0x10000
    2.56 +		push	ax		// 12 A20HOLDBUFFER
    2.57  		push	#-1		// 10
    2.58  		mov	cl, #8		// 0E..00
    2.59  a20z2:
    2.60 -		push	di
    2.61 +		push	ax
    2.62  		loop	a20z2
    2.63  		mov	ch, #0x10000/512
    2.64  		push	ss
    2.65  		pop	es
    2.66  		mov	si, sp
    2.67 -		mov	ax, #0x8793
    2.68 -		mov	[si+0x15], al
    2.69 -		xchg	[si+0x1D], al
    2.70 -		xchg	[si+0x1F], al	// bits 24..31
    2.71 +		mov	ah, #0x87
    2.72  		int	0x15
    2.73  		add	sp, #0x30
    2.74  		popa
    2.75 +no_a20buffer:
    2.76  #endasm
    2.77 -	}
    2.78 -	dosshutdown();
    2.79  }
    2.80  
    2.81  #define dosshutdown dosshutdowna20
     3.1 --- a/syslinux/stuff/iso2exe/bootlinux.c	Tue Dec 16 18:51:42 2014 +0100
     3.2 +++ b/syslinux/stuff/iso2exe/bootlinux.c	Tue Dec 16 18:59:28 2014 +0100
     3.3 @@ -2,7 +2,6 @@
     3.4  #include "libdos.h"
     3.5  #include "iso9660.h"
     3.6  
     3.7 -static unsigned setup_version;
     3.8  #define ELKSSIG		0x1E6
     3.9  #define SETUPSECTORS	0x1F1
    3.10  #define ROFLAG		0x1F2
    3.11 @@ -45,9 +44,9 @@
    3.12  static int vm86(void)
    3.13  {
    3.14  #asm
    3.15 -		xor	ax, ax
    3.16 -		cmp	ax, _iselks
    3.17 -		jne	fakerealmode	// elks may run on a 8086
    3.18 +		mov	ax, _iselks
    3.19 +		dec	ax
    3.20 +		je	fakerealmode	// elks may run on a 8086
    3.21  		smsw	ax		// 286+
    3.22  		and	ax, #1		// 0:realmode	1:vm86
    3.23  fakerealmode:
    3.24 @@ -59,37 +58,51 @@
    3.25  	int align;
    3.26  } mem = { 0x100000, 0 };
    3.27  
    3.28 +#ifdef __MSDOS__ 
    3.29 +#define A20HOLDBUFFER	0x80000
    3.30 +static int a20buffer = 0;
    3.31 +#endif
    3.32 +
    3.33  static void movehi(void)
    3.34  {
    3.35  #asm
    3.36  		push	si
    3.37  		push	di
    3.38  
    3.39 +		xor	ax, ax
    3.40  		mov	si, #_mem
    3.41  		cmp	word ptr [si+2], #0x10
    3.42 +#ifdef __MSDOS__ 
    3.43 +		jne	nota20
    3.44 +		mov	ax, #A20HOLDBUFFER/16
    3.45 +		mov	_a20buffer, ax
    3.46 +		mov	di, [si]	// mem.base & 0xFFFF
    3.47 +		jmp	mvbuffer
    3.48 +nota20:
    3.49 +#endif
    3.50  		jnc	movehiz
    3.51 -		mov	ax, [si+1]
    3.52 +		lodsb
    3.53 +		xchg	ax, di
    3.54 +		lodsw
    3.55  		mov	cl, #4
    3.56  		shl	ax, cl		// 8086 support for elks
    3.57 +mvbuffer:
    3.58  		mov	es, ax
    3.59 -		mov	di, #0x00FF
    3.60 -		and	di, [si]
    3.61  		mov	si, #_buffer
    3.62 +		cld
    3.63  		mov	cx, #BUFFERSZ/2
    3.64 -		cld
    3.65  		rep
    3.66  		  movw
    3.67  		jmp	movedone
    3.68 -movehiz:
    3.69 -		xor	di, di		// 30
    3.70 +movehiz:				// 30
    3.71  		mov	cx, #9		// 2E..1E
    3.72  zero1:
    3.73 -		push	di
    3.74 +		push	ax
    3.75  		loop	zero1
    3.76  		push	dword [si]	// 1A mem.base
    3.77  		push	#-1		// 18
    3.78 -		push	di		// 16
    3.79 -		xor	eax, eax
    3.80 +		push	ax		// 16
    3.81 +		cwde
    3.82  		cdq
    3.83  		mov	dx, ds
    3.84  		shl	edx, #4
    3.85 @@ -99,7 +112,7 @@
    3.86  		push	#-1		// 10
    3.87  		mov	cl, #8		// 0E..00
    3.88  zero2:
    3.89 -		push	di
    3.90 +		push	#0
    3.91  		loop	zero2
    3.92  		mov	ch, #BUFFERSZ/512
    3.93  		push	ss
    3.94 @@ -117,10 +130,6 @@
    3.95  #endasm
    3.96  }
    3.97  
    3.98 -#define ZIMAGE_SUPPORT
    3.99 -#define FULL_ZIMAGE
   3.100 -
   3.101 -#ifdef ZIMAGE_SUPPORT
   3.102  static unsigned zimage = 0;
   3.103  static unsigned getss(void)
   3.104  {
   3.105 @@ -128,7 +137,6 @@
   3.106  	mov	ax, ss
   3.107  #endasm
   3.108  }
   3.109 -#endif
   3.110  
   3.111  static unsigned extendedramsizeinkb(void)
   3.112  {
   3.113 @@ -190,12 +198,13 @@
   3.114  #asm
   3.115  		push	si
   3.116  		mov	es, _setupseg
   3.117 +		xchg	di, _setupofs
   3.118  		mov	si, #_buffer
   3.119 -		xchg	di, _setupofs
   3.120 +		cld
   3.121  		mov	cx, #BUFFERSZ/2
   3.122  		rep
   3.123  		  movsw
   3.124 -		xchg	_setupofs, di
   3.125 +		xchg	di, _setupofs
   3.126  		pop	si
   3.127  #endasm
   3.128  }
   3.129 @@ -207,16 +216,25 @@
   3.130  #endasm
   3.131  }
   3.132  
   3.133 +#define WORD(x)	* (unsigned short *) (x)
   3.134 +#define LONG(x)	* (unsigned long *) (x)
   3.135 +static unsigned setup_version = 0;
   3.136  static unsigned long kernel_version = 0;
   3.137  unsigned long loadkernel(void)
   3.138  {
   3.139 -	unsigned setup, n = BUFFERSZ;
   3.140 +	unsigned setup;
   3.141 +#define LINUX001_SUPPORT
   3.142 +#ifdef LINUX001_SUPPORT
   3.143 +	unsigned n = 512;
   3.144 +#else
   3.145 +	unsigned n = BUFFERSZ;
   3.146 +#endif
   3.147  	unsigned long syssize = 0;
   3.148  
   3.149  	do {
   3.150  		isoread(buffer, n);
   3.151  		if (setupofs == 0) {
   3.152 -			if (* (unsigned short *) (buffer + BOOTFLAG) != 0xAA55)
   3.153 +			if (WORD(buffer + BOOTFLAG) != 0xAA55)
   3.154  				die("The kernel is not bootable");
   3.155  #asm
   3.156  			int	0x12
   3.157 @@ -230,16 +248,25 @@
   3.158  			mov	_setupseg, ax
   3.159  has640k:
   3.160  #endasm
   3.161 +			syssize = LONG(buffer + SYSSIZE) << 4;
   3.162 +			if (!syssize) syssize = 0x7F000;
   3.163  			setup = (1 + buffer[SETUPSECTORS]) << 9;
   3.164 -			if (setup == 512) setup = 5 << 9;
   3.165 -			syssize = * (unsigned long  *) (buffer + SYSSIZE) << 4;
   3.166 -			if (!syssize) syssize = 0x7F000;
   3.167 -			setup_version = * (unsigned short *) (buffer + VERSION);
   3.168 +			if (setup == 512) {
   3.169 +#ifdef LINUX001_SUPPORT
   3.170 +				if (WORD(buffer + 0x3F) == 0x3AE8) /* linux 0.01 */
   3.171 +					goto linux001;
   3.172 +#endif
   3.173 +				setup = 5 << 9;
   3.174 +			}
   3.175 +#ifdef LINUX001_SUPPORT
   3.176 +			n = BUFFERSZ;
   3.177 +			isoread(buffer+512, BUFFERSZ-512);
   3.178 +#endif
   3.179  #define HDRS	0x53726448
   3.180 -			if (* (unsigned long *) (buffer + HEADER) != HDRS)
   3.181 -				setup_version = 0;
   3.182 +			if (LONG(buffer + HEADER) == HDRS)
   3.183 +				setup_version = WORD(buffer + VERSION);
   3.184  #define ELKS	0x534B4C45
   3.185 -			if (* (unsigned long *) (buffer + ELKSSIG) == ELKS)
   3.186 +			if (LONG(buffer + ELKSSIG) == ELKS)
   3.187  				iselks = 1;
   3.188  			if (setup_version < 0x204)
   3.189  				syssize &= 0x000FFFFFUL;
   3.190 @@ -256,34 +283,24 @@
   3.191  				retf
   3.192  end_realmode_switch:
   3.193  #endasm
   3.194 -				* (unsigned short *) (buffer + RMSWOFS) = 
   3.195 -					far_realmode_switch;
   3.196 -				* (unsigned short *) (buffer + RMSWSEG) = 
   3.197 -					getcs();
   3.198 +				WORD(buffer + RMSWOFS) =  far_realmode_switch;
   3.199 +				WORD(buffer + RMSWSEG) =  getcs();
   3.200  #endif
   3.201 -				mem.base =
   3.202 -					* (unsigned long *) (buffer + SYSTEMCODE);
   3.203 -				* (unsigned short *) (buffer + HEAPPTR) = 
   3.204 -					0x9B00;
   3.205 +				mem.base = LONG(buffer + SYSTEMCODE);
   3.206 +				WORD(buffer + HEAPPTR) = 0x9B00;
   3.207  				// buffer[LOADFLAGS] |= 0x80;
   3.208 -				* (unsigned short *) (buffer + LOADERTYPE) |= 
   3.209 -					0x80FF;
   3.210 +				WORD(buffer + LOADERTYPE) |= 0x80FF;
   3.211  			}
   3.212 +#ifdef LINUX001_SUPPORT
   3.213 +	linux001:
   3.214 +#endif
   3.215  			if (!setup_version || !(buffer[LOADFLAGS] & 1)) {
   3.216 -#ifdef ZIMAGE_SUPPORT
   3.217  				zimage = getss() + 0x1000;
   3.218  				mem.base = zimage * 16L; 
   3.219  				if (mem.base + syssize > setupseg*16L - 32) {
   3.220 -#ifdef FULL_ZIMAGE
   3.221 -					zimage = 0x11;
   3.222 +					zimage = 0x9311;
   3.223  					mem.base = 0x110000L;	// 1M + 64K HMA 
   3.224 -#else
   3.225 -					die("Out of memory");
   3.226 -#endif
   3.227  				}
   3.228 -#else
   3.229 -				die("Not a bzImage format");
   3.230 -#endif
   3.231  			}
   3.232  		}
   3.233  		movesetup();
   3.234 @@ -296,25 +313,24 @@
   3.235  		mov	si, #0x200
   3.236  		cmp	si, _setup_version
   3.237  		jae	noversion
   3.238 -		push	ds
   3.239 -		mov	ds, _setupseg		// setup > 2.00 => 386+
   3.240 -		xor	eax, eax
   3.241 -		cdq				// clear edx
   3.242 +		mov	es, _setupseg
   3.243 +		seg	es
   3.244  		add	si, [si+14]
   3.245 -		mov	cx, #3
   3.246 +		mov	bx, #2
   3.247 +		mov	cl, #4
   3.248 +nextnumber:
   3.249 +		xor	ax, ax
   3.250  nextdigit:
   3.251 -		shl	al, #4
   3.252 -		shl	ax, #4
   3.253 -next:
   3.254 +		shl	al, cl
   3.255 +		shl	ax, cl
   3.256 +		seg	es
   3.257  		lodsb
   3.258  		sub	al, #0x30
   3.259  		cmp	al, #9
   3.260  		jbe	nextdigit
   3.261 -		shl	eax, #16
   3.262 -		shld	edx, eax, #8
   3.263 -		loop	next
   3.264 -		pop	ds
   3.265 -		mov	_kernel_version, edx
   3.266 +		mov	[bx+_kernel_version], ah
   3.267 +		dec	bx
   3.268 +		jns	nextnumber
   3.269  noversion:
   3.270  		pop	si
   3.271  #endasm
   3.272 @@ -332,52 +348,48 @@
   3.273  {
   3.274  	dosshutdown();
   3.275  #asm
   3.276 +	cld
   3.277  	mov	es, _setupseg
   3.278 -#endasm
   3.279 -	if (cmdline) {
   3.280 -		if (setup_version <= 0x201) {
   3.281 -#asm
   3.282 +	mov	ax, _setup_version
   3.283 +	cmp	ax, #0x200
   3.284 +	jb	noinitrd
   3.285 +		mov	di, #0x218
   3.286 +		mov	si, #_initrd_addr
   3.287 +		movsw
   3.288 +		movsw
   3.289 +		mov	si, #_initrd_size
   3.290 +		movsw
   3.291 +		movsw
   3.292 +noinitrd:
   3.293 +	pop	si	// return address
   3.294 +	pop	si	// .bootlinux.cmdline[bp]
   3.295 +	or	si, si
   3.296 +	jz	nocmdline
   3.297 +		cmp	ax, #0x201
   3.298  		mov	di, #0x0020
   3.299  		mov	ax, #0xA33F
   3.300 +		mov	bx, #CMDLINE_OFFSET
   3.301 +		push	bx
   3.302 +		jbe	oldcmdline
   3.303 +		mov	di, #0x0228
   3.304 +		mov	ax, es
   3.305 +		mov	cl, #12
   3.306 +		shr	ax, cl
   3.307 +		xchg	ax, bx
   3.308 +oldcmdline:
   3.309  		stosw
   3.310 -		mov	ax, #CMDLINE_OFFSET
   3.311 +		xchg	ax, bx
   3.312  		stosw
   3.313 -#endasm
   3.314 -		}
   3.315 -		else {
   3.316 -#asm
   3.317 -		mov	di, #0x0228
   3.318 -		mov	eax, #SETUP_SEGMENT*16+CMDLINE_OFFSET
   3.319 -		stosd
   3.320 -#endasm
   3.321 -		}
   3.322 -#asm
   3.323 -		xchg	ax, di
   3.324 -		mov	si, .bootlinux.cmdline[bp]
   3.325 +		pop	di
   3.326  copy:
   3.327  		lodsb
   3.328  		stosb
   3.329  		or	al,al
   3.330  		jne	copy
   3.331 -#endasm
   3.332 -	}
   3.333 -	if (setup_version >= 0x200) {
   3.334 -#asm
   3.335 -		mov	eax, _initrd_addr
   3.336 -		mov	di, #0x218
   3.337 -		stosd
   3.338 -		mov	eax, _initrd_size
   3.339 -		stosd
   3.340 -#endasm
   3.341 -	}
   3.342 -#asm
   3.343 +nocmdline:
   3.344  	push	es
   3.345  	pop	ss
   3.346  	mov	sp, #CMDLINE_OFFSET
   3.347 -#endasm
   3.348 -#ifdef ZIMAGE_SUPPORT
   3.349 -#asm
   3.350 -	cld
   3.351  	mov	ax, _mem
   3.352  	mov	dx, _mem+2
   3.353  	mov	bx, _zimage
   3.354 @@ -395,7 +407,6 @@
   3.355  		  movsb
   3.356  		retf
   3.357  sysmove:
   3.358 -#ifdef FULL_ZIMAGE
   3.359  		cmp	dx, #0x0010
   3.360  		jb	lowsys
   3.361  // bx first 64k page, dx:ax last byte+1
   3.362 @@ -413,7 +424,7 @@
   3.363  		mov	[si+0x10], cx	// limit = -1
   3.364  		mov	[si+0x18], cx	// limit = -1
   3.365  		mov	cx, #0x9300+SYSTEM_SEGMENT/0x1000
   3.366 -		mov	bh, #0x93
   3.367 +		//mov	bh, #0x93
   3.368  mvdown:
   3.369  		mov	[si+0x12+2], bx	// srce
   3.370  		mov	[si+0x1A+2], cx	// dest
   3.371 @@ -427,14 +438,12 @@
   3.372  		cmp	dl, bl
   3.373  		ja	mvdown
   3.374  		jmp	notzimage
   3.375 -#endif
   3.376  lowsys:
   3.377  // bx first segment, dx:ax last byte+1 (paragraph aligned)
   3.378 -		mov	cl, #4
   3.379 +		mov	cl, #4		// elks may run on a 8086
   3.380  		shr	ax, cl
   3.381 -		mov	cl, #12
   3.382  		shl	dx, cl
   3.383 -		or	ax, dx		// last segment+1
   3.384 +		or	ah, dl		// last segment+1
   3.385  		mov	dx, #SYSTEM_SEGMENT
   3.386  		sub	ax, bx		// ax = paragraph count
   3.387  		sub	bx, dx
   3.388 @@ -443,44 +452,45 @@
   3.389  		dec	dx
   3.390  sysmovelp:		// move ax paragraphs from bx+dx:0 to dx:0
   3.391  		mov	es, dx
   3.392 -		mov	cx, dx
   3.393 -		add	cx, bx
   3.394 -		mov	ds, cx
   3.395 -		sbb	cx, cx		// cx = 0 : -1
   3.396 +		mov	si, dx
   3.397 +		add	si, bx
   3.398 +		mov	ds, si
   3.399 +		sbb	si, si		// si = 0 : -1
   3.400  		cmc			// C  = 1 :  0
   3.401 -		adc	dx, cx
   3.402 +		adc	dx, si
   3.403 +		mov	cl, #8
   3.404  		xor	di, di
   3.405  		xor	si, si
   3.406 -		mov	cx, #8
   3.407  		rep
   3.408  		  movsw
   3.409  		dec	ax
   3.410  		jne	sysmovelp
   3.411  notzimage:
   3.412 -	or	bp, bp
   3.413 -	jz	notelks
   3.414 +	mov	ax, ss
   3.415 +	mov	ds, ax
   3.416 +	dec	bp
   3.417 +	jnz	notelks
   3.418 +	mov	ah, #0x1
   3.419 +	mov	ss, ax
   3.420 +notelks:
   3.421  	push	ss
   3.422 -	pop	ds
   3.423 -	mov	cx, #0x100
   3.424 -	mov	es, cx
   3.425 -	mov	ch, #0x78	// do not overload SYSTEM_SEGMENT
   3.426 +	pop	es
   3.427 +	xor	di, di
   3.428  	xor	si, si
   3.429 -	xor	di, di
   3.430 -	push	es
   3.431 +#ifdef LINUX001_SUPPORT
   3.432 +	mov	cx, #0x0042
   3.433 +	cmp	word ptr [si+0x3F], #0x3AE8
   3.434 +	je	islinux001
   3.435 +#endif
   3.436 +	mov	cx, #0x7800	// do not overload SYSTEM_SEGMENT
   3.437  	rep
   3.438  	  movsw
   3.439 -	pop	ss
   3.440 -notelks:
   3.441 -#endasm
   3.442 -#endif
   3.443 -#asm
   3.444 -	mov	ax, ss
   3.445 -	mov	ds, ax
   3.446 -	mov	es, ax
   3.447 -	add	ax, #0x20
   3.448 +	push	es
   3.449 +	pop	ds
   3.450 +	xor	al, #0x20
   3.451 +islinux001:
   3.452  	push	ax
   3.453 -	xor	dx, dx
   3.454 -	push	dx
   3.455 +	push	cx
   3.456  	retf
   3.457  endsysmove:
   3.458  #endasm