QoL improvements

This commit is contained in:
Alex 2023-03-27 20:11:32 +03:00
parent 3eb6923374
commit 93afcd2210
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
59 changed files with 612 additions and 424 deletions

View File

@ -30,6 +30,18 @@
"-mcmodel=kernel", "-mcmodel=kernel",
"-fno-builtin", "-fno-builtin",
// Warnings
"-Wall",
"-Wextra",
"-Wfloat-equal",
"-Wpointer-arith",
"-Wcast-align",
"-Wredundant-decls",
"-Winit-self",
"-Wswitch-default",
"-Wstrict-overflow=5",
"-Wconversion",
// C++ flags // C++ flags
"-fno-rtti", "-fno-rtti",
"-fexceptions", "-fexceptions",
@ -90,6 +102,18 @@
"-msoft-float", "-msoft-float",
"-fno-builtin", "-fno-builtin",
// Warnings
"-Wall",
"-Wextra",
"-Wfloat-equal",
"-Wpointer-arith",
"-Wcast-align",
"-Wredundant-decls",
"-Winit-self",
"-Wswitch-default",
"-Wstrict-overflow=5",
"-Wconversion",
// C++ flags // C++ flags
"-fno-rtti", "-fno-rtti",
"-fexceptions", "-fexceptions",

View File

@ -124,8 +124,8 @@ namespace ACPI
if (FADT) if (FADT)
{ {
outb(FADT->SMI_CommandPort, FADT->AcpiEnable); outb(s_cst(uint16_t, FADT->SMI_CommandPort), FADT->AcpiEnable);
while (!(inw(FADT->PM1aControlBlock) & 1)) while (!(inw(s_cst(uint16_t, FADT->PM1aControlBlock)) & 1))
; ;
} }
} }

View File

@ -123,9 +123,9 @@ SafeFunction NIF void init_limine()
{ {
struct limine_framebuffer *framebuffer = FrameBufferResponse->framebuffers[i]; struct limine_framebuffer *framebuffer = FrameBufferResponse->framebuffers[i];
binfo.Framebuffer[i].BaseAddress = (void *)((uint64_t)framebuffer->address - 0xffff800000000000); binfo.Framebuffer[i].BaseAddress = (void *)((uint64_t)framebuffer->address - 0xffff800000000000);
binfo.Framebuffer[i].Width = framebuffer->width; binfo.Framebuffer[i].Width = (uint32_t)framebuffer->width;
binfo.Framebuffer[i].Height = framebuffer->height; binfo.Framebuffer[i].Height = (uint32_t)framebuffer->height;
binfo.Framebuffer[i].Pitch = framebuffer->pitch; binfo.Framebuffer[i].Pitch = (uint32_t)framebuffer->pitch;
binfo.Framebuffer[i].BitsPerPixel = framebuffer->bpp; binfo.Framebuffer[i].BitsPerPixel = framebuffer->bpp;
binfo.Framebuffer[i].MemoryModel = framebuffer->memory_model; binfo.Framebuffer[i].MemoryModel = framebuffer->memory_model;
binfo.Framebuffer[i].RedMaskSize = framebuffer->red_mask_size; 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.PhysicalBase = (void *)KernelAddressResponse->physical_base;
binfo.Kernel.VirtualBase = (void *)KernelAddressResponse->virtual_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, strncpy(binfo.Kernel.CommandLine,
KernelFileResponse->kernel_file->cmdline, KernelFileResponse->kernel_file->cmdline,
strlen(KernelFileResponse->kernel_file->cmdline) + 1); strlen(KernelFileResponse->kernel_file->cmdline) + 1);

View File

@ -39,13 +39,13 @@ namespace ACPI
uint16_t a = 0, b = 0; uint16_t a = 0, b = 0;
if (acpi->FADT->PM1aEventBlock) if (acpi->FADT->PM1aEventBlock)
{ {
a = inw(acpi->FADT->PM1aEventBlock); a = inw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock));
outw(acpi->FADT->PM1aEventBlock, a); outw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock), a);
} }
if (acpi->FADT->PM1bEventBlock) if (acpi->FADT->PM1bEventBlock)
{ {
b = inw(acpi->FADT->PM1bEventBlock); b = inw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock));
outw(acpi->FADT->PM1bEventBlock, b); outw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock), b);
} }
Event = a | b; Event = a | b;
} }
@ -99,12 +99,24 @@ namespace ACPI
trace("Shutting down..."); trace("Shutting down...");
if (SCI_EN == 1) 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) if (acpi->FADT->PM1bControlBlock)
outw(acpi->FADT->PM1bControlBlock, (inw(acpi->FADT->PM1bControlBlock) & 0xE3FF) | ((SLP_TYPb << 10) | ACPI_SLEEP)); outw(s_cst(uint16_t, acpi->FADT->PM1bControlBlock),
outw(PM1a_CNT, SLP_TYPa | SLP_EN); 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) 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) switch (acpi->FADT->ResetReg.AddressSpace)
{ {
case ACPI_GAS_MMIO: case ACPI_GAS_MMIO:
{
*(uint8_t *)(acpi->FADT->ResetReg.Address) = acpi->FADT->ResetValue; *(uint8_t *)(acpi->FADT->ResetReg.Address) = acpi->FADT->ResetValue;
break; break;
}
case ACPI_GAS_IO: 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; break;
}
case ACPI_GAS_PCI: case ACPI_GAS_PCI:
{
fixme("ACPI_GAS_PCI not supported."); fixme("ACPI_GAS_PCI not supported.");
/* /*
seg - 0 seg - 0
@ -131,6 +148,12 @@ namespace ACPI
*/ */
break; break;
} }
default:
{
error("Unknown reset register address space: %d", acpi->FADT->ResetReg.AddressSpace);
break;
}
}
} }
DSDT::DSDT(ACPI *acpi) : Interrupts::Handler(acpi->FADT->SCI_Interrupt) DSDT::DSDT(ACPI *acpi) : Interrupts::Handler(acpi->FADT->SCI_Interrupt)
@ -157,11 +180,11 @@ namespace ACPI
S5Address += ((*S5Address & 0xC0) >> 6) + 2; S5Address += ((*S5Address & 0xC0) >> 6) + 2;
if (*S5Address == 0x0A) if (*S5Address == 0x0A)
S5Address++; S5Address++;
SLP_TYPa = *(S5Address) << 10; SLP_TYPa = s_cst(uint16_t, *(S5Address) << 10);
S5Address++; S5Address++;
if (*S5Address == 0x0A) if (*S5Address == 0x0A)
S5Address++; S5Address++;
SLP_TYPb = *(S5Address) << 10; SLP_TYPb = s_cst(uint16_t, *(S5Address) << 10);
SMI_CMD = acpi->FADT->SMI_CommandPort; SMI_CMD = acpi->FADT->SMI_CommandPort;
ACPI_ENABLE = acpi->FADT->AcpiEnable; ACPI_ENABLE = acpi->FADT->AcpiEnable;
ACPI_DISABLE = acpi->FADT->AcpiDisable; ACPI_DISABLE = acpi->FADT->AcpiDisable;
@ -175,8 +198,8 @@ namespace ACPI
uint16_t value = ACPI_POWER_BUTTON | ACPI_SLEEP_BUTTON | ACPI_WAKE; uint16_t value = ACPI_POWER_BUTTON | ACPI_SLEEP_BUTTON | ACPI_WAKE;
{ {
uint16_t a = acpi->FADT->PM1aEventBlock + (acpi->FADT->PM1EventLength / 2); uint16_t a = s_cst(uint16_t, acpi->FADT->PM1aEventBlock + (acpi->FADT->PM1EventLength / 2));
uint16_t b = acpi->FADT->PM1bEventBlock + (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); debug("SCI Event: %#llx [a:%#x b:%#x]", value, a, b);
if (acpi->FADT->PM1aEventBlock) if (acpi->FADT->PM1aEventBlock)
outw(a, value); outw(a, value);
@ -188,13 +211,13 @@ namespace ACPI
uint16_t a = 0, b = 0; uint16_t a = 0, b = 0;
if (acpi->FADT->PM1aEventBlock) if (acpi->FADT->PM1aEventBlock)
{ {
a = inw(acpi->FADT->PM1aEventBlock); a = inw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock));
outw(acpi->FADT->PM1aEventBlock, a); outw(s_cst(uint16_t, acpi->FADT->PM1aEventBlock), a);
} }
if (acpi->FADT->PM1bEventBlock) if (acpi->FADT->PM1bEventBlock)
{ {
b = inw(acpi->FADT->PM1bEventBlock); b = inw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock));
outw(acpi->FADT->PM1bEventBlock, b); outw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock), b);
} }
} }
((APIC::APIC *)Interrupts::apic[0])->RedirectIRQ(0, acpi->FADT->SCI_Interrupt, 1); ((APIC::APIC *)Interrupts::apic[0])->RedirectIRQ(0, acpi->FADT->SCI_Interrupt, 1);

View File

@ -56,6 +56,11 @@ namespace ACPI
KPrint("APIC found at \e8888FF%#lx\eCCCCCC", LAPICAddress); KPrint("APIC found at \e8888FF%#lx\eCCCCCC", LAPICAddress);
break; 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? Memory::Virtual(KernelPageTable).Map((void *)LAPICAddress, (void *)LAPICAddress, Memory::PTFlag::RW | Memory::PTFlag::PCD); // I should map more than one page?
} }

View File

