Added interrupt handling
This commit is contained in:
7
Makefile
7
Makefile
@@ -1,6 +1,7 @@
|
||||
objs = src/addressspace.o src/tty.o src/buddyallocator.o src/math.o \
|
||||
objs = src/addressspace.o src/tty.o src/buddyallocator.o src/math.o \
|
||||
src/cstring.o src/pagetableentry.o src/multiboot2header.o \
|
||||
src/systeminfo.o src/memorymap.o src/entry.o src/quarkkernel.o
|
||||
src/systeminfo.o src/memorymap.o src/interruptdescriptor.o \
|
||||
src/inthandlers.o src/pio.o src/entry.o src/quarkkernel.o
|
||||
link_script = src/linker.ld
|
||||
quark_bin = qkernel
|
||||
quark_img = quark.iso
|
||||
@@ -8,7 +9,7 @@ quark_img = quark.iso
|
||||
CXX = i686-elf-g++
|
||||
CC = i686-elf-gcc
|
||||
|
||||
CPPFLAGS = -ffreestanding -O2 -Wall -fno-exceptions -fno-rtti -ggdb
|
||||
CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb
|
||||
|
||||
.PHONY: all
|
||||
all: $(quark_img)
|
||||
|
||||
27
src/entry.S
27
src/entry.S
@@ -3,6 +3,22 @@
|
||||
|
||||
.section .rodata
|
||||
|
||||
gdt:
|
||||
.long 0, 0
|
||||
.short 0xFFFF
|
||||
.short 0x0000
|
||||
.short 0x9A00
|
||||
.short 0x00CF
|
||||
.short 0xFFFF
|
||||
.short 0x0000
|
||||
.short 0x9200
|
||||
.short 0x00CF
|
||||
|
||||
gdt_info:
|
||||
.short 23
|
||||
.long gdt
|
||||
|
||||
.align 16
|
||||
idt_info:
|
||||
.short idt_end - idt - 1
|
||||
.long idt
|
||||
@@ -199,9 +215,18 @@ s_end:
|
||||
|
||||
# Initialize stack
|
||||
mov $stackTop, %esp
|
||||
|
||||
lgdt gdt_info
|
||||
lidt idt_info
|
||||
|
||||
jmp $8, $.ldcs
|
||||
.ldcs:
|
||||
mov $16, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %gs
|
||||
mov %ax, %fs
|
||||
mov %ax, %ss
|
||||
|
||||
mov $_bootCmdLine, %eax
|
||||
push %eax
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ kernel::InterruptDescriptor::InterruptDescriptor(void* handler, Type type, unsig
|
||||
{
|
||||
uint32_t offset = (uint32_t) handler;
|
||||
this->m_offset1 = (uint16_t) offset;
|
||||
this->m_selector = 1;
|
||||
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 = 0;
|
||||
this->m_offset2 = (uint16_t) (offset >> 16);
|
||||
this->m_present = 1;
|
||||
this->m_offset2 = offset >> 16;
|
||||
}
|
||||
|
||||
bool kernel::InterruptDescriptor::present()
|
||||
@@ -58,5 +58,5 @@ void* kernel::InterruptDescriptor::operator=(void* rhs)
|
||||
{
|
||||
uint32_t offset = (uint32_t) rhs;
|
||||
m_offset1 = (uint16_t) offset;
|
||||
m_offset2 = (uint16_t) (offset >> 16);
|
||||
m_offset2 = (offset >> 16);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
TASK32 = 5,
|
||||
TRAP32 = 15,
|
||||
INT32 = 14,
|
||||
TRAP16 = 7,
|
||||
INT16 = 6
|
||||
TASK32 = 5,
|
||||
TRAP32 = 15,
|
||||
INT32 = 14,
|
||||
TRAP16 = 7,
|
||||
INT16 = 6
|
||||
};
|
||||
|
||||
InterruptDescriptor();
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
#include "inthandlers.hpp"
|
||||
|
||||
extern "C"
|
||||
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';
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
extern "C"
|
||||
__attribute__ ((interrupt))
|
||||
void pageFaultHandler(unsigned int error)
|
||||
void pageFaultHandler(void* frame, unsigned int error)
|
||||
{
|
||||
|
||||
*display = '0';
|
||||
//asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void doubleFaultHandler(void* frame, unsigned int error)
|
||||
{
|
||||
*display = '#';
|
||||
//asm("hlt");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#ifndef INTHANDLERS_H
|
||||
#define INTHANDLERS_H
|
||||
|
||||
extern "C"
|
||||
__attribute__ ((interrupt))
|
||||
void divisionByZero(void* frame);
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void gpFaultHandler(void* frame, unsigned int error);
|
||||
|
||||
extern "C"
|
||||
__attribute__ ((interrupt))
|
||||
void pageFaultHandler(void* frame, unsigned int error);
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void doubleFaultHandler(void* frame, unsigned int error);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,30 +6,47 @@
|
||||
#include "memorymap.hpp"
|
||||
#include "buddyallocator.hpp"
|
||||
#include "addressspace.hpp"
|
||||
#include "interruptdescriptor.hpp"
|
||||
#include "inthandlers.hpp"
|
||||
#include "pio.hpp"
|
||||
#include "tty.h"
|
||||
|
||||
using namespace kernel;
|
||||
|
||||
extern SystemInfo system_info;
|
||||
extern MemoryMap::Region memory_map;
|
||||
extern InterruptDescriptor idt;
|
||||
|
||||
extern "C" void __cxa_pure_virtual()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void main(char* cmdline)
|
||||
{
|
||||
TTY tty((char*) 0xC00B8000);
|
||||
TTY tty((char*) 0xC00B8000);
|
||||
tty << "--Quark Kernel--\n";
|
||||
tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n";
|
||||
tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n";
|
||||
tty << "Type\t\tLocation\t\tSize\n";
|
||||
MemoryMap memmap(&memory_map, 16);
|
||||
for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++)
|
||||
for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++)
|
||||
{
|
||||
tty << (int) memmap[i].getType() << "\t\t\t"
|
||||
<< (void*) memmap[i].getLocation() << "\t\t"
|
||||
<< (int) memmap[i].getSize() << "\n";
|
||||
tty << (int) memmap[i].getType() << "\t\t\t";
|
||||
tty << (void*) memmap[i].getLocation() << "\t\t";
|
||||
tty << (int) memmap[i].getSize() << "\n";
|
||||
}
|
||||
BuddyAllocator alloc(memmap, (char*) 0xC0000000,
|
||||
system_info.getHighMemory() / 4 + 256, 6);
|
||||
BuddyAllocator alloc(memmap, (char*) 0xC0000000, system_info.getHighMemory() / 4 + 256, 6);
|
||||
AddressSpace vmem(alloc);
|
||||
tty << vmem.mmap((void*) 0x80000000, 0x10000) << '\n';
|
||||
vmem.mmap((void*) 0x80000000, 0x10000);
|
||||
InterruptDescriptor* interruptTable = &idt;
|
||||
interruptTable[0] = InterruptDescriptor((void*) &divisionByZero, InterruptDescriptor::INT32, 0);
|
||||
interruptTable[8] = InterruptDescriptor((void*) &doubleFaultHandler, InterruptDescriptor::INT32, 0);
|
||||
interruptTable[14] = InterruptDescriptor((void*) &pageFaultHandler, InterruptDescriptor::INT32, 0);
|
||||
//for(int i = 1; i < 32; i++)
|
||||
// interruptTable[i] = InterruptDescriptor((void*) &pageFaultHandler, InterruptDescriptor::INT32, 0);
|
||||
outb(0xa1, 0xff);
|
||||
outb(0x21, 0xff);
|
||||
asm("sti");
|
||||
tty << "Nothing left to do. Hanging.\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user