diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index c630de7..6afd451 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -30,6 +30,18 @@ "-mcmodel=kernel", "-fno-builtin", + // Warnings + "-Wall", + "-Wextra", + "-Wfloat-equal", + "-Wpointer-arith", + "-Wcast-align", + "-Wredundant-decls", + "-Winit-self", + "-Wswitch-default", + "-Wstrict-overflow=5", + "-Wconversion", + // C++ flags "-fno-rtti", "-fexceptions", @@ -90,6 +102,18 @@ "-msoft-float", "-fno-builtin", + // Warnings + "-Wall", + "-Wextra", + "-Wfloat-equal", + "-Wpointer-arith", + "-Wcast-align", + "-Wredundant-decls", + "-Winit-self", + "-Wswitch-default", + "-Wstrict-overflow=5", + "-Wconversion", + // C++ flags "-fno-rtti", "-fexceptions", diff --git a/Architecture/amd64/AdvancedConfigurationAndPowerInterface.cpp b/Architecture/amd64/AdvancedConfigurationAndPowerInterface.cpp index 3a5c5af..26e5904 100644 --- a/Architecture/amd64/AdvancedConfigurationAndPowerInterface.cpp +++ b/Architecture/amd64/AdvancedConfigurationAndPowerInterface.cpp @@ -124,8 +124,8 @@ namespace ACPI if (FADT) { - outb(FADT->SMI_CommandPort, FADT->AcpiEnable); - while (!(inw(FADT->PM1aControlBlock) & 1)) + outb(s_cst(uint16_t, FADT->SMI_CommandPort), FADT->AcpiEnable); + while (!(inw(s_cst(uint16_t, FADT->PM1aControlBlock)) & 1)) ; } } diff --git a/Architecture/amd64/Bootstrap/Limine.c b/Architecture/amd64/Bootstrap/Limine.c index e7c8933..73d8c7e 100644 --- a/Architecture/amd64/Bootstrap/Limine.c +++ b/Architecture/amd64/Bootstrap/Limine.c @@ -123,9 +123,9 @@ SafeFunction NIF void init_limine() { struct limine_framebuffer *framebuffer = FrameBufferResponse->framebuffers[i]; binfo.Framebuffer[i].BaseAddress = (void *)((uint64_t)framebuffer->address - 0xffff800000000000); - binfo.Framebuffer[i].Width = framebuffer->width; - binfo.Framebuffer[i].Height = framebuffer->height; - binfo.Framebuffer[i].Pitch = framebuffer->pitch; + binfo.Framebuffer[i].Width = (uint32_t)framebuffer->width; + binfo.Framebuffer[i].Height = (uint32_t)framebuffer->height; + binfo.Framebuffer[i].Pitch = (uint32_t)framebuffer->pitch; binfo.Framebuffer[i].BitsPerPixel = framebuffer->bpp; binfo.Framebuffer[i].MemoryModel = framebuffer->memory_model; binfo.Framebuffer[i].RedMaskSize = framebuffer->red_mask_size; @@ -237,7 +237,7 @@ SafeFunction NIF void init_limine() binfo.Kernel.PhysicalBase = (void *)KernelAddressResponse->physical_base; binfo.Kernel.VirtualBase = (void *)KernelAddressResponse->virtual_base; - binfo.Kernel.FileBase = KernelFileResponse->kernel_file->address - 0xffff800000000000; + binfo.Kernel.FileBase = (void *)((uint64_t)KernelFileResponse->kernel_file->address - 0xffff800000000000); strncpy(binfo.Kernel.CommandLine, KernelFileResponse->kernel_file->cmdline, strlen(KernelFileResponse->kernel_file->cmdline) + 1); diff --git a/Architecture/amd64/DifferentiatedSystemDescriptionTable.cpp b/Architecture/amd64/DifferentiatedSystemDescriptionTable.cpp index 3cb9bdf..bc0c443 100644 --- a/Architecture/amd64/DifferentiatedSystemDescriptionTable.cpp +++ b/Architecture/amd64/DifferentiatedSystemDescriptionTable.cpp @@ -39,13 +39,13 @@ namespace ACPI uint16_t a = 0, b = 0; if (acpi->FADT->PM1aEventBlock) { - a = inw(acpi->FADT->PM1aEventBlock); - outw(acpi->FADT->PM1aEventBlock, a); + a = inw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock)); + outw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock), a); } if (acpi->FADT->PM1bEventBlock) { - b = inw(acpi->FADT->PM1bEventBlock); - outw(acpi->FADT->PM1bEventBlock, b); + b = inw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock)); + outw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock), b); } Event = a | b; } @@ -99,12 +99,24 @@ namespace ACPI trace("Shutting down..."); if (SCI_EN == 1) { - outw(acpi->FADT->PM1aControlBlock, (inw(acpi->FADT->PM1aControlBlock) & 0xE3FF) | ((SLP_TYPa << 10) | ACPI_SLEEP)); + outw(s_cst(uint16_t, acpi->FADT->PM1aControlBlock), + s_cst(uint16_t, + (inw(s_cst(uint16_t, + acpi->FADT->PM1aControlBlock)) & + 0xE3FF) | + ((SLP_TYPa << 10) | ACPI_SLEEP))); + if (acpi->FADT->PM1bControlBlock) - outw(acpi->FADT->PM1bControlBlock, (inw(acpi->FADT->PM1bControlBlock) & 0xE3FF) | ((SLP_TYPb << 10) | ACPI_SLEEP)); - outw(PM1a_CNT, SLP_TYPa | SLP_EN); + outw(s_cst(uint16_t, acpi->FADT->PM1bControlBlock), + s_cst(uint16_t, + (inw( + s_cst(uint16_t, acpi->FADT->PM1bControlBlock)) & + 0xE3FF) | + ((SLP_TYPb << 10) | ACPI_SLEEP))); + + outw(s_cst(uint16_t, PM1a_CNT), SLP_TYPa | SLP_EN); if (PM1b_CNT) - outw(PM1b_CNT, SLP_TYPb | SLP_EN); + outw(s_cst(uint16_t, PM1b_CNT), SLP_TYPb | SLP_EN); } } @@ -114,12 +126,17 @@ namespace ACPI switch (acpi->FADT->ResetReg.AddressSpace) { case ACPI_GAS_MMIO: + { *(uint8_t *)(acpi->FADT->ResetReg.Address) = acpi->FADT->ResetValue; break; + } case ACPI_GAS_IO: - outb(acpi->FADT->ResetReg.Address, acpi->FADT->ResetValue); + { + outb(s_cst(uint16_t, acpi->FADT->ResetReg.Address), acpi->FADT->ResetValue); break; + } case ACPI_GAS_PCI: + { fixme("ACPI_GAS_PCI not supported."); /* seg - 0 @@ -131,6 +148,12 @@ namespace ACPI */ break; } + default: + { + error("Unknown reset register address space: %d", acpi->FADT->ResetReg.AddressSpace); + break; + } + } } DSDT::DSDT(ACPI *acpi) : Interrupts::Handler(acpi->FADT->SCI_Interrupt) @@ -157,11 +180,11 @@ namespace ACPI S5Address += ((*S5Address & 0xC0) >> 6) + 2; if (*S5Address == 0x0A) S5Address++; - SLP_TYPa = *(S5Address) << 10; + SLP_TYPa = s_cst(uint16_t, *(S5Address) << 10); S5Address++; if (*S5Address == 0x0A) S5Address++; - SLP_TYPb = *(S5Address) << 10; + SLP_TYPb = s_cst(uint16_t, *(S5Address) << 10); SMI_CMD = acpi->FADT->SMI_CommandPort; ACPI_ENABLE = acpi->FADT->AcpiEnable; ACPI_DISABLE = acpi->FADT->AcpiDisable; @@ -175,8 +198,8 @@ namespace ACPI uint16_t value = ACPI_POWER_BUTTON | ACPI_SLEEP_BUTTON | ACPI_WAKE; { - uint16_t a = acpi->FADT->PM1aEventBlock + (acpi->FADT->PM1EventLength / 2); - uint16_t b = acpi->FADT->PM1bEventBlock + (acpi->FADT->PM1EventLength / 2); + uint16_t a = s_cst(uint16_t, acpi->FADT->PM1aEventBlock + (acpi->FADT->PM1EventLength / 2)); + uint16_t b = s_cst(uint16_t, acpi->FADT->PM1bEventBlock + (acpi->FADT->PM1EventLength / 2)); debug("SCI Event: %#llx [a:%#x b:%#x]", value, a, b); if (acpi->FADT->PM1aEventBlock) outw(a, value); @@ -188,13 +211,13 @@ namespace ACPI uint16_t a = 0, b = 0; if (acpi->FADT->PM1aEventBlock) { - a = inw(acpi->FADT->PM1aEventBlock); - outw(acpi->FADT->PM1aEventBlock, a); + a = inw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock)); + outw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock), a); } if (acpi->FADT->PM1bEventBlock) { - b = inw(acpi->FADT->PM1bEventBlock); - outw(acpi->FADT->PM1bEventBlock, b); + b = inw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock)); + outw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock), b); } } ((APIC::APIC *)Interrupts::apic[0])->RedirectIRQ(0, acpi->FADT->SCI_Interrupt, 1); diff --git a/Architecture/amd64/MultipleAPICDescriptionTable.cpp b/Architecture/amd64/MultipleAPICDescriptionTable.cpp index 434c75b..8a069d0 100644 --- a/Architecture/amd64/MultipleAPICDescriptionTable.cpp +++ b/Architecture/amd64/MultipleAPICDescriptionTable.cpp @@ -56,6 +56,11 @@ namespace ACPI KPrint("APIC found at \e8888FF%#lx\eCCCCCC", LAPICAddress); break; } + default: + { + KPrint("Unknown MADT entry \e8888FF%#lx\eCCCCCC", *(ptr)); + break; + } } Memory::Virtual(KernelPageTable).Map((void *)LAPICAddress, (void *)LAPICAddress, Memory::PTFlag::RW | Memory::PTFlag::PCD); // I should map more than one page? } diff --git a/Architecture/amd64/cpu/AdvancedProgrammableInterruptController.cpp b/Architecture/amd64/cpu/AdvancedProgrammableInterruptController.cpp index 0c06152..3a288d0 100644 --- a/Architecture/amd64/cpu/AdvancedProgrammableInterruptController.cpp +++ b/Architecture/amd64/cpu/AdvancedProgrammableInterruptController.cpp @@ -38,9 +38,9 @@ namespace APIC if (x2APICSupported) { if (Register != APIC_ICRHI) - return rdmsr((Register >> 4) + 0x800); + return s_cst(uint32_t, rdmsr((Register >> 4) + 0x800)); else - return rdmsr(0x30 + 0x800); + return s_cst(uint32_t, rdmsr(0x30 + 0x800)); } else { @@ -107,7 +107,7 @@ namespace APIC } while (icr.DeliveryStatus != Idle); } - void APIC::IPI(uint8_t CPU, InterruptCommandRegisterLow icr) + void APIC::IPI(int CPU, InterruptCommandRegisterLow icr) { SmartCriticalSection(APICLock); if (x2APICSupported) @@ -118,12 +118,12 @@ namespace APIC else { this->Write(APIC_ICRHI, (CPU << 24)); - this->Write(APIC_ICRLO, icr.raw); + this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw)); this->WaitForIPI(); } } - void APIC::SendInitIPI(uint8_t CPU) + void APIC::SendInitIPI(int CPU) { SmartCriticalSection(APICLock); if (x2APICSupported) @@ -137,12 +137,12 @@ namespace APIC icr.DeliveryMode = INIT; icr.Level = Assert; this->Write(APIC_ICRHI, (CPU << 24)); - this->Write(APIC_ICRLO, icr.raw); + this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw)); this->WaitForIPI(); } } - void APIC::SendStartupIPI(uint8_t CPU, uint64_t StartupAddress) + void APIC::SendStartupIPI(int CPU, uint64_t StartupAddress) { SmartCriticalSection(APICLock); if (x2APICSupported) @@ -153,11 +153,11 @@ namespace APIC else { InterruptCommandRegisterLow icr = {.raw = 0}; - icr.Vector = StartupAddress >> 12; + icr.Vector = s_cst(uint8_t, StartupAddress >> 12); icr.DeliveryMode = Startup; icr.Level = Assert; this->Write(APIC_ICRHI, (CPU << 24)); - this->Write(APIC_ICRLO, icr.raw); + this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw)); this->WaitForIPI(); } } @@ -168,14 +168,14 @@ namespace APIC return ((IOAPICVersion *)&TableAddress)->MaximumRedirectionEntry; } - void APIC::RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status) + void APIC::RawRedirectIRQ(uint16_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status) { uint64_t Value = Vector; int64_t IOAPICTarget = -1; for (uint64_t i = 0; ((ACPI::MADT *)PowerManager->GetMADT())->ioapic[i] != 0; i++) if (((ACPI::MADT *)PowerManager->GetMADT())->ioapic[i]->GSIBase <= GSI) - if (((ACPI::MADT *)PowerManager->GetMADT())->ioapic[i]->GSIBase + IOGetMaxRedirect(i) > GSI) + if (((ACPI::MADT *)PowerManager->GetMADT())->ioapic[i]->GSIBase + IOGetMaxRedirect(s_cst(uint32_t, i)) > GSI) { IOAPICTarget = i; break; @@ -205,7 +205,7 @@ namespace APIC this->IOWrite(((ACPI::MADT *)PowerManager->GetMADT())->ioapic[IOAPICTarget]->Address, IORegister + 1, (uint32_t)(Value >> 32)); } - void APIC::RedirectIRQ(int CPU, uint8_t IRQ, int Status) + void APIC::RedirectIRQ(int CPU, uint16_t IRQ, int Status) { for (uint64_t i = 0; i < ((ACPI::MADT *)PowerManager->GetMADT())->iso.size(); i++) if (((ACPI::MADT *)PowerManager->GetMADT())->iso[i]->IRQSource == IRQ) @@ -224,7 +224,7 @@ namespace APIC { SmartCriticalSection(APICLock); debug("Redirecting IRQs..."); - for (int i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) this->RedirectIRQ(CPU, i, 1); debug("Redirecting IRQs completed."); } @@ -314,7 +314,7 @@ namespace APIC Spurious Spurious = {.raw = this->Read(APIC_SVR)}; Spurious.Vector = IRQ223; // TODO: Should I map the IRQ to something? Spurious.Software = 1; - this->Write(APIC_SVR, Spurious.raw); + this->Write(APIC_SVR, s_cst(uint32_t, Spurious.raw)); static int once = 0; if (!once++) @@ -337,14 +337,14 @@ namespace APIC { SmartCriticalSection(APICLock); LVTTimer timer = {.raw = 0}; - timer.Vector = Vector; + timer.Vector = s_cst(uint8_t, Vector); timer.TimerMode = 0; if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0) this->lapic->Write(APIC_TDCR, DivideBy128); else this->lapic->Write(APIC_TDCR, DivideBy16); - this->lapic->Write(APIC_TICR, Ticks * Miliseconds); - this->lapic->Write(APIC_TIMER, timer.raw); + this->lapic->Write(APIC_TICR, s_cst(uint32_t, Ticks * Miliseconds)); + this->lapic->Write(APIC_TIMER, s_cst(uint32_t, timer.raw)); } Timer::Timer(APIC *apic) : Interrupts::Handler(0) /* IRQ0 */ @@ -372,8 +372,8 @@ namespace APIC // Initialize APIC timer this->lapic->Write(APIC_TDCR, Divider); - this->lapic->Write(APIC_TICR, Ticks); - this->lapic->Write(APIC_TIMER, timer.raw); + this->lapic->Write(APIC_TICR, s_cst(uint32_t, Ticks)); + this->lapic->Write(APIC_TIMER, s_cst(uint32_t, timer.raw)); trace("%d APIC Timer %d ticks in.", GetCurrentCPU()->ID, Ticks); KPrint("APIC Timer: \e8888FF%ld\eCCCCCC ticks.", Ticks); } diff --git a/Architecture/amd64/cpu/GlobalDescriptorTable.cpp b/Architecture/amd64/cpu/GlobalDescriptorTable.cpp index a217ea8..58c89f2 100644 --- a/Architecture/amd64/cpu/GlobalDescriptorTable.cpp +++ b/Architecture/amd64/cpu/GlobalDescriptorTable.cpp @@ -147,7 +147,7 @@ namespace GlobalDescriptorTable gdt[Core].Entries->TaskStateSegment.BaseLow = Base & 0xFFFF; gdt[Core].Entries->TaskStateSegment.BaseMiddle = (Base >> 16) & 0xFF; gdt[Core].Entries->TaskStateSegment.BaseHigh = (Base >> 24) & 0xFF; - gdt[Core].Entries->TaskStateSegment.BaseUpper = (Base >> 32) & 0xFFFFFFFF; + gdt[Core].Entries->TaskStateSegment.BaseUpper = s_cst(uint32_t, (Base >> 32) & 0xFFFFFFFF); gdt[Core].Entries->TaskStateSegment.Flags = {.A = 1, .RW = 0, .DC = 0, .E = 1, .S = 0, .DPL = 0, .P = 1}; gdt[Core].Entries->TaskStateSegment.Granularity = (0 << 4) | ((Limit >> 16) & 0xF); diff --git a/Architecture/amd64/cpu/InterruptDescriptorTable.cpp b/Architecture/amd64/cpu/InterruptDescriptorTable.cpp index 79787b0..494970f 100644 --- a/Architecture/amd64/cpu/InterruptDescriptorTable.cpp +++ b/Architecture/amd64/cpu/InterruptDescriptorTable.cpp @@ -7,6 +7,9 @@ #include "gdt.hpp" +/* conversion from ‘uint64_t’ {aka ‘long unsigned int’} to ‘unsigned char:2’ may change value */ +#pragma GCC diagnostic ignored "-Wconversion" + extern "C" void MainInterruptHandler(void *Data); extern "C" void ExceptionHandler(void *Data); @@ -26,8 +29,8 @@ namespace InterruptDescriptorTable InterruptDescriptorTableFlags Ring, uint16_t SegmentSelector) { - Entries[Index].BaseLow = (uint16_t)((uint64_t)Base & 0xFFFF); - Entries[Index].BaseHigh = (uint64_t)((uint64_t)Base >> 16 /* & 0xFFFF */); + Entries[Index].BaseLow = s_cst(uint16_t, ((uint64_t)Base & 0xFFFF)); + Entries[Index].BaseHigh = s_cst(uint64_t, ((uint64_t)Base >> 16 /* & 0xFFFF */)); Entries[Index].SegmentSelector = SegmentSelector; Entries[Index].Flags = Attribute; Entries[Index].Reserved1 = 0; diff --git a/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp b/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp index 3b7f8bd..7c03637 100644 --- a/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp +++ b/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp @@ -50,7 +50,7 @@ SafeFunction CPUData *GetCurrentCPU() extern "C" void StartCPU() { CPU::Interrupts(CPU::Disable); - uint64_t CoreID = (int)*reinterpret_cast(CORE); + int CoreID = (int)*reinterpret_cast(CORE); CPU::InitializeFeatures(CoreID); // Initialize GDT and IDT Interrupts::Initialize(CoreID); @@ -96,14 +96,14 @@ namespace SMP memcpy((void *)TRAMPOLINE_START, &_trampoline_start, TrampolineLength); - POKE(volatile uint64_t, PAGE_TABLE) = (uint64_t)KernelPageTable; - POKE(volatile uint64_t, STACK) = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; - POKE(volatile uint64_t, CORE) = i; + VPOKE(uint64_t, PAGE_TABLE) = (uint64_t)KernelPageTable; + VPOKE(uint64_t, STACK) = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; + VPOKE(int, CORE) = i; asmv("sgdt [0x580]\n" "sidt [0x590]\n"); - POKE(volatile uint64_t, START_ADDR) = (uintptr_t)&StartCPU; + VPOKE(uint64_t, START_ADDR) = (uintptr_t)&StartCPU; ((APIC::APIC *)Interrupts::apic[0])->SendInitIPI(((ACPI::MADT *)madt)->lapic[i]->APICId); ((APIC::APIC *)Interrupts::apic[0])->SendStartupIPI(((ACPI::MADT *)madt)->lapic[i]->APICId, TRAMPOLINE_START); diff --git a/Architecture/amd64/cpu/apic.hpp b/Architecture/amd64/cpu/apic.hpp index 0c8e606..cd23473 100644 --- a/Architecture/amd64/cpu/apic.hpp +++ b/Architecture/amd64/cpu/apic.hpp @@ -309,12 +309,12 @@ namespace APIC void EOI(); void RedirectIRQs(int CPU = 0); void WaitForIPI(); - void IPI(uint8_t CPU, InterruptCommandRegisterLow icr); - void SendInitIPI(uint8_t CPU); - void SendStartupIPI(uint8_t CPU, uint64_t StartupAddress); + void IPI(int CPU, InterruptCommandRegisterLow icr); + void SendInitIPI(int CPU); + void SendStartupIPI(int CPU, uint64_t StartupAddress); uint32_t IOGetMaxRedirect(uint32_t APICID); - void RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status); - void RedirectIRQ(int CPU, uint8_t IRQ, int Status); + void RawRedirectIRQ(uint16_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status); + void RedirectIRQ(int CPU, uint16_t IRQ, int Status); APIC(int Core); ~APIC(); }; diff --git a/Architecture/i686/cpu/apic.hpp b/Architecture/i686/cpu/apic.hpp index 07d5881..f4991fd 100644 --- a/Architecture/i686/cpu/apic.hpp +++ b/Architecture/i686/cpu/apic.hpp @@ -314,7 +314,7 @@ namespace APIC void SendStartupIPI(uint8_t CPU, uint64_t StartupAddress); uint32_t IOGetMaxRedirect(uint32_t APICID); void RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status); - void RedirectIRQ(int CPU, uint8_t IRQ, int Status); + void RedirectIRQ(int CPU, uint16_t IRQ, int Status); APIC(int Core); ~APIC(); }; diff --git a/Core/CPU.cpp b/Core/CPU.cpp index cfcd8ab..e986b18 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -140,6 +140,8 @@ namespace CPU #endif return true; } + default: + break; } return false; } diff --git a/Core/Crash/CrashHandler.cpp b/Core/Crash/CrashHandler.cpp index c5fb24c..247c88c 100644 --- a/Core/Crash/CrashHandler.cpp +++ b/Core/Crash/CrashHandler.cpp @@ -508,7 +508,7 @@ namespace CrashHandler EHPrint("\e00FF000"); if (i % 128 == 127) { - short Percentage = (i * 100) / bm.Size; + short Percentage = s_cst(short, (i * 100) / bm.Size); EHPrint("\n\eFAFAFA[%03ld%%] %08ld: ", Percentage, i); Display->SetBuffer(SBIdx); } @@ -524,8 +524,8 @@ namespace CrashHandler uint64_t Reserved = KernelAllocator.GetReservedMemory(); EHPrint("\e22AA44Total: %ld bytes\n\eFF0000Used: %ld bytes\n\e00FF00Free: %ld bytes\n\eFF00FFReserved: %ld bytes\n", Total, Used, Free, Reserved); - int Progress = (Used * 100) / Total; - int ReservedProgress = (Reserved * 100) / Total; + int Progress = s_cst(int, (Used * 100) / Total); + int ReservedProgress = s_cst(int, (Reserved * 100) / Total); EHPrint("\e22AA44%3d%% \eCCCCCC[", Progress); for (int i = 0; i < Progress; i++) EHPrint("\eFF0000|"); @@ -695,7 +695,7 @@ namespace CrashHandler if (unlikely(i % 0x1000 == 0)) { - int NewProgress = (i * 100) / ProgressLength; + int NewProgress = (int)((i * 100) / ProgressLength); if (unlikely(NewProgress != Progress)) { Progress = NewProgress; diff --git a/Core/Crash/KBDrv.cpp b/Core/Crash/KBDrv.cpp index 7db6429..81e3666 100644 --- a/Core/Crash/KBDrv.cpp +++ b/Core/Crash/KBDrv.cpp @@ -126,6 +126,9 @@ namespace CrashHandler case KEY_D_RIGHT: case KEY_D_DOWN: ArrowInput(scanCode); + break; + default: + break; } int key = GetLetterFromScanCode(scanCode); @@ -148,8 +151,8 @@ namespace CrashHandler } else { - append(UserInputBuffer, key); - Display->Print(key, SBIdx); + append(UserInputBuffer, s_cst(char, key)); + Display->Print((char)key, SBIdx); BackSpaceLimit++; } Display->SetBuffer(SBIdx); // Update as we type. diff --git a/Core/Crash/Screens/Main.cpp b/Core/Crash/Screens/Main.cpp index 4edf9d7..469840c 100644 --- a/Core/Crash/Screens/Main.cpp +++ b/Core/Crash/Screens/Main.cpp @@ -141,6 +141,13 @@ namespace CrashHandler EHPrint(" %ld\n", SelCode.Idx); break; } + default: + { + EHPrint(" ? \n"); + EHPrint(" ? \n"); + EHPrint(" %ld\n", SelCode.Idx); + break; + } } break; } @@ -181,6 +188,13 @@ namespace CrashHandler EHPrint(" %ld\n", SelCode.Idx); break; } + default: + { + EHPrint(" ? \n"); + EHPrint(" ? \n"); + EHPrint(" %ld\n", SelCode.Idx); + break; + } } break; } @@ -220,6 +234,13 @@ namespace CrashHandler EHPrint(" %ld\n", SelCode.Idx); break; } + default: + { + EHPrint(" ? \n"); + EHPrint(" ? \n"); + EHPrint(" %ld\n", SelCode.Idx); + break; + } } break; } @@ -260,6 +281,13 @@ namespace CrashHandler EHPrint(" %ld\n", SelCode.Idx); break; } + default: + { + EHPrint(" ? \n"); + EHPrint(" ? \n"); + EHPrint(" %ld\n", SelCode.Idx); + break; + } } break; } diff --git a/Core/Driver/Driver.cpp b/Core/Driver/Driver.cpp index d4fe9ec..4ad539d 100644 --- a/Core/Driver/Driver.cpp +++ b/Core/Driver/Driver.cpp @@ -235,9 +235,9 @@ namespace Driver if (!Handle.InterruptCallback) { #if defined(a64) || defined(a32) - int IntNum = Frame->InterruptNumber - 32; + uint64_t IntNum = Frame->InterruptNumber - 32; #elif defined(aa64) - int IntNum = Frame->InterruptNumber; + uint64_t IntNum = Frame->InterruptNumber; #endif warn("Interrupt callback for %ld is not set for driver %ld!", IntNum, Handle.DriverUID); return; diff --git a/Core/Driver/DriverLoading/BindInterrupt.cpp b/Core/Driver/DriverLoading/BindInterrupt.cpp index 8ad8272..753ba0a 100644 --- a/Core/Driver/DriverLoading/BindInterrupt.cpp +++ b/Core/Driver/DriverLoading/BindInterrupt.cpp @@ -20,7 +20,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -75,7 +75,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -123,7 +123,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -172,7 +172,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -253,7 +253,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -302,7 +302,7 @@ namespace Driver debug("Searching for conflicting drivers..."); if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -392,7 +392,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); diff --git a/Core/Driver/DriverLoading/BindPCI.cpp b/Core/Driver/DriverLoading/BindPCI.cpp index 11a8f18..45d3597 100644 --- a/Core/Driver/DriverLoading/BindPCI.cpp +++ b/Core/Driver/DriverLoading/BindPCI.cpp @@ -133,7 +133,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -181,7 +181,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -229,7 +229,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -306,7 +306,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -383,7 +383,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -431,7 +431,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); @@ -479,7 +479,7 @@ namespace Driver if (fexExtended->Driver.OverrideOnConflict) { - std::vector DriversToRemove = std::vector(); + std::vector DriversToRemove = std::vector(); foreach (auto Drv in Drivers) { FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); diff --git a/Core/InterruptsManager.cpp b/Core/InterruptsManager.cpp index 7967e41..e10b096 100644 --- a/Core/InterruptsManager.cpp +++ b/Core/InterruptsManager.cpp @@ -190,16 +190,16 @@ namespace Interrupts Handler::~Handler() { - debug("Unregistering interrupt handler for IRQ%d.", InterruptNumber); + debug("Unregistering interrupt handler for IRQ%d.", this->InterruptNumber); for (size_t i = 0; i < RegisteredEvents.size(); i++) { - if (RegisteredEvents[i].ID == InterruptNumber) + if (RegisteredEvents[i].ID == this->InterruptNumber) { RegisteredEvents.remove(i); return; } } - warn("Event %d not found.", InterruptNumber); + warn("Event %d not found.", this->InterruptNumber); } #if defined(a64) diff --git a/Core/PeripheralComponentInterconnect.cpp b/Core/PeripheralComponentInterconnect.cpp index 2310dec..699568a 100644 --- a/Core/PeripheralComponentInterconnect.cpp +++ b/Core/PeripheralComponentInterconnect.cpp @@ -22,9 +22,9 @@ namespace PCI { uint8_t Digit = (Value >> (4 - (i * 4))) & 0xF; if (Digit < 10) - Buffer[i] = '0' + Digit; + Buffer[i] = s_cst(char, '0' + Digit); else - Buffer[i] = 'A' + (Digit - 10); + Buffer[i] = s_cst(char, 'A' + (Digit - 10)); } return Buffer; } @@ -37,9 +37,9 @@ namespace PCI { uint8_t Digit = (Value >> (28 - (i * 4))) & 0xF; if (Digit < 10) - Buffer[i] = '0' + Digit; + Buffer[i] = s_cst(char, '0' + Digit); else - Buffer[i] = 'A' + (Digit - 10); + Buffer[i] = s_cst(char, 'A' + (Digit - 10)); } return Buffer; } @@ -555,6 +555,8 @@ namespace PCI } break; } + default: + break; } fixme("Unknown device %04x:%04x", VendorID, DeviceID); return u32ToHexString(DeviceID); @@ -649,7 +651,10 @@ namespace PCI } break; } + default: + break; } + default: break; } case 0x03: @@ -667,6 +672,8 @@ namespace PCI return "VGA Compatible Controller"; } break; + default: + break; } break; } @@ -838,7 +845,7 @@ namespace PCI PCI::PCI() { #if defined(a64) - int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig); + int Entries = s_cst(int, ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig)); Memory::Virtual vma = Memory::Virtual(KernelPageTable); for (int t = 0; t < Entries; t++) { diff --git a/Core/Symbols.cpp b/Core/Symbols.cpp index 30443a7..4d5c0e7 100644 --- a/Core/Symbols.cpp +++ b/Core/Symbols.cpp @@ -46,6 +46,8 @@ namespace SymbolResolver debug("String table found, %d entries", ElfSections[i].sh_size); } break; + default: + break; } if (ElfSymbols != nullptr && strtab != nullptr) diff --git a/Core/Timer.cpp b/Core/Timer.cpp index 1a264c5..fc7858b 100644 --- a/Core/Timer.cpp +++ b/Core/Timer.cpp @@ -64,7 +64,7 @@ namespace Time this->hpet = (void *)acpi->HPET->Address.Address; HPET *hpet = (HPET *)this->hpet; trace("%s timer is at address %016p", acpi->HPET->Header.OEMID, (void *)acpi->HPET->Address.Address); - clk = hpet->GeneralCapabilities >> 32; + clk = s_cst(uint32_t, hpet->GeneralCapabilities >> 32); mmoutq(&hpet->GeneralConfiguration, 0); mmoutq(&hpet->MainCounterValue, 0); mmoutq(&hpet->GeneralConfiguration, 1); diff --git a/Core/UniversalAsynchronousReceiverTransmitter.cpp b/Core/UniversalAsynchronousReceiverTransmitter.cpp index f99dd1e..01a9322 100644 --- a/Core/UniversalAsynchronousReceiverTransmitter.cpp +++ b/Core/UniversalAsynchronousReceiverTransmitter.cpp @@ -80,16 +80,16 @@ namespace UniversalAsynchronousReceiverTransmitter return; // Initialize the serial port - NoProfiler_outportb(Port + 1, 0x00); // Disable all interrupts - NoProfiler_outportb(Port + 3, SERIAL_ENABLE_DLAB); // Enable DLAB (set baud rate divisor) - NoProfiler_outportb(Port + 0, SERIAL_RATE_115200_LO); // Set divisor to 1 (lo byte) 115200 baud - NoProfiler_outportb(Port + 1, SERIAL_RATE_115200_HI); // (hi byte) - NoProfiler_outportb(Port + 3, 0x03); // 8 bits, no parity, one stop bit - NoProfiler_outportb(Port + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold - NoProfiler_outportb(Port + 4, 0x0B); // IRQs enabled, RTS/DSR set + NoProfiler_outportb(s_cst(uint16_t, Port + 1), 0x00); // Disable all interrupts + NoProfiler_outportb(s_cst(uint16_t, Port + 3), SERIAL_ENABLE_DLAB); // Enable DLAB (set baud rate divisor) + NoProfiler_outportb(s_cst(uint16_t, Port + 0), SERIAL_RATE_115200_LO); // Set divisor to 1 (lo byte) 115200 baud + NoProfiler_outportb(s_cst(uint16_t, Port + 1), SERIAL_RATE_115200_HI); // (hi byte) + NoProfiler_outportb(s_cst(uint16_t, Port + 3), 0x03); // 8 bits, no parity, one stop bit + NoProfiler_outportb(s_cst(uint16_t, Port + 2), 0xC7); // Enable FIFO, clear them, with 14-byte threshold + NoProfiler_outportb(s_cst(uint16_t, Port + 4), 0x0B); // IRQs enabled, RTS/DSR set // Check if the serial port is faulty. - if (NoProfiler_inportb(Port + 0) != 0xAE) + if (NoProfiler_inportb(s_cst(uint16_t, Port + 0)) != 0xAE) { static int once = 0; if (!once++) @@ -99,7 +99,7 @@ namespace UniversalAsynchronousReceiverTransmitter } // Set to normal operation mode. - NoProfiler_outportb(Port + 4, 0x0F); + NoProfiler_outportb(s_cst(uint16_t, Port + 4), 0x0F); serialports[PortNumber] = true; #endif } @@ -109,7 +109,7 @@ namespace UniversalAsynchronousReceiverTransmitter SafeFunction NIF void UART::Write(uint8_t Char) { #if defined(a64) || defined(a32) - while ((NoProfiler_inportb(Port + 5) & SERIAL_BUFFER_EMPTY) == 0) + while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & SERIAL_BUFFER_EMPTY) == 0) ; NoProfiler_outportb(Port, Char); #endif @@ -121,7 +121,7 @@ namespace UniversalAsynchronousReceiverTransmitter SafeFunction NIF uint8_t UART::Read() { #if defined(a64) || defined(a32) - while ((NoProfiler_inportb(Port + 5) & 1) == 0) + while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & 1) == 0) ; return NoProfiler_inportb(Port); #endif diff --git a/Core/Video/Display.cpp b/Core/Video/Display.cpp index 4c2f535..c77986d 100644 --- a/Core/Video/Display.cpp +++ b/Core/Video/Display.cpp @@ -116,14 +116,14 @@ namespace Video uint8_t g = (color >> 8) & 0xff; uint8_t b = (color >> 16) & 0xff; - r = (r * Value) / 100; - g = (g * Value) / 100; - b = (b * Value) / 100; + r = s_cst(uint8_t, (r * Value) / 100); + g = s_cst(uint8_t, (g * Value) / 100); + b = s_cst(uint8_t, (b * Value) / 100); pixel[y * this->Buffers[Index].Width + x] = (b << 16) | (g << 8) | r; } } - this->Buffers[Index].Brightness = Value; + this->Buffers[Index].Brightness = s_cst(char, Value); } void Display::SetBufferCursor(int Index, uint32_t X, uint32_t Y) @@ -198,7 +198,7 @@ namespace Video { uint32_t LineSize = this->Buffers[Index].Width * (this->framebuffer.BitsPerPixel / 8); uint32_t BytesToMove = LineSize * Lines * this->CurrentFont->GetInfo().Height; - uint32_t BytesToClear = this->Buffers[Index].Size - BytesToMove; + size_t BytesToClear = this->Buffers[Index].Size - BytesToMove; memmove(this->Buffers[Index].Buffer, (uint8_t *)this->Buffers[Index].Buffer + BytesToMove, BytesToClear); memset((uint8_t *)this->Buffers[Index].Buffer + BytesToClear, 0, BytesToMove); } @@ -304,6 +304,8 @@ namespace Video this->Buffers[Index].CursorY += this->GetCurrentFont()->GetInfo().Height; return Char; } + default: + break; } uint32_t FontHeight = this->GetCurrentFont()->GetInfo().Height; @@ -412,7 +414,7 @@ namespace Video this->ClearBuffer(0); this->SetBuffer(0); - for (size_t i = 0; i < sizeof(this->Buffers) / sizeof(this->Buffers[0]); i++) + for (int i = 0; i < s_cst(int, sizeof(this->Buffers) / sizeof(this->Buffers[0])); i++) { if (this->Buffers[i].Checksum == 0xBBFFE515A117E) this->DeleteBuffer(i); diff --git a/Execute/Elf/Parse.cpp b/Execute/Elf/Parse.cpp index 056fc81..187630d 100644 --- a/Execute/Elf/Parse.cpp +++ b/Execute/Elf/Parse.cpp @@ -50,6 +50,10 @@ namespace Execute SymbolTable = shdr; StringTable = GetELFSection(Header, shdr->sh_link); break; + default: + { + break; + } } } diff --git a/GUI/GUITools.cpp b/GUI/GUITools.cpp index 22e61d2..2202fd0 100644 --- a/GUI/GUITools.cpp +++ b/GUI/GUITools.cpp @@ -136,6 +136,8 @@ namespace GraphicalUserInterface { } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-overflow" void PaintChar(Video::Font *font, ScreenBitmap *Bitmap, char c, uint32_t Color, long *CharCursorX, long *CharCursorY) { switch (font->GetInfo().Type) @@ -182,6 +184,7 @@ namespace GraphicalUserInterface break; } } +#pragma GCC diagnostic pop void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color) { diff --git a/GUI/WidgetEvents.cpp b/GUI/WidgetEvents.cpp index b650ded..45d6720 100644 --- a/GUI/WidgetEvents.cpp +++ b/GUI/WidgetEvents.cpp @@ -69,15 +69,15 @@ namespace GraphicalUserInterface this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size)); memset(this->Buffer->Data, 0, this->Buffer->Size); - NeedRedraw = true; + this->NeedRedraw = true; } - if (NeedRedraw) + if (this->NeedRedraw) { memset(this->Buffer->Data, 0, this->Buffer->Size); this->OnPaintBackground(e); this->OnPaintForeground(e); - NeedRedraw = false; + this->NeedRedraw = false; } DrawOverBitmap(((Window *)this->ParentWindow)->GetBuffer(), this->Buffer, 0, 0); } @@ -92,7 +92,7 @@ namespace GraphicalUserInterface { debug("Button Hold"); Button->Pressed = true; - NeedRedraw = true; + this->NeedRedraw = true; } } } @@ -114,7 +114,7 @@ namespace GraphicalUserInterface ((void (*)(void))Button->OnClick)(); Button->Pressed = false; - NeedRedraw = true; + this->NeedRedraw = true; } } } @@ -128,12 +128,12 @@ namespace GraphicalUserInterface if (Button->rect.Contains(e->MouseMove.X, e->MouseMove.Y)) { Button->Hover = true; - NeedRedraw = true; + this->NeedRedraw = true; } else { Button->Hover = false; - NeedRedraw = true; + this->NeedRedraw = true; } } } diff --git a/GUI/Widgets.cpp b/GUI/Widgets.cpp index 9559c33..f89027c 100644 --- a/GUI/Widgets.cpp +++ b/GUI/Widgets.cpp @@ -17,7 +17,7 @@ namespace GraphicalUserInterface { Handle WidgetCollection::CreatePanel(Rect rect, uint32_t Color) { - PanelObject *panel = (PanelObject *)mem->RequestPages(TO_PAGES(sizeof(PanelObject))); + PanelObject *panel = (PanelObject *)this->mem->RequestPages(TO_PAGES(sizeof(PanelObject))); panel->Handle.Type[0] = 'P'; panel->Handle.Type[1] = 'N'; @@ -31,13 +31,13 @@ namespace GraphicalUserInterface panel->Shadow = false; Panels.push_back(panel); - NeedRedraw = true; + this->NeedRedraw = true; return (Handle)panel; } Handle WidgetCollection::CreateLabel(Rect rect, const char *Text) { - LabelObject *label = (LabelObject *)mem->RequestPages(TO_PAGES(sizeof(LabelObject))); + LabelObject *label = (LabelObject *)this->mem->RequestPages(TO_PAGES(sizeof(LabelObject))); label->Handle.Type[0] = 'L'; label->Handle.Type[1] = 'B'; @@ -57,7 +57,7 @@ namespace GraphicalUserInterface Handle WidgetCollection::CreateButton(Rect rect, const char *Text, uintptr_t OnClick) { - ButtonObject *button = (ButtonObject *)mem->RequestPages(TO_PAGES(sizeof(ButtonObject))); + ButtonObject *button = (ButtonObject *)this->mem->RequestPages(TO_PAGES(sizeof(ButtonObject))); button->Handle.Type[0] = 'B'; button->Handle.Type[1] = 'T'; @@ -77,7 +77,7 @@ namespace GraphicalUserInterface button->OnClick = OnClick; Buttons.push_back(button); - NeedRedraw = true; + this->NeedRedraw = true; return (Handle)button; } @@ -88,7 +88,7 @@ namespace GraphicalUserInterface { LabelObject *label = (LabelObject *)handle; strcpy(label->Text, Text); - NeedRedraw = true; + this->NeedRedraw = true; } } diff --git a/KConfig.cpp b/KConfig.cpp index f6a0f08..d114512 100644 --- a/KConfig.cpp +++ b/KConfig.cpp @@ -243,6 +243,11 @@ void ParseConfig(char *ConfigString, KernelConfig *ModConfig) KPrint("\eFF2200System Halted."); CPU::Stop(); } + default: + { + KPrint("\eFF2200Unknown option: %c", identifier); + break; + } } } debug("Config loaded"); diff --git a/KThread.cpp b/KThread.cpp index 530e531..3a7bbce 100644 --- a/KThread.cpp +++ b/KThread.cpp @@ -161,7 +161,7 @@ void BootLogoAnimationThread() break; } - FrameSizes[FrameCount] = ba->node->Length; + FrameSizes[FrameCount] = s_cst(uint32_t, ba->node->Length); Frames[FrameCount] = new uint8_t[ba->node->Length]; memcpy((void *)Frames[FrameCount], (void *)ba->node->Address, ba->node->Length); bootanim_vfs->Close(ba); @@ -189,10 +189,10 @@ void BootLogoAnimationThread() for (int i = 0; i < x * y; i++) { uint32_t pixel = ((uint32_t *)img)[i]; - uint8_t r = (pixel >> 16) & 0xFF; - uint8_t g = (pixel >> 8) & 0xFF; - uint8_t b = (pixel >> 0) & 0xFF; - uint8_t a = (pixel >> 24) & 0xFF; + int r = (pixel >> 16) & 0xFF; + int g = (pixel >> 8) & 0xFF; + int b = (pixel >> 0) & 0xFF; + int a = (pixel >> 24) & 0xFF; if (a != 0xFF) { @@ -244,10 +244,10 @@ void ExitLogoAnimationThread() for (int i = 0; i < x * y; i++) { uint32_t pixel = ((uint32_t *)img)[i]; - uint8_t r = (pixel >> 16) & 0xFF; - uint8_t g = (pixel >> 8) & 0xFF; - uint8_t b = (pixel >> 0) & 0xFF; - uint8_t a = (pixel >> 24) & 0xFF; + int r = (pixel >> 16) & 0xFF; + int g = (pixel >> 8) & 0xFF; + int b = (pixel >> 0) & 0xFF; + int a = (pixel >> 24) & 0xFF; if (a != 0xFF) { diff --git a/Library/Convert.cpp b/Library/Convert.cpp index 2c830cb..fa6c414 100644 --- a/Library/Convert.cpp +++ b/Library/Convert.cpp @@ -20,13 +20,13 @@ EXTERNC int memcmp(const void *vl, const void *vr, size_t n) EXTERNC void backspace(char s[]) { - int len = strlen(s); + int len = s_cst(int, strlen(s)); s[len - 1] = '\0'; } EXTERNC void append(char s[], char n) { - int len = strlen(s); + int len = s_cst(int, strlen(s)); s[len] = n; s[len + 1] = '\0'; } @@ -184,7 +184,7 @@ EXTERNC long int strtol(const char *str, char **endptr, int base) base = c == '0' ? 8 : 10; cutoff = neg ? LONG_MIN : LONG_MAX; - cutlim = cutoff % base; + cutlim = s_cst(int, cutoff % base); cutoff /= base; for (acc = 0, any = 0;; c = *s++) { @@ -249,7 +249,7 @@ EXTERNC unsigned long int strtoul(const char *str, char **endptr, int base) base = c == '0' ? 8 : 10; cutoff = neg ? LONG_MIN : LONG_MAX; - cutlim = cutoff % base; + cutlim = s_cst(int, cutoff % base); cutoff /= base; for (acc = 0, any = 0;; c = *s++) { @@ -342,8 +342,12 @@ EXTERNC float sqrtf(float x) float guess = x / 2.0f; for (short i = 0; i < 10; i++) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" if (guess == 0.0f) return 0.0f; +#pragma GCC diagnostic pop + guess = (guess + x / guess) / 2.0f; } return guess; @@ -366,7 +370,10 @@ EXTERNC float lerp(float a, float b, float t) EXTERNC float smoothstep(float a, float b, float t) { - t = clamp(t, 0.0, 1.0); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-conversion" + t = clamp(s_cst(double, t), 0.0, 1.0); +#pragma GCC diagnostic pop return lerp(a, b, t * t * (3 - 2 * t)); } @@ -420,8 +427,8 @@ EXTERNC char *strtok(char *src, const char *delim) EXTERNC int atoi(const char *String) { uint64_t Length = strlen((char *)String); - uint64_t OutBuffer = 0; - uint64_t Power = 1; + int OutBuffer = 0; + int Power = 1; for (uint64_t i = Length; i > 0; --i) { OutBuffer += (String[i - 1] - 48) * Power; @@ -517,16 +524,16 @@ EXTERNC char *itoa(int Value, char *Buffer, int Base) if (Base < 2 || Base > 32) return Buffer; - int n = abs(Value); + int n = s_cst(int, abs(Value)); int i = 0; while (n) { - int r = n % Base; + int r = s_cst(int, n % Base); if (r >= 10) - Buffer[i++] = 65 + (r - 10); + Buffer[i++] = s_cst(char, 65 + (r - 10)); else - Buffer[i++] = 48 + r; + Buffer[i++] = s_cst(char, 48 + r); n = n / Base; } @@ -550,11 +557,11 @@ EXTERNC char *ltoa(long Value, char *Buffer, int Base) while (n) { - int r = n % Base; + int r = s_cst(int, n % Base); if (r >= 10) - Buffer[i++] = 65 + (r - 10); + Buffer[i++] = s_cst(char, 65 + (r - 10)); else - Buffer[i++] = 48 + r; + Buffer[i++] = s_cst(char, 48 + r); n = n / Base; } @@ -578,11 +585,11 @@ EXTERNC char *ultoa(unsigned long Value, char *Buffer, int Base) while (n) { - int r = n % Base; + int r = s_cst(int, n % Base); if (r >= 10) - Buffer[i++] = 65 + (r - 10); + Buffer[i++] = s_cst(char, 65 + (r - 10)); else - Buffer[i++] = 48 + r; + Buffer[i++] = s_cst(char, 48 + r); n = n / Base; } diff --git a/Library/MemOp.c b/Library/MemOp.c index c4adb18..c840c00 100644 --- a/Library/MemOp.c +++ b/Library/MemOp.c @@ -4,6 +4,9 @@ #include #include +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" + /* Some of the functions are from musl library */ /* https://www.musl-libc.org/ */ /* @@ -85,9 +88,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) } if (n >= 32) + { switch ((uintptr_t)d % 4) { case 1: + { w = *(u32 *)s; *d++ = *s++; *d++ = *s++; @@ -105,7 +110,9 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) *(u32 *)(d + 12) = (x LS 24) | (w RS 8); } break; + } case 2: + { w = *(u32 *)s; *d++ = *s++; *d++ = *s++; @@ -122,7 +129,9 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) *(u32 *)(d + 12) = (x LS 16) | (w RS 16); } break; + } case 3: + { w = *(u32 *)s; *d++ = *s++; n -= 1; @@ -139,6 +148,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) } break; } + default: + break; + } + } + if (n & 16) { *d++ = *s++; @@ -158,6 +172,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) *d++ = *s++; *d++ = *s++; } + if (n & 8) { *d++ = *s++; @@ -169,6 +184,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) *d++ = *s++; *d++ = *s++; } + if (n & 4) { *d++ = *s++; @@ -176,11 +192,13 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n) *d++ = *s++; *d++ = *s++; } + if (n & 2) { *d++ = *s++; *d++ = *s++; } + if (n & 1) { *d = *s; @@ -200,18 +218,24 @@ void *memset_unsafe(void *dest, int c, size_t n) if (!n) return dest; + s[0] = c; s[n - 1] = c; + if (n <= 2) return dest; + s[1] = c; s[2] = c; s[n - 2] = c; s[n - 3] = c; + if (n <= 6) return dest; + s[3] = c; s[n - 4] = c; + if (n <= 8) return dest; @@ -227,14 +251,18 @@ void *memset_unsafe(void *dest, int c, size_t n) u32 c32 = ((u32)-1) / 255 * (unsigned char)c; *(u32 *)(s + 0) = c32; *(u32 *)(s + n - 4) = c32; + if (n <= 8) return dest; + *(u32 *)(s + 4) = c32; *(u32 *)(s + 8) = c32; *(u32 *)(s + n - 12) = c32; *(u32 *)(s + n - 8) = c32; + if (n <= 24) return dest; + *(u32 *)(s + 12) = c32; *(u32 *)(s + 16) = c32; *(u32 *)(s + 20) = c32; @@ -276,6 +304,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n) if (d == s) return d; + if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n) return memcpy(d, s, n); @@ -288,6 +317,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n) { if (!n--) return dest; + *d++ = *s++; } for (; n >= WS; n -= WS, d += WS, s += WS) @@ -306,6 +336,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n) { if (!n--) return dest; + d[n] = s[n]; } while (n >= WS) diff --git a/Library/cargs.c b/Library/cargs.c index 6865771..473a790 100644 --- a/Library/cargs.c +++ b/Library/cargs.c @@ -23,6 +23,7 @@ SOFTWARE. */ #pragma GCC diagnostic ignored "-Wimplicit-function-declaration" +#pragma GCC diagnostic ignored "-Wsign-conversion" #include #include diff --git a/Library/liballoc_1_1.c b/Library/liballoc_1_1.c index d37dac7..46fd60a 100644 --- a/Library/liballoc_1_1.c +++ b/Library/liballoc_1_1.c @@ -1,5 +1,8 @@ #include "liballoc_1_1.h" +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wsign-conversion" + /** Durand's Amazing Super Duper Memory functions. */ #define VERSION "1.1" diff --git a/Library/printf.c b/Library/printf.c index 6806184..7032a34 100644 --- a/Library/printf.c +++ b/Library/printf.c @@ -37,6 +37,8 @@ * THE SOFTWARE. */ +#pragma GCC diagnostic ignored "-Wfloat-equal" + // Define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H=1 ...) to include the // printf_config.h header file #if PRINTF_INCLUDE_CONFIG_H @@ -354,6 +356,8 @@ static inline NIF void append_termination_with_gadget(output_gadget_t *gadget) gadget->buffer[null_char_pos] = '\0'; } +extern void putchar(char c); + // We can't use putchar_ as is, since our output gadget // only takes pointers to functions with an extra argument static inline NIF void putchar_wrapper(char c, void *unused) diff --git a/Makefile b/Makefile index aad7592..d32d48b 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,10 @@ INCLUDE_DIR = ./include LDFLAGS := -Wl,-Map kernel.map -shared -nostdlib -nodefaultlibs -nolibc # Disable all warnings by adding "-w" in WARNCFLAG and if you want to treat the warnings as errors, add "-Werror" -WARNCFLAG = -Wall -Wextra +WARNCFLAG = -Wall -Wextra \ + -Wfloat-equal -Wpointer-arith -Wcast-align \ + -Wredundant-decls -Winit-self -Wswitch-default \ + -Wstrict-overflow=5 -Wconversion # https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html CFLAGS := \ @@ -59,6 +62,8 @@ CFLAGS := \ -DGIT_COMMIT='"$(GIT_COMMIT)"' \ -DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' +SIMD_FLAGS := -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mavx512f + ifeq ($(OSARCH), amd64) CFLAGS += -fno-pic -fno-pie \ diff --git a/Network/AddressResolutionProtocol.cpp b/Network/AddressResolutionProtocol.cpp index 2e3dc46..b6eb9ff 100644 --- a/Network/AddressResolutionProtocol.cpp +++ b/Network/AddressResolutionProtocol.cpp @@ -4,6 +4,9 @@ #include "../kernel.h" +/* conversion from ‘uint48_t’ {aka ‘long unsigned int’} to ‘long unsigned int:48’ may change value */ +#pragma GCC diagnostic ignored "-Wconversion" + namespace NetworkARP { DiscoveredAddress *ARP::ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC) @@ -58,6 +61,10 @@ namespace NetworkARP } return nullptr; } + default: + { + return nullptr; + } } return nullptr; } diff --git a/Network/DynamicHostConfigurationProtocol.cpp b/Network/DynamicHostConfigurationProtocol.cpp index 7b7e596..ec0e50b 100644 --- a/Network/DynamicHostConfigurationProtocol.cpp +++ b/Network/DynamicHostConfigurationProtocol.cpp @@ -66,7 +66,7 @@ namespace NetworkDHCP *(Ptr++) = DHCP_OPTION_HOST_NAME; char *HostName = (char *)KERNEL_NAME; - *(Ptr++) = 1 + strlen(HostName); + *(Ptr++) = s_cst(uint8_t, 1 + strlen(HostName)); memcpy(Ptr, HostName, strlen(HostName)); Ptr += strlen(HostName); diff --git a/Network/Ethernet.cpp b/Network/Ethernet.cpp index 444e85a..8bf592b 100644 --- a/Network/Ethernet.cpp +++ b/Network/Ethernet.cpp @@ -3,6 +3,9 @@ #include "../kernel.h" +/* conversion from ‘uint48_t’ {aka ‘long unsigned int’} to ‘long unsigned int:48’ may change value */ +#pragma GCC diagnostic ignored "-Wconversion" + namespace NetworkEthernet { struct EthernetEventHelperStruct diff --git a/Network/InternetProtocol.cpp b/Network/InternetProtocol.cpp index 97f54af..fe2bf11 100644 --- a/Network/InternetProtocol.cpp +++ b/Network/InternetProtocol.cpp @@ -27,8 +27,8 @@ namespace NetworkIPv4 Packet->Header.IHL = b8(sizeof(IPv4Header) / 4); Packet->Header.TypeOfService = b8(0); /* We don't byteswap. */ - Packet->Header.TotalLength = Length + sizeof(IPv4Header); - Packet->Header.TotalLength = ((Packet->Header.TotalLength & 0xFF00) >> 8) | ((Packet->Header.TotalLength & 0x00FF) << 8); + Packet->Header.TotalLength = s_cst(uint16_t, Length + sizeof(IPv4Header)); + Packet->Header.TotalLength = s_cst(uint16_t, ((Packet->Header.TotalLength & 0xFF00) >> 8) | ((Packet->Header.TotalLength & 0x00FF) << 8)); Packet->Header.Identification = b16(0x0000); Packet->Header.Flags = b8(0x0); diff --git a/Network/NetworkTimeProtocol.cpp b/Network/NetworkTimeProtocol.cpp index 77e81d8..6419ac2 100644 --- a/Network/NetworkTimeProtocol.cpp +++ b/Network/NetworkTimeProtocol.cpp @@ -49,8 +49,8 @@ namespace NetworkNTP TaskManager->Sleep(1000); } - int UnixTimestamp = b32(this->NTPPacket.TransmitTimestamp[0]) - 2208988800; + long UnixTimestamp = b32(this->NTPPacket.TransmitTimestamp[0]) - 2208988800; debug("Unix time: %d", UnixTimestamp); - return UnixTimestamp; + return s_cst(int, UnixTimestamp); } } diff --git a/Network/UserDatagramProtocol.cpp b/Network/UserDatagramProtocol.cpp index 6be0ffb..bfb84cd 100644 --- a/Network/UserDatagramProtocol.cpp +++ b/Network/UserDatagramProtocol.cpp @@ -60,7 +60,7 @@ namespace NetworkUDP void UDP::Send(Socket *Socket, uint8_t *Data, uint64_t Length) { netdbg("Sending %d bytes to %s", Length, Socket->RemoteIP.v4.ToStringLittleEndian(), Socket->RemotePort); - uint16_t TotalLength = Length + sizeof(UDPHeader); + uint16_t TotalLength = s_cst(uint16_t, Length + sizeof(UDPHeader)); UDPPacket *packet = (UDPPacket *)kmalloc(TotalLength); packet->Header.SourcePort = Socket->LocalPort; packet->Header.DestinationPort = Socket->RemotePort; diff --git a/Recovery/RecoveryMain.cpp b/Recovery/RecoveryMain.cpp index f884044..d5cd943 100644 --- a/Recovery/RecoveryMain.cpp +++ b/Recovery/RecoveryMain.cpp @@ -115,7 +115,7 @@ namespace Recovery void CSR88200() { ChangeSampleRate(7); } void CSR96000() { ChangeSampleRate(8); } - void ChangeVolume(int percentage) + void ChangeVolume(char percentage) { Driver::DriverFile AudioDrv; @@ -253,8 +253,8 @@ namespace Recovery MemUsed = KernelAllocator.GetUsedMemory(); MemTotal = KernelAllocator.GetTotalMemory(); MemReserved = KernelAllocator.GetReservedMemory(); - int MemPercent = (MemUsed * 100) / MemTotal; - sprintf(TicksText, "%ldMB / %ldGB (%ldMB reserved) %d%% (%ld bytes allocated)", TO_MB(MemUsed), TO_GB(MemTotal), TO_MB(MemReserved), MemPercent, MemUsed); + uint64_t MemPercent = (MemUsed * 100) / MemTotal; + sprintf(TicksText, "%ldMB / %ldGB (%ldMB reserved) %ld%% (%ld bytes allocated)", TO_MB(MemUsed), TO_GB(MemTotal), TO_MB(MemReserved), MemPercent, MemUsed); wdgDbgWin->SetText(MemLblHnd, TicksText); RefreshMemCounter = 25; } diff --git a/Tests/Marco.cpp b/Tests/Marco.cpp index 43811f2..ccf0ee5 100644 --- a/Tests/Marco.cpp +++ b/Tests/Marco.cpp @@ -29,13 +29,13 @@ __constructor void TestMacros() debug("-------------------------"); { - uintptr_t actual = PAGE_SIZE; - int expected = 1; + uint64_t actual = PAGE_SIZE; + uint64_t expected = 1; for (int i = 0; i < 128; i++) { - int a = TO_PAGES(actual); - uintptr_t b = FROM_PAGES(expected); + uint64_t a = TO_PAGES(actual); + uint64_t b = FROM_PAGES(expected); /* TODO: This is a workaround for now. */ if (a != expected + 1) diff --git a/include/atomic.hpp b/include/atomic.hpp index 0589dd8..3130c29 100644 --- a/include/atomic.hpp +++ b/include/atomic.hpp @@ -64,11 +64,11 @@ enum MemoryOrder template class Atomic { - _Atomic(T) m_Value; + _Atomic(T) Value; public: - Atomic() : m_Value(0) {} - Atomic(T Init) : m_Value(Init) {} + Atomic() : Value(0) {} + Atomic(T Init) : Value(Init) {} /** * @brief Load the value of the atomic variable @@ -78,7 +78,7 @@ public: */ T Load(MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic_n(load)(&m_Value, Order); + return builtin_atomic_n(load)(&this->Value, Order); } /** @@ -89,7 +89,7 @@ public: */ void Store(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic_n(store)(&m_Value, v, Order); + return builtin_atomic_n(store)(&this->Value, v, Order); } /** @@ -101,7 +101,7 @@ public: */ T Exchange(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic_n(exchange)(&m_Value, v, Order); + return builtin_atomic_n(exchange)(&this->Value, v, Order); } /** @@ -115,7 +115,7 @@ public: */ bool CompareExchange(T &Expected, T Desired, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic_n(compare_exchange)(&m_Value, &Expected, Desired, true, Order, Order); + return builtin_atomic_n(compare_exchange)(&this->Value, &Expected, Desired, true, Order, Order); } /** @@ -127,7 +127,7 @@ public: */ T FetchAdd(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_add)(&m_Value, v, Order); + return builtin_atomic(fetch_add)(&this->Value, v, Order); } /** @@ -139,7 +139,7 @@ public: */ T FetchSub(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_sub)(&m_Value, v, Order); + return builtin_atomic(fetch_sub)(&this->Value, v, Order); } /** @@ -151,7 +151,7 @@ public: */ T FetchAnd(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_and)(&m_Value, v, Order); + return builtin_atomic(fetch_and)(&this->Value, v, Order); } /** @@ -163,7 +163,7 @@ public: */ T FetchOr(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_or)(&m_Value, v, Order); + return builtin_atomic(fetch_or)(&this->Value, v, Order); } /** @@ -175,7 +175,7 @@ public: */ T FetchXor(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_xor)(&m_Value, v, Order); + return builtin_atomic(fetch_xor)(&this->Value, v, Order); } /** @@ -187,7 +187,7 @@ public: */ T FetchNand(T v, MemoryOrder Order = MemoryOrder::SeqCst) { - return builtin_atomic(fetch_nand)(&m_Value, v, Order); + return builtin_atomic(fetch_nand)(&this->Value, v, Order); } operator bool() { return this->Load() != 0; } diff --git a/include/boot/binfo.h b/include/boot/binfo.h index 944b7f0..6372519 100644 --- a/include/boot/binfo.h +++ b/include/boot/binfo.h @@ -23,8 +23,8 @@ struct BootInfo struct FramebufferInfo { void *BaseAddress; - __UINT64_TYPE__ Width; - __UINT64_TYPE__ Height; + __UINT32_TYPE__ Width; + __UINT32_TYPE__ Height; __UINT64_TYPE__ Pitch; __UINT16_TYPE__ BitsPerPixel; __UINT8_TYPE__ MemoryModel; diff --git a/include/cpu/x86/x64/msr.hpp b/include/cpu/x86/x64/msr.hpp index cad5024..1722f1d 100644 --- a/include/cpu/x86/x64/msr.hpp +++ b/include/cpu/x86/x64/msr.hpp @@ -397,7 +397,7 @@ namespace CPU SafeFunction static inline void wrmsr(uint32_t msr, uint64_t Value) { - uint32_t Low = Value, High = Value >> 32; + uint32_t Low = s_cst(uint32_t, Value), High = s_cst(uint32_t, Value >> 32); asmv("wrmsr" : : "c"(msr), "a"(Low), "d"(High) diff --git a/include/ints.hpp b/include/ints.hpp index a407fb5..4af643a 100644 --- a/include/ints.hpp +++ b/include/ints.hpp @@ -38,7 +38,7 @@ namespace Interrupts * @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32) */ void SetInterruptNumber(int InterruptNumber) { this->InterruptNumber = InterruptNumber; } - int GetInterruptNumber() { return InterruptNumber; } + int GetInterruptNumber() { return this->InterruptNumber; } /** * @brief Create a new interrupt handler. diff --git a/include/net/nc.hpp b/include/net/nc.hpp index 51a0931..cc3756f 100644 --- a/include/net/nc.hpp +++ b/include/net/nc.hpp @@ -28,7 +28,7 @@ namespace NetworkInterfaceManager void *DriverCallBackAddress; /** @brief Reserved */ - unsigned int DriverID; + unsigned long DriverID; }; class Events diff --git a/include/net/net.hpp b/include/net/net.hpp index aeaf3d8..dcf7b3d 100644 --- a/include/net/net.hpp +++ b/include/net/net.hpp @@ -16,16 +16,6 @@ static inline void DbgNetwork() { return; } static inline void DbgDumpData(const char *Description, void *Address, unsigned long Length) { return; } #endif -// TODO: How i would do this? -typedef __UINT64_TYPE__ uint48_t; - -#define b4(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4) -#define b8(x) ((x)&0xFF) -#define b16(x) __builtin_bswap16(x) -#define b32(x) __builtin_bswap32(x) -#define b48(x) (((((x)&0x0000000000ff) << 40) | (((x)&0x00000000ff00) << 24) | (((x)&0x000000ff0000) << 8) | (((x)&0x0000ff000000) >> 8) | (((x)&0x00ff00000000) >> 24) | (((x)&0xff0000000000) >> 40))) -#define b64(x) __builtin_bswap64(x) - enum Endianness { LITTLE_ENDIAN, @@ -149,10 +139,10 @@ struct InternetProtocol inline uint32_t ToHex() { - return ((uint64_t)this->Address[0] << 24) | - ((uint64_t)this->Address[1] << 16) | - ((uint64_t)this->Address[2] << 8) | - ((uint64_t)this->Address[3]); + return ((uint32_t)this->Address[0] << 24) | + ((uint32_t)this->Address[1] << 16) | + ((uint32_t)this->Address[2] << 8) | + ((uint32_t)this->Address[3]); } inline InternetProtocol::Version4 FromHex(uint32_t Hex) diff --git a/include/printf.h b/include/printf.h index 0dcb247..52866c6 100644 --- a/include/printf.h +++ b/include/printf.h @@ -95,8 +95,8 @@ extern "C" * * @param c the single character to print */ - PRINTF_VISIBILITY - void putchar(char c); + // PRINTF_VISIBILITY + // void putchar(char c); /** * An implementation of the C standard's printf/vprintf diff --git a/include/smp.hpp b/include/smp.hpp index 4ff4312..39d4d91 100644 --- a/include/smp.hpp +++ b/include/smp.hpp @@ -31,7 +31,7 @@ struct CPUData uintptr_t Stack; /** @brief CPU ID. */ - long ID; + int ID; /** @brief Local CPU error code. */ long ErrorCode; diff --git a/include/std/functional.hpp b/include/std/functional.hpp index 412fe30..238e0ae 100644 --- a/include/std/functional.hpp +++ b/include/std/functional.hpp @@ -17,15 +17,15 @@ namespace std const uint8_t *data = reinterpret_cast(&key); const size_t size = sizeof(Key); - uint64_t hash = fnv_offset_basis; + uint64_t ret = fnv_offset_basis; for (size_t i = 0; i < size; ++i) { - hash ^= static_cast(data[i]); - hash *= fnv_prime; + ret ^= static_cast(data[i]); + ret *= fnv_prime; } - return static_cast(hash); + return static_cast(ret); } }; } diff --git a/include/std/smart_ptr.hpp b/include/std/smart_ptr.hpp index 130518b..647a7bb 100644 --- a/include/std/smart_ptr.hpp +++ b/include/std/smart_ptr.hpp @@ -31,37 +31,37 @@ namespace std template class smart_ptr { - T *m_RealPointer; + T *RealPointer; public: explicit smart_ptr(T *Pointer = nullptr) { - spdbg("Smart pointer created (%#lx)", m_RealPointer); - m_RealPointer = Pointer; + spdbg("Smart pointer created (%#lx)", this->RealPointer); + this->RealPointer = Pointer; } ~smart_ptr() { - spdbg("Smart pointer deleted (%#lx)", m_RealPointer); - delete m_RealPointer, m_RealPointer = nullptr; + spdbg("Smart pointer deleted (%#lx)", this->RealPointer); + delete this->RealPointer, this->RealPointer = nullptr; } T &operator*() { - spdbg("Smart pointer dereferenced (%#lx)", m_RealPointer); - return *m_RealPointer; + spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer); + return *this->RealPointer; } T *operator->() { - spdbg("Smart pointer dereferenced (%#lx)", m_RealPointer); - return m_RealPointer; + spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer); + return this->RealPointer; } T *get() { - spdbg("Smart pointer returned (%#lx)", m_RealPointer); - return m_RealPointer; + spdbg("Smart pointer returned (%#lx)", this->RealPointer); + return this->RealPointer; } }; @@ -87,148 +87,148 @@ namespace std class counter { private: - unsigned int m_RefCount{}; + unsigned int RefCount{}; public: - counter() : m_RefCount(0) { spdbg("Counter %#lx created", this); }; + counter() : RefCount(0) { spdbg("Counter %#lx created", this); }; counter(const counter &) = delete; counter &operator=(const counter &) = delete; ~counter() { spdbg("Counter %#lx deleted", this); } void reset() { - m_RefCount = 0; + this->RefCount = 0; spdbg("reset"); } unsigned int get() { - return m_RefCount; + return this->RefCount; spdbg("return"); } void operator++() { - m_RefCount++; + this->RefCount++; spdbg("increment"); } void operator++(int) { - m_RefCount++; + this->RefCount++; spdbg("increment"); } void operator--() { - m_RefCount--; + this->RefCount--; spdbg("decrement"); } void operator--(int) { - m_RefCount--; + this->RefCount--; spdbg("decrement"); } }; - counter *m_ReferenceCounter; - T *m_RealPointer; + counter *ReferenceCounter; + T *RealPointer; public: explicit shared_ptr(T *Pointer = nullptr) { - m_RealPointer = Pointer; - m_ReferenceCounter = new counter(); - spdbg("[%#lx] Shared pointer created (ptr=%#lx, ref=%#lx)", this, Pointer, m_ReferenceCounter); + this->RealPointer = Pointer; + this->ReferenceCounter = new counter(); + spdbg("[%#lx] Shared pointer created (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter); if (Pointer) - (*m_ReferenceCounter)++; + (*this->ReferenceCounter)++; } shared_ptr(shared_ptr &SPtr) { - spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.m_RealPointer, SPtr.m_ReferenceCounter); - m_RealPointer = SPtr.m_RealPointer; - m_ReferenceCounter = SPtr.m_ReferenceCounter; - (*m_ReferenceCounter)++; + spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.RealPointer, SPtr.ReferenceCounter); + this->RealPointer = SPtr.RealPointer; + this->ReferenceCounter = SPtr.ReferenceCounter; + (*this->ReferenceCounter)++; } ~shared_ptr() { spdbg("[%#lx] Shared pointer destructor called", this); - (*m_ReferenceCounter)--; - if (m_ReferenceCounter->get() == 0) + (*this->ReferenceCounter)--; + if (this->ReferenceCounter->get() == 0) { - spdbg("[%#lx] Shared pointer deleted (ptr=%#lx, ref=%#lx)", this, m_RealPointer, m_ReferenceCounter); - delete m_ReferenceCounter, m_ReferenceCounter = nullptr; - delete m_RealPointer, m_RealPointer = nullptr; + spdbg("[%#lx] Shared pointer deleted (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter); + delete this->ReferenceCounter, this->ReferenceCounter = nullptr; + delete this->RealPointer, this->RealPointer = nullptr; } } unsigned int get_count() { - spdbg("[%#lx] Shared pointer count (%d)", this, m_ReferenceCounter->get()); - return m_ReferenceCounter->get(); + spdbg("[%#lx] Shared pointer count (%d)", this, this->ReferenceCounter->get()); + return this->ReferenceCounter->get(); } T *get() { - spdbg("[%#lx] Shared pointer get (%#lx)", this, m_RealPointer); - return m_RealPointer; + spdbg("[%#lx] Shared pointer get (%#lx)", this, this->RealPointer); + return this->RealPointer; } T &operator*() { - spdbg("[%#lx] Shared pointer dereference (ptr*=%#lx)", this, *m_RealPointer); - return *m_RealPointer; + spdbg("[%#lx] Shared pointer dereference (ptr*=%#lx)", this, *this->RealPointer); + return *this->RealPointer; } T *operator->() { - spdbg("[%#lx] Shared pointer dereference (ptr->%#lx)", this, m_RealPointer); - return m_RealPointer; + spdbg("[%#lx] Shared pointer dereference (ptr->%#lx)", this, this->RealPointer); + return this->RealPointer; } void reset(T *Pointer = nullptr) { - if (m_RealPointer == Pointer) + if (this->RealPointer == Pointer) return; - spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, Pointer, m_ReferenceCounter); - (*m_ReferenceCounter)--; - if (m_ReferenceCounter->get() == 0) + spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter); + (*this->ReferenceCounter)--; + if (this->ReferenceCounter->get() == 0) { - delete m_RealPointer; - delete m_ReferenceCounter; + delete this->RealPointer; + delete this->ReferenceCounter; } - m_RealPointer = Pointer; - m_ReferenceCounter = new counter(); + this->RealPointer = Pointer; + this->ReferenceCounter = new counter(); if (Pointer) - (*m_ReferenceCounter)++; + (*this->ReferenceCounter)++; } void reset() { - spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, m_RealPointer, m_ReferenceCounter); - if (m_ReferenceCounter->get() == 1) + spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter); + if (this->ReferenceCounter->get() == 1) { - delete m_RealPointer, m_RealPointer = nullptr; - delete m_ReferenceCounter, m_ReferenceCounter = nullptr; + delete this->RealPointer, this->RealPointer = nullptr; + delete this->ReferenceCounter, this->ReferenceCounter = nullptr; } else { - (*m_ReferenceCounter)--; + (*this->ReferenceCounter)--; } } void swap(shared_ptr &Other) { spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)", - this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter); - T *tempRealPointer = m_RealPointer; - counter *tempReferenceCounter = m_ReferenceCounter; - m_RealPointer = Other.m_RealPointer; - m_ReferenceCounter = Other.m_ReferenceCounter; - Other.m_RealPointer = tempRealPointer; - Other.m_ReferenceCounter = tempReferenceCounter; + this, this->RealPointer, this->ReferenceCounter, Other.RealPointer, Other.ReferenceCounter); + T *tempRealPointer = this->RealPointer; + counter *tempReferenceCounter = this->ReferenceCounter; + this->RealPointer = Other.RealPointer; + this->ReferenceCounter = Other.ReferenceCounter; + Other.RealPointer = tempRealPointer; + Other.ReferenceCounter = tempReferenceCounter; } }; diff --git a/include/std/stdexcept.hpp b/include/std/stdexcept.hpp index 6260675..e0e4ae2 100644 --- a/include/std/stdexcept.hpp +++ b/include/std/stdexcept.hpp @@ -12,7 +12,7 @@ namespace std public: runtime_error(const char *what_arg) : m_what(what_arg) {} - const char *what() const { return m_what; } + const char *what() const { return this->m_what; } }; } diff --git a/include/std/string.hpp b/include/std/string.hpp index 630efcb..34ca5ec 100644 --- a/include/std/string.hpp +++ b/include/std/string.hpp @@ -25,85 +25,85 @@ namespace std class string { private: - char *m_Data; - size_t m_Length; - size_t m_Capacity; + char *Data; + size_t Length; + size_t Capacity; public: static const size_t npos = -1; string(const char *Str = "") { - this->m_Length = strlen(Str); - this->m_Capacity = this->m_Length + 1; - this->m_Data = new char[m_Capacity]; - strcpy(m_Data, Str); - strdbg("New string created: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + this->Length = strlen(Str); + this->Capacity = this->Length + 1; + this->Data = new char[this->Capacity]; + strcpy(this->Data, Str); + strdbg("New string created: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } ~string() { - strdbg("String deleted: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); - delete[] this->m_Data, this->m_Data = nullptr; + strdbg("String deleted: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); + delete[] this->Data, this->Data = nullptr; } - int length() const + size_t length() const { - strdbg("String length: %d", this->m_Length); - return this->m_Length; + strdbg("String length: %d", this->Length); + return this->Length; } - int capacity() const + size_t capacity() const { - strdbg("String capacity: %d", this->m_Capacity); - return this->m_Capacity; + strdbg("String capacity: %d", this->Capacity); + return this->Capacity; } const char *c_str() const { - strdbg("String data: \"%s\"", this->m_Data); - return this->m_Data; + strdbg("String data: \"%s\"", this->Data); + return this->Data; } void resize(size_t NewLength) { strdbg("String resize: %d", NewLength); - if (NewLength > this->m_Capacity) + if (NewLength > this->Capacity) { size_t newCapacity = NewLength + 1; char *newData = new char[newCapacity]; - strcpy(newData, this->m_Data); + strcpy(newData, this->Data); - strdbg("old: %#lx, new: %#lx", this->m_Data, newData); - delete[] this->m_Data; - this->m_Data = newData; - this->m_Capacity = newCapacity; + strdbg("old: %#lx, new: %#lx", this->Data, newData); + delete[] this->Data; + this->Data = newData; + this->Capacity = newCapacity; } - this->m_Length = NewLength; - this->m_Data[m_Length] = '\0'; - strdbg("String resized: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + this->Length = NewLength; + this->Data[this->Length] = '\0'; + strdbg("String resized: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } void concat(const string &Other) { - int NewLength = this->m_Length + Other.m_Length; + size_t NewLength = this->Length + Other.Length; this->resize(NewLength); - strcat(m_Data, Other.m_Data); - strdbg("String concatenated: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strcat(this->Data, Other.Data); + strdbg("String concatenated: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } bool empty() const { - strdbg("String empty: %d", this->m_Length == 0); - return this->m_Length == 0; + strdbg("String empty: %d", this->Length == 0); + return this->Length == 0; } size_t size() const { - strdbg("String size: %d", this->m_Length); - return this->m_Length; + strdbg("String size: %d", this->Length); + return this->Length; } void clear() @@ -115,15 +115,15 @@ namespace std size_t find(const char *Str, size_t Pos = 0) const { strdbg("String find: \"%s\", %d", Str, Pos); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return npos; - for (size_t i = Pos; i < this->m_Length; i++) + for (size_t i = Pos; i < this->Length; i++) { bool found = true; for (size_t j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i + j] != Str[j]) + if (this->Data[i + j] != Str[j]) { found = false; break; @@ -144,35 +144,35 @@ namespace std void erase(int Index, int Count = 1) { strdbg("String erase: %d, %d", Index, Count); - if (Index < 0 || (size_t)Index >= this->m_Length) + if (Index < 0 || (size_t)Index >= this->Length) return; if (Count < 0) return; - if ((size_t)(Index + Count) > this->m_Length) - Count = this->m_Length - Index; + if ((size_t)(Index + Count) > this->Length) + Count = (int)this->Length - Index; - for (size_t i = Index; i < this->m_Length - Count; i++) - this->m_Data[i] = this->m_Data[i + Count]; + for (size_t i = Index; i < this->Length - Count; i++) + this->Data[i] = this->Data[i + Count]; - this->m_Length -= Count; - this->m_Data[m_Length] = '\0'; - strdbg("String erased: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + this->Length -= Count; + this->Data[this->Length] = '\0'; + strdbg("String erased: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } size_t find_last_not_of(const char *Str, size_t Pos = npos) const { strdbg("String find_last_not_of: \"%s\", %d", Str, Pos); if (Pos == npos) - Pos = this->m_Length - 1; + Pos = this->Length - 1; for (int i = (int)Pos; i >= 0; i--) { bool found = false; for (size_t j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i] == Str[j]) + if (this->Data[i] == Str[j]) { found = true; break; @@ -187,15 +187,15 @@ namespace std size_t find_first_not_of(const char *Str, size_t Pos = 0) const { strdbg("String find_first_not_of: \"%s\", %d", Str, Pos); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return npos; - for (size_t i = Pos; i < this->m_Length; i++) + for (size_t i = Pos; i < this->Length; i++) { bool found = false; for (size_t j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i] == Str[j]) + if (this->Data[i] == Str[j]) { found = true; break; @@ -210,15 +210,15 @@ namespace std size_t find_first_of(const char *Str, size_t Pos = 0) const { strdbg("String find_first_of: \"%s\", %d", Str, Pos); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return npos; - for (size_t i = Pos; i < this->m_Length; i++) + for (size_t i = Pos; i < this->Length; i++) { bool found = false; for (size_t j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i] == Str[j]) + if (this->Data[i] == Str[j]) { found = true; break; @@ -234,14 +234,14 @@ namespace std { strdbg("String find_last_of: \"%s\", %d", Str, Pos); if (Pos == npos) - Pos = this->m_Length - 1; + Pos = this->Length - 1; for (int i = (int)Pos; i >= 0; i--) { bool found = false; for (int j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i] == Str[j]) + if (this->Data[i] == Str[j]) { found = true; break; @@ -256,12 +256,12 @@ namespace std size_t find_first_of(char C, size_t Pos = 0) const { strdbg("String find_first_of: '%c', %d", C, Pos); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return npos; - for (size_t i = Pos; i < this->m_Length; i++) + for (size_t i = Pos; i < this->Length; i++) { - if (this->m_Data[i] == C) + if (this->Data[i] == C) return i; } return npos; @@ -271,11 +271,11 @@ namespace std { strdbg("String find_last_of: '%c', %d", C, Pos); if (Pos == npos) - Pos = this->m_Length - 1; + Pos = this->Length - 1; for (int i = (int)Pos; i >= 0; i--) { - if (this->m_Data[i] == C) + if (this->Data[i] == C) return i; } return npos; @@ -284,15 +284,15 @@ namespace std size_t substr(const char *Str, size_t Pos = 0) const { strdbg("String substr: \"%s\", %d", Str, Pos); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return npos; - for (size_t i = Pos; i < this->m_Length; i++) + for (size_t i = Pos; i < this->Length; i++) { bool found = true; for (size_t j = 0; Str[j] != '\0'; j++) { - if (this->m_Data[i + j] != Str[j]) + if (this->Data[i + j] != Str[j]) { found = false; break; @@ -313,76 +313,76 @@ namespace std string substr(size_t Pos = 0, size_t Count = npos) const { strdbg("String substr: %d, %d", Pos, Count); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return string(); if (Count == npos) - Count = this->m_Length - Pos; + Count = this->Length - Pos; - if (Pos + Count > this->m_Length) - Count = this->m_Length - Pos; + if (Pos + Count > this->Length) + Count = this->Length - Pos; string ret; ret.resize(Count); for (size_t i = 0; i < Count; i++) - ret.m_Data[i] = this->m_Data[Pos + i]; - ret.m_Data[Count] = '\0'; + ret.Data[i] = this->Data[Pos + i]; + ret.Data[Count] = '\0'; return ret; } void replace(size_t Pos, size_t Count, const char *Str) { strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str); - if (Pos >= this->m_Length) + if (Pos >= this->Length) return; if ((int64_t)Count < 0) return; - if (Pos + Count > this->m_Length) - Count = this->m_Length - Pos; + if (Pos + Count > this->Length) + Count = this->Length - Pos; - int NewLength = this->m_Length - Count + strlen(Str); + size_t NewLength = this->Length - Count + strlen(Str); this->resize(NewLength); - for (size_t i = this->m_Length - 1; i >= Pos + strlen(Str); i--) - this->m_Data[i] = this->m_Data[i - strlen(Str) + Count]; + for (size_t i = this->Length - 1; i >= Pos + strlen(Str); i--) + this->Data[i] = this->Data[i - strlen(Str) + Count]; for (unsigned long i = 0; i < strlen(Str); i++) - this->m_Data[Pos + i] = Str[i]; + this->Data[Pos + i] = Str[i]; - strdbg("String replaced: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String replaced: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } void replace(size_t Pos, size_t Count, const string &Str) { - strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str.m_Data); - if (Pos >= this->m_Length) + strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str.Data); + if (Pos >= this->Length) return; if ((int64_t)Count < 0) return; - if (Pos + Count > this->m_Length) - Count = this->m_Length - Pos; + if (Pos + Count > this->Length) + Count = this->Length - Pos; - int NewLength = this->m_Length - Count + Str.m_Length; + size_t NewLength = this->Length - Count + Str.Length; this->resize(NewLength); - for (size_t i = this->m_Length - 1; i >= Pos + Str.m_Length; i--) - this->m_Data[i] = this->m_Data[i - Str.m_Length + Count]; + for (size_t i = this->Length - 1; i >= Pos + Str.Length; i--) + this->Data[i] = this->Data[i - Str.Length + Count]; - for (size_t i = 0; i < Str.m_Length; i++) - this->m_Data[Pos + i] = Str.m_Data[i]; + for (size_t i = 0; i < Str.Length; i++) + this->Data[Pos + i] = Str.Data[i]; - strdbg("String replaced: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String replaced: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); } string operator+(const string &Other) const { string result = *this; result.concat(Other); - strdbg("String added: \"%s\" (data: %#lx, length: %d, capacity: %d)", result.m_Data, result.m_Data, result.m_Length, result.m_Capacity); + strdbg("String added: \"%s\" (data: %#lx, length: %d, capacity: %d)", result.Data, result.Data, result.Length, result.Capacity); return result; } @@ -390,21 +390,21 @@ namespace std { string result = *this; result.concat(Other); - strdbg("String added: \"%s\" (data: %#lx, length: %d, capacity: %d)", result.m_Data, result.m_Data, result.m_Length, result.m_Capacity); + strdbg("String added: \"%s\" (data: %#lx, length: %d, capacity: %d)", result.Data, result.Data, result.Length, result.Capacity); return result; } string &operator+=(const string &Other) { this->concat(Other); - strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); return *this; } string &operator+=(const char *Other) { this->concat(Other); - strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); return *this; } @@ -415,120 +415,120 @@ namespace std // { // if (this != &Other) // { - // delete[] this->m_Data; - // this->m_Data = Other.m_Data; - // this->m_Length = Other.m_Length; - // this->m_Capacity = Other.m_Capacity; - // strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + // delete[] this->Data; + // this->Data = Other.Data; + // this->Length = Other.Length; + // this->Capacity = Other.Capacity; + // strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); // } // return *this; // } string &operator=(const char *Other) { - this->m_Length = strlen(Other); - this->m_Capacity = this->m_Length + 1; - delete[] this->m_Data; - this->m_Data = new char[m_Capacity]; - strcpy(m_Data, Other); - strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + this->Length = strlen(Other); + this->Capacity = this->Length + 1; + delete[] this->Data; + this->Data = new char[this->Capacity]; + strcpy(this->Data, Other); + strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); return *this; } string &operator<<(const string &Other) { this->concat(Other); - strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); return *this; } string &operator<<(const char *Other) { this->concat(Other); - strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); + strdbg("String appended: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity); return *this; } char &operator[](int Index) { strdbg("String index: %d", Index); - return this->m_Data[Index]; + return this->Data[Index]; } const char &operator[](int Index) const { strdbg("String index: %d", Index); - return this->m_Data[Index]; + return this->Data[Index]; } bool operator==(const string &Other) const { - strdbg("String compared: \"%s\" == \"%s\"", this->m_Data, Other.m_Data); - return strcmp(this->m_Data, Other.m_Data) == 0; + strdbg("String compared: \"%s\" == \"%s\"", this->Data, Other.Data); + return strcmp(this->Data, Other.Data) == 0; } bool operator!=(const char *Other) const { - strdbg("String compared: \"%s\" != \"%s\"", this->m_Data, Other); - return strcmp(this->m_Data, Other) != 0; + strdbg("String compared: \"%s\" != \"%s\"", this->Data, Other); + return strcmp(this->Data, Other) != 0; } bool operator!=(const string &Other) const { - strdbg("String compared: \"%s\" != \"%s\"", this->m_Data, Other.m_Data); - return strcmp(this->m_Data, Other.m_Data) != 0; + strdbg("String compared: \"%s\" != \"%s\"", this->Data, Other.Data); + return strcmp(this->Data, Other.Data) != 0; } bool operator==(const char *Other) const { - strdbg("String compared: \"%s\" == \"%s\"", this->m_Data, Other); - return strcmp(this->m_Data, Other) == 0; + strdbg("String compared: \"%s\" == \"%s\"", this->Data, Other); + return strcmp(this->Data, Other) == 0; } class iterator { private: - char *m_Pointer; + char *Pointer; public: - iterator(char *Pointer) : m_Pointer(Pointer) {} + iterator(char *Pointer) : Pointer(Pointer) {} iterator &operator++() { - ++this->m_Pointer; - strdbg("String iterator incremented: %#lx", this->m_Pointer); + ++this->Pointer; + strdbg("String iterator incremented: %#lx", this->Pointer); return *this; } char &operator*() { - strdbg("String iterator dereferenced: %#lx", this->m_Pointer); - return *this->m_Pointer; + strdbg("String iterator dereferenced: %#lx", this->Pointer); + return *this->Pointer; } bool operator!=(const iterator &Other) const { - strdbg("String iterator compared: %#lx != %#lx", this->m_Pointer, Other.m_Pointer); - return this->m_Pointer != Other.m_Pointer; + strdbg("String iterator compared: %#lx != %#lx", this->Pointer, Other.Pointer); + return this->Pointer != Other.Pointer; } bool operator==(const iterator &Other) const { - strdbg("String iterator compared: %#lx == %#lx", this->m_Pointer, Other.m_Pointer); - return this->m_Pointer == Other.m_Pointer; + strdbg("String iterator compared: %#lx == %#lx", this->Pointer, Other.Pointer); + return this->Pointer == Other.Pointer; } }; iterator begin() { - strdbg("String iterator begin: %#lx", this->m_Data); - return iterator(this->m_Data); + strdbg("String iterator begin: %#lx", this->Data); + return iterator(this->Data); } iterator end() { - strdbg("String iterator end: %#lx", this->m_Data + this->m_Length); - return iterator(this->m_Data + this->m_Length); + strdbg("String iterator end: %#lx", this->Data + this->Length); + return iterator(this->Data + this->Length); } }; } diff --git a/include/std/unordered_map.hpp b/include/std/unordered_map.hpp index 8927ce8..587b56f 100644 --- a/include/std/unordered_map.hpp +++ b/include/std/unordered_map.hpp @@ -19,23 +19,23 @@ namespace std private: static const size_t DEFAULT_NUM_BUCKETS = 10; - std::vector m_buckets; + std::vector bkts; size_t hash(const key_type &key) const { std::hash hash_function; - return hash_function(key) % m_buckets.size(); + return hash_function(key) % this->bkts.size(); } public: - unordered_map() : m_buckets(DEFAULT_NUM_BUCKETS) {} - unordered_map(size_t num_buckets) : m_buckets(num_buckets) {} + unordered_map() : bkts(DEFAULT_NUM_BUCKETS) {} + unordered_map(size_t num_buckets) : bkts(num_buckets) {} void insert(const key_value_pair &pair) { size_t bucket_index = hash(pair.first); - bucket &bucket = m_buckets[bucket_index]; - for (auto it = bucket.begin(); it != bucket.end(); ++it) + bucket &bkt = this->bkts[bucket_index]; + for (auto it = bkt.begin(); it != bkt.end(); ++it) { if (it->first == pair.first) { @@ -43,14 +43,14 @@ namespace std return; } } - bucket.push_back(pair); + bkt.push_back(pair); } bool contains(const key_type &key) const { size_t bucket_index = hash(key); - const bucket &bucket = m_buckets[bucket_index]; - for (auto it = bucket.begin(); it != bucket.end(); ++it) + const bucket &bkt = this->bkts[bucket_index]; + for (auto it = bkt.begin(); it != bkt.end(); ++it) { if (it->first == key) { @@ -63,34 +63,34 @@ namespace std iterator find(const key_type &k) { size_t bucket_index = hash(k); - bucket &bucket = m_buckets[bucket_index]; - for (auto it = bucket.begin(); it != bucket.end(); ++it) + bucket &bkt = this->bkts[bucket_index]; + for (auto it = bkt.begin(); it != bkt.end(); ++it) { if (it->first == k) return it; } - return bucket.end(); + return bkt.end(); } const_iterator find(const key_type &k) const { size_t bucket_index = hash(k); - const bucket &bucket = m_buckets[bucket_index]; - for (auto it = bucket.begin(); it != bucket.end(); ++it) + const bucket &bkt = this->bkts[bucket_index]; + for (auto it = bkt.begin(); it != bkt.end(); ++it) { if (it->first == k) return it; } - return bucket.end(); + return bkt.end(); } - iterator end() noexcept { return m_buckets.end(); } + iterator end() noexcept { return this->bkts.end(); } size_t size() const { size_t count = 0; - for (const auto &bucket : m_buckets) - count += bucket.size(); + foreach (const auto &bkt in this->bkts) + count += bkt.size(); return count; } @@ -98,14 +98,14 @@ namespace std value_type &operator[](const key_type &key) { size_t bucket_index = hash(key); - bucket &bucket = m_buckets[bucket_index]; - for (auto it = bucket.begin(); it != bucket.end(); ++it) + bucket &bkt = this->bkts[bucket_index]; + for (auto it = bkt.begin(); it != bkt.end(); ++it) { if (it->first == key) return it->second; } - bucket.emplace_back(key, value_type()); - return bucket.back().second; + bkt.emplace_back(key, value_type()); + return bkt.back().second; } }; } diff --git a/include/std/vector.hpp b/include/std/vector.hpp index 7332e9e..d55825d 100644 --- a/include/std/vector.hpp +++ b/include/std/vector.hpp @@ -52,17 +52,17 @@ namespace std VectorBuffer[i] = Initial; } - NIF vector(const vector &vector) + NIF vector(const vector &v) { - VectorSize = vector.VectorSize; - VectorCapacity = vector.VectorCapacity; + VectorSize = v.VectorSize; + VectorCapacity = v.VectorCapacity; #ifdef DEBUG_MEM_ALLOCATION debug("VECTOR INIT: vector( )->Size: %lld", VectorSize); #endif assert(VectorSize > 0); VectorBuffer = new T[VectorSize]; for (size_t i = 0; i < VectorSize; i++) - VectorBuffer[i] = vector.VectorBuffer[i]; + VectorBuffer[i] = v.VectorBuffer[i]; } NIF ~vector() @@ -248,17 +248,17 @@ namespace std return VectorBuffer[Index]; } - NIF vector &operator=(const vector &vector) + NIF vector &operator=(const vector &v) { delete[] VectorBuffer; - VectorSize = vector.VectorSize; - VectorCapacity = vector.VectorCapacity; + VectorSize = v.VectorSize; + VectorCapacity = v.VectorCapacity; #ifdef DEBUG_MEM_ALLOCATION debug("VECTOR ALLOCATION: operator=( )->Size:%lld", VectorSize); #endif VectorBuffer = new T[VectorSize]; for (size_t i = 0; i < VectorSize; i++) - VectorBuffer[i] = vector.VectorBuffer[i]; + VectorBuffer[i] = v.VectorBuffer[i]; return *this; } }; diff --git a/include/types.h b/include/types.h index 818059c..20fa1ec 100644 --- a/include/types.h +++ b/include/types.h @@ -8,18 +8,18 @@ { #define END_EXTERNC \ } -#else +#else // __cplusplus #define EXTERNC #define START_EXTERNC #define END_EXTERNC -#endif +#endif // __cplusplus #ifdef __cplusplus #define NULL 0 -#else +#else // __cplusplus #define NULL ((void *)0) #define bool _Bool -#endif +#endif // __cplusplus #define asm __asm__ #define asmv __asm__ volatile @@ -30,7 +30,12 @@ #ifdef __cplusplus #define foreach for #define in : -#endif + +#define r_cst(t, v) reinterpret_cast(v) +#define c_cst(t, v) const_cast(v) +#define s_cst(t, v) static_cast(v) +#define d_cst(t, v) dynamic_cast(v) +#endif // __cplusplus #define UNUSED(x) (void)(x) #define CONCAT(x, y) x##y @@ -231,11 +236,32 @@ typedef intptr_t ssize_t; : "memory"); #endif +#ifdef __INT48_TYPE__ +typedef __INT48_TYPE__ int48_t; +typedef __UINT48_TYPE__ uint48_t; +typedef int48_t int_least48_t; +typedef uint48_t uint_least48_t; +typedef int48_t int_fast48_t; +typedef uint48_t uint_fast48_t; +#else // __INT48_TYPE__ +typedef __INT64_TYPE__ int48_t; +typedef __UINT64_TYPE__ uint48_t; +typedef int48_t int_least48_t; +typedef uint48_t uint_least48_t; +typedef int48_t int_fast48_t; +typedef uint48_t uint_fast48_t; +#endif // __INT48_TYPE__ + #define b4(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4) #define b8(x) ((x)&0xFF) #define b16(x) __builtin_bswap16(x) #define b32(x) __builtin_bswap32(x) -#define b48(x) (((((x)&0x0000000000ff) << 40) | (((x)&0x00000000ff00) << 24) | (((x)&0x000000ff0000) << 8) | (((x)&0x0000ff000000) >> 8) | (((x)&0x00ff00000000) >> 24) | (((x)&0xff0000000000) >> 40))) +#define b48(x) (((((x)&0x0000000000ff) << 40) | \ + (((x)&0x00000000ff00) << 24) | \ + (((x)&0x000000ff0000) << 8) | \ + (((x)&0x0000ff000000) >> 8) | \ + (((x)&0x00ff00000000) >> 24) | \ + (((x)&0xff0000000000) >> 40))) #define b64(x) __builtin_bswap64(x) /* https://gcc.gnu.org/onlinedocs/gcc-9.5.0/gnat_ugn/Optimization-Levels.html */