@ -38,9 +38,9 @@ namespace APIC
if (x2APICSupported) if (x2APICSupported)
{ {
if (Register != APIC_ICRHI) if (Register != APIC_ICRHI)
return rdmsr((Register >> 4) + 0x800); return s_cst(uint32_t, rdmsr((Register >> 4) + 0x800));
else else
return rdmsr(0x30 + 0x800); return s_cst(uint32_t, rdmsr(0x30 + 0x800));
} }
else else
{ {
@ -107,7 +107,7 @@ namespace APIC
} while (icr.DeliveryStatus != Idle); } while (icr.DeliveryStatus != Idle);
} }
void APIC::IPI(uint8_t CPU, InterruptCommandRegisterLow icr) void APIC::IPI(int CPU, InterruptCommandRegisterLow icr)
{ {
SmartCriticalSection(APICLock); SmartCriticalSection(APICLock);
if (x2APICSupported) if (x2APICSupported)
@ -118,12 +118,12 @@ namespace APIC
else else
{ {
this->Write(APIC_ICRHI, (CPU << 24)); this->Write(APIC_ICRHI, (CPU << 24));
this->Write(APIC_ICRLO, icr.raw); this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw));
this->WaitForIPI(); this->WaitForIPI();
} }
} }
void APIC::SendInitIPI(uint8_t CPU) void APIC::SendInitIPI(int CPU)
{ {
SmartCriticalSection(APICLock); SmartCriticalSection(APICLock);
if (x2APICSupported) if (x2APICSupported)
@ -137,12 +137,12 @@ namespace APIC
icr.DeliveryMode = INIT; icr.DeliveryMode = INIT;
icr.Level = Assert; icr.Level = Assert;
this->Write(APIC_ICRHI, (CPU << 24)); this->Write(APIC_ICRHI, (CPU << 24));
this->Write(APIC_ICRLO, icr.raw); this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw));
this->WaitForIPI(); this->WaitForIPI();
} }
} }
void APIC::SendStartupIPI(uint8_t CPU, uint64_t StartupAddress) void APIC::SendStartupIPI(int CPU, uint64_t StartupAddress)
{ {
SmartCriticalSection(APICLock); SmartCriticalSection(APICLock);
if (x2APICSupported) if (x2APICSupported)
@ -153,11 +153,11 @@ namespace APIC
else else
{ {
InterruptCommandRegisterLow icr = {.raw = 0}; InterruptCommandRegisterLow icr = {.raw = 0};
icr.Vector = StartupAddress >> 12; icr.Vector = s_cst(uint8_t, StartupAddress >> 12);
icr.DeliveryMode = Startup; icr.DeliveryMode = Startup;
icr.Level = Assert; icr.Level = Assert;
this->Write(APIC_ICRHI, (CPU << 24)); this->Write(APIC_ICRHI, (CPU << 24));
this->Write(APIC_ICRLO, icr.raw); this->Write(APIC_ICRLO, s_cst(uint32_t, icr.raw));
this->WaitForIPI(); this->WaitForIPI();
} }
} }
@ -168,14 +168,14 @@ namespace APIC
return ((IOAPICVersion *)&TableAddress)->MaximumRedirectionEntry; 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; uint64_t Value = Vector;
int64_t IOAPICTarget = -1; int64_t IOAPICTarget = -1;
for (uint64_t i = 0; ((ACPI::MADT *)PowerManager->GetMADT())->ioapic[i] != 0; i++) 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 <= 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; IOAPICTarget = i;
break; break;
@ -205,7 +205,7 @@ namespace APIC
this->IOWrite(((ACPI::MADT *)PowerManager->GetMADT())->ioapic[IOAPICTarget]->Address, IORegister + 1, (uint32_t)(Value >> 32)); 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++) for (uint64_t i = 0; i < ((ACPI::MADT *)PowerManager->GetMADT())->iso.size(); i++)
if (((ACPI::MADT *)PowerManager->GetMADT())->iso[i]->IRQSource == IRQ) if (((ACPI::MADT *)PowerManager->GetMADT())->iso[i]->IRQSource == IRQ)
@ -224,7 +224,7 @@ namespace APIC
{ {
SmartCriticalSection(APICLock); SmartCriticalSection(APICLock);
debug("Redirecting IRQs..."); debug("Redirecting IRQs...");
for (int i = 0; i < 16; i++) for (uint8_t i = 0; i < 16; i++)
this->RedirectIRQ(CPU, i, 1); this->RedirectIRQ(CPU, i, 1);
debug("Redirecting IRQs completed."); debug("Redirecting IRQs completed.");
} }
@ -314,7 +314,7 @@ namespace APIC
Spurious Spurious = {.raw = this->Read(APIC_SVR)}; Spurious Spurious = {.raw = this->Read(APIC_SVR)};
Spurious.Vector = IRQ223; // TODO: Should I map the IRQ to something? Spurious.Vector = IRQ223; // TODO: Should I map the IRQ to something?
Spurious.Software = 1; Spurious.Software = 1;
this->Write(APIC_SVR, Spurious.raw); this->Write(APIC_SVR, s_cst(uint32_t, Spurious.raw));
static int once = 0; static int once = 0;
if (!once++) if (!once++)
@ -337,14 +337,14 @@ namespace APIC
{ {
SmartCriticalSection(APICLock); SmartCriticalSection(APICLock);
LVTTimer timer = {.raw = 0}; LVTTimer timer = {.raw = 0};
timer.Vector = Vector; timer.Vector = s_cst(uint8_t, Vector);
timer.TimerMode = 0; timer.TimerMode = 0;
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0) if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) != 0)
this->lapic->Write(APIC_TDCR, DivideBy128); this->lapic->Write(APIC_TDCR, DivideBy128);
else else
this->lapic->Write(APIC_TDCR, DivideBy16); this->lapic->Write(APIC_TDCR, DivideBy16);
this->lapic->Write(APIC_TICR, Ticks * Miliseconds); this->lapic->Write(APIC_TICR, s_cst(uint32_t, Ticks * Miliseconds));
this->lapic->Write(APIC_TIMER, timer.raw); this->lapic->Write(APIC_TIMER, s_cst(uint32_t, timer.raw));
} }
Timer::Timer(APIC *apic) : Interrupts::Handler(0) /* IRQ0 */ Timer::Timer(APIC *apic) : Interrupts::Handler(0) /* IRQ0 */
@ -372,8 +372,8 @@ namespace APIC
// Initialize APIC timer // Initialize APIC timer
this->lapic->Write(APIC_TDCR, Divider); this->lapic->Write(APIC_TDCR, Divider);
this->lapic->Write(APIC_TICR, Ticks); this->lapic->Write(APIC_TICR, s_cst(uint32_t, Ticks));
this->lapic->Write(APIC_TIMER, timer.raw); this->lapic->Write(APIC_TIMER, s_cst(uint32_t, timer.raw));
trace("%d APIC Timer %d ticks in.", GetCurrentCPU()->ID, Ticks); trace("%d APIC Timer %d ticks in.", GetCurrentCPU()->ID, Ticks);
KPrint("APIC Timer: \e8888FF%ld\eCCCCCC ticks.", Ticks); KPrint("APIC Timer: \e8888FF%ld\eCCCCCC ticks.", Ticks);
} }

View File

@ -147,7 +147,7 @@ namespace GlobalDescriptorTable
gdt[Core].Entries->TaskStateSegment.BaseLow = Base & 0xFFFF; gdt[Core].Entries->TaskStateSegment.BaseLow = Base & 0xFFFF;
gdt[Core].Entries->TaskStateSegment.BaseMiddle = (Base >> 16) & 0xFF; gdt[Core].Entries->TaskStateSegment.BaseMiddle = (Base >> 16) & 0xFF;
gdt[Core].Entries->TaskStateSegment.BaseHigh = (Base >> 24) & 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.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); gdt[Core].Entries->TaskStateSegment.Granularity = (0 << 4) | ((Limit >> 16) & 0xF);

View File

@ -7,6 +7,9 @@
#include "gdt.hpp" #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 MainInterruptHandler(void *Data);
extern "C" void ExceptionHandler(void *Data); extern "C" void ExceptionHandler(void *Data);
@ -26,8 +29,8 @@ namespace InterruptDescriptorTable
InterruptDescriptorTableFlags Ring, InterruptDescriptorTableFlags Ring,
uint16_t SegmentSelector) uint16_t SegmentSelector)
{ {
Entries[Index].BaseLow = (uint16_t)((uint64_t)Base & 0xFFFF); Entries[Index].BaseLow = s_cst(uint16_t, ((uint64_t)Base & 0xFFFF));
Entries[Index].BaseHigh = (uint64_t)((uint64_t)Base >> 16 /* & 0xFFFF */); Entries[Index].BaseHigh = s_cst(uint64_t, ((uint64_t)Base >> 16 /* & 0xFFFF */));
Entries[Index].SegmentSelector = SegmentSelector; Entries[Index].SegmentSelector = SegmentSelector;
Entries[Index].Flags = Attribute; Entries[Index].Flags = Attribute;
Entries[Index].Reserved1 = 0; Entries[Index].Reserved1 = 0;

View File

@ -50,7 +50,7 @@ SafeFunction CPUData *GetCurrentCPU()
extern "C" void StartCPU() extern "C" void StartCPU()
{ {
CPU::Interrupts(CPU::Disable); CPU::Interrupts(CPU::Disable);
uint64_t CoreID = (int)*reinterpret_cast<int *>(CORE); int CoreID = (int)*reinterpret_cast<int *>(CORE);
CPU::InitializeFeatures(CoreID); CPU::InitializeFeatures(CoreID);
// Initialize GDT and IDT // Initialize GDT and IDT
Interrupts::Initialize(CoreID); Interrupts::Initialize(CoreID);
@ -96,14 +96,14 @@ namespace SMP
memcpy((void *)TRAMPOLINE_START, &_trampoline_start, TrampolineLength); memcpy((void *)TRAMPOLINE_START, &_trampoline_start, TrampolineLength);
POKE(volatile uint64_t, PAGE_TABLE) = (uint64_t)KernelPageTable; VPOKE(uint64_t, PAGE_TABLE) = (uint64_t)KernelPageTable;
POKE(volatile uint64_t, STACK) = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; VPOKE(uint64_t, STACK) = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE;
POKE(volatile uint64_t, CORE) = i; VPOKE(int, CORE) = i;
asmv("sgdt [0x580]\n" asmv("sgdt [0x580]\n"
"sidt [0x590]\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])->SendInitIPI(((ACPI::MADT *)madt)->lapic[i]->APICId);
((APIC::APIC *)Interrupts::apic[0])->SendStartupIPI(((ACPI::MADT *)madt)->lapic[i]->APICId, TRAMPOLINE_START); ((APIC::APIC *)Interrupts::apic[0])->SendStartupIPI(((ACPI::MADT *)madt)->lapic[i]->APICId, TRAMPOLINE_START);

View File

@ -309,12 +309,12 @@ namespace APIC
void EOI(); void EOI();
void RedirectIRQs(int CPU = 0); void RedirectIRQs(int CPU = 0);
void WaitForIPI(); void WaitForIPI();
void IPI(uint8_t CPU, InterruptCommandRegisterLow icr); void IPI(int CPU, InterruptCommandRegisterLow icr);
void SendInitIPI(uint8_t CPU); void SendInitIPI(int CPU);
void SendStartupIPI(uint8_t CPU, uint64_t StartupAddress); void SendStartupIPI(int CPU, uint64_t StartupAddress);
uint32_t IOGetMaxRedirect(uint32_t APICID); uint32_t IOGetMaxRedirect(uint32_t APICID);
void RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status); void RawRedirectIRQ(uint16_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(int Core);
~APIC(); ~APIC();
}; };

View File

@ -314,7 +314,7 @@ namespace APIC
void SendStartupIPI(uint8_t CPU, uint64_t StartupAddress); void SendStartupIPI(uint8_t CPU, uint64_t StartupAddress);
uint32_t IOGetMaxRedirect(uint32_t APICID); uint32_t IOGetMaxRedirect(uint32_t APICID);
void RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status); 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(int Core);
~APIC(); ~APIC();
}; };

View File

@ -140,6 +140,8 @@ namespace CPU
#endif #endif
return true; return true;
} }
default:
break;
} }
return false; return false;
} }

View File

@ -508,7 +508,7 @@ namespace CrashHandler
EHPrint("\e00FF000"); EHPrint("\e00FF000");
if (i % 128 == 127) 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); EHPrint("\n\eFAFAFA[%03ld%%] %08ld: ", Percentage, i);
Display->SetBuffer(SBIdx); Display->SetBuffer(SBIdx);
} }
@ -524,8 +524,8 @@ namespace CrashHandler
uint64_t Reserved = KernelAllocator.GetReservedMemory(); 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); 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 Progress = s_cst(int, (Used * 100) / Total);
int ReservedProgress = (Reserved * 100) / Total; int ReservedProgress = s_cst(int, (Reserved * 100) / Total);
EHPrint("\e22AA44%3d%% \eCCCCCC[", Progress); EHPrint("\e22AA44%3d%% \eCCCCCC[", Progress);
for (int i = 0; i < Progress; i++) for (int i = 0; i < Progress; i++)
EHPrint("\eFF0000|"); EHPrint("\eFF0000|");
@ -695,7 +695,7 @@ namespace CrashHandler
if (unlikely(i % 0x1000 == 0)) if (unlikely(i % 0x1000 == 0))
{ {
int NewProgress = (i * 100) / ProgressLength; int NewProgress = (int)((i * 100) / ProgressLength);
if (unlikely(NewProgress != Progress)) if (unlikely(NewProgress != Progress))
{ {
Progress = NewProgress; Progress = NewProgress;

View File

@ -126,6 +126,9 @@ namespace CrashHandler
case KEY_D_RIGHT: case KEY_D_RIGHT:
case KEY_D_DOWN: case KEY_D_DOWN:
ArrowInput(scanCode); ArrowInput(scanCode);
break;
default:
break;
} }
int key = GetLetterFromScanCode(scanCode); int key = GetLetterFromScanCode(scanCode);
@ -148,8 +151,8 @@ namespace CrashHandler
} }
else else
{ {
append(UserInputBuffer, key); append(UserInputBuffer, s_cst(char, key));
Display->Print(key, SBIdx); Display->Print((char)key, SBIdx);
BackSpaceLimit++; BackSpaceLimit++;
} }
Display->SetBuffer(SBIdx); // Update as we type. Display->SetBuffer(SBIdx); // Update as we type.

View File

