Tried to fix it. Seemingly we need a i686-elf gcc now

This commit is contained in:
Morten Delenk 2015-10-14 20:02:41 +02:00
parent 3fbaebeee3
commit 0e2daf575e
13 changed files with 61 additions and 52 deletions

View file

@ -1,6 +1,9 @@
MODE = debug MODE = debug
#MODE = release # enables optimization #MODE = release # enables optimization
#PREFIX =
PREFIX = i686-elf-
ifeq ($(MODE),debug) ifeq ($(MODE),debug)
CFLAGS += -g3 -DDEBUG CFLAGS += -g3 -DDEBUG
CPPFLAGS += -g3 -DDEBUG CPPFLAGS += -g3 -DDEBUG

View file

@ -1,7 +1,8 @@
include ../kernel.settings
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]') SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS))) OBJS = $(addsuffix .o,$(basename $(SRCS)))
LD = g++ LD = $(PREFIX)g++
LDFLAGS = -T kernel.ld -nostdlib -nodefaultlibs LDFLAGS = -T kernel.ld -nostdlib -nodefaultlibs -m32 -nostdlib -fno-builtin
all: hal all: hal
$(LD) $(LDFLAGS) -o mtgos $(OBJS) $(LD) $(LDFLAGS) -o mtgos $(OBJS)
hal: hal:

View file

@ -1,14 +1,14 @@
include ../../../kernel.settings
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]') SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS))) OBJS = $(addsuffix .o,$(basename $(SRCS)))
CPP = g++ CPP = $(PREFIX)g++
CC = gcc CC = $(PREFIX)gcc
ASFLAGS = -m32 ASFLAGS = -m32
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib 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 LDFLAGS = -r -melf_i386
include ../../../kernel.settings
all: $(OBJS) all: $(OBJS)

View file

@ -11,10 +11,10 @@ namespace MTGosHAL {
class IDT; class IDT;
enum class BG_color: uint16_t; enum class BG_color: uint16_t;
enum class FG_color: uint16_t; enum class FG_color: uint16_t;
extern Serial* debug; extern Serial debug;
extern Screen* out; extern Screen out;
extern Screen* err; extern Screen err;
extern GDT* gdt; extern GDT gdt;
extern IDT* idt; extern IDT idt;
} }
#endif #endif

View file

@ -22,7 +22,7 @@ namespace MTGosHAL {
auto serial_received() -> int; auto serial_received() -> int;
auto getChar() -> char; auto getChar() -> char;
public: public:
Serial(uint32_t baud); Serial();
auto debug() -> void; auto debug() -> void;
}; };
} }

View file

@ -45,7 +45,6 @@ namespace MTGosHAL {
private: private:
FG_color fg; FG_color fg;
BG_color bg; BG_color bg;
int x,y;
uint16_t* vmem=(uint16_t*)0xB8000; uint16_t* vmem=(uint16_t*)0xB8000;
auto putChar(char c) -> void; auto putChar(char c) -> void;
public: public:

View file

@ -14,7 +14,7 @@ namespace MTGosHAL {
gdt[i] |= ((base >> 24) & 0xffLL) << 56; gdt[i] |= ((base >> 24) & 0xffLL) << 56;
} }
auto GDT::apply() -> void { 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}; fin={(uint16_t)7*8-1, (void*)gdt};
loadGDT((void*)(&fin)); loadGDT((void*)(&fin));
}; };

View file

@ -25,15 +25,15 @@ namespace MTGosHAL {
idt[i]|=((uint64_t)flags)<<40; idt[i]|=((uint64_t)flags)<<40;
} }
auto IDT::apply() -> void { 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.limit=(uint16_t)(256*8-1);
idtptr.pointer=(uint64_t*)&idt; idtptr.pointer=(uint64_t*)&idt;
loadIDT((void*)&idtptr); loadIDT((void*)&idtptr);
} }
auto IDT::handle(struct cpu_state* cpu) -> void { 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) { 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) { while(1) {
asm volatile("cli; hlt"); asm volatile("cli; hlt");
} }
@ -42,9 +42,9 @@ namespace MTGosHAL {
outb(0xA0, 0x20); outb(0xA0, 0x20);
} }
outb(0x20, 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) { if(cpu->intr==0x20) {
debug->debug(); debug.debug();
} }
} }
for(int i=0;i<16;i++) { for(int i=0;i<16;i++) {
@ -63,5 +63,5 @@ namespace MTGosHAL {
} }
} }
extern "C" void handleINT(struct cpu_state* cpu) { extern "C" void handleINT(struct cpu_state* cpu) {
MTGosHAL::idt->handle(cpu); MTGosHAL::idt.handle(cpu);
} }

View file

