diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-01 17:24:38 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-01 17:24:38 +0100 |
commit | 0921a33fc9f3724cb36a03a24b58b0a5bfc519b1 (patch) | |
tree | 6f3db52ba8c38928749806cb2d94ca548b3b19bd /kernel/include | |
parent | 6f11c9e5c15cc8ef936741e5ee7575b731a47e0f (diff) | |
download | kogata-0921a33fc9f3724cb36a03a24b58b0a5bfc519b1.tar.gz kogata-0921a33fc9f3724cb36a03a24b58b0a5bfc519b1.zip |
Advance HH, GDT, IDT (details below)
- Implement higher-half in loader with paging (using 4Mb pages)
- Add GDT installation code
- Add IDT installation code (spend a loong time debugging the ISRs!)
- Add CDROM generation scripts
- Add scripts to launch bochs (debug) and qemu (debug)
Diffstat (limited to 'kernel/include')
-rw-r--r-- | kernel/include/dbglog.h | 2 | ||||
-rw-r--r-- | kernel/include/gdt.h | 64 | ||||
-rw-r--r-- | kernel/include/idt.h | 40 | ||||
-rw-r--r-- | kernel/include/multiboot.h | 1 | ||||
-rw-r--r-- | kernel/include/printf.h | 1 | ||||
-rw-r--r-- | kernel/include/string.h | 2 | ||||
-rw-r--r-- | kernel/include/sys.h | 5 |
7 files changed, 114 insertions, 1 deletions
diff --git a/kernel/include/dbglog.h b/kernel/include/dbglog.h index c8904c6..2f670e8 100644 --- a/kernel/include/dbglog.h +++ b/kernel/include/dbglog.h @@ -5,3 +5,5 @@ void dbglog_setup(); void dbg_print(const char* str); void dbg_printf(const char* format, ...); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/gdt.h b/kernel/include/gdt.h new file mode 100644 index 0000000..cd66676 --- /dev/null +++ b/kernel/include/gdt.h @@ -0,0 +1,64 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> + +/* The GDT is one of the x86's descriptor tables. It is used for memory segmentation. + Here, we don't use segmentation to separate processes from one another (this is done with paging). + We only use segmentation to make the difference between kernel mode (ring 3) and user mode (ring 0) */ + +/* One entry of the table */ +struct gdt_entry { + 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; + +/* Structure defining the whole table : address and size (in bytes). */ +struct gdt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); +typedef struct gdt_ptr 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 { + 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. + uint32_t esp1; // Unused... + uint32_t ss1; + uint32_t esp2; + uint32_t ss2; + uint32_t cr3; + uint32_t eip; + uint32_t eflags; + uint32_t eax; + uint32_t ecx; + uint32_t edx; + uint32_t ebx; + uint32_t esp; + uint32_t ebp; + uint32_t esi; + uint32_t edi; + uint32_t es; // The value to load into ES when we change to kernel mode. + uint32_t cs; // The value to load into CS when we change to kernel mode. + uint32_t ss; // The value to load into SS when we change to kernel mode. + uint32_t ds; // The value to load into DS when we change to kernel mode. + uint32_t fs; // The value to load into FS when we change to kernel mode. + uint32_t gs; // The value to load into GS when we change to kernel mode. + uint32_t ldt; // Unused... + uint16_t trap; + uint16_t iomap_base; +} __attribute__((packed)); +typedef struct tss_entry tss_entry_t; + +void gdt_init(); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/idt.h b/kernel/include/idt.h new file mode 100644 index 0000000..5730f5e --- /dev/null +++ b/kernel/include/idt.h @@ -0,0 +1,40 @@ +#pragma once + +/* The IDT is the system descriptor table that tells the CPU what to do when an interrupt fires. + There are three categories of interrupts : + - Exceptions ; eg page fault, divide by 0 + - IRQ : interrupts caused by hardware + - System calls : when an applications asks the system to do something */ + +#include <config.h> + +struct idt_entry { + uint16_t base_lo; //Low part of address to jump to + uint16_t sel; //Kernel segment selector + uint8_t always0; + uint8_t flags; //Flags + uint16_t base_hi; //High part of address to jump to +} __attribute__((packed)); +typedef struct idt_entry idt_entry_t; + +struct idt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); +typedef struct idt_ptr idt_ptr_t; + +struct registers { + uint32_t ds; // Data segment selector + uint32_t edi, esi, ebp, useless_esp, ebx, edx, ecx, eax; // Pushed by pusha. + uint32_t int_no, err_code; // Interrupt number and error code (if applicable) + uint32_t eip, cs, eflags, esp, ss; // Pushed by the processor automatically. +}; +typedef struct registers registers_t; + +typedef void (*isr_handler_t)(registers_t*); + +void idt_init(); +//void idt_handleIrq(int number, isr_handler_t func); //Set IRQ handler + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/multiboot.h b/kernel/include/multiboot.h index 8fd9dee..581337a 100644 --- a/kernel/include/multiboot.h +++ b/kernel/include/multiboot.h @@ -60,3 +60,4 @@ struct memory_map_t { unsigned long type; }; +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/printf.h b/kernel/include/printf.h index b37816d..b4e1c1b 100644 --- a/kernel/include/printf.h +++ b/kernel/include/printf.h @@ -7,3 +7,4 @@ int snprintf(char* s, size_t n, const char* format, ...); int vsnprintf(char* s, size_t n, const char* format, va_list arg); +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/string.h b/kernel/include/string.h index 3cb0db3..682b25a 100644 --- a/kernel/include/string.h +++ b/kernel/include/string.h @@ -13,3 +13,5 @@ char *strchr(const char *str, char c); char *strcpy(char *dest, const char *src); char *strcat(char *dest, const char *src); int strcmp(const char *s1, const char *s2); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/kernel/include/sys.h b/kernel/include/sys.h index 85cbee6..319cbef 100644 --- a/kernel/include/sys.h +++ b/kernel/include/sys.h @@ -7,8 +7,11 @@ void outw(uint16_t port, uint16_t value); uint8_t inb(uint16_t port); uint16_t inw(uint16_t port); - void panic(const char* message, const char* file, int line); void panic_assert(const char* assertion, const char* file, int line); #define PANIC(s) panic(s, __FILE__, __LINE__); #define ASSERT(s) { if (!(s)) panic_assert(#s, __FILE__, __LINE__); } + +#define BOCHS_BREAKPOINT asm volatile("xchg %bx, %bx") + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |