wok rev 19920

memtest: VCPI support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 19 22:14:58 2017 +0200 (2017-04-19)
parents a0df590cdf14
children 1bf63f69896d
files memtest/stuff/bootloader.S memtest/stuff/pack memtest/stuff/unpack.S
line diff
     1.1 --- a/memtest/stuff/bootloader.S	Wed Apr 19 17:06:08 2017 +0200
     1.2 +++ b/memtest/stuff/bootloader.S	Wed Apr 19 22:14:58 2017 +0200
     1.3 @@ -14,7 +14,9 @@
     1.4  #define EXE_SUPPORT		real mode dos .exe file support
     1.5  #define CMDLINE	0x9E00
     1.6  #define HELP			store help message for /? argument
     1.7 -#define CHECK_REALMODE		does not support vm86
     1.8 +#define TINYSYSTEM		the full file in one segment
     1.9 +#define CHECK_CPU		need a 386+
    1.10 +#define VM2RM			(0x3C+0x19B)
    1.11  #define SHUTDOWNDOS		shutdown DOS services
    1.12  
    1.13  /* some contraints to reduce the size */
    1.14 @@ -26,7 +28,7 @@
    1.15  stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    1.16  	decw	%bp			// Magic number: MZ
    1.17  	popw	%dx
    1.18 -	jmp	start			// Bytes on last page of file
    1.19 +	jmp	startz			// Bytes on last page of file
    1.20  	.word	(CODESZ+511)/512	// Pages in file
    1.21  	.word	0			// Relocations
    1.22  	.word	(end_header-_start)/16	// Size of header in paragraphs
    1.23 @@ -39,7 +41,9 @@
    1.24  	.word	0xFFF0			// Initial (relative) CS value
    1.25  //	.word	0x001C			// File address of relocation table
    1.26  //	.word	0,0,0			// Overlay number
    1.27 -	.ascii  "(SliTaz)"
    1.28 +	.ascii  "SliTaz"
    1.29 +startz:
    1.30 +	jmp	start
    1.31  end_header:
    1.32  comstart:
    1.33  	cld				# assume nothing
    1.34 @@ -68,7 +72,7 @@
    1.35  # define PUTS
    1.36  	movw	$EXEADRS(helpmsg), %si
    1.37  	cmpb	$'/'+1, %al
    1.38 -#  ifdef CHECK_REALMODE
    1.39 +#  ifdef CHECK_CPU
    1.40  	js	jsputs
    1.41  #  else
    1.42  	js	puts
    1.43 @@ -79,7 +83,7 @@
    1.44  	movw	$SYSSEG, %ax
    1.45  	movb	$(512-(end_header-_start))/2, %cl
    1.46  	movw	$end_header, %di
    1.47 -#ifdef CHECK_REALMODE
    1.48 +#ifdef CHECK_CPU
    1.49  #define PUTS
    1.50  	movw	$EXEADRS(realmode_expected), %si
    1.51  	//movb	setup_sects-realmode_expected(%si), %ch
    1.52 @@ -96,7 +100,14 @@
    1.53  	js	puts		// S= not 386+
    1.54  	smsww	%dx
    1.55  	shrw	$1, %dx
    1.56 +# ifdef VM2RM
    1.57 +	jnc	isrm
    1.58 +	push	%cs
    1.59 +	call	VM2RM
    1.60 +isrm:
    1.61 +# else
    1.62  	jc	puts		// protected mode: vm86
    1.63 +# endif
    1.64  #else
    1.65  	movb	EXEADRS(setup_sects), %ch
    1.66  #endif
    1.67 @@ -127,7 +138,7 @@
    1.68  #else
    1.69  #undef HELP
    1.70  #undef CMDLINE
    1.71 -#undef CHECK_REALMODE
    1.72 +#undef CHECK_CPU
    1.73  #endif
    1.74  	cld				# assume nothing
    1.75  stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    1.76 @@ -244,6 +255,28 @@
    1.77  	popaw
    1.78  #endif
    1.79  movesys:				// %ax = SYSSEG
    1.80 +#ifdef TINYSYSTEM
    1.81 +	movw	%si, %cx
    1.82 +	negw	%cx
    1.83 +	xorw	%di, %di
    1.84 +	movw	%ax, %es
    1.85 +	movw	%si, %dx
    1.86 +	shrw	$4, %dx
    1.87 +# ifdef SHUTDOWNDOS
    1.88 +	movw	%bx, %ds
    1.89 +# endif
    1.90 +	addw	%dx, %bx
    1.91 +	subw	%ax, %bx
    1.92 +	jnc	forward
    1.93 +	addw	%cx, %di
    1.94 +	addw	%cx, %si
    1.95 +	incw	%cx
    1.96 +	std
    1.97 +forward:
    1.98 +	rep
    1.99 +	  movsb
   1.100 +	cld
   1.101 +#else
   1.102  	movw	%cs:syssize, %bp
   1.103  	shrw	$4, %si
   1.104  	addw	%si, %bx
   1.105 @@ -265,6 +298,7 @@
   1.106  	  movsw
   1.107  	decw	%bp
   1.108  	jns	forward
   1.109 +#endif
   1.110  #ifndef NO_CURSOR_DEFINITION
   1.111  	movb	$1, %ah
   1.112  	movb	$0, %bh
   1.113 @@ -415,17 +449,77 @@
   1.114  bdendlp:
   1.115          jmp	read_sectorslp
   1.116  
   1.117 +#ifdef VM2RM
   1.118 +pagebuf		=	0x96000
   1.119 +saved_ss_sp	=	gdt_abs-44
   1.120 +saved_sp	=	gdt_abs-44
   1.121 +saved_ss	=	gdt_abs-42
   1.122 +tss		=	gdt_abs-40
   1.123 +gdt		=	gdt_abs-32
   1.124 +gdt_null	=	gdt_abs-32
   1.125 +gdt_vcpi	=	gdt_abs-24
   1.126 +gdt_vcpi2	=	gdt_abs-16
   1.127 +gdt_vcpi3	=	gdt_abs-8
   1.128 +gdt_abs:
   1.129 +	.word	0xFFFF,0
   1.130 +	.byte	0,0x92,0xCF,0
   1.131 +gdt_code:
   1.132 +	.word	0xFFFF
   1.133 +gdt_code_base:
   1.134 +	.long	0x9A000000
   1.135 +	.byte	0x8F,0
   1.136 +gdt_tss:
   1.137 +	.word	0x00FF
   1.138 +gdt_tss_base:
   1.139 +	.long	0x89000000+EXEADRS(tss)
   1.140 +	.byte	0,0
   1.141 +gdtr:
   1.142 +gdt_lim:
   1.143 +	.word	0xFFFF
   1.144 +gdt_base:
   1.145 +	.long	EXEADRS(gdt)
   1.146 +sw2pm_params:
   1.147 +sw2pm_cr3:
   1.148 +	.long	pagebuf+0x1000
   1.149 +sw2pm_gdtr_ptr:
   1.150 +	.long	EXEADRS(gdtr)
   1.151 +sw2pm_idtr_ptr:
   1.152 +	.long	EXEADRS(idtr)
   1.153 +sw2pm_ldtr:
   1.154 +	.word	0
   1.155 +sw2pm_tr:
   1.156 +SEL_TSS		= gdt_tss-gdt_null
   1.157 +	.word	SEL_TSS
   1.158 +sw2pm_jumpaddr:
   1.159 +#define SETUPEXEADRS(x)	(x+0x2E0)
   1.160 +pm_code		=	0x0084
   1.161 +	.long	SETUPEXEADRS(pm_code)
   1.162 +SEL_CODE	= gdt_code-gdt_null
   1.163 +	.word	SEL_CODE
   1.164 +idtr:
   1.165 +idt_lim:
   1.166 +	.word	0x03FF
   1.167 +idt_base:
   1.168 +	.long	0
   1.169 +#endif
   1.170  #ifdef HELP
   1.171  helpmsg:
   1.172 -	.ascii	"No help available."
   1.173 +	.ascii	"No help."
   1.174  	.byte	13,10
   1.175  	.byte	0
   1.176  #endif
   1.177 -#ifdef CHECK_REALMODE
   1.178 +#ifdef CHECK_CPU
   1.179 +# if VM2RM
   1.180 +	.org	484
   1.181 +realmode_expected:
   1.182 +helpend:
   1.183 +	.ascii	"386+ only."
   1.184 +# else
   1.185  	.org	475
   1.186  realmode_expected:
   1.187  helpend:
   1.188  	.ascii	"386 real mode only."
   1.189 +# endif
   1.190  	.byte	13,10,0
   1.191  #endif
   1.192  	.org	497
     2.1 --- a/memtest/stuff/pack	Wed Apr 19 17:06:08 2017 +0200
     2.2 +++ b/memtest/stuff/pack	Wed Apr 19 22:14:58 2017 +0200
     2.3 @@ -13,10 +13,14 @@
     2.4  	[ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0
     2.5  	grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0
     2.6  	grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0
     2.7 -	helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
     2.8 -	helpend=$(sed '/helpend:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
     2.9 -	sed -i "s/YYY/$((0x$helpmsg))/" $0
    2.10 -	sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg-1))/" $0
    2.11 +	helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    2.12 +	helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
    2.13 +	if [ -n "$helpmsg" ]; then
    2.14 +		sed -i "s/YYY/$((0x$helpmsg))/" $0
    2.15 +		sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg-1))/" $0
    2.16 +	else
    2.17 +		sed -i '/YYY/d' $0
    2.18 +	fi
    2.19  	cat >> $0 <<EOM
    2.20  $(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -)
    2.21  EOT
    2.22 @@ -62,7 +66,7 @@
    2.23  }
    2.24  
    2.25  HELP="$(unix2dos <<EOT
    2.26 -Memtest86+ VERSION is an endless advanced memory diagnostic tool (GPL).
    2.27 +Memtest86+ VERSION GPL endless
    2.28  EOT
    2.29  )"
    2.30  main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT
     3.1 --- a/memtest/stuff/unpack.S	Wed Apr 19 17:06:08 2017 +0200
     3.2 +++ b/memtest/stuff/unpack.S	Wed Apr 19 22:14:58 2017 +0200
     3.3 @@ -11,6 +11,7 @@
     3.4  #define FLAT16			1
     3.5  //#define FLAT16OUT		0
     3.6  #define SAVEREGS		0 
     3.7 +#define VM2RM			1
     3.8  
     3.9  	.text
    3.10  	.code16
    3.11 @@ -205,6 +206,63 @@
    3.12  	lret
    3.13  #endif
    3.14  
    3.15 +#if VM2RM
    3.16 +#define EXEADRS(x)	(x+0x2E0)
    3.17 +#define BOOTEXEADRS(x)	(x+0xE0)
    3.18 +vm2rm:
    3.19 +pagebuf		=	0x96000
    3.20 +gdt_abs		=	0x18e		// see bootloader.lst
    3.21 +sw2pm_params	=	gdt_abs+30
    3.22 +sw2pm_cr3	=	sw2pm_params
    3.23 +sw2pm_idtr_ptr	=	sw2pm_params+8
    3.24 +saved_ss_sp	=	gdt_abs-44
    3.25 +saved_sp	=	gdt_abs-44
    3.26 +saved_ss	=	gdt_abs-42
    3.27 +tss		=	gdt_abs-40
    3.28 +gdt		=	gdt_abs-32
    3.29 +gdt_null	=	gdt_abs-32
    3.30 +gdt_vcpi	=	gdt_abs-24
    3.31 +gdt_vcpi2	=	gdt_abs-16
    3.32 +gdt_vcpi3	=	gdt_abs-8
    3.33 +gdt_code_base	=	gdt_abs+10
    3.34 +fixuprange	=	0x20
    3.35 +	pushaw
    3.36 +	pushw	%es
    3.37 +	pushw	%ds
    3.38 +	movl	%cs,%edx
    3.39 +	shll	$4,%edx
    3.40 +	movw	$BOOTEXEADRS(gdt_vcpi),%si
    3.41 +	movw	$-fixuprange,%bx
    3.42 +	addl	%edx,sw2pm_idtr_ptr-gdt_vcpi(%si)
    3.43 +fixup:
    3.44 +	addl	%edx,fixuprange+gdt_code_base-gdt_vcpi(%bx,%si)
    3.45 +	addw	$8,%bx
    3.46 +	jne	fixup
    3.47 +	pushw	$pagebuf/16
    3.48 +	popw	%es
    3.49 +	movl	$pagebuf+3,%es:0x1000
    3.50 +	xorw	%di,%di
    3.51 +	movw	$0xDE01,%ax	// EBX = getiface(DS:SI, ES:DI)
    3.52 +	int	$0x67
    3.53 +	movw	$BOOTEXEADRS(saved_sp),%bx
    3.54 +	movw	%ss,2(%bx)
    3.55 +	movw	%sp,(%bx)
    3.56 +	leal	BOOTEXEADRS(sw2pm_params)(%edx),%esi
    3.57 +	movw	$0xDE0C, %ax	// switchpm(ESI)
    3.58 +	cli
    3.59 +	int	$0x67
    3.60 +pm_code:
    3.61 +	movl	%cr0,%eax
    3.62 +	andl	$0x7FFFFFFE,%eax
    3.63 +	movl	%eax,%cr0
    3.64 +	movl	%eax,%cr3
    3.65 +	lssw	%cs:(%bx),%sp	
    3.66 +	popw	%ds
    3.67 +	popw	%es
    3.68 +	popaw
    3.69 +	retf
    3.70 +#endif
    3.71 +
    3.72  unpack:
    3.73  #define NO_LZMA_HEADER
    3.74  #include "unlzma.S"