summaryrefslogtreecommitdiffstats
path: root/src/arch/i386/transitions/librm.S
diff options
context:
space:
mode:
authorMichael Brown2014-05-02 14:18:55 +0200
committerMichael Brown2014-05-02 16:23:21 +0200
commitc64747db5040d860c9c77f2673c4cce287249bbd (patch)
tree1c9ddbd0516a5240916bcd79eae9ca4652c13ffa /src/arch/i386/transitions/librm.S
parent[librm] Speed up protected-to-real mode transition under KVM (diff)
downloadipxe-c64747db5040d860c9c77f2673c4cce287249bbd.tar.gz
ipxe-c64747db5040d860c9c77f2673c4cce287249bbd.tar.xz
ipxe-c64747db5040d860c9c77f2673c4cce287249bbd.zip
[librm] Speed up real-to-protected mode transition under KVM
Ensure that all segment registers have zero in the low two bits before transitioning to protected mode. This allows the CPU state to immediately be deemed to be "valid", and eliminates the need for any further emulated instructions. Load the protected-mode interrupt descriptor table after switching to protected mode, since this avoids triggering an EXCEPTION_NMI and corresponding VM exit. This reduces the time taken by real_to_prot under KVM by around 50%. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/i386/transitions/librm.S')
-rw-r--r--src/arch/i386/transitions/librm.S19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/arch/i386/transitions/librm.S b/src/arch/i386/transitions/librm.S
index 0d8110ac..eaf520b3 100644
--- a/src/arch/i386/transitions/librm.S
+++ b/src/arch/i386/transitions/librm.S
@@ -200,10 +200,22 @@ real_to_prot:
addr32 leal (%eax,%edx), %esi
subl rm_virt_offset, %esi
+ /* Load protected-mode global descriptor table */
+ data32 lgdt gdtr
+
+ /* Zero segment registers. This wastes around 12 cycles on
+ * real hardware, but saves a substantial number of emulated
+ * instructions under KVM.
+ */
+ xorw %ax, %ax
+ movw %ax, %ds
+ movw %ax, %es
+ movw %ax, %fs
+ movw %ax, %gs
+ movw %ax, %ss
+
/* Switch to protected mode */
cli
- data32 lgdt gdtr
- data32 lidt idtr
movl %cr0, %eax
orb $CR0_PE, %al
movl %eax, %cr0
@@ -220,6 +232,9 @@ r2p_pmode:
movw %ax, %ss
movl pm_esp, %esp
+ /* Load protected-mode interrupt descriptor table */
+ lidt idtr
+
/* Record real-mode %ss:sp (after removal of data) */
movw %bp, rm_ss
addl %ecx, %edx