From c1e6d245b100428cf7682d7df25e77769f2e8cef Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Mon, 8 Jun 2020 12:35:51 +0100 Subject: [PATCH] Multi-line support in printf --- Makefile | 7 +++++-- src/gdt.cpp | 6 +++--- src/kernel.cpp | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8a80308..2776d87 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-excep ASPARAMS = --32 LDPARAMS = -melf_i386 -objs = loader.o gdt.o kernel.o +objs = loader.o gdt.o port.o kernel.o %.o: src/%.cpp g++ $(GPPPARAMS) -o $@ -c $< @@ -30,6 +30,9 @@ ferglos.iso: ferglos.bin run: ferglos.iso /usr/lib/virtualbox/VirtualBoxVM --startvm ferglos + +run-qemu: ferglos.iso + qemu-system-i386 -boot d -cdrom ferglos.iso -m 512 clean: - rm -rfv iso *.o *.bin + rm -rfv $(objects) iso *.o *.bin diff --git a/src/gdt.cpp b/src/gdt.cpp index b06efc4..40213b3 100644 --- a/src/gdt.cpp +++ b/src/gdt.cpp @@ -16,9 +16,9 @@ GlobalDescriptorTable::GlobalDescriptorTable() : nullSegmentSelector(0, 0, 0), i[1] = (uint32_t)this; i[0] = sizeof(GlobalDescriptorTable) << 16; - asm volatile("lgdt (%0)" - : - : "p"(((uint8_t *)i) + 2)); + __asm__ volatile("lgdt (%0)" + : + : "p"(((uint8_t *)i) + 2)); } GlobalDescriptorTable::~GlobalDescriptorTable() { } diff --git a/src/kernel.cpp b/src/kernel.cpp index a2e0c44..ab78512 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -11,9 +11,34 @@ void printf(char* str) { static uint16_t* VideoMemory = (uint16_t*)0xb8000; + static uint8_t x = 0, y = 0; - for (int i = 0; str[i] != '\0'; ++i) - VideoMemory[i] = (VideoMemory[i] & 0xFF00) | str[i]; + for (int i = 0; str[i] != '\0'; ++i) { + switch (str[i]) { + case '\n': + y++; + x = 0; + break; + default: + VideoMemory[80 * y + x] = (VideoMemory[80 * y + x] & 0xFF00) | str[i]; + x++; + break; + } + + //line feed after 80 chars (terminal width) + if (x >= 80) { + y++; + x = 0; + } + //we've reached max screen rows + if (y > 25) { + for (y = 0; y < 25; y++) { + for (x - 0; x < 80; x++) { + VideoMemory[80 * y + x] = (VideoMemory[80 * y + x] & 0xFF00) | ' '; + } + } + } + } } typedef void (*constructor)(); @@ -25,7 +50,10 @@ extern "C" void call_constructors() { } extern "C" void ferglos_Main(const void* multiboot_structure, uint32_t /*mb_mag*/) { - printf("Welcome to FerglOS v0.0.1!"); + printf("Welcome to FerglOS v0.0.2!\n"); + printf("Hitler blinks."); + + GlobalDescriptorTable gdt; while (1) ; } \ No newline at end of file