@ -141,6 +141,13 @@ namespace CrashHandler
EHPrint(" %ld\n", SelCode.Idx); EHPrint(" %ld\n", SelCode.Idx);
break; break;
} }
default:
{
EHPrint(" ? \n");
EHPrint(" ? \n");
EHPrint(" %ld\n", SelCode.Idx);
break;
}
} }
break; break;
} }
@ -181,6 +188,13 @@ namespace CrashHandler
EHPrint(" %ld\n", SelCode.Idx); EHPrint(" %ld\n", SelCode.Idx);
break; break;
} }
default:
{
EHPrint(" ? \n");
EHPrint(" ? \n");
EHPrint(" %ld\n", SelCode.Idx);
break;
}
} }
break; break;
} }
@ -220,6 +234,13 @@ namespace CrashHandler
EHPrint(" %ld\n", SelCode.Idx); EHPrint(" %ld\n", SelCode.Idx);
break; break;
} }
default:
{
EHPrint(" ? \n");
EHPrint(" ? \n");
EHPrint(" %ld\n", SelCode.Idx);
break;
}
} }
break; break;
} }
@ -260,6 +281,13 @@ namespace CrashHandler
EHPrint(" %ld\n", SelCode.Idx); EHPrint(" %ld\n", SelCode.Idx);
break; break;
} }
default:
{
EHPrint(" ? \n");
EHPrint(" ? \n");
EHPrint(" %ld\n", SelCode.Idx);
break;
}
} }
break; break;
} }

View File

@ -235,9 +235,9 @@ namespace Driver
if (!Handle.InterruptCallback) if (!Handle.InterruptCallback)
{ {
#if defined(a64) || defined(a32) #if defined(a64) || defined(a32)
int IntNum = Frame->InterruptNumber - 32; uint64_t IntNum = Frame->InterruptNumber - 32;
#elif defined(aa64) #elif defined(aa64)
int IntNum = Frame->InterruptNumber; uint64_t IntNum = Frame->InterruptNumber;
#endif #endif
warn("Interrupt callback for %ld is not set for driver %ld!", IntNum, Handle.DriverUID); warn("Interrupt callback for %ld is not set for driver %ld!", IntNum, Handle.DriverUID);
return; return;

View File

@ -20,7 +20,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -75,7 +75,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -123,7 +123,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -172,7 +172,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -253,7 +253,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -302,7 +302,7 @@ namespace Driver
debug("Searching for conflicting drivers..."); debug("Searching for conflicting drivers...");
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -392,7 +392,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));

View File

@ -133,7 +133,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -181,7 +181,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -229,7 +229,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -306,7 +306,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -383,7 +383,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -431,7 +431,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
@ -479,7 +479,7 @@ namespace Driver
if (fexExtended->Driver.OverrideOnConflict) if (fexExtended->Driver.OverrideOnConflict)
{ {
std::vector<int> DriversToRemove = std::vector<int>(); std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
foreach (auto Drv in Drivers) foreach (auto Drv in Drivers)
{ {
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS)); FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));

View File

@ -190,16 +190,16 @@ namespace Interrupts
Handler::~Handler() 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++) for (size_t i = 0; i < RegisteredEvents.size(); i++)
{ {
if (RegisteredEvents[i].ID == InterruptNumber) if (RegisteredEvents[i].ID == this->InterruptNumber)
{ {
RegisteredEvents.remove(i); RegisteredEvents.remove(i);
return; return;
} }
} }
warn("Event %d not found.", InterruptNumber); warn("Event %d not found.", this->InterruptNumber);
} }
#if defined(a64) #if defined(a64)

View File

@ -22,9 +22,9 @@ namespace PCI
{ {
uint8_t Digit = (Value >> (4 - (i * 4))) & 0xF; uint8_t Digit = (Value >> (4 - (i * 4))) & 0xF;
if (Digit < 10) if (Digit < 10)
Buffer[i] = '0' + Digit; Buffer[i] = s_cst(char, '0' + Digit);
else else
Buffer[i] = 'A' + (Digit - 10); Buffer[i] = s_cst(char, 'A' + (Digit - 10));
} }
return Buffer; return Buffer;
} }
@ -37,9 +37,9 @@ namespace PCI
{ {
uint8_t Digit = (Value >> (28 - (i * 4))) & 0xF; uint8_t Digit = (Value >> (28 - (i * 4))) & 0xF;
if (Digit < 10) if (Digit < 10)
Buffer[i] = '0' + Digit; Buffer[i] = s_cst(char, '0' + Digit);
else else
Buffer[i] = 'A' + (Digit - 10); Buffer[i] = s_cst(char, 'A' + (Digit - 10));
} }
return Buffer; return Buffer;
} }
@ -555,6 +555,8 @@ namespace PCI
} }
break; break;
} }
default:
break;
} }
fixme("Unknown device %04x:%04x", VendorID, DeviceID); fixme("Unknown device %04x:%04x", VendorID, DeviceID);
return u32ToHexString(DeviceID); return u32ToHexString(DeviceID);
@ -649,7 +651,10 @@ namespace PCI
} }
break; break;
} }
default:
break;
} }
default:
break; break;
} }
case 0x03: case 0x03:
@ -667,6 +672,8 @@ namespace PCI
return "VGA Compatible Controller"; return "VGA Compatible Controller";
} }
break; break;
default:
break;
} }
break; break;
} }
@ -838,7 +845,7 @@ namespace PCI
PCI::PCI() PCI::PCI()
{ {
#if defined(a64) #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); Memory::Virtual vma = Memory::Virtual(KernelPageTable);
for (int t = 0; t < Entries; t++) for (int t = 0; t < Entries; t++)
{ {

View File

@ -46,6 +46,8 @@ namespace SymbolResolver
debug("String table found, %d entries", ElfSections[i].sh_size); debug("String table found, %d entries", ElfSections[i].sh_size);
} }
break; break;
default:
break;
} }
if (ElfSymbols != nullptr && strtab != nullptr) if (ElfSymbols != nullptr && strtab != nullptr)

View File

@ -64,7 +64,7 @@ namespace Time
this->hpet = (void *)acpi->HPET->Address.Address; this->hpet = (void *)acpi->HPET->Address.Address;
HPET *hpet = (HPET *)this->hpet; HPET *hpet = (HPET *)this->hpet;
trace("%s timer is at address %016p", acpi->HPET->Header.OEMID, (void *)acpi->HPET->Address.Address); 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->GeneralConfiguration, 0);
mmoutq(&hpet->MainCounterValue, 0); mmoutq(&hpet->MainCounterValue, 0);
mmoutq(&hpet->GeneralConfiguration, 1); mmoutq(&hpet->GeneralConfiguration, 1);

View File

@ -80,16 +80,16 @@ namespace UniversalAsynchronousReceiverTransmitter
return; return;
// Initialize the serial port // Initialize the serial port
NoProfiler_outportb(Port + 1, 0x00); // Disable all interrupts NoProfiler_outportb(s_cst(uint16_t, Port + 1), 0x00); // Disable all interrupts
NoProfiler_outportb(Port + 3, SERIAL_ENABLE_DLAB); // Enable DLAB (set baud rate divisor) NoProfiler_outportb(s_cst(uint16_t, 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(s_cst(uint16_t, 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(s_cst(uint16_t, Port + 1), SERIAL_RATE_115200_HI); // (hi byte)
NoProfiler_outportb(Port + 3, 0x03); // 8 bits, no parity, one stop bit NoProfiler_outportb(s_cst(uint16_t, 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(s_cst(uint16_t, 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 + 4), 0x0B); // IRQs enabled, RTS/DSR set
// Check if the serial port is faulty. // 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; static int once = 0;
if (!once++) if (!once++)
@ -99,7 +99,7 @@ namespace UniversalAsynchronousReceiverTransmitter
} }
// Set to normal operation mode. // Set to normal operation mode.
NoProfiler_outportb(Port + 4, 0x0F); NoProfiler_outportb(s_cst(uint16_t, Port + 4), 0x0F);
serialports[PortNumber] = true; serialports[PortNumber] = true;
#endif #endif
} }
@ -109,7 +109,7 @@ namespace UniversalAsynchronousReceiverTransmitter
SafeFunction NIF void UART::Write(uint8_t Char) SafeFunction NIF void UART::Write(uint8_t Char)
{ {
#if defined(a64) || defined(a32) #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); NoProfiler_outportb(Port, Char);
#endif #endif
@ -121,7 +121,7 @@ namespace UniversalAsynchronousReceiverTransmitter
SafeFunction NIF uint8_t UART::Read() SafeFunction NIF uint8_t UART::Read()
{ {
#if defined(a64) || defined(a32) #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); return NoProfiler_inportb(Port);
#endif #endif

View File

@ -116,14 +116,14 @@ namespace Video
uint8_t g = (color >> 8) & 0xff; uint8_t g = (color >> 8) & 0xff;
uint8_t b = (color >> 16) & 0xff; uint8_t b = (color >> 16) & 0xff;
r = (r * Value) / 100; r = s_cst(uint8_t, (r * Value) / 100);
g = (g * Value) / 100; g = s_cst(uint8_t, (g * Value) / 100);
b = (b * Value) / 100; b = s_cst(uint8_t, (b * Value) / 100);
pixel[y * this->Buffers[Index].Width + x] = (b << 16) | (g << 8) | r; 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) 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 LineSize = this->Buffers[Index].Width * (this->framebuffer.BitsPerPixel / 8);
uint32_t BytesToMove = LineSize * Lines * this->CurrentFont->GetInfo().Height; 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); memmove(this->Buffers[Index].Buffer, (uint8_t *)this->Buffers[Index].Buffer + BytesToMove, BytesToClear);
memset((uint8_t *)this->Buffers[Index].Buffer + BytesToClear, 0, BytesToMove); memset((uint8_t *)this->Buffers[Index].Buffer + BytesToClear, 0, BytesToMove);
} }
@ -304,6 +304,8 @@ namespace Video
this->Buffers[Index].CursorY += this->GetCurrentFont()->GetInfo().Height; this->Buffers[Index].CursorY += this->GetCurrentFont()->GetInfo().Height;
return Char; return Char;
} }
default:
break;
} }
uint32_t FontHeight = this->GetCurrentFont()->GetInfo().Height; uint32_t FontHeight = this->GetCurrentFont()->GetInfo().Height;
@ -412,7 +414,7 @@ namespace Video
this->ClearBuffer(0); this->ClearBuffer(0);
this->SetBuffer(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) if (this->Buffers[i].Checksum == 0xBBFFE515A117E)
this->DeleteBuffer(i); this->DeleteBuffer(i);

View File

@ -50,6 +50,10 @@ namespace Execute
SymbolTable = shdr; SymbolTable = shdr;
StringTable = GetELFSection(Header, shdr->sh_link); StringTable = GetELFSection(Header, shdr->sh_link);
break; break;
default:
{
break;
}
} }
} }

View File

@ -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) void PaintChar(Video::Font *font, ScreenBitmap *Bitmap, char c, uint32_t Color, long *CharCursorX, long *CharCursorY)
{ {
switch (font->GetInfo().Type) switch (font->GetInfo().Type)
@ -182,6 +184,7 @@ namespace GraphicalUserInterface
break; break;
} }
} }
#pragma GCC diagnostic pop
void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color) void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color)
{ {

View File

@ -69,15 +69,15 @@ namespace GraphicalUserInterface
this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size)); this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size));
memset(this->Buffer->Data, 0, 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); memset(this->Buffer->Data, 0, this->Buffer->Size);
this->OnPaintBackground(e); this->OnPaintBackground(e);
this->OnPaintForeground(e); this->OnPaintForeground(e);
NeedRedraw = false; this->NeedRedraw = false;
} }
DrawOverBitmap(((Window *)this->ParentWindow)->GetBuffer(), this->Buffer, 0, 0); DrawOverBitmap(((Window *)this->ParentWindow)->GetBuffer(), this->Buffer, 0, 0);
} }
@ -92,7 +92,7 @@ namespace GraphicalUserInterface
{ {
debug("Button Hold"); debug("Button Hold");
Button->Pressed = true; Button->Pressed = true;
NeedRedraw = true; this->NeedRedraw = true;
} }
} }
} }
@ -114,7 +114,7 @@ namespace GraphicalUserInterface
((void (*)(void))Button->OnClick)(); ((void (*)(void))Button->OnClick)();
Button->Pressed = false; Button->Pressed = false;
NeedRedraw = true; this->NeedRedraw = true;
} }
} }
} }
@ -128,12 +128,12 @@ namespace GraphicalUserInterface
if (Button->rect.Contains(e->MouseMove.X, e->MouseMove.Y)) if (Button->rect.Contains(e->MouseMove.X, e->MouseMove.Y))
{ {
Button->Hover = true; Button->Hover = true;
NeedRedraw = true; this->NeedRedraw = true;
} }
else else
{ {
Button->Hover = false; Button->Hover = false;
NeedRedraw = true; this->NeedRedraw = true;
} }
} }
} }

View File

@ -17,7 +17,7 @@ namespace GraphicalUserInterface
{ {
Handle WidgetCollection::CreatePanel(Rect rect, uint32_t Color) 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[0] = 'P';
panel->Handle.Type[1] = 'N'; panel->Handle.Type[1] = 'N';
@ -31,13 +31,13 @@ namespace GraphicalUserInterface
panel->Shadow = false; panel->Shadow = false;
Panels.push_back(panel); Panels.push_back(panel);
NeedRedraw = true; this->NeedRedraw = true;
return (Handle)panel; return (Handle)panel;
} }
Handle WidgetCollection::CreateLabel(Rect rect, const char *Text) 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[0] = 'L';
label->Handle.Type[1] = 'B'; label->Handle.Type[1] = 'B';
@ -57,7 +57,7 @@ namespace GraphicalUserInterface
Handle WidgetCollection::CreateButton(Rect rect, const char *Text, uintptr_t OnClick) 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[0] = 'B';
button->Handle.Type[1] = 'T'; button->Handle.Type[1] = 'T';
@ -77,7 +77,7 @@ namespace GraphicalUserInterface
button->OnClick = OnClick; button->OnClick = OnClick;
Buttons.push_back(button); Buttons.push_back(button);
NeedRedraw = true; this->NeedRedraw = true;
return (Handle)button; return (Handle)button;
} }
@ -88,7 +88,7 @@ namespace GraphicalUserInterface
{ {
LabelObject *label = (LabelObject *)handle; LabelObject *label = (LabelObject *)handle;
strcpy(label->Text, Text); strcpy(label->Text, Text);
NeedRedraw = true; this->NeedRedraw = true;
} }
} }

View File

@ -243,6 +243,11 @@ void ParseConfig(char *ConfigString, KernelConfig *ModConfig)
KPrint("\eFF2200System Halted."); KPrint("\eFF2200System Halted.");
CPU::Stop(); CPU::Stop();
} }
default:
{
KPrint("\eFF2200Unknown option: %c", identifier);
break;
}
} }
} }
debug("Config loaded"); debug("Config loaded");

View File

@ -161,7 +161,7 @@ void BootLogoAnimationThread()
break; break;
} }
FrameSizes[FrameCount] = ba->node->Length; FrameSizes[FrameCount] = s_cst(uint32_t, ba->node->Length);
Frames[FrameCount] = new uint8_t[ba->node->Length]; Frames[FrameCount] = new uint8_t[ba->node->Length];
memcpy((void *)Frames[FrameCount], (void *)ba->node->Address, ba->node->Length); memcpy((void *)Frames[FrameCount], (void *)ba->node->Address, ba->node->Length);
bootanim_vfs->Close(ba); bootanim_vfs->Close(ba);
@ -189,10 +189,10 @@ void BootLogoAnimationThread()
for (int i = 0; i < x * y; i++) for (int i = 0; i < x * y; i++)
{ {
uint32_t pixel = ((uint32_t *)img)[i]; uint32_t pixel = ((uint32_t *)img)[i];
uint8_t r = (pixel >> 16) & 0xFF; int r = (pixel >> 16) & 0xFF;
uint8_t g = (pixel >> 8) & 0xFF; int g = (pixel >> 8) & 0xFF;
uint8_t b = (pixel >> 0) & 0xFF; int b = (pixel >> 0) & 0xFF;
uint8_t a = (pixel >> 24) & 0xFF; int a = (pixel >> 24) & 0xFF;
if (a != 0xFF) if (a != 0xFF)
{ {
@ -244,10 +244,10 @@ void ExitLogoAnimationThread()
for (int i = 0; i < x * y; i++) for (int i = 0; i < x * y; i++)
{ {
uint32_t pixel = ((uint32_t *)img)[i]; uint32_t pixel = ((uint32_t *)img)[i];
uint8_t r = (pixel >> 16) & 0xFF; int r = (pixel >> 16) & 0xFF;
uint8_t g = (pixel >> 8) & 0xFF; int g = (pixel >> 8) & 0xFF;
uint8_t b = (pixel >> 0) & 0xFF; int b = (pixel >> 0) & 0xFF;
uint8_t a = (pixel >> 24) & 0xFF; int a = (pixel >> 24) & 0xFF;
if (a != 0xFF) if (a != 0xFF)
{ {

View File

@ -20,13 +20,13 @@ EXTERNC int memcmp(const void *vl, const void *vr, size_t n)
EXTERNC void backspace(char s[]) EXTERNC void backspace(char s[])
{ {
int len = strlen(s); int len = s_cst(int, strlen(s));
s[len - 1] = '\0'; s[len - 1] = '\0';
} }
EXTERNC void append(char s[], char n) EXTERNC void append(char s[], char n)
{ {
int len = strlen(s); int len = s_cst(int, strlen(s));
s[len] = n; s[len] = n;
s[len + 1] = '\0'; s[len + 1] = '\0';
} }
@ -184,7 +184,7 @@ EXTERNC long int strtol(const char *str, char **endptr, int base)
base = c == '0' ? 8 : 10; base = c == '0' ? 8 : 10;
cutoff = neg ? LONG_MIN : LONG_MAX; cutoff = neg ? LONG_MIN : LONG_MAX;
cutlim = cutoff % base; cutlim = s_cst(int, cutoff % base);
cutoff /= base; cutoff /= base;
for (acc = 0, any = 0;; c = *s++) 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; base = c == '0' ? 8 : 10;
cutoff = neg ? LONG_MIN : LONG_MAX; cutoff = neg ? LONG_MIN : LONG_MAX;
cutlim = cutoff % base; cutlim = s_cst(int, cutoff % base);
cutoff /= base; cutoff /= base;
for (acc = 0, any = 0;; c = *s++) for (acc = 0, any = 0;; c = *s++)
{ {
@ -342,8 +342,12 @@ EXTERNC float sqrtf(float x)
float guess = x / 2.0f; float guess = x / 2.0f;
for (short i = 0; i < 10; i++) for (short i = 0; i < 10; i++)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
if (guess == 0.0f) if (guess == 0.0f)
return 0.0f; return 0.0f;
#pragma GCC diagnostic pop
guess = (guess + x / guess) / 2.0f; guess = (guess + x / guess) / 2.0f;
} }
return guess; return guess;
@ -366,7 +370,10 @@ EXTERNC float lerp(float a, float b, float t)
EXTERNC float smoothstep(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)); 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) EXTERNC int atoi(const char *String)
{ {
uint64_t Length = strlen((char *)String); uint64_t Length = strlen((char *)String);
uint64_t OutBuffer = 0; int OutBuffer = 0;
uint64_t Power = 1; int Power = 1;
for (uint64_t i = Length; i > 0; --i) for (uint64_t i = Length; i > 0; --i)
{ {
OutBuffer += (String[i - 1] - 48) * Power; OutBuffer += (String[i - 1] - 48) * Power;
@ -517,16 +524,16 @@ EXTERNC char *itoa(int Value, char *Buffer, int Base)
if (Base < 2 || Base > 32) if (Base < 2 || Base > 32)
return Buffer; return Buffer;
int n = abs(Value); int n = s_cst(int, abs(Value));
int i = 0; int i = 0;
while (n) while (n)
{ {
int r = n % Base; int r = s_cst(int, n % Base);
if (r >= 10) if (r >= 10)
Buffer[i++] = 65 + (r - 10); Buffer[i++] = s_cst(char, 65 + (r - 10));
else else
Buffer[i++] = 48 + r; Buffer[i++] = s_cst(char, 48 + r);
n = n / Base; n = n / Base;
} }
@ -550,11 +557,11 @@ EXTERNC char *ltoa(long Value, char *Buffer, int Base)
while (n) while (n)
{ {
int r = n % Base; int r = s_cst(int, n % Base);
if (r >= 10) if (r >= 10)
Buffer[i++] = 65 + (r - 10); Buffer[i++] = s_cst(char, 65 + (r - 10));
else else
Buffer[i++] = 48 + r; Buffer[i++] = s_cst(char, 48 + r);
n = n / Base; n = n / Base;
} }
@ -578,11 +585,11 @@ EXTERNC char *ultoa(unsigned long Value, char *Buffer, int Base)
while (n) while (n)
{ {
int r = n % Base; int r = s_cst(int, n % Base);
if (r >= 10) if (r >= 10)
Buffer[i++] = 65 + (r - 10); Buffer[i++] = s_cst(char, 65 + (r - 10));
else else
Buffer[i++] = 48 + r; Buffer[i++] = s_cst(char, 48 + r);
n = n / Base; n = n / Base;
} }

View File

@ -4,6 +4,9 @@
#include <limits.h> #include <limits.h>
#include <debug.h> #include <debug.h>
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
/* Some of the functions are from musl library */ /* Some of the functions are from musl library */
/* https://www.musl-libc.org/ */ /* https://www.musl-libc.org/ */
/* /*
@ -85,9 +88,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
} }
if (n >= 32) if (n >= 32)
{
switch ((uintptr_t)d % 4) switch ((uintptr_t)d % 4)
{ {
case 1: case 1:
{
w = *(u32 *)s; w = *(u32 *)s;
*d++ = *s++; *d++ = *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); *(u32 *)(d + 12) = (x LS 24) | (w RS 8);
} }
break; break;
}
case 2: case 2:
{
w = *(u32 *)s; w = *(u32 *)s;
*d++ = *s++; *d++ = *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); *(u32 *)(d + 12) = (x LS 16) | (w RS 16);
} }
break; break;
}
case 3: case 3:
{
w = *(u32 *)s; w = *(u32 *)s;
*d++ = *s++; *d++ = *s++;
n -= 1; n -= 1;
@ -139,6 +148,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
} }
break; break;
} }
default:
break;
}
}
if (n & 16) if (n & 16)
{ {
*d++ = *s++; *d++ = *s++;
@ -158,6 +172,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++;
} }
if (n & 8) if (n & 8)
{ {
*d++ = *s++; *d++ = *s++;
@ -169,6 +184,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++;
} }
if (n & 4) if (n & 4)
{ {
*d++ = *s++; *d++ = *s++;
@ -176,11 +192,13 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++;
} }
if (n & 2) if (n & 2)
{ {
*d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++;
} }
if (n & 1) if (n & 1)
{ {
*d = *s; *d = *s;
@ -200,18 +218,24 @@ void *memset_unsafe(void *dest, int c, size_t n)
if (!n) if (!n)
return dest; return dest;
s[0] = c; s[0] = c;
s[n - 1] = c; s[n - 1] = c;
if (n <= 2) if (n <= 2)
return dest; return dest;
s[1] = c; s[1] = c;
s[2] = c; s[2] = c;
s[n - 2] = c; s[n - 2] = c;
s[n - 3] = c; s[n - 3] = c;
if (n <= 6) if (n <= 6)
return dest; return dest;
s[3] = c; s[3] = c;
s[n - 4] = c; s[n - 4] = c;
if (n <= 8) if (n <= 8)
return dest; 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 c32 = ((u32)-1) / 255 * (unsigned char)c;
*(u32 *)(s + 0) = c32; *(u32 *)(s + 0) = c32;
*(u32 *)(s + n - 4) = c32; *(u32 *)(s + n - 4) = c32;
if (n <= 8) if (n <= 8)
return dest; return dest;
*(u32 *)(s + 4) = c32; *(u32 *)(s + 4) = c32;
*(u32 *)(s + 8) = c32; *(u32 *)(s + 8) = c32;
*(u32 *)(s + n - 12) = c32; *(u32 *)(s + n - 12) = c32;
*(u32 *)(s + n - 8) = c32; *(u32 *)(s + n - 8) = c32;
if (n <= 24) if (n <= 24)
return dest; return dest;
*(u32 *)(s + 12) = c32; *(u32 *)(s + 12) = c32;
*(u32 *)(s + 16) = c32; *(u32 *)(s + 16) = c32;
*(u32 *)(s + 20) = c32; *(u32 *)(s + 20) = c32;
@ -276,6 +304,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n)
if (d == s) if (d == s)
return d; return d;
if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n) if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n)
return memcpy(d, s, n); return memcpy(d, s, n);
@ -288,6 +317,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n)
{ {
if (!n--) if (!n--)
return dest; return dest;
*d++ = *s++; *d++ = *s++;
} }
for (; n >= WS; n -= WS, d += WS, s += WS) 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--) if (!n--)
return dest; return dest;
d[n] = s[n]; d[n] = s[n];
} }
while (n >= WS) while (n >= WS)

View File

@ -23,6 +23,7 @@ SOFTWARE.
*/ */
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration" #pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#include <assert.h> #include <assert.h>
#include <cargs.h> #include <cargs.h>

View File

@ -1,5 +1,8 @@
#include "liballoc_1_1.h" #include "liballoc_1_1.h"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
/** Durand's Amazing Super Duper Memory functions. */ /** Durand's Amazing Super Duper Memory functions. */
#define VERSION "1.1" #define VERSION "1.1"

View File

@ -37,6 +37,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#pragma GCC diagnostic ignored "-Wfloat-equal"
// Define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H=1 ...) to include the // Define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H=1 ...) to include the
// printf_config.h header file // printf_config.h header file
#if PRINTF_INCLUDE_CONFIG_H #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'; gadget->buffer[null_char_pos] = '\0';
} }
extern void putchar(char c);
// We can't use putchar_ as is, since our output gadget // We can't use putchar_ as is, since our output gadget
// only takes pointers to functions with an extra argument // only takes pointers to functions with an extra argument
static inline NIF void putchar_wrapper(char c, void *unused) static inline NIF void putchar_wrapper(char c, void *unused)

View File

@ -49,7 +49,10 @@ INCLUDE_DIR = ./include
LDFLAGS := -Wl,-Map kernel.map -shared -nostdlib -nodefaultlibs -nolibc 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" # 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 # https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
CFLAGS := \ CFLAGS := \
@ -59,6 +62,8 @@ CFLAGS := \
-DGIT_COMMIT='"$(GIT_COMMIT)"' \ -DGIT_COMMIT='"$(GIT_COMMIT)"' \
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' -DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
SIMD_FLAGS := -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mavx512f
ifeq ($(OSARCH), amd64) ifeq ($(OSARCH), amd64)
CFLAGS += -fno-pic -fno-pie \ CFLAGS += -fno-pic -fno-pie \

View File

@ -4,6 +4,9 @@
#include "../kernel.h" #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 namespace NetworkARP
{ {
DiscoveredAddress *ARP::ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC) DiscoveredAddress *ARP::ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC)
@ -58,6 +61,10 @@ namespace NetworkARP
} }
return nullptr; return nullptr;
} }
default:
{
return nullptr;
}
} }
return nullptr; return nullptr;
} }

