Setting up a host TSS
This commit is contained in:
parent
e1ba08bbc0
commit
af84732da1
4 changed files with 37 additions and 9 deletions
|
|
@ -21,6 +21,25 @@ struct GDTR {
|
||||||
uint64_t base;
|
uint64_t base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__attribute__ ((packed))
|
||||||
|
struct TSS {
|
||||||
|
uint32_t reserved0;
|
||||||
|
uint64_t rsp0;
|
||||||
|
uint64_t rsp1;
|
||||||
|
uint64_t rsp2;
|
||||||
|
uint64_t reserved1;
|
||||||
|
uint64_t ist1;
|
||||||
|
uint64_t ist2;
|
||||||
|
uint64_t ist3;
|
||||||
|
uint64_t ist4;
|
||||||
|
uint64_t ist5;
|
||||||
|
uint64_t ist6;
|
||||||
|
uint64_t ist7;
|
||||||
|
uint64_t reserved2;
|
||||||
|
uint16_t reserved3;
|
||||||
|
uint16_t iopb;
|
||||||
|
};
|
||||||
|
|
||||||
static inline struct GDTR
|
static inline struct GDTR
|
||||||
storegdt(void)
|
storegdt(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
21
src/proc.c
21
src/proc.c
|
|
@ -3,18 +3,21 @@
|
||||||
#include "procvisor.h"
|
#include "procvisor.h"
|
||||||
#include "bootstrap.h"
|
#include "bootstrap.h"
|
||||||
|
|
||||||
#define GDT_SIZE ( 3 * sizeof (struct segdescr))
|
#define GDT_SIZE ( 5 * sizeof (struct segdescr))
|
||||||
#define IDT_SIZE (256 * sizeof (struct intdescr))
|
#define IDT_SIZE (256 * sizeof (struct intdescr))
|
||||||
|
#define TSS_SIZE (sizeof (struct TSS))
|
||||||
|
|
||||||
struct procvisor *procvisors[256];
|
struct procvisor *procvisors[256];
|
||||||
|
|
||||||
static void
|
static void
|
||||||
proc_fill_host_gdt(struct GDTR gdtr)
|
proc_fill_host_gdt(struct GDTR gdtr, struct TSS *tss)
|
||||||
{
|
{
|
||||||
struct segdescr *descrs = (void *)gdtr.base;
|
struct segdescr *descrs = (void *)gdtr.base;
|
||||||
setsegdescr(&descrs[0], 0, 0, 0, 0); // null
|
setsegdescr(&descrs[0], 0, 0, 0, 0); // null
|
||||||
setsegdescr(&descrs[1], 0, 0xffffff, 0x9B, 0xA0); // code
|
setsegdescr(&descrs[1], 0, 0xffffff, 0x9B, 0xA0); // code
|
||||||
setsegdescr(&descrs[2], 0, 0xffffff, 0x93, 0xC0); // data
|
setsegdescr(&descrs[2], 0, 0xffffff, 0x93, 0xC0); // data
|
||||||
|
setsegdescr(&descrs[3], (uintptr_t)tss, TSS_SIZE - 1, 0x89, 0x00); // TSS
|
||||||
|
*(uint64_t *)(&descrs[4]) = (uintptr_t)tss >> 32;// TSS (continued)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -37,22 +40,26 @@ proc_setup(void)
|
||||||
top -= sizeof (struct procvisor);
|
top -= sizeof (struct procvisor);
|
||||||
struct procvisor *pv = (void *)top;
|
struct procvisor *pv = (void *)top;
|
||||||
|
|
||||||
|
// Carve out IDT
|
||||||
|
top -= IDT_SIZE;
|
||||||
|
pv->host_idtr.base = (uintptr_t)top;
|
||||||
|
pv->host_idtr.limit = IDT_SIZE - 1;
|
||||||
|
|
||||||
// Carve out GDT
|
// Carve out GDT
|
||||||
top -= GDT_SIZE;
|
top -= GDT_SIZE;
|
||||||
pv->host_gdtr.base = (uintptr_t)top;
|
pv->host_gdtr.base = (uintptr_t)top;
|
||||||
pv->host_gdtr.limit = GDT_SIZE - 1;
|
pv->host_gdtr.limit = GDT_SIZE - 1;
|
||||||
|
|
||||||
// Carve out IDT
|
// Carve out TSS
|
||||||
top -= IDT_SIZE;
|
top -= TSS_SIZE;
|
||||||
pv->host_idtr.base = (uintptr_t)top;
|
pv->host_tss = (void *)top;
|
||||||
pv->host_idtr.limit = IDT_SIZE - 1;
|
|
||||||
|
|
||||||
// Leave the rest as stack
|
// Leave the rest as stack
|
||||||
top -= ((uintptr_t)top & 0xf); // align on 16-byte boundary
|
top -= ((uintptr_t)top & 0xf); // align on 16-byte boundary
|
||||||
pv->host_stack = top;
|
pv->host_stack = top;
|
||||||
|
|
||||||
// Fill out GDT & IDT structures
|
// Fill out GDT & IDT structures
|
||||||
proc_fill_host_gdt(pv->host_gdtr);
|
proc_fill_host_gdt(pv->host_gdtr, pv->host_tss);
|
||||||
proc_fill_host_idt(pv->host_idtr);
|
proc_fill_host_idt(pv->host_idtr);
|
||||||
|
|
||||||
// Register procvisor & return
|
// Register procvisor & return
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,10 @@
|
||||||
|
|
||||||
/* Per-processor visor state and structures */
|
/* Per-processor visor state and structures */
|
||||||
struct procvisor {
|
struct procvisor {
|
||||||
void *host_stack;
|
|
||||||
struct GDTR host_gdtr;
|
|
||||||
struct IDTR host_idtr;
|
struct IDTR host_idtr;
|
||||||
|
struct GDTR host_gdtr;
|
||||||
|
struct TSS *host_tss;
|
||||||
|
void *host_stack;
|
||||||
//void *host_cr3;
|
//void *host_cr3;
|
||||||
//void *vmctl;
|
//void *vmctl;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ vintel_init_host(void)
|
||||||
vmwrite(HOST_DS_SELECTOR, 0x10);
|
vmwrite(HOST_DS_SELECTOR, 0x10);
|
||||||
vmwrite(HOST_FS_SELECTOR, 0x00);
|
vmwrite(HOST_FS_SELECTOR, 0x00);
|
||||||
vmwrite(HOST_GS_SELECTOR, 0x00);
|
vmwrite(HOST_GS_SELECTOR, 0x00);
|
||||||
|
vmwrite(HOST_TR_SELECTOR, 0x18);
|
||||||
|
|
||||||
// Set control registers
|
// Set control registers
|
||||||
vmwrite(HOST_CR0, readcr0());
|
vmwrite(HOST_CR0, readcr0());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue