diff --git a/OVMFbin/OVMF_VARS-pure-efi.fd b/OVMFbin/OVMF_VARS-pure-efi.fd index 77e762c..453efac 100644 Binary files a/OVMFbin/OVMF_VARS-pure-efi.fd and b/OVMFbin/OVMF_VARS-pure-efi.fd differ diff --git a/kernel/Makefile b/kernel/Makefile index 6ef303b..8300f94 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -7,7 +7,7 @@ CC = gcc ASMC = nasm LD = ld -CFLAGS = -ffreestanding -fshort-wchar +CFLAGS = -ffreestanding -fshort-wchar -mno-red-zone ASMFLAGS = LDFLAGS = -T $(LDS) -static -Bsymbolic -nostdlib diff --git a/kernel/bin/CustomOS.img b/kernel/bin/CustomOS.img index 655e3c1..2f0d7ab 100644 Binary files a/kernel/bin/CustomOS.img and b/kernel/bin/CustomOS.img differ diff --git a/kernel/bin/kernel.elf b/kernel/bin/kernel.elf index 3b7fde3..e334a67 100755 Binary files a/kernel/bin/kernel.elf and b/kernel/bin/kernel.elf differ diff --git a/kernel/lib/BasicRenderer.o b/kernel/lib/BasicRenderer.o index b5815d4..e99f4dc 100644 Binary files a/kernel/lib/BasicRenderer.o and b/kernel/lib/BasicRenderer.o differ diff --git a/kernel/lib/Bitmap.o b/kernel/lib/Bitmap.o index dd11b57..36556c4 100644 Binary files a/kernel/lib/Bitmap.o and b/kernel/lib/Bitmap.o differ diff --git a/kernel/lib/IO.o b/kernel/lib/IO.o index 5ac9739..3a77d43 100644 Binary files a/kernel/lib/IO.o and b/kernel/lib/IO.o differ diff --git a/kernel/lib/cstr.o b/kernel/lib/cstr.o index 89f6fcf..426c179 100644 Binary files a/kernel/lib/cstr.o and b/kernel/lib/cstr.o differ diff --git a/kernel/lib/interrupts/IDT.o b/kernel/lib/interrupts/IDT.o index f8f3fba..5f87d39 100644 Binary files a/kernel/lib/interrupts/IDT.o and b/kernel/lib/interrupts/IDT.o differ diff --git a/kernel/lib/interrupts/interrupts.o b/kernel/lib/interrupts/interrupts.o index 9cd6d79..b0e5086 100644 Binary files a/kernel/lib/interrupts/interrupts.o and b/kernel/lib/interrupts/interrupts.o differ diff --git a/kernel/lib/kernel.o b/kernel/lib/kernel.o index 907aff0..39b9e9a 100644 Binary files a/kernel/lib/kernel.o and b/kernel/lib/kernel.o differ diff --git a/kernel/lib/kernelUtil.o b/kernel/lib/kernelUtil.o index 51112a9..d26aeca 100644 Binary files a/kernel/lib/kernelUtil.o and b/kernel/lib/kernelUtil.o differ diff --git a/kernel/lib/memory.o b/kernel/lib/memory.o index 7bd77d6..c41b43a 100644 Binary files a/kernel/lib/memory.o and b/kernel/lib/memory.o differ diff --git a/kernel/lib/paging/PageFrameAllocator.o b/kernel/lib/paging/PageFrameAllocator.o index 96b60f5..97e2cb0 100644 Binary files a/kernel/lib/paging/PageFrameAllocator.o and b/kernel/lib/paging/PageFrameAllocator.o differ diff --git a/kernel/lib/paging/PageMapIndexer.o b/kernel/lib/paging/PageMapIndexer.o index 04d5596..e6a4c44 100644 Binary files a/kernel/lib/paging/PageMapIndexer.o and b/kernel/lib/paging/PageMapIndexer.o differ diff --git a/kernel/lib/paging/PageTableManager.o b/kernel/lib/paging/PageTableManager.o index bfffc95..6bca8bb 100644 Binary files a/kernel/lib/paging/PageTableManager.o and b/kernel/lib/paging/PageTableManager.o differ diff --git a/kernel/lib/paging/paging.o b/kernel/lib/paging/paging.o index 673c765..eb34f8d 100644 Binary files a/kernel/lib/paging/paging.o and b/kernel/lib/paging/paging.o differ diff --git a/kernel/lib/panic.o b/kernel/lib/panic.o index 4da2650..6e6b2fd 100644 Binary files a/kernel/lib/panic.o and b/kernel/lib/panic.o differ diff --git a/kernel/lib/userinput/kbScancodeTranslation.o b/kernel/lib/userinput/kbScancodeTranslation.o new file mode 100644 index 0000000..f288631 Binary files /dev/null and b/kernel/lib/userinput/kbScancodeTranslation.o differ diff --git a/kernel/lib/userinput/keyboard.o b/kernel/lib/userinput/keyboard.o new file mode 100644 index 0000000..32304c9 Binary files /dev/null and b/kernel/lib/userinput/keyboard.o differ diff --git a/kernel/src/BasicRenderer.cpp b/kernel/src/BasicRenderer.cpp index 0f6810c..c87c1d9 100644 --- a/kernel/src/BasicRenderer.cpp +++ b/kernel/src/BasicRenderer.cpp @@ -25,6 +25,15 @@ void BasicRenderer::PutChar(char chr, unsigned int xOff, unsigned int yOff) { } } +void BasicRenderer::PutChar(char chr) { + PutChar(chr, cursorPosition.x, cursorPosition.y); + cursorPosition.x += 8; + if (cursorPosition.x + 8 > targetFramebuffer->Width) { + cursorPosition.x = 0; + cursorPosition.y += 16; + } +} + void BasicRenderer::Print(const char* str) { unsigned int x = 0; char* chr = (char*)str; @@ -42,7 +51,7 @@ void BasicRenderer::Print(const char* str) { } } -void BasicRenderer::Clear(uint32_t colour) { +void BasicRenderer::Clear() { uint64_t fbBase = (uint64_t)targetFramebuffer->BaseAddress; uint64_t bytesPerScanline = targetFramebuffer->PixelsPerScanline * 4; uint64_t fbHeight = targetFramebuffer->Height; @@ -51,11 +60,39 @@ void BasicRenderer::Clear(uint32_t colour) { for (int verticalScanline = 0; verticalScanline < fbHeight; verticalScanline ++){ uint64_t pixPtrBase = fbBase + (bytesPerScanline * verticalScanline); for (uint32_t* pixPtr = (uint32_t*)pixPtrBase; pixPtr < (uint32_t*)(pixPtrBase + bytesPerScanline); pixPtr ++){ - *pixPtr = colour; + *pixPtr = ClearColour; } } } +void BasicRenderer::ClearChar(){ + + if (cursorPosition.x == 0){ + cursorPosition.x = targetFramebuffer->Width; + cursorPosition.y -= 16; + if (cursorPosition.y < 0) cursorPosition.y = 0; + } + + unsigned int xOff = cursorPosition.x; + unsigned int yOff = cursorPosition.y; + + unsigned int* pixPtr = (unsigned int*)targetFramebuffer->BaseAddress; + for (unsigned long y = yOff; y < yOff + 16; y++){ + for (unsigned long x = xOff - 8; x < xOff; x++){ + *(unsigned int*)(pixPtr + x + (y * targetFramebuffer->PixelsPerScanline)) = ClearColour; + } + } + + cursorPosition.x -= 8; + + if (cursorPosition.x < 0){ + cursorPosition.x = targetFramebuffer->Width; + cursorPosition.y -= 16; + if (cursorPosition.y < 0) cursorPosition.y = 0; + } + +} + void BasicRenderer::Next() { cursorPosition.x = 0; cursorPosition.y += 16; diff --git a/kernel/src/BasicRenderer.h b/kernel/src/BasicRenderer.h index 877dc2a..5c08eeb 100644 --- a/kernel/src/BasicRenderer.h +++ b/kernel/src/BasicRenderer.h @@ -11,9 +11,12 @@ class BasicRenderer { Framebuffer* targetFramebuffer; PSF1_FONT* PSF1_Font; unsigned int Colour; + unsigned int ClearColour; void Print(const char* str); void PutChar(char chr, unsigned int xOff, unsigned int yOff); - void Clear(uint32_t colour); + void PutChar(char chr); + void ClearChar(); + void Clear(); void Next(); }; diff --git a/kernel/src/interrupts/interrupts.cpp b/kernel/src/interrupts/interrupts.cpp index 4cf7d17..bcf694d 100644 --- a/kernel/src/interrupts/interrupts.cpp +++ b/kernel/src/interrupts/interrupts.cpp @@ -1,6 +1,7 @@ #include "interrupts.h" #include "../panic.h" #include "../IO.h" +#include "../userinput/keyboard.h" __attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame) { Panic("Page Fault"); @@ -18,10 +19,10 @@ __attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame) { } __attribute__((interrupt)) void KeyboardInterrupt_Handler(struct interrupt_frame* frame) { - GlobalRenderer->Print("A"); - uint8_t scancode = inb(0x60); + HandleKeyboard(scancode); + PIC_EndMaster(); } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 7f792e4..2d25849 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -4,7 +4,8 @@ extern "C" void _start(BootInfo* bootInfo) { KernelInfo kernelInfo = InitializeKernel(bootInfo); PageTableManager* pageTableManager = kernelInfo.pageTableManager; - GlobalRenderer->Clear(0xFF191919); + GlobalRenderer->ClearColour = 0xFF191919; + GlobalRenderer->Clear(); GlobalRenderer->Print("Kernel initialized successfully!"); GlobalRenderer->Next(); diff --git a/kernel/src/math.h b/kernel/src/math.h index a14daa5..a83b255 100644 --- a/kernel/src/math.h +++ b/kernel/src/math.h @@ -1,6 +1,6 @@ #pragma once struct Point { - unsigned int x; - unsigned int y; + long x; + long y; }; \ No newline at end of file diff --git a/kernel/src/paging/PageFrameAllocator.cpp b/kernel/src/paging/PageFrameAllocator.cpp index e3ffb9e..52ee19d 100644 --- a/kernel/src/paging/PageFrameAllocator.cpp +++ b/kernel/src/paging/PageFrameAllocator.cpp @@ -33,7 +33,7 @@ void PageFrameAllocator::ReadEFIMemoryMap(EFI_MEMORY_DESCRIPTOR* mMap, size_t mM InitBitmap(bitmapSize, largestFreeMemSeg); // lock pages of bitmap - LockPages(&PageBitmap, PageBitmap.Size / 4096 + 1); + LockPages(PageBitmap.Buffer, PageBitmap.Size / 4096 + 1); //reserve pages of unsable/reserverd memory for (int i = 0; i < mMapEntries; i++) { diff --git a/kernel/src/panic.cpp b/kernel/src/panic.cpp index bbd1da9..ece1571 100644 --- a/kernel/src/panic.cpp +++ b/kernel/src/panic.cpp @@ -2,7 +2,8 @@ #include "BasicRenderer.h" void Panic(const char* panicMessage) { - GlobalRenderer->Clear(0xFF000000); + GlobalRenderer->ClearColour = 0xFF000000; + GlobalRenderer->Clear(); GlobalRenderer->Colour = 0xFFFF0000; GlobalRenderer->cursorPosition = {0,0}; GlobalRenderer->Print("PANIC!!! "); diff --git a/kernel/src/userinput/kbScancodeTranslation.cpp b/kernel/src/userinput/kbScancodeTranslation.cpp new file mode 100644 index 0000000..361c50c --- /dev/null +++ b/kernel/src/userinput/kbScancodeTranslation.cpp @@ -0,0 +1,31 @@ +#include "kbScancodeTranslation.h" + +namespace QWERTYKeyboard { + const char ASCIITable[] = { + 0 , 0 , '1', '2', + '3', '4', '5', '6', + '7', '8', '9', '0', + '-', '=', 0 , 0 , + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', + 0 , 0 , 'a', 's', + 'd', 'f', 'g', 'h', + 'j', 'k', 'l', ';', + '\'','`', 0 , '\\', + 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', + '.', '/', 0 , '*', + 0 , ' ' + }; + + char Translate(uint8_t scancode, bool uppercase) { + if (scancode > 58) return 0; // longer than the length of our ascii array + + if (uppercase) { + return ASCIITable[scancode] - 32; + } + + return ASCIITable[scancode]; + } +} \ No newline at end of file diff --git a/kernel/src/userinput/kbScancodeTranslation.h b/kernel/src/userinput/kbScancodeTranslation.h new file mode 100644 index 0000000..c2867bb --- /dev/null +++ b/kernel/src/userinput/kbScancodeTranslation.h @@ -0,0 +1,15 @@ +#pragma once +#include + +namespace QWERTYKeyboard { + + #define LeftShift 0x2A + #define RightShift 0x36 + #define Enter 0x1C + #define Backspace 0x0E + #define Spacebar 0x39 + + extern const char ASCIITable[]; + char Translate(uint8_t scancode, bool uppercase); +} + diff --git a/kernel/src/userinput/keyboard.cpp b/kernel/src/userinput/keyboard.cpp new file mode 100644 index 0000000..c1bafb2 --- /dev/null +++ b/kernel/src/userinput/keyboard.cpp @@ -0,0 +1,36 @@ +#include "keyboard.h" + +bool isLeftShiftPressed = false; +bool isRightShiftPressed = false; + +void HandleKeyboard(uint8_t scancode) { + switch (scancode) { + case LeftShift: + isLeftShiftPressed = true; + return; + case LeftShift + 0x80: + isLeftShiftPressed = false; + return; + case RightShift: + isRightShiftPressed = true; + return; + case RightShift + 0x80: + isRightShiftPressed = false; + return; + case Enter: + GlobalRenderer->Next(); + return; + case Spacebar: + GlobalRenderer->PutChar(' '); + return; + case Backspace: + GlobalRenderer->ClearChar(); + break; + } + + char ascii = QWERTYKeyboard::Translate(scancode, isLeftShiftPressed || isRightShiftPressed); + + if (ascii != 0) { + GlobalRenderer->PutChar(ascii); + } +} \ No newline at end of file diff --git a/kernel/src/userinput/keyboard.h b/kernel/src/userinput/keyboard.h new file mode 100644 index 0000000..ad85d7e --- /dev/null +++ b/kernel/src/userinput/keyboard.h @@ -0,0 +1,6 @@ +#pragma once +#include +#include "kbScancodeTranslation.h" +#include "../BasicRenderer.h" + +void HandleKeyboard(uint8_t scancode); \ No newline at end of file