Skip to content

Commit

Permalink
Prohibit old-style casts
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 14, 2019
1 parent 5b482e1 commit 0b0a079
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion cmake/toolchain.cmake
Expand Up @@ -39,7 +39,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Os")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -fpic -fpie")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wproperty-attribute-mismatch")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual -Wcast-align -Winline")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wold-style-cast -Wcast-qual -Wcast-align -Winline")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)

Expand Down
6 changes: 3 additions & 3 deletions src/kernlib/display.cpp
Expand Up @@ -84,7 +84,7 @@ class FramebufferDisplay: public Display {
} else if (c == '\t') {
offset += 8 - ((offset % charWidth()) % 8);
} else {
const uint8_t *fontsym = fb_font_8x16 + ((size_t)c * 16);
const uint8_t *fontsym = fb_font_8x16 + (size_t(c) * 16);
size_t offsetX = offset % charWidth();
size_t offsetY = offset / charWidth();
size_t pb = pixelBytes();
Expand Down Expand Up @@ -123,8 +123,8 @@ class FramebufferDisplay: public Display {
PixelFormat pixelFormat):
framebuffer(framebuffer), width(width), height(height),
pixelFormat(pixelFormat), offset(0) {
for (uintptr_t ptr = (uintptr_t)framebuffer;
ptr < (uintptr_t)framebuffer + bufferSize() + 0xFFF;
for (uintptr_t ptr = uintptr_t(framebuffer);
ptr < uintptr_t(framebuffer) + bufferSize() + 0xFFF;
ptr += 0x1000) {
Pagetable::map(reinterpret_cast<void*>(ptr));
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/include/kernlib/cpu.hpp
Expand Up @@ -7,7 +7,7 @@
inline static uint64_t rdtsc() {
uint32_t eax, edx;
asm volatile("rdtsc":"=a"(eax), "=d"(edx));
return (((uint64_t)edx << 32) | eax);
return ((uint64_t(edx) << 32) | eax);
}

inline static uint64_t __attribute__((always_inline)) EnterCritical() {
Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/include/list.hpp
Expand Up @@ -15,7 +15,7 @@ class List {

Item& insert() {
if (count == capacity) {
capacity += MAX(256 / sizeof(Item), (size_t)1);
capacity += MAX(256 / sizeof(Item), size_t(1));
items = static_cast<Item*>(Heap::realloc(items, sizeof(Item) * capacity));
}
return items[count++];
Expand Down
4 changes: 2 additions & 2 deletions src/kernlib/printf.cpp
Expand Up @@ -10,7 +10,7 @@ static inline char *longlong_to_string(
int pos = len;
char table_start = fl_caps ? 'A' : 'a';
bool negative = 0;
if (fl_signed && (int64_t)n < 0) {
if (fl_signed && int64_t(n) < 0) {
negative = 1;
n = -n;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
case 'p':
flags.fl_altfmt = 1;
numsig = 0;
numval = (uintptr_t)va_arg(ap, void*);
numval = uintptr_t(va_arg(ap, void*));
numbase = 16;
goto out_num;
case 'x':
Expand Down
2 changes: 1 addition & 1 deletion src/kernlib/std.cpp
Expand Up @@ -12,7 +12,7 @@ extern "C" {

size_t strlen(const char* c, size_t limit) {
const char *e = c;
while (((size_t)(e - c) < limit) && (*e++) != 0) {}
while ((size_t(e - c) < limit) && (*e++) != 0) {}
return e - c - 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/kernlib/stream.cpp
Expand Up @@ -31,9 +31,9 @@ size_t MemoryStream::read(void* dest, size_t size) {
Stream* MemoryStream::substream(int64_t offset, size_t limit) {
if (offset == -1)
offset = this->offset;
if ((limit == (size_t)-1) || (limit > this->limit - offset))
if ((limit == size_t(-1)) || (limit > this->limit - offset))
limit = this->limit - offset;
return new MemoryStream(memory + (size_t)offset, limit);
return new MemoryStream(memory + size_t(offset), limit);
}
char* MemoryStream::readstr() {
size_t len = strlen(memory + offset, limit - offset);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/cpu.cpp
Expand Up @@ -105,7 +105,7 @@ uint64_t CPU::getFeatures() {
asm volatile("cpuid" :
"=a"(eax), "=c"(ecx), "=d"(edx) :
"a"(eax) :"ebx");
features = ((uint64_t)edx << 32) | (uint64_t)ecx;
features = (uint64_t(edx) << 32) | uint64_t(ecx);
struct CPUID_INFO {
uint32_t stepping:3;
uint32_t model:4;
Expand Down Expand Up @@ -133,7 +133,7 @@ uint64_t CPU::getFeaturesExt() {
asm volatile("cpuid" :
"=a"(eax), "=b"(ebx), "=c"(ecx) :
"a"(eax), "c"(ecx): "edx");
features_ext = (uint64_t)ebx | ((uint64_t)ecx << 32);
features_ext = uint64_t(ebx) | (uint64_t(ecx) << 32);
}
return features_ext;
}
Expand All @@ -144,7 +144,7 @@ uint64_t CPU::getExtFeatures() {
asm volatile("cpuid" :
"=a"(eax), "=c"(ecx), "=d"(edx) :
"a"(eax): "ebx");
ext_features = (uint64_t)edx | ((uint64_t)ecx << 32);
ext_features = uint64_t(edx) | (uint64_t(ecx) << 32);
}
return ext_features;
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform/heap.cpp
Expand Up @@ -46,7 +46,7 @@ void* Heap::alloc(size_t size, size_t align) {
uintptr_t page = 0xFFFFFFFFFFFFFFFF;
while (pages) {
for (size_t i = 0; i < 511; i++) {
uintptr_t paddr = (uintptr_t)pages->pages[i];
uintptr_t paddr = uintptr_t(pages->pages[i]);
if (paddr == 0) continue;
if (page > paddr && paddr >= ptr) {
page = paddr;
Expand Down Expand Up @@ -79,15 +79,15 @@ void* Heap::alloc(size_t size, size_t align) {
pages = heap_pages;
while (pages) {
for (size_t i = 0; i < 511; i++) {
if ((uintptr_t)pages->pages[i] == pg) goto next_page;
if (uintptr_t(pages->pages[i]) == pg) goto next_page;
}
pages = pages->next;
}
pages = heap_pages;
while (pages) {
for (size_t i = 0; i < 511; i++) {
if ((uintptr_t)pages->pages[i] > ptr) {
ptr = (uintptr_t)pages->pages[i];
if (uintptr_t(pages->pages[i]) > ptr) {
ptr = uintptr_t(pages->pages[i]);
goto check_ptr;
}
}
Expand All @@ -100,7 +100,7 @@ void* Heap::alloc(size_t size, size_t align) {
table = allocs;
while (table) {
for (size_t i = 0; i < 255; i++) {
uintptr_t alloc_base = (uintptr_t)table->allocs[i].addr;
uintptr_t alloc_base = uintptr_t(table->allocs[i].addr);
uintptr_t alloc_top = alloc_base + table->allocs[i].size;
if (ptr >= alloc_top || ptr_top < alloc_base) continue;
ptr = alloc_top;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/include/interrupts.hpp
Expand Up @@ -86,8 +86,8 @@ struct GDT_ENT {
bool granularity :1;
uint64_t base_high :8;

uint64_t getBase() { return ((uint64_t)base_high << 24) | base_low; }
uint64_t getLimit() { return ((uint64_t)seg_lim_high << 16) | seg_lim_low; }
uint64_t getBase() { return (uint64_t(base_high) << 24) | base_low; }
uint64_t getLimit() { return (uint64_t(seg_lim_high) << 16) | seg_lim_low; }

void setBase(uint64_t base) {
base_low = base & 0xFFFFFF;
Expand Down Expand Up @@ -116,7 +116,7 @@ struct GDT_SYS_ENT {
uint64_t base_high :32;
uint32_t rsvd;

uint64_t getBase() { return ((uintptr_t)base_high << 32) | ent.getBase(); }
uint64_t getBase() { return (uintptr_t(base_high) << 32) | ent.getBase(); }

void setBase(uint64_t base) {
ent.setBase(base);
Expand Down
14 changes: 7 additions & 7 deletions src/platform/include/pagetable.hpp
Expand Up @@ -31,10 +31,10 @@ struct PTE {
flags(flags), rsvd(0), avl(avl), _ptr(ptr >> 12) {}
PTE(uintptr_t ptr, uint8_t flags):
flags(flags), rsvd(0), avl(0), _ptr(ptr >> 12) {}
PTE(void *ptr, uint8_t avl, uint8_t flags):
flags(flags), rsvd(0), avl(avl), _ptr((uintptr_t)ptr >> 12) {}
PTE(void *ptr, uint8_t flags):
flags(flags), rsvd(0), avl(0), _ptr((uintptr_t)ptr >> 12) {}
PTE(const void *ptr, uint8_t avl, uint8_t flags):
flags(flags), rsvd(0), avl(avl), _ptr(uintptr_t(ptr) >> 12) {}
PTE(const void *ptr, uint8_t flags):
flags(flags), rsvd(0), avl(0), _ptr(uintptr_t(ptr) >> 12) {}

static PTE* find(uintptr_t ptr, PTE *pagetable) {
uint16_t ptx = (ptr >> (12 + 9 + 9 + 9)) & 0x1FF;
Expand All @@ -52,7 +52,7 @@ struct PTE {
return &page[pml4x];
}
static PTE* find(void *addr, PTE *pagetable) {
return find((uintptr_t)addr, pagetable);
return find(uintptr_t(addr), pagetable);
}
} PACKED;

Expand All @@ -71,9 +71,9 @@ class Pagetable {

inline static void MmioWrite32(void *p, uint32_t data) {
Pagetable::map(p);
*(volatile uint32_t *)(p) = data;
*reinterpret_cast<volatile uint32_t *>(p) = data;
}
inline static uint32_t MmioRead32(const void *p) {
Pagetable::map(p);
return *(const volatile uint32_t *)(p);
return *reinterpret_cast<const volatile uint32_t *>(p);
}
18 changes: 9 additions & 9 deletions src/platform/interrupts.cpp
Expand Up @@ -218,8 +218,8 @@ uint64_t __attribute__((sysv_abi)) Interrupts::handle(
cpuid, *pagetable,

info->rip,
(uint16_t)(info->cs & 0xFFF8), info->rflags, info->rsp,
(uint16_t)(info->ss & 0xFFF8), (uint8_t)(info->cs & 7),
uint16_t(info->cs & 0xFFF8), info->rflags, info->rsp,
uint16_t(info->ss & 0xFFF8), uint8_t(info->cs & 7),

regs->rax,
regs->rcx, regs->rdx, regs->rbx, regs->rbp, regs->rsi, regs->rdi,
Expand All @@ -246,9 +246,9 @@ uint64_t __attribute__((sysv_abi)) Interrupts::handle(
cb_regs.rbx, cb_regs.rdx, cb_regs.rcx, cb_regs.rax,
};
*info = {
cb_regs.rip, (uint64_t)(cb_regs.cs | cb_regs.dpl),
cb_regs.rip, uint64_t(cb_regs.cs | cb_regs.dpl),
cb_regs.rflags | 0x202,
cb_regs.rsp, (uint64_t)(cb_regs.ss | cb_regs.dpl)
cb_regs.rsp, uint64_t(cb_regs.ss | cb_regs.dpl)
};
*pagetable = cb_regs.cr3;
return has_code ? 8 : 0;
Expand Down Expand Up @@ -281,15 +281,15 @@ void Interrupts::init() {
gdt->ents[4] = GDT_ENT(0, 0xFFFFFFFFFFFFFFFF, 0x2, 3, 1, 1, 0, 0, 1, 1);
for (uint32_t idx = 0; idx < ncpu; idx++) {
void *stack = Pagetable::alloc();
uintptr_t stack_ptr = (uintptr_t)stack + 0x1000;
uintptr_t stack_ptr = uintptr_t(stack) + 0x1000;
Memory::zero(&tss[idx], sizeof(tss[idx]));
tss[idx].ist[0] = stack_ptr;
gdt->sys_ents[idx] = GDT_SYS_ENT(
(uintptr_t)&tss[idx], sizeof(TSS64_ENT),
uintptr_t(&tss[idx]), sizeof(TSS64_ENT),
0x9, 0, 0, 1, 0, 1, 0, 0);
}

DTREG gdtreg = { (uint16_t)(GDT::size(ncpu) -1), &gdt->ents[0] };
DTREG gdtreg = { uint16_t(GDT::size(ncpu) -1), &gdt->ents[0] };

asm volatile(
"mov %%rsp, %%rcx;"
Expand Down Expand Up @@ -320,11 +320,11 @@ void Interrupts::init() {
::"a"(lapic_eoi)
);
for (int i = 0; i < 256; i++) {
uintptr_t jmp_from = (uintptr_t)&(handlers[i].reljmp);
uintptr_t jmp_from = uintptr_t(&(handlers[i].reljmp));
uintptr_t diff = addr - jmp_from - 5;
handlers[i] = int_handler(i, diff);

uintptr_t hptr = (uintptr_t)(&handlers[i]);
uintptr_t hptr = uintptr_t(&handlers[i]);
idt[i] = INTERRUPT64(hptr, 8, 1, 0xE, 0, true);
}
callbacks = new List<intcb*>[256]();
Expand Down
36 changes: 18 additions & 18 deletions src/platform/pagetable.cpp
Expand Up @@ -18,7 +18,7 @@ static void fillPages(uintptr_t low, uintptr_t top, PTE *pagetable) {
}

static inline void fillPages(void *low, void *top, PTE *pagetable) {
fillPages((uintptr_t)low, (uintptr_t)top, pagetable);
fillPages(uintptr_t(low), uintptr_t(top), pagetable);
}

static void *efiAllocatePage(uintptr_t min, const EFI_SYSTEM_TABLE *ST) {
Expand All @@ -34,9 +34,9 @@ static void *efiAllocatePage(uintptr_t min, const EFI_SYSTEM_TABLE *ST) {
ST->BootServices->GetMemoryMap(&mapSize, map, &mapKey, &entSize, &entVer);
for (ent = map;
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)map + mapSize);
uintptr_t(map) + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)ent + entSize)) {
uintptr_t(ent) + entSize)) {
if (ent->Type != EFI_MEMORY_TYPE_CONVENTIONAL) continue;
if (ent->PhysicalStart + ent->NumberOfPages * 0x1000 <= min) continue;
ptr = reinterpret_cast<void*>(MAX(min, ent->PhysicalStart));
Expand All @@ -51,7 +51,7 @@ static void *efiAllocatePage(uintptr_t min, const EFI_SYSTEM_TABLE *ST) {

static void efiMapPage(PTE *pagetable, const void *page,
const EFI_SYSTEM_TABLE *ST) {
uintptr_t ptr = (uintptr_t)page, min = (uintptr_t)pagetable;
uintptr_t ptr = uintptr_t(page), min = uintptr_t(pagetable);
uint64_t ptx = (ptr >> (12 + 9*3)) & 0x1FF;
uint64_t pdx = (ptr >> (12 + 9*2)) & 0x1FF;
uint64_t pdpx = (ptr >> (12 + 9)) & 0x1FF;
Expand All @@ -73,7 +73,7 @@ static void efiMapPage(PTE *pagetable, const void *page,
efiMapPage(pagetable, pdpe->getPtr(), ST);
}
PTE *pml4e = pdpe->getPTE() + pml4x;
*pml4e = PTE((uintptr_t)page, 3);
*pml4e = PTE(page, 3);
}

void Pagetable::init() {
Expand Down Expand Up @@ -117,9 +117,9 @@ void Pagetable::init() {
ST->BootServices->GetMemoryMap(&mapSize, map, &mapKey, &entSize, &entVer);
for (ent = map;
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)map + mapSize);
uintptr_t(map) + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)ent + entSize)) {
uintptr_t(ent) + entSize)) {
if (ent->Type == EFI_MEMORY_TYPE_CONVENTIONAL) continue;
for (uintptr_t ptr = ent->PhysicalStart;
ptr < ent->PhysicalStart + ent->NumberOfPages * 0x1000;
Expand All @@ -130,7 +130,7 @@ void Pagetable::init() {
ST->BootServices->ExitBootServices(EFI::getImageHandle(), mapKey);
asm volatile("mov %q0, %%cr3"::"r"(pagetable));
} else {
PTE::find((uintptr_t)0, pagetable)->present = 0;
PTE::find(nullptr, pagetable)->present = 0;
fillPages(0x1000, 0x3FFFF000, pagetable);

static const size_t pdpe_num = 64;
Expand Down Expand Up @@ -168,17 +168,17 @@ void Pagetable::init() {
if (multiboot) {
if (multiboot->flags & MB_FLAG_CMDLINE) {
if (multiboot->pcmdline < 0x80000)
multiboot->pcmdline += (uintptr_t)bss_top;
multiboot->pcmdline += uintptr_t(bss_top);
map(reinterpret_cast<void*>(multiboot->pcmdline));
}

if (multiboot->flags & MB_FLAG_MODS) {
if (multiboot->pmods_addr < 0x80000)
multiboot->pmods_addr += (uintptr_t)bss_top;
multiboot->pmods_addr += uintptr_t(bss_top);

uintptr_t low = (uintptr_t)multiboot->pmods_addr & 0xFFFFFFFFFFFFF000;
uintptr_t low = uintptr_t(multiboot->pmods_addr) & 0xFFFFFFFFFFFFF000;
uintptr_t top = ALIGN(
(uintptr_t)multiboot->pmods_addr +
uintptr_t(multiboot->pmods_addr) +
multiboot->mods_count * sizeof(MULTIBOOT_MODULE),
0x1000);
for (uintptr_t addr = low; addr < top; addr += 0x1000)
Expand All @@ -196,7 +196,7 @@ void Pagetable::init() {

if (multiboot->flags & MB_FLAG_MEMMAP) {
if (multiboot->pmmap_addr < 0x80000)
multiboot->pmmap_addr += (uintptr_t)bss_top;
multiboot->pmmap_addr += uintptr_t(bss_top);

const char *mmap = reinterpret_cast<const char*>(multiboot->pmmap_addr);
const char *mmap_top = mmap + multiboot->mmap_length;
Expand All @@ -205,8 +205,8 @@ void Pagetable::init() {
reinterpret_cast<const MULTIBOOT_MMAP_ENT*>(mmap);
map(ent);
if (ent->type != 1) {
uintptr_t low = (uintptr_t)ent->base & 0xFFFFFFFFFFFFF000;
uintptr_t top = ALIGN((uintptr_t)ent->base + ent->length, 0x1000);
uintptr_t low = uintptr_t(ent->base) & 0xFFFFFFFFFFFFF000;
uintptr_t top = ALIGN(uintptr_t(ent->base) + ent->length, 0x1000);
for (uintptr_t addr = low; addr < top; addr += 0x1000)
map(reinterpret_cast<void*>(addr));
}
Expand All @@ -219,7 +219,7 @@ void Pagetable::init() {
void* Pagetable::map(const void* mem) {
uint64_t t = EnterCritical();
page_mutex.lock();
uintptr_t i = (uintptr_t)(mem) >> 12;
uintptr_t i = uintptr_t(mem) >> 12;
void *addr = reinterpret_cast<void*>(i << 12);
PTE pte = pagetable[(i >> 27) & 0x1FF];
if (!pte.present) {
Expand Down Expand Up @@ -298,8 +298,8 @@ void Pagetable::free(void* page) {
if ((pdata != 0) && pdata->present) {
pdata->present = 0;
void *addr = pdata->getPtr();
if (((uintptr_t)addr >> 12) < last_page)
last_page = (uintptr_t)addr >> 12;
if ((uintptr_t(addr) >> 12) < last_page)
last_page = uintptr_t(addr) >> 12;
}
page_mutex.release();
LeaveCritical(t);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/smp.cpp
Expand Up @@ -57,7 +57,7 @@ void SMP::init() {
info = reinterpret_cast<StartupInfo*>(startupCode + ALIGN(smp_init_size, 8));

Memory::copy(startupCode, smp_init, smp_init_size);
char smp_init_vector = (((uintptr_t)startupCode) >> 12) & 0xFF;
char smp_init_vector = (uintptr_t(startupCode) >> 12) & 0xFF;

info->lapicAddr = acpi->getLapicAddr();
info->cpuids = new uint64_t[cpuCount]();
Expand Down

0 comments on commit 0b0a079

Please sign in to comment.