all kernel headers have been moved from include/mango to include/kernel and include definitions that are only relevant to kernel-space. any definitions that are relevant to both kernel- and user-space (i.e. type definitions, syscall IDs) have been moved to include/mango within libmango.
49 lines
842 B
C
49 lines
842 B
C
#include "arch/msr.h"
|
|
|
|
#include <arch/gdt.h>
|
|
#include <arch/tss.h>
|
|
#include <kernel/libc/string.h>
|
|
|
|
static void tss_flush(int index)
|
|
{
|
|
index *= sizeof(struct gdt_entry);
|
|
index |= 3;
|
|
asm volatile("mov %0, %%eax; ltr %%ax" ::"r"(index));
|
|
}
|
|
|
|
void tss_init(struct tss *tss, struct tss_ptr *ptr)
|
|
{
|
|
memset(tss, 0x0, sizeof *tss);
|
|
|
|
ptr->tss_base = (uint64_t)tss;
|
|
ptr->tss_limit = (uint16_t)sizeof *tss;
|
|
}
|
|
|
|
void tss_load(struct tss *tss)
|
|
{
|
|
tss_flush(TSS_GDT_INDEX);
|
|
|
|
uintptr_t kernel_gs_base_reg = 0xC0000102;
|
|
wrmsr(kernel_gs_base_reg, (uintptr_t)tss);
|
|
}
|
|
|
|
virt_addr_t tss_get_kstack(struct tss *tss)
|
|
{
|
|
return tss->rsp0;
|
|
}
|
|
|
|
virt_addr_t tss_get_ustack(struct tss *tss)
|
|
{
|
|
return tss->rsp2;
|
|
}
|
|
|
|
void tss_set_kstack(struct tss *tss, virt_addr_t sp)
|
|
{
|
|
tss->rsp0 = sp;
|
|
}
|
|
|
|
void tss_set_ustack(struct tss *tss, virt_addr_t sp)
|
|
{
|
|
tss->rsp2 = sp;
|
|
}
|