From 39710685fbb9adfb35507ee32161aff0cd92eefe Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Sat, 1 Aug 2020 19:03:51 -0500 Subject: [PATCH] Merged several files together --- src/Makefile.am | 6 +- src/x86/entry.S | 95 ++++++++++++++++++- src/x86/idt.S | 21 ----- src/x86/idt.hpp | 10 -- src/x86/interruptdescriptor.cpp | 63 ------------- src/x86/interruptdescriptor.hpp | 55 ----------- src/x86/interrupts.cpp | 162 +++++++++++++++++++++++++++++++- src/x86/inthandlers.cpp | 39 -------- src/x86/inthandlers.hpp | 19 ---- src/x86/multiboot2header.S | 94 ------------------ 10 files changed, 252 insertions(+), 312 deletions(-) delete mode 100644 src/x86/idt.S delete mode 100644 src/x86/idt.hpp delete mode 100644 src/x86/interruptdescriptor.cpp delete mode 100644 src/x86/interruptdescriptor.hpp delete mode 100644 src/x86/inthandlers.cpp delete mode 100644 src/x86/inthandlers.hpp delete mode 100755 src/x86/multiboot2header.S diff --git a/src/Makefile.am b/src/Makefile.am index a5b0db4..5ff9807 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,12 +8,8 @@ if x86 quark_kernel_SOURCES += x86/pagetableentry.cpp \ x86/mmap.cpp \ x86/interrupts.cpp \ - x86/inthandlers.cpp \ - x86/interruptdescriptor.cpp \ - x86/idt.S \ x86/entry.S \ - x86/pio.S \ - x86/multiboot2header.S + x86/pio.S quark_kernel_LDFLAGS += -T x86/linker.ld quark_kernel_DEPENDENCIES = x86/linker.ld endif diff --git a/src/x86/entry.S b/src/x86/entry.S index 55dc9d0..7a68f9d 100755 --- a/src/x86/entry.S +++ b/src/x86/entry.S @@ -1,5 +1,98 @@ .section .multiboot -.include "x86/multiboot2header.S" + +/* + * Define constants for the multiboot header. See Multiboot 2 Specifications for details. + */ +.set align, 1<<0 +.set meminfo, 1<<1 +.set magic, 0xE85250D6 +.set arch, 0 +.set headerLength, _multibootHeaderEnd - _multibootHeaderStart +.set checksum, -(magic + arch + headerLength) + +.set tagNotOptional, 0 + +.set tagInfoRequestType, 1 +.set tagInfoRequestSize, _multibootInfoTagEnd - _multibootInfoTagStart +.set requestBootCommand, 1 +.set requestBootLoaderName, 2 +.set requestBootModules, 3 +.set requestMemoryInfo, 4 +.set requestBootDevice, 5 +.set requestMemoryMap, 6 + +.set tagAddressType, 2 +.set tagAddressSize, 24 +.set tagAddressHeaderLocation, LOAD_START +.set tagAddressLoadStart, LOAD_START +.set tagAddressLoadEnd, LOAD_END +.set tagAddressBSSEnd, BSS_END + +.set tagEntryType, 3 +.set tagEntrySize, 12 +.set tagEntryAddress, _start - (0xFF900000 - 0x100000) + +.set tagModuleAlignType, 6 +.set tagModuleAlignSize, 8 + +/* + * Each multiboot tag must be 8-byte aligned, or GRUB will not be able to read the header. + */ +.align 8 +_multibootHeaderStart: + +.long magic +.long arch +.long headerLength +.long checksum + +.align 8 + +_multibootInfoTagStart: +.short tagInfoRequestType +.short tagNotOptional +.long tagInfoRequestSize +.long requestBootCommand +.long requestBootLoaderName +.long requestBootModules +.long requestMemoryInfo +.long requestBootDevice +.long requestMemoryMap +_multibootInfoTagEnd: + +.align 8 + +.short tagAddressType +.short tagNotOptional +.long tagAddressSize +.long tagAddressHeaderLocation +.long tagAddressLoadStart +.long tagAddressLoadEnd +.long tagAddressBSSEnd + +.align 8 + +.short tagEntryType +.short tagNotOptional +.long tagEntrySize +.long tagEntryAddress + +.align 8 + +.short tagModuleAlignType +.short tagNotOptional +.long tagModuleAlignSize + +.align 8 + +/* + * Terminate list of multiboot header tags. + * Ending tag has type = 0, flags = 0, size = 8 + */ +.long 0 +.long 8 + +_multibootHeaderEnd: .section .rodata diff --git a/src/x86/idt.S b/src/x86/idt.S deleted file mode 100644 index a76f770..0000000 --- a/src/x86/idt.S +++ /dev/null @@ -1,21 +0,0 @@ -.section .bss - -.align 8 -.global idt -idt: -.skip 8 * 256 -idt_end: - -.section .rodata - -.idt_info: -.short idt_end - idt - 1 -.long idt - -.section .text - -.global _lidt -.type _lidt, @function -_lidt: - - ret \ No newline at end of file diff --git a/src/x86/idt.hpp b/src/x86/idt.hpp deleted file mode 100644 index 2c1cf0f..0000000 --- a/src/x86/idt.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef IDT_H -#define IDT_H - -#include "interruptdescriptor.hpp" - -extern kernel::InterruptDescriptor idt[256]; - -extern "C" void _lidt(); - -#endif \ No newline at end of file diff --git a/src/x86/interruptdescriptor.cpp b/src/x86/interruptdescriptor.cpp deleted file mode 100644 index 63803e6..0000000 --- a/src/x86/interruptdescriptor.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "interruptdescriptor.hpp" - -kernel::InterruptDescriptor::InterruptDescriptor() -{ - this->m_offset1 = 0; - this->m_selector = 0; - this->m_zero = 0; - this->m_type = 0; - this->m_storage = 0; - this->m_dpl = 0; - this->m_present = 0; - this->m_offset2 = 0; -} - -kernel::InterruptDescriptor::InterruptDescriptor(void* handler, Type type, unsigned int dpl) -{ - uint32_t offset = (uint32_t) handler; - this->m_offset1 = (uint16_t) offset; - this->m_selector = 8; - this->m_zero = 0; - this->m_type = (uint16_t) type; - this->m_storage = 0; - this->m_dpl = dpl; - this->m_present = 1; - this->m_offset2 = offset >> 16; -} - -bool kernel::InterruptDescriptor::present() -{ - return m_present == 1; -} -void kernel::InterruptDescriptor::present(bool present) -{ - m_present = present ? 1 : 0; -} - -kernel::InterruptDescriptor::Type kernel::InterruptDescriptor::type() -{ - return (Type) m_type; -} - -void kernel::InterruptDescriptor::type(kernel::InterruptDescriptor::Type type) -{ - m_type = (unsigned int) type; -} - -unsigned int kernel::InterruptDescriptor::dpl() -{ - return m_dpl; -} - -void kernel::InterruptDescriptor::dpl(unsigned int dpl) -{ - m_dpl = dpl; -} - -void* kernel::InterruptDescriptor::operator=(void* rhs) -{ - uint32_t offset = (uint32_t) rhs; - m_offset1 = (uint16_t) offset; - m_offset2 = (offset >> 16); - return rhs; -} diff --git a/src/x86/interruptdescriptor.hpp b/src/x86/interruptdescriptor.hpp deleted file mode 100644 index c4365fe..0000000 --- a/src/x86/interruptdescriptor.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef INTERRUPTDESCRIPTOR_H -#define INTERRUPTDESCRIPTOR_H - -#include - -namespace kernel -{ - -class InterruptDescriptor -{ -public: - - enum Type - { - TASK32 = 5, - TRAP32 = 15, - INT32 = 14, - TRAP16 = 7, - INT16 = 6 - }; - - InterruptDescriptor(); - - InterruptDescriptor(void* handler, Type type, unsigned int dpl); - - bool present(); - - void present(bool present); - - Type type(); - - void type(Type type); - - unsigned int dpl(); - - void dpl(unsigned int dpl); - - void* operator=(void* rhs); - -private: - - uint16_t m_offset1; - uint16_t m_selector; - uint16_t m_zero : 8; - uint16_t m_type : 4; - uint16_t m_storage : 1; - uint16_t m_dpl : 2; - uint16_t m_present : 1; - uint16_t m_offset2; - -}; - -} - -#endif diff --git a/src/x86/interrupts.cpp b/src/x86/interrupts.cpp index 9e5c964..2b22417 100644 --- a/src/x86/interrupts.cpp +++ b/src/x86/interrupts.cpp @@ -1,6 +1,158 @@ #include "../interrupts.hpp" -#include "idt.hpp" -#include "inthandlers.hpp" + +#include + +class InterruptDescriptor +{ +public: + + enum Type + { + TASK32 = 5, + TRAP32 = 15, + INT32 = 14, + TRAP16 = 7, + INT16 = 6 + }; + + InterruptDescriptor(); + + InterruptDescriptor(void* handler, Type type, unsigned int dpl); + + bool present(); + + void present(bool present); + + Type type(); + + void type(Type type); + + unsigned int dpl(); + + void dpl(unsigned int dpl); + + void* operator=(void* rhs); + +private: + + uint16_t m_offset1; + uint16_t m_selector; + uint16_t m_zero : 8; + uint16_t m_type : 4; + uint16_t m_storage : 1; + uint16_t m_dpl : 2; + uint16_t m_present : 1; + uint16_t m_offset2; + +}; + +struct IDTInfo +{ + uint16_t size; + void* location; +}; + +InterruptDescriptor idt[256]; + +void lidt() +{ + IDTInfo idtInfo; + idtInfo.size = sizeof(idt) - 1; + idtInfo.location = (void*) &idt; + asm("lidt idt"); +} + +__attribute__ ((interrupt)) +void divisionByZero(void* frame) +{ + +} + +__attribute__ ((interrupt)) +void gpFaultHandler(void* frame, unsigned int error) +{ + +} + +__attribute__ ((interrupt)) +void pageFaultHandler(void* frame, unsigned int error) +{ + +} + +__attribute__ ((interrupt)) +void doubleFaultHandler(void* frame, unsigned int error) +{ + asm("hlt"); +} + +__attribute__ ((interrupt)) +void syscallHandler(void* frame) +{ + +} + +InterruptDescriptor::InterruptDescriptor() +{ + this->m_offset1 = 0; + this->m_selector = 0; + this->m_zero = 0; + this->m_type = 0; + this->m_storage = 0; + this->m_dpl = 0; + this->m_present = 0; + this->m_offset2 = 0; +} + +InterruptDescriptor::InterruptDescriptor(void* handler, Type type, unsigned int dpl) +{ + uint32_t offset = (uint32_t) handler; + this->m_offset1 = (uint16_t) offset; + this->m_selector = 8; + this->m_zero = 0; + this->m_type = (uint16_t) type; + this->m_storage = 0; + this->m_dpl = dpl; + this->m_present = 1; + this->m_offset2 = offset >> 16; +} + +bool InterruptDescriptor::present() +{ + return m_present == 1; +} +void InterruptDescriptor::present(bool present) +{ + m_present = present ? 1 : 0; +} + +InterruptDescriptor::Type InterruptDescriptor::type() +{ + return (Type) m_type; +} + +void InterruptDescriptor::type(InterruptDescriptor::Type type) +{ + m_type = (unsigned int) type; +} + +unsigned int InterruptDescriptor::dpl() +{ + return m_dpl; +} + +void InterruptDescriptor::dpl(unsigned int dpl) +{ + m_dpl = dpl; +} + +void* InterruptDescriptor::operator=(void* rhs) +{ + uint32_t offset = (uint32_t) rhs; + m_offset1 = (uint16_t) offset; + m_offset2 = (offset >> 16); + return rhs; +} kernel::Interrupts::Interrupts() { @@ -9,15 +161,15 @@ kernel::Interrupts::Interrupts() idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0); // Load interrupt handlers // Configure PIC - _lidt(); + lidt(); } -inline void kernel::Interrupts::enable() +void kernel::Interrupts::enable() { asm("sti"); } -inline void kernel::Interrupts::disable() +void kernel::Interrupts::disable() { asm("cli"); } \ No newline at end of file diff --git a/src/x86/inthandlers.cpp b/src/x86/inthandlers.cpp deleted file mode 100644 index 6519620..0000000 --- a/src/x86/inthandlers.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "inthandlers.hpp" - -char* display = (char*) 0xC00B8000; - -__attribute__ ((interrupt)) -void divisionByZero(void* frame) -{ - *display = 'z'; - display += 2; -} - -__attribute__ ((interrupt)) -void gpFaultHandler(void* frame, unsigned int error) -{ - *display = 'a'; - display += 2; -} - -__attribute__ ((interrupt)) -void pageFaultHandler(void* frame, unsigned int error) -{ - *display = '0'; - display += 2; -} - -__attribute__ ((interrupt)) -void doubleFaultHandler(void* frame, unsigned int error) -{ - *display = '#'; - asm("hlt"); -} - -__attribute__ ((interrupt)) -void syscallHandler(void* frame) -{ - *display = 'z'; - display += 2; -} - diff --git a/src/x86/inthandlers.hpp b/src/x86/inthandlers.hpp deleted file mode 100644 index bf92c56..0000000 --- a/src/x86/inthandlers.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef INTHANDLERS_H -#define INTHANDLERS_H - -__attribute__ ((interrupt)) -void divisionByZero(void* frame); - -__attribute__ ((interrupt)) -void gpFaultHandler(void* frame, unsigned int error); - -__attribute__ ((interrupt)) -void pageFaultHandler(void* frame, unsigned int error); - -__attribute__ ((interrupt)) -void doubleFaultHandler(void* frame, unsigned int error); - -__attribute__ ((interrupt)) -void syscallHandler(void* frame); - -#endif diff --git a/src/x86/multiboot2header.S b/src/x86/multiboot2header.S deleted file mode 100755 index 050df1c..0000000 --- a/src/x86/multiboot2header.S +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Define constants for the multiboot header. See Multuboot 2 Specifications for details. - */ -.set align, 1<<0 -.set meminfo, 1<<1 -.set magic, 0xE85250D6 -.set arch, 0 -.set headerLength, _multibootHeaderEnd - _multibootHeaderStart -.set checksum, -(magic + arch + headerLength) - -.set tagNotOptional, 0 - -.set tagInfoRequestType, 1 -.set tagInfoRequestSize, _multibootInfoTagEnd - _multibootInfoTagStart -.set requestBootCommand, 1 -.set requestBootLoaderName, 2 -.set requestBootModules, 3 -.set requestMemoryInfo, 4 -.set requestBootDevice, 5 -.set requestMemoryMap, 6 - -.set tagAddressType, 2 -.set tagAddressSize, 24 -.set tagAddressHeaderLocation, LOAD_START -.set tagAddressLoadStart, LOAD_START -.set tagAddressLoadEnd, LOAD_END -.set tagAddressBSSEnd, BSS_END - -.set tagEntryType, 3 -.set tagEntrySize, 12 -.set tagEntryAddress, _start - (0xFF900000 - 0x100000) - -.set tagModuleAlignType, 6 -.set tagModuleAlignSize, 8 - -/* - * Each multiboot tag must be 8-byte aligned, or GRUB will not be able to read the header. - */ -.align 8 -_multibootHeaderStart: - -.long magic -.long arch -.long headerLength -.long checksum - -.align 8 - -_multibootInfoTagStart: -.short tagInfoRequestType -.short tagNotOptional -.long tagInfoRequestSize -.long requestBootCommand -.long requestBootLoaderName -.long requestBootModules -.long requestMemoryInfo -.long requestBootDevice -.long requestMemoryMap -_multibootInfoTagEnd: - -.align 8 - -.short tagAddressType -.short tagNotOptional -.long tagAddressSize -.long tagAddressHeaderLocation -.long tagAddressLoadStart -.long tagAddressLoadEnd -.long tagAddressBSSEnd - -.align 8 - -.short tagEntryType -.short tagNotOptional -.long tagEntrySize -.long tagEntryAddress - -.align 8 - -.short tagModuleAlignType -.short tagNotOptional -.long tagModuleAlignSize - -.align 8 - -/* - * Terminate list of multiboot header tags. - * Ending tag has type = 0, flags = 0, size = 8 - */ -.long 0 -.long 8 - -_multibootHeaderEnd: -