Tried to fix it. Seemingly we need a i686-elf gcc now
This commit is contained in:
parent
3fbaebeee3
commit
0e2daf575e
13 changed files with 61 additions and 52 deletions
|
@ -1,6 +1,9 @@
|
|||
MODE = debug
|
||||
#MODE = release # enables optimization
|
||||
|
||||
#PREFIX =
|
||||
PREFIX = i686-elf-
|
||||
|
||||
ifeq ($(MODE),debug)
|
||||
CFLAGS += -g3 -DDEBUG
|
||||
CPPFLAGS += -g3 -DDEBUG
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
include ../kernel.settings
|
||||
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
|
||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||
LD = g++
|
||||
LDFLAGS = -T kernel.ld -nostdlib -nodefaultlibs
|
||||
LD = $(PREFIX)g++
|
||||
LDFLAGS = -T kernel.ld -nostdlib -nodefaultlibs -m32 -nostdlib -fno-builtin
|
||||
all: hal
|
||||
$(LD) $(LDFLAGS) -o mtgos $(OBJS)
|
||||
hal:
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
include ../../../kernel.settings
|
||||
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
|
||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||
|
||||
CPP = g++
|
||||
CC = gcc
|
||||
CPP = $(PREFIX)g++
|
||||
CC = $(PREFIX)gcc
|
||||
ASFLAGS = -m32
|
||||
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib
|
||||
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib
|
||||
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused
|
||||
LDFLAGS = -r -melf_i386
|
||||
|
||||
include ../../../kernel.settings
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ namespace MTGosHAL {
|
|||
class IDT;
|
||||
enum class BG_color: uint16_t;
|
||||
enum class FG_color: uint16_t;
|
||||
extern Serial* debug;
|
||||
extern Screen* out;
|
||||
extern Screen* err;
|
||||
extern GDT* gdt;
|
||||
extern IDT* idt;
|
||||
extern Serial debug;
|
||||
extern Screen out;
|
||||
extern Screen err;
|
||||
extern GDT gdt;
|
||||
extern IDT idt;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace MTGosHAL {
|
|||
auto serial_received() -> int;
|
||||
auto getChar() -> char;
|
||||
public:
|
||||
Serial(uint32_t baud);
|
||||
Serial();
|
||||
auto debug() -> void;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace MTGosHAL {
|
|||
private:
|
||||
FG_color fg;
|
||||
BG_color bg;
|
||||
int x,y;
|
||||
uint16_t* vmem=(uint16_t*)0xB8000;
|
||||
auto putChar(char c) -> void;
|
||||
public:
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MTGosHAL {
|
|||
gdt[i] |= ((base >> 24) & 0xffLL) << 56;
|
||||
}
|
||||
auto GDT::apply() -> void {
|
||||
*debug << "We are now trying to set our GDT. If the CPU triplefaults, something went wrong in MTGosHAL::GDT::apply() or loadGDT().\n";
|
||||
debug << "We are now trying to set our GDT. If the CPU triplefaults, something went wrong in MTGosHAL::GDT::apply() or loadGDT().\n";
|
||||
fin={(uint16_t)7*8-1, (void*)gdt};
|
||||
loadGDT((void*)(&fin));
|
||||
};
|
||||
|
|
|
@ -25,15 +25,15 @@ namespace MTGosHAL {
|
|||
idt[i]|=((uint64_t)flags)<<40;
|
||||
}
|
||||
auto IDT::apply() -> void {
|
||||
*debug << "Now trying to load the IDT.\n";
|
||||
debug << "Now trying to load the IDT.\n";
|
||||
idtptr.limit=(uint16_t)(256*8-1);
|
||||
idtptr.pointer=(uint64_t*)&idt;
|
||||
loadIDT((void*)&idtptr);
|
||||
}
|
||||
auto IDT::handle(struct cpu_state* cpu) -> void {
|
||||
*debug << "Interrupt 0x" << Base::HEXADECIMAL << (int) cpu->intr << " was raised.\n";
|
||||
debug << "Interrupt 0x" << Base::HEXADECIMAL << (int) cpu->intr << " was raised.\n";
|
||||
if(cpu->intr<=0x1F) {
|
||||
*out << "Exception 0x" << Base::HEXADECIMAL << (int) cpu->intr << "! Kernel halted!\n";
|
||||
out << "Exception 0x" << Base::HEXADECIMAL << (int) cpu->intr << "! Kernel halted!\n";
|
||||
while(1) {
|
||||
asm volatile("cli; hlt");
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ namespace MTGosHAL {
|
|||
outb(0xA0, 0x20);
|
||||
}
|
||||
outb(0x20, 0x20);
|
||||
*debug << "The IRQ " << Base::DECIMAL << (int) cpu->intr-0x20 << " was handled.\n";
|
||||
debug << "The IRQ " << Base::DECIMAL << (int) cpu->intr-0x20 << " was handled.\n";
|
||||
if(cpu->intr==0x20) {
|
||||
debug->debug();
|
||||
debug.debug();
|
||||
}
|
||||
}
|
||||
for(int i=0;i<16;i++) {
|
||||
|
@ -63,5 +63,5 @@ namespace MTGosHAL {
|
|||
}
|
||||
}
|
||||
extern "C" void handleINT(struct cpu_state* cpu) {
|
||||
MTGosHAL::idt->handle(cpu);
|
||||
MTGosHAL::idt.handle(cpu);
|
||||
}
|
||||
|
|
|
@ -7,22 +7,16 @@
|
|||
#include <keyboard.hpp>
|
||||
extern "C" void intr_stub_0(void);
|
||||
namespace MTGosHAL {
|
||||
Serial* debug;
|
||||
Screen* out;
|
||||
Screen* err;
|
||||
Keyboard* in;
|
||||
IDT* idt;
|
||||
void main() {
|
||||
Serial serialOUT(115200);
|
||||
Screen display;
|
||||
Serial debug;
|
||||
Screen out;
|
||||
Screen err;
|
||||
Keyboard in;
|
||||
IDT idt;
|
||||
GDT gdt;
|
||||
IDT interrupts;
|
||||
debug=&serialOUT;
|
||||
err=&display;
|
||||
out=&display;
|
||||
idt=&interrupts;
|
||||
*out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
||||
*debug << "Hello debugger! This is MTGos version 0.0\nThese logs are probably very long, so please redirect the output to a file.\n";
|
||||
void main() {
|
||||
out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
||||
err << BG_color::BLACK << FG_color::RED;
|
||||
debug << "Hello debugger! This is MTGos version 0.0\nThese logs are probably very long, so please redirect the output to a file.\n";
|
||||
gdt.setEntry(0, 0, 0, 0);
|
||||
gdt.setEntry(1, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
||||
gdt.setEntry(2, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
||||
|
@ -31,25 +25,26 @@ namespace MTGosHAL {
|
|||
gdt.setEntry(5, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_TSS | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
||||
gdt.setEntry(6, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_TSS | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
||||
gdt.apply();
|
||||
*debug << "We are now creating the IDT.\n";
|
||||
debug << "We are now creating the IDT.\n";
|
||||
for(int i=0;i<256;i++) {
|
||||
idt->setEntry(i, (void *)((uint32_t)&intr_stub_0+i*16), SEG_KERNEL, IDT_INTERRUPT_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt.setEntry(i, (void *)((uint32_t)&intr_stub_0+i*16), SEG_KERNEL, IDT_INTERRUPT_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
}
|
||||
idt->setEntry(48, (void *)((uint32_t)&intr_stub_0+768), SEG_KERNEL, IDT_TRAP_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt->setEntry(8, (void *)((uint32_t)&intr_stub_0+128), SEG_DBL_FAULT, IDT_TASK_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt->apply();
|
||||
|
||||
//Init the Keyboard
|
||||
Keyboard kb;
|
||||
in = &kb;
|
||||
idt.setEntry(48, (void *)((uint32_t)&intr_stub_0+768), SEG_KERNEL, IDT_TRAP_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt.setEntry(8, (void *)((uint32_t)&intr_stub_0+128), SEG_DBL_FAULT, IDT_TASK_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt.apply();
|
||||
sti();
|
||||
for(;;);
|
||||
}
|
||||
}
|
||||
typedef void (*constructor)();
|
||||
extern "C" constructor start_ctors;
|
||||
extern "C" constructor end_ctors;
|
||||
extern "C" void init() {
|
||||
for(constructor* i = &start_ctors; i != &end_ctors; ++i)
|
||||
(*i)();
|
||||
MTGosHAL::main();
|
||||
}
|
||||
extern "C" void __cxa_pure_virtual() {
|
||||
*MTGosHAL::debug << "A pure virtual function just got called.\n";
|
||||
MTGosHAL::debug << "A pure virtual function just got called.\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ namespace MTGosHAL {
|
|||
outb(0x60, command);
|
||||
}
|
||||
auto Keyboard::handleIRQ1(struct cpu_state* cpu) -> void {
|
||||
*debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int) inb(0x60) << ".\n";
|
||||
debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int) inb(0x60) << ".\n";
|
||||
}
|
||||
Keyboard::Keyboard(): shift(false), numlock(true), caps(false), scrollock(false) {
|
||||
if(!idt->request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) {
|
||||
*debug << "Could not get an handler for IRQ1 (Keyboard)\n";
|
||||
if(!idt.request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) {
|
||||
debug << "Could not get an handler for IRQ1 (Keyboard)\n";
|
||||
return;
|
||||
}
|
||||
//Clear keyboard buffer
|
||||
|
@ -34,7 +34,7 @@ namespace MTGosHAL {
|
|||
sendCommand(0x20);
|
||||
uint8_t ccb=inb(0x60);
|
||||
if(!(ccb&4)) {
|
||||
*debug << "Keyboard didn't pass self-test!\nDeactivating IRQ1.\n";
|
||||
debug << "Keyboard didn't pass self-test!\nDeactivating IRQ1.\n";
|
||||
ccb &= ~1;
|
||||
} else {
|
||||
ccb |= 1;
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace MTGosHAL {
|
|||
*this << '\n';
|
||||
return chr;
|
||||
}
|
||||
Serial::Serial(uint32_t baud) {
|
||||
Serial::Serial() {
|
||||
uint32_t baud=115200;
|
||||
port=*((uint16_t*)0x0400);
|
||||
union {
|
||||
uint8_t b[2];
|
||||
|
@ -54,9 +55,10 @@ namespace MTGosHAL {
|
|||
auto Serial::debug() -> void {
|
||||
if(getChar()) {
|
||||
*this << "The interactive debug shell was started.\n> ";
|
||||
*out << "The debug shell was started.\n";
|
||||
out << "The debug shell was started.\n";
|
||||
char buf[256];
|
||||
*out << buf << "\nDebug shell closed.\n";
|
||||
*this >> buf;
|
||||
out << buf << "\nDebug shell closed.\n";
|
||||
*this << "Unknown command. TODO\n";
|
||||
}
|
||||
uint64_t wt = waittimes;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <base.hpp>
|
||||
#include <textDISP.hpp>
|
||||
int x=0, y=0;
|
||||
namespace MTGosHAL {
|
||||
auto Screen::putChar(char c) -> void {
|
||||
switch(c) {
|
||||
|
@ -27,6 +28,7 @@ namespace MTGosHAL {
|
|||
auto Screen::clrscr() -> void {
|
||||
for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH+SCREEN_WIDTH; p++)
|
||||
vmem[p]=((uint16_t)fg) | ((uint16_t)bg) | ((uint16_t)' ');
|
||||
x=y=0;
|
||||
}
|
||||
auto Screen::scroll() -> void {
|
||||
for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH; p++)
|
||||
|
|
|
@ -9,6 +9,13 @@ SECTIONS
|
|||
*(.text)
|
||||
}
|
||||
.data ALIGN(4096) : {
|
||||
start_ctors = .;
|
||||
KEEP(*( .init_array ));
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
|
||||
end_ctors = .;
|
||||
start_dtors = .;
|
||||
*(.dtors)
|
||||
end_dtors = .;
|
||||
*(.data)
|
||||
}
|
||||
.rodata ALIGN(4096) : {
|
||||
|
|
Loading…
Reference in a new issue