gdt: add TSS entries for application processors
This commit is contained in:
parent
b1c7737d0e
commit
c2daea8b18
4 changed files with 60 additions and 9 deletions
37
init/gdt.c
37
init/gdt.c
|
|
@ -6,9 +6,13 @@
|
|||
|
||||
void gdt_load();
|
||||
|
||||
void gdt_insert(uint16_t offset, uint8_t access, uint8_t flags)
|
||||
static int gdt_index = 0;
|
||||
|
||||
spinlock_t gdt_lock = 0;
|
||||
|
||||
void gdt_insert(uint8_t access, uint8_t flags)
|
||||
{
|
||||
struct gdt_desc *desc = (__gdt + offset);
|
||||
struct gdt_desc *desc = (__gdt + gdt_index++);
|
||||
desc->limit = 0;
|
||||
desc->base = 0;
|
||||
desc->base_2 = 0;
|
||||
|
|
@ -18,15 +22,30 @@ void gdt_insert(uint16_t offset, uint8_t access, uint8_t flags)
|
|||
desc->flags = flags;
|
||||
}
|
||||
|
||||
uint16_t gdt_insert_tss(uintptr_t rsp0)
|
||||
{
|
||||
spinlock_acquire(&gdt_lock);
|
||||
struct gdt_desc_tss *tss = (struct gdt_desc_tss *)((struct gdt_desc *)__gdt + gdt_index);
|
||||
|
||||
memset(tss, 0, sizeof(*tss));
|
||||
tss->rsp0 = rsp0;
|
||||
|
||||
gdt_index += 2;
|
||||
|
||||
spinlock_release(&gdt_lock);
|
||||
/* return the index of the TSS descriptor */
|
||||
return (gdt_index - 2) * sizeof(struct gdt_desc);
|
||||
}
|
||||
|
||||
void gdt_init()
|
||||
{
|
||||
gdt_insert(0, 0, 0);
|
||||
gdt_insert(1, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(2, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(3, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(4, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(5, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(6, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(0, 0);
|
||||
gdt_insert(GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
|
||||
__gdtr.size = (sizeof(__gdt) - 1);
|
||||
__gdtr.offset = (uint64_t)__gdt;
|
||||
|
|
|
|||
Loading…
Reference in a new issue