Navigation

Project: wok

Clone project: hg clone http://hg.slitaz.org/wok

  • Download tarball:
  • bz2
  • gz

Search

wok changeset 15188:b0e9e83532e2

Add memtest-serial
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 25 18:09:21 2013 +0000 (12 months ago ago)
parents 95c2e3f416e2
children 20fd4e3d8970
files memtest-serial/receipt.serial memtest/receipt memtest/stuff/bootloader.S memtest/stuff/pack memtest/stuff/unpack.S
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memtest-serial/receipt.serial	Sun Aug 25 18:09:21 2013 +0000
     1.3 @@ -0,0 +1,25 @@
     1.4 +# SliTaz package receipt.
     1.5 +
     1.6 +PACKAGE="memtest-serial"
     1.7 +VERSION="4.20"
     1.8 +CATEGORY="base-system"
     1.9 +SHORT_DESC="Memory failures detection tool using serial port."
    1.10 +MAINTAINER="pascal.bellard@slitaz.org"
    1.11 +LICENSE="GPL"
    1.12 +WEB_SITE="http://www.memtest.org/"
    1.13 +WANTED="memtest"
    1.14 +
    1.15 +# Rules to gen a SliTaz package suitable for Tazpkg.
    1.16 +genpkg_rules()
    1.17 +{
    1.18 +	mkdir -p $fs/boot
    1.19 +	cp $src/memtest.packed-115200 $fs/boot/memtest
    1.20 +}
    1.21 +
    1.22 +# Pre and post install commands for Tazpkg.
    1.23 +post_install()
    1.24 +{
    1.25 +	cat <<EOT
    1.26 +Output to vga and serial port. Default kernel cmdline: console=ttyS0,115200e8
    1.27 +EOT
    1.28 +}
     2.1 --- a/memtest/receipt	Sat Aug 24 15:12:52 2013 +0300
     2.2 +++ b/memtest/receipt	Sun Aug 25 18:09:21 2013 +0000
     2.3 @@ -19,9 +19,11 @@
     2.4  	cd $src
     2.5  	make
     2.6  	cp $stuff/*.S $stuff/pack .
     2.7 -	cc -o unpack.o -Wa,-a=unpack.lst -c unpack.S
     2.8 -	objcopy -O binary unpack.o unpack.bin
     2.9 -	./pack --build unpack.bin
    2.10 +	for i in bootloader unpack ; do
    2.11 +		cc -o $i.o -Wa,-a=$i.lst -c $i.S
    2.12 +		objcopy -O binary $i.o $i.bin
    2.13 +	done
    2.14 +	./pack --build bootloader.bin unpack.bin
    2.15  	./pack memtest.bin memtest.packed
    2.16  	sed -i  -e 's/SERIAL_CONSOLE_DEFAULT 0/SERIAL_CONSOLE_DEFAULT 1/' \
    2.17  		-e 's/SERIAL_BAUD_RATE 9600/SERIAL_BAUD_RATE 115200/' config.h
    2.18 @@ -35,13 +37,5 @@
    2.19  genpkg_rules()
    2.20  {
    2.21  	mkdir -p $fs/boot
    2.22 -	cp $src/memtest.packed-115200 $fs/boot/memtest
    2.23 +	cp $src/memtest.packed $fs/boot/memtest
    2.24  }
    2.25 -
    2.26 -# Pre and post install commands for Tazpkg.
    2.27 -post_install()
    2.28 -{
    2.29 -	cat <<EOT
    2.30 -Output to vga and serial port. Default kernel cmdline: console=ttyS0,115200e8
    2.31 -EOT
    2.32 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/memtest/stuff/bootloader.S	Sun Aug 25 18:09:21 2013 +0000
     3.3 @@ -0,0 +1,389 @@
     3.4 +SYSSEG		= 0x1000
     3.5 +INITSEG		= 0x9000
     3.6 +SETUPSEG	= 0x9020
     3.7 +
     3.8 +setup_sects	= 497
     3.9 +syssize		= 500
    3.10 +
    3.11 +	.text
    3.12 +	.code16
    3.13 +	.org	0
    3.14 +	.globl	_start
    3.15 +_start:
    3.16 +
    3.17 +#define CODESZ 512
    3.18 +
    3.19 +/* some extra features */
    3.20 +#define EXE_SUPPORT		real mode dos .exe file support
    3.21 +#define CMDLINE	0x9E00
    3.22 +#define HELP			store help message for /? argument
    3.23 +#define CHECK_REALMODE		does not support vm86
    3.24 +
    3.25 +/* some contraints to reduce the size */
    3.26 +//#define FLOPPY_1440K_ONLY	1.44M floppies support only
    3.27 +#define NO_CURSOR_DEFINITION
    3.28 +
    3.29 +#ifdef EXE_SUPPORT
    3.30 +#define EXEADRS(x)	x+0xE0
    3.31 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    3.32 +	decw	%bp			// Magic number: MZ
    3.33 +	popw	%dx
    3.34 +	jmp	start			// Bytes on last page of file
    3.35 +	.word	(CODESZ+511)/512	// Pages in file
    3.36 +	.word	0			// Relocations
    3.37 +	.word	(end_header-_start)/16	// Size of header in paragraphs
    3.38 +	.word	4096			// Minimum extra paragraphs needed
    3.39 +	.word	-1			// Maximum extra paragraphs needed
    3.40 +	.word	(CODESZ+15)/16		// Initial (relative) SS value
    3.41 +	.word	stacktop		// Initial SP value
    3.42 +	.word	0			// Checksum
    3.43 +	.word	EXEADRS(comstart)	// Initial IP value
    3.44 +	.word	0xFFF0			// Initial (relative) CS value
    3.45 +//	.word	0x001C			// File address of relocation table
    3.46 +//	.word	0,0,0			// Overlay number
    3.47 +	.ascii  "(SliTaz)"
    3.48 +end_header:
    3.49 +comstart:
    3.50 +#ifdef CMDLINE
    3.51 +	.word	0xA33A			// CMP     AH,[BP+DI+stacktop]
    3.52 +	.word	stacktop
    3.53 +#else
    3.54 +#undef HELP
    3.55 +#endif
    3.56 +	cld				# assume nothing
    3.57 +	pushw	$INITSEG
    3.58 +	popw	%es
    3.59 +#ifdef CMDLINE
    3.60 +	movw	%sp, %di
    3.61 +	movw	$0x80, %si
    3.62 +	lodsb
    3.63 +	cbw
    3.64 +	xchgw	%ax, %cx
    3.65 +	jcxz	nocmdline
    3.66 +	movb	$0x3F, 0x7F(%si)
    3.67 +skipspace:
    3.68 +	lodsb
    3.69 +	cmpb	$0x20, %al
    3.70 +	je	skipspace
    3.71 +	decw	%si
    3.72 +	rep
    3.73 +	  movsb
    3.74 +# ifdef HELP
    3.75 +# define PUTS
    3.76 +	movw	$EXEADRS(helpmsg), %si
    3.77 +	cmpb	$'/', %al
    3.78 +	je	puts
    3.79 +# endif
    3.80 +nocmdline:
    3.81 +#endif
    3.82 +#ifdef CHECK_REALMODE
    3.83 +#define PUTS
    3.84 +	movw	$EXEADRS(realmode_expected), %si
    3.85 +	pushfw			// save flags
    3.86 +		// bits  15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
    3.87 +		// flags  0 NT  IOPL OF DF IF TF SF ZF  0 AF  0 PF  1 CF
    3.88 +	movb	$0x10, %ah	// DF = IF = TF = 0
    3.89 +	pushw	%ax
    3.90 +	popfw			// < 286 : flags[12..15] are forced 1
    3.91 +	pushfw			// = 286 : flags[12..15] are forced 0
    3.92 +	popw	%cx		// > 286 : only flags[15] is forced 0
    3.93 +	popfw			// restore flags
    3.94 +	addb	%ah, %ch	// test F0 and 00 cases
    3.95 +	cmpb	%ah, %ch
    3.96 +	jbe	puts		// C=8086/80186, Z=80286
    3.97 +	smsww	%ax
    3.98 +	andb	$1, %al
    3.99 +	jne	puts
   3.100 +#endif
   3.101 +	movw	$0x100, %si
   3.102 +	movw	$end_header, %di
   3.103 +	movb	EXEADRS(setup_sects), %ch
   3.104 +	movb	$(512-(end_header-_start))/2, %cl
   3.105 +	rep
   3.106 +	  movsw
   3.107 +	ljmp	$INITSEG, $movesys
   3.108 +start:
   3.109 +	pushw	%dx
   3.110 +	xorw	%dx, %dx
   3.111 +#else
   3.112 +#undef HELP
   3.113 +#undef CMDLINE
   3.114 +#undef CHECK_REALMODE
   3.115 +#endif
   3.116 +	cld				# assume nothing
   3.117 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
   3.118 +zeroed		= 12			# zeroed registers
   3.119 +	movw	$stacktop-12-zeroed, %di	# stacktop is an arbitrary value >=
   3.120 +					# length of bootsect + length of
   3.121 +					# setup + room for stack;
   3.122 +					# 12 is disk parm size.
   3.123 +	pushw	$INITSEG
   3.124 +	popw	%ss			# %ss contain INITSEG
   3.125 +	movw	%di, %sp		# put stack at INITSEG:stacktop-...
   3.126 +
   3.127 +# Many BIOS's default disk parameter tables will not recognize
   3.128 +# multi-sector reads beyond the maximum sector number specified
   3.129 +# in the default diskette parameter tables - this may mean 7
   3.130 +# sectors in some cases.
   3.131 +#
   3.132 +# Since single sector reads are slow and out of the question,
   3.133 +# we must take care of this by creating new parameter tables
   3.134 +# (for the first disk) in RAM.  We can set the maximum sector
   3.135 +# count to 36 - the most we will encounter on an ED 2.88.  
   3.136 +#
   3.137 +# High doesn't hurt.  Low does.  Let's use the max: 63
   3.138 +
   3.139 +	pushw	%ss
   3.140 +	popw	%es			# %es = %ss = INITSEG
   3.141 +	xorw	%ax, %ax		# %ax = 0
   3.142 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
   3.143 +	rep				# don't worry about cld
   3.144 +	stosw				# already done above
   3.145 +	popw	%bx			# offset = 0
   3.146 +	popw	%ds			# %ds = 0
   3.147 +	popw	%fs			# %fs = 0
   3.148 +
   3.149 +	movb	setup_sects+0x7C00, %al	# read bootsector + setup (%ds = 0)
   3.150 +	incw	%ax
   3.151 +
   3.152 +	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   3.153 +	pushw	%es
   3.154 +	pushw	%di
   3.155 +	movb	$6, %cl			# copy 12 bytes
   3.156 +	rep				# don't worry about cld
   3.157 +	movsw				# already done above
   3.158 +	pushw	%ss
   3.159 +	popw	%ds			# now %ds = %es = %ss = INITSEG
   3.160 +	popl	%fs:0x78(%bx)		# update parameter table address
   3.161 +	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   3.162 +	cli
   3.163 +
   3.164 +	xchg	%ax, %di		# sector count
   3.165 +	popw	%ax			# limits = 0
   3.166 +	incw	%cx			# cylinder 0, sector 1, clear Z
   3.167 +	call	read_first_sectors	# read setup
   3.168 +
   3.169 +# This routine loads the system at address LOADSEG, making sure
   3.170 +# no 64kB boundaries are crossed. We try to load it as fast as
   3.171 +# possible, loading whole tracks whenever we can.
   3.172 +
   3.173 +	popw	%bx			# clear %bx
   3.174 +	movw	syssize, %di
   3.175 +	addw	$(512/16)-1, %di
   3.176 +	shrw	$9-4, %di
   3.177 +	movw	$SYSSEG, %cx
   3.178 +	call	read_sectorsCX
   3.179 +
   3.180 +# This procedure turns off the floppy drive motor, so
   3.181 +# that we enter the kernel in a known state, and
   3.182 +# don't have to worry about it later.
   3.183 +
   3.184 +kill_motor:
   3.185 +	xchgw	%ax, %di		# reset FDC (%di < 128)
   3.186 +	int	$0x13
   3.187 +
   3.188 +# After that (everything loaded), we jump to the setup-routine
   3.189 +# loaded directly after the bootblock:
   3.190 +# Segments are as follows: %ds = %ss = INITSEG
   3.191 +
   3.192 +jmp_setup:
   3.193 +	ljmp	$SETUPSEG, $0
   3.194 +
   3.195 +#ifdef PUTS
   3.196 +#define PUTC
   3.197 +puts:
   3.198 +	lodsb
   3.199 +	orb	%al, %al
   3.200 +	je	exit
   3.201 +	call	putc
   3.202 +	jmp	puts
   3.203 +#endif
   3.204 +#ifdef EXE_SUPPORT
   3.205 +movesys:
   3.206 +	pushw	%es
   3.207 +	popw	%ss
   3.208 +	movw	EXEADRS(syssize), %bp	// %ds untouched
   3.209 +	movw	$SYSSEG, %ax
   3.210 +	movw	%ds, %bx
   3.211 +	cwd
   3.212 +	incw	%dx
   3.213 +	cmpw	%ax, %bx
   3.214 +	jnc	forward
   3.215 +	negw	%dx
   3.216 +	addw	%bp, %ax
   3.217 +	addw	%bp, %bx
   3.218 +forward:
   3.219 +	movw	%ax, %es
   3.220 +	movw	%bx, %ds
   3.221 +	xorw	%di, %di
   3.222 +	movb	$8, %cl
   3.223 +	rep
   3.224 +	  movsw
   3.225 +	subw	$16, %si
   3.226 +	addw	%dx, %ax
   3.227 +	addw	%dx, %bx
   3.228 +	decw	%bp
   3.229 +	jns	forward
   3.230 +#ifndef NO_CURSOR_DEFINITION
   3.231 +	movb	$1, %ah
   3.232 +	movb	$0, %bh
   3.233 +	movb	$0x20, %ch	// 0x2000
   3.234 +	int	$0x10
   3.235 +#endif
   3.236 +	pushw	%ss
   3.237 +	popw	%ds
   3.238 +	jmp	jmp_setup
   3.239 +#endif
   3.240 +putcdot:
   3.241 +#ifdef PUTC
   3.242 +	movb	$0x2E, %al
   3.243 +putc:
   3.244 +	movb	$0xE, %ah
   3.245 +	movw	$7, %bx
   3.246 +	int	$0x10
   3.247 +#endif
   3.248 +exit:
   3.249 +	ret
   3.250 +
   3.251 +
   3.252 +# read_sectors reads %di sectors into %es:0 buffer.
   3.253 +# %es:0 is updated to the next memory location.
   3.254 +# First, sectors are read sector by sector until
   3.255 +# sector per track count is known. Then they are
   3.256 +# read track by track.
   3.257 +# Assume no error on first track.
   3.258 +
   3.259 +#ifdef FLOPPY_1440K_ONLY
   3.260 +#define FLOPPY_HEADS		2	/* 2 heads */
   3.261 +#define FLOPPY_SECTORS		18	/* 18 sectors */
   3.262 +#else
   3.263 +#define FLOPPY_HEADS		2	/* 2 heads minimum */
   3.264 +#define FLOPPY_SECTORS		9	/* 9 sectors minimum */
   3.265 +#endif
   3.266 +
   3.267 +check_limits:
   3.268 +#ifndef FLOPPY_1440K_ONLY
   3.269 +	popw	%dx
   3.270 +#ifdef FLOPPY_SECTORS
   3.271 +	cmpb	$FLOPPY_SECTORS+1, %cl	# minimum sector count
   3.272 +	jb	check_head
   3.273 +#endif
   3.274 +        cmpb    %al, %cl		# max sector known ?
   3.275 +        ja	next_head		#   no -> store it
   3.276 +check_head:
   3.277 +#ifdef FLOPPY_HEADS
   3.278 +	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   3.279 +	jb	check_cylinder
   3.280 +#endif
   3.281 +        cmpb    %ah, %dh		# max head known ?
   3.282 +        ja	next_cylinder		#   no -> store it
   3.283 +check_cylinder:
   3.284 +#endif
   3.285 +	pushaw
   3.286 +#ifndef FLOPPY_1440K_ONLY
   3.287 +	cbw				# %ah = 0
   3.288 +#endif
   3.289 +        int     $0x13			# reset controler
   3.290 +	popaw
   3.291 +	movb	$1, %al			# sector by sector...
   3.292 +read_sectorslp:
   3.293 +	pushw	%dx			# some bios break dx...
   3.294 +#ifndef FLOPPY_1440K_ONLY
   3.295 +        pushw   %ax			# limits
   3.296 +	subb	%cl, %al		# sectors remaining in track
   3.297 +	ja	tolastsect
   3.298 +	movb	$1, %al			# 1 sector mini
   3.299 +tolastsect:
   3.300 +#else
   3.301 +	mov	$FLOPPY_SECTORS+1, %al
   3.302 +	subb	%cl, %al		# sectors remaining in track
   3.303 +#endif
   3.304 +	cbw
   3.305 +	cmpw	%di, %ax
   3.306 +	jb	more1trk
   3.307 +	movw	%di, %ax		# sectors to read
   3.308 +more1trk:
   3.309 +	pushw	%ax			# save context
   3.310 +	movb	$2, %ah			# cmd: read chs
   3.311 +        int     $0x13
   3.312 +#ifndef FLOPPY_1440K_ONLY
   3.313 +	popw	%dx			# save %ax
   3.314 +        popw    %ax			# limits
   3.315 +#else
   3.316 +	popw	%ax			# restore context
   3.317 +	popw	%dx
   3.318 +#endif
   3.319 +	jc	check_limits
   3.320 +#ifndef FLOPPY_1440K_ONLY
   3.321 +	xchgw	%ax, %bp
   3.322 +	addw	%dx,%cx			# next sector
   3.323 +	movw	%cx, %gs
   3.324 +	movw	%es, %cx
   3.325 +	pushw	%dx
   3.326 +	shlw	$5, %dx
   3.327 +	addw	%dx, %cx
   3.328 +	popw	%dx
   3.329 +	subw	%dx,%di			# update sector counter
   3.330 +	popw	%dx
   3.331 +read_sectorsCX:
   3.332 +	movw	%cx, %es		# next location
   3.333 +	jz	putcdot
   3.334 +#else
   3.335 +	addw	%ax,%cx			# next sector
   3.336 +	movw	%cx, %gs
   3.337 +	movw	%es, %cx
   3.338 +	pushw	%ax
   3.339 +	shlw	$5, %ax
   3.340 +	addw	%ax, %cx
   3.341 +	popw	%ax
   3.342 +	subw	%ax,%di			# update sector counter
   3.343 +read_sectorsCX:
   3.344 +	movw	%cx, %es		# next location
   3.345 +	jz	putcdot
   3.346 +#endif
   3.347 +read_sectors:
   3.348 +	movw	%gs, %cx
   3.349 +#ifndef FLOPPY_1440K_ONLY
   3.350 +#   al is last sector+1
   3.351 +#   ah is last cylinder+1
   3.352 +	xchgw	%ax, %bp
   3.353 +#endif
   3.354 +#ifndef FLOPPY_1440K_ONLY
   3.355 +        cmpb    %al,%cl			# reach sector limit ?
   3.356 +        jne     bdendlp
   3.357 +next_head:
   3.358 +        movb    %cl,%al
   3.359 +#else
   3.360 +        cmpb    $FLOPPY_SECTORS+1,%cl	# reach sector limit ?
   3.361 +        jne     bdendlp
   3.362 +#endif
   3.363 +        incb    %dh			# next head
   3.364 +        movb    $1,%cl			# first sector
   3.365 +#ifndef FLOPPY_1440K_ONLY
   3.366 +        cmpb    %ah, %dh		# reach head limit ?
   3.367 +        jne     bdendlp
   3.368 +next_cylinder:
   3.369 +        movb    %dh,%ah
   3.370 +#else
   3.371 +        cmpb    %cl,%dh			# reach head limit ?
   3.372 +        je	bdendlp
   3.373 +#endif
   3.374 +# NOTE : support 256 cylinders max
   3.375 +        incb    %ch			# next cylinder
   3.376 +read_first_sectors:
   3.377 +        movb    $0,%dh			# first head
   3.378 +bdendlp:
   3.379 +        jmp	read_sectorslp
   3.380 +
   3.381 +#ifdef CHECK_REALMODE
   3.382 +realmode_expected:
   3.383 +	.ascii	"386 real mode only."
   3.384 +	.byte	13,10,0
   3.385 +#endif
   3.386 +#ifdef HELP
   3.387 +helpmsg:
   3.388 +	.ascii	"No help available."
   3.389 +	.byte	13,10
   3.390 +	.byte	0
   3.391 +#endif
   3.392 +	.org	497
     4.1 --- a/memtest/stuff/pack	Sat Aug 24 15:12:52 2013 +0300
     4.2 +++ b/memtest/stuff/pack	Sun Aug 25 18:09:21 2013 +0000
     4.3 @@ -1,12 +1,15 @@
     4.4  #!/bin/sh
     4.5  if [ "$1" == "--build" ]; then
     4.6 -	bin=${2:-unpack.bin}
     4.7 +	set -- ${2:-bootloader.bin} ${3:-unpack.bin}
     4.8  	cat >> $0 <<EOM
     4.9 -$(gzip -9 < $bin | uuencode -m -)
    4.10 +$(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -)
    4.11  EOT
    4.12  EOM
    4.13 -	getip=$(grep -s getip ${bin/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    4.14 +	getip=$(grep -s getip ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    4.15  	sed -i "s/XXX/$((515+0x${getip:-5}))/" $0
    4.16 +	helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
    4.17 +	sed -i "s/YYY/$((0x$helpmsg))/" $0
    4.18 +	sed -i "s/ZZZ/$((496-0x$helpmsg))/" $0
    4.19  	sed -i '/--build/,/^fi/d' $0
    4.20  	exit
    4.21  fi
    4.22 @@ -14,7 +17,7 @@
    4.23  store()
    4.24  {
    4.25  	n=$1
    4.26 -	for i in $(seq 1 $4); do
    4.27 +	for i in $(seq 1 ${4:-2}); do
    4.28  		printf '\\\\x%02X' $(($n & 255))
    4.29  		n=$(($n >> 8))
    4.30  	done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
    4.31 @@ -27,16 +30,25 @@
    4.32  
    4.33  main()
    4.34  {
    4.35 -	dd if=$1 bs=512 count=1 >$2
    4.36 -	uudecode | gunzip >>$2
    4.37 +	uudecode | gunzip >$2
    4.38 +	dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
    4.39  	setup="$(echo $(od -j 497 -N 1 -dAn $1))"
    4.40  	syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
    4.41  	dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
    4.42  	dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
    4.43  	size=$(stat -c %s $2)
    4.44 -	store $((($size-512)/16)) $2 XXX 2
    4.45 -	store $((($size-2560)/16)) $2 500 2
    4.46 +	store $((($size-512)/16)) $2 XXX
    4.47 +	store $((($size-2560)/16)) $2 500
    4.48  	store 4 $2 497 1
    4.49 +	store $((($size+511)/512)) $2 4
    4.50 +	store $((($size+15)/16)) $2 14
    4.51 +	echo -en "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
    4.52  }
    4.53  
    4.54 -main $1 $2 2>/dev/null <<EOT
    4.55 +HELP="$(unix2dos <<EOT
    4.56 +Memtest86+ is an endless advanced memory diagnostic tool released under the
    4.57 +terms of the Gnu Public License (GPL).
    4.58 +
    4.59 +EOT
    4.60 +)"
    4.61 +main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT
     5.1 --- a/memtest/stuff/unpack.S	Sat Aug 24 15:12:52 2013 +0300
     5.2 +++ b/memtest/stuff/unpack.S	Sun Aug 25 18:09:21 2013 +0000
     5.3 @@ -1,9 +1,15 @@
     5.4 -#define TOP		0x8FD00
     5.5 +#define TOP		(0x90000+_start-end)
     5.6  #define SYSTEM		0x10000
     5.7  #define SETUP		4
     5.8 +#define SYSSIZE		0x1F4
     5.9 +#define SETUPSIZE	0x1F1
    5.10  
    5.11 -#define CHANGE_STACK	1
    5.12 -#define LINUX_HEADER	0
    5.13 +#define CHANGE_STACK		0
    5.14 +#define LINUX_HEADER		0
    5.15 +#define UPDATE_SYSSIZE		1
    5.16 +#define HARDCODED_SYSSIZE	1
    5.17 +#define HARDCODED_SETUPSIZE	1
    5.18 +#define HARDCODED_IP		1
    5.19  
    5.20  	.text
    5.21  	.code16
    5.22 @@ -29,74 +35,103 @@
    5.23  #endif
    5.24  	pushf
    5.25  	pushw	%cs
    5.26 +#if HARDCODED_IP
    5.27 +	pushw	$0
    5.28 +#else
    5.29  	call	getip
    5.30  getip:
    5.31 +#endif
    5.32  	pushal
    5.33 -	movw	$0, %bx		// packed sizes
    5.34 +#if HARDCODED_SYSSIZE
    5.35 +packed_syssize:
    5.36 +	movw	$0, %bx		// system size
    5.37 +#else
    5.38 +	movw	SYSSIZE, %bx
    5.39 +#endif
    5.40 +#if HARDCODED_SETUPSIZE == 0
    5.41 +	xorw	%dx, %dx
    5.42 +	movb	SETUPSIZE, %dh
    5.43 +#endif
    5.44 +#if HARDCODED_IP
    5.45 +	xorw	%si, %si
    5.46 +#else
    5.47  	movw	%sp, %bp
    5.48  #define START_IP	32(%bp)
    5.49 +	subw	$getip-_start, START_IP
    5.50 +	movw	START_IP, %si
    5.51 +#endif
    5.52  	pushw	%ds
    5.53  	pushw	%es
    5.54 -	subw	$getip-_start, START_IP
    5.55  
    5.56  	cld
    5.57 +#if CHANGE_STACK
    5.58 +STKSZ=0x9000-0x0990
    5.59 +	movw	$(TOP-STKSZ)/16, %ax
    5.60 +#else
    5.61 +	movw	$TOP/16, %ax
    5.62 +#endif
    5.63 +	movw	%ax, %es
    5.64 +	pushw	%es			// moved
    5.65 +	.byte	0x6A, moved-_start	//   unpack code
    5.66  	pushw	%cs
    5.67  	popw	%ds	
    5.68 -	movw	$TOP/16, %ax
    5.69 -	movw	%ax, %es
    5.70 -	subw	%bx, %ax	// moved packed data
    5.71 -	movw	START_IP, %si
    5.72 -	movw	$moved-_start, %di
    5.73 -	addw	%si, %di
    5.74 -	pushw	%ds		// save setup seg
    5.75 -	pushw	%es		// moved
    5.76 -	pushw	%di		//   unpack code
    5.77 -	movw	%si, %di
    5.78 +	xorw	%di, %di
    5.79  	movw	$end-_start, %cx
    5.80 +	pushw	%si
    5.81  	rep
    5.82  	movsb			// move upack code to $TOP
    5.83 -	pushw	%si		// data offset
    5.84 +
    5.85 +	leaw	SYSTEM/16(%bx), %bp
    5.86 +movlp:
    5.87 +	decw	%bp
    5.88 +	movw	%bp, %ds
    5.89 +	decw	%ax
    5.90  	movw	%ax, %es
    5.91 -	movw	$SETUP*512, %cx
    5.92 -	subw	$SETUP*32, %bx
    5.93  	xorw	%si, %si
    5.94  	xorw	%di, %di
    5.95 -	rep
    5.96 -	movsb			// move header part
    5.97 -	pushw	$SYSTEM/16
    5.98 -	popw	%ds
    5.99 -movlp:
   5.100 -	xorw	%si, %si
   5.101 -	movw	$8, %cx
   5.102 +	movb	$8, %cl
   5.103  	rep
   5.104  	movsw			// move system part
   5.105 -	subw	$16, %di
   5.106 -	movw	%ds, %cx
   5.107 -	incw	%cx
   5.108 -	movw	%cx, %ds
   5.109 -	movw	%es, %cx
   5.110 -	incw	%cx
   5.111 -	movw	%cx, %es
   5.112  	decw	%bx
   5.113 -	jns	movlp
   5.114 -	popw	%si		// data offset
   5.115 -	movw	%ax, %ds
   5.116 +	jnz	movlp
   5.117 +
   5.118 +	pushw	%cs
   5.119 +	popw	%ds
   5.120 +	popw	%si
   5.121 +	xorw	%di, %di
   5.122 +#if HARDCODED_SETUPSIZE
   5.123 +	movb	$SETUP, %ch
   5.124 +	subw	$SETUP*32, %ax
   5.125 +#else
   5.126 +	movb	%dh, %ch
   5.127 +	shrw	$3, %dx
   5.128 +	subw	%dx, %ax
   5.129 +#endif
   5.130 +	movw	%ax, %es
   5.131 +	pushw	%si
   5.132 +	rep
   5.133 +	movsw			// move header part
   5.134 +
   5.135 +	pushw	%es
   5.136 +	popw	%ds
   5.137 +	movw	$end-_start, %si
   5.138 +	pushw	%cs
   5.139 +	popw	%es		// restore setup seg
   5.140 +	popw	%di
   5.141  	retf
   5.142  
   5.143  moved:
   5.144 -	popw	%es		// restore setup seg
   5.145 -	movw	START_IP, %di
   5.146  #if CHANGE_STACK
   5.147 -	movw	$0xFFFE, %ax
   5.148 +	movw	$STKSZ, %ax	// trick: %ss = %sp
   5.149  	movw	%ss, %bx
   5.150 -	pushw	$0
   5.151 +	pushw	%ax
   5.152  	popw	%ss
   5.153  	xchgw	%ax, %sp
   5.154  	pushw	%bx		// %ss
   5.155  	pushw	%ax		// %sp
   5.156  #endif
   5.157 +	pushw	%bp		// SYSTEM/16
   5.158  	call	unpack		// unpack setup
   5.159 -	pushw	$SYSTEM/16
   5.160  	popw	%es
   5.161  	xorw	%di,%di
   5.162  	call	unpack		// unpack system
   5.163 @@ -105,8 +140,23 @@
   5.164  	popw	%ss
   5.165  	xchgw	%ax, %sp
   5.166  #endif
   5.167 +#if UPDATE_SYSSIZE
   5.168 +# if HARDCODED_SYSSIZE
   5.169 +original_syssize:
   5.170 +	movw	$0, %ax
   5.171 +# else
   5.172 +	addw	$15, %di
   5.173 +	shrw	$4, %di
   5.174 +	movw	%es, %ax
   5.175 +	addw	%di, %ax
   5.176 +	subw	$SYSTEM/16, %ax
   5.177 +# endif
   5.178 +#endif
   5.179  	popw	%es
   5.180  	popw	%ds
   5.181 +#if UPDATE_SYSSIZE
   5.182 +	movw	%ax, SYSSIZE
   5.183 +#endif
   5.184  	popal
   5.185  	iret
   5.186