feat(gdt): add gdt kernel entries creation
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
e862a4185b
commit
a5ff8a6a92
53
k/gdt.c
53
k/gdt.c
@ -4,10 +4,58 @@ static struct gdt gdt = { 0 };
|
||||
|
||||
static void create_kernel_ds()
|
||||
{
|
||||
struct gdt_entry *entry = gdt.entries + KERNEL_DS_INDEX;
|
||||
|
||||
uint32_t limit = 0xffff;
|
||||
uint32_t base = 0x0;
|
||||
|
||||
entry->granularity = 1;
|
||||
entry->db = 1;
|
||||
entry->l = 0;
|
||||
entry->available = 0;
|
||||
|
||||
entry->present = 1;
|
||||
entry->desc_priv = 0;
|
||||
entry->desc_type = 1;
|
||||
entry->ex = 0;
|
||||
entry->dc = 0;
|
||||
entry->rw = 1;
|
||||
entry->accessed = 0;
|
||||
|
||||
entry->limit_1 = limit & 0xffff;
|
||||
entry->limit_2 = (limit >> 16) & 0xf;
|
||||
|
||||
entry->base_1 = base & 0xffff;
|
||||
entry->base_2 = (base >> 16) & 0xff;
|
||||
entry->base_3 = (base >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static void create_kernel_cs()
|
||||
{
|
||||
struct gdt_entry *entry = gdt.entries + KERNEL_CS_INDEX;
|
||||
|
||||
uint32_t limit = 0xffff;
|
||||
uint32_t base = 0x0;
|
||||
|
||||
entry->granularity = 1;
|
||||
entry->db = 1;
|
||||
entry->l = 0;
|
||||
entry->available = 0;
|
||||
|
||||
entry->present = 1;
|
||||
entry->desc_priv = 0;
|
||||
entry->desc_type = 1;
|
||||
entry->ex = 1;
|
||||
entry->dc = 0;
|
||||
entry->rw = 1;
|
||||
entry->accessed = 0;
|
||||
|
||||
entry->limit_1 = limit & 0xffff;
|
||||
entry->limit_2 = (limit >> 16) & 0xf;
|
||||
|
||||
entry->base_1 = base & 0xffff;
|
||||
entry->base_2 = (base >> 16) & 0xff;
|
||||
entry->base_3 = (base >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static void create_gdt()
|
||||
@ -62,13 +110,18 @@ static void load_cs()
|
||||
|
||||
static void reload_segment_selectors()
|
||||
{
|
||||
printf("Before load_ds\r\n");
|
||||
load_ds();
|
||||
load_cs();
|
||||
}
|
||||
|
||||
void init_gdt()
|
||||
{
|
||||
printf("Before create_gdt\r\n");
|
||||
create_gdt();
|
||||
printf("Before load_gdt\r\n");
|
||||
load_gdt();
|
||||
printf("Before reload_segment_selectors\r\n");
|
||||
reload_segment_selectors();
|
||||
printf("All good\r\n");
|
||||
}
|
||||
|
5
k/gdt.h
5
k/gdt.h
@ -14,7 +14,10 @@ struct gdt_entry
|
||||
uint16_t limit_1 : 16;
|
||||
uint16_t base_1 : 16;
|
||||
uint8_t base_2 : 8;
|
||||
uint8_t seg_type : 4;
|
||||
uint8_t accessed : 1;
|
||||
uint8_t rw : 1;
|
||||
uint8_t dc : 1;
|
||||
uint8_t ex : 1;
|
||||
uint8_t desc_type : 1;
|
||||
uint8_t desc_priv : 2;
|
||||
uint8_t present : 1;
|
||||
|
1
k/k.c
1
k/k.c
@ -30,6 +30,7 @@
|
||||
static void k_init(void)
|
||||
{
|
||||
init_serial();
|
||||
init_gdt();
|
||||
}
|
||||
|
||||
void k_main(unsigned long magic, multiboot_info_t *info)
|
||||
|
Loading…
Reference in New Issue
Block a user