diff --git a/CMakeLists.txt b/CMakeLists.txt index c2b59a0..6686564 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,6 @@ SET(src_no_sse set_property(SOURCE ${src_no_sse} PROPERTY COMPILE_FLAGS -mgeneral-regs-only) add_executable(kernel.elf ${src_files} ${src_no_sse} font.o) -target_compile_options(kernel.elf PRIVATE -ffreestanding -O2 -Wall -Wextra -v -fPIC) +target_compile_options(kernel.elf PRIVATE -ffreestanding -O2 -Wall -Wextra -Wall -Werror -pedantic -fPIC) target_link_options(kernel.elf PRIVATE -T linker.ld -ffreestanding -O2 -nostdlib -lgcc) diff --git a/chroma/inc/kernel/system/interrupts.h b/chroma/inc/kernel/system/interrupts.h index 565c8f3..f381c40 100644 --- a/chroma/inc/kernel/system/interrupts.h +++ b/chroma/inc/kernel/system/interrupts.h @@ -1,41 +1,7 @@ #pragma once #include -static const char* ExceptionStrings[] = { - "Division by Zero", - "Debug", - "Non Maskable Interrupt", - "Breakpoint", - "Into Detected Overflow", - "Out of Bounds", - "Invalid Opcode", - "No Coprocessor", - "Double Fault", - "Coprocessor Segment Overrun", - "Bad TSS", - "Segment Not Present", - "Stack Fault", - "General Protection Fault", - "Page Fault", - "Unknown Interrupt", - "Coprocessor Fault", - "Alignment Check", - "Machine Check", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved" -}; - +extern const char* ExceptionStrings[]; typedef struct __attribute__((packed)) { @@ -55,10 +21,10 @@ typedef struct __attribute__((packed)) { size_t ss; } EXCEPTION_FRAME; -static void* IRQ_Handlers[16] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; + +typedef void (*IRQHandler)(INTERRUPT_FRAME* Frame); + +extern IRQHandler IRQ_Handlers[16]; void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interupt); void ISR_Common(INTERRUPT_FRAME* Frame, size_t Interrupt); diff --git a/chroma/inc/kernel/video/tty.h b/chroma/inc/kernel/video/tty.h deleted file mode 100644 index 0fcab05..0000000 --- a/chroma/inc/kernel/video/tty.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _KERNEL_TTY_H -#define _KERNEL_TTY_H - -#include - -void Term_Init(void); -void Term_PutChar(char c); -void Term_Write(const char* str, size_t len); -void Term_WriteStr(const char* str); - -#endif diff --git a/chroma/system/drivers/keyboard.c b/chroma/system/drivers/keyboard.c index a4fe573..cf52ea6 100644 --- a/chroma/system/drivers/keyboard.c +++ b/chroma/system/drivers/keyboard.c @@ -36,6 +36,18 @@ char keys[128] = { +void KbdEcho() { + if(!KbdFlags.EchoCount) { + if(!KbdFlags.Echo) { + Send8042(0xEE); + } + } else { + KbdFlags.EchoCount = 0; + KbdFlags.Echo = 0; + } +} + + void UpdateKeyboard(uint8_t msg) { InputBuffer[0] = msg; @@ -79,23 +91,12 @@ void UpdateKeyboard(uint8_t msg) { if(msg & 0x80) { } else { - SerialPrintf("Key pressed: [\%c]\r\n", keys[msg]); + SerialPrintf("Key pressed: [\\%c]\r\n", keys[msg]); WriteChar(keys[msg]); } } -void KbdEcho() { - if(!KbdFlags.EchoCount) { - if(!KbdFlags.Echo) { - Send8042(0xEE); - } - } else { - KbdFlags.EchoCount = 0; - KbdFlags.Echo = 0; - } -} - void Send8042(size_t info) { for(size_t i = 0; i < 8; i++) { unsigned char chr = (unsigned char) info; diff --git a/chroma/system/interrupts.c b/chroma/system/interrupts.c index 9a08447..409e453 100644 --- a/chroma/system/interrupts.c +++ b/chroma/system/interrupts.c @@ -36,6 +36,51 @@ #include #include +#define UNUSED(X) ((void)X) + +const char* ExceptionStrings[] = { + "Division by Zero", + "Debug", + "Non Maskable Interrupt", + "Breakpoint", + "Into Detected Overflow", + "Out of Bounds", + "Invalid Opcode", + "No Coprocessor", + "Double Fault", + "Coprocessor Segment Overrun", + "Bad TSS", + "Segment Not Present", + "Stack Fault", + "General Protection Fault", + "Page Fault", + "Unknown Interrupt", + "Coprocessor Fault", + "Alignment Check", + "Machine Check", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved" +}; + +typedef void (*IRQHandler)(INTERRUPT_FRAME* Frame); + +IRQHandler IRQ_Handlers[16] = { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +}; + + typedef unsigned long long int uword_t; /* All of the ISR routines call this function for now. @@ -43,6 +88,9 @@ typedef unsigned long long int uword_t; ! Be careful! */ void ISR_Common(INTERRUPT_FRAME* Frame, size_t Exception) { + + UNUSED(Frame); + /* Only the first 32 ISR/IRQs are reserved for exceptions by the CPU. We can handle up to 512 interrupts total, though. */ if(Exception < 32) { @@ -58,6 +106,9 @@ void ISR_Common(INTERRUPT_FRAME* Frame, size_t Exception) { /* The common handler for exceptions that throw error codes, which give us useful insight into what went wrong. In pure Curle style, though, we just ignore the error code. */ void ISR_Error_Common(INTERRUPT_FRAME* Frame, size_t ErrorCode, size_t Exception) { + + UNUSED(Frame); + if(Exception < 32) { FillScreen(0x0000FF00); @@ -125,11 +176,14 @@ void InstallIRQ(int IRQ, void (*Handler)(INTERRUPT_FRAME* Frame)) { /* A simple wrapper that unlinks a function pointer, rendering the IRQ unused. */ void UninstallIRQHandler(int IRQ) { - IRQ_Handlers[IRQ] = 0; // 0 is used in the common check to make sure that the function is callable. + IRQ_Handlers[IRQ] = NULL; // 0 is used in the common check to make sure that the function is callable. // This removes this irq from that check, ergo the function will no longer be called. } void EmptyIRQ(INTERRUPT_FRAME* frame) { + + UNUSED(frame); + // Flash the borders green, then back to blue for(size_t y = 0; y < bootldr.fb_height; y++) { @@ -175,6 +229,8 @@ void EmptyIRQ(INTERRUPT_FRAME* frame) { static void KeyboardCallback(INTERRUPT_FRAME* frame) { + UNUSED(frame); + uint8_t msg = ReadPort(0x60, 1); UpdateKeyboard(msg); @@ -271,7 +327,7 @@ __attribute__((interrupt)) void ISR14Handler(INTERRUPT_FRAME* Frame, size_t Erro SerialPrintf("Page fault! Caused by: [\r\n"); - size_t FaultAddr = ReadControlRegister(2); + //size_t FaultAddr = ReadControlRegister(2); uint8_t FaultPres = ErrorCode & 0x1; uint8_t FaultRW = ErrorCode & 0x2; uint8_t FaultUser = ErrorCode & 0x4; diff --git a/chroma/system/memory/paging.c b/chroma/system/memory/paging.c index 36522a6..6d3fb4a 100644 --- a/chroma/system/memory/paging.c +++ b/chroma/system/memory/paging.c @@ -1,6 +1,6 @@ #include -__attribute__((aligned(4096))) static size_t Pagetable[512] = {0}; +//__attribute__((aligned(4096))) static size_t Pagetable[512] = {0}; #define LAST_ENTRY 0xFF8 @@ -72,7 +72,7 @@ void InitPaging() { SET_ADDRESS(PT_KERNEL + LAST_ENTRY, 0xF14003); MappingIterations = 1; // For every core: - for(size_t i = 0; i < (bootldr.numcores + 3) >> 2; i++) { + for(size_t i = 0; i < (bootldr.numcores + 3U) >> 2; i++) { // PT_KERNEL[512 - (iterations + 1)] = 0x14003 + (iterations * page-width) SET_ADDRESS(PT_KERNEL + LAST_ENTRY - (MappingIterations * 8), 0xF14003 + (4096 * MappingIterations)); MappingIterations++; @@ -115,7 +115,7 @@ void InitPagingOldImpl() { // Clear space for our pagetable size_t PagetableDest = 0x1000; - memset(PagetableDest, 0, 4096); + memset((char*)PagetableDest, 0, 4096); // Start setting pagetable indexes *((size_t*)PagetableDest) = 0x2003; // PDP at 0x2000, present & r/w diff --git a/chroma/system/memory/physmem.c b/chroma/system/memory/physmem.c index d8c03b5..4cc442a 100644 --- a/chroma/system/memory/physmem.c +++ b/chroma/system/memory/physmem.c @@ -2,7 +2,7 @@ #include uint8_t* Memory = ((uint8_t*)(&end)); -uint8_t MemoryStart; +uint8_t* MemoryStart; size_t MemoryBuckets; @@ -56,7 +56,7 @@ void ListMemoryMap() { - for(MMapEnt* MapEntry = &bootldr.mmap; MapEntry < (size_t) &bootldr + bootldr.size; MapEntry++) { + for(MMapEnt* MapEntry = &bootldr.mmap; (size_t)MapEntry < (size_t)&environment; MapEntry++) { char EntryType[8] = {0}; switch(MMapEnt_Type(MapEntry)) { case MMAP_FREE: @@ -103,9 +103,9 @@ void MemoryTest() { SerialPrintf("Initializing basic memory test..\r\n"); bool Passed = true; size_t FirstPage = SeekFrame(); - void* FirstPageAlloc = (void*) AllocateFrame(); + /*(void* FirstPageAlloc = (void*)*/ AllocateFrame(); size_t SecondPage = SeekFrame(); - void* SecondPageAlloc = (void*) AllocateFrame(); + /*void* SecondPageAlloc = (void*)*/ AllocateFrame(); if(!(FirstPage == 0 && SecondPage == 1)) { Passed = false; diff --git a/chroma/system/rw.c b/chroma/system/rw.c index c6d3e03..f86ca02 100644 --- a/chroma/system/rw.c +++ b/chroma/system/rw.c @@ -41,10 +41,9 @@ size_t ReadModelSpecificRegister(size_t MSR) { } size_t WriteModelSpecificRegister(size_t MSR, size_t Data) { - size_t DataLow = 0, DataHigh = 0; - DataLow = ((uint32_t*) &Data)[0]; - DataHigh = ((uint32_t*) &Data)[1]; + const size_t DataLow = Data & 0x00000000ffffffff; + const size_t DataHigh = (Data & 0xffffffff00000000) >> 32; __asm__ __volatile__ ("wrmsr" : : "a" (DataLow), "c" (MSR), "d" (DataHigh) :); @@ -104,6 +103,8 @@ size_t ReadControlRegister(int CRX) { __asm__ __volatile__ ("pushfq\n\t" "popq %[dest]" : [dest] "=r" (Data) : :); break; default: + SerialPrintf("invalid crx read %x\r\n",CRX); + Data = 0xdeadbeef; break; } @@ -148,9 +149,12 @@ size_t ReadExtendedControlRegister(size_t XCRX) { return (RegHigh << 32 | RegLow); } +//TODO: make this just have an assert as returning data for a write to catch +// errors that shoudlunt really happen doesent make alot of sense size_t WriteExtendedControlRegister(size_t XCRX, size_t Data){ - - __asm__ __volatile__("xsetbv" : : "a" ( ((uint32_t*) &Data)[0]), "c" (XCRX), "d" ( ((uint32_t*) &Data)[1] ) :); + uint32_t DataLow = Data & 0xffffffff; + uint32_t DataHigh = (Data & 0xffffffff00000000) >> 32; + __asm__ __volatile__("xsetbv" : : "a" (DataLow), "c" (XCRX), "d" (DataHigh) :); return Data; } diff --git a/chroma/video/draw.c b/chroma/video/draw.c index fdd2f5b..e145c3f 100644 --- a/chroma/video/draw.c +++ b/chroma/video/draw.c @@ -70,7 +70,7 @@ static void DrawChar(const char character, size_t x, size_t y) { // This one is crazy. Stick with me. - if((FONT[character][Row * Y + X] >> (Bit & 0x7)) & 1) { // Check the bit in the bitmap, if it's solid.. + if((FONT[(int)character][Row * Y + X] >> (Bit & 0x7)) & 1) { // Check the bit in the bitmap, if it's solid.. for(uint32_t ScaleY = 0; ScaleY < PrintInfo.charScale; ScaleY++) { // Take care of the scale height for(uint32_t ScaleX = 0; ScaleX < PrintInfo.charScale; ScaleX++) { // And the scale width @@ -267,7 +267,7 @@ void WriteChar(const char character) { } void WriteString(const char* string) { - for(int i = 0; i < strlen(string); i++) { + for(unsigned int i = 0; i < strlen(string); i++) { WriteChar(string[i]); } } @@ -276,15 +276,15 @@ void WriteStringWithFont(const char *inChar) { psf_t *font = (psf_t*) &_binary_font_psf_start; - int drawX, drawY, kx = 0, fontLine, bitMask, offset; + unsigned int drawX, drawY, kx = 0, fontLine, bitMask, offset; - int bytesPerLine = ( font -> glyphWidth + 7 ) / 8; + const unsigned int bytesPerLine = ( font -> glyphWidth + 7 ) / 8; while(*inChar) { unsigned char *glyph = (unsigned char*) &_binary_font_psf_start + font->headerSize - + (*inChar > 0 && *inChar < font->numGlyphs ? *inChar : 0) * + + (*inChar > 0 && *inChar < (int)font->numGlyphs ? *inChar : 0) * font->glyphSize; diff --git a/chroma/video/tty.c b/chroma/video/tty.c deleted file mode 100644 index 98af3c8..0000000 --- a/chroma/video/tty.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -static const size_t TERM_WIDTH = 80; -static const size_t TERM_HEIGHT = 25; - -size_t TERM_ROW; -size_t TERM_COL; -uint8_t TERM_COLOR; - -uint16_t* TERM_BUFFER; - -void Term_Init(void) { - - TERM_ROW = 0; - TERM_COL = 0; - TERM_COLOR = VGACharColor(VGA_COLOR_LIGHTGREY, VGA_COLOR_BLACK); - - TERM_BUFFER = (uint16_t*) 0xB8000; - - for(size_t y = 0; y < TERM_HEIGHT; y++) { - for(size_t x = 0; x < TERM_WIDTH; x++) { - const size_t index = y * TERM_WIDTH + x; - TERM_BUFFER[index] = VGAChar(' ', TERM_COLOR); - } - } -} - -void Term_SetColor(uint8_t color) { - TERM_COLOR = color; -} - -void Term_PutVGAChar(char c, uint8_t color, size_t x, size_t y) { - const size_t index = y * TERM_WIDTH + x; - TERM_BUFFER[index] = VGAChar(c, color); -} - -void Term_PutChar(char c) { - Term_PutVGAChar(c, TERM_COLOR, TERM_COL, TERM_ROW); - - if(++TERM_COL == TERM_WIDTH) { - TERM_COL = 0; - if(++TERM_ROW == TERM_HEIGHT) - TERM_ROW = 0; - } -} - -void Term_Write(const char* str, size_t len) { - for(size_t i = 0; i < len; i++) - Term_PutChar(str[i]); -} - -void Term_WriteString(const char* str) { - Term_Write(str, strlen(str)); -} - diff --git a/chroma/video/tty.d b/chroma/video/tty.d deleted file mode 100644 index 02cf1e2..0000000 --- a/chroma/video/tty.d +++ /dev/null @@ -1,6 +0,0 @@ -chroma/video/tty.o: chroma/video/tty.c chroma/inc/kernel/video/tty.h \ - chroma/inc/kernel/video/vga-textmode.h - -chroma/inc/kernel/video/tty.h: - -chroma/inc/kernel/video/vga-textmode.h: diff --git a/iso/boot/initrd b/iso/boot/initrd index 56e794e..7f049be 100755 Binary files a/iso/boot/initrd and b/iso/boot/initrd differ diff --git a/kernel.elf b/kernel.elf deleted file mode 100755 index 56e794e..0000000 Binary files a/kernel.elf and /dev/null differ diff --git a/sync.iso b/sync.iso index 7cb79e1..8e62607 100644 Binary files a/sync.iso and b/sync.iso differ