proc: fix errors, enter userspace
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
b279d0a06a
commit
c7fa9a75fa
15 changed files with 86 additions and 8 deletions
34
amd64/gdt.c
34
amd64/gdt.c
|
|
@ -1,9 +1,14 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <arch/proc.h>
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
#include "descriptor.h"
|
||||
#include "arch/reg.h"
|
||||
|
||||
#define TSS_STACK_SIZE 0x4000
|
||||
|
||||
static size_t gdt_index = 0;
|
||||
|
||||
void gdt_insert(uint8_t offset, uint8_t access, uint8_t flags)
|
||||
|
|
@ -38,3 +43,32 @@ void gdt_init()
|
|||
|
||||
krdy("GDT initialized\n");
|
||||
}
|
||||
|
||||
void tss_init(int cpu_id, struct cpu_local *local)
|
||||
{
|
||||
int gdt_idx = 9 + cpu_id * 2;
|
||||
uint16_t sel = gdt_idx * 8;
|
||||
|
||||
char *tss_stack = kalloc(TSS_STACK_SIZE, ALLOC_KERN);
|
||||
if (!tss_stack)
|
||||
panic("failed to alloc tss stack for cpu %d\n", cpu_id);
|
||||
|
||||
struct tss *tss = &local->tss;
|
||||
|
||||
memset(tss, 0, sizeof(*tss));
|
||||
tss->rsp0 = (u64)tss_stack + TSS_STACK_SIZE;
|
||||
|
||||
uint64_t addr = (uint64_t)tss;
|
||||
struct gdt_desc_sys *desc = (struct gdt_desc_sys *)&__gdt[gdt_idx];
|
||||
|
||||
desc->limit = sizeof(struct tss) - 1;
|
||||
desc->base = addr & 0xFFFF;
|
||||
desc->base_2 = (addr >> 16) & 0xFF;
|
||||
desc->base_3 = (addr >> 24) & 0xFF;
|
||||
desc->base_4 = addr >> 32;
|
||||
desc->access = 0x89;
|
||||
desc->flags = 0x00;
|
||||
desc->reserved = 0;
|
||||
|
||||
ltr(sel);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue