diff --git a/Makefile b/Makefile index 697e49f..2ad7c66 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ SRC_DIR=src BUILD_DIR=build ISO_DIR=$(BUILD_DIR)/iso +INCLUDE_DIR=$(SRC_DIR)/kernel/include + KERNEL_ASM := $(shell find $(SRC_DIR)/kernel -name "*.asm") KERNEL_C := $(shell find $(SRC_DIR)/kernel -name "*.c") @@ -31,7 +33,7 @@ $(BUILD_DIR)/%.asm.o: $(SRC_DIR)/%.asm $(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c @mkdir -p "$(@D)" - $(CC) -c $< -o $@ -std=gnu99 -ffreestanding -O2 -Wall -Wextra + $(CC) -c $< -o $@ -I$(INCLUDE_DIR) -std=gnu99 -ffreestanding -O2 -Wall -Wextra clean: rm -rf $(BUILD_DIR)/* diff --git a/src/kernel/include/string.h b/src/kernel/include/string.h new file mode 100644 index 0000000..4f6049d --- /dev/null +++ b/src/kernel/include/string.h @@ -0,0 +1,7 @@ +#ifndef _CLIPPER_STRING_H_ +#define _CLIPPER_STRING_H_ + +void putch(char c); +void puts(const char* str); + +#endif diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index b146843..42d71eb 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -10,6 +10,9 @@ # error "Please use an ix86-elf compiler" #endif +#include "string.h" + void kmain(void) { + puts("Clipper has booted!\r\n"); return; } diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c new file mode 100644 index 0000000..bb51a3b --- /dev/null +++ b/src/kernel/lib/string.c @@ -0,0 +1,44 @@ +#include "string.h" + +#include + +static volatile char* video = (volatile char*)0xB8000; +static uint8_t cursor_x = 0, cursor_y = 0; + +#define SCREEN_WIDTH 80 +#define SCREEN_HEIGHT 25 + +static inline void advance_cursor(void) { + cursor_x++; + if (cursor_x >= SCREEN_WIDTH) { + cursor_x = 0; + cursor_y++; + + if (cursor_y >= SCREEN_HEIGHT) { + cursor_y = 0; + } + } +} + +static inline void linefeed(void) { + cursor_y++; + if (cursor_y >= SCREEN_HEIGHT) { + cursor_y = 0; + } +} + +void putch(char c) { + switch(c) { + case '\r': cursor_x = 0; return; + case '\n': linefeed(); return; + } + + video[cursor_y * (SCREEN_WIDTH * 2) + (cursor_x * 2)] = c; + advance_cursor(); +} + +void puts(const char* str) { + for (const char* c = str; *c != '\0'; c++) { + putch(*c); + } +}