View File

@ -66,7 +66,7 @@ namespace NetworkDHCP
*(Ptr++) = DHCP_OPTION_HOST_NAME; *(Ptr++) = DHCP_OPTION_HOST_NAME;
char *HostName = (char *)KERNEL_NAME; char *HostName = (char *)KERNEL_NAME;
*(Ptr++) = 1 + strlen(HostName); *(Ptr++) = s_cst(uint8_t, 1 + strlen(HostName));
memcpy(Ptr, HostName, strlen(HostName)); memcpy(Ptr, HostName, strlen(HostName));
Ptr += strlen(HostName); Ptr += strlen(HostName);

View File

@ -3,6 +3,9 @@
#include "../kernel.h" #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 namespace NetworkEthernet
{ {
struct EthernetEventHelperStruct struct EthernetEventHelperStruct

View File

@ -27,8 +27,8 @@ namespace NetworkIPv4
Packet->Header.IHL = b8(sizeof(IPv4Header) / 4); Packet->Header.IHL = b8(sizeof(IPv4Header) / 4);
Packet->Header.TypeOfService = b8(0); Packet->Header.TypeOfService = b8(0);
/* We don't byteswap. */ /* We don't byteswap. */
Packet->Header.TotalLength = Length + sizeof(IPv4Header); Packet->Header.TotalLength = s_cst(uint16_t, Length + sizeof(IPv4Header));
Packet->Header.TotalLength = ((Packet->Header.TotalLength & 0xFF00) >> 8) | ((Packet->Header.TotalLength & 0x00FF) << 8); Packet->Header.TotalLength = s_cst(uint16_t, ((Packet->Header.TotalLength & 0xFF00) >> 8) | ((Packet->Header.TotalLength & 0x00FF) << 8));
Packet->Header.Identification = b16(0x0000); Packet->Header.Identification = b16(0x0000);
Packet->Header.Flags = b8(0x0); Packet->Header.Flags = b8(0x0);

View File

@ -49,8 +49,8 @@ namespace NetworkNTP
TaskManager->Sleep(1000); TaskManager->Sleep(1000);
} }
int UnixTimestamp = b32(this->NTPPacket.TransmitTimestamp[0]) - 2208988800; long UnixTimestamp = b32(this->NTPPacket.TransmitTimestamp[0]) - 2208988800;
debug("Unix time: %d", UnixTimestamp); debug("Unix time: %d", UnixTimestamp);
return UnixTimestamp; return s_cst(int, UnixTimestamp);
} }
} }

View File

@ -60,7 +60,7 @@ namespace NetworkUDP
void UDP::Send(Socket *Socket, uint8_t *Data, uint64_t Length) void UDP::Send(Socket *Socket, uint8_t *Data, uint64_t Length)
{ {
netdbg("Sending %d bytes to %s", Length, Socket->RemoteIP.v4.ToStringLittleEndian(), Socket->RemotePort); 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); UDPPacket *packet = (UDPPacket *)kmalloc(TotalLength);
packet->Header.SourcePort = Socket->LocalPort; packet->Header.SourcePort = Socket->LocalPort;
packet->Header.DestinationPort = Socket->RemotePort; packet->Header.DestinationPort = Socket->RemotePort;

View File

@ -115,7 +115,7 @@ namespace Recovery
void CSR88200() { ChangeSampleRate(7); } void CSR88200() { ChangeSampleRate(7); }
void CSR96000() { ChangeSampleRate(8); } void CSR96000() { ChangeSampleRate(8); }
void ChangeVolume(int percentage) void ChangeVolume(char percentage)
{ {
Driver::DriverFile AudioDrv; Driver::DriverFile AudioDrv;
@ -253,8 +253,8 @@ namespace Recovery
MemUsed = KernelAllocator.GetUsedMemory(); MemUsed = KernelAllocator.GetUsedMemory();
MemTotal = KernelAllocator.GetTotalMemory(); MemTotal = KernelAllocator.GetTotalMemory();
MemReserved = KernelAllocator.GetReservedMemory(); MemReserved = KernelAllocator.GetReservedMemory();
int MemPercent = (MemUsed * 100) / MemTotal; uint64_t 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); 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); wdgDbgWin->SetText(MemLblHnd, TicksText);
RefreshMemCounter = 25; RefreshMemCounter = 25;
} }

View File

@ -29,13 +29,13 @@ __constructor void TestMacros()
debug("-------------------------"); debug("-------------------------");
{ {
uintptr_t actual = PAGE_SIZE; uint64_t actual = PAGE_SIZE;
int expected = 1; uint64_t expected = 1;
for (int i = 0; i < 128; i++) for (int i = 0; i < 128; i++)
{ {
int a = TO_PAGES(actual); uint64_t a = TO_PAGES(actual);
uintptr_t b = FROM_PAGES(expected); uint64_t b = FROM_PAGES(expected);
/* TODO: This is a workaround for now. */ /* TODO: This is a workaround for now. */
if (a != expected + 1) if (a != expected + 1)

View File

@ -64,11 +64,11 @@ enum MemoryOrder
template <typename T> template <typename T>
class Atomic class Atomic
{ {
_Atomic(T) m_Value; _Atomic(T) Value;
public: public:
Atomic() : m_Value(0) {} Atomic() : Value(0) {}
Atomic(T Init) : m_Value(Init) {} Atomic(T Init) : Value(Init) {}
/** /**
* @brief Load the value of the atomic variable * @brief Load the value of the atomic variable
@ -78,7 +78,7 @@ public:
*/ */
T Load(MemoryOrder Order = MemoryOrder::SeqCst) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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; } operator bool() { return this->Load() != 0; }

View File

@ -23,8 +23,8 @@ struct BootInfo
struct FramebufferInfo struct FramebufferInfo
{ {
void *BaseAddress; void *BaseAddress;
__UINT64_TYPE__ Width; __UINT32_TYPE__ Width;
__UINT64_TYPE__ Height; __UINT32_TYPE__ Height;
__UINT64_TYPE__ Pitch; __UINT64_TYPE__ Pitch;
__UINT16_TYPE__ BitsPerPixel; __UINT16_TYPE__ BitsPerPixel;
__UINT8_TYPE__ MemoryModel; __UINT8_TYPE__ MemoryModel;

View File

@ -397,7 +397,7 @@ namespace CPU
SafeFunction static inline void wrmsr(uint32_t msr, uint64_t Value) 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" asmv("wrmsr"
: :
: "c"(msr), "a"(Low), "d"(High) : "c"(msr), "a"(Low), "d"(High)

View File

@ -38,7 +38,7 @@ namespace Interrupts
* @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32) * @param InterruptNumber The interrupt number. NOT the IRQ number! (IRQ0 != 32)
*/ */
void SetInterruptNumber(int InterruptNumber) { this->InterruptNumber = InterruptNumber; } void SetInterruptNumber(int InterruptNumber) { this->InterruptNumber = InterruptNumber; }
int GetInterruptNumber() { return InterruptNumber; } int GetInterruptNumber() { return this->InterruptNumber; }
/** /**
* @brief Create a new interrupt handler. * @brief Create a new interrupt handler.

View File

@ -28,7 +28,7 @@ namespace NetworkInterfaceManager
void *DriverCallBackAddress; void *DriverCallBackAddress;
/** @brief Reserved */ /** @brief Reserved */
unsigned int DriverID; unsigned long DriverID;
}; };
class Events class Events

View File

@ -16,16 +16,6 @@ static inline void DbgNetwork() { return; }
static inline void DbgDumpData(const char *Description, void *Address, unsigned long Length) { return; } static inline void DbgDumpData(const char *Description, void *Address, unsigned long Length) { return; }
#endif #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 enum Endianness
{ {
LITTLE_ENDIAN, LITTLE_ENDIAN,
@ -149,10 +139,10 @@ struct InternetProtocol
inline uint32_t ToHex() inline uint32_t ToHex()
{ {
return ((uint64_t)this->Address[0] << 24) | return ((uint32_t)this->Address[0] << 24) |
((uint64_t)this->Address[1] << 16) | ((uint32_t)this->Address[1] << 16) |
((uint64_t)this->Address[2] << 8) | ((uint32_t)this->Address[2] << 8) |
((uint64_t)this->Address[3]); ((uint32_t)this->Address[3]);
} }
inline InternetProtocol::Version4 FromHex(uint32_t Hex) inline InternetProtocol::Version4 FromHex(uint32_t Hex)

View File

@ -95,8 +95,8 @@ extern "C"
* *
* @param c the single character to print * @param c the single character to print
*/ */
PRINTF_VISIBILITY // PRINTF_VISIBILITY
void putchar(char c); // void putchar(char c);
/** /**
* An implementation of the C standard's printf/vprintf * An implementation of the C standard's printf/vprintf

View File

@ -31,7 +31,7 @@ struct CPUData
uintptr_t Stack; uintptr_t Stack;
/** @brief CPU ID. */ /** @brief CPU ID. */
long ID; int ID;
/** @brief Local CPU error code. */ /** @brief Local CPU error code. */
long ErrorCode; long ErrorCode;

View File

@ -17,15 +17,15 @@ namespace std
const uint8_t *data = reinterpret_cast<const uint8_t *>(&key); const uint8_t *data = reinterpret_cast<const uint8_t *>(&key);
const size_t size = sizeof(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) for (size_t i = 0; i < size; ++i)
{ {
hash ^= static_cast<uint64_t>(data[i]); ret ^= static_cast<uint64_t>(data[i]);
hash *= fnv_prime; ret *= fnv_prime;
} }
return static_cast<size_t>(hash); return static_cast<size_t>(ret);
} }
}; };
} }

