diff --git a/arch/amd64/hw/exc_s.S b/arch/amd64/hw/exc_s.S index 33e59b5..0e02ae0 100644 --- a/arch/amd64/hw/exc_s.S +++ b/arch/amd64/hw/exc_s.S @@ -22,8 +22,8 @@ amd64_exc_generic: // 0x10: rip // 0x08: error code // 0x00: error number - cmpq $0x08, 0x18(%rip) - jnz 1f + cmpq $0x08, 0x18(%rsp) + jz 1f swapgs 1: @@ -79,6 +79,7 @@ amd64_exc_generic: addq $16, %rsp + iret_swapgs_if_needed iretq amd64_isr_nerr 0 diff --git a/arch/amd64/hw/irq0.S b/arch/amd64/hw/irq0.S index d2b6f20..a53e942 100644 --- a/arch/amd64/hw/irq0.S +++ b/arch/amd64/hw/irq0.S @@ -7,16 +7,16 @@ amd64_irq0_early: cli - swapgs_if_needed + iret_swapgs_if_needed pushq %rax irq_eoi_lapic 0 popq %rax - swapgs_if_needed + iret_swapgs_if_needed iretq amd64_irq0: cli - swapgs_if_needed + iret_swapgs_if_needed // Push caller-saved registers so it appears as if a thread just called yield() pushq %r11 @@ -42,7 +42,7 @@ amd64_irq0: popq %r10 popq %r11 - swapgs_if_needed + iret_swapgs_if_needed iretq amd64_irq2_counting: diff --git a/arch/amd64/hw/irqs_s.S b/arch/amd64/hw/irqs_s.S index d3e7a33..1387450 100644 --- a/arch/amd64/hw/irqs_s.S +++ b/arch/amd64/hw/irqs_s.S @@ -50,7 +50,7 @@ amd64_idt_load: .global amd64_irq_msi0 amd64_irq_msi0: cli - swapgs_if_needed + iret_swapgs_if_needed pushq %r11 pushq %r10 @@ -78,5 +78,5 @@ amd64_irq_msi0: popq %r10 popq %r11 - swapgs_if_needed + iret_swapgs_if_needed iretq diff --git a/arch/amd64/sched_s.S b/arch/amd64/sched_s.S index b9c73e7..10e0a75 100644 --- a/arch/amd64/sched_s.S +++ b/arch/amd64/sched_s.S @@ -14,7 +14,7 @@ context_enter: popq %r10 popq %r11 - swapgs_if_needed + iret_swapgs_if_needed iretq .global context_exec_enter @@ -53,7 +53,7 @@ context_exec_enter: xorq %r14, %r14 xorq %r15, %r15 - swapgs_if_needed + iret_swapgs_if_needed iretq .global context_switch_first diff --git a/etc/Kernel.makefile b/etc/Kernel.makefile index 6861d05..9fc9ba5 100644 --- a/etc/Kernel.makefile +++ b/etc/Kernel.makefile @@ -170,8 +170,7 @@ KERNEL_CFLAGS=-Iinclude \ -Wall \ -Wextra \ -Wno-unused \ - -O2 \ - -funroll-loops \ + -Og \ -ggdb \ -Werror $(KERNEL_DEF) KERNEL_LDFLAGS=-nostdlib \ diff --git a/include/arch/amd64/asm/asm_cpu.h b/include/arch/amd64/asm/asm_cpu.h index 761cf9e..d29376e 100644 --- a/include/arch/amd64/asm/asm_cpu.h +++ b/include/arch/amd64/asm/asm_cpu.h @@ -11,9 +11,9 @@ (__amd64_cpu + off)(%rip) #endif -// To be used in interrupt handlers +// To be used in interrupt handlers or anything with iret-like stack layout // DIRECTLY AFTER ENTRY without prior stack modification -.macro swapgs_if_needed +.macro iret_swapgs_if_needed cmpq $0x08, 0x08(%rsp) je 1f swapgs diff --git a/include/arch/amd64/asm/asm_irq.h b/include/arch/amd64/asm/asm_irq.h index 7773d64..e88e4e6 100644 --- a/include/arch/amd64/asm/asm_irq.h +++ b/include/arch/amd64/asm/asm_irq.h @@ -13,7 +13,7 @@ .global amd64_irq\n amd64_irq\n: cli - swapgs_if_needed + iret_swapgs_if_needed pushq %r11 pushq %r10 @@ -39,7 +39,7 @@ amd64_irq\n: popq %r10 popq %r11 - swapgs_if_needed + iret_swapgs_if_needed iretq .endm