wok rev 20179

ipxe: update bootloader
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 27 12:56:10 2018 +0100 (2018-01-27)
parents 12473799110f
children 35a23f513b71
files ipxe/receipt ipxe/stuff/bootloader.S ipxe/stuff/lkrnprefix.S memtest/stuff/bootloader.S
line diff
     1.1 --- a/ipxe/receipt	Thu Jan 25 03:48:04 2018 +0200
     1.2 +++ b/ipxe/receipt	Sat Jan 27 12:56:10 2018 +0100
     1.3 @@ -25,13 +25,27 @@
     1.4  	sed -i -e 's|//\(#define.*IMAGE_PNG\)|\1|' \
     1.5  	    -e 's|//\(#define.*CONSOLE_CMD\)|\1|' \
     1.6  	    -e 's|//\(#define.*REBOOT_CMD\)|\1|' config/general.h
     1.7 -	cp $stuff/lkrnprefix.S arch/i386/prefix
     1.8 +	sed -i 's|//\(#define.*CPUID_SETTINGS\)|\1|' config/settings.h
     1.9  	pxelinux="$(ls $WOK/syslinux/source/*/core/pxelinux.0)"
    1.10  	make bin/undionly.kkkpxe EMBED=$stuff/ipxelinux.ipxe,$pxelinux &&
    1.11  		mv bin/undionly.kkkpxe bin/ipxelinux.0
    1.12 +	make bin-i386-efi/snponly.efi EMBED=$stuff/ipxelinux.ipxe,$pxelinux &&
    1.13 +		mv bin-i386-efi/snponly.efi bin-i386-efi/ipxelinux.efi
    1.14  	make bin/undionly.pxe bin/undionly.kpxe bin/undionly.kkpxe \
    1.15  	     bin/undionly.kkkpxe bin/ipxe.pxe bin/ipxe.kpxe bin/ipxe.kkpxe \
    1.16 -	     bin/ipxe.kkkpxe bin/ipxe.nbi bin/ipxe.lkrn EMBED=$stuff/ipxe.cmd
    1.17 +	     bin/ipxe.kkkpxe bin/ipxe.nbi bin/ipxe.lkrn bin-i386-efi/ipxe.efi \
    1.18 +	     bin-i386-efi/snponly.efi EMBED=$stuff/ipxe.cmd
    1.19 +	cp $stuff/bootloader.S .
    1.20 +	cc -o bootloader.o -Wa,-a=bootloader.lst -c bootloader.S
    1.21 +	objcopy -O binary bootloader.o bootloader.bin
    1.22 +	size=$(stat -c %s bin/ipxe.lkrn)
    1.23 +	while read ofs val ; do
    1.24 +		printf '\\\\x%02X\\\\x%02X' $(($val & 255)) $(($val / 256)) | \
    1.25 +		xargs echo -en|dd bs=1 conv=notrunc of=bootloader.bin seek=$ofs
    1.26 +	done 2> /dev/null <<EOT
    1.27 +4	$((($size+511)/512))
    1.28 +14	$((($size+15)/16))
    1.29 +EOT
    1.30  }
    1.31  
    1.32  # Rules to gen a SliTaz package suitable for Tazpkg.
    1.33 @@ -40,9 +54,5 @@
    1.34  	mkdir -p $fs/boot $install/usr/share
    1.35  	cp -a $src/src/doc $install/usr/share
    1.36  	cp -a $src/src/bin/ipxe.lkrn $fs/boot/ipxe
    1.37 -	OFS=$((0x156))
    1.38 -	unix2dos <<EOT | dd bs=1 of=$fs/boot/ipxe conv=notrunc \
    1.39 -		seek=$OFS count=$((0x1F0-$OFS))
    1.40 -$SHORT_DESC
    1.41 -EOT
    1.42 +	dd if=$src/src/bootloader.bin of=$fs/boot/ipxe conv=notrunc
    1.43  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/ipxe/stuff/bootloader.S	Sat Jan 27 12:56:10 2018 +0100
     2.3 @@ -0,0 +1,554 @@
     2.4 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2.
     2.5 +
     2.6 +SYSSEG		= 0x1000
     2.7 +INITSEG		= 0x9000
     2.8 +SETUPSEG	= 0x9020
     2.9 +setup_sects	= 497
    2.10 +syssize		= 500
    2.11 +cmd_line_ptr	= 0x228
    2.12 +
    2.13 +	.text
    2.14 +	.code16
    2.15 +	.org	0
    2.16 +	.globl	_start
    2.17 +_start:
    2.18 +
    2.19 +#define CODESZ 512		/* patched by installer */
    2.20 +
    2.21 +#define BZIMAGE 0x207		/* setup version ; for bzImage < 512 Kb only */
    2.22 +
    2.23 +/* some extra features */
    2.24 +#define EXE_SUPPORT		real mode dos .exe file support
    2.25 +#define CMDLINE			kernel cmdline support	
    2.26 +#define VCPI			VCPI 4.0 support
    2.27 +#define SHUTDOWNDOS		shutdown DOS services
    2.28 +
    2.29 +/* some contraints to reduce the code size */
    2.30 +//#define FLOPPY_1440K_ONLY	1.44M floppies support only	-33
    2.31 +//#define FLOPPY_HAS_2_SIDES	hardcoded heads count to 2	-13
    2.32 +//#define NO_CMDLINE_SHRINK	remove heading spaces ?		-6-20
    2.33 +//#define NO_CMDLINE_FILE	remove @cmdline file support ?	-20
    2.34 +#define NO_DOTS		show progression dots ?		-8
    2.35 +#ifndef BZIMAGE
    2.36 +//#defime NO_MINSETUP		default setup (dos only) ?	-4
    2.37 +//#define NO_CURSOR_DEFINITION					-8
    2.38 +#endif
    2.39 +
    2.40 +#ifdef EXE_SUPPORT
    2.41 +#define EXEADRS(x)	(x+0xE0)
    2.42 +#define FLAT20(x)	(x+16*INITSEG)
    2.43 +
    2.44 +.macro	trace_int19
    2.45 +	pushl	$4
    2.46 +	popw	%si
    2.47 +	popw	%ds
    2.48 +	pushl	(%si)
    2.49 +	movl	$step19+(INITSEG<<16), (%si)
    2.50 +	pushfw
    2.51 +	popw	%ax
    2.52 +	incb	%ah			# set TF
    2.53 +	pushw	%ax
    2.54 +	popfw
    2.55 +	ljmp	*4*0x19-4(%si)
    2.56 +.endm
    2.57 +
    2.58 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    2.59 +	decw	%bp			// Magic number: MZ
    2.60 +	popw	%dx
    2.61 +	jmp	start			// Bytes on last page of file
    2.62 +	.word	(CODESZ+511)/512	// Pages in file			INSTALLER
    2.63 +	.word	0			// Relocations
    2.64 +	.word	(end_header-_start)/16	// Size of header in paragraphs
    2.65 +	.word	4096			// Minimum extra paragraphs needed
    2.66 +	.word	-1			// Maximum extra paragraphs needed
    2.67 +	.word	(CODESZ+15)/16		// Initial (relative) SS value		INSTALLER
    2.68 +	.word	stacktop		// Initial SP value
    2.69 +	.word	0			// Checksum				INSTALLER?
    2.70 +	.word	EXEADRS(comstart)	// Initial IP value
    2.71 +	.word	0xFFF0			// Initial (relative) CS value
    2.72 +//	.word	0x001C			// File address of relocation table
    2.73 +//	.word	0,0,0			// Overlay number
    2.74 +#endif
    2.75 +start:
    2.76 +	xorw	%ax, %ax		# %ax = 0
    2.77 +#ifdef BZIMAGE
    2.78 +zeroed		= 14			# zeroed registers
    2.79 +#else
    2.80 +zeroed		= 12			# zeroed registers
    2.81 +#endif
    2.82 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
    2.83 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000 (+zeroed+12)
    2.84 +	pushw	$INITSEG
    2.85 +end_header:
    2.86 +	cld				# assume nothing
    2.87 +#if defined(BZIMAGE) && BZIMAGE >= 0x202
    2.88 +	popw	%es			# %es contain INITSEG
    2.89 +	movw	%es, %di
    2.90 +#else
    2.91 +					# cmdline offset at 0x22
    2.92 +	movw	$stacktop, %di		# stacktop is an arbitrary value >=
    2.93 +					# length of bootsect + length of
    2.94 +					# setup + room for stack;
    2.95 +					# 12 is disk parm size.
    2.96 +	popw	%es			# %es contain INITSEG
    2.97 +#endif
    2.98 +	pushw	%es
    2.99 +	popw	%ss			# %es = %ss = INITSEG
   2.100 +	movw	%di, %sp		# put stack at INITSEG:stacktop-...
   2.101 +#ifdef EXE_SUPPORT
   2.102 +	cwd				# force %dx = 0 (floppy only)
   2.103 +#endif
   2.104 +
   2.105 +# Many BIOS's default disk parameter tables will not recognize
   2.106 +# multi-sector reads beyond the maximum sector number specified
   2.107 +# in the default diskette parameter tables - this may mean 7
   2.108 +# sectors in some cases.
   2.109 +#
   2.110 +# Since single sector reads are slow and out of the question,
   2.111 +# we must take care of this by creating new parameter tables
   2.112 +# (for the first disk) in RAM.  We can set the maximum sector
   2.113 +# count to 36 - the most we will encounter on an ED 2.88.  
   2.114 +#
   2.115 +# High doesn't hurt.  Low does.  Let's use the max: 63
   2.116 +
   2.117 +	rep				# don't worry about cld
   2.118 +	stosw				# already done above
   2.119 +	popw	%bx			# offset = 0
   2.120 +	popw	%ds			# %ds = 0
   2.121 +	popw	%fs			# %fs = 0
   2.122 +
   2.123 +	movb	setup_sects+0x7C00, %al	# read bootsector + setup (%ds = 0)
   2.124 +	incw	%ax
   2.125 +
   2.126 +	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   2.127 +	pushw	%es
   2.128 +	pushw	%di
   2.129 +	movb	$6, %cl			# copy 12 bytes
   2.130 +	rep				# don't worry about cld
   2.131 +	movsw				# already done above
   2.132 +	pushw	%ss
   2.133 +	popw	%ds			# now %ds = %es = %ss = INITSEG
   2.134 +	popl	%fs:0x78(%bx)		# update parameter table address
   2.135 +	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   2.136 +	cli
   2.137 +
   2.138 +	xchg	%ax, %di		# sector count
   2.139 +	popw	%ax			# limits = 0
   2.140 +	incw	%cx			# cylinder 0, sector 1, clear Z
   2.141 +	call	read_first_sectors	# read setup
   2.142 +
   2.143 +# This routine loads the system at address LOADSEG, making sure
   2.144 +# no 64kB boundaries are crossed. We try to load it as fast as
   2.145 +# possible, loading whole tracks whenever we can.
   2.146 +
   2.147 +#ifndef NO_DOTS
   2.148 +	popw	%bx			# clear %bx
   2.149 +#endif
   2.150 +	movw	syssize, %di
   2.151 +	decw	%di
   2.152 +	shrw	$9-4, %di
   2.153 +	incw	%di
   2.154 +	movw	$SYSSEG, %cx
   2.155 +#ifdef BZIMAGE
   2.156 +	push	%cx
   2.157 +#endif
   2.158 +	call	read_sectorsCX
   2.159 +
   2.160 +# This procedure turns off the floppy drive motor, so
   2.161 +# that we enter the kernel in a known state, and
   2.162 +# don't have to worry about it later.
   2.163 +
   2.164 +kill_motor:
   2.165 +	xchgw	%ax, %di		# reset FDC (%di < 128)
   2.166 +	int	$0x13
   2.167 +
   2.168 +# After that (everything loaded), we jump to the setup-routine
   2.169 +# loaded directly after the bootblock:
   2.170 +# Segments are as follows: %ds = %ss = INITSEG
   2.171 +
   2.172 +#ifdef BZIMAGE
   2.173 +	popw	%bx
   2.174 +	popw	%si			// SYSSEG:0
   2.175 +movesys:				// %bx = DS, %si
   2.176 +	movw	$16, %ax
   2.177 +	mulw	%bx
   2.178 +	addw	%si, %ax
   2.179 +	adcw	$0x9300, %dx		// %dx:%ax src flat address
   2.180 +	movw	$9, %cx
   2.181 +zero1:
   2.182 +	pushw	$0			// 2E..1E
   2.183 +	loop	zero1
   2.184 +	//pushl	$0x93100000		// 1A: dest
   2.185 +	pushw	$0x9310
   2.186 +	pushw	%cx
   2.187 +	pushw	$-1			// 18
   2.188 +	pushw	%cx			// 16
   2.189 +	pushw	%dx			// src
   2.190 +	pushw	%ax
   2.191 +	pushw	$-1			// 10
   2.192 +	movb	$8, %cl
   2.193 +	movw	%cx, %bx		// will move 8*64 = 512Kb
   2.194 +zero2:
   2.195 +	pushw	$0			// 0E..00
   2.196 +	loop	zero2
   2.197 +	movw	%sp, %si
   2.198 +	pushw	%ss
   2.199 +	popw	%es
   2.200 +	pushw	%es
   2.201 +	popw	%ds
   2.202 +syslp:
   2.203 +	movb	$0x80, %ch	
   2.204 +	movb	$0x87, %ah
   2.205 +	int	$0x15
   2.206 +	incb	0x14(%si)
   2.207 +	incb	0x1C(%si)
   2.208 +	decw	%bx
   2.209 +	jne	syslp
   2.210 +#endif
   2.211 +jmp_setup:
   2.212 +	ljmp	$SETUPSEG, $0
   2.213 +
   2.214 +#ifdef EXE_SUPPORT
   2.215 +#ifdef SHUTDOWNDOS
   2.216 +doiret:
   2.217 +	iret
   2.218 +step19:
   2.219 +	pushw	%si
   2.220 +	pushw	%ds
   2.221 +	movw	%sp, %si
   2.222 +	ldsw	%ss:4(%si), %si
   2.223 +	cmpw	$0x19CD, (%si)
   2.224 +	popw    %ds
   2.225 +	popw    %si
   2.226 +	jne	doiret
   2.227 +	xorw	%si, %si
   2.228 +	movw	%si, %ds
   2.229 +	pushw	%cs
   2.230 +	popw	%ss
   2.231 +	movw	$stacktop-4-16, %sp
   2.232 +	popl	4(%si)
   2.233 +	popaw
   2.234 +#ifdef BZIMAGE
   2.235 +	jmp	movesys
   2.236 +#endif
   2.237 +#endif
   2.238 +#ifndef BZIMAGE
   2.239 +movesys:				// %ax = SYSSEG, %bx = DS, %si
   2.240 +	shrw	$4, %si
   2.241 +	addw	%si, %bx
   2.242 +	subw	%ax, %bx
   2.243 +	jnc	forward
   2.244 +	movb	$0x90, %ah
   2.245 +	;decw	%ax
   2.246 +forward:
   2.247 +	movw	%ax, %es
   2.248 +	movw	%ax, %di
   2.249 +	addw	%bx, %di
   2.250 +	movw	%di, %ds
   2.251 +	sbbw	%di, %di		// %di = 0 : -1
   2.252 +	cmc				//  C  = 1 :  0
   2.253 +	adcw	%di, %ax
   2.254 +	xorw	%si, %si
   2.255 +	xorw	%di, %di
   2.256 +	movb	$0x10, %cl
   2.257 +	cmpb	%cl, %ah		// move 512k
   2.258 +	rep
   2.259 +	  movsb
   2.260 +	jns	forward
   2.261 +#ifndef NO_CURSOR_DEFINITION
   2.262 +	movb	$1, %ah
   2.263 +	movb	$0, %bh
   2.264 +	movb	$0x20, %ch	// 0x2000
   2.265 +	int	$0x10
   2.266 +#endif
   2.267 +	pushw	%ss
   2.268 +	popw	%ds
   2.269 +	jmp	jmp_setup
   2.270 +#endif
   2.271 +comstart:
   2.272 +	cld				# assume nothing
   2.273 +	pushw	$INITSEG
   2.274 +	popw	%es
   2.275 +#ifdef CMDLINE
   2.276 +	movw	%sp, %di
   2.277 +	movw	$0x80, %si
   2.278 +	lodsb
   2.279 +	cbw
   2.280 +	xchgw	%ax, %cx
   2.281 +	jcxz	nocmdline
   2.282 +# if defined(BZIMAGE) && BZIMAGE >= 0x202
   2.283 +	movw	$INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1)
   2.284 +# else
   2.285 +	movw	$0xA33F, 0x7F(%si)
   2.286 +# endif
   2.287 +# ifndef NO_CMDLINE_SHRINK
   2.288 +skipspace:
   2.289 +	lodsb
   2.290 +	cmpb	$0x20, %al
   2.291 +	je	skipspace
   2.292 +#  ifndef NO_CMDLINE_FILE
   2.293 +	movw	%si,%dx
   2.294 +	decw	%si
   2.295 +	subb	$'@',%al
   2.296 +	jne	notafile
   2.297 +	movb	$0x3D,%ah
   2.298 +	int	$0x21
   2.299 +	jc	notafile
   2.300 +	xchgw	%ax,%bx
   2.301 +	//movw	%si,%dx		// ~320 bytes max
   2.302 +	movw	$EXEADRS(notafile)-130,%cx
   2.303 +	movb	$0x3F,%ah
   2.304 +	int	$0x21
   2.305 +	xchgw	%ax,%cx
   2.306 +notafile:
   2.307 +#  else
   2.308 +	decw	%si
   2.309 +#  endif
   2.310 +# endif
   2.311 +	rep
   2.312 +	  movsb
   2.313 +nocmdline:
   2.314 +	orb	EXEADRS(setup_sects), %ch
   2.315 +# ifndef NO_MINSETUP
   2.316 +#  ifndef BZIMAGE
   2.317 +	jnz	setupok
   2.318 +	mov	$4, %ch
   2.319 +setupok:
   2.320 +#  endif
   2.321 +# endif
   2.322 +#else
   2.323 +	movb	EXEADRS(setup_sects), %ch
   2.324 +#endif
   2.325 +	movb	$(512-(end_header-_start))/2, %cl
   2.326 +	movw	$0x100, %si
   2.327 +	movw	$end_header, %di
   2.328 +	rep
   2.329 +	  movsw
   2.330 +	movw	$SYSSEG, %ax
   2.331 +	movw	%ds, %bx
   2.332 +	pushw	%es
   2.333 +	popw	%ss
   2.334 +#ifndef SHUTDOWNDOS
   2.335 +	pushw	%es
   2.336 +	pushw	$movesys
   2.337 +#endif
   2.338 +#ifdef VCPI
   2.339 +	pushaw
   2.340 +	smsww	%ax
   2.341 +	andb	$1, %al
   2.342 +	je	isrm
   2.343 +	movw	$EXEADRS(gdt_vcpi),%si
   2.344 +	movw	$pagebuf-0x90000,%di	// %es = 0x9000
   2.345 +	movl	$pagebuf+3,%es:0x1000(%di)
   2.346 +call_vcpi:
   2.347 +	movb	$0xDE,%ah	// DE01, EBX = getiface(DS:SI, ES:DI)
   2.348 +	int	$0x67
   2.349 +	movl	$FLAT20(sw2pm_params),%esi
   2.350 +	movb	$0x0C,%al	// DE0C switchpm(ESI)
   2.351 +	cli
   2.352 +	jmp	call_vcpi
   2.353 +pm_code:
   2.354 +	movl	%cr0,%eax
   2.355 +	andl	$0x7FFFFFFE,%eax
   2.356 +	movl	%eax,%cr0
   2.357 +	movl	%eax,%cr3
   2.358 +isrm:
   2.359 +# ifdef SHUTDOWNDOS
   2.360 +	trace_int19
   2.361 +# else
   2.362 +	lssw	%cs:EXEADRS(saved_ss_sp),%sp	
   2.363 +	popaw
   2.364 +	retf
   2.365 +# endif
   2.366 +#else
   2.367 +# ifdef SHUTDOWNDOS
   2.368 +	pushaw
   2.369 +	trace_int19
   2.370 +# endif
   2.371 +	retf
   2.372 +#endif
   2.373 +#endif
   2.374 +
   2.375 +# read_sectors reads %di sectors into %es:0 buffer.
   2.376 +# %es:0 is updated to the next memory location.
   2.377 +# First, sectors are read sector by sector until
   2.378 +# sector per track count is known. Then they are
   2.379 +# read track by track.
   2.380 +# Assume no error on first track.
   2.381 +
   2.382 +#ifdef FLOPPY_1440K_ONLY
   2.383 +#define FLOPPY_HAS_2_SIDES	hardcore heads count to 2
   2.384 +#define FLOPPY_SECTORS		18	/* 18 sectors */
   2.385 +#else
   2.386 +#define FLOPPY_HEADS		2	/* 2 heads minimum */
   2.387 +#endif
   2.388 +
   2.389 +return:
   2.390 +#ifndef NO_DOTS
   2.391 +	movw	$0xE2E,%ax
   2.392 +	movb	$7,%bl
   2.393 +	int	$0x10
   2.394 +#endif
   2.395 +	ret
   2.396 +
   2.397 +check_limits:
   2.398 +#ifndef FLOPPY_1440K_ONLY
   2.399 +	popw	%dx
   2.400 +        cmpb    %al, %cl		# max sector known ?
   2.401 +        ja	next_head		#   no -> store it
   2.402 +#ifndef FLOPPY_HAS_2_SIDES
   2.403 +#ifdef FLOPPY_HEADS
   2.404 +	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   2.405 +	jb	check_cylinder
   2.406 +#endif
   2.407 +        cmpb    %ah, %dh		# max head known ?
   2.408 +        ja	next_cylinder		#   no -> store it
   2.409 +check_cylinder:
   2.410 +#endif
   2.411 +#endif
   2.412 +	pushaw
   2.413 +#ifndef FLOPPY_1440K_ONLY
   2.414 +	cbw				# %ah = 0
   2.415 +#endif
   2.416 +        int     $0x13			# reset controler
   2.417 +	popaw
   2.418 +	movb	$1, %al			# sector by sector...
   2.419 +read_sectorslp:
   2.420 +	pushw	%dx			# some bios break dx...
   2.421 +#ifndef FLOPPY_1440K_ONLY
   2.422 +        pushw   %ax			# limits
   2.423 +	subb	%cl, %al		# sectors remaining in track
   2.424 +	ja	tolastsect
   2.425 +	movb	$1, %al			# 1 sector mini
   2.426 +tolastsect:
   2.427 +#else
   2.428 +	movb	$FLOPPY_SECTORS+1, %al
   2.429 +	subb	%cl, %al		# sectors remaining in track
   2.430 +#endif
   2.431 +	cbw
   2.432 +	cmpw	%di, %ax
   2.433 +	jb	more1trk
   2.434 +	movw	%di, %ax		# sectors to read
   2.435 +more1trk:
   2.436 +	pushw	%ax			# save context
   2.437 +	movb	$2, %ah			# cmd: read chs
   2.438 +        int     $0x13
   2.439 +#ifndef FLOPPY_1440K_ONLY
   2.440 +	popw	%dx			# save %ax
   2.441 +        popw    %ax			# limits
   2.442 +#else
   2.443 +	popw	%ax			# restore context
   2.444 +	popw	%dx
   2.445 +#endif
   2.446 +	jc	check_limits
   2.447 +#ifndef FLOPPY_1440K_ONLY
   2.448 +	xchgw	%ax, %bp
   2.449 +	addw	%dx,%cx			# next sector
   2.450 +	movw	%cx, %gs
   2.451 +	movw	%es, %cx
   2.452 +	pushw	%dx
   2.453 +	shlw	$5, %dx
   2.454 +	addw	%dx, %cx
   2.455 +	popw	%dx
   2.456 +	subw	%dx,%di			# update sector counter
   2.457 +	popw	%dx
   2.458 +#else
   2.459 +	addw	%ax,%cx			# next sector
   2.460 +	movw	%cx, %gs
   2.461 +	movw	%es, %cx
   2.462 +	pushw	%ax
   2.463 +	shlw	$5, %ax
   2.464 +	addw	%ax, %cx
   2.465 +	popw	%ax
   2.466 +	subw	%ax,%di			# update sector counter
   2.467 +#endif
   2.468 +read_sectorsCX:
   2.469 +	movw	%cx, %es		# next location
   2.470 +	jz	return
   2.471 +read_sectors:
   2.472 +	movw	%gs, %cx
   2.473 +#ifndef FLOPPY_1440K_ONLY
   2.474 +#   al is last sector+1
   2.475 +#   ah is last cylinder+1
   2.476 +	xchgw	%ax, %bp
   2.477 +#endif
   2.478 +#ifndef FLOPPY_1440K_ONLY
   2.479 +        cmpb    %al,%cl			# reach sector limit ?
   2.480 +        jne     bdendlp
   2.481 +next_head:
   2.482 +        movb    %cl,%al
   2.483 +#else
   2.484 +        cmpb    $FLOPPY_SECTORS+1,%cl	# reach sector limit ?
   2.485 +        jne     bdendlp
   2.486 +#endif
   2.487 +        movb    $1,%cl			# first sector
   2.488 +#ifndef FLOPPY_HAS_2_SIDES
   2.489 +        incb    %dh			# next head
   2.490 +        cmpb    %ah, %dh		# reach head limit ?
   2.491 +        jne     bdendlp
   2.492 +next_cylinder:
   2.493 +        movb    %dh,%ah
   2.494 +        movb    $0,%dh			# first head
   2.495 +#else
   2.496 +        xorb    %cl,%dh			# next head
   2.497 +        jne	bdendlp			# reach head limit ?
   2.498 +#endif
   2.499 +# NOTE : support 256 cylinders max
   2.500 +        incb    %ch			# next cylinder
   2.501 +read_first_sectors:
   2.502 +bdendlp:
   2.503 +        jmp	read_sectorslp
   2.504 +
   2.505 +#ifdef VCPI
   2.506 +pagebuf		=	0x98000
   2.507 +tss		=	gdt_abs-40
   2.508 +gdt		=	gdt_abs-32
   2.509 +gdt_null	=	gdt_abs-32
   2.510 +gdt_vcpi	=	gdt_abs-24
   2.511 +gdt_vcpi2	=	gdt_abs-16
   2.512 +gdt_vcpi3	=	gdt_abs-8
   2.513 +gdt_abs:
   2.514 +	.word	0xFFFF
   2.515 +	.long	0x92000000
   2.516 +	.byte	0xCF,0
   2.517 +gdt_code:
   2.518 +	.word	0xFFFF
   2.519 +gdt_code_base:
   2.520 +	.long	0x9A000000+FLAT20(0)
   2.521 +	.byte	0x8F,0
   2.522 +gdt_tss:
   2.523 +	.word	0x00FF
   2.524 +gdt_tss_base:
   2.525 +	.long	0x89000000+FLAT20(tss)
   2.526 +	.byte	0,0
   2.527 +gdtr:
   2.528 +gdt_lim:
   2.529 +	.word	0xFFFF
   2.530 +gdt_base:
   2.531 +	.long	FLAT20(gdt)
   2.532 +sw2pm_params:
   2.533 +sw2pm_cr3:
   2.534 +	.long	pagebuf+0x1000
   2.535 +sw2pm_gdtr_ptr:
   2.536 +	.long	FLAT20(gdtr)
   2.537 +sw2pm_idtr_ptr:
   2.538 +	.long	FLAT20(idtr)
   2.539 +sw2pm_ldtr:
   2.540 +	.word	0
   2.541 +sw2pm_tr:
   2.542 +SEL_TSS		= gdt_tss-gdt_null
   2.543 +	.word	SEL_TSS
   2.544 +sw2pm_jumpaddr:
   2.545 +	.long	pm_code
   2.546 +SEL_CODE	= gdt_code-gdt_null
   2.547 +	.word	SEL_CODE
   2.548 +idtr:
   2.549 +idt_lim:
   2.550 +	.word	0x03FF
   2.551 +idt_base:
   2.552 +	.long	0
   2.553 +# ifndef SHUTDOWNDOS
   2.554 +saved_ss_sp:
   2.555 +	.word	stacktop-4-16-4,INITSEG
   2.556 +# endif
   2.557 +#endif
     3.1 --- a/ipxe/stuff/lkrnprefix.S	Thu Jan 25 03:48:04 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,639 +0,0 @@
     3.4 -/*
     3.5 -	Copyright (C) 2000, Entity Cyber, Inc.
     3.6 -
     3.7 -	Authors: Gary Byers (gb@thinguin.org)
     3.8 -		 Marty Connor (mdc@thinguin.org)
     3.9 -
    3.10 -	This software may be used and distributed according to the terms
    3.11 -	of the GNU Public License (GPL), incorporated herein by reference.
    3.12 -
    3.13 -	Description:	
    3.14 -
    3.15 -	This is just a little bit of code and data that can get prepended
    3.16 -	to a ROM image in order to allow bootloaders to load the result
    3.17 -	as if it were a Linux kernel image.
    3.18 -
    3.19 -	A real Linux kernel image consists of a one-sector boot loader
    3.20 -	(to load the image from a floppy disk), followed a few sectors
    3.21 -	of setup code, followed by the kernel code itself.  There's
    3.22 -	a table in the first sector (starting at offset 497) that indicates
    3.23 -	how many sectors of setup code follow the first sector and which
    3.24 -	contains some other parameters that aren't interesting in this
    3.25 -	case.
    3.26 -
    3.27 -	We don't require much in the way of setup code.  Historically, the
    3.28 -	Linux kernel required at least 4 sectors of setup code.
    3.29 -	Therefore, at least 4 sectors must be present even though we don't
    3.30 -	use them.
    3.31 -
    3.32 -*/
    3.33 -
    3.34 -FILE_LICENCE ( GPL_ANY )
    3.35 -
    3.36 -#define	SETUPSECS 4		/* Minimal nr of setup-sectors */
    3.37 -#define PREFIXSIZE ((SETUPSECS+1)*512)
    3.38 -#define PREFIXPGH (PREFIXSIZE / 16 )
    3.39 -#define	BOOTSEG  0x07C0		/* original address of boot-sector */
    3.40 -#define	INITSEG  0x9000		/* we move boot here - out of the way */
    3.41 -#define	SETUPSEG 0x9020		/* setup starts here */
    3.42 -#define SYSSEG   0x1000		/* system loaded at 0x10000 (65536). */
    3.43 -
    3.44 -	.text
    3.45 -	.code16
    3.46 -	.arch i386
    3.47 -	.org	0
    3.48 -	.section ".prefix", "ax", @progbits
    3.49 -	.globl	_lkrn_start
    3.50 -_lkrn_start:
    3.51 -
    3.52 -bootsector: 
    3.53 -_start:
    3.54 -
    3.55 -/* some extra features */
    3.56 -#define EXE_SUPPORT		real mode dos .exe file support
    3.57 -
    3.58 -#define EXEADRS(x)	(x+0xE0)
    3.59 -
    3.60 -/* some contraints to reduce the size */
    3.61 -//#define FLOPPY_1440K_ONLY	1.44M floppies support only
    3.62 -
    3.63 -#ifdef EXE_SUPPORT
    3.64 -/* Initial temporary stack size */
    3.65 -#define EXE_STACK_SIZE 0x400
    3.66 -
    3.67 -/* Temporary decompression area (avoid DOS high memory area) */
    3.68 -#define EXE_DECOMPRESS_ADDRESS 0x110000
    3.69 -
    3.70 -/* Fields within the Program Segment Prefix */
    3.71 -#define PSP_CMDLINE_LEN 0x80
    3.72 -#define PSP_CMDLINE_START 0x81
    3.73 -
    3.74 -#define HEADER_SIZE	0x20
    3.75 -
    3.76 -signature:
    3.77 -	decw	%bp			// Magic number: MZ
    3.78 -	popw	%dx
    3.79 -	jmp	start			// Bytes on last page of file
    3.80 -blocks:
    3.81 -	.word	0			// Pages in file
    3.82 -	.section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
    3.83 -	.ascii	"ADDW"
    3.84 -	.long	blocks
    3.85 -	.long	512
    3.86 -	.long	0
    3.87 -	.previous
    3.88 -	.word	0			// Relocations
    3.89 -	.word	( HEADER_SIZE / 16 )	// Size of header in paragraphs
    3.90 -	.word	( EXE_STACK_SIZE / 16 )	// Minimum extra paragraphs needed
    3.91 -	.word	( EXE_STACK_SIZE / 16 )	// Maximum extra paragraphs needed
    3.92 -init_ss:
    3.93 -	.word	-( ( _exe_start - signature ) / 16 )	// Initial (relative) SS value
    3.94 -	.section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
    3.95 -	.ascii	"ADDW"
    3.96 -	.long	init_ss
    3.97 -	.long	16
    3.98 -	.long	0
    3.99 -	.previous
   3.100 -	.word	EXE_STACK_SIZE		// Initial SP value
   3.101 -	.word	0			// Checksum
   3.102 -	.word	_exe_start		// Initial IP value
   3.103 -	/* Initial code segment (relative to start of executable) */
   3.104 -	.word	-( HEADER_SIZE / 16 )	// Initial (relative) CS value
   3.105 -//	.word	0x001C			// File address of relocation table
   3.106 -//	.word	0,0,0			// Overlay number
   3.107 -	.ascii	"(SliTaz)"
   3.108 -
   3.109 -start:
   3.110 -	pushw	%dx
   3.111 -#endif
   3.112 -	cld				# assume nothing
   3.113 -stacktop	= 0x9E00		# in 0x8000 .. 0xA000
   3.114 -zeroed		= 12			# zeroed registers
   3.115 -	movw	$stacktop-12-zeroed, %di	# stacktop is an arbitrary value >=
   3.116 -					# length of bootsect + length of
   3.117 -					# setup + room for stack;
   3.118 -					# 12 is disk parm size.
   3.119 -	pushw	$INITSEG
   3.120 -	popw	%ss			# %ss contain INITSEG
   3.121 -	movw	%di, %sp		# put stack at INITSEG:stacktop-...
   3.122 -
   3.123 -# Many BIOS's default disk parameter tables will not recognize
   3.124 -# multi-sector reads beyond the maximum sector number specified
   3.125 -# in the default diskette parameter tables - this may mean 7
   3.126 -# sectors in some cases.
   3.127 -#
   3.128 -# Since single sector reads are slow and out of the question,
   3.129 -# we must take care of this by creating new parameter tables
   3.130 -# (for the first disk) in RAM.  We can set the maximum sector
   3.131 -# count to 36 - the most we will encounter on an ED 2.88.  
   3.132 -#
   3.133 -# High doesn't hurt.  Low does.  Let's use the max: 63
   3.134 -
   3.135 -	pushw	%ss
   3.136 -	popw	%es			# %es = %ss = INITSEG
   3.137 -	xorw	%ax, %ax		# %ax = 0
   3.138 -#ifdef EXE_SUPPORT
   3.139 -	cwd				# %dx = 0
   3.140 -#endif
   3.141 -	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
   3.142 -	rep				# don't worry about cld
   3.143 -	stosw				# already done above
   3.144 -	popw	%bx			# offset = 0
   3.145 -	popw	%ds			# %ds = 0
   3.146 -	popw	%fs			# %fs = 0
   3.147 -
   3.148 -	movb	setup_sects+0x7C00, %al	# read bootsector + setup (%ds = 0)
   3.149 -	incw	%ax
   3.150 -
   3.151 -	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   3.152 -	pushw	%es
   3.153 -	pushw	%di
   3.154 -	movb	$6, %cl			# copy 12 bytes
   3.155 -	rep				# don't worry about cld
   3.156 -	movsw				# already done above
   3.157 -	pushw	%ss
   3.158 -	popw	%ds			# now %ds = %es = %ss = INITSEG
   3.159 -	popl	%fs:0x78(%bx)		# update parameter table address
   3.160 -	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   3.161 -	cli
   3.162 -
   3.163 -	xchg	%ax, %di		# sector count
   3.164 -	popw	%ax			# limits = 0
   3.165 -	incw	%cx			# cylinder 0, sector 1, clear Z
   3.166 -	call	read_first_sectors	# read setup
   3.167 -
   3.168 -# This routine loads the system at address LOADSEG, making sure
   3.169 -# no 64kB boundaries are crossed. We try to load it as fast as
   3.170 -# possible, loading whole tracks whenever we can.
   3.171 -
   3.172 -	popw	%bx			# clear %bx
   3.173 -	movw	syssize, %di
   3.174 -	addw	$(512/16)-1, %di
   3.175 -	shrw	$9-4, %di
   3.176 -	movw	$SYSSEG, %cx
   3.177 -	call	read_sectorsCX
   3.178 -
   3.179 -# This procedure turns off the floppy drive motor, so
   3.180 -# that we enter the kernel in a known state, and
   3.181 -# don't have to worry about it later.
   3.182 -
   3.183 -kill_motor:
   3.184 -	xchgw	%ax, %di		# reset FDC (%di < 128)
   3.185 -	int	$0x13
   3.186 -
   3.187 -# After that (everything loaded), we jump to the setup-routine
   3.188 -# loaded directly after the bootblock:
   3.189 -# Segments are as follows: %ds = %ss = INITSEG
   3.190 -
   3.191 -	ljmp	$SETUPSEG, $0
   3.192 -
   3.193 -#ifdef EXE_SUPPORT
   3.194 -dosexit:
   3.195 -	movw	$0x4c00, %ax
   3.196 -	int	$0x21
   3.197 -
   3.198 -_exe_start:
   3.199 -	pushw	$dosexit
   3.200 -	movw	$EXEADRS(need386), %si
   3.201 -	pushfw			// save flags
   3.202 -		// bits  15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
   3.203 -		// flags  0 NT  IOPL OF DF IF TF SF ZF  0 AF  0 PF  1 CF
   3.204 -	movb	$0x10, %ah	// DF = IF = TF = 0
   3.205 -	pushw	%ax
   3.206 -	popfw			// < 286 : flags[12..15] are forced 1
   3.207 -	pushfw			// = 286 : flags[12..15] are forced 0
   3.208 -	popw	%cx		// > 286 : only flags[15] is forced 0
   3.209 -	popfw			// restore flags
   3.210 -	cmpb	%ah, %ch	// test Fx and 0x cases
   3.211 -	js	puts		// S= not 386+
   3.212 -//	smsww	%ax
   3.213 -//	andb	$1, %al
   3.214 -//	jne	puts
   3.215 -
   3.216 -	/* Terminate command line with a NUL */
   3.217 -	movzbw	PSP_CMDLINE_LEN, %si
   3.218 -	movb	$0, PSP_CMDLINE_START(%si)
   3.219 -	cmpb	$'?', PSP_CMDLINE_START-1(%si)
   3.220 -	je	help
   3.221 -	pushw	%si
   3.222 -
   3.223 -	/* Install iPXE.  Use a fixed temporary decompression area to
   3.224 -	 * avoid trashing the DOS high memory area.
   3.225 -	 */
   3.226 -	call	alloc_basemem
   3.227 -	movl	$EXE_DECOMPRESS_ADDRESS, %edi
   3.228 -	stc
   3.229 -	sbbl	%ebp, %ebp		/* Allow arbitrary relocation */
   3.230 -	xorl	%esi, %esi
   3.231 -	call	install_prealloc
   3.232 -
   3.233 -	xorl	%ebp, %ebp
   3.234 -	xorl	%ecx, %ecx
   3.235 -
   3.236 -	/* Calculate command line physical address */
   3.237 -	xorl	%edx, %edx
   3.238 -	movw	%ds, %dx
   3.239 -	shll	$4, %edx
   3.240 -	popw	%si
   3.241 -	orw	%si, %si
   3.242 -	jne	gotarg
   3.243 -	movw	$EXEADRS(default_config), %bp
   3.244 -	addl	%edx, %ebp
   3.245 -	movw	$0xA00-default_config, %cx
   3.246 -gotarg:
   3.247 -	addl	$PSP_CMDLINE_START, %edx
   3.248 -	
   3.249 -	jmp	start_ipxe
   3.250 -
   3.251 -help:
   3.252 -	movw	$EXEADRS(helpmsg), %si
   3.253 -puts:
   3.254 -	lodsb
   3.255 -	orb	%al, %al
   3.256 -	je	exit
   3.257 -	call	putc
   3.258 -	jmp	puts
   3.259 -#endif
   3.260 -
   3.261 -putcdot:
   3.262 -	movb	$0x2E, %al
   3.263 -putc:
   3.264 -	movb	$0xE, %ah
   3.265 -	movw	$7, %bx
   3.266 -	int	$0x10
   3.267 -exit:
   3.268 -	ret
   3.269 -
   3.270 -
   3.271 -# read_sectors reads %di sectors into %es:0 buffer.
   3.272 -# %es:0 is updated to the next memory location.
   3.273 -# First, sectors are read sector by sector until
   3.274 -# sector per track count is known. Then they are
   3.275 -# read track by track.
   3.276 -# Assume no error on first track.
   3.277 -
   3.278 -#ifdef FLOPPY_1440K_ONLY
   3.279 -#define FLOPPY_HEADS		2	/* 2 heads */
   3.280 -#define FLOPPY_SECTORS		18	/* 18 sectors */
   3.281 -#else
   3.282 -#define FLOPPY_HEADS		2	/* 2 heads minimum */
   3.283 -#define FLOPPY_SECTORS		9	/* 9 sectors minimum */
   3.284 -#endif
   3.285 -
   3.286 -check_limits:
   3.287 -#ifndef FLOPPY_1440K_ONLY
   3.288 -	popw	%dx
   3.289 -#ifdef FLOPPY_SECTORS
   3.290 -	cmpb	$FLOPPY_SECTORS+1, %cl	# minimum sector count
   3.291 -	jb	check_head
   3.292 -#endif
   3.293 -        cmpb    %al, %cl		# max sector known ?
   3.294 -        ja	next_head		#   no -> store it
   3.295 -check_head:
   3.296 -#ifdef FLOPPY_HEADS
   3.297 -	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   3.298 -	jb	check_cylinder
   3.299 -#endif
   3.300 -        cmpb    %ah, %dh		# max head known ?
   3.301 -        ja	next_cylinder		#   no -> store it
   3.302 -check_cylinder:
   3.303 -#endif
   3.304 -	pushaw
   3.305 -#ifndef FLOPPY_1440K_ONLY
   3.306 -	cbw				# %ah = 0
   3.307 -#endif
   3.308 -        int     $0x13			# reset controler
   3.309 -	popaw
   3.310 -	movb	$1, %al			# sector by sector...
   3.311 -read_sectorslp:
   3.312 -	pushw	%dx			# some bios break dx...
   3.313 -#ifndef FLOPPY_1440K_ONLY
   3.314 -        pushw   %ax			# limits
   3.315 -	subb	%cl, %al		# sectors remaining in track
   3.316 -	ja	tolastsect
   3.317 -	movb	$1, %al			# 1 sector mini
   3.318 -tolastsect:
   3.319 -#else
   3.320 -	mov	$FLOPPY_SECTORS+1, %al
   3.321 -	subb	%cl, %al		# sectors remaining in track
   3.322 -#endif
   3.323 -	cbw
   3.324 -	cmpw	%di, %ax
   3.325 -	jb	more1trk
   3.326 -	movw	%di, %ax		# sectors to read
   3.327 -more1trk:
   3.328 -	pushw	%ax			# save context
   3.329 -	movb	$2, %ah			# cmd: read chs
   3.330 -        int     $0x13
   3.331 -#ifndef FLOPPY_1440K_ONLY
   3.332 -	popw	%dx			# save %ax
   3.333 -        popw    %ax			# limits
   3.334 -#else
   3.335 -	popw	%ax			# restore context
   3.336 -	popw	%dx
   3.337 -#endif
   3.338 -	jc	check_limits
   3.339 -#ifndef FLOPPY_1440K_ONLY
   3.340 -	xchgw	%ax, %bp
   3.341 -	addw	%dx,%cx			# next sector
   3.342 -	movw	%cx, %gs
   3.343 -	movw	%es, %cx
   3.344 -	pushw	%dx
   3.345 -	shlw	$5, %dx
   3.346 -	addw	%dx, %cx
   3.347 -	popw	%dx
   3.348 -	subw	%dx,%di			# update sector counter
   3.349 -	popw	%dx
   3.350 -read_sectorsCX:
   3.351 -	movw	%cx, %es		# next location
   3.352 -	jz	putcdot
   3.353 -#else
   3.354 -	addw	%ax,%cx			# next sector
   3.355 -	movw	%cx, %gs
   3.356 -	movw	%es, %cx
   3.357 -	pushw	%ax
   3.358 -	shlw	$5, %ax
   3.359 -	addw	%ax, %cx
   3.360 -	popw	%ax
   3.361 -	subw	%ax,%di			# update sector counter
   3.362 -read_sectorsCX:
   3.363 -	movw	%cx, %es		# next location
   3.364 -	jz	putcdot
   3.365 -#endif
   3.366 -read_sectors:
   3.367 -	movw	%gs, %cx
   3.368 -#ifndef FLOPPY_1440K_ONLY
   3.369 -#   al is last sector+1
   3.370 -#   ah is last cylinder+1
   3.371 -	xchgw	%ax, %bp
   3.372 -#endif
   3.373 -#ifndef FLOPPY_1440K_ONLY
   3.374 -        cmpb    %al,%cl			# reach sector limit ?
   3.375 -        jne     bdendlp
   3.376 -next_head:
   3.377 -        movb    %cl,%al
   3.378 -#else
   3.379 -        cmpb    $FLOPPY_SECTORS+1,%cl	# reach sector limit ?
   3.380 -        jne     bdendlp
   3.381 -#endif
   3.382 -        incb    %dh			# next head
   3.383 -        movb    $1,%cl			# first sector
   3.384 -#ifndef FLOPPY_1440K_ONLY
   3.385 -        cmpb    %ah, %dh		# reach head limit ?
   3.386 -        jne     bdendlp
   3.387 -next_cylinder:
   3.388 -        movb    %dh,%ah
   3.389 -#else
   3.390 -        cmpb    %cl,%dh			# reach head limit ?
   3.391 -        je	bdendlp
   3.392 -#endif
   3.393 -# NOTE : support 256 cylinders max
   3.394 -        incb    %ch			# next cylinder
   3.395 -        movb    $0,%dh			# first head
   3.396 -read_first_sectors:
   3.397 -bdendlp:
   3.398 -        jmp	read_sectorslp
   3.399 -
   3.400 -#ifdef EXE_SUPPORT
   3.401 -need386:
   3.402 -	.ascii	"No 386+."
   3.403 -	.byte	13,10
   3.404 -	.byte	0
   3.405 -helpmsg:
   3.406 -	.ascii	"No help available."
   3.407 -	.byte	13,10
   3.408 -	.byte	0
   3.409 -#endif
   3.410 -
   3.411 -/*
   3.412 -	The following header is documented in the Linux source code at
   3.413 -	Documentation/x86/boot.txt
   3.414 -*/
   3.415 -	.org	497
   3.416 -setup_sects: 
   3.417 -	.byte	SETUPSECS
   3.418 -root_flags: 
   3.419 -	.word	0
   3.420 -syssize: 
   3.421 -	.long	-PREFIXPGH
   3.422 -
   3.423 -	.section ".zinfo.fixup", "a", @progbits	/* Compressor fixups */
   3.424 -	.ascii	"ADDL"
   3.425 -	.long	syssize
   3.426 -	.long	16
   3.427 -	.long	0
   3.428 -	.previous
   3.429 -	
   3.430 -ram_size: 
   3.431 -	.word	0
   3.432 -vid_mode: 
   3.433 -	.word	0
   3.434 -root_dev: 
   3.435 -	.word	0
   3.436 -boot_flag: 
   3.437 -	.word	0xAA55
   3.438 -jump:
   3.439 -	/* Manually specify a two-byte jmp instruction here rather
   3.440 -	 * than leaving it up to the assembler. */
   3.441 -	.byte	0xeb
   3.442 -	.byte	setup_code - header
   3.443 -header:
   3.444 -	.byte	'H', 'd', 'r', 'S'
   3.445 -version:
   3.446 -	.word	0x0207 /* 2.07 */
   3.447 -realmode_swtch:
   3.448 -	.long	0
   3.449 -start_sys:
   3.450 -	.word	0
   3.451 -kernel_version:
   3.452 -	.word	0
   3.453 -type_of_loader:
   3.454 -	.byte	0
   3.455 -loadflags:
   3.456 -	.byte	0
   3.457 -setup_move_size:
   3.458 -	.word	0
   3.459 -code32_start:
   3.460 -	.long	SYSSEG*16
   3.461 -ramdisk_image:
   3.462 -	.long	0
   3.463 -ramdisk_size:
   3.464 -	.long	0
   3.465 -bootsect_kludge:
   3.466 -	.long	0
   3.467 -heap_end_ptr:
   3.468 -	.word	0
   3.469 -pad1:
   3.470 -	.word	0
   3.471 -cmd_line_ptr:
   3.472 -	.long	0
   3.473 -initrd_addr_max:
   3.474 -	/* We don't use an initrd but some bootloaders (e.g. SYSLINUX) have
   3.475 -	 * been known to require this field.  Set the value to 2 GB.  This
   3.476 -	 * value is also used by the Linux kernel. */
   3.477 -	.long	0x7fffffff
   3.478 -kernel_alignment:
   3.479 -	.long	0
   3.480 -relocatable_kernel:
   3.481 -	.byte	0
   3.482 -pad2:
   3.483 -	.byte	0, 0, 0
   3.484 -cmdline_size:
   3.485 -	.long	0x7ff
   3.486 -hardware_subarch:
   3.487 -	.long	0
   3.488 -hardware_subarch_data:
   3.489 -	.byte	0, 0, 0, 0, 0, 0, 0, 0
   3.490 -
   3.491 -/*
   3.492 -	We don't need to do too much setup.
   3.493 -
   3.494 -	This code gets loaded at SETUPSEG:0.  It wants to start
   3.495 -	executing the image that's loaded at SYSSEG:0 and
   3.496 -	whose entry point is SYSSEG:0.
   3.497 -*/
   3.498 -setup_code:
   3.499 -	movl	ramdisk_image, %eax
   3.500 -	orl	%eax, %eax
   3.501 -	jnz	setup_done
   3.502 -
   3.503 -	movw	$default_config, %di
   3.504 -	movw	$-1, %bx
   3.505 -
   3.506 -	movw	$9, %cx
   3.507 -1:
   3.508 -	pushw	%ax
   3.509 -	loop	1b
   3.510 -	pushw	$0x9310
   3.511 -	pushw	%ax
   3.512 -	pushw	%bx
   3.513 -	pushw	%ax
   3.514 -	pushw	$0x9300+(INITSEG>>12)
   3.515 -	pushw	%di
   3.516 -	pushw	%bx
   3.517 -	movb	$8, %cl
   3.518 -1:
   3.519 -	pushw	%ax
   3.520 -	loop	1b
   3.521 -1:
   3.522 -	incw	%bx
   3.523 -	cmpb	%al, (%bx,%di)
   3.524 -	jne	1b
   3.525 -	movw	%bx, ramdisk_size
   3.526 -	movb	$0x10, ramdisk_image+2
   3.527 -
   3.528 -	pushw	%ss
   3.529 -	popw	%es
   3.530 -	movw	%sp, %si
   3.531 -	movb	$0x87, %ah
   3.532 -	movw	$(run_ipxe-default_config)/2+1, %cx
   3.533 -	int	$0x15
   3.534 -
   3.535 -setup_done:
   3.536 -	/* We expect to be contiguous in memory once loaded.  The Linux image
   3.537 -	 * boot process requires that setup code is loaded separately from
   3.538 -	 * "non-real code".  Since we don't need any information that's left
   3.539 -	 * in the prefix, it doesn't matter: we just have to ensure that
   3.540 -	 * %cs:0000 is where the start of the image *would* be.
   3.541 -	 */
   3.542 -	ljmp	$(SYSSEG-(PREFIXSIZE/16)), $run_ipxe
   3.543 -
   3.544 -default_config:
   3.545 -
   3.546 -	.org	PREFIXSIZE
   3.547 -/*
   3.548 -	We're now at the beginning of the kernel proper.
   3.549 - */
   3.550 -run_ipxe:
   3.551 -	/* Set up stack just below 0x7c00 and clear direction flag */
   3.552 -	xorw	%ax, %ax
   3.553 -	movw	%ax, %ss
   3.554 -	movw	$0x7c00, %sp
   3.555 -	cld
   3.556 -
   3.557 -	/* Retrieve command-line pointer */
   3.558 -	movl	%ds:cmd_line_ptr, %edx
   3.559 -	testl	%edx, %edx
   3.560 -	jz	no_cmd_line
   3.561 -
   3.562 -	/* Set up %es:%di to point to command line */
   3.563 -	movl	%edx, %edi
   3.564 -	andl	$0xf, %edi
   3.565 -	rorl	$4, %edx
   3.566 -	movw	%dx, %es
   3.567 -
   3.568 -	/* Find length of command line */
   3.569 -	pushw	%di
   3.570 -	movw	$0xffff, %cx
   3.571 -	repnz scasb
   3.572 -	notw	%cx
   3.573 -	popw	%si
   3.574 -
   3.575 -	/* Make space for command line on stack */
   3.576 -	movw	%sp, %di
   3.577 -	subw	%cx, %di
   3.578 -	andw	$~0xf, %di
   3.579 -	movw	%di, %sp
   3.580 -
   3.581 -	/* Copy command line to stack */
   3.582 -	pushw	%ds
   3.583 -	pushw	%es
   3.584 -	popw	%ds
   3.585 -	pushw	%ss
   3.586 -	popw	%es
   3.587 -	rep movsb
   3.588 -	popw	%ds
   3.589 -
   3.590 -	/* Store new command-line pointer */
   3.591 -	movzwl	%sp, %edx
   3.592 -no_cmd_line:
   3.593 -
   3.594 -	/* Calculate maximum relocation address */
   3.595 -	movl	ramdisk_image, %ebp
   3.596 -	testl	%ebp, %ebp
   3.597 -	jnz	1f
   3.598 -	decl	%ebp		/* Allow arbitrary relocation if no initrd */
   3.599 -1:
   3.600 -
   3.601 -	/* Install iPXE */
   3.602 -	call	alloc_basemem
   3.603 -	xorl	%esi, %esi
   3.604 -	xorl	%edi, %edi
   3.605 -	call	install_prealloc
   3.606 -
   3.607 -	/* Retrieve initrd pointer and size */
   3.608 -	movl	ramdisk_image, %ebp
   3.609 -	movl	ramdisk_size, %ecx
   3.610 -
   3.611 -start_ipxe:
   3.612 -	/* Set up real-mode stack */
   3.613 -	movw	%bx, %ss
   3.614 -	movw	$_estack16, %sp
   3.615 -
   3.616 -	/* Jump to .text16 segment */
   3.617 -	pushw	%ax
   3.618 -	pushw	$1f
   3.619 -	lret
   3.620 -	.section ".text16", "awx", @progbits
   3.621 -1:
   3.622 -	/* Set up %ds for access to .data16 */
   3.623 -	movw	%bx, %ds
   3.624 -
   3.625 -	/* Store command-line pointer */
   3.626 -	movl	%edx, cmdline_phys
   3.627 -
   3.628 -	/* Store initrd pointer and size */
   3.629 -	movl	%ebp, initrd_phys
   3.630 -	movl	%ecx, initrd_len
   3.631 -
   3.632 -	/* Run iPXE */
   3.633 -	pushl	$main
   3.634 -	pushw	%cs
   3.635 -	call	prot_call
   3.636 -	popl	%ecx /* discard */
   3.637 -
   3.638 -	/* Uninstall iPXE */
   3.639 -	call	uninstall
   3.640 -
   3.641 -	/* Boot next device */
   3.642 -	int $0x18
     4.1 --- a/memtest/stuff/bootloader.S	Thu Jan 25 03:48:04 2018 +0200
     4.2 +++ b/memtest/stuff/bootloader.S	Sat Jan 27 12:56:10 2018 +0100
     4.3 @@ -1,10 +1,11 @@
     4.4 -// Image/zImage boot sector
     4.5 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2.
     4.6  
     4.7  SYSSEG		= 0x1000
     4.8  INITSEG		= 0x9000
     4.9  SETUPSEG	= 0x9020
    4.10  setup_sects	= 497
    4.11  syssize		= 500
    4.12 +cmd_line_ptr	= 0x228
    4.13  
    4.14  	.text
    4.15  	.code16
    4.16 @@ -14,20 +15,24 @@
    4.17  
    4.18  #define CODESZ 512		/* patched by installer */
    4.19  
    4.20 +//#define BZIMAGE 0x207		/* setup version ; for bzImage < 512 Kb only */
    4.21 +
    4.22  /* some extra features */
    4.23  #define EXE_SUPPORT		real mode dos .exe file support
    4.24 -#define CMDLINE		0x9E00
    4.25 +#define CMDLINE			kernel cmdline support	
    4.26  #define VCPI			VCPI 4.0 support
    4.27  #define SHUTDOWNDOS		shutdown DOS services
    4.28  
    4.29 -/* some contraints to reduce the size */
    4.30 +/* some contraints to reduce the code size */
    4.31  //#define FLOPPY_1440K_ONLY	1.44M floppies support only	-33
    4.32  //#define FLOPPY_HAS_2_SIDES	hardcoded heads count to 2	-13
    4.33 -//#define MOVE_MAX_SYSSIZE	always memcpy 512Kb		-2
    4.34 -//#define NO_CURSOR_DEFINITION					-8
    4.35 -//#define NO_CMDLINE_SHRINK	remove heading spaces ?		-6
    4.36 +//#define NO_CMDLINE_SHRINK	remove heading spaces ?		-6-20
    4.37  //#define NO_CMDLINE_FILE	remove @cmdline file support ?	-20
    4.38  //#define NO_DOTS		show progression dots ?		-8
    4.39 +#ifndef BZIMAGE
    4.40 +//#defime NO_MINSETUP		default setup (dos only) ?	-4
    4.41 +//#define NO_CURSOR_DEFINITION					-8
    4.42 +#endif
    4.43  
    4.44  #ifdef EXE_SUPPORT
    4.45  #define EXEADRS(x)	(x+0xE0)
    4.46 @@ -65,23 +70,33 @@
    4.47  //	.word	0,0,0			// Overlay number
    4.48  #endif
    4.49  start:
    4.50 -	cld				# assume nothing
    4.51  	xorw	%ax, %ax		# %ax = 0
    4.52 +#ifdef BZIMAGE
    4.53 +zeroed		= 14			# zeroed registers
    4.54 +#else
    4.55  zeroed		= 12			# zeroed registers
    4.56 +#endif
    4.57 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
    4.58  stacktop	= 0x9E00		# in 0x8000 .. 0xA000 (+zeroed+12)
    4.59  	pushw	$INITSEG
    4.60 -	popw	%ss			# %ss contain INITSEG
    4.61 -	pushw	%ss
    4.62  end_header:
    4.63 -	popw	%es			# %es = %ss = INITSEG
    4.64 +	cld				# assume nothing
    4.65 +#if defined(BZIMAGE) && BZIMAGE >= 0x202
    4.66 +	popw	%es			# %es contain INITSEG
    4.67 +	movw	%es, %di
    4.68 +#else
    4.69  					# cmdline offset at 0x22
    4.70  	movw	$stacktop, %di		# stacktop is an arbitrary value >=
    4.71  					# length of bootsect + length of
    4.72  					# setup + room for stack;
    4.73  					# 12 is disk parm size.
    4.74 +	popw	%es			# %es contain INITSEG
    4.75 +#endif
    4.76 +	pushw	%es
    4.77 +	popw	%ss			# %es = %ss = INITSEG
    4.78  	movw	%di, %sp		# put stack at INITSEG:stacktop-...
    4.79  #ifdef EXE_SUPPORT
    4.80 -	cwd				# %dx = 0
    4.81 +	cwd				# force %dx = 0 (floppy only)
    4.82  #endif
    4.83  
    4.84  # Many BIOS's default disk parameter tables will not recognize
    4.85 @@ -96,7 +111,6 @@
    4.86  #
    4.87  # High doesn't hurt.  Low does.  Let's use the max: 63
    4.88  
    4.89 -	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
    4.90  	rep				# don't worry about cld
    4.91  	stosw				# already done above
    4.92  	popw	%bx			# offset = 0
    4.93 @@ -135,6 +149,9 @@
    4.94  	shrw	$9-4, %di
    4.95  	incw	%di
    4.96  	movw	$SYSSEG, %cx
    4.97 +#ifdef BZIMAGE
    4.98 +	push	%cx
    4.99 +#endif
   4.100  	call	read_sectorsCX
   4.101  
   4.102  # This procedure turns off the floppy drive motor, so
   4.103 @@ -149,6 +166,45 @@
   4.104  # loaded directly after the bootblock:
   4.105  # Segments are as follows: %ds = %ss = INITSEG
   4.106  
   4.107 +#ifdef BZIMAGE
   4.108 +	popw	%bx
   4.109 +	popw	%si			// SYSSEG:0
   4.110 +movesys:				// %bx = DS, %si
   4.111 +	movw	$16, %ax
   4.112 +	mulw	%bx
   4.113 +	addw	%si, %ax
   4.114 +	adcw	$0x9300, %dx		// %dx:%ax src flat address
   4.115 +	movw	$9, %cx
   4.116 +zero1:
   4.117 +	pushw	$0			// 2E..1E
   4.118 +	loop	zero1
   4.119 +	//pushl	$0x93100000		// 1A: dest
   4.120 +	pushw	$0x9310
   4.121 +	pushw	%cx
   4.122 +	pushw	$-1			// 18
   4.123 +	pushw	%cx			// 16
   4.124 +	pushw	%dx			// src
   4.125 +	pushw	%ax
   4.126 +	pushw	$-1			// 10
   4.127 +	movb	$8, %cl
   4.128 +	movw	%cx, %bx		// will move 8*64 = 512Kb
   4.129 +zero2:
   4.130 +	pushw	$0			// 0E..00
   4.131 +	loop	zero2
   4.132 +	movw	%sp, %si
   4.133 +	pushw	%ss
   4.134 +	popw	%es
   4.135 +	pushw	%es
   4.136 +	popw	%ds
   4.137 +syslp:
   4.138 +	movb	$0x80, %ch	
   4.139 +	movb	$0x87, %ah
   4.140 +	int	$0x15
   4.141 +	incb	0x14(%si)
   4.142 +	incb	0x1C(%si)
   4.143 +	decw	%bx
   4.144 +	jne	syslp
   4.145 +#endif
   4.146  jmp_setup:
   4.147  	ljmp	$SETUPSEG, $0
   4.148  
   4.149 @@ -172,29 +228,32 @@
   4.150  	movw	$stacktop-4-16, %sp
   4.151  	popl	4(%si)
   4.152  	popaw
   4.153 +#ifdef BZIMAGE
   4.154 +	jmp	movesys
   4.155  #endif
   4.156 +#endif
   4.157 +#ifndef BZIMAGE
   4.158  movesys:				// %ax = SYSSEG, %bx = DS, %si
   4.159 -	//movw	%cs:syssize, %bp
   4.160 -	movw	$0x8000, %bp
   4.161  	shrw	$4, %si
   4.162  	addw	%si, %bx
   4.163  	subw	%ax, %bx
   4.164  	jnc	forward
   4.165 -	addw	%bp, %ax
   4.166 +	movb	$0x90, %ah
   4.167 +	;decw	%ax
   4.168  forward:
   4.169  	movw	%ax, %es
   4.170 -	movw	%ax, %dx
   4.171 -	addw	%bx, %dx
   4.172 -	movw	%dx, %ds
   4.173 -	sbbw	%dx, %dx		// %dx = 0 : -1
   4.174 +	movw	%ax, %di
   4.175 +	addw	%bx, %di
   4.176 +	movw	%di, %ds
   4.177 +	sbbw	%di, %di		// %di = 0 : -1
   4.178  	cmc				//  C  = 1 :  0
   4.179 -	adcw	%dx, %ax
   4.180 +	adcw	%di, %ax
   4.181  	xorw	%si, %si
   4.182  	xorw	%di, %di
   4.183 -	movb	$8, %cl
   4.184 +	movb	$0x10, %cl
   4.185 +	cmpb	%cl, %ah		// move 512k
   4.186  	rep
   4.187 -	  movsw
   4.188 -	decw	%bp
   4.189 +	  movsb
   4.190  	jns	forward
   4.191  #ifndef NO_CURSOR_DEFINITION
   4.192  	movb	$1, %ah
   4.193 @@ -205,6 +264,7 @@
   4.194  	pushw	%ss
   4.195  	popw	%ds
   4.196  	jmp	jmp_setup
   4.197 +#endif
   4.198  comstart:
   4.199  	cld				# assume nothing
   4.200  	pushw	$INITSEG
   4.201 @@ -216,7 +276,11 @@
   4.202  	cbw
   4.203  	xchgw	%ax, %cx
   4.204  	jcxz	nocmdline
   4.205 +# if defined(BZIMAGE) && BZIMAGE >= 0x202
   4.206 +	movw	$INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1)
   4.207 +# else
   4.208  	movw	$0xA33F, 0x7F(%si)
   4.209 +# endif
   4.210  # ifndef NO_CMDLINE_SHRINK
   4.211  skipspace:
   4.212  	lodsb
   4.213 @@ -244,9 +308,18 @@
   4.214  	rep
   4.215  	  movsb
   4.216  nocmdline:
   4.217 +	orb	EXEADRS(setup_sects), %ch
   4.218 +# ifndef NO_MINSETUP
   4.219 +#  ifndef BZIMAGE
   4.220 +	jnz	setupok
   4.221 +	mov	$4, %ch
   4.222 +setupok:
   4.223 +#  endif
   4.224 +# endif
   4.225 +#else
   4.226 +	movb	EXEADRS(setup_sects), %ch
   4.227  #endif
   4.228  	movb	$(512-(end_header-_start))/2, %cl
   4.229 -	movb	EXEADRS(setup_sects), %ch
   4.230  	movw	$0x100, %si
   4.231  	movw	$end_header, %di
   4.232  	rep
   4.233 @@ -260,19 +333,13 @@
   4.234  	pushw	$movesys
   4.235  #endif
   4.236  #ifdef VCPI
   4.237 -# ifndef SHUTDOWNDOS
   4.238 -	pushw	%es
   4.239 -	pushw	%ds
   4.240 -# endif
   4.241  	pushaw
   4.242  	smsww	%ax
   4.243  	andb	$1, %al
   4.244  	je	isrm
   4.245  	movw	$EXEADRS(gdt_vcpi),%si
   4.246 -	pushw	$pagebuf/16
   4.247 -	popw	%es
   4.248 -	movl	$pagebuf+3,%es:0x1000
   4.249 -	xorw	%di,%di
   4.250 +	movw	$pagebuf-0x90000,%di	// %es = 0x9000
   4.251 +	movl	$pagebuf+3,%es:0x1000(%di)
   4.252  call_vcpi:
   4.253  	movb	$0xDE,%ah	// DE01, EBX = getiface(DS:SI, ES:DI)
   4.254  	int	$0x67
   4.255 @@ -291,8 +358,6 @@
   4.256  # else
   4.257  	lssw	%cs:EXEADRS(saved_ss_sp),%sp	
   4.258  	popaw
   4.259 -	popw	%ds
   4.260 -	popw	%es
   4.261  	retf
   4.262  # endif
   4.263  #else
   4.264 @@ -316,7 +381,6 @@
   4.265  #define FLOPPY_SECTORS		18	/* 18 sectors */
   4.266  #else
   4.267  #define FLOPPY_HEADS		2	/* 2 heads minimum */
   4.268 -#define FLOPPY_SECTORS		9	/* 9 sectors minimum */
   4.269  #endif
   4.270  
   4.271  return:
   4.272 @@ -330,14 +394,9 @@
   4.273  check_limits:
   4.274  #ifndef FLOPPY_1440K_ONLY
   4.275  	popw	%dx
   4.276 -#ifdef FLOPPY_SECTORS
   4.277 -	cmpb	$FLOPPY_SECTORS+1, %cl	# minimum sector count
   4.278 -	jb	check_head
   4.279 -#endif
   4.280          cmpb    %al, %cl		# max sector known ?
   4.281          ja	next_head		#   no -> store it
   4.282  #ifndef FLOPPY_HAS_2_SIDES
   4.283 -check_head:
   4.284  #ifdef FLOPPY_HEADS
   4.285  	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   4.286  	jb	check_cylinder