feat: gestion TSS/TSR en cours

This commit is contained in:
Nicolas Hordé 2018-09-18 15:11:50 +02:00
parent a12ddfa03b
commit 87956a41a3
5 changed files with 59 additions and 16 deletions

View File

@ -36,6 +36,8 @@
#define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) ) #define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) )
#define ltr(tss) asm volatile ("ltr %%ax":: "a" (tss))
/******************************************************************************/ /******************************************************************************/
#define outb(port,value) \ #define outb(port,value) \

View File

@ -8,12 +8,13 @@
#define SEL_KERNEL_DATA 0x28 /* selecteur data du kernel */ #define SEL_KERNEL_DATA 0x28 /* selecteur data du kernel */
#define SEL_USER_DATA 0x30 /* selecteur data utilisateur */ #define SEL_USER_DATA 0x30 /* selecteur data utilisateur */
#define SEL_TSS 0x38 /* selecteur TSR */
#define STACK_OFFSET 0xFFFF /* adresse de la pile du kernel */ #define STACK_OFFSET 0xFFFF /* adresse de la pile du kernel */
#define SIZEGDT 0x7 /* nombre de descripteurs */ #define SIZEGDT 0x8 /* nombre de descripteurs */
#define BASEGDT 0x00000800 /* addr de la GDT */ #define BASEGDT 0x00000800 /* addr de la GDT */
typedef struct gdtdes { typedef struct gdtdes {
u16 lim0_15; u16 lim0_15;
u16 base0_15; u16 base0_15;
@ -29,22 +30,26 @@ struct gdtr {
u32 base; u32 base;
} __attribute__ ((packed)); } __attribute__ ((packed));
struct tss { typedef struct tss {
u16 previous_task, __previous_task_unused; u16 prevtask, reserved00;
u32 esp0; u32 esp0;
u16 ss0, __ss0_unused; u16 ss0, reserved0;
u32 esp1; u32 esp1;
u16 ss1, __ss1_unused; u16 ss1, reserved1;
u32 esp2; u32 esp2;
u16 ss2, __ss2_unused; u16 ss2, reserved2;
u32 cr3; u32 cr3;
u32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi; u32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
u16 es, __es_unused; u16 es, reserved3;
u16 cs, __cs_unused; u16 cs, reserved4;
u16 ss, __ss_unused; u16 ss, reserved5;
u16 ds, __ds_unused; u16 ds, reserved6;
u16 fs, __fs_unused; u16 fs, reserved7;
u16 gs, __gs_unused; u16 gs, reserved8;
u16 ldt_selector, __ldt_sel_unused; u16 ldt_selector, reserved9;
u16 debug_flag, io_map; u16 trapflag, iomap;
} __attribute__ ((packed)); } __attribute__ ((packed));
void inittr(void);
void initgdt(u32 offset);
void makegdtdes(u32 base, u32 limite, u8 acces, u8 flags, gdtdes *desc);

View File

@ -9,13 +9,16 @@ static struct gdtr gdtreg;
/* table de GDT */ /* table de GDT */
static gdtdes gdt[SIZEGDT]; static gdtdes gdt[SIZEGDT];
/* TSS */
static struct tss tss0;
/*******************************************************************************/ /*******************************************************************************/
/* Initialise la GDT */ /* Initialise la GDT */
void initgdt(u32 offset) void initgdt(u32 offset)
{ {
makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* selecteur nul */ makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* descripteur nul */
makegdtdes(0x0, 0xFFFFF, 0x9B, 0x0D, &gdt[1]); /* code -> SEL_KERNEL_CODE */ makegdtdes(0x0, 0xFFFFF, 0x9B, 0x0D, &gdt[1]); /* code -> SEL_KERNEL_CODE */
makegdtdes(0x0, 0x00000, 0x97, 0x0D, &gdt[2]); /* pile -> SEL_KERNEL_STACK */ makegdtdes(0x0, 0x00000, 0x97, 0x0D, &gdt[2]); /* pile -> SEL_KERNEL_STACK */
makegdtdes(0x0, 0xFFFFF, 0xFF, 0x0D, &gdt[3]); /* code -> SEL_USER_CODE */ makegdtdes(0x0, 0xFFFFF, 0xFF, 0x0D, &gdt[3]); /* code -> SEL_USER_CODE */
@ -23,6 +26,13 @@ void initgdt(u32 offset)
makegdtdes(0x0, 0xFFFFF, 0x93, 0x0D, &gdt[5]); /* data -> SEL_KERNEL_DATA */ makegdtdes(0x0, 0xFFFFF, 0x93, 0x0D, &gdt[5]); /* data -> SEL_KERNEL_DATA */
makegdtdes(0x0, 0xFFFFF, 0xF3, 0x0D, &gdt[6]); /* data -> SEL_USER_DATA */ makegdtdes(0x0, 0xFFFFF, 0xF3, 0x0D, &gdt[6]); /* data -> SEL_USER_DATA */
tss0.trapflag = 0x00;
tss0.iomap = 0x00;
tss0.esp0 = 0x1FFF0;
tss0.ss0 = SEL_TSS;
makegdtdes(&tss0, 0x67, 0xE9, 0x00, &gdt[7]); /* descripteur de tss */
/* initialise le registre gdt */ /* initialise le registre gdt */
gdtreg.limite = SIZEGDT * 8; gdtreg.limite = SIZEGDT * 8;
gdtreg.base = BASEGDT; gdtreg.base = BASEGDT;
@ -36,6 +46,15 @@ void initgdt(u32 offset)
/*******************************************************************************/ /*******************************************************************************/
/* Initialise le registre de tâche (TSR) */
void inittr(void)
{
ltr(SEL_TSS);
}
/*******************************************************************************/
/* Initialise les selecteurs avec la GDT */ /* Initialise les selecteurs avec la GDT */
void initselectors(u32 executingoffset) void initselectors(u32 executingoffset)

View File

@ -2,6 +2,19 @@
#include <gdt.h> #include <gdt.h>
#include <asm.h> #include <asm.h>
/* 32bit SYSENTER instruction entry.
*
* Arguments:
* %eax System call number.
* %ebx Arg1
* %ecx Arg2
* %edx Arg3
* %esi Arg4
* %edi Arg5
* %ebp user stack
* 0(%ebp) Arg6*/
/*******************************************************************************/ /*******************************************************************************/
/* Entrée pour les appels système SYSENTER */ /* Entrée pour les appels système SYSENTER */

View File

@ -56,6 +56,10 @@ int main(void)
next: next:
ok(); ok();
print("\033[37m\033[0m -Initilisation des taches (TSR)\000");
inittr();
ok();
print("\033[37m\033[0m -Initilisation des interruptions (IDT/PIC)\000"); print("\033[37m\033[0m -Initilisation des interruptions (IDT/PIC)\000");
initidt(); initidt();
initpic(); initpic();