summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2022-05-29 21:21:46 +0200
committerdzwdz2022-05-29 21:21:46 +0200
commitc3e611ecf1e0f6ac5790e56bb0b21d30f5253d15 (patch)
treee47b9d9ba7489c7510498895620217c9e6514e5b /src
parenta6ed7a20a823e67c19b93309706c57ddee1933c6 (diff)
kernel: fix overlapping interrupt / regular stacks
Diffstat (limited to 'src')
-rw-r--r--src/kernel/arch/i386/boot.s2
-rw-r--r--src/kernel/arch/i386/gdt/gdt.c4
-rw-r--r--src/kernel/arch/i386/interrupts/isr_stub.s9
-rw-r--r--src/kernel/linker.ld5
4 files changed, 11 insertions, 9 deletions
diff --git a/src/kernel/arch/i386/boot.s b/src/kernel/arch/i386/boot.s
index 24c076f..743c6d6 100644
--- a/src/kernel/arch/i386/boot.s
+++ b/src/kernel/arch/i386/boot.s
@@ -2,7 +2,7 @@
.global _start
.type _start, @function
_start:
- mov $_bss_end, %esp // the stack is at the top of bss
+ mov $_stack_top, %esp
call sysenter_setup
push %ebx // address of the Multiboot struct
call kmain_early
diff --git a/src/kernel/arch/i386/gdt/gdt.c b/src/kernel/arch/i386/gdt/gdt.c
index f016caa..3662bf6 100644
--- a/src/kernel/arch/i386/gdt/gdt.c
+++ b/src/kernel/arch/i386/gdt/gdt.c
@@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stdint.h>
-extern char _isr_stack_top;
+extern char _isr_mini_stack;
struct gdt_entry {
uint64_t limit_low : 16;
@@ -83,7 +83,7 @@ static void gdt_prepare(void) {
// tss
memset(&TSS, 0, sizeof(TSS));
TSS.ss0 = SEG_r0data << 3; // kernel data segment
- TSS.esp0 = (uintptr_t) &_isr_stack_top;
+ TSS.esp0 = (uintptr_t) &_isr_mini_stack;
GDT[SEG_TSS] = (struct gdt_entry) {
.limit_low = sizeof(TSS),
diff --git a/src/kernel/arch/i386/interrupts/isr_stub.s b/src/kernel/arch/i386/interrupts/isr_stub.s
index 9a903f6..c09d4b2 100644
--- a/src/kernel/arch/i386/interrupts/isr_stub.s
+++ b/src/kernel/arch/i386/interrupts/isr_stub.s
@@ -23,11 +23,11 @@ _isr_stage2:
mov %ebx, %cr0
mov %esp, %ebp
- mov $_bss_end, %esp // switch to kernel stack
+ mov $_isr_big_stack, %esp
push %eax // push the vector nr
call isr_stage3
- mov %ebp, %esp // switch back to isr_stack
+ mov %ebp, %esp
pop %eax // restore old cr0
mov %eax, %cr0
@@ -35,8 +35,7 @@ _isr_stage2:
iret
.align 8
-_ist_stack_btm:
// TODO overflow check
.skip 64 // seems to be enough
-.global _isr_stack_top
-_isr_stack_top:
+.global _isr_mini_stack
+_isr_mini_stack:
diff --git a/src/kernel/linker.ld b/src/kernel/linker.ld
index 84945b1..371f2d7 100644
--- a/src/kernel/linker.ld
+++ b/src/kernel/linker.ld
@@ -30,8 +30,11 @@ SECTIONS
*(COMMON)
*(.bss)
- _stack_bottom = .;
. += 16K;
+ _isr_big_stack = .;
+
+ . += 16K;
+ _stack_top = .;
}
_bss_end = (. + 0xFFF) & ~0xFFF; /* aligned to 4K */
}