Merged several files together

This commit is contained in:
2020-08-01 19:03:51 -05:00
parent 09edf0cedc
commit 39710685fb
10 changed files with 252 additions and 312 deletions

View File

@@ -8,12 +8,8 @@ if x86
quark_kernel_SOURCES += x86/pagetableentry.cpp \ quark_kernel_SOURCES += x86/pagetableentry.cpp \
x86/mmap.cpp \ x86/mmap.cpp \
x86/interrupts.cpp \ x86/interrupts.cpp \
x86/inthandlers.cpp \
x86/interruptdescriptor.cpp \
x86/idt.S \
x86/entry.S \ x86/entry.S \
x86/pio.S \ x86/pio.S
x86/multiboot2header.S
quark_kernel_LDFLAGS += -T x86/linker.ld quark_kernel_LDFLAGS += -T x86/linker.ld
quark_kernel_DEPENDENCIES = x86/linker.ld quark_kernel_DEPENDENCIES = x86/linker.ld
endif endif

View File

@@ -1,5 +1,98 @@
.section .multiboot .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 .section .rodata

View File

@@ -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

View File

@@ -1,10 +0,0 @@
#ifndef IDT_H
#define IDT_H
#include "interruptdescriptor.hpp"
extern kernel::InterruptDescriptor idt[256];
extern "C" void _lidt();
#endif

View File

@@ -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;
}

View File

@@ -1,55 +0,0 @@
#ifndef INTERRUPTDESCRIPTOR_H
#define INTERRUPTDESCRIPTOR_H
#include <stdint.h>
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

View File

@@ -1,6 +1,158 @@
#include "../interrupts.hpp" #include "../interrupts.hpp"
#include "idt.hpp"
#include "inthandlers.hpp" #include <stdint.h>
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() kernel::Interrupts::Interrupts()
{ {
@@ -9,15 +161,15 @@ kernel::Interrupts::Interrupts()
idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0); idt[0x80] = InterruptDescriptor((void*) &syscallHandler, InterruptDescriptor::INT32, 0);
// Load interrupt handlers // Load interrupt handlers
// Configure PIC // Configure PIC
_lidt(); lidt();
} }
inline void kernel::Interrupts::enable() void kernel::Interrupts::enable()
{ {
asm("sti"); asm("sti");
} }
inline void kernel::Interrupts::disable() void kernel::Interrupts::disable()
{ {
asm("cli"); asm("cli");
} }

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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: