summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch/amd64')
-rw-r--r--src/kernel/arch/amd64/32/boot.s5
-rw-r--r--src/kernel/arch/amd64/interrupts/isr_stub.s1
-rw-r--r--src/kernel/arch/amd64/registers.h2
-rw-r--r--src/kernel/arch/amd64/sysenter.s7
4 files changed, 13 insertions, 2 deletions
diff --git a/src/kernel/arch/amd64/32/boot.s b/src/kernel/arch/amd64/32/boot.s
index 0621038..b0808d3 100644
--- a/src/kernel/arch/amd64/32/boot.s
+++ b/src/kernel/arch/amd64/32/boot.s
@@ -17,7 +17,7 @@ _start:
jz panic_early
mov %cr4, %eax
- or $(1<<5), %eax // PAE
+ or $(1<<5 | 1<<9 | 1<<10), %eax // PAE | SSE | SSE
mov %eax, %cr4
call pml4_identity_init
@@ -30,7 +30,8 @@ _start:
wrmsr
mov %cr0, %eax
- or $0x80000000, %eax
+ or $0x80000002, %eax // enable paging, coprocessor monitoring
+ and $(~4), %eax // disable coprocessor emulation
mov %eax, %cr0
call gdt_init
diff --git a/src/kernel/arch/amd64/interrupts/isr_stub.s b/src/kernel/arch/amd64/interrupts/isr_stub.s
index c63bf2c..75934d5 100644
--- a/src/kernel/arch/amd64/interrupts/isr_stub.s
+++ b/src/kernel/arch/amd64/interrupts/isr_stub.s
@@ -32,6 +32,7 @@ _isr_stage2:
push %r13
push %r14
push %r15
+ // TODO FXSAVE might be required on interrupts too?
// convert the return address into the vector nr
mov 120(%rsp), %rdi
diff --git a/src/kernel/arch/amd64/registers.h b/src/kernel/arch/amd64/registers.h
index 5d88595..b8f6248 100644
--- a/src/kernel/arch/amd64/registers.h
+++ b/src/kernel/arch/amd64/registers.h
@@ -2,11 +2,13 @@
#include <camellia/types.h>
#include <stdint.h>
+/* requires 16-byte alignment */
struct registers {
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
uint64_t rdi, rsi;
userptr_t rbp, rsp;
uint64_t rbx, rdx, rcx, rax;
+ uint8_t _sse[512];
} __attribute__((__packed__));
// saves a return value according to the SysV ABI
diff --git a/src/kernel/arch/amd64/sysenter.s b/src/kernel/arch/amd64/sysenter.s
index 8fa8acc..6b6d684 100644
--- a/src/kernel/arch/amd64/sysenter.s
+++ b/src/kernel/arch/amd64/sysenter.s
@@ -51,6 +51,12 @@ _sysexit_real:
mov %ax, %gs
*/
+ /* The state image referenced with an FXRSTOR instruction must have
+ * been saved using an FXSAVE instruction or be in the same format
+ * as required [...] will result in an incorrect state restoration. */
+ // TODO will probably end up fucking something up in a hard to debug way
+ // sorry, future me. hopefully you have learned something from this
+ fxrstor (_sysexit_regs + 128)
mov $_sysexit_regs, %rsp
pop %r15
pop %r14
@@ -86,6 +92,7 @@ sysenter_stage1:
mov $pml4_identity, %rsp
mov %rsp, %cr3
+ fxsave (_sysexit_regs + 128)
mov $(_sysexit_regs + 128), %rsp
push %rax
push %rcx