@ -7,22 +7,16 @@
#include <keyboard.hpp> #include <keyboard.hpp>
extern "C" void intr_stub_0(void); extern "C" void intr_stub_0(void);
namespace MTGosHAL { namespace MTGosHAL {
Serial* debug; Serial debug;
Screen* out; Screen out;
Screen* err; Screen err;
Keyboard* in; Keyboard in;
IDT* idt; IDT idt;
void main() {
Serial serialOUT(115200);
Screen display;
GDT gdt; GDT gdt;
IDT interrupts; void main() {
debug=&serialOUT; out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
err=&display; err << BG_color::BLACK << FG_color::RED;
out=&display; debug << "Hello debugger! This is MTGos version 0.0\nThese logs are probably very long, so please redirect the output to a file.\n";
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";
gdt.setEntry(0, 0, 0, 0); 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(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); 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(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.setEntry(6, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_TSS | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
gdt.apply(); 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++) { 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(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.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(); idt.apply();
//Init the Keyboard
Keyboard kb;
in = &kb;
sti(); sti();
for(;;); for(;;);
} }
} }
typedef void (*constructor)();
extern "C" constructor start_ctors;
extern "C" constructor end_ctors;
extern "C" void init() { extern "C" void init() {
for(constructor* i = &start_ctors; i != &end_ctors; ++i)
(*i)();
MTGosHAL::main(); MTGosHAL::main();
} }
extern "C" void __cxa_pure_virtual() { 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";
} }

View file

@ -18,11 +18,11 @@ namespace MTGosHAL {
outb(0x60, command); outb(0x60, command);
} }
auto Keyboard::handleIRQ1(struct cpu_state* cpu) -> void { 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) { Keyboard::Keyboard(): shift(false), numlock(true), caps(false), scrollock(false) {
if(!idt->request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) { if(!idt.request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) {
*debug << "Could not get an handler for IRQ1 (Keyboard)\n"; debug << "Could not get an handler for IRQ1 (Keyboard)\n";
return; return;
} }
//Clear keyboard buffer //Clear keyboard buffer
@ -34,7 +34,7 @@ namespace MTGosHAL {
sendCommand(0x20); sendCommand(0x20);
uint8_t ccb=inb(0x60); uint8_t ccb=inb(0x60);
if(!(ccb&4)) { 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; ccb &= ~1;
} else { } else {
ccb |= 1; ccb |= 1;

View file

@ -31,7 +31,8 @@ namespace MTGosHAL {
*this << '\n'; *this << '\n';
return chr; return chr;
} }
Serial::Serial(uint32_t baud) { Serial::Serial() {
uint32_t baud=115200;
port=*((uint16_t*)0x0400); port=*((uint16_t*)0x0400);
union { union {
uint8_t b[2]; uint8_t b[2];
@ -54,9 +55,10 @@ namespace MTGosHAL {
auto Serial::debug() -> void { auto Serial::debug() -> void {
if(getChar()) { if(getChar()) {
*this << "The interactive debug shell was started.\n> "; *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]; char buf[256];
*out << buf << "\nDebug shell closed.\n"; *this >> buf;
out << buf << "\nDebug shell closed.\n";
*this << "Unknown command. TODO\n"; *this << "Unknown command. TODO\n";
} }
uint64_t wt = waittimes; uint64_t wt = waittimes;

View file

@ -1,5 +1,6 @@
#include <base.hpp> #include <base.hpp>
#include <textDISP.hpp> #include <textDISP.hpp>
int x=0, y=0;
namespace MTGosHAL { namespace MTGosHAL {
auto Screen::putChar(char c) -> void { auto Screen::putChar(char c) -> void {
switch(c) { switch(c) {
@ -27,6 +28,7 @@ namespace MTGosHAL {
auto Screen::clrscr() -> void { auto Screen::clrscr() -> void {
for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH+SCREEN_WIDTH; p++) for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH+SCREEN_WIDTH; p++)
vmem[p]=((uint16_t)fg) | ((uint16_t)bg) | ((uint16_t)' '); vmem[p]=((uint16_t)fg) | ((uint16_t)bg) | ((uint16_t)' ');
x=y=0;
} }
auto Screen::scroll() -> void { auto Screen::scroll() -> void {
for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH; p++) for(int p=0; p<SCREEN_HEIGHT*SCREEN_WIDTH; p++)

View file

@ -9,6 +9,13 @@ SECTIONS
*(.text) *(.text)
} }
.data ALIGN(4096) : { .data ALIGN(4096) : {
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
start_dtors = .;
*(.dtors)
end_dtors = .;
*(.data) *(.data)
} }
.rodata ALIGN(4096) : { .rodata ALIGN(4096) : {