View File

@ -31,37 +31,37 @@ namespace std
template <class T> template <class T>
class smart_ptr class smart_ptr
{ {
T *m_RealPointer; T *RealPointer;
public: public:
explicit smart_ptr(T *Pointer = nullptr) explicit smart_ptr(T *Pointer = nullptr)
{ {
spdbg("Smart pointer created (%#lx)", m_RealPointer); spdbg("Smart pointer created (%#lx)", this->RealPointer);
m_RealPointer = Pointer; this->RealPointer = Pointer;
} }
~smart_ptr() ~smart_ptr()
{ {
spdbg("Smart pointer deleted (%#lx)", m_RealPointer); spdbg("Smart pointer deleted (%#lx)", this->RealPointer);
delete m_RealPointer, m_RealPointer = nullptr; delete this->RealPointer, this->RealPointer = nullptr;
} }
T &operator*() T &operator*()
{ {
spdbg("Smart pointer dereferenced (%#lx)", m_RealPointer); spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer);
return *m_RealPointer; return *this->RealPointer;
} }
T *operator->() T *operator->()
{ {
spdbg("Smart pointer dereferenced (%#lx)", m_RealPointer); spdbg("Smart pointer dereferenced (%#lx)", this->RealPointer);
return m_RealPointer; return this->RealPointer;
} }
T *get() T *get()
{ {
spdbg("Smart pointer returned (%#lx)", m_RealPointer); spdbg("Smart pointer returned (%#lx)", this->RealPointer);
return m_RealPointer; return this->RealPointer;
} }
}; };
@ -87,148 +87,148 @@ namespace std
class counter class counter
{ {
private: private:
unsigned int m_RefCount{}; unsigned int RefCount{};
public: public:
counter() : m_RefCount(0) { spdbg("Counter %#lx created", this); }; counter() : RefCount(0) { spdbg("Counter %#lx created", this); };
counter(const counter &) = delete; counter(const counter &) = delete;
counter &operator=(const counter &) = delete; counter &operator=(const counter &) = delete;
~counter() { spdbg("Counter %#lx deleted", this); } ~counter() { spdbg("Counter %#lx deleted", this); }
void reset() void reset()
{ {
m_RefCount = 0; this->RefCount = 0;
spdbg("reset"); spdbg("reset");
} }
unsigned int get() unsigned int get()
{ {
return m_RefCount; return this->RefCount;
spdbg("return"); spdbg("return");
} }
void operator++() void operator++()
{ {
m_RefCount++; this->RefCount++;
spdbg("increment"); spdbg("increment");
} }
void operator++(int) void operator++(int)
{ {
m_RefCount++; this->RefCount++;
spdbg("increment"); spdbg("increment");
} }
void operator--() void operator--()
{ {
m_RefCount--; this->RefCount--;
spdbg("decrement"); spdbg("decrement");
} }
void operator--(int) void operator--(int)
{ {
m_RefCount--; this->RefCount--;
spdbg("decrement"); spdbg("decrement");
} }
}; };
counter *m_ReferenceCounter; counter *ReferenceCounter;
T *m_RealPointer; T *RealPointer;
public: public:
explicit shared_ptr(T *Pointer = nullptr) explicit shared_ptr(T *Pointer = nullptr)
{ {
m_RealPointer = Pointer; this->RealPointer = Pointer;
m_ReferenceCounter = new counter(); this->ReferenceCounter = new counter();
spdbg("[%#lx] Shared pointer created (ptr=%#lx, ref=%#lx)", this, Pointer, m_ReferenceCounter); spdbg("[%#lx] Shared pointer created (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter);
if (Pointer) if (Pointer)
(*m_ReferenceCounter)++; (*this->ReferenceCounter)++;
} }
shared_ptr(shared_ptr<T> &SPtr) shared_ptr(shared_ptr<T> &SPtr)
{ {
spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.m_RealPointer, SPtr.m_ReferenceCounter); spdbg("[%#lx] Shared pointer copied (ptr=%#lx, ref=%#lx)", this, SPtr.RealPointer, SPtr.ReferenceCounter);
m_RealPointer = SPtr.m_RealPointer; this->RealPointer = SPtr.RealPointer;
m_ReferenceCounter = SPtr.m_ReferenceCounter; this->ReferenceCounter = SPtr.ReferenceCounter;
(*m_ReferenceCounter)++; (*this->ReferenceCounter)++;
} }
~shared_ptr() ~shared_ptr()
{ {
spdbg("[%#lx] Shared pointer destructor called", this); spdbg("[%#lx] Shared pointer destructor called", this);
(*m_ReferenceCounter)--; (*this->ReferenceCounter)--;
if (m_ReferenceCounter->get() == 0) if (this->ReferenceCounter->get() == 0)
{ {
spdbg("[%#lx] Shared pointer deleted (ptr=%#lx, ref=%#lx)", this, m_RealPointer, m_ReferenceCounter); spdbg("[%#lx] Shared pointer deleted (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter);
delete m_ReferenceCounter, m_ReferenceCounter = nullptr; delete this->ReferenceCounter, this->ReferenceCounter = nullptr;
delete m_RealPointer, m_RealPointer = nullptr; delete this->RealPointer, this->RealPointer = nullptr;
} }
} }
unsigned int get_count() unsigned int get_count()
{ {
spdbg("[%#lx] Shared pointer count (%d)", this, m_ReferenceCounter->get()); spdbg("[%#lx] Shared pointer count (%d)", this, this->ReferenceCounter->get());
return m_ReferenceCounter->get(); return this->ReferenceCounter->get();
} }
T *get() T *get()
{ {
spdbg("[%#lx] Shared pointer get (%#lx)", this, m_RealPointer); spdbg("[%#lx] Shared pointer get (%#lx)", this, this->RealPointer);
return m_RealPointer; return this->RealPointer;
} }
T &operator*() T &operator*()
{ {
spdbg("[%#lx] Shared pointer dereference (ptr*=%#lx)", this, *m_RealPointer); spdbg("[%#lx] Shared pointer dereference (ptr*=%#lx)", this, *this->RealPointer);
return *m_RealPointer; return *this->RealPointer;
} }
T *operator->() T *operator->()
{ {
spdbg("[%#lx] Shared pointer dereference (ptr->%#lx)", this, m_RealPointer); spdbg("[%#lx] Shared pointer dereference (ptr->%#lx)", this, this->RealPointer);
return m_RealPointer; return this->RealPointer;
} }
void reset(T *Pointer = nullptr) void reset(T *Pointer = nullptr)
{ {
if (m_RealPointer == Pointer) if (this->RealPointer == Pointer)
return; return;
spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, Pointer, m_ReferenceCounter); spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, Pointer, this->ReferenceCounter);
(*m_ReferenceCounter)--; (*this->ReferenceCounter)--;
if (m_ReferenceCounter->get() == 0) if (this->ReferenceCounter->get() == 0)
{ {
delete m_RealPointer; delete this->RealPointer;
delete m_ReferenceCounter; delete this->ReferenceCounter;
} }
m_RealPointer = Pointer; this->RealPointer = Pointer;
m_ReferenceCounter = new counter(); this->ReferenceCounter = new counter();
if (Pointer) if (Pointer)
(*m_ReferenceCounter)++; (*this->ReferenceCounter)++;
} }
void reset() void reset()
{ {
spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, m_RealPointer, m_ReferenceCounter); spdbg("[%#lx] Shared pointer reset (ptr=%#lx, ref=%#lx)", this, this->RealPointer, this->ReferenceCounter);
if (m_ReferenceCounter->get() == 1) if (this->ReferenceCounter->get() == 1)
{ {
delete m_RealPointer, m_RealPointer = nullptr; delete this->RealPointer, this->RealPointer = nullptr;
delete m_ReferenceCounter, m_ReferenceCounter = nullptr; delete this->ReferenceCounter, this->ReferenceCounter = nullptr;
} }
else else
{ {
(*m_ReferenceCounter)--; (*this->ReferenceCounter)--;
} }
} }
void swap(shared_ptr<T> &Other) void swap(shared_ptr<T> &Other)
{ {
spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)", spdbg("[%#lx] Shared pointer swap (ptr=%#lx, ref=%#lx <=> ptr=%#lx, ref=%#lx)",
this, m_RealPointer, m_ReferenceCounter, Other.m_RealPointer, Other.m_ReferenceCounter); this, this->RealPointer, this->ReferenceCounter, Other.RealPointer, Other.ReferenceCounter);
T *tempRealPointer = m_RealPointer; T *tempRealPointer = this->RealPointer;
counter *tempReferenceCounter = m_ReferenceCounter; counter *tempReferenceCounter = this->ReferenceCounter;
m_RealPointer = Other.m_RealPointer; this->RealPointer = Other.RealPointer;
m_ReferenceCounter = Other.m_ReferenceCounter; this->ReferenceCounter = Other.ReferenceCounter;
Other.m_RealPointer = tempRealPointer; Other.RealPointer = tempRealPointer;
Other.m_ReferenceCounter = tempReferenceCounter; Other.ReferenceCounter = tempReferenceCounter;
} }
}; };

View File

@ -12,7 +12,7 @@ namespace std
public: public:
runtime_error(const char *what_arg) : m_what(what_arg) {} 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; }
}; };
} }

View File

