From bb36ab3656c9d43e5206a4b0a86a7de7b0c4f684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 5 Apr 2018 10:23:23 +0200 Subject: [PATCH] Load the TSS. --- src/kernel/arch/x86/gdt.c | 7 +++++++ src/kernel/arch/x86/gdt.h | 1 + src/kernel/arch/x86/gdt.s | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/kernel/arch/x86/gdt.c b/src/kernel/arch/x86/gdt.c index 1914df1..129c20e 100644 --- a/src/kernel/arch/x86/gdt.c +++ b/src/kernel/arch/x86/gdt.c @@ -58,9 +58,16 @@ void gdt_install() { // user gdt_entry_set(&gdt[3], 0, 0xFFFFFFFF, 0xFA, 0xCF); gdt_entry_set(&gdt[4], 0, 0xFFFFFFFF, 0xF2, 0xCF); + // TSS + tss.ss0 = 0x10; + // TODO: set esp0 for system interrupts + tss.iopb = sizeof(tss); gdt_entry_set(&gdt[5], (uint32_t)&tss, sizeof(tss), 0x89, 0x40); gdt_flush(&gdtr); + + // load the TSS + tss_load(); } diff --git a/src/kernel/arch/x86/gdt.h b/src/kernel/arch/x86/gdt.h index 3581e45..63a33a5 100644 --- a/src/kernel/arch/x86/gdt.h +++ b/src/kernel/arch/x86/gdt.h @@ -21,6 +21,7 @@ #include "structs.h" extern void gdt_flush(struct segreg *gdtr); +extern void tss_load(); void gdt_entry_set(struct segdesc *entry, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran); void gdt_install(); diff --git a/src/kernel/arch/x86/gdt.s b/src/kernel/arch/x86/gdt.s index 85d9acf..f036c72 100644 --- a/src/kernel/arch/x86/gdt.s +++ b/src/kernel/arch/x86/gdt.s @@ -35,3 +35,13 @@ gdt_flush: gdt_flush_end: popl %ebp ret + +.global tss_load +.type tss_load,@function +tss_load: + pushl %ebp + movl %esp, %ebp + movw $0x28, %ax + ltr %ax + popl %ebp + ret