diff options
author | dzwdz | 2022-08-28 22:23:05 +0200 |
---|---|---|
committer | dzwdz | 2022-08-28 22:23:20 +0200 |
commit | f2eb3a78c7b69c4b8e118d91327cc5c1016481fc (patch) | |
tree | 152904ceda01fb7d067819dc483aab91d2ccd91c | |
parent | 98464ad1b65066880bc892289239bafd39fe470b (diff) |
kernel/amd64: SSE support
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | ports/bin/cc | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/32/boot.s | 5 | ||||
-rw-r--r-- | src/kernel/arch/amd64/interrupts/isr_stub.s | 1 | ||||
-rw-r--r-- | src/kernel/arch/amd64/registers.h | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/sysenter.s | 7 |
6 files changed, 15 insertions, 4 deletions
@@ -10,7 +10,7 @@ CFLAGS += -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declara CFLAGS += -mgeneral-regs-only -Wno-address-of-packed-member CFLAGS += -Isrc/ -Isrc/shared/include/ -KERNEL_CFLAGS = $(CFLAGS) +KERNEL_CFLAGS = $(CFLAGS) -mno-sse USER_CFLAGS = $(CFLAGS) -Isrc/user/lib/include/ SPARSEFLAGS = -Wno-non-pointer-null diff --git a/ports/bin/cc b/ports/bin/cc index 6478b6e..885b512 100755 --- a/ports/bin/cc +++ b/ports/bin/cc @@ -1,5 +1,5 @@ #!/bin/sh -exec x86_64-elf-gcc -ffreestanding -fPIE -mno-sse \ +exec x86_64-elf-gcc -ffreestanding -fPIE \ -nostdlib -Wl,-pie -Wl,-no-dynamic-linker -T $REPO/src/user/linker.ld \ -I$REPO/src/ -I$REPO/src/shared/include/ -I$REPO/src/user/lib/include/ \ $* \ 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 |