diff --git a/kernel/hal/x86/boot/boot.S b/kernel/hal/x86/boot/boot.S index 816f87a..2b6f13a 100644 --- a/kernel/hal/x86/boot/boot.S +++ b/kernel/hal/x86/boot/boot.S @@ -17,5 +17,5 @@ _stop: hlt jmp _stop .section .bss -.space 65536 +.space 8192 kernel_stack: diff --git a/kernel/hal/x86/include/base.hpp b/kernel/hal/x86/include/base.hpp new file mode 100644 index 0000000..02a211b --- /dev/null +++ b/kernel/hal/x86/include/base.hpp @@ -0,0 +1,14 @@ +#ifndef _BASE_HPP +#define _BASE_HPP +#include +namespace MTGosHAL { + class Output; + class Serial; + class Screen; + enum class BG_color: uint16_t; + enum class FG_color: uint16_t; + extern Serial* debug; + extern Screen* out; + extern Screen* err; +} +#endif diff --git a/kernel/hal/x86/include/output.hpp b/kernel/hal/x86/include/output.hpp index e5f61ac..143b182 100644 --- a/kernel/hal/x86/include/output.hpp +++ b/kernel/hal/x86/include/output.hpp @@ -1,6 +1,9 @@ #ifndef _OUTPUT_HPP #define _OUTPUT_HPP +#include +#include namespace MTGosHAL { + enum class Base : int { BINARY=2, TERNARY, @@ -20,12 +23,8 @@ namespace MTGosHAL { }; /* abstract */ class Output { private: - virtual void putChar(char c) { /*ignore*/ }; - auto puts(const char* s) -> void { - int i=0; - while(s[i]!='\0') - putChar(s[i++]); - } + virtual auto putChar(char c) -> void = 0; + auto puts(const char* s) -> void; int base=10; public: template @@ -36,32 +35,12 @@ namespace MTGosHAL { }; template <> - auto Output::operator<<(Base output) -> Output & { - base=static_cast(output); - return *this; - } + auto Output::operator<<(Base output) -> Output &; template <> - auto Output::operator<<(int output) -> Output & { - const char* chars="0123456789ABCDEF"; - char buf[33]; - buf[32]='\0'; - char* ptr=buf+31; - do { - *(ptr--)=chars[output%base]; - output/=base; - } while(output && (ptr!=buf)); - puts(ptr+1); - return *this; - } + auto Output::operator<<(int output) -> Output &; template <> - auto Output::operator<<(char output) -> Output & { - putChar(output); - return *this; - } + auto Output::operator<<(char output) -> Output &; template <> - auto Output::operator<<(char* output) -> Output & { - puts(output); - return *this; - } + auto Output::operator<<(char* output) -> Output &; } #endif diff --git a/kernel/hal/x86/include/textDISP.hpp b/kernel/hal/x86/include/textDISP.hpp new file mode 100644 index 0000000..2d62396 --- /dev/null +++ b/kernel/hal/x86/include/textDISP.hpp @@ -0,0 +1,71 @@ +#ifndef _TEXTDISP_H +#define _TEXTDISP_H +#include +#include +#define SCREEN_WIDTH 80 +#define SCREEN_HEIGHT 24 +namespace MTGosHAL { + enum class BG_color : uint16_t { + BLACK=0x0000, + BLUE=0x1000, + GREEN=0x2000, + CYAN=0x3000, + RED=0x4000, + MAGENTA=0x5000, + BROWN=0x6000, + LIGHT_GREY=0x7000, + GREY=0x8000, + LIGHT_BLUE=0x9000, + LIGHT_GREEN=0xA000, + LIGHT_CYAN=0xB000, + LIGHT_RED=0xC000, + LIGHT_MAGENTA=0xD000, + YELLOW=0xE000, + WHITE=0xF000 + }; + enum class FG_color : uint16_t { + BLACK=0x000, + BLUE=0x100, + GREEN=0x200, + CYAN=0x300, + RED=0x400, + MAGENTA=0x500, + BROWN=0x600, + LIGHT_GREY=0x700, + GREY=0x800, + LIGHT_BLUE=0x900, + LIGHT_GREEN=0xA00, + LIGHT_CYAN=0xB00, + LIGHT_RED=0xC00, + LIGHT_MAGENTA=0xD00, + YELLOW=0xE00, + WHITE=0xF00 + }; + class Screen: public Output { + private: + FG_color fg; + BG_color bg; + int x,y; + uint16_t* vmem=(uint16_t*)0xB8000; + auto putChar(char c) -> void; + public: + Screen() { + clrscr(); + } + template + auto operator<< (T output) -> Screen & { + Output::operator<<(output); + return *this; + } + auto clrscr() -> void; + auto scroll() -> void; + auto setColor(FG_color fg) -> Screen &; + auto setColor(BG_color bg) -> Screen &; + auto setColor(FG_color fg, BG_color bg) -> Screen &; + }; + template <> + auto Screen::operator<<(FG_color fg) -> Screen &; + template <> + auto Screen::operator<<(BG_color bg) -> Screen &; +} +#endif diff --git a/kernel/hal/x86/init/init.cpp b/kernel/hal/x86/init/init.cpp index 3d09423..79cef21 100644 --- a/kernel/hal/x86/init/init.cpp +++ b/kernel/hal/x86/init/init.cpp @@ -1,15 +1,26 @@ +#include #include #include -namespace MTGosHAL { +#include +namespace MTGosHAL { + Serial* debug; + Screen* out; + Screen* err; void main() { Serial serialOUT(115200); - serialOUT << "This is the debug output of MTGos\n"; + Screen display; + debug=&serialOUT; + err=&display; + out=&display; + *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"; + for(;;); } } extern "C" void init() { MTGosHAL::main(); } extern "C" void __cxa_pure_virtual() { - for(;;); + *MTGosHAL::debug << "A pure virtual function just got called.\n"; } diff --git a/kernel/hal/x86/output/output.cpp b/kernel/hal/x86/output/output.cpp new file mode 100644 index 0000000..dda21a7 --- /dev/null +++ b/kernel/hal/x86/output/output.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +namespace MTGosHAL { + auto Output::puts(const char* s) -> void { + int i=0; + while(s[i]!='\0') + putChar(s[i++]); + } + template <> + auto Output::operator<<(Base output) -> Output & { + base=static_cast(output); + return *this; + } + template <> + auto Output::operator<<(int output) -> Output & { + const char* chars="0123456789ABCDEF"; + char buf[33]; + buf[32]='\0'; + char* ptr=buf+31; + do { + *(ptr--)=chars[output%base]; + output/=base; + } while(output && (ptr!=buf)); + puts(ptr+1); + return *this; + } + template <> + auto Output::operator<<(char output) -> Output & { + putChar(output); + return *this; + } + template <> + auto Output::operator<<(char* output) -> Output & { + puts(output); + return *this; + } +} diff --git a/kernel/hal/x86/output/textDISP.cpp b/kernel/hal/x86/output/textDISP.cpp new file mode 100644 index 0000000..1d0751c --- /dev/null +++ b/kernel/hal/x86/output/textDISP.cpp @@ -0,0 +1,56 @@ +#include +#include +namespace MTGosHAL { + auto Screen::putChar(char c) -> void { + switch(c) { + case '\n': + x=0; y++; + break; + case '\r': + x=0; + break; + case '\0': + break; + default: + vmem[y*SCREEN_WIDTH+(x++)]=((uint16_t)fg) | ((uint16_t)bg) | ((uint16_t)c); + if(x==SCREEN_WIDTH) { + x=0; y++; + } + break; + } + if(y>SCREEN_HEIGHT) + scroll(); + } + auto Screen::clrscr() -> void { + for(int p=0; p void { + for(int p=0; p + auto Screen::operator<<(FG_color fg) -> Screen &{ + this->fg=fg; + return *this; + } + template <> + auto Screen::operator<<(BG_color bg) -> Screen &{ + this->bg=bg; + return *this; + } + auto Screen::setColor(FG_color fg) -> Screen &{ + this->fg=fg; + return *this; + } + auto Screen::setColor(BG_color bg) -> Screen &{ + this->bg=bg; + return *this; + } + auto Screen::setColor(FG_color fg, BG_color bg) -> Screen &{ + return (*this).setColor(fg).setColor(bg); + } +}