From 21719edafcecf63fe0e555fbb7ce8fd88b4cf557 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Thu, 16 Jun 2016 20:10:07 +0200 Subject: [PATCH] Some refactor --- kernel/Makefile | 2 +- kernel/hal/dummy/Makefile | 26 ------ kernel/hal/dummy/c_include/io.h | 53 ------------ kernel/hal/dummy/c_include/stdint.h | 9 -- kernel/hal/dummy/include/base.hpp | 24 ------ kernel/hal/dummy/include/pmm.hpp | 16 ---- kernel/hal/dummy/include/textDISP.hpp | 70 ---------------- kernel/hal/x86/Makefile | 4 +- kernel/hal/x86/include/Multitasking.hpp | 51 ++++++----- kernel/hal/x86/include/idt.hpp | 10 +-- kernel/hal/x86/include/input.hpp | 29 ------- kernel/hal/x86/include/keycodes.hpp | 41 --------- kernel/hal/x86/include/keymap_DE.hpp | 17 ---- kernel/hal/x86/include/output.hpp | 46 ---------- kernel/hal/x86/init/Multitasking.cpp | 6 +- kernel/hal/x86/init/idt.cpp | 4 +- kernel/hal/x86/io/keyboard.cpp | 7 +- kernel/hal/x86/io/textDISP.cpp | 78 ----------------- kernel/{kernel.ld => kernel-x86.ld} | 0 kernel/kernel-x86_64.ld | 31 +++++++ kernel/kernel/Makefile | 4 +- kernel/kernel/c_include/cpu_state.h | 2 + kernel/{hal/dummy => kernel}/c_include/elf.h | 0 .../{hal/dummy => kernel}/c_include/macro.h | 0 kernel/kernel/c_include/stdint.h | 21 +++++ .../{hal/dummy => kernel}/c_include/string.h | 6 +- .../include/Multitasking.hpp} | 2 +- kernel/{hal/x86 => kernel}/include/base.hpp | 0 .../dummy => kernel}/include/blockdev.hpp | 0 .../{hal/dummy => kernel}/include/input.hpp | 0 .../dummy => kernel}/include/keyboard.hpp | 3 - .../dummy => kernel}/include/keycodes.hpp | 19 ++--- .../dummy => kernel}/include/keymap_DE.hpp | 0 .../{hal/dummy => kernel}/include/output.hpp | 0 kernel/kernel/include/pmm.hpp | 20 +++++ .../{hal/dummy => kernel}/include/serial.hpp | 4 - .../x86/c_include => kernel/include}/stdfnt.h | 2 +- kernel/kernel/include/textDISP.hpp | 70 ++++++++++++++++ kernel/kernel/init.cpp | 2 +- kernel/{hal/x86 => kernel}/io/output.cpp | 0 kernel/kernel/io/textDISP.cpp | 84 +++++++++++++++++++ 41 files changed, 287 insertions(+), 476 deletions(-) delete mode 100644 kernel/hal/dummy/Makefile delete mode 100644 kernel/hal/dummy/c_include/io.h delete mode 100644 kernel/hal/dummy/c_include/stdint.h delete mode 100644 kernel/hal/dummy/include/base.hpp delete mode 100644 kernel/hal/dummy/include/pmm.hpp delete mode 100644 kernel/hal/dummy/include/textDISP.hpp delete mode 100644 kernel/hal/x86/include/input.hpp delete mode 100644 kernel/hal/x86/include/keycodes.hpp delete mode 100644 kernel/hal/x86/include/keymap_DE.hpp delete mode 100644 kernel/hal/x86/include/output.hpp rename kernel/{kernel.ld => kernel-x86.ld} (100%) create mode 100644 kernel/kernel-x86_64.ld create mode 100644 kernel/kernel/c_include/cpu_state.h rename kernel/{hal/dummy => kernel}/c_include/elf.h (100%) rename kernel/{hal/dummy => kernel}/c_include/macro.h (100%) create mode 100644 kernel/kernel/c_include/stdint.h rename kernel/{hal/dummy => kernel}/c_include/string.h (54%) rename kernel/{hal/dummy/include/Multitasking.h => kernel/include/Multitasking.hpp} (96%) rename kernel/{hal/x86 => kernel}/include/base.hpp (100%) rename kernel/{hal/dummy => kernel}/include/blockdev.hpp (100%) rename kernel/{hal/dummy => kernel}/include/input.hpp (100%) rename kernel/{hal/dummy => kernel}/include/keyboard.hpp (77%) rename kernel/{hal/dummy => kernel}/include/keycodes.hpp (73%) rename kernel/{hal/dummy => kernel}/include/keymap_DE.hpp (100%) rename kernel/{hal/dummy => kernel}/include/output.hpp (100%) create mode 100644 kernel/kernel/include/pmm.hpp rename kernel/{hal/dummy => kernel}/include/serial.hpp (87%) rename kernel/{hal/x86/c_include => kernel/include}/stdfnt.h (99%) create mode 100644 kernel/kernel/include/textDISP.hpp rename kernel/{hal/x86 => kernel}/io/output.cpp (100%) create mode 100644 kernel/kernel/io/textDISP.cpp diff --git a/kernel/Makefile b/kernel/Makefile index d973f22..f315c41 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -6,7 +6,7 @@ OBJS += $(addsuffix .o,$(basename $(KERNSRCS))) LD = $(PREFIX)g++ LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin ifeq ($(arch),x86) - LDFLAGS += -m32 -T kernel.ld + LDFLAGS += -m32 -T kernel-$(arch).ld endif all: hal kernel $(LD) $(LDFLAGS) -o mtgos $(OBJS) diff --git a/kernel/hal/dummy/Makefile b/kernel/hal/dummy/Makefile deleted file mode 100644 index 312a18a..0000000 --- a/kernel/hal/dummy/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -include ../../../kernel.settings -SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]') -OBJS = $(addsuffix .o,$(basename $(SRCS))) - -CPP = $(PREFIX)g++ -CC = $(PREFIX)gcc -ASFLAGS = -CFLAGS = -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib -g -CPPFLAGS = -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 -g -LDFLAGS = -r - -all: $(OBJS) - -%.o: %.cpp - $(CPP) $(CPPFLAGS) -c -o $@ $^ - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $^ - -%.o: $.S - $(CC) $(CFLAGS) -c -o $@ $^ - -clean: - rm -rf $(OBJS) - -.PHONY: clean all diff --git a/kernel/hal/dummy/c_include/io.h b/kernel/hal/dummy/c_include/io.h deleted file mode 100644 index 990e441..0000000 --- a/kernel/hal/dummy/c_include/io.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _IO_H -#define _IO_H -#include -static inline void outb(uint16_t port, uint8_t val) __attribute__((always_inline)); -static inline void outb(uint16_t port, uint8_t val) { - asm volatile("outb %0, %1" : : "a"(val), "Nd"(port)); -} -static inline void outw(uint16_t port, uint16_t val) __attribute__((always_inline)); -static inline void outw(uint16_t port, uint16_t val) { - asm volatile("outw %0, %1" : : "a"(val), "Nd"(port)); -} -static inline void outl(uint16_t port, uint32_t val) __attribute__((always_inline)); -static inline void outl(uint16_t port, uint32_t val) { - asm volatile("outl %0, %1" : : "a"(val), "Nd"(port)); -} -static inline uint8_t inb(uint16_t port) __attribute__((always_inline)); -static inline uint8_t inb(uint16_t port) { - uint8_t ret; - asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} -static inline uint16_t inw(uint16_t port) __attribute__((always_inline)); -static inline uint16_t inw(uint16_t port) { - uint16_t ret; - asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} -static inline uint32_t inl(uint16_t port) __attribute__((always_inline)); -static inline uint32_t inl(uint16_t port) { - uint32_t ret; - asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port)); - return ret; -} -static inline void io_wait() __attribute__((always_inline)); -static inline void io_wait() { - asm volatile("outb %%al, $0x80" : : "a"(0)); -} -static inline void cli() __attribute__((always_inline)); -static inline void cli() { - asm volatile("cli"); -} -static inline void sti() __attribute__((always_inline)); -static inline void sti() { - asm volatile("sti"); -} -static inline uint64_t rdtsc() __attribute__((always_inline)); -static inline uint64_t rdtsc() -{ - uint64_t ret; - asm volatile ( "rdtsc" : "=A"(ret) ); - return ret; -} -#endif diff --git a/kernel/hal/dummy/c_include/stdint.h b/kernel/hal/dummy/c_include/stdint.h deleted file mode 100644 index 2926bb5..0000000 --- a/kernel/hal/dummy/c_include/stdint.h +++ /dev/null @@ -1,9 +0,0 @@ -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed int int32_t; -typedef signed long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; -typedef unsigned int uintptr_t; diff --git a/kernel/hal/dummy/include/base.hpp b/kernel/hal/dummy/include/base.hpp deleted file mode 100644 index 839f817..0000000 --- a/kernel/hal/dummy/include/base.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _BASE_HPP -#define _BASE_HPP -#include -namespace MTGosHAL { - class Output; - class Input; - class Serial; - class Screen; - class Keyboard; - class Multitasking; - class BlockDevice; - class Task; - class PMM; - enum class BG_color: uint16_t; - enum class FG_color: uint16_t; - extern Serial debug; - extern Screen out; - extern Screen err; - extern Keyboard in; - extern Multitasking tasks; - extern BlockDevice disk; - extern PMM mm; -} -#endif diff --git a/kernel/hal/dummy/include/pmm.hpp b/kernel/hal/dummy/include/pmm.hpp deleted file mode 100644 index 99b64d8..0000000 --- a/kernel/hal/dummy/include/pmm.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _PMM_HPP -#define _PMM_HPP -#include -namespace MTGosHAL { -class PMM { -private: - uint32_t bitmap[0x8000]; //Enough for 4 GB -public: - auto markUsed(void * addr) -> void; - auto init(struct multiboot_info*) -> void; - auto operator >> (void * &addr) -> PMM &; //alloc - auto operator << (const void * addr) -> PMM &; //free - auto operator () (uint32_t len) -> void*; -}; -} -#endif diff --git a/kernel/hal/dummy/include/textDISP.hpp b/kernel/hal/dummy/include/textDISP.hpp deleted file mode 100644 index b91d12d..0000000 --- a/kernel/hal/dummy/include/textDISP.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#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; - 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/Makefile b/kernel/hal/x86/Makefile index 17a221b..e4c7cf2 100644 --- a/kernel/hal/x86/Makefile +++ b/kernel/hal/x86/Makefile @@ -5,8 +5,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS))) CPP = $(PREFIX)g++ CC = $(PREFIX)gcc ASFLAGS = -m32 -CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie -CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder +CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../kernel/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie +CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../kernel/c_include -I../../kernel/include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder LDFLAGS = -r -melf_i386 diff --git a/kernel/hal/x86/include/Multitasking.hpp b/kernel/hal/x86/include/Multitasking.hpp index 2afe622..41f4b9c 100644 --- a/kernel/hal/x86/include/Multitasking.hpp +++ b/kernel/hal/x86/include/Multitasking.hpp @@ -1,34 +1,31 @@ #ifndef MULTITASKING_H #define MULTITASKING_H -#define PID_KERNEL 0 -#define PID_INIT 1 -#include namespace MTGosHAL { - class Multitasking - { - public: - Multitasking(); - auto schedule(struct cpu_state* cpu) -> struct cpu_state*; - auto initTask(void(*entry)()) -> struct cpu_state*; - uint32_t tss[32]; - protected: - private: - Task* first_task; - Task* curr_task; - }; - class Task - { - private: - struct cpu_state* cpu_state; - Task* next; - public: - Task(struct cpu_state*); - auto unpause() -> struct cpu_state*; - auto pause(struct cpu_state*) -> Task *; - auto addTask(Task*) -> void; - auto hasNext() -> bool; - }; + class Multitasking + { + public: + Multitasking(); + auto schedule(struct cpu_state* cpu) -> struct cpu_state*; + auto initTask(void(*entry)()) -> struct cpu_state*; + uint32_t tss[32]; + protected: + private: + Task* first_task; + Task* curr_task; + }; + class Task + { + private: + struct cpu_state* cpu_state; + Task* next; + public: + Task(struct cpu_state*); + auto unpause() -> struct cpu_state*; + auto pause(struct cpu_state*) -> Task *; + auto addTask(Task*) -> void; + auto hasNext() -> bool; + }; } // namespace MTGosHAL diff --git a/kernel/hal/x86/include/idt.hpp b/kernel/hal/x86/include/idt.hpp index 2ef184b..37e6aed 100644 --- a/kernel/hal/x86/include/idt.hpp +++ b/kernel/hal/x86/include/idt.hpp @@ -13,8 +13,10 @@ #define SEG_DBL_FAULT 0x28 /*Only use for double fault handler!!*/ extern "C" { void loadIDT(void * ptr); +} + +namespace MTGosHAL { struct cpu_state { - // Von Hand gesicherte Register uint32_t eax; uint32_t ebx; uint32_t ecx; @@ -22,17 +24,16 @@ extern "C" { uint32_t esi; uint32_t edi; uint32_t ebp; + uint32_t intr; uint32_t error; - // Von der CPU gesichert + uint32_t eip; uint32_t cs; uint32_t eflags; uint32_t esp; uint32_t ss; }; -} -namespace MTGosHAL { class IDT { private: uint64_t idt[256]; @@ -50,5 +51,4 @@ namespace MTGosHAL { auto request(uint8_t intr, struct cpu_state* (*handler)(struct cpu_state*)) -> bool; }; } -extern "C" struct cpu_state* handleINT(struct cpu_state* cpu); #endif diff --git a/kernel/hal/x86/include/input.hpp b/kernel/hal/x86/include/input.hpp deleted file mode 100644 index ed55198..0000000 --- a/kernel/hal/x86/include/input.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _INPUT_HPP -#define _INPUT_HPP -namespace MTGosHAL { - class Input { - private: - virtual auto getChar() -> char = 0; - public: - auto operator>>(char &input) -> Input & { - input=getChar(); - return *this; - } - //Note that it receives up to 256 bytes. - auto operator>>(char* input) -> Input & { - int ptr=0; - char tmp='\0'; - while(ptr<256 && tmp!='\r') { - while(!(tmp=getChar())); - if(tmp=='\r') - input[ptr++]='\0'; - else - input[ptr++]=tmp; - } - input[255]='\0'; - return *this; - } - //TODO: Add more possibilities. - }; -} -#endif diff --git a/kernel/hal/x86/include/keycodes.hpp b/kernel/hal/x86/include/keycodes.hpp deleted file mode 100644 index c79a76f..0000000 --- a/kernel/hal/x86/include/keycodes.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _KEYCODES_HPP -#define _KEYCODES_HPP -bool keydowns[0x69]; -uint8_t keyboardKeycodes[2][128] { - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x00, 0x00, 0x54, 0x55, - 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }, { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x57, 0x58, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, - 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5B, - 0x5C, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00, 0x60, - 0x61, 0x62, 0x63, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x64, 0x65, 0x66, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - } -}; -#endif - diff --git a/kernel/hal/x86/include/keymap_DE.hpp b/kernel/hal/x86/include/keymap_DE.hpp deleted file mode 100644 index baeda85..0000000 --- a/kernel/hal/x86/include/keymap_DE.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _KEYMAP_DE_HPP -#define _KEYMAP_DE_HPP -#include -#define SHIFT 1 -#define CTRL 2 -#define ALT 4 -char keymap[8][0x80] = { - "\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\000789-456+1230,<\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // No modifier - "\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Shift modifier - "\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control modifier - "\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers - "\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt modifier - "\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt+Shift modifiers - "\0\0001\xFD\x33\xAC\xAB\xAA{[]}\\\xa7\b\0@w\xEErtzui\xEDp\x81~\n\0\x91sdfghjkl\x94^\0#\xAF\xAE\x9Bvbn\xe6,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Alt modifiers - "\0\000\xAD\"\x9C\x0F%&/(\xF1\xF8\xA8`\b\0\xEAW\xEERT\x9DUIOP\xF8*\n\0\x92SD\xA6GHJ&L\x99\x8e\xF8\0|YXCVBN\xF8;\xF6_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers -}; -#endif diff --git a/kernel/hal/x86/include/output.hpp b/kernel/hal/x86/include/output.hpp deleted file mode 100644 index 143b182..0000000 --- a/kernel/hal/x86/include/output.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _OUTPUT_HPP -#define _OUTPUT_HPP -#include -#include -namespace MTGosHAL { - - enum class Base : int { - BINARY=2, - TERNARY, - BASE4, - BASE5, - BASE6, - BASE7, - OCTAL, - BASE9, - DECIMAL, - BASE11, - BASE12, - BASE13, - BASE14, - BASE15, - HEXADECIMAL - }; - /* abstract */ class Output { - private: - virtual auto putChar(char c) -> void = 0; - auto puts(const char* s) -> void; - int base=10; - public: - template - auto operator<<(T output) -> Output & { - puts(output); //kernel won't compile if class cannot be converted into string - return *this; - } - - }; - template <> - auto Output::operator<<(Base output) -> Output &; - template <> - auto Output::operator<<(int output) -> Output &; - template <> - auto Output::operator<<(char output) -> Output &; - template <> - auto Output::operator<<(char* output) -> Output &; -} -#endif diff --git a/kernel/hal/x86/init/Multitasking.cpp b/kernel/hal/x86/init/Multitasking.cpp index cb413b3..ff20343 100644 --- a/kernel/hal/x86/init/Multitasking.cpp +++ b/kernel/hal/x86/init/Multitasking.cpp @@ -3,12 +3,12 @@ #include #include #include +#include #include +namespace MTGosHAL { auto schedule(struct cpu_state* cpu) -> struct cpu_state* { return MTGosHAL::tasks.schedule(cpu); } -namespace MTGosHAL { - Multitasking::Multitasking(): curr_task(nullptr), first_task(nullptr) { for(int i=0;i<32;i++) { @@ -19,7 +19,7 @@ Multitasking::Multitasking(): curr_task(nullptr), first_task(nullptr) tss[2]=0x10; //task_states[0] = initTask(stack_a, user_stack_a, task_a); //task_states[1] = initTask(stack_b, user_stack_b, task_b); - if(!idt.request(0x20,::schedule)) { + if(!idt.request(0x20,MTGosHAL::schedule)) { err << "Could not start multitasking\nFatal error; Kernel halted!\n"; while(true) asm volatile("cli; hlt"); diff --git a/kernel/hal/x86/init/idt.cpp b/kernel/hal/x86/init/idt.cpp index a138b16..89a482b 100644 --- a/kernel/hal/x86/init/idt.cpp +++ b/kernel/hal/x86/init/idt.cpp @@ -86,6 +86,6 @@ namespace MTGosHAL { return false; } } -extern "C" struct cpu_state* handleINT(struct cpu_state* cpu) { - return MTGosHAL::idt.handle(cpu); +extern "C" void* handleINT(void* cpu) { + return (void*)MTGosHAL::idt.handle((MTGosHAL::cpu_state*)cpu); } diff --git a/kernel/hal/x86/io/keyboard.cpp b/kernel/hal/x86/io/keyboard.cpp index 1bd01e4..9ee9c4e 100644 --- a/kernel/hal/x86/io/keyboard.cpp +++ b/kernel/hal/x86/io/keyboard.cpp @@ -3,10 +3,11 @@ #include #include #include -auto handleIRQ(struct cpu_state* cpu) -> struct cpu_state* { - return MTGosHAL::in.handleIRQ1(cpu); -} + namespace MTGosHAL { + auto handleIRQ(struct cpu_state* cpu) -> struct cpu_state* { + return in.handleIRQ1(cpu); + } auto Keyboard::getChar() -> char { char chr=buf[0]; for(int i=0;i<15;i++) { diff --git a/kernel/hal/x86/io/textDISP.cpp b/kernel/hal/x86/io/textDISP.cpp index 77af38e..52bc3ee 100644 --- a/kernel/hal/x86/io/textDISP.cpp +++ b/kernel/hal/x86/io/textDISP.cpp @@ -2,85 +2,7 @@ #include #include #include -int x=0, y=0; namespace MTGosHAL { - auto Screen::putChar(char c) -> void { - switch(c) { - case '\n': - x=0; y++; - break; - case '\r': - x=0; - - break; - case '\b': - x--; - if(x<0) x=0; - putChar(' '); - x--; - if(x<0) x=0; - break; - case '\0': - break; - default: - for(int lx=0;lx<8;lx++) { - for(int ly=0;ly<8;ly++) { - if(font[(int)((uint8_t)c)][ly]&(1<(fg); - } else { - lfb[(x*8+lx)+(y*8+ly)*1024]=0x000000;//static_cast(bg); - } - } - } - x++; - if(x==SCREEN_WIDTH) { - x=0; y++; - } - break; - } - if(y>SCREEN_HEIGHT) - scroll(); - } - auto Screen::clrscr() -> void { - for(int p=0;p<1024*786;p++) { - lfb[p]=0x000000;//static_cast(bg); - } - x=y=0; - } - auto Screen::scroll() -> void { - for(int ly=0;ly<786-8;ly++) { - for(int lx=0;lx<1024;lx++) { - lfb[lx+ly*1024]=lfb[lx+(ly+8)*1024]; - } - } - for(int ly=786-8;ly<786;ly++) { - for(int lx=0;lx<1024;lx++) { - lfb[lx+ly*1024]=0x000000;//static_cast(bg); - } - } - y--; - } - template <> - 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); - } auto Screen::init(struct multiboot_info* mb_info) -> void { lfb=(uint32_t*)((uint32_t)mb_info->framebuffer_addr); //clrscr(); diff --git a/kernel/kernel.ld b/kernel/kernel-x86.ld similarity index 100% rename from kernel/kernel.ld rename to kernel/kernel-x86.ld diff --git a/kernel/kernel-x86_64.ld b/kernel/kernel-x86_64.ld new file mode 100644 index 0000000..5ebe4d2 --- /dev/null +++ b/kernel/kernel-x86_64.ld @@ -0,0 +1,31 @@ +ENTRY(_start) +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386:x86-64) +SECTIONS +{ + . = 0x100000; + kernel_start = .; + .text : { + *(multiboot) + *(.text) + } + .data ALIGN(4096) : { + start_ctors = .; + KEEP(*( .init_array )); + KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ))); + *(.ctors) + end_ctors = .; + start_dtors = .; + *(.dtors) + end_dtors = .; + *(.data) + } + .rodata ALIGN(4096) : { + *(.rodata) + } + .bss ALIGN(4096) : { + *(.bss) + } + . = ALIGN(4096); + kernel_end = .; +} diff --git a/kernel/kernel/Makefile b/kernel/kernel/Makefile index f89888d..99b6b11 100644 --- a/kernel/kernel/Makefile +++ b/kernel/kernel/Makefile @@ -4,8 +4,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS))) CPP = $(PREFIX)g++ CC = $(PREFIX)gcc ASFLAGS = -m32 -CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../hal/dummy/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie -CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../hal/dummy/include -I../hal/dummy/c_include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpie +CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie +CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpie all: $(OBJS) %.o: %.cpp diff --git a/kernel/kernel/c_include/cpu_state.h b/kernel/kernel/c_include/cpu_state.h new file mode 100644 index 0000000..ad3d683 --- /dev/null +++ b/kernel/kernel/c_include/cpu_state.h @@ -0,0 +1,2 @@ +struct cpu_state { +}; //Empty struct diff --git a/kernel/hal/dummy/c_include/elf.h b/kernel/kernel/c_include/elf.h similarity index 100% rename from kernel/hal/dummy/c_include/elf.h rename to kernel/kernel/c_include/elf.h diff --git a/kernel/hal/dummy/c_include/macro.h b/kernel/kernel/c_include/macro.h similarity index 100% rename from kernel/hal/dummy/c_include/macro.h rename to kernel/kernel/c_include/macro.h diff --git a/kernel/kernel/c_include/stdint.h b/kernel/kernel/c_include/stdint.h new file mode 100644 index 0000000..314b8da --- /dev/null +++ b/kernel/kernel/c_include/stdint.h @@ -0,0 +1,21 @@ +#ifndef __LP64__ +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long long int int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef unsigned int uintptr_t; +#else +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long int int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long int uint64_t; +typedef unsigned long int uintptr_t; +#endif diff --git a/kernel/hal/dummy/c_include/string.h b/kernel/kernel/c_include/string.h similarity index 54% rename from kernel/hal/dummy/c_include/string.h rename to kernel/kernel/c_include/string.h index f31a22e..6073285 100644 --- a/kernel/hal/dummy/c_include/string.h +++ b/kernel/kernel/c_include/string.h @@ -1,11 +1,13 @@ #ifndef _STRING_H #define _STRING_H -#ifdef _cplusplus +#ifdef __cplusplus extern "C" { #endif #include void memmove(void* dst, void* src, uint32_t size); -#ifdef _cplusplus +uint32_t strlen(const char* str); +int strcmp(const char* str1, const char* str2); +#ifdef __cplusplus } #endif #endif diff --git a/kernel/hal/dummy/include/Multitasking.h b/kernel/kernel/include/Multitasking.hpp similarity index 96% rename from kernel/hal/dummy/include/Multitasking.h rename to kernel/kernel/include/Multitasking.hpp index 41f4b9c..9a96aa0 100644 --- a/kernel/hal/dummy/include/Multitasking.h +++ b/kernel/kernel/include/Multitasking.hpp @@ -1,5 +1,6 @@ #ifndef MULTITASKING_H #define MULTITASKING_H +#include namespace MTGosHAL { class Multitasking @@ -8,7 +9,6 @@ namespace MTGosHAL { Multitasking(); auto schedule(struct cpu_state* cpu) -> struct cpu_state*; auto initTask(void(*entry)()) -> struct cpu_state*; - uint32_t tss[32]; protected: private: Task* first_task; diff --git a/kernel/hal/x86/include/base.hpp b/kernel/kernel/include/base.hpp similarity index 100% rename from kernel/hal/x86/include/base.hpp rename to kernel/kernel/include/base.hpp diff --git a/kernel/hal/dummy/include/blockdev.hpp b/kernel/kernel/include/blockdev.hpp similarity index 100% rename from kernel/hal/dummy/include/blockdev.hpp rename to kernel/kernel/include/blockdev.hpp diff --git a/kernel/hal/dummy/include/input.hpp b/kernel/kernel/include/input.hpp similarity index 100% rename from kernel/hal/dummy/include/input.hpp rename to kernel/kernel/include/input.hpp diff --git a/kernel/hal/dummy/include/keyboard.hpp b/kernel/kernel/include/keyboard.hpp similarity index 77% rename from kernel/hal/dummy/include/keyboard.hpp rename to kernel/kernel/include/keyboard.hpp index 8a5c9fd..598f710 100644 --- a/kernel/hal/dummy/include/keyboard.hpp +++ b/kernel/kernel/include/keyboard.hpp @@ -2,7 +2,6 @@ #define _KEYBOARD_HPP #include #include -#include namespace MTGosHAL { class Keyboard: public Input { @@ -12,8 +11,6 @@ namespace MTGosHAL { char buf[16]; int len; auto getChar() -> char; - auto sendCommand(uint8_t command) -> void; - bool numlock, capslock, scrolllock, response; public: auto handleIRQ1(struct cpu_state* cpu) -> struct cpu_state*; Keyboard(); diff --git a/kernel/hal/dummy/include/keycodes.hpp b/kernel/kernel/include/keycodes.hpp similarity index 73% rename from kernel/hal/dummy/include/keycodes.hpp rename to kernel/kernel/include/keycodes.hpp index c79a76f..f5f1532 100644 --- a/kernel/hal/dummy/include/keycodes.hpp +++ b/kernel/kernel/include/keycodes.hpp @@ -19,23 +19,22 @@ uint8_t keyboardKeycodes[2][128] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x58, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5B, 0x5C, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00, 0x60, 0x61, 0x62, 0x63, 0x64, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x64, 0x65, 0x66, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x64, 0x65, 0x66, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; #endif - diff --git a/kernel/hal/dummy/include/keymap_DE.hpp b/kernel/kernel/include/keymap_DE.hpp similarity index 100% rename from kernel/hal/dummy/include/keymap_DE.hpp rename to kernel/kernel/include/keymap_DE.hpp diff --git a/kernel/hal/dummy/include/output.hpp b/kernel/kernel/include/output.hpp similarity index 100% rename from kernel/hal/dummy/include/output.hpp rename to kernel/kernel/include/output.hpp diff --git a/kernel/kernel/include/pmm.hpp b/kernel/kernel/include/pmm.hpp new file mode 100644 index 0000000..dbe0dc2 --- /dev/null +++ b/kernel/kernel/include/pmm.hpp @@ -0,0 +1,20 @@ +#ifndef _PMM_HPP +#define _PMM_HPP +#include +namespace MTGosHAL { +struct malloc_t { + uint32_t len; + malloc_t *last; + malloc_t *next; +}; +class PMM { +private: + malloc_t *head; +public: + PMM(); + auto init(void *) -> void; + auto alloc(uint32_t length) -> void *; + auto free(void* ptr) -> bool; +}; +} +#endif diff --git a/kernel/hal/dummy/include/serial.hpp b/kernel/kernel/include/serial.hpp similarity index 87% rename from kernel/hal/dummy/include/serial.hpp rename to kernel/kernel/include/serial.hpp index 71399c6..8adfee8 100644 --- a/kernel/hal/dummy/include/serial.hpp +++ b/kernel/kernel/include/serial.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #define SERIAL_IER 1 #define SERIAL_IIR 2 #define SERIAL_FCR 2 @@ -14,9 +13,6 @@ namespace MTGosHAL { class Serial: public Output, public Input { private: - uint16_t port; - uint64_t waittimes; - uint64_t transmits; bool works; auto isTransmitEmpty() -> int; auto putChar(char chr) -> void; diff --git a/kernel/hal/x86/c_include/stdfnt.h b/kernel/kernel/include/stdfnt.h similarity index 99% rename from kernel/hal/x86/c_include/stdfnt.h rename to kernel/kernel/include/stdfnt.h index 2539d9b..d8eb41c 100644 --- a/kernel/hal/x86/c_include/stdfnt.h +++ b/kernel/kernel/include/stdfnt.h @@ -1,6 +1,6 @@ //Thanks to masterq32 for this font! //You should check out his OS project (https://github.com/MasterQ32/DasOS) -uint8_t font[256][8] = { +static uint8_t font[256][8] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // ? { 0x00, 0x00, 0x0D, 0x12, 0x12, 0x09, 0x09, 0x00 }, // ? { 0x00, 0x00, 0x11, 0x11, 0x11, 0x19, 0x16, 0x00 }, // ? diff --git a/kernel/kernel/include/textDISP.hpp b/kernel/kernel/include/textDISP.hpp new file mode 100644 index 0000000..6a18f40 --- /dev/null +++ b/kernel/kernel/include/textDISP.hpp @@ -0,0 +1,70 @@ +#ifndef _TEXTDISP_H +#define _TEXTDISP_H +#include +#include +#include +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 96 +namespace MTGosHAL { + enum class BG_color : uint32_t { + BLACK=0x000000, + BLUE=0x0000AA, + GREEN=0x00AA00, + CYAN=0x00AAAA, + RED=0xAA0000, + MAGENTA=0xAA00AA, + BROWN=0xAA5500, + LIGHT_GREY=0xAAAAAA, + GREY=0x555555, + LIGHT_BLUE=0x5555FF, + LIGHT_GREEN=0x55FF55, + LIGHT_CYAN=0x55FFFF, + LIGHT_RED=0xFF5555, + LIGHT_MAGENTA=0xFF55FF, + YELLOW=0xFFFF55, + WHITE=0xFFFFFF + }; + enum class FG_color : uint32_t { + BLACK=0x000000, + BLUE=0x0000AA, + GREEN=0x00AA00, + CYAN=0x00AAAA, + RED=0xAA0000, + MAGENTA=0xAA00AA, + BROWN=0xAA5500, + LIGHT_GREY=0xAAAAAA, + GREY=0x555555, + LIGHT_BLUE=0x5555FF, + LIGHT_GREEN=0x55FF55, + LIGHT_CYAN=0x55FFFF, + LIGHT_RED=0xFF5555, + LIGHT_MAGENTA=0xFF55FF, + YELLOW=0xFFFF55, + WHITE=0xFFFFFF + }; + class Screen: public Output { + private: + FG_color fg; + BG_color bg; + uint32_t* lfb; + auto putChar(char c) -> void; + public: + Screen(): fg(FG_color::WHITE), bg(BG_color::BLACK) { + } + 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/kernel/init.cpp b/kernel/kernel/init.cpp index 2b489cd..98c55c8 100644 --- a/kernel/kernel/init.cpp +++ b/kernel/kernel/init.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include using namespace MTGosHAL; diff --git a/kernel/hal/x86/io/output.cpp b/kernel/kernel/io/output.cpp similarity index 100% rename from kernel/hal/x86/io/output.cpp rename to kernel/kernel/io/output.cpp diff --git a/kernel/kernel/io/textDISP.cpp b/kernel/kernel/io/textDISP.cpp new file mode 100644 index 0000000..dd142c7 --- /dev/null +++ b/kernel/kernel/io/textDISP.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +int x=0, y=0; +namespace MTGosHAL { + auto Screen::putChar(char c) -> void { + switch(c) { + case '\n': + x=0; y++; + break; + case '\r': + x=0; + + break; + case '\b': + x--; + if(x<0) x=0; + putChar(' '); + x--; + if(x<0) x=0; + break; + case '\0': + break; + default: + for(int lx=0;lx<8;lx++) { + for(int ly=0;ly<8;ly++) { + if(font[(int)((uint8_t)c)][ly]&(1<(fg); + } else { + lfb[(x*8+lx)+(y*8+ly)*1024]=0x000000;//static_cast(bg); + } + } + } + x++; + if(x==SCREEN_WIDTH) { + x=0; y++; + } + break; + } + if(y>SCREEN_HEIGHT) + scroll(); + } + auto Screen::clrscr() -> void { + for(int p=0;p<1024*786;p++) { + lfb[p]=0x000000;//static_cast(bg); + } + x=y=0; + } + auto Screen::scroll() -> void { + for(int ly=0;ly<786-8;ly++) { + for(int lx=0;lx<1024;lx++) { + lfb[lx+ly*1024]=lfb[lx+(ly+8)*1024]; + } + } + for(int ly=786-8;ly<786;ly++) { + for(int lx=0;lx<1024;lx++) { + lfb[lx+ly*1024]=0x000000;//static_cast(bg); + } + } + y--; + } + template <> + 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); + } +}