diff --git a/CMakeLists.txt b/CMakeLists.txt index 569b2ac..eb72fbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,19 +14,21 @@ include_directories(OwOS "./") # Kernel source -file(GLOB KERN_SRC "*.asm" "*.cpp" "kernel/*.asm" "kernel/*.cpp") +file(GLOB KERN_SRC "*.asm" "*.cpp") +file(GLOB KERN_LIB_SRC "kernel/*.cpp" "kernel/*.asm") # Driver source -file(GLOB DRIV_DISP_VGA "kernel/drivers/VGA/*.asm" "kernel/drivers/VGA/*.cpp") -file(GLOB DRIV_DISP_TERM "kernel/drivers/terminal/*.asm" "kernel/drivers/terminal/*.cpp") +file(GLOB DRIV_DISP_VGA "kernel/drivers/VGA/*.cpp" "kernel/drivers/VGA/*.asm") +file(GLOB DRIV_DISP_TERM "kernel/drivers/terminal/*.cpp" "kernel/drivers/terminal/*.asm") # Lib source -file(GLOB LIB_STD "lib/std/*.asm" "lib/std/*.cpp") +file(GLOB LIB_STD "lib/std/*.cpp" "lib/std/*.asm") -set(SRCS ${KERN_SRC}) -add_executable(OwOS ${SRCS} ${DRIV_DISP_VGA} ${LIB_STD}) +add_executable(OwOS ${KERN_SRC} ${KERN_LIB_SRC} + ${DRIV_DISP_VGA} ${DRIV_DISP_TERM} + ${LIB_STD}) set_target_properties(OwOS PROPERTIES OUTPUT_NAME "OwOS.bin") diff --git a/build/OwOS.bin b/build/OwOS.bin index b99ede5..8960002 100755 Binary files a/build/OwOS.bin and b/build/OwOS.bin differ diff --git a/build/OwOS.iso b/build/OwOS.iso index 795f1a6..6991253 100644 Binary files a/build/OwOS.iso and b/build/OwOS.iso differ diff --git a/iso/boot/OwOS.bin b/iso/boot/OwOS.bin index 334be57..8960002 100644 Binary files a/iso/boot/OwOS.bin and b/iso/boot/OwOS.bin differ diff --git a/kernel.cpp b/kernel.cpp index 0016ee8..98fa373 100644 --- a/kernel.cpp +++ b/kernel.cpp @@ -1,21 +1,25 @@ #include +#include extern "C" int kernel_main() { - putchar(0, 0, 'H', 0x01, 0x07); - putchar(1, 0, 'A', 0x01, 0x07); - putchar(2, 0, 'H', 0x01, 0x07); - putchar(3, 0, 'A', 0x01, 0x07); - putchar(4, 0, '!', 0x01, 0x07); - putchar(5, 0, ' ', 0x01, 0x07); - putchar(6, 0, 'P', 0x01, 0x07); - putchar(7, 0, 'E', 0x01, 0x07); - putchar(8, 0, 'N', 0x01, 0x07); - putchar(9, 0, 'I', 0x01, 0x07); - putchar(10, 0, 'S', 0x01, 0x07); - putchar(11, 0, '!', 0x01, 0x07); + cls(); + showCursor(); + + putcar(0, 0, 'H', 0x01, 0x07); + putcar(1, 0, 'A', 0x01, 0x07); + putcar(2, 0, 'H', 0x01, 0x07); + putcar(3, 0, 'A', 0x01, 0x07); + putcar(4, 0, '!', 0x01, 0x07); + putcar(5, 0, ' ', 0x01, 0x07); + putcar(6, 0, 'P', 0x01, 0x07); + putcar(7, 0, 'E', 0x01, 0x07); + putcar(8, 0, 'N', 0x01, 0x07); + putcar(9, 0, 'I', 0x01, 0x07); + putcar(10, 0, 'S', 0x01, 0x07); + putcar(11, 0, '!', 0x01, 0x07); for (;;) asm("hlt"); diff --git a/kernel/drivers/VGA/vga.cpp b/kernel/drivers/VGA/vga.cpp index 18d1001..6d38c27 100644 --- a/kernel/drivers/VGA/vga.cpp +++ b/kernel/drivers/VGA/vga.cpp @@ -2,7 +2,7 @@ VGAChar_t* framebuffer = (VGAChar_t*)0xB8000; -void putchar(int x, int y, char c, char foreground, char background) { +void putcar(int x, int y, char c, char foreground, char background) { framebuffer[(y * TERM_WIDTH) + x].c = c; framebuffer[(y * TERM_WIDTH) + x].foreground = foreground; framebuffer[(y * TERM_WIDTH) + x].background = background; diff --git a/kernel/drivers/VGA/vga.h b/kernel/drivers/VGA/vga.h index 34076c2..fad8674 100644 --- a/kernel/drivers/VGA/vga.h +++ b/kernel/drivers/VGA/vga.h @@ -7,4 +7,4 @@ struct VGAChar_t { char background:4; }__attribute__((packed)); -void putchar(int x, int y, char c, char foreground, char background); +void putcar(int x, int y, char c, char foreground, char background); diff --git a/kernel/drivers/terminal/terminal.cpp b/kernel/drivers/terminal/terminal.cpp index e69de29..dad4f0f 100644 --- a/kernel/drivers/terminal/terminal.cpp +++ b/kernel/drivers/terminal/terminal.cpp @@ -0,0 +1,72 @@ +#include "terminal.h" + +#include + +static const int TERMINAL_WIDTH = 80; +static const int TERMINAL_HEIGHT = 24; + +static char* frameBuffer = (char*)0xB8000; + +static char clearColour = 0x0; +static char bgColour = 0x0; +static char fgColour = 0xF; + +struct Cursor { + uint8_t x; + uint8_t y; +} __attribute__((packed)); + +Cursor cursor; + +void cls() { + for (uint8_t x = 0; x < TERMINAL_WIDTH; x++) { + for (uint8_t y = 0; y < TERMINAL_HEIGHT; y++) { + frameBuffer[x + TERMINAL_WIDTH * y] = 0; + } + } + + moveCursor(0,0); +} + +void putchar(char input) { + +} + +void write(char* input) { + +} + +void writeln(char* input) { + write(input); + nline(); +} + +void nline() { + +} + +void setClearColour(char col) { + clearColour = col; +} + +void showCursor() { + outb(0x3D4, 0x0A); + outb(0x3D5, (inb(0x3D5) & 0xC0) | 1); + + outb(0x3D4, 0x0B); + outb(0x3D5, (inb(0x3D5) & 0xE0) | 1); +} + +void hideCursor() { + outb(0x3D4, 0x0A); + outb(0x3D5, 0x20); +} + +void moveCursor(int x, int y) { + uint16_t pos = y * TERMINAL_WIDTH + x; + + outb(0x3D4, 0x0F); + outb(0x3D5, (uint8_t) (pos & 0xFF)); + outb(0x3D4, 0x0E); + outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF)); +} diff --git a/kernel/drivers/terminal/terminal.h b/kernel/drivers/terminal/terminal.h index 7c64c9d..6466f0f 100644 --- a/kernel/drivers/terminal/terminal.h +++ b/kernel/drivers/terminal/terminal.h @@ -1,5 +1,37 @@ -#include +#include +#include -void clear(); -template -void print(T input); +enum { + BLACK = 0x0, + BLUE = 0x1, + GREEN = 0x2, + CYAN = 0x3, + RED = 0x4, + MAGENTA = 0x5, + BROWN = 0x6, + GREY = 0x7, + DARK_GREY = 0x8, + BRIGHT_BLUE = 0x9, + BRIGHT_GREEN = 0xA, + BRIGHT_CYAN = 0xB, + BRIGHT_RED = 0xC, + BRIGHT_MAGENTA = 0xD, + YELLOW = 0xE, + WHITE = 0xF, +}; + +void cls(); + +void putchar(char input); + +void write(char* input); +void writeln(char* input); + +void nline(); + +void setClearColour(char col); + +void showCursor(); +void hideCursor(); + +void moveCursor(int x, int y); diff --git a/kernel/kernio.cpp b/kernel/kernio.cpp index a968f1e..17c0573 100644 --- a/kernel/kernio.cpp +++ b/kernel/kernio.cpp @@ -1,13 +1 @@ #include "kernio.h" - -inline void outb(uint16_t port, uint8_t b) { - asm("outb %0, %1" : : "a"(b), "Nd"(port)); -} - -inline uint8_t inb(uint16_t port) { - uint8_t ret; - asm volatile ( "inb %1, %0" - : "=a"(ret) // Output - : "Nd"(port)); // Input - return ret; -} diff --git a/kernel/kernio.h b/kernel/kernio.h index 0d37f00..317287c 100644 --- a/kernel/kernio.h +++ b/kernel/kernio.h @@ -1,4 +1,14 @@ #include -inline void outb(uint16_t port, uint8_t b); -inline uint8_t inb(uint16_t port); +inline void outb(uint16_t port, uint8_t b) { + asm("outb %0, %1" : : "a"(b), "Nd"(port)); +} + +inline uint8_t inb(uint16_t port) { + uint8_t ret; + asm ( "inb %1, %0" + : "=a"(ret) // Output + : "Nd"(port)); // Input + return ret; +} +