@ -25,85 +25,85 @@ namespace std
class string class string
{ {
private: private:
char *m_Data; char *Data;
size_t m_Length; size_t Length;
size_t m_Capacity; size_t Capacity;
public: public:
static const size_t npos = -1; static const size_t npos = -1;
string(const char *Str = "") string(const char *Str = "")
{ {
this->m_Length = strlen(Str); this->Length = strlen(Str);
this->m_Capacity = this->m_Length + 1; this->Capacity = this->Length + 1;
this->m_Data = new char[m_Capacity]; this->Data = new char[this->Capacity];
strcpy(m_Data, Str); strcpy(this->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); strdbg("New string created: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
} }
~string() ~string()
{ {
strdbg("String deleted: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); strdbg("String deleted: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
delete[] this->m_Data, this->m_Data = nullptr; delete[] this->Data, this->Data = nullptr;
} }
int length() const size_t length() const
{ {
strdbg("String length: %d", this->m_Length); strdbg("String length: %d", this->Length);
return this->m_Length; return this->Length;
} }
int capacity() const size_t capacity() const
{ {
strdbg("String capacity: %d", this->m_Capacity); strdbg("String capacity: %d", this->Capacity);
return this->m_Capacity; return this->Capacity;
} }
const char *c_str() const const char *c_str() const
{ {
strdbg("String data: \"%s\"", this->m_Data); strdbg("String data: \"%s\"", this->Data);
return this->m_Data; return this->Data;
} }
void resize(size_t NewLength) void resize(size_t NewLength)
{ {
strdbg("String resize: %d", NewLength); strdbg("String resize: %d", NewLength);
if (NewLength > this->m_Capacity) if (NewLength > this->Capacity)
{ {
size_t newCapacity = NewLength + 1; size_t newCapacity = NewLength + 1;
char *newData = new char[newCapacity]; char *newData = new char[newCapacity];
strcpy(newData, this->m_Data); strcpy(newData, this->Data);
strdbg("old: %#lx, new: %#lx", this->m_Data, newData); strdbg("old: %#lx, new: %#lx", this->Data, newData);
delete[] this->m_Data; delete[] this->Data;
this->m_Data = newData; this->Data = newData;
this->m_Capacity = newCapacity; this->Capacity = newCapacity;
} }
this->m_Length = NewLength; this->Length = NewLength;
this->m_Data[m_Length] = '\0'; this->Data[this->Length] = '\0';
strdbg("String resized: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); strdbg("String resized: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
} }
void concat(const string &Other) void concat(const string &Other)
{ {
int NewLength = this->m_Length + Other.m_Length; size_t NewLength = this->Length + Other.Length;
this->resize(NewLength); this->resize(NewLength);
strcat(m_Data, Other.m_Data); strcat(this->Data, Other.Data);
strdbg("String concatenated: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); strdbg("String concatenated: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
} }
bool empty() const bool empty() const
{ {
strdbg("String empty: %d", this->m_Length == 0); strdbg("String empty: %d", this->Length == 0);
return this->m_Length == 0; return this->Length == 0;
} }
size_t size() const size_t size() const
{ {
strdbg("String size: %d", this->m_Length); strdbg("String size: %d", this->Length);
return this->m_Length; return this->Length;
} }
void clear() void clear()
@ -115,15 +115,15 @@ namespace std
size_t find(const char *Str, size_t Pos = 0) const size_t find(const char *Str, size_t Pos = 0) const
{ {
strdbg("String find: \"%s\", %d", Str, Pos); strdbg("String find: \"%s\", %d", Str, Pos);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return npos; return npos;
for (size_t i = Pos; i < this->m_Length; i++) for (size_t i = Pos; i < this->Length; i++)
{ {
bool found = true; bool found = true;
for (size_t j = 0; Str[j] != '\0'; j++) 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; found = false;
break; break;
@ -144,35 +144,35 @@ namespace std
void erase(int Index, int Count = 1) void erase(int Index, int Count = 1)
{ {
strdbg("String erase: %d, %d", Index, Count); 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; return;
if (Count < 0) if (Count < 0)
return; return;
if ((size_t)(Index + Count) > this->m_Length) if ((size_t)(Index + Count) > this->Length)
Count = this->m_Length - Index; Count = (int)this->Length - Index;
for (size_t i = Index; i < this->m_Length - Count; i++) for (size_t i = Index; i < this->Length - Count; i++)
this->m_Data[i] = this->m_Data[i + Count]; this->Data[i] = this->Data[i + Count];
this->m_Length -= Count; this->Length -= Count;
this->m_Data[m_Length] = '\0'; this->Data[this->Length] = '\0';
strdbg("String erased: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); 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 size_t find_last_not_of(const char *Str, size_t Pos = npos) const
{ {
strdbg("String find_last_not_of: \"%s\", %d", Str, Pos); strdbg("String find_last_not_of: \"%s\", %d", Str, Pos);
if (Pos == npos) if (Pos == npos)
Pos = this->m_Length - 1; Pos = this->Length - 1;
for (int i = (int)Pos; i >= 0; i--) for (int i = (int)Pos; i >= 0; i--)
{ {
bool found = false; bool found = false;
for (size_t j = 0; Str[j] != '\0'; j++) for (size_t j = 0; Str[j] != '\0'; j++)
{ {
if (this->m_Data[i] == Str[j]) if (this->Data[i] == Str[j])
{ {
found = true; found = true;
break; break;
@ -187,15 +187,15 @@ namespace std
size_t find_first_not_of(const char *Str, size_t Pos = 0) const size_t find_first_not_of(const char *Str, size_t Pos = 0) const
{ {
strdbg("String find_first_not_of: \"%s\", %d", Str, Pos); strdbg("String find_first_not_of: \"%s\", %d", Str, Pos);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return npos; return npos;
for (size_t i = Pos; i < this->m_Length; i++) for (size_t i = Pos; i < this->Length; i++)
{ {
bool found = false; bool found = false;
for (size_t j = 0; Str[j] != '\0'; j++) for (size_t j = 0; Str[j] != '\0'; j++)
{ {
if (this->m_Data[i] == Str[j]) if (this->Data[i] == Str[j])
{ {
found = true; found = true;
break; break;
@ -210,15 +210,15 @@ namespace std
size_t find_first_of(const char *Str, size_t Pos = 0) const size_t find_first_of(const char *Str, size_t Pos = 0) const
{ {
strdbg("String find_first_of: \"%s\", %d", Str, Pos); strdbg("String find_first_of: \"%s\", %d", Str, Pos);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return npos; return npos;
for (size_t i = Pos; i < this->m_Length; i++) for (size_t i = Pos; i < this->Length; i++)
{ {
bool found = false; bool found = false;
for (size_t j = 0; Str[j] != '\0'; j++) for (size_t j = 0; Str[j] != '\0'; j++)
{ {
if (this->m_Data[i] == Str[j]) if (this->Data[i] == Str[j])
{ {
found = true; found = true;
break; break;
@ -234,14 +234,14 @@ namespace std
{ {
strdbg("String find_last_of: \"%s\", %d", Str, Pos); strdbg("String find_last_of: \"%s\", %d", Str, Pos);
if (Pos == npos) if (Pos == npos)
Pos = this->m_Length - 1; Pos = this->Length - 1;
for (int i = (int)Pos; i >= 0; i--) for (int i = (int)Pos; i >= 0; i--)
{ {
bool found = false; bool found = false;
for (int j = 0; Str[j] != '\0'; j++) for (int j = 0; Str[j] != '\0'; j++)
{ {
if (this->m_Data[i] == Str[j]) if (this->Data[i] == Str[j])
{ {
found = true; found = true;
break; break;
@ -256,12 +256,12 @@ namespace std
size_t find_first_of(char C, size_t Pos = 0) const size_t find_first_of(char C, size_t Pos = 0) const
{ {
strdbg("String find_first_of: '%c', %d", C, Pos); strdbg("String find_first_of: '%c', %d", C, Pos);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return npos; 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 i;
} }
return npos; return npos;
@ -271,11 +271,11 @@ namespace std
{ {
strdbg("String find_last_of: '%c', %d", C, Pos); strdbg("String find_last_of: '%c', %d", C, Pos);
if (Pos == npos) if (Pos == npos)
Pos = this->m_Length - 1; Pos = this->Length - 1;
for (int i = (int)Pos; i >= 0; i--) for (int i = (int)Pos; i >= 0; i--)
{ {
if (this->m_Data[i] == C) if (this->Data[i] == C)
return i; return i;
} }
return npos; return npos;
@ -284,15 +284,15 @@ namespace std
size_t substr(const char *Str, size_t Pos = 0) const size_t substr(const char *Str, size_t Pos = 0) const
{ {
strdbg("String substr: \"%s\", %d", Str, Pos); strdbg("String substr: \"%s\", %d", Str, Pos);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return npos; return npos;
for (size_t i = Pos; i < this->m_Length; i++) for (size_t i = Pos; i < this->Length; i++)
{ {
bool found = true; bool found = true;
for (size_t j = 0; Str[j] != '\0'; j++) 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; found = false;
break; break;
@ -313,76 +313,76 @@ namespace std
string substr(size_t Pos = 0, size_t Count = npos) const string substr(size_t Pos = 0, size_t Count = npos) const
{ {
strdbg("String substr: %d, %d", Pos, Count); strdbg("String substr: %d, %d", Pos, Count);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return string(); return string();
if (Count == npos) if (Count == npos)
Count = this->m_Length - Pos; Count = this->Length - Pos;
if (Pos + Count > this->m_Length) if (Pos + Count > this->Length)
Count = this->m_Length - Pos; Count = this->Length - Pos;
string ret; string ret;
ret.resize(Count); ret.resize(Count);
for (size_t i = 0; i < Count; i++) for (size_t i = 0; i < Count; i++)
ret.m_Data[i] = this->m_Data[Pos + i]; ret.Data[i] = this->Data[Pos + i];
ret.m_Data[Count] = '\0'; ret.Data[Count] = '\0';
return ret; return ret;
} }
void replace(size_t Pos, size_t Count, const char *Str) void replace(size_t Pos, size_t Count, const char *Str)
{ {
strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str); strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return; return;
if ((int64_t)Count < 0) if ((int64_t)Count < 0)
return; return;
if (Pos + Count > this->m_Length) if (Pos + Count > this->Length)
Count = this->m_Length - Pos; Count = this->Length - Pos;
int NewLength = this->m_Length - Count + strlen(Str); size_t NewLength = this->Length - Count + strlen(Str);
this->resize(NewLength); this->resize(NewLength);
for (size_t i = this->m_Length - 1; i >= Pos + strlen(Str); i--) for (size_t i = this->Length - 1; i >= Pos + strlen(Str); i--)
this->m_Data[i] = this->m_Data[i - strlen(Str) + Count]; this->Data[i] = this->Data[i - strlen(Str) + Count];
for (unsigned long i = 0; i < strlen(Str); i++) 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) void replace(size_t Pos, size_t Count, const string &Str)
{ {
strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str.m_Data); strdbg("String replace: %d, %d, \"%s\"", Pos, Count, Str.Data);
if (Pos >= this->m_Length) if (Pos >= this->Length)
return; return;
if ((int64_t)Count < 0) if ((int64_t)Count < 0)
return; return;
if (Pos + Count > this->m_Length) if (Pos + Count > this->Length)
Count = this->m_Length - Pos; Count = this->Length - Pos;
int NewLength = this->m_Length - Count + Str.m_Length; size_t NewLength = this->Length - Count + Str.Length;
this->resize(NewLength); this->resize(NewLength);
for (size_t i = this->m_Length - 1; i >= Pos + Str.m_Length; i--) for (size_t i = this->Length - 1; i >= Pos + Str.Length; i--)
this->m_Data[i] = this->m_Data[i - Str.m_Length + Count]; this->Data[i] = this->Data[i - Str.Length + Count];
for (size_t i = 0; i < Str.m_Length; i++) for (size_t i = 0; i < Str.Length; i++)
this->m_Data[Pos + i] = Str.m_Data[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 operator+(const string &Other) const
{ {
string result = *this; string result = *this;
result.concat(Other); 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; return result;
} }
@ -390,21 +390,21 @@ namespace std
{ {
string result = *this; string result = *this;
result.concat(Other); 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; return result;
} }
string &operator+=(const string &Other) string &operator+=(const string &Other)
{ {
this->concat(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; return *this;
} }
string &operator+=(const char *Other) string &operator+=(const char *Other)
{ {
this->concat(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; return *this;
} }
@ -415,120 +415,120 @@ namespace std
// { // {
// if (this != &Other) // if (this != &Other)
// { // {
// delete[] this->m_Data; // delete[] this->Data;
// this->m_Data = Other.m_Data; // this->Data = Other.Data;
// this->m_Length = Other.m_Length; // this->Length = Other.Length;
// this->m_Capacity = Other.m_Capacity; // this->Capacity = Other.Capacity;
// strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); // strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
// } // }
// return *this; // return *this;
// } // }
string &operator=(const char *Other) string &operator=(const char *Other)
{ {
this->m_Length = strlen(Other); this->Length = strlen(Other);
this->m_Capacity = this->m_Length + 1; this->Capacity = this->Length + 1;
delete[] this->m_Data; delete[] this->Data;
this->m_Data = new char[m_Capacity]; this->Data = new char[this->Capacity];
strcpy(m_Data, Other); strcpy(this->Data, Other);
strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->m_Data, this->m_Data, this->m_Length, this->m_Capacity); strdbg("String assigned: \"%s\" (data: %#lx, length: %d, capacity: %d)", this->Data, this->Data, this->Length, this->Capacity);
return *this; return *this;
} }
string &operator<<(const string &Other) string &operator<<(const string &Other)
{ {
this->concat(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; return *this;
} }
string &operator<<(const char *Other) string &operator<<(const char *Other)
{ {
this->concat(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; return *this;
} }
char &operator[](int Index) char &operator[](int Index)
{ {
strdbg("String index: %d", Index); strdbg("String index: %d", Index);
return this->m_Data[Index]; return this->Data[Index];
} }
const char &operator[](int Index) const const char &operator[](int Index) const
{ {
strdbg("String index: %d", Index); strdbg("String index: %d", Index);
return this->m_Data[Index]; return this->Data[Index];
} }
bool operator==(const string &Other) const bool operator==(const string &Other) const
{ {
strdbg("String compared: \"%s\" == \"%s\"", this->m_Data, Other.m_Data); strdbg("String compared: \"%s\" == \"%s\"", this->Data, Other.Data);
return strcmp(this->m_Data, Other.m_Data) == 0; return strcmp(this->Data, Other.Data) == 0;
} }
bool operator!=(const char *Other) const bool operator!=(const char *Other) const
{ {
strdbg("String compared: \"%s\" != \"%s\"", this->m_Data, Other); strdbg("String compared: \"%s\" != \"%s\"", this->Data, Other);
return strcmp(this->m_Data, Other) != 0; return strcmp(this->Data, Other) != 0;
} }
bool operator!=(const string &Other) const bool operator!=(const string &Other) const
{ {
strdbg("String compared: \"%s\" != \"%s\"", this->m_Data, Other.m_Data); strdbg("String compared: \"%s\" != \"%s\"", this->Data, Other.Data);
return strcmp(this->m_Data, Other.m_Data) != 0; return strcmp(this->Data, Other.Data) != 0;
} }
bool operator==(const char *Other) const bool operator==(const char *Other) const
{ {
strdbg("String compared: \"%s\" == \"%s\"", this->m_Data, Other); strdbg("String compared: \"%s\" == \"%s\"", this->Data, Other);
return strcmp(this->m_Data, Other) == 0; return strcmp(this->Data, Other) == 0;
} }
class iterator class iterator
{ {
private: private:
char *m_Pointer; char *Pointer;
public: public:
iterator(char *Pointer) : m_Pointer(Pointer) {} iterator(char *Pointer) : Pointer(Pointer) {}
iterator &operator++() iterator &operator++()
{ {
++this->m_Pointer; ++this->Pointer;
strdbg("String iterator incremented: %#lx", this->m_Pointer); strdbg("String iterator incremented: %#lx", this->Pointer);
return *this; return *this;
} }
char &operator*() char &operator*()
{ {
strdbg("String iterator dereferenced: %#lx", this->m_Pointer); strdbg("String iterator dereferenced: %#lx", this->Pointer);
return *this->m_Pointer; return *this->Pointer;
} }
bool operator!=(const iterator &Other) const bool operator!=(const iterator &Other) const
{ {
strdbg("String iterator compared: %#lx != %#lx", this->m_Pointer, Other.m_Pointer); strdbg("String iterator compared: %#lx != %#lx", this->Pointer, Other.Pointer);
return this->m_Pointer != Other.m_Pointer; return this->Pointer != Other.Pointer;
} }
bool operator==(const iterator &Other) const bool operator==(const iterator &Other) const
{ {
strdbg("String iterator compared: %#lx == %#lx", this->m_Pointer, Other.m_Pointer); strdbg("String iterator compared: %#lx == %#lx", this->Pointer, Other.Pointer);
return this->m_Pointer == Other.m_Pointer; return this->Pointer == Other.Pointer;
} }
}; };
iterator begin() iterator begin()
{ {
strdbg("String iterator begin: %#lx", this->m_Data); strdbg("String iterator begin: %#lx", this->Data);
return iterator(this->m_Data); return iterator(this->Data);
} }
iterator end() iterator end()
{ {
strdbg("String iterator end: %#lx", this->m_Data + this->m_Length); strdbg("String iterator end: %#lx", this->Data + this->Length);
return iterator(this->m_Data + this->m_Length); return iterator(this->Data + this->Length);
} }
}; };
} }

View File

@ -19,23 +19,23 @@ namespace std
private: private:
static const size_t DEFAULT_NUM_BUCKETS = 10; static const size_t DEFAULT_NUM_BUCKETS = 10;
std::vector<bucket> m_buckets; std::vector<bucket> bkts;
size_t hash(const key_type &key) const size_t hash(const key_type &key) const
{ {
std::hash<key_type> hash_function; std::hash<key_type> hash_function;
return hash_function(key) % m_buckets.size(); return hash_function(key) % this->bkts.size();
} }
public: public:
unordered_map() : m_buckets(DEFAULT_NUM_BUCKETS) {} unordered_map() : bkts(DEFAULT_NUM_BUCKETS) {}
unordered_map(size_t num_buckets) : m_buckets(num_buckets) {} unordered_map(size_t num_buckets) : bkts(num_buckets) {}
void insert(const key_value_pair &pair) void insert(const key_value_pair &pair)
{ {
size_t bucket_index = hash(pair.first); size_t bucket_index = hash(pair.first);
bucket &bucket = m_buckets[bucket_index]; bucket &bkt = this->bkts[bucket_index];
for (auto it = bucket.begin(); it != bucket.end(); ++it) for (auto it = bkt.begin(); it != bkt.end(); ++it)
{ {
if (it->first == pair.first) if (it->first == pair.first)
{ {
@ -43,14 +43,14 @@ namespace std
return; return;
} }
} }
bucket.push_back(pair); bkt.push_back(pair);
} }
bool contains(const key_type &key) const bool contains(const key_type &key) const
{ {
size_t bucket_index = hash(key); size_t bucket_index = hash(key);
const bucket &bucket = m_buckets[bucket_index]; const bucket &bkt = this->bkts[bucket_index];
for (auto it = bucket.begin(); it != bucket.end(); ++it) for (auto it = bkt.begin(); it != bkt.end(); ++it)
{ {
if (it->first == key) if (it->first == key)
{ {
@ -63,34 +63,34 @@ namespace std
iterator find(const key_type &k) iterator find(const key_type &k)
{ {
size_t bucket_index = hash(k); size_t bucket_index = hash(k);
bucket &bucket = m_buckets[bucket_index]; bucket &bkt = this->bkts[bucket_index];
for (auto it = bucket.begin(); it != bucket.end(); ++it) for (auto it = bkt.begin(); it != bkt.end(); ++it)
{ {
if (it->first == k) if (it->first == k)
return it; return it;
} }
return bucket.end(); return bkt.end();
} }
const_iterator find(const key_type &k) const const_iterator find(const key_type &k) const
{ {
size_t bucket_index = hash(k); size_t bucket_index = hash(k);
const bucket &bucket = m_buckets[bucket_index]; const bucket &bkt = this->bkts[bucket_index];
for (auto it = bucket.begin(); it != bucket.end(); ++it) for (auto it = bkt.begin(); it != bkt.end(); ++it)
{ {
if (it->first == k) if (it->first == k)
return it; 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 size() const
{ {
size_t count = 0; size_t count = 0;
for (const auto &bucket : m_buckets) foreach (const auto &bkt in this->bkts)
count += bucket.size(); count += bkt.size();
return count; return count;
} }
@ -98,14 +98,14 @@ namespace std
value_type &operator[](const key_type &key) value_type &operator[](const key_type &key)
{ {
size_t bucket_index = hash(key); size_t bucket_index = hash(key);
bucket &bucket = m_buckets[bucket_index]; bucket &bkt = this->bkts[bucket_index];
for (auto it = bucket.begin(); it != bucket.end(); ++it) for (auto it = bkt.begin(); it != bkt.end(); ++it)
{ {
if (it->first == key) if (it->first == key)
return it->second; return it->second;
} }
bucket.emplace_back(key, value_type()); bkt.emplace_back(key, value_type());
return bucket.back().second; return bkt.back().second;
} }
}; };
} }

View File

@ -52,17 +52,17 @@ namespace std
VectorBuffer[i] = Initial; VectorBuffer[i] = Initial;
} }
NIF vector(const vector<T> &vector) NIF vector(const vector<T> &v)
{ {
VectorSize = vector.VectorSize; VectorSize = v.VectorSize;
VectorCapacity = vector.VectorCapacity; VectorCapacity = v.VectorCapacity;
#ifdef DEBUG_MEM_ALLOCATION #ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR INIT: vector( <vector> )->Size: %lld", VectorSize); debug("VECTOR INIT: vector( <vector> )->Size: %lld", VectorSize);
#endif #endif
assert(VectorSize > 0); assert(VectorSize > 0);
VectorBuffer = new T[VectorSize]; VectorBuffer = new T[VectorSize];
for (size_t i = 0; i < VectorSize; i++) for (size_t i = 0; i < VectorSize; i++)
VectorBuffer[i] = vector.VectorBuffer[i]; VectorBuffer[i] = v.VectorBuffer[i];
} }
NIF ~vector() NIF ~vector()
@ -248,17 +248,17 @@ namespace std
return VectorBuffer[Index]; return VectorBuffer[Index];
} }
NIF vector<T> &operator=(const vector<T> &vector) NIF vector<T> &operator=(const vector<T> &v)
{ {
delete[] VectorBuffer; delete[] VectorBuffer;
VectorSize = vector.VectorSize; VectorSize = v.VectorSize;
VectorCapacity = vector.VectorCapacity; VectorCapacity = v.VectorCapacity;
#ifdef DEBUG_MEM_ALLOCATION #ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%lld", VectorSize); debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%lld", VectorSize);
#endif #endif
VectorBuffer = new T[VectorSize]; VectorBuffer = new T[VectorSize];
for (size_t i = 0; i < VectorSize; i++) for (size_t i = 0; i < VectorSize; i++)
VectorBuffer[i] = vector.VectorBuffer[i]; VectorBuffer[i] = v.VectorBuffer[i];
return *this; return *this;
} }
}; };

View File

@ -8,18 +8,18 @@
{ {
#define END_EXTERNC \ #define END_EXTERNC \
} }
#else #else // __cplusplus
#define EXTERNC #define EXTERNC
#define START_EXTERNC #define START_EXTERNC
#define END_EXTERNC #define END_EXTERNC
#endif #endif // __cplusplus
#ifdef __cplusplus #ifdef __cplusplus
#define NULL 0 #define NULL 0
#else #else // __cplusplus
#define NULL ((void *)0) #define NULL ((void *)0)
#define bool _Bool #define bool _Bool
#endif #endif // __cplusplus
#define asm __asm__ #define asm __asm__
#define asmv __asm__ volatile #define asmv __asm__ volatile
@ -30,7 +30,12 @@
#ifdef __cplusplus #ifdef __cplusplus
#define foreach for #define foreach for
#define in : #define in :
#endif
#define r_cst(t, v) reinterpret_cast<t>(v)
#define c_cst(t, v) const_cast<t>(v)
#define s_cst(t, v) static_cast<t>(v)
#define d_cst(t, v) dynamic_cast<t>(v)
#endif // __cplusplus
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
#define CONCAT(x, y) x##y #define CONCAT(x, y) x##y
@ -231,11 +236,32 @@ typedef intptr_t ssize_t;
: "memory"); : "memory");
#endif #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 b4(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4)
#define b8(x) ((x)&0xFF) #define b8(x) ((x)&0xFF)
#define b16(x) __builtin_bswap16(x) #define b16(x) __builtin_bswap16(x)
#define b32(x) __builtin_bswap32(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) #define b64(x) __builtin_bswap64(x)
/* https://gcc.gnu.org/onlinedocs/gcc-9.5.0/gnat_ugn/Optimization-Levels.html */ /* https://gcc.gnu.org/onlinedocs/gcc-9.5.0/gnat_ugn/Optimization-Levels.html */