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 17 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
 	pushl	_data16
186
 	pushl	_data16
187
 	addw	$16, %cx /* %ecx must be less than 64kB anyway */
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
 	movw	%ss, %bp
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
 	/* Switch to protected mode */
198
 	/* Switch to protected mode */
194
 	cli
199
 	cli
200
 	.section ".text"
205
 	.section ".text"
201
 	.code32
206
 	.code32
202
 1:
207
 1:
203
-	/* Set up protected-mode data segments */
208
+	/* Set up protected-mode data segments and stack pointer */
204
 	movw	$VIRTUAL_DS, %ax
209
 	movw	$VIRTUAL_DS, %ax
205
 	movw	%ax, %ds
210
 	movw	%ax, %ds
206
 	movw	%ax, %es
211
 	movw	%ax, %es
207
 	movw	%ax, %fs
212
 	movw	%ax, %fs
208
 	movw	%ax, %gs
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
 	movw	%ax, %ss
214
 	movw	%ax, %ss
215
+	movl	pm_esp, %esp
216
 
216
 
217
 	/* Record real-mode %ss:sp (after removal of data) */
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
 	/* Publish virt_offset, text16 and data16 for PM code to use */
227
 	/* Publish virt_offset, text16 and data16 for PM code to use */
222
 	popl	data16
228
 	popl	data16
251
 	/* Add return address to data to be moved to RM stack */
257
 	/* Add return address to data to be moved to RM stack */
252
 	addl	$4, %ecx
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
 	subl	%ecx, %edx
263
 	subl	%ecx, %edx
258
-	
259
-	/* Move data from PM stack to RM stack */
260
 	movl	%ebp, %eax
264
 	movl	%ebp, %eax
261
 	shll	$4, %eax
265
 	shll	$4, %eax
262
 	leal	(%eax,%edx), %edi
266
 	leal	(%eax,%edx), %edi
263
 	subl	virt_offset, %edi
267
 	subl	virt_offset, %edi
268
+	
269
+	/* Move data from PM stack to RM stack */
264
 	movl	%esp, %esi
270
 	movl	%esp, %esi
265
 	rep movsb
271
 	rep movsb
266
 	
272
 	
285
 	ljmp	*p2r_jump_vector
291
 	ljmp	*p2r_jump_vector
286
 p2r_jump_target:
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
 	movw	%cs:rm_ds, %ax
295
 	movw	%cs:rm_ds, %ax
294
 	movw	%ax, %ds
296
 	movw	%ax, %ds
295
 	movw	%ax, %es
297
 	movw	%ax, %es
296
 	movw	%ax, %fs
298
 	movw	%ax, %fs
297
 	movw	%ax, %gs
299
 	movw	%ax, %gs
300
+	movw	%bp, %ss
301
+	movl	%edx, %esp
298
 
302
 
299
 	/* Return to real-mode address */
303
 	/* Return to real-mode address */
300
 	data32 ret
304
 	data32 ret
398
 	.section ".text16"
402
 	.section ".text16"
399
 	.code16
403
 	.code16
400
 1:	
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
 	movw	%sp, %bp
406
 	movw	%sp, %bp
405
 	lgdt	(%bp)
407
 	lgdt	(%bp)
406
 	addw	$12, %sp /* also skip %cs and %ss */
408
 	addw	$12, %sp /* also skip %cs and %ss */
409
 	popw	%fs
411
 	popw	%fs
410
 	popw	%gs
412
 	popw	%gs
411
 	popal
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
 	popfl
420
 	popfl
418
 	lret
421
 	lret
419
 
422
 
528
  ****************************************************************************
531
  ****************************************************************************
529
  */
532
  */
530
 	.section ".data"
533
 	.section ".data"
531
-rm_sp:	.word 0
532
-rm_ss:	.word 0
534
+rm_sp:	.long 0
535
+rm_ss:	.long 0
533
 pm_esp:	.long _estack
536
 pm_esp:	.long _estack
534
 
537
 
535
 /****************************************************************************
538
 /****************************************************************************

Loading…
Cancel
Save