diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-13 21:52:48 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-13 21:52:48 +0100 |
commit | 47e6cd42f0744f6c04b8347093f6549339a856c9 (patch) | |
tree | c91fc43178d136c2aa0f093087ba8cfb4e90bdae /src/kernel/core/gdt.c | |
parent | cf0b8a52287ee7c747b1d5a7d77abdef1fb46f94 (diff) | |
download | kogata-47e6cd42f0744f6c04b8347093f6549339a856c9.tar.gz kogata-47e6cd42f0744f6c04b8347093f6549339a856c9.zip |
Implement ELF loading ; arrange so that user processes run.
Diffstat (limited to 'src/kernel/core/gdt.c')
-rw-r--r-- | src/kernel/core/gdt.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/kernel/core/gdt.c b/src/kernel/core/gdt.c index 97e6661..ed7abe0 100644 --- a/src/kernel/core/gdt.c +++ b/src/kernel/core/gdt.c @@ -4,27 +4,25 @@ #define GDT_ENTRIES 6 // The contents of each entry is defined in gdt_init. /* One entry of the table */ -struct gdt_entry { +typedef struct { uint16_t limit_low; uint16_t base_low; uint8_t base_middle; uint8_t access; uint8_t granularity; uint8_t base_high; -} __attribute__((packed)); -typedef struct gdt_entry gdt_entry_t; +} __attribute__((packed)) gdt_entry_t; /* Structure defining the whole table : address and size (in bytes). */ -struct gdt_ptr { +typedef struct { uint16_t limit; uint32_t base; -} __attribute__((packed)); -typedef struct gdt_ptr gdt_ptr_t; +} __attribute__((packed)) gdt_ptr_t; /* The TSS is used for hardware multitasking. We don't use that, but we still need a TSS so that user mode process exceptions can be handled correctly by the kernel. */ -struct tss_entry { +typedef struct { uint32_t prev_tss; // The previous TSS - if we used hardware task switching this would form a linked list. uint32_t esp0; // The stack pointer to load when we change to kernel mode. uint32_t ss0; // The stack segment to load when we change to kernel mode. @@ -52,8 +50,7 @@ struct tss_entry { uint32_t ldt; // Unused... uint16_t trap; uint16_t iomap_base; -} __attribute__((packed)); -typedef struct tss_entry tss_entry_t; +} __attribute__((packed)) tss_entry_t; // ========================= // // Actual definitions @@ -86,13 +83,11 @@ void gdt_init() { gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); //User data segment 0x20 // Write TSS - memset(&tss_entry, 0, sizeof(tss_entry)); + memset(&tss_entry, 0, sizeof(tss_entry_t)); tss_entry.ss0 = 0x10; tss_entry.esp0 = 0; - - tss_entry.cs = 0x0b; - tss_entry.ss = tss_entry.ds = tss_entry.es = tss_entry.fs = tss_entry.gs = 0x13; + tss_entry.iomap_base = sizeof(tss_entry_t); uint32_t tss_base = (uint32_t)&tss_entry; uint32_t tss_limit = tss_base + sizeof(tss_entry_t); |