wok diff memtest64/stuff/unpackx.S @ rev 25514

Add memtest64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 16 14:18:05 2023 +0000 (16 months ago)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memtest64/stuff/unpackx.S	Thu Feb 16 14:18:05 2023 +0000
     1.3 @@ -0,0 +1,323 @@
     1.4 +#define SYSTEM		0x10000
     1.5 +#define SETUP		14
     1.6 +#define SYSSIZE		0x1F4
     1.7 +#define SETUPSIZE	0x1F1
     1.8 +
     1.9 +#define KEEP_BOOTSECTOR		0
    1.10 +#define LINUX_HEADER		0
    1.11 +#define UPDATE_SYSSIZE		1
    1.12 +#define FLAT16			1	// lzma case
    1.13 +#define FLAT16OUT		0
    1.14 +#define COPYTOHIGHMEM		0
    1.15 +#define UPDATE_CODE32_START	0
    1.16 +#define DOUBLE_PACKED		0
    1.17 +#define SAVEREGS		0 
    1.18 +#define ELKS			0
    1.19 +
    1.20 +	.text
    1.21 +	.code16
    1.22 +	.org	0
    1.23 +
    1.24 +#if KEEP_BOOTSECTOR
    1.25 +#undef UPDATE_SYSSIZE
    1.26 +#define UPDATE_SYSSIZE		0
    1.27 +#endif
    1.28 +#if ELKS
    1.29 +	.arch	i8086
    1.30 +#define FLAT16			1
    1.31 +#define KEEP_BOOTSECTOR		1
    1.32 +#define LINUX_HEADER		0
    1.33 +#define SAVEREGS		0 
    1.34 +#define TOPSEG		0x2000
    1.35 +#else
    1.36 +#define TOPSEG		0x8000
    1.37 +#endif
    1.38 +
    1.39 +.macro	pusham
    1.40 +#if ELKS
    1.41 +	pushw	%ax
    1.42 +//	movw	%sp, %ax
    1.43 +//	incw	%ax		// emulate popa behaviour
    1.44 +//	incw	%ax
    1.45 +	pushw	%cx
    1.46 +	pushw	%dx
    1.47 +	pushw	%bx
    1.48 +//	pushw	%ax		// %sp
    1.49 +	pushw	%bp
    1.50 +	pushw	%si
    1.51 +	pushw	%di
    1.52 +#else
    1.53 +	pushaw
    1.54 +#endif
    1.55 +.endm 
    1.56 +
    1.57 +.macro	popam
    1.58 +#if ELKS
    1.59 +	popw	%di
    1.60 +	popw	%si
    1.61 +	popw	%bp
    1.62 +//	popw	%ax
    1.63 +	popw	%bx
    1.64 +	popw	%dx
    1.65 +	popw	%cx
    1.66 +	popw	%ax
    1.67 +#else
    1.68 +	popaw
    1.69 +#endif
    1.70 +.endm 
    1.71 +
    1.72 +.macro	pushm	val
    1.73 +#if ELKS
    1.74 +	movw	\val, %ax
    1.75 +	pushw	%ax
    1.76 +#else
    1.77 +	pushw	\val
    1.78 +#endif
    1.79 +.endm 
    1.80 +
    1.81 +.macro	shrwm	cnt, reg
    1.82 +#if ELKS
    1.83 +	.rept	\cnt
    1.84 +	shrw	$1, \reg
    1.85 +	.endr
    1.86 +#else
    1.87 +	shrw	$\cnt, \reg
    1.88 +#endif
    1.89 +.endm
    1.90 +
    1.91 +	.globl	_start
    1.92 +_start:
    1.93 +#if LINUX_HEADER
    1.94 +	jmp	start2
    1.95 +	.ascii	"HdrS"		// 202 magic
    1.96 +	.word	0x200		// 206 version 2.00
    1.97 +	.long	0		// 208 realmode_swtch
    1.98 +	.word	SYSTEM/16	// 20C start_sys_seg
    1.99 +	.word	0		// 20E kernel_version
   1.100 +	.byte	0		// 210 type_of_loader
   1.101 +	.byte	0		// 211 loadflags
   1.102 +	.word	0		// 212 setup_move_size
   1.103 +	.long	SYSTEM		// 214 code32_start
   1.104 +	.long	0		// 218 ramdisk_image
   1.105 +	.long	0		// 21C ramdisk_size
   1.106 +	.long	0		// 220 bootsect_kludge
   1.107 +start2:
   1.108 +#endif
   1.109 +#if SAVEREGS
   1.110 +	pushfw
   1.111 +	pushw	%cs
   1.112 +	pushw	$0
   1.113 +	pusham
   1.114 +	xorw	%si, %si
   1.115 +	pushw	%ds
   1.116 +	pushw	%es
   1.117 +	cld
   1.118 +#else
   1.119 +	pushw	%cs			// return adress is %cs:0
   1.120 +	xorw	%si, %si
   1.121 +	pushw	%si
   1.122 +#endif	// SAVEREGS
   1.123 +	pushw	%ds			// <A> bootsector+setup segment
   1.124 +#if FLAT16
   1.125 +# 1- move 9000..9020+stp -> TOPSEG
   1.126 +	pushm	$TOPSEG
   1.127 +	popw	%es
   1.128 +# if SAVEREGS
   1.129 +setup_word:
   1.130 +	movw	$SETUP*256+256, %cx
   1.131 +	pushw	%cx			// <B> bootsector+setup words
   1.132 +# endif
   1.133 +	pushw	%es			// <C> TOPSEG
   1.134 +	pushw	%es
   1.135 +# if SAVEREGS
   1.136 +	xorw	%di, %di		// %ds:%si = 9000:0000		%es:%di = TOPSEG:0
   1.137 +	pushm	$0x200+cont
   1.138 +	rep
   1.139 +	  movsw
   1.140 +	lret
   1.141 +cont:
   1.142 +# else
   1.143 +	movw	$-0x200, %di
   1.144 +	call	jumpinto
   1.145 +# endif
   1.146 +# 2- move 1000..1000+sys -> TOPSEG+stp
   1.147 +	pushm	$0x1000
   1.148 +	popw	%ds
   1.149 +	xorw	%si, %si		// %ds:%si = 1000:0
   1.150 +	subw	%di, %cx		// %cx = 64K - setupsz
   1.151 +	rep
   1.152 +	  movsb
   1.153 +# 3- unlz(TOPSEG+stp:end, 1000-stp:0)
   1.154 +setup_seg:
   1.155 +	pushm	$0x1000-(SETUP*32)-32
   1.156 +	popw	%es
   1.157 +#else		// FLAT16
   1.158 +# 1- move 9020..9020+unpack -> 0700 and jump into
   1.159 +	movw	$0x700, %cx		// Up to 3.5KB for unpacker (unlzma is << 1KB)
   1.160 +	movw	%cx, %es		// Use 7000 .. 7E00, keep up to 23 elks setup sectors
   1.161 +	pushw	%es
   1.162 +	xorw	%di, %di		// %ds:%si = 9000:0000	%es:%di = 0700:0000
   1.163 +	pushm	$0x200+cont
   1.164 +# if SAVEREGS
   1.165 +	rep
   1.166 +	  movsw
   1.167 +	lret
   1.168 +# else
   1.169 +	jmp	jumpinto
   1.170 +# endif
   1.171 +cont:
   1.172 +# 2- move 9020..9020+stp -> 9000-sys-stp
   1.173 +	movw	%ds, %dx
   1.174 +setup_byte:
   1.175 +	movb	$SETUP+1, %ch
   1.176 +setup_para:
   1.177 +	subw	$SETUP*32+32+0xF000, %dx
   1.178 +packed_syssize:
   1.179 +	movw	$0+0x1000, %ax
   1.180 +	pushw	%cx			// <B> bootsector+setup words
   1.181 +	subw	%ax, %dx
   1.182 +	movw	%dx, %es
   1.183 +	pushw	%es			// <C> 9000-sys-stp
   1.184 +	xorw	%si, %si
   1.185 +	xorw	%di, %di		// %ds:%si = 9000:0	%es:%di = 9000-sys-stp:0
   1.186 +	rep
   1.187 +	  movsw
   1.188 +# 3- move 1000..1000+sys -> 9000-sys
   1.189 +	movw	%ds, %dx
   1.190 +mvsys:
   1.191 +	decw	%ax
   1.192 +	decw	%dx
   1.193 +	movw	%ax, %ds
   1.194 +	movw	%dx, %es
   1.195 +	xorw	%si, %si
   1.196 +	xorw	%di, %di
   1.197 +	movw	$8, %cx
   1.198 +	rep
   1.199 +	  movsw
   1.200 +	cmpw	$0x1000, %ax
   1.201 +	jne	mvsys
   1.202 +# 4- unlz(9000-sys-stp:end, 1000-stp:0)
   1.203 +setup_seg:
   1.204 +	pushm	$0x1000-(SETUP*32)-32
   1.205 +	popw	%es
   1.206 +#endif		// FLAT16
   1.207 +	popw	%ds			// <C>
   1.208 +#if FLAT16 && SAVEREGS == 0
   1.209 +	movw	$end-_start, %si	// %ds:%si = TOPSSEG:compressed
   1.210 +#else
   1.211 +	movw	$0x200+end-_start, %si	// %ds:%si = 9000-sys-stp:compressed
   1.212 +#endif
   1.213 +#if KEEP_BOOTSECTOR
   1.214 +setup_keep:
   1.215 +	xorw	%di, %di
   1.216 +#else
   1.217 +# if UPDATE_SYSSIZE
   1.218 +setup_syssize:
   1.219 +	movw	$0x1F4, %di		// %es:%di = 1000-setup-bootsector:SYSSIZE
   1.220 +# else
   1.221 +	movw	$0x200, %di
   1.222 +# endif
   1.223 +#endif
   1.224 +	pushw	%di
   1.225 +	pushw	%es
   1.226 +#if DOUBLE_PACKED
   1.227 +double_packed:
   1.228 +	pushm	$0x4000
   1.229 +	popw	%es
   1.230 +	pushw	%di
   1.231 +	pushw	%es
   1.232 +	call	unpack
   1.233 +	popw	%ds
   1.234 +	popw	%si
   1.235 +	popw	%es
   1.236 +	popw	%di
   1.237 +	pushw	%di
   1.238 +	pushw	%es
   1.239 +#endif
   1.240 +	call	unpack
   1.241 +#if COPYTOHIGHMEM
   1.242 +# if FLAT16OUT
   1.243 +	movw	$0x9310+1, %ax		// from 1000:FFFF
   1.244 +# else
   1.245 +#  if 0
   1.246 +	movw	%es, %ax
   1.247 +	shrw	$12, %ax
   1.248 +	orw	$0x9310, %ax
   1.249 +#  else
   1.250 +	movw	$0x9310+7, %ax		// from 7000:FFFF
   1.251 +#  endif
   1.252 +# endif
   1.253 +	pushw	%ss
   1.254 +	popw	%es
   1.255 +	movw	$8, %cx
   1.256 +zero1:
   1.257 +	pushw	$0			// 2E..20
   1.258 +	loop	zero1
   1.259 +src:		
   1.260 +	pushw	%cx			// 1E, 16
   1.261 +	pushw	%ax			// 1A: dst %ax:%cx, 12: src %ax:%cx
   1.262 +	pushw	%cx
   1.263 +	pushw	$-1			// 18, 10: full 64K segment
   1.264 +	subb	$0x10, %al
   1.265 +	jnc	src
   1.266 +	movb	$8, %cl
   1.267 +zero2:
   1.268 +	pushw	$0			// 0E..00
   1.269 +	loop	zero2
   1.270 +	movw	%sp, %si
   1.271 +syslp:
   1.272 +	movb	$0x80, %ch	
   1.273 +	movb	$0x87, %ah
   1.274 +	int	$0x15
   1.275 +# if FLAT16OUT == 0
   1.276 +	decb	%es:0x1C(%si)
   1.277 +	decb	%es:0x14(%si)
   1.278 +	jne	syslp			// down to 1000:0000
   1.279 +# endif
   1.280 +	addw	$0x30, %sp
   1.281 +#endif	// COPYTOHIGHMEM
   1.282 +	popw	%ds
   1.283 +	popw	%si			// %ds:%si = 1000-setup-bootsector:SYSSIZE / 0
   1.284 +#if UPDATE_CODE32_START
   1.285 +update_code32_start:
   1.286 +//	movb	$1, 0x216
   1.287 +#endif
   1.288 +#if FLAT16 == 0 || SAVEREGS
   1.289 +	popw	%cx			// <B> bootsector+setup words
   1.290 +#endif
   1.291 +	popw	%es			// <A> bootsector+setup segment
   1.292 +	movw	%si, %di
   1.293 +jumpinto:
   1.294 +#if FLAT16 && SAVEREGS == 0
   1.295 +setup_word:
   1.296 +	movw	$SETUP*256+256, %cx
   1.297 +#endif
   1.298 +# 5- move 1000-stp..1000 -> 9000
   1.299 +	rep
   1.300 +	  movsw
   1.301 +#if SAVEREGS
   1.302 +	popw	%es
   1.303 +	popw	%ds
   1.304 +	popam
   1.305 +	iret
   1.306 +#else
   1.307 +	lret
   1.308 +#endif
   1.309 +
   1.310 +unpack:
   1.311 +#define NO_LZMA_HEADER
   1.312 +#define NO_LZSA2_HEADER
   1.313 +#define NO_LZSA1_HEADER
   1.314 +#define NO_LZ4_HEADER
   1.315 +#if ELKS
   1.316 +#define ONLY8086	1
   1.317 +#endif
   1.318 +#if defined(FLAT16OUT) && FLAT16OUT == 0
   1.319 +#undef FLAT16OUT
   1.320 +#endif
   1.321 +#if defined(FLAT16) && FLAT16 == 0
   1.322 +#undef FLAT16
   1.323 +#endif
   1.324 +#include "uncompress.S"
   1.325 +
   1.326 +end: