Browse Source

Don't use the "rep ss movsb" trick to copy the RM stack to the PM

stack; it breaks vmxassist.
tags/v0.9.3
Michael Brown 16 years ago
parent
commit
42d96bcb07
1 changed files with 34 additions and 31 deletions
  1. 34
    31
      src/arch/i386/transitions/librm.S

+ 34
- 31
src/arch/i386/transitions/librm.S View File

@@ -186,9 +186,14 @@ real_to_prot:
186 186
 	pushl	_data16
187 187
 	addw	$16, %cx /* %ecx must be less than 64kB anyway */
188 188
 	
189
-	/* Real-mode %ss:%sp => %bp:%esi */
189
+	/* Real-mode %ss:%sp => %ebp:%edx and virtual address => %esi */
190
+	xorl	%ebp, %ebp
190 191
 	movw	%ss, %bp
191
-	movzwl	%sp, %esi
192
+	movzwl	%sp, %edx
193
+	movl	%ebp, %eax
194
+	shll	$4, %eax
195
+	leal	(%eax,%edx), %esi
196
+	subl	_virt_offset, %esi
192 197
 
193 198
 	/* Switch to protected mode */
194 199
 	cli
@@ -200,23 +205,24 @@ real_to_prot:
200 205
 	.section ".text"
201 206
 	.code32
202 207
 1:
203
-	/* Set up protected-mode data segments */
208
+	/* Set up protected-mode data segments and stack pointer */
204 209
 	movw	$VIRTUAL_DS, %ax
205 210
 	movw	%ax, %ds
206 211
 	movw	%ax, %es
207 212
 	movw	%ax, %fs
208 213
 	movw	%ax, %gs
209
-
210
-	/* Move data from RM stack to PM stack and set up PM stack */
211
-	movl	pm_esp, %esp
212
-	subl	%ecx, %esp
213
-	movl	%esp, %edi
214
-	rep ss movsb
215 214
 	movw	%ax, %ss
215
+	movl	pm_esp, %esp
216 216
 
217 217
 	/* Record real-mode %ss:sp (after removal of data) */
218
-	movw	%bp, rm_ss
219
-	movw	%si, rm_sp
218
+	movl	%ebp, rm_ss
219
+	addl	%ecx, %edx
220
+	movl	%edx, rm_sp
221
+
222
+	/* Move data from RM stack to PM stack */
223
+	subl	%ecx, %esp
224
+	movl	%esp, %edi
225
+	rep movsb
220 226
 
221 227
 	/* Publish virt_offset, text16 and data16 for PM code to use */
222 228
 	popl	data16
@@ -251,16 +257,16 @@ prot_to_real:
251 257
 	/* Add return address to data to be moved to RM stack */
252 258
 	addl	$4, %ecx
253 259
 	
254
-	/* Real-mode %ss:sp => %ebp:edx */
255
-	movzwl	rm_ss, %ebp
256
-	movzwl	rm_sp, %edx
260
+	/* Real-mode %ss:sp => %ebp:edx and virtual address => %edi */
261
+	movl	rm_ss, %ebp
262
+	movl	rm_sp, %edx
257 263
 	subl	%ecx, %edx
258
-	
259
-	/* Move data from PM stack to RM stack */
260 264
 	movl	%ebp, %eax
261 265
 	shll	$4, %eax
262 266
 	leal	(%eax,%edx), %edi
263 267
 	subl	virt_offset, %edi
268
+	
269
+	/* Move data from PM stack to RM stack */
264 270
 	movl	%esp, %esi
265 271
 	rep movsb
266 272
 	
@@ -285,16 +291,14 @@ prot_to_real:
285 291
 	ljmp	*p2r_jump_vector
286 292
 p2r_jump_target:
287 293
 
288
-	/* Set up real-mode stack */
289
-	movw	%bp, %ss
290
-	movl	%edx, %esp
291
-	
292
-	/* Set up real-mode data segments */
294
+	/* Set up real-mode data segments and stack pointer */
293 295
 	movw	%cs:rm_ds, %ax
294 296
 	movw	%ax, %ds
295 297
 	movw	%ax, %es
296 298
 	movw	%ax, %fs
297 299
 	movw	%ax, %gs
300
+	movw	%bp, %ss
301
+	movl	%edx, %esp
298 302
 
299 303
 	/* Return to real-mode address */
300 304
 	data32 ret
@@ -398,9 +402,7 @@ prot_call:
398 402
 	.section ".text16"
399 403
 	.code16
400 404
 1:	
401
-	/* Reload GDT, restore registers and flags and return.  Note
402
-	 * that %esp is restored manually, since popal discards it.
403
-	 */
405
+	/* Reload GDT, restore registers and flags and return */
404 406
 	movw	%sp, %bp
405 407
 	lgdt	(%bp)
406 408
 	addw	$12, %sp /* also skip %cs and %ss */
@@ -409,11 +411,12 @@ prot_call:
409 411
 	popw	%fs
410 412
 	popw	%gs
411 413
 	popal
412
-	addr32 movl -20(%esp), %esp /* -20(%sp) is not a valid 80386
413
-				     * expression.  -20(%esp) is safe
414
-				     * because prot_to_real zeroes the
415
-				     * high word of %esp, and interrupts
416
-				     * are still disabled at this point. */
414
+	/* popal skips %esp.  We therefore want to do "movl -20(%sp),
415
+	 * %esp", but -20(%sp) is not a valid 80386 expression.
416
+	 * Fortunately, pot_to_real() zeroes the high word of %esp, so
417
+	 * we can just use -20(%esp) instead.
418
+	 */
419
+	addr32 movl -20(%esp), %esp
417 420
 	popfl
418 421
 	lret
419 422
 
@@ -528,8 +531,8 @@ rc_function:	.word 0, 0
528 531
  ****************************************************************************
529 532
  */
530 533
 	.section ".data"
531
-rm_sp:	.word 0
532
-rm_ss:	.word 0
534
+rm_sp:	.long 0
535
+rm_ss:	.long 0
533 536
 pm_esp:	.long _estack
534 537
 
535 538
 /****************************************************************************

Loading…
Cancel
Save