[USER] TSS

This commit is contained in:
Thomas Lovén 2016-11-26 13:20:57 +01:00
parent 474914ab1e
commit f63afbb3b1
6 changed files with 42 additions and 19 deletions

View File

@ -1,4 +1,5 @@
#include <gdt.h>
#include <cpu.h>
#include <stdint.h>
#include <debug.h>
#include <cpu.h>
@ -10,16 +11,19 @@
void gdt_init()
{
cpu_t *cpu = get_cpu();
cpu->tss.io_mba = sizeof(tss_t);
GDT[0] = 0;
GDT[SEG_KCODE/8] = (uint64_t)(GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_EXECUTE | GDT_64BIT);
GDT[SEG_KDATA/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE);
GDT[SEG_UCODE/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_EXECUTE | GDT_64BIT | GDT_RING3);
GDT[SEG_UDATA/8] = (GDT_PRESENT | GDT_CODEDATA | GDT_WRITE | GDT_RING3);
GDT[SEG_TSS/8] = (GDT_PRESENT | GDT_TSS | TSS_BLO((uint64_t)&cpu->tss) | TSS_LIM(sizeof(tss_t)));
GDT[SEG_TSS/8 + 1] = (TSS_BHI((uint64_t)&cpu->tss));
GDTP.len = 5*8-1;
GDTP.len = 7*8-1;
GDTP.addr = (uint64_t)&GDT[0];
load_gdt(&GDTP);
load_tr(SEG_TSS);
}

View File

@ -1,3 +1,4 @@
#include <mem.h>
.intel_syntax noprefix
#include <gdt.h>
@ -41,3 +42,8 @@ load_gdt:
.load_gdt:
ret
.global load_tr
load_tr:
mov rax, rdi
ltr ax
ret

View File

@ -30,22 +30,9 @@ int kmain(uint64_t multiboot_magic, void *multiboot_data)
pit_init();
process_t *p1 = process_spawn(0);
thread_t *t1 = new_thread(thread_function);
process_attach(p1, t1);
scheduler_insert(t1);
t1 = new_thread(thread_function);
process_attach(p1, t1);
scheduler_insert(t1);
t1 = new_thread(thread_function);
process_attach(p1, t1);
scheduler_insert(t1);
t1 = new_thread(thread_function);
process_attach(p1, t1);
scheduler_insert(t1);
t1 = new_thread(thread_function);
process_attach(p1, t1);
scheduler_insert(t1);
asm("sti");

View File

@ -62,9 +62,8 @@ void cpu_init()
all_ap_started = 1;
vmm_set_page(0, TRAMPOLINE_ADDR, 0, 0);
// Keep the GDT mapped for now
/* vmm_set_page(0, TRAMPOLINE_GDT, 0, 0); */
/* pmm_free(page); */
vmm_set_page(0, TRAMPOLINE_GDT, 0, 0);
pmm_free(page);
debug_info("CPU - Status\n");
for(unsigned int i = 0; i < num_cpu; i++)

View File

@ -34,9 +34,10 @@ typedef struct cpu_t
thread_t *current_thread;
thread_t *last_thread;
process_t *current_process;
uint64_t gdt[5];
uint64_t gdt[7];
struct gdtp_st gdt_p;
thread_t *scheduler;
tss_t tss;
}__attribute__((packed)) cpu_t;
extern cpu_t cpus[];

View File

@ -4,6 +4,7 @@
#define SEG_KDATA 0x10
#define SEG_UDATA 0x18
#define SEG_UCODE 0x20
#define SEG_TSS 0x28
#ifdef __ASSEMBLER__
#define GDT_WRITE (1<<41)
@ -20,6 +21,10 @@
#define GDT_RING3 (3LL<<45)
#define GDT_TSS (9LL<<40)
#define TSS_BLO(base) ((((base)&0xFFFF)<<16) | ((((base)>>16)&0xFF)<<32) | ((((base)>>24)&0xFF)<<56))
#define TSS_BHI(base) (((base)>>32)&0xFFFFFFFF)
#define TSS_LIM(lim) (((lim)&0xFFFF) | ((((lim)>>16)&0xF)<<48))
#include <stdint.h>
extern uint64_t BootGDT;
@ -32,6 +37,27 @@ struct gdtp_st
uint32_t pad2;
}__attribute__((packed));
typedef struct
{
uint32_t r1;
uint64_t rsp0;
uint64_t rsp1;
uint64_t rsp2;
uint64_t r2;
uint64_t ist1;
uint64_t ist2;
uint64_t ist3;
uint64_t ist4;
uint64_t ist5;
uint64_t ist6;
uint64_t ist7;
uint64_t r3;
uint16_t r4;
uint16_t io_mba;
}__attribute__((packed)) tss_t;
void load_gdt(struct gdtp_st *);
void gdt_init();
void load_tr(uint32_t segment);
#endif