Browse Source

Preserve GDT across prot_call().

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
c10d1aa9d7
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      src/arch/i386/transitions/librm.S

+ 12
- 6
src/arch/i386/transitions/librm.S View File

335
  ****************************************************************************
335
  ****************************************************************************
336
  */
336
  */
337
 
337
 
338
-#define PC_OFFSET_IX86 ( 0 )
338
+#define PC_OFFSET_GDT ( 0 )
339
+#define PC_OFFSET_IX86 ( PC_OFFSET_GDT + 8 /* pad to 8 to keep alignment */ )
339
 #define PC_OFFSET_RETADDR ( PC_OFFSET_IX86 + SIZEOF_I386_ALL_REGS )
340
 #define PC_OFFSET_RETADDR ( PC_OFFSET_IX86 + SIZEOF_I386_ALL_REGS )
340
 #define PC_OFFSET_FUNCTION ( PC_OFFSET_RETADDR + 4 )
341
 #define PC_OFFSET_FUNCTION ( PC_OFFSET_RETADDR + 4 )
341
 #define PC_OFFSET_END ( PC_OFFSET_FUNCTION + 4 )
342
 #define PC_OFFSET_END ( PC_OFFSET_FUNCTION + 4 )
344
 	.code16
345
 	.code16
345
 	.globl prot_call
346
 	.globl prot_call
346
 prot_call:
347
 prot_call:
347
-	/* Preserve registers and flags on external RM stack */
348
+	/* Preserve registers, flags and GDT on external RM stack */
348
 	pushfl
349
 	pushfl
349
 	pushal
350
 	pushal
350
 	pushw	%gs
351
 	pushw	%gs
353
 	pushw	%ds
354
 	pushw	%ds
354
 	pushw	%ss
355
 	pushw	%ss
355
 	pushw	%cs
356
 	pushw	%cs
357
+	subw	$8, %sp
358
+	movw	%sp, %bp
359
+	sgdt	(%bp)
356
 
360
 
357
 	/* For sanity's sake, clear the direction flag as soon as possible */
361
 	/* For sanity's sake, clear the direction flag as soon as possible */
358
 	cld
362
 	cld
368
 	call	gateA20_set
372
 	call	gateA20_set
369
 
373
 
370
 	/* Call function */
374
 	/* Call function */
371
-	pushl	%esp
375
+	leal	PC_OFFSET_IX86(%esp), %eax
376
+	pushl	%eax
372
 	call	*(PC_OFFSET_FUNCTION+4)(%esp)
377
 	call	*(PC_OFFSET_FUNCTION+4)(%esp)
373
 	popl	%eax /* discard */
378
 	popl	%eax /* discard */
374
 
379
 
379
 	.section ".text16"
384
 	.section ".text16"
380
 	.code16
385
 	.code16
381
 1:	
386
 1:	
382
-	/* Restore registers and flags and return */
383
-	popw	%ax	/* skip %cs - it is already set */
384
-	popw	%ax	/* skip %ss - it is already set */
387
+	/* Reload GDT, restore registers and flags and return */
388
+	movw	%sp, %bp
389
+	lgdt	(%bp)
390
+	addw	$12, %sp /* also skip %cs and %ss */
385
 	popw	%ds
391
 	popw	%ds
386
 	popw	%es
392
 	popw	%es
387
 	popw	%fs
393
 	popw	%fs

Loading…
Cancel
Save