diff --git a/tiny-os/source/fb.c b/tiny-os/source/fb.c new file mode 100644 index 0000000000000000000000000000000000000000..b75f30aa1f920d16bec8404302d5a618b66d1ce6 --- /dev/null +++ b/tiny-os/source/fb.c @@ -0,0 +1,37 @@ +#include "../include/fb.h" // Header file for framebuffer functions +#include "../include/io.h" // Include for outb function + +#define FB_COLS 80 // Number of columns in the framebuffer +#define FB_ROWS 25 // Number of rows in the framebuffer +#define FB_ADDR 0xB8000 // Starting address of the framebuffer + +// Function to clear the framebuffer +void fb_clear() { + char *fb = (char *)FB_ADDR; + for (int i = 0; i < FB_COLS * FB_ROWS; i++) { + fb[i * 2] = ' '; // Empty space + fb[i * 2 + 1] = 0x07; // Default color (white on black) + } +} + +// Function to print a string to the framebuffer at a specific location +void fb_print(const char *str, unsigned short row, unsigned short col) { + char *fb = (char *)FB_ADDR; + unsigned short pos = (row * FB_COLS + col) * 2; // Calculate position + + for (int i = 0; str[i] != '\0'; i++) { + fb[pos + i * 2] = str[i]; // Write character + fb[pos + i * 2 + 1] = 0x07; // Default color + } +} + +// Function to set the cursor position +void fb_move(unsigned short row, unsigned short col) { + unsigned short pos = row * FB_COLS + col; + + // Send the position to the VGA cursor registers + outb(0x3D4, 0x0F); // Low cursor byte + outb(0x3D5, (unsigned char)(pos & 0xFF)); + outb(0x3D4, 0x0E); // High cursor byte + outb(0x3D5, (unsigned char)((pos >> 8) & 0xFF)); +} diff --git a/tiny-os/source/fb.o b/tiny-os/source/fb.o new file mode 100644 index 0000000000000000000000000000000000000000..2f2b810f70b79fb02495e712d657f02db491f7a0 Binary files /dev/null and b/tiny-os/source/fb.o differ diff --git a/tiny-os/source/io.c b/tiny-os/source/io.c new file mode 100644 index 0000000000000000000000000000000000000000..a2b731fb2d2f99a08e63a770931923afb76e74fb --- /dev/null +++ b/tiny-os/source/io.c @@ -0,0 +1,6 @@ +#include "../include/io.h" + +// Function to send a byte to a specific hardware port +void outb(unsigned short port, unsigned char val) { + asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port)); +} diff --git a/tiny-os/source/io.o b/tiny-os/source/io.o new file mode 100644 index 0000000000000000000000000000000000000000..3c958d2b55d271c55f1db8cb66b558a73a24701a Binary files /dev/null and b/tiny-os/source/io.o differ diff --git a/tiny-os/source/kernel.c b/tiny-os/source/kernel.c new file mode 100644 index 0000000000000000000000000000000000000000..9ff22efded45285fefca3f33cb27c2295c05d819 --- /dev/null +++ b/tiny-os/source/kernel.c @@ -0,0 +1,16 @@ +#include "../include/fb.h" + +void kernel_main() { + // Clear the screen + fb_clear(); + + // Print messages using the framebuffer API + fb_print("Welcome to Tiny OS", 0, 0); // First row + fb_print("Framebuffer driver is working!", 1, 0); // Second row + + // Move the cursor to the third row + fb_move(2, 0); + + // Halt the CPU + while (1) {} +} diff --git a/tiny-os/source/kernel.o b/tiny-os/source/kernel.o new file mode 100644 index 0000000000000000000000000000000000000000..3eea2b44b3c8d8dfc8bf4fc8bbb6de451d50929c Binary files /dev/null and b/tiny-os/source/kernel.o differ diff --git a/tiny-os/source/link.ld b/tiny-os/source/link.ld new file mode 100644 index 0000000000000000000000000000000000000000..0a0ade33363ca750e01262dafe1875945fc6167a --- /dev/null +++ b/tiny-os/source/link.ld @@ -0,0 +1,15 @@ +ENTRY(loader) + +SECTIONS +{ + . = 0x100000; + + .text : { + *(.multiboot_header) + *(.text) + } + + .rodata : { *(.rodata) } + .data : { *(.data) } + .bss : { *(.bss) } +} diff --git a/tiny-os/source/loader.asm b/tiny-os/source/loader.asm new file mode 100644 index 0000000000000000000000000000000000000000..42137339678045683086a0db0935bf5888ea5b5b --- /dev/null +++ b/tiny-os/source/loader.asm @@ -0,0 +1,17 @@ +global loader +extern kernel_main ; Declare the external C function + +section .text +align 4 + +MAGIC_NUMBER equ 0x1BADB002 +FLAGS equ 0x0 +CHECKSUM equ -MAGIC_NUMBER + +dd MAGIC_NUMBER +dd FLAGS +dd CHECKSUM + +loader: + call kernel_main ; Call the C function + hlt ; Halt if it returns diff --git a/tiny-os/source/loader.o b/tiny-os/source/loader.o new file mode 100644 index 0000000000000000000000000000000000000000..b9e7e9aa55b23c173d132449bcddbb2e2b3245f1 Binary files /dev/null and b/tiny-os/source/loader.o differ