fix interrupt entry stack alignment

This commit is contained in:
2023-10-22 12:30:38 +02:00
parent 4386d8c1cd
commit b0ebd1d019
3 changed files with 8 additions and 6 deletions

View File

@@ -28,11 +28,11 @@ void gdt_setup() {
gdt_tss.unused = 0;
gdt_tss.gran = 0;
gdt_tss.base_high = (tss_base >> 24) & 0xFFFFFFFFFF;
tss_entry.ist1 = ((uintptr_t) int_stack + INT_STACK_SIZE - 1) & (~0xFULL);
if ((tss_entry.ist1 & 0xFULL) != 0) _hcf();
tss_entry.rsp0 = ((uintptr_t) rsp_stack + RSP_STACK_SIZE - 1) & (~0xFULL);
if ((tss_entry.rsp0 & 0xFULL) != 0) _hcf();
tss_entry.ist1 = (((uintptr_t) int_stack + (INT_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
if ((tss_entry.ist1 & 0xFULL) != 8) _hcf();
tss_entry.rsp0 = (((uintptr_t) rsp_stack + (RSP_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
if ((tss_entry.rsp0 & 0xFULL) != 8) _hcf();
barrier();// The asm function might clobber registers
_gdt_setup();

View File

@@ -57,6 +57,7 @@ typedef struct {
// Assuming the compiler understands that this is pushed on the stack in the correct order
struct task_frame {
uint64_t guard;
uint64_t guard2;// To keep stack aligned after pushaq
uint64_t r15;
uint64_t r14;

View File

@@ -29,10 +29,11 @@ extern temp_fxsave
mov rdi, 0xdeadbe3fdeadb3ef ; IDT_GUARD
push rdi ; IDT_GUARD
push rdi ; IDT_GUARD2 for alignment
%endmacro
%macro popaq 0
add rsp, 8 ; remove IDT_GUARD
add rsp, 16 ; remove IDT_GUARD
fxrstor64 [temp_fxsave]