diff --git a/kernel/Makefile b/kernel/Makefile index 8f62835f..2c97a286 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -3,7 +3,7 @@ MOON_SRC := $(MOON_DIR)/src MOON_OBJ := $(MOON_DIR)/lib MOON_BIN := $(MOON_DIR)/bin -CFLAGS := -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Os -ffreestanding -fstack-protector-all -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std +CFLAGS := -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion -Os -ffreestanding -fstack-protector-all -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std CXXFLAGS := -fno-rtti -fno-exceptions ASMFLAGS := -felf64 LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000 diff --git a/kernel/include/init/InitRD.h b/kernel/include/init/InitRD.h index 388b4f34..9c7b89fe 100644 --- a/kernel/include/init/InitRD.h +++ b/kernel/include/init/InitRD.h @@ -30,15 +30,15 @@ namespace InitRD struct File { char name[100]; - int size; - int size_in_blocks; + uint64_t size; + uint64_t size_in_blocks; void* addr; }; - int get_total_blocks(); + uint64_t get_total_blocks(); File get_file(TarHeader* header); void free_file(File& file); - TarHeader* get_block(int block_index); + TarHeader* get_block(uint64_t block_index); bool is_valid_header(TarHeader* header); uint64_t get_file_physical_address(File& file); diff --git a/kernel/include/memory/Paging.h b/kernel/include/memory/Paging.h index faf67ea1..bab9e79b 100644 --- a/kernel/include/memory/Paging.h +++ b/kernel/include/memory/Paging.h @@ -16,6 +16,8 @@ namespace Paging bool ignore1 : 1; uint8_t Available : 3; uint64_t Address : 52; + + void set_address(uint64_t addr); }; struct PageTable diff --git a/kernel/src/acpi/RSDT.cpp b/kernel/src/acpi/RSDT.cpp index 21fdb89d..63206170 100644 --- a/kernel/src/acpi/RSDT.cpp +++ b/kernel/src/acpi/RSDT.cpp @@ -53,13 +53,13 @@ bool ACPI::is_xsdt() void* ACPI::find_table(ACPI::SDTHeader* root_sdt, const char* signature) { bool isXSDT = is_xsdt(); - int entries = (root_sdt->Length - sizeof(SDTHeader)) / (isXSDT ? 8 : 4); - kdbgln("Searching for table %s in the %s at %lx (table contains %d entries)", signature, isXSDT ? "XSDT" : "RSDT", + uint64_t entries = (root_sdt->Length - sizeof(SDTHeader)) / (isXSDT ? 8 : 4); + kdbgln("Searching for table %s in the %s at %lx (table contains %ld entries)", signature, isXSDT ? "XSDT" : "RSDT", (uint64_t)root_sdt, entries); - for (int i = 0; i < entries; i++) + for (uint64_t i = 0; i < entries; i++) { - kdbgln("Testing for table %s in entry %d", signature, i); + kdbgln("Testing for table %s in entry %ld", signature, i); SDTHeader* h; if (isXSDT) { @@ -74,7 +74,7 @@ void* ACPI::find_table(ACPI::SDTHeader* root_sdt, const char* signature) } if (!h) { - kwarnln("Entry %d in the %s points to null", i, isXSDT ? "XSDT" : "RSDT"); + kwarnln("Entry %ld in the %s points to null", i, isXSDT ? "XSDT" : "RSDT"); continue; } kdbgln("Physical address of entry: %lx", (uint64_t)h); @@ -82,7 +82,7 @@ void* ACPI::find_table(ACPI::SDTHeader* root_sdt, const char* signature) kdbgln("Mapped entry to virtual address %lx", (uint64_t)realHeader); if (!validate_sdt_header(realHeader)) { - kwarnln("Header of entry %d is not valid, skipping this entry", i); + kwarnln("Header of entry %ld is not valid, skipping this entry", i); MemoryManager::release_unaligned_mapping(realHeader); continue; } diff --git a/kernel/src/acpi/SDT.cpp b/kernel/src/acpi/SDT.cpp index 6aedcde3..9b861ab6 100644 --- a/kernel/src/acpi/SDT.cpp +++ b/kernel/src/acpi/SDT.cpp @@ -1,5 +1,8 @@ #include "acpi/SDT.h" +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wconversion" + bool ACPI::validate_sdt_header(ACPI::SDTHeader* header) { uint8_t sum = 0; @@ -7,4 +10,6 @@ bool ACPI::validate_sdt_header(ACPI::SDTHeader* header) for (uint32_t i = 0; i < header->Length; i++) { sum += ((char*)header)[i]; } return sum == 0; -} \ No newline at end of file +} + +#pragma GCC pop_options \ No newline at end of file diff --git a/kernel/src/gdt/GDT.cpp b/kernel/src/gdt/GDT.cpp index d5e5c164..6b9915ad 100644 --- a/kernel/src/gdt/GDT.cpp +++ b/kernel/src/gdt/GDT.cpp @@ -68,14 +68,14 @@ static void set_base(GDTEntry* entry, uint32_t base) { entry->base0 = (base & 0xFFFF); entry->base1 = (base >> 16) & 0xFF; - entry->base2 = (base >> 24) & 0xFF; + entry->base2 = (uint8_t)((base >> 24) & 0xFF); } static void set_limit(GDTEntry* entry, uint32_t limit) { ASSERT(limit <= 0xFFFFF); - entry->limit0 = limit; - entry->limit1_flags = (entry->limit1_flags & 0xF0) | (limit & 0xF); + entry->limit0 = limit & 0xFFFF; + entry->limit1_flags = (entry->limit1_flags & 0xF0) | ((limit >> 16) & 0xF); } void GDT::load() @@ -87,7 +87,7 @@ void GDT::load() main_tss.rsp[0] = (uint64_t)MemoryManager::get_pages(4) + (4096 * 4) - 8; // allocate 16KB for the syscall stack main_tss.iomap_base = sizeof(TSS); set_base(&internal_gdt.tss, (uint64_t)&main_tss & 0xffffffff); - internal_gdt.tss2.base_high = (uint64_t)&main_tss >> 32; + internal_gdt.tss2.base_high = (uint32_t)(((uint64_t)&main_tss >> 32) & 0xffffffff); set_limit(&internal_gdt.tss, sizeof(TSS) - 1); kdbgln("Loading GDT at offset %lx, size %d", gdtr.offset, gdtr.size); load_gdt(&gdtr); diff --git a/kernel/src/init/InitRD.cpp b/kernel/src/init/InitRD.cpp index 125fd5a9..b03480b5 100644 --- a/kernel/src/init/InitRD.cpp +++ b/kernel/src/init/InitRD.cpp @@ -19,17 +19,17 @@ bool InitRD::is_initialized() return initrd_initialized; } -static inline int get_file_size_in_blocks(InitRD::File f) +static inline uint64_t get_file_size_in_blocks(InitRD::File f) { return f.size_in_blocks; } -inline int InitRD::get_total_blocks() +inline uint64_t InitRD::get_total_blocks() { return bootboot.initrd_size / TAR_BLOCKSIZE; } -inline InitRD::TarHeader* InitRD::get_block(int block_index) +inline InitRD::TarHeader* InitRD::get_block(uint64_t block_index) { return (TarHeader*)((uintptr_t)initrd_base + block_index * TAR_BLOCKSIZE); } @@ -63,8 +63,8 @@ InitRD::File InitRD::get_file(TarHeader* header) InitRD::File InitRD::open(const char* filename) { - int block = 0; - int total_blocks = get_total_blocks(); + uint64_t block = 0; + uint64_t total_blocks = get_total_blocks(); while (block < total_blocks) { TarHeader* hdr = (TarHeader*)get_block(block); @@ -83,7 +83,7 @@ InitRD::File InitRD::open(const char* filename) block += get_file_size_in_blocks(f) + 1; } File nullFile; - nullFile.addr = NULL; + nullFile.addr = 0; nullFile.size = 0; memcpy(nullFile.name, "NULL", 5); return nullFile; @@ -91,8 +91,8 @@ InitRD::File InitRD::open(const char* filename) void InitRD::for_each(void (*callback)(File& f)) { - int block = 0; - int total_blocks = get_total_blocks(); + uint64_t block = 0; + uint64_t total_blocks = get_total_blocks(); while (block < total_blocks) { TarHeader* hdr = (TarHeader*)get_block(block); diff --git a/kernel/src/interrupts/IRQ.cpp b/kernel/src/interrupts/IRQ.cpp index e1771c51..3402cc5d 100644 --- a/kernel/src/interrupts/IRQ.cpp +++ b/kernel/src/interrupts/IRQ.cpp @@ -28,6 +28,6 @@ void IRQ::interrupt_handler(Context* context) default: kwarnln("Unhandled IRQ: %ld", context->irq_number); break; } Mersenne::reseed(); - PIC::send_eoi(context->irq_number); + PIC::send_eoi((unsigned char)(context->irq_number & 0xFF)); return; } \ No newline at end of file diff --git a/kernel/src/interrupts/Install.cpp b/kernel/src/interrupts/Install.cpp index 8c33012c..2025af3a 100644 --- a/kernel/src/interrupts/Install.cpp +++ b/kernel/src/interrupts/Install.cpp @@ -106,7 +106,7 @@ void Interrupts::install() INSTALL_ISR(46); INSTALL_ISR(47); kdbgln("Installing unused handler stubs for the rest of the IDT"); - for (int i = 48; i < 256; i++) { INSTALL_UNUSED(i); } + for (short i = 48; i < 256; i++) { INSTALL_UNUSED(i); } kdbgln("Installing syscall handler stub"); INSTALL_USER_ISR(66); } \ No newline at end of file diff --git a/kernel/src/io/PCI.cpp b/kernel/src/io/PCI.cpp index 97d909aa..204f2289 100644 --- a/kernel/src/io/PCI.cpp +++ b/kernel/src/io/PCI.cpp @@ -36,13 +36,13 @@ void PCI::raw_write32(uint32_t bus, uint32_t slot, uint32_t function, int32_t of uint8_t PCI::raw_read8(uint32_t bus, uint32_t slot, uint32_t function, int32_t offset) { IO::outl(PCI_ADDRESS, raw_address(bus, slot, function, offset)); - return IO::inl(PCI_VALUE + (offset & 3)); + return (uint8_t)(IO::inl(PCI_VALUE + (offset & 3)) & 0xFF); } uint16_t PCI::raw_read16(uint32_t bus, uint32_t slot, uint32_t function, int32_t offset) { IO::outl(PCI_ADDRESS, raw_address(bus, slot, function, offset)); - return IO::inl(PCI_VALUE + (offset & 2)); + return (uint8_t)(IO::inl(PCI_VALUE + (offset & 2)) & 0xFFFF); } uint32_t PCI::raw_read32(uint32_t bus, uint32_t slot, uint32_t function, int32_t offset) diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index d2185c75..baec78d6 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -124,7 +124,7 @@ extern "C" void _start() } }); - int demo = Mersenne::get() % 5; + uint64_t demo = Mersenne::get() % 5; switch (demo) { diff --git a/kernel/src/memory/PMM.cpp b/kernel/src/memory/PMM.cpp index bc48fc0c..62432df8 100644 --- a/kernel/src/memory/PMM.cpp +++ b/kernel/src/memory/PMM.cpp @@ -79,7 +79,7 @@ static void bitmap_set(uint64_t index, bool value) { uint64_t byteIndex = index / 8; uint8_t bitIndexer = 0b10000000 >> (index % 8); - virtual_bitmap_addr[byteIndex] &= ~bitIndexer; + virtual_bitmap_addr[byteIndex] &= (uint8_t)(~bitIndexer); if (value) { virtual_bitmap_addr[byteIndex] |= bitIndexer; } } diff --git a/kernel/src/memory/Paging.cpp b/kernel/src/memory/Paging.cpp new file mode 100644 index 00000000..59e08552 --- /dev/null +++ b/kernel/src/memory/Paging.cpp @@ -0,0 +1,11 @@ +#include "memory/Paging.h" + +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wconversion" + +void Paging::PageDirectoryEntry::set_address(uint64_t addr) +{ + this->Address = (addr >> 12); +} + +#pragma GCC pop_options \ No newline at end of file diff --git a/kernel/src/memory/VMM.cpp b/kernel/src/memory/VMM.cpp index 4ee7fb8d..d36f0d63 100644 --- a/kernel/src/memory/VMM.cpp +++ b/kernel/src/memory/VMM.cpp @@ -165,7 +165,7 @@ namespace Paging PDP = (PageTable*)PMM::request_page(); ASSERT(!(PMM_DID_FAIL(PDP))); memset(PDP, 0, 0x1000); - PDE.Address = (uint64_t)PDP >> 12; + PDE.set_address((uint64_t)PDP); PDE.Present = true; PDE.ReadWrite = true; if (flags & User) PDE.UserSuper = true; @@ -185,7 +185,7 @@ namespace Paging PD = (PageTable*)PMM::request_page(); ASSERT(!(PMM_DID_FAIL(PD))); memset(PD, 0, 0x1000); - PDE.Address = (uint64_t)PD >> 12; + PDE.set_address((uint64_t)PD); PDE.Present = true; PDE.ReadWrite = true; if (flags & User) PDE.UserSuper = true; @@ -205,7 +205,7 @@ namespace Paging PT = (PageTable*)PMM::request_page(); ASSERT(!(PMM_DID_FAIL(PT))); memset(PT, 0, 0x1000); - PDE.Address = (uint64_t)PT >> 12; + PDE.set_address((uint64_t)PT); PDE.Present = true; PDE.ReadWrite = true; if (flags & User) PDE.UserSuper = true; @@ -222,7 +222,7 @@ namespace Paging PDE.Present = true; PDE.ReadWrite = flags & ReadWrite; PDE.UserSuper = flags & User; - PDE.Address = physicalAddress >> 12; + PDE.set_address(physicalAddress); PT->entries[P_i] = PDE; } } \ No newline at end of file diff --git a/kernel/src/memory/liballoc/liballoc.c b/kernel/src/memory/liballoc/liballoc.c index 737221ee..90c9f2b4 100644 --- a/kernel/src/memory/liballoc/liballoc.c +++ b/kernel/src/memory/liballoc/liballoc.c @@ -2,6 +2,10 @@ #include +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" + /** Durand's Amazing Super Duper Memory functions. */ #define VERSION "1.1" @@ -739,3 +743,5 @@ void* PREFIX(realloc)(void* p, size_t size) return ptr; } + +#pragma GCC pop_options diff --git a/kernel/src/misc/MSR.cpp b/kernel/src/misc/MSR.cpp index 47ac7875..d38140bd 100644 --- a/kernel/src/misc/MSR.cpp +++ b/kernel/src/misc/MSR.cpp @@ -3,7 +3,7 @@ void MSR::write_to(uint32_t msr_num, uint64_t value) { uint32_t lo = value & 0xFFFFFFFF; - uint32_t hi = value << 32; + uint32_t hi = (uint32_t)(value >> 32); asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr_num)); } diff --git a/kernel/src/misc/reboot.cpp b/kernel/src/misc/reboot.cpp index add7df72..30800dda 100644 --- a/kernel/src/misc/reboot.cpp +++ b/kernel/src/misc/reboot.cpp @@ -47,12 +47,12 @@ static void try_acpi_reboot() case ACPI::SystemIO: kdbgln("Attempting ACPI Reset via SystemIO: sending byte %d to port %lx", fadt->ResetValue, fadt->ResetReg.Address); - IO::outb(fadt->ResetReg.Address, fadt->ResetValue); + IO::outb((uint16_t)fadt->ResetReg.Address, fadt->ResetValue); break; case ACPI::GeneralPurposeIO: kdbgln("Attempting ACPI Reset via GeneralPurposeIO: sending byte %d to port %lx", fadt->ResetValue, fadt->ResetReg.Address); - IO::outb(fadt->ResetReg.Address, fadt->ResetValue); + IO::outb((uint16_t)fadt->ResetReg.Address, fadt->ResetValue); break; default: kwarnln("This method of rebooting via ACPI is not yet implemented"); return; } diff --git a/kernel/src/panic/Panic.cpp b/kernel/src/panic/Panic.cpp index 79649c13..c53fa6fa 100644 --- a/kernel/src/panic/Panic.cpp +++ b/kernel/src/panic/Panic.cpp @@ -57,7 +57,7 @@ extern "C" [[noreturn]] void __do_int_panic(Context* context, const char* file, { asm volatile("cli"); - if (context->number >= 0x20 && context->number < 0x30) { PIC::send_eoi(context->irq_number); } + if (context->number >= 0x20 && context->number < 0x30) { PIC::send_eoi((uint8_t)(context->irq_number & 0xFF)); } Task* task; if ((task = Scheduler::current_task())) diff --git a/kernel/src/std/stdio.cpp b/kernel/src/std/stdio.cpp index 09d45717..2c634200 100644 --- a/kernel/src/std/stdio.cpp +++ b/kernel/src/std/stdio.cpp @@ -65,7 +65,7 @@ static int internal_printf(const char* format, PutString put_string_callback, ss switch (current_char) { case 'c': { - buffer[buffer_insert_index++] = va_arg(ap, int); + buffer[buffer_insert_index++] = (char)va_arg(ap, int); if (buffer_insert_index == 1024) flush_buffer(); break; } @@ -194,7 +194,7 @@ static int internal_printf(const char* format, PutString put_string_callback, ss } if (buffer_insert_index > 0) flush_buffer(); - return written; + return (int)written; } int printf(const char* fmt, ...) diff --git a/kernel/src/std/stdlib.cpp b/kernel/src/std/stdlib.cpp index 44494d9f..b7d42f42 100644 --- a/kernel/src/std/stdlib.cpp +++ b/kernel/src/std/stdlib.cpp @@ -36,7 +36,7 @@ char* itoa(int32_t number, char* arr, int base) while (number != 0) { r = number % base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } @@ -56,7 +56,8 @@ char* itoa(int32_t number, char* arr, int base) char* ltoa(int64_t number, char* arr, int base) { - int i = 0, r, negative = 0; + int i = 0, negative = 0; + int64_t r; if (number == 0) { @@ -74,7 +75,7 @@ char* ltoa(int64_t number, char* arr, int base) while (number != 0) { r = number % base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } @@ -94,7 +95,8 @@ char* ltoa(int64_t number, char* arr, int base) char* utoa(uint32_t number, char* arr, int base) { - int i = 0, r; + int i = 0; + uint32_t r; if (number == 0) { @@ -106,7 +108,7 @@ char* utoa(uint32_t number, char* arr, int base) while (number != 0) { r = number % base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } @@ -120,7 +122,8 @@ char* utoa(uint32_t number, char* arr, int base) char* ultoa(uint64_t number, char* arr, int base) { - int i = 0, r; + int i = 0; + uint64_t r; if (number == 0) { @@ -132,7 +135,7 @@ char* ultoa(uint64_t number, char* arr, int base) while (number != 0) { r = number % base; - arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; + arr[i] = (char)((r > 9) ? (r - 10) + 'a' : r + '0'); i++; number /= base; } diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index 7beeb902..1f11e5b4 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -23,7 +23,7 @@ void Syscall::entry(Context* context) case SYS_rand: sys_rand(context); break; case SYS_getversion: sys_getversion(context, (char*)context->rdi, context->rsi); break; case SYS_gettid: sys_gettid(context); break; - case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, context->rdx); break; + case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx); break; case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break; default: context->rax = -1; break; } diff --git a/kernel/src/sys/elf/ELFLoader.cpp b/kernel/src/sys/elf/ELFLoader.cpp index c7d72f9d..236fb862 100644 --- a/kernel/src/sys/elf/ELFLoader.cpp +++ b/kernel/src/sys/elf/ELFLoader.cpp @@ -77,7 +77,7 @@ void* ELFLoader::load_elf_from_address(uintptr_t addr) kerrorln("Address is NULL, this is invalid :("); return 0; } - int pages = Utilities::get_blocks_from_size(0x1000, phdr->p_memsz); + uint64_t pages = Utilities::get_blocks_from_size(0x1000, phdr->p_memsz); void* buffer = MemoryManager::get_pages_at(phdr->p_vaddr, pages, phdr->p_flags & 2 ? MAP_READ_WRITE | MAP_USER : MAP_USER); memcpy(buffer, (void*)(addr + phdr->p_offset), phdr->p_filesz); diff --git a/kernel/src/sys/mem.cpp b/kernel/src/sys/mem.cpp index 9eba7426..f87843c6 100644 --- a/kernel/src/sys/mem.cpp +++ b/kernel/src/sys/mem.cpp @@ -66,7 +66,7 @@ void sys_munmap(Context* context, void* address, size_t size) context->rax = -1; return; } - int flags = kernelVMM.getFlags((uint64_t)address); + uint64_t flags = kernelVMM.getFlags((uint64_t)address); if (!(flags & MAP_USER)) { kdbgln("munmap failed: attempted to unmap a kernel page"); diff --git a/kernel/src/sys/paint.cpp b/kernel/src/sys/paint.cpp index aac06061..9a56de2a 100644 --- a/kernel/src/sys/paint.cpp +++ b/kernel/src/sys/paint.cpp @@ -20,7 +20,7 @@ void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint32_t color = (uint32_t)c; - framebuffer0.paint_rect(x, y, w, h, Color::from_integer(color)); + framebuffer0.paint_rect((uint32_t)x, (uint32_t)y, (uint32_t)w, (uint32_t)h, Color::from_integer(color)); context->rax = 0; } \ No newline at end of file diff --git a/kernel/src/thread/PIT.cpp b/kernel/src/thread/PIT.cpp index 8f3da946..074e5b5e 100644 --- a/kernel/src/thread/PIT.cpp +++ b/kernel/src/thread/PIT.cpp @@ -11,7 +11,7 @@ static uint16_t divisor = 65535; void PIT::initialize(uint64_t frequency) { - divisor = base_frequency / frequency; + divisor = (uint16_t)(base_frequency / frequency); kdbgln("Configuring PIT to use divisor %d (will tick %lu times per second)", divisor, frequency); if (divisor < 100) divisor = 100; IO::outb(PIT_CHANNEL_0_PORT, (uint8_t)(divisor & 0xFF));