From 6d5dbb5ff23bf64ac4ea99e11adbde5583be522c Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 29 Feb 2024 11:15:35 -0500 Subject: kernel/amd64: tss: Allocate stack for RSP0 Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/tss.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sys/arch') diff --git a/sys/arch/amd64/amd64/tss.c b/sys/arch/amd64/amd64/tss.c index 8bd7deb..aefc1f2 100644 --- a/sys/arch/amd64/amd64/tss.c +++ b/sys/arch/amd64/amd64/tss.c @@ -43,6 +43,9 @@ static void alloc_resources(struct cpu_info *cpu) { struct tss_entry *tss; + const size_t STACK_SIZE = 0x1000; + static uintptr_t rsp0_base = 0, rsp0 = 0; + /* * Allocate TSS entries for this CPU @@ -50,9 +53,19 @@ alloc_resources(struct cpu_info *cpu) if (cpu->tss == NULL) { /* Allocate a TSS for this CPU */ tss = dynalloc(sizeof(*tss)); + if (tss == NULL) panic("Failed to alloc %d bytes for TSS\n", sizeof(*tss)); + memset(tss, 0, sizeof(*tss)); + rsp0_base = (uintptr_t)dynalloc(STACK_SIZE); + + if (rsp0_base == 0) + panic("Could not allocate rsp0 base\n"); + + rsp0 = rsp0_base + STACK_SIZE; + tss->rsp0_lo = __SHIFTOUT(rsp0, __MASK(32)); + tss->rsp0_hi = __SHIFTOUT(rsp0, __MASK(32) << 32); cpu->tss = tss; } } -- cgit v1.2.3