Skip to content

Instantly share code, notes, and snippets.

@sortie
Created July 29, 2016 13:09
Show Gist options
  • Select an option

  • Save sortie/d01c59aeb792ab26b193040a47afc7c8 to your computer and use it in GitHub Desktop.

Select an option

Save sortie/d01c59aeb792ab26b193040a47afc7c8 to your computer and use it in GitHub Desktop.
diff
diff --git a/kernel/x64/boot.S b/kernel/x64/boot.S
index e541b55..da5798c 100644
--- a/kernel/x64/boot.S
+++ b/kernel/x64/boot.S
@@ -174,6 +174,15 @@ __start:
.code64
2:
+ # The upper 32 bits of the general purpose registers are *undefined* after
+ # switching into 64-bit mode (Intel Manual, Vol 1, 3.4.1.1 "General-Purpose
+ # Registers in 64-Bit Mode"). The lower 32 bits are preserved from 32-bit
+ # mode. Any registers whose value we wish to retain must have its upper 32
+ # bits masked off. Assigning a register to itself in a 32-bit operation will
+ # zero the upper 32 bits. The only register the below code assumes is
+ # retained is the stack register (esp/rsp).
+ mov %esp, %esp
+
# Switch ds, es, fs, gs, ss to the kernel data segment (0x10).
movw $0x10, %cx
movw %cx, %ds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment