...
 
Commits (2)
......@@ -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)
......
......@@ -299,7 +299,7 @@ struct EFI_CONFIGURATION_TABLE {
const void *VendorTable;
};
static inline bool operator ==(const EFI_GUID lhs, const EFI_GUID rhs) {
static inline bool operator ==(const EFI_GUID &lhs, const EFI_GUID &rhs) {
return
lhs.Data1 == rhs.Data1 &&
lhs.Data2 == rhs.Data2 &&
......
......@@ -21,6 +21,7 @@ class ConsoleDisplay: public Display {
do {
*(display++) = ' ';
*(display++) = 0x0F;
pos += 2;
} while (pos % 8 != 0);
} else {
*(display++) = c;
......@@ -67,8 +68,7 @@ class FramebufferDisplay: public Display {
size_t pixelBytes() {
switch (pixelFormat) {
case PixelFormatRGBX: return 4;
case PixelFormatBGRX: return 4;
case PixelFormatRGBX: case PixelFormatBGRX: return 4;
}
return 0;
}
......@@ -84,17 +84,17 @@ 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();
char *fbptr = static_cast<char*>(framebuffer)
uint8_t *fbptr = static_cast<uint8_t*>(framebuffer)
+ offsetY * 16 * width * pb
+ offsetX * 8 * pb;
for (size_t y = 0; y < 16; y++) {
char *line = fbptr + y * width * pb;
uint8_t *line = fbptr + y * width * pb;
uint8_t fontline = fontsym[y];
for (size_t x = 0; x < 8; x++) {
if (fontline & (1 << (8 - x))) {
......@@ -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));
}
......
......@@ -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() {
......
......@@ -15,13 +15,13 @@ 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++];
}
void add(const Item item) { insert() = item; }
void add(const Item &item) { insert() = item; }
size_t getCount() { return count; }
......
......@@ -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;
}
......@@ -243,7 +243,7 @@ parse_size:
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':
......
......@@ -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;
}
......@@ -38,7 +38,7 @@ void print_stacktrace(uintptr_t base) {
printf("STACK TRACE:");
const struct stackframe *frame;
if (base) {
frame = (struct stackframe*)base;
frame = reinterpret_cast<struct stackframe*>(base);
} else {
asm volatile("mov %%rbp, %q0":"=r"(frame)::);
}
......
......@@ -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);
......
......@@ -84,7 +84,7 @@ ACPI::ACPI() {
LapicOut(LAPIC_TMRINITCNT, -1);
while ((inportb(0x61) & 0x20) == (t & 0x20)) {}
LapicOut(LAPIC_LVT_TMR, LAPIC_DISABLE);
busfreq = ((-1 - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
busfreq = (static_cast<uint64_t>(-1 - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
}
void ACPI::ParseDT(const AcpiHeader *header) {
Pagetable::map(header);
......@@ -119,7 +119,7 @@ void ACPI::ParseXsdt(const AcpiHeader *xsdt) {
void ACPI::ParseApic(const AcpiMadt *madt) {
Pagetable::map(madt);
localApicAddr = reinterpret_cast<char*>(madt->localApicAddr);
localApicAddr = reinterpret_cast<char*>(uintptr_t(madt->localApicAddr));
Pagetable::map(localApicAddr);
const uint8_t *p = reinterpret_cast<const uint8_t*>(madt + 1);
......@@ -137,7 +137,7 @@ void ACPI::ParseApic(const AcpiMadt *madt) {
acpiCpuIds[acpiCpuCount++] = s->apicId;
} else if (type == 1) {
const ApicIoApic *s = reinterpret_cast<const ApicIoApic*>(p);
ioApicAddr = reinterpret_cast<char*>(s->ioApicAddress);
ioApicAddr = reinterpret_cast<char*>(uintptr_t(s->ioApicAddress));
Pagetable::map(ioApicAddr);
} else if (type == 2) {
const ApicInterruptOverride *s =
......@@ -171,7 +171,7 @@ bool ACPI::ParseRsdp(const void *ptr) {
Pagetable::map(rsdtPtr + 1);
uint32_t rsdtAddr = *rsdtPtr;
if (revision == 0) {
ParseRsdt(reinterpret_cast<AcpiHeader*>(rsdtAddr));
ParseRsdt(reinterpret_cast<AcpiHeader*>(uintptr_t(rsdtAddr)));
} else if (revision == 2) {
Pagetable::map(xsdtPtr);
Pagetable::map(xsdtPtr + 1);
......@@ -180,7 +180,7 @@ bool ACPI::ParseRsdp(const void *ptr) {
if (xsdtAddr)
ParseXsdt(reinterpret_cast<AcpiHeader*>(xsdtAddr));
else
ParseRsdt(reinterpret_cast<AcpiHeader*>(rsdtAddr));
ParseRsdt(reinterpret_cast<AcpiHeader*>(uintptr_t(rsdtAddr)));
}
return true;
......
......@@ -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;
......@@ -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;
}
......@@ -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;
}
......@@ -172,19 +172,19 @@ char* CPU::getFeaturesStr() {
char *end = buf;
for (int i = 0; i < 64; i++) {
if (((f & (1 << i)) != 0) && CPUID_FEAT_STR[i][0]) {
if (((f & (1ll << i)) != 0) && CPUID_FEAT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_FEAT_STR[i]);
}
}
for (int i = 0; i < 64; i++) {
if (((ef & (1 << i)) != 0) && CPUID_EXT_FEAT_STR[i][0]) {
if (((ef & (1ll << i)) != 0) && CPUID_EXT_FEAT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_EXT_FEAT_STR[i]);
}
}
for (int i = 0; i < 64; i++) {
if (((fe & (1 << i)) != 0) && CPUID_FEAT_EXT_STR[i][0]) {
if (((fe & (1ll << i)) != 0) && CPUID_FEAT_EXT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_FEAT_EXT_STR[i]);
}
}
......
......@@ -46,7 +46,7 @@ find_page:
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;
......@@ -79,15 +79,15 @@ check_ptr:
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;
}
}
......@@ -100,7 +100,7 @@ next_page:
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;
......
......@@ -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;
......@@ -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);
......
......@@ -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;
......@@ -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;
......@@ -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);
}
......@@ -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,
......@@ -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;
......@@ -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;"
......@@ -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]();
......
......@@ -10,15 +10,15 @@ PTE *Pagetable::pagetable;
Mutex Pagetable::page_mutex;
uintptr_t Pagetable::last_page = 1;
static void fillPages(uintptr_t low, uintptr_t top, PTE *pagetable) {
static void fillPages(uintptr_t low, uintptr_t top, PTE *pagetable, uint8_t flags = 3) {
low &= 0xFFFFFFFFFFFFF000;
top = ALIGN(top, 0x1000);
for (; low < top; low += 0x1000)
*PTE::find(low, pagetable) = PTE(low, 3);
*PTE::find(low, pagetable) = PTE(low, flags);
}
static inline void fillPages(void *low, void *top, PTE *pagetable) {
fillPages((uintptr_t)low, (uintptr_t)top, pagetable);
static inline void fillPages(void *low, void *top, PTE *pagetable, uint8_t flags = 3) {
fillPages(uintptr_t(low), uintptr_t(top), pagetable, flags);
}
static void *efiAllocatePage(uintptr_t min, const EFI_SYSTEM_TABLE *ST) {
......@@ -33,13 +33,11 @@ static void *efiAllocatePage(uintptr_t min, const EFI_SYSTEM_TABLE *ST) {
map = static_cast<EFI_MEMORY_DESCRIPTOR*>(alloca(mapSize));
ST->BootServices->GetMemoryMap(&mapSize, map, &mapKey, &entSize, &entVer);
for (ent = map;
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)map + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)ent + entSize)) {
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(uintptr_t(map) + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(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));
ptr = reinterpret_cast<void*>(MAX(min, uintptr_t(ent->PhysicalStart)));
break;
}
ST->BootServices->AllocatePages(
......@@ -50,8 +48,8 @@ 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;
const EFI_SYSTEM_TABLE *ST, uint8_t flags = 3) {
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;
......@@ -73,7 +71,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, flags);
}
void Pagetable::init() {
......@@ -116,10 +114,8 @@ void Pagetable::init() {
map = static_cast<EFI_MEMORY_DESCRIPTOR*>(alloca(mapSize));
ST->BootServices->GetMemoryMap(&mapSize, map, &mapKey, &entSize, &entVer);
for (ent = map;
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)map + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(
(uintptr_t)ent + entSize)) {
ent < reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(uintptr_t(map) + mapSize);
ent = reinterpret_cast<EFI_MEMORY_DESCRIPTOR*>(uintptr_t(ent) + entSize)) {
if (ent->Type == EFI_MEMORY_TYPE_CONVENTIONAL) continue;
for (uintptr_t ptr = ent->PhysicalStart;
ptr < ent->PhysicalStart + ent->NumberOfPages * 0x1000;
......@@ -130,7 +126,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;
......@@ -168,24 +164,24 @@ void Pagetable::init() {
if (multiboot) {
if (multiboot->flags & MB_FLAG_CMDLINE) {
if (multiboot->pcmdline < 0x80000)
multiboot->pcmdline += (uintptr_t)bss_top;
map(reinterpret_cast<void*>(multiboot->pcmdline));
multiboot->pcmdline += uintptr_t(bss_top);
map(reinterpret_cast<void*>(uintptr_t(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)
map(reinterpret_cast<void*>(addr));
const MULTIBOOT_MODULE *mods =
reinterpret_cast<MULTIBOOT_MODULE*>(multiboot->pmods_addr);
reinterpret_cast<MULTIBOOT_MODULE*>(uintptr_t(multiboot->pmods_addr));
for (uint32_t i = 0; i < multiboot->mods_count; i++) {
uintptr_t low = mods[i].start;
uintptr_t top = ALIGN(mods[i].end, 0x1000);
......@@ -196,17 +192,17 @@ 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 = reinterpret_cast<const char*>(uintptr_t(multiboot->pmmap_addr));
const char *mmap_top = mmap + multiboot->mmap_length;
while (mmap < mmap_top) {
const MULTIBOOT_MMAP_ENT *ent =
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));
}
......@@ -219,7 +215,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) {
......@@ -298,8 +294,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);
......
......@@ -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]();
......
......@@ -47,7 +47,7 @@ static uint64_t syscall_index(uint64_t hash) {
uint64_t Syscall::callByName(const char *name) {
uint64_t hash = syscall_hash(name);
if (syscall_index(hash) == (uint64_t)-1) return 0;
if (syscall_index(hash) == uint64_t(-1)) return 0;
return hash;
}
......@@ -132,8 +132,8 @@ void Syscall::setup() {
"mov %%cr3, %%rax; mov %%rax, 2 + _wrapper_mov_cr3(%%rip)":::"%rax"
);
wrmsr(MSR_STAR,
((uint64_t)USER_CS) << 48 |
((uint64_t)KERNEL_CS) << 32);
wrmsr(MSR_LSTAR, (uintptr_t)wrapper);
uint64_t(USER_CS) << 48 |
uint64_t(KERNEL_CS) << 32);
wrmsr(MSR_LSTAR, uintptr_t(wrapper));
wrmsr(MSR_EFER, rdmsr(MSR_EFER) | MSR_EFER_SCE);
}
......@@ -12,5 +12,5 @@ static inline void wrmsr(uint32_t msr_id, uint64_t msr_value) {
static inline uint64_t rdmsr(uint32_t msr_id) {
uint32_t msr_hi, msr_lo;
asm volatile("rdmsr":"=A"(msr_lo), "=d"(msr_hi):"c"(msr_id));
return ((uint64_t)msr_hi << 32) | (uint64_t)msr_lo;
return (uint64_t(msr_hi) << 32) | uint64_t(msr_lo);
}
......@@ -85,10 +85,10 @@ void ModuleManager::parseInitRD() {
MULTIBOOT_PAYLOAD *multiboot = Multiboot::getPayload();
if (!multiboot || (multiboot->flags & MB_FLAG_MODS) == 0) return;
const MULTIBOOT_MODULE *mods =
reinterpret_cast<const MULTIBOOT_MODULE*>(multiboot->pmods_addr);
reinterpret_cast<const MULTIBOOT_MODULE*>(uintptr_t(multiboot->pmods_addr));
for (uint32_t i = 0; i < multiboot->mods_count; i++) {
const char *base = reinterpret_cast<const char*>(mods[i].start);
const char *top = reinterpret_cast<const char*>(mods[i].end);
const char *base = reinterpret_cast<const char*>(uintptr_t(mods[i].start));
const char *top = reinterpret_cast<const char*>(uintptr_t(mods[i].end));
size_t length = top - base;
MemoryStream ms(base, length);
loadStream(&ms, 1);
......
......@@ -16,29 +16,29 @@ Process::Process() {
Process::~Process() {
if (pagetable != 0) {
PTE addr;
for (uint16_t ptx = 0; ptx < 512; ptx++) {
for (uintptr_t ptx = 0; ptx < 512; ptx++) {
addr = pagetable[ptx];
if (!addr.present)
continue;
PTE *ppde = addr.getPTE();
for (uint16_t pdx = 0; pdx < 512; pdx++) {
for (uintptr_t pdx = 0; pdx < 512; pdx++) {
addr = ppde[pdx];
if (!addr.present)
continue;
PTE *pppde = addr.getPTE();
for (uint16_t pdpx = 0; pdpx < 512; pdpx++) {
for (uintptr_t pdpx = 0; pdpx < 512; pdpx++) {
addr = pppde[pdpx];
if (!addr.present)
continue;
PTE *ppml4e = addr.getPTE();
for (uint16_t pml4x = 0; pml4x < 512; pml4x++) {
for (uintptr_t pml4x = 0; pml4x < 512; pml4x++) {
addr = ppml4e[pml4x];
if (!addr.present)
continue;
void *page = addr.getPtr();
if ((uintptr_t)page == (((uintptr_t)ptx << (12 + 9 + 9 + 9))
| ((uintptr_t)pdx << (12 + 9 + 9))
| ((uintptr_t)pdpx << (12 + 9)) | ((uintptr_t)pml4x << (12))))
if (uintptr_t(page) == ((ptx << (12 + 9 + 9 + 9))
| (pdx << (12 + 9 + 9))
| (pdpx << (12 + 9)) | (pml4x << (12))))
continue;
Pagetable::free(page);
}
......@@ -66,7 +66,7 @@ void Process::addPage(uintptr_t vaddr, void* paddr, uint8_t flags) {
uint16_t pml4x = (vaddr >> (12)) & 0x1FF;
if (pagetable == 0) {
pagetable = static_cast<PTE*>(Pagetable::alloc());
addPage((uintptr_t)pagetable, pagetable, 5);
addPage(uintptr_t(pagetable), pagetable, 5);
}
PTE pte = pagetable[ptx];
if (!pte.present) {
......@@ -166,7 +166,7 @@ void Process::writeData(uintptr_t address, void* src, size_t size) {
char *ptr = static_cast<char*>(src);
while (size > 0) {
void *dest = getPhysicalAddress(address);
size_t limit = 0x1000 - ((uintptr_t)dest & 0xFFF);
size_t limit = 0x1000 - (uintptr_t(dest) & 0xFFF);
size_t count = MIN(size, limit);
Memory::copy(dest, ptr, count);
size -= count;
......@@ -178,7 +178,7 @@ void Process::readData(void* dst, uintptr_t address, size_t size) {
char *ptr = static_cast<char*>(dst);
while (size > 0) {
void *src = getPhysicalAddress(address);
size_t limit = 0x1000 - ((uintptr_t)src & 0xFFF);
size_t limit = 0x1000 - (uintptr_t(src) & 0xFFF);
size_t count = MIN(size, limit);
Memory::copy(ptr, src, count);
size -= count;
......@@ -189,7 +189,7 @@ void Process::readData(void* dst, uintptr_t address, size_t size) {
char *Process::readString(uintptr_t address) {
size_t length = 0;
const char *src = static_cast<const char*>(getPhysicalAddress(address));
size_t limit = 0x1000 - ((uintptr_t)src & 0xFFF);
size_t limit = 0x1000 - (uintptr_t(src) & 0xFFF);
while (limit-- && src[length] != 0) {
length++;
if (limit == 0) {
......@@ -227,20 +227,20 @@ void Process::startup() {
asm volatile("sgdtq %0; sidtq %1":"=m"(gdt), "=m"(idt));
static const uintptr_t KB4 = 0xFFFFFFFFFFFFF000;
for (uintptr_t addr = (uintptr_t)gdt.addr & KB4;
addr < ((uintptr_t)gdt.addr + gdt.limit); addr += 0x1000) {
for (uintptr_t addr = uintptr_t(gdt.addr) & KB4;
addr < (uintptr_t(gdt.addr) + gdt.limit); addr += 0x1000) {
addPage(addr, reinterpret_cast<void*>(addr), 5);
}
for (uintptr_t addr = (uintptr_t)idt.addr & KB4;
addr < ((uintptr_t)idt.addr + idt.limit); addr += 0x1000) {
for (uintptr_t addr = uintptr_t(idt.addr) & KB4;
addr < (uintptr_t(idt.addr) + idt.limit); addr += 0x1000) {
addPage(addr, reinterpret_cast<void*>(addr), 5);
}
INTERRUPT64 *recs = static_cast<INTERRUPT64*>(idt.addr);
uintptr_t page = 0;
for (uint16_t i = 0; i < 0x100; i++) {
uintptr_t handler = ((uintptr_t)recs[i].offset_low
| ((uintptr_t)recs[i].offset_middle << 16)
| ((uintptr_t)recs[i].offset_high << 32));
uintptr_t handler = (uintptr_t(recs[i].offset_low)
| (uintptr_t(recs[i].offset_middle) << 16)
| (uintptr_t(recs[i].offset_high) << 32));
if (page != (handler & KB4)) {
page = handler & KB4;
addPage(page, reinterpret_cast<void*>(page), 5);
......@@ -254,9 +254,9 @@ void Process::startup() {
addPage(handler, reinterpret_cast<void*>(handler), 5);
addPage(sc_wrapper, reinterpret_cast<void*>(sc_wrapper), 5);
GDT_ENT *gdt_ent = reinterpret_cast<GDT_ENT*>(
(uintptr_t)gdt.addr + 8 * 3);
uintptr_t(gdt.addr) + 8 * 3);
GDT_ENT *gdt_top = reinterpret_cast<GDT_ENT*>(
(uintptr_t)gdt.addr + gdt.limit);
uintptr_t(gdt.addr) + gdt.limit);
while (gdt_ent < gdt_top) {
uintptr_t base = gdt_ent->getBase();
size_t limit = gdt_ent->getLimit();
......
......@@ -43,7 +43,7 @@ bool ProcessManager::FaultHandler(
return getManager()->HandleFault(intr, code, regs);
}
bool ProcessManager::SwitchProcess(intcb_regs *regs) {
uintptr_t loopbase = (uintptr_t)&process_loop, looptop;
uintptr_t loopbase = uintptr_t(&process_loop), looptop;
asm volatile("lea process_loop_top(%%rip), %q0":"=r"(looptop));
processSwitchMutex.lock();
if (regs->dpl == 0 &&
......@@ -80,7 +80,7 @@ bool ProcessManager::SwitchProcess(intcb_regs *regs) {
cpuThreads[regs->cpuid] = thread;
Thread *th = thread->thread;
*regs = {
regs->cpuid, (uintptr_t)thread->process->pagetable,
regs->cpuid, uintptr_t(thread->process->pagetable),
th->regs.rip, 0x18,
th->regs.rflags,
th->regs.rsp, 0x20,
......@@ -111,7 +111,7 @@ bool ProcessManager::HandleFault(
t = EnterCritical();
processSwitchMutex.lock();
asm volatile("mov %%cr3, %0":"=r"(regs->cr3));
regs->rip = (uintptr_t)&process_loop;
regs->rip = uintptr_t(&process_loop);
regs->cs = 0x08;
regs->ss = 0x10;
regs->dpl = 0;
......
......@@ -153,17 +153,16 @@ static bool readelf_dylink_handle_dynamic_jmprel(Process *process,
if (sym.name) {
char *name = process->readString(strtab + sym.name);
addr = process->linkLibrary(name);
delete name;
if (addr == 0) {
printf("Cannot link symbol: %s\n", name);
delete name;
return 0;
}
delete name;
} else {
return 0;
}
} else {
printf("SYM=%016lx n=%x i=%x s=%x sz=%lx\n",
sym.value, sym.name, sym.info, sym.shndx, sym.size);
return 0;
}
addr += rel.add;
......@@ -210,7 +209,7 @@ static bool readelf_dylink_handle_dynamic_symtab(Process *process,
uintptr_t ptr = readelf_find_load_addr(process, start, sym.value);
if (ptr == 0) continue;
char *name = process->readString(strtab + sym.name);
if (name && strlen(name) > 0) process->addSymbol(name, ptr);
if (name && name[0] != 0) process->addSymbol(name, ptr);
delete name;
}
return 1;
......@@ -356,7 +355,7 @@ size_t readelf(Process *process, Stream *stream) {
off += prog->filesz - offset_load;
process->writeData(vaddr + offset_load, buf,
prog->filesz - offset_load);
delete buf; buf = 0;
delete[] buf; buf = 0;
prog->vaddr = vaddr;
}
break;
......
......@@ -72,7 +72,7 @@ enum ELF64_PROG_TYPE: uint32_t {
PT_LOOS = 0x60000000,
PT_HIOS = 0x6FFFFFFF,
PT_LOPROC = 0x70000000,
PT_HIPROC = 0x6FFFFFFF
PT_HIPROC = 0x7FFFFFFF
};
enum ELF64_PROG_FLAGS: uint32_t {
......