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