Unverified Commit 50999068 authored by PhoeniX's avatar PhoeniX

Enable and fix more warnings

parent d9aaf39e
Pipeline #1843 failed with stages
in 5 seconds
......@@ -39,7 +39,9 @@ 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} -Wold-style-cast -Wcast-qual -Wcast-align -Winline")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wold-style-cast -Wcast-qual -Wcast-align")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcomma -Wconditional-uninitialized -Wconversion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wzero-as-null-pointer-constant")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)
......
......@@ -5,8 +5,8 @@
#include "efi.hpp"
namespace EFI {
const struct EFI::SystemTable *SystemTable = 0;
const void *ImageHandle = 0;
const struct EFI::SystemTable *SystemTable = nullptr;
const void *ImageHandle = nullptr;
}
const struct EFI::SystemTable *EFI::getSystemTable() { return SystemTable; }
const void *EFI::getImageHandle() { return ImageHandle; }
......@@ -3,7 +3,7 @@
#include "multiboot_info.hpp"
Multiboot::Payload *Multiboot::payload = 0;
Multiboot::Payload *Multiboot::payload = nullptr;
Multiboot::Payload *Multiboot::getPayload() {
return payload;
}
......@@ -14,7 +14,7 @@ class ConsoleDisplay: public Display {
char *display;
void putc(const char c) {
if (c == 0) return;
size_t pos = display - base;
size_t pos = size_t(display - base);
if (c == '\n') {
display += 160 - (pos % 160);
} else if (c == '\t') {
......@@ -36,7 +36,7 @@ class ConsoleDisplay: public Display {
public:
ConsoleDisplay() {
if (EFI::getSystemTable() != 0) return;
if (EFI::getSystemTable() != nullptr) return;
display = base;
clean();
}
......@@ -166,7 +166,7 @@ class SerialDisplay: public Display {
uint64_t t = EnterCritical();
mutex.lock();
char c;
while ((c = *str++) != 0) Port<port>::out<uint8_t>(c);
while ((c = *str++) != 0) Port<port>::out(uint8_t(c));
mutex.release();
LeaveCritical(t);
}
......@@ -189,9 +189,9 @@ void Display::setup() {
if (instance != &serialConsole) return;
const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST) { // EFI Framebuffer
EFI::GraphicsOutput *graphics_output = 0;
EFI::GraphicsOutput *graphics_output = nullptr;
ST->BootServices->LocateProtocol(
&EFI::GUID_GraphicsOutputProtocol, 0,
&EFI::GUID_GraphicsOutputProtocol, nullptr,
reinterpret_cast<void**>(&graphics_output));
PixelFormat pixelFormat;
switch (graphics_output->Mode->Info->PixelFormat) {
......
......@@ -19,7 +19,7 @@ namespace klib {
template<typename T> inline static T PURE min(T a, T b) { return a < b ? a : b; }
template<typename T> inline static T PURE abs(T a) { return a > 0 ? a : -a; }
size_t strlen(const char*, size_t limit = -1) PURE;
size_t strlen(const char*, size_t limit = static_cast<size_t>(-1)) PURE;
char* strdup(const char*);
int strcmp(const char*, const char*) PURE;
......
......@@ -7,7 +7,7 @@
template<typename Item>
class List {
private:
Item *items = 0;
Item *items = nullptr;
size_t count = 0;
size_t capacity = 0;
public:
......
......@@ -9,7 +9,7 @@ class Stream {
virtual size_t read(void* dest, size_t size) = 0;
virtual size_t size() = 0;
virtual size_t seek(int64_t offset, char base = 0) = 0;
virtual Stream* substream(int64_t offset = -1, size_t limit = -1) = 0;
virtual Stream* substream(int64_t offset = -1, size_t limit = size_t(-1)) = 0;
virtual bool eof() = 0;
virtual char* readstr() = 0;
virtual ~Stream() {}
......@@ -26,7 +26,7 @@ class MemoryStream: public Stream {
size_t read(void* dest, size_t size);
size_t size() PURE;
size_t seek(int64_t offset, char base = 0);
Stream* substream(int64_t offset = -1, size_t limit = -1);
Stream* substream(int64_t offset = -1, size_t limit = size_t(-1));
char* readstr();
bool eof() PURE;
};
......@@ -7,7 +7,7 @@
static inline char *longlong_to_string(
char *buf, size_t len, uint64_t n, uint8_t base,
bool fl_signed, bool fl_showsign, bool fl_caps) {
int pos = len;
size_t pos = len;
char table_start = fl_caps ? 'A' : 'a';
bool negative = 0;
if (fl_signed && int64_t(n) < 0) {
......@@ -19,7 +19,7 @@ static inline char *longlong_to_string(
uint8_t digit = n % base;
n /= base;
if (digit < 10) {
buf[ --pos] = digit + '0';
buf[ --pos] = static_cast<char>(digit + '0');
} else {
buf[ --pos] = digit - 10 + table_start;
}
......@@ -33,7 +33,7 @@ static inline char *longlong_to_string(
static void printf_putc(char *str, size_t *size, int *len, char c) {
if ((*len) == -1) return;
(*len)++;
if (str == 0) return;
if (str == nullptr) return;
if (*size == 0) {
*len = -1;
return;
......@@ -71,7 +71,7 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
} PACKED;
char c;
const char *fmt_start;
const char *fmt_start = nullptr;
int out_len = 0;
flags_t flags;
......@@ -205,36 +205,36 @@ parse_size:
printf_putc(str, &size, &out_len, '%');
goto next_format;
case 'c':
c = va_arg(ap, /* char */ int) & 0xFF;
c = static_cast<char>(va_arg(ap, /* char */ int) & 0xFF);
numbuf[0] = c;
numbuf[1] = 0;
strval = numbuf;
goto out_str;
case 's':
strval = va_arg(ap, const char*);
if (strval == 0) strval = "<null>";
if (strval == nullptr) strval = "<null>";
goto out_str;
case 'd':
case 'i':
numsig = 1;
if (flags.sz_halfhalf)
numval = va_arg(ap, /* signed char, int8_t */ int32_t);
numval = uintmax_t(va_arg(ap, /* signed char, int8_t */ int32_t));
else if (flags.sz_half)
numval = va_arg(ap, /* short int, int16_t */ int32_t);
numval = uintmax_t(va_arg(ap, /* short int, int16_t */ int32_t));
else if (flags.sz_long)
numval = va_arg(ap, int32_t);
numval = uintmax_t(va_arg(ap, int32_t));
else if (flags.sz_longlong)
numval = va_arg(ap, int64_t);
numval = uintmax_t(va_arg(ap, int64_t));
else if (flags.sz_max)
numval = va_arg(ap, intmax_t);
numval = uintmax_t(va_arg(ap, intmax_t));
else if (flags.sz_sizet)
numval = va_arg(ap, size_t);
numval = uintmax_t(va_arg(ap, size_t));
else if (flags.sz_ptrdiff)
numval = va_arg(ap, ptrdiff_t);
numval = uintmax_t(va_arg(ap, ptrdiff_t));
else if (flags.sz_longdbl)
goto invalid_fmt;
else
numval = va_arg(ap, int);
numval = uintmax_t(va_arg(ap, int));
goto out_num;
case 'X':
upcaseout = 1;
......@@ -268,7 +268,7 @@ get_num:
else if (flags.sz_sizet)
numval = va_arg(ap, size_t);
else if (flags.sz_ptrdiff)
numval = va_arg(ap, ptrdiff_t);
numval = uintmax_t(va_arg(ap, ptrdiff_t));
else if (flags.sz_longdbl)
goto invalid_fmt;
else
......@@ -276,11 +276,11 @@ get_num:
goto out_num;
case 'n': {
void *ptrval = va_arg(ap, void*);
if (ptrval == 0) goto next_format;
if (ptrval == nullptr) goto next_format;
if (flags.sz_halfhalf)
*static_cast<int8_t*>(ptrval) = out_len;
*static_cast<int8_t*>(ptrval) = int8_t(out_len);
else if (flags.sz_half)
*static_cast<int16_t*>(ptrval) = out_len;
*static_cast<int16_t*>(ptrval) = int16_t(out_len);
else if (flags.sz_long)
*static_cast<int64_t*>(ptrval) = out_len;
else if (flags.sz_longlong)
......@@ -288,7 +288,7 @@ get_num:
else if (flags.sz_max)
*static_cast<intmax_t*>(ptrval) = out_len;
else if (flags.sz_sizet)
*static_cast<size_t*>(ptrval) = out_len;
*static_cast<size_t*>(ptrval) = size_t(out_len);
else if (flags.sz_ptrdiff)
*static_cast<ptrdiff_t*>(ptrval) = out_len;
else if (flags.sz_longdbl)
......@@ -326,7 +326,7 @@ out_num:
out_str:
int pad = width - klib::strlen(strval);
int pad = width - static_cast<int>(klib::strlen(strval));
if (!flags.fl_leftfmt && (flags.fl_leadzero || flags.fl_leadspace)) {
c = flags.fl_leadzero ? '0' : ' ';
while (pad-- > 0) printf_putc(str, &size, &out_len, c);
......@@ -338,22 +338,22 @@ out_str:
goto next_format;
}
if (str != 0 && out_len != -1) str[out_len] = 0;
if (str != nullptr && out_len != -1) str[out_len] = 0;
return out_len;
}
int vprintf(const char *format, va_list ap) {
va_list tmp;
va_copy(tmp, ap);
int len = vsnprintf(0, 0, format, tmp);
int len = vsnprintf(nullptr, 0, format, tmp);
va_end(tmp);
char smbuf[512], *buf;
if (len > 511) {
buf = static_cast<char*>(Heap::alloc(len + 1));
buf = static_cast<char*>(Heap::alloc(size_t(len) + 1));
} else {
buf = smbuf;
}
len = vsnprintf(buf, len, format, ap);
len = vsnprintf(buf, size_t(len), format, ap);
buf[len] = 0;
Display::getInstance()->write(buf);
if (len > 511) Heap::free(buf);
......
......@@ -4,7 +4,7 @@
#include "kernlib.hpp"
extern "C" {
void *__dso_handle = 0;
void *__dso_handle = nullptr;
void CONST __cxa_pure_virtual() {}
int CONST __cxa_atexit(void (*)(void*), void*, void*) { return 0; }
......@@ -14,7 +14,7 @@ namespace klib {
size_t strlen(const char* c, size_t limit) {
const char *e = c;
while ((size_t(e - c) < limit) && (*e++) != 0) {}
return e - c - 1;
return size_t(e - c - 1);
}
char* strdup(const char* c) {
......
......@@ -16,10 +16,10 @@ size_t MemoryStream::size() {
}
size_t MemoryStream::seek(int64_t offset, char base) {
if (base == -1)
return (this->offset = offset);
return (this->offset = size_t(offset));
if (base == 1)
return (this->offset = this->limit - offset);
return (this->offset += offset);
return (this->offset = size_t(ptrdiff_t(this->limit) - offset));
return (this->offset = size_t(ptrdiff_t(this->offset) + offset));
}
size_t MemoryStream::read(void* dest, size_t size) {
if (offset + size >= limit)
......@@ -30,9 +30,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))
limit = this->limit - offset;
offset = ptrdiff_t(this->offset);
if ((limit == size_t(-1)) || (limit > size_t(ptrdiff_t(this->limit) - offset)))
limit = size_t(ptrdiff_t(this->limit) - offset);
return new MemoryStream(memory + size_t(offset), limit);
}
char* MemoryStream::readstr() {
......
......@@ -8,7 +8,7 @@
#include "pagetable.hpp"
Mutex ACPI::controllerMutex;
ACPI* ACPI::controller = 0;
ACPI* ACPI::controller = nullptr;
ACPI* ACPI::getController() {
if (controller) return controller;
......@@ -22,10 +22,8 @@ ACPI* ACPI::getController() {
}
ACPI::ACPI() {
static const void *const ACPI_FIND_START =
reinterpret_cast<char*>(0x000e0000);
static const void *const ACPI_FIND_TOP =
reinterpret_cast<char*>(0x000fffff);
static const void *const ACPI_FIND_START = reinterpret_cast<char*>(0x000e0000);
static const void *const ACPI_FIND_TOP = reinterpret_cast<char*>(0x000fffff);
static const uint64_t ACPI_SIG_RTP_DSR = 0x2052545020445352; // 'RTP DSR '
acpiCpuCount = 0;
......@@ -38,7 +36,7 @@ ACPI::ACPI() {
const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST && ST->ConfigurationTable) {
const EFI::ConfigurationTable *acpi1 = 0, *acpi2 = 0;
const EFI::ConfigurationTable *acpi1 = nullptr, *acpi2 = nullptr;
for (uint64_t i = 0; i < ST->NumberOfTableEntries; i++) {
const EFI::ConfigurationTable *tbl = ST->ConfigurationTable + i;
if (tbl->VendorGuid == EFI::GUID_ConfigTableACPI1) acpi1 = tbl;
......@@ -81,10 +79,10 @@ ACPI::ACPI() {
uint8_t t = Port<0x61>::in<uint8_t>() & 0xFE;
Port<0x61>::out<uint8_t>(t);
Port<0x61>::out<uint8_t>(t | 1);
LapicOut(LAPIC_TMRINITCNT, -1);
LapicOut(LAPIC_TMRINITCNT, 0xFFFFFFFF);
while ((Port<0x61>::in<uint8_t>() & 0x20) == (t & 0x20)) {}
LapicOut(LAPIC_LVT_TMR, LAPIC_DISABLE);
busfreq = (static_cast<uint64_t>(-1 - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
busfreq = (static_cast<uint64_t>(0xFFFFFFFF - LapicIn(LAPIC_TMRCURRCNT)) << 4) * 100;
}
void ACPI::ParseDT(const Header *header) {
Pagetable::map(header);
......@@ -163,7 +161,7 @@ bool ACPI::ParseRsdp(const void *ptr) {
Memory::copy(oem, p + 9, 6);
oem[6] = 0;
char revision = p[15];
uint8_t revision = p[15];
const uint32_t *rsdtPtr = static_cast<const uint32_t*>(ptr) + 4;
const uint64_t *xsdtPtr = static_cast<const uint64_t*>(ptr) + 3;
......@@ -231,7 +229,7 @@ void ACPI::IOapicOut(uint32_t reg, uint32_t data) {
MmioWrite32(ioApicAddr + IOAPIC_REGSEL, reg);
MmioWrite32(ioApicAddr + IOAPIC_REGWIN, data);
}
void ACPI::IOapicMap(uint32_t idx, IOApicRedir r) {
void ACPI::IOapicMap(uint32_t idx, const IOApicRedir &r) {
IOapicOut(IOAPIC_REDTBL + idx * 2 + 0, r.raw[0]);
IOapicOut(IOAPIC_REDTBL + idx * 2 + 1, r.raw[1]);
}
......@@ -305,7 +303,7 @@ void ACPI::EOI() {
(ACPI::getController())->LapicOut(LAPIC_EOI, 0);
}
void ACPI::initIOAPIC() {
if (ioApicAddr == 0)
if (ioApicAddr == nullptr)
return;
ioApicMaxCount = (IOapicIn(IOAPIC_VER) >> 16) & 0xFF;
IOApicRedir kbd;
......@@ -321,7 +319,7 @@ void ACPI::initIOAPIC() {
IOapicMap(1, kbd);
}
bool ACPI::initAPIC() {
if (localApicAddr == 0)
if (localApicAddr == nullptr)
return false;
initCPU();
initIOAPIC();
......
......@@ -75,10 +75,8 @@ static const char CPUID_EXT_FEAT_STR[64][16] = {
char* CPU::getVendor() {
if (vendor[0] == 0) {
int eax = 0, ebx, ecx, edx;
asm volatile("cpuid" :
"=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) :
"a"(eax));
uint32_t eax = 0, ebx, ecx, edx;
asm volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax));
uint32_t *v = reinterpret_cast<uint32_t*>(vendor);
v[0] = ebx;
v[1] = edx;
......@@ -121,7 +119,7 @@ uint64_t CPU::getFeatures() {
info.family = cpuid_info->family;
if (info.family == 6 || info.family == 15) {
info.family += cpuid_info->family_ext;
info.model += cpuid_info->model_ext << 4;
info.model += uint32_t(cpuid_info->model_ext << 4);
}
}
return features;
......@@ -173,19 +171,19 @@ char* CPU::getFeaturesStr() {
for (int i = 0; i < 64; i++) {
if (((f & (1ll << i)) != 0) && CPUID_FEAT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_FEAT_STR[i]);
end += snprintf(end, bufsize - size_t(end - buf), "%s ", CPUID_FEAT_STR[i]);
}
}
for (int i = 0; i < 64; i++) {
if (((ef & (1ll << i)) != 0) && CPUID_EXT_FEAT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_EXT_FEAT_STR[i]);
end += snprintf(end, bufsize - size_t(end - buf), "%s ", CPUID_EXT_FEAT_STR[i]);
}
}
for (int i = 0; i < 64; i++) {
if (((fe & (1ll << i)) != 0) && CPUID_FEAT_EXT_STR[i][0]) {
end += snprintf(end, bufsize - (end - buf), "%s ", CPUID_FEAT_EXT_STR[i]);
end += snprintf(end, bufsize - size_t(end - buf), "%s ", CPUID_FEAT_EXT_STR[i]);
}
}
......@@ -205,17 +203,17 @@ char* CPU::getBrandString() {
asm volatile("cpuid" :
"=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) :
"a"(eax));
v[0] = eax, v[1] = ebx, v[2] = ecx, v[3] = edx;
v[0] = eax; v[1] = ebx; v[2] = ecx; v[3] = edx;
eax = 0x80000003;
asm volatile("cpuid" :
"=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) :
"a"(eax));
v[4] = eax, v[5] = ebx, v[6] = ecx, v[7] = edx;
v[4] = eax; v[5] = ebx; v[6] = ecx; v[7] = edx;
eax = 0x80000004;
asm volatile("cpuid" :
"=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) :
"a"(eax));
v[8] = eax, v[9] = ebx, v[10] = ecx, v[11] = edx;
v[8] = eax; v[9] = ebx; v[10] = ecx; v[11] = edx;
brandString[48] = 0;
}
return brandString;
......
......@@ -21,13 +21,13 @@ struct Heap::HeapPage {
HeapPage *next;
};
Heap::AllocTable *Heap::allocs = 0;
Heap::HeapPage* Heap::heap_pages = 0;
Heap::AllocTable *Heap::allocs = nullptr;
Heap::HeapPage* Heap::heap_pages = nullptr;
Mutex Heap::heap_mutex;
void* Heap::alloc(size_t size, size_t align) {
if (size == 0)
return 0;
return nullptr;
heap_mutex.lock();
if (!heap_pages)
......@@ -61,7 +61,7 @@ new_page:
pages = heap_pages;
while (pages) {
for (size_t i = 0; i < 511; i++) {
if (pages->pages[i] != 0) continue;
if (pages->pages[i] != nullptr) continue;
pages->pages[i] = Pagetable::alloc();
ptr = 0;
goto find_page;
......@@ -113,7 +113,7 @@ next_page:
table = allocs;
while (table) {
for (size_t i = 0; i < 255; i++) {
if (table->allocs[i].addr != 0) continue;
if (table->allocs[i].addr != nullptr) continue;
table->allocs[i].addr = reinterpret_cast<void*>(ptr);
table->allocs[i].size = size;
goto done;
......@@ -131,19 +131,19 @@ done:
return a;
}
void Heap::free(void* addr) {
if (addr == 0)
if (addr == nullptr)
return;
heap_mutex.lock();
AllocTable *t = allocs;
while (1) {
for (int i = 0; i < 255; i++) {
if (t->allocs[i].addr == addr) {
t->allocs[i].addr = 0;
t->allocs[i].addr = nullptr;
t->allocs[i].size = 0;
goto end;
}
}
if (t->next == 0)
if (t->next == nullptr)
goto end;
t = t->next;
}
......@@ -152,14 +152,14 @@ void Heap::free(void* addr) {
void *Heap::realloc(void *addr, size_t size, size_t align) {
if (size == 0) {
free(addr);
return 0;
return nullptr;
}
if (addr == 0)
if (addr == nullptr)
return alloc(size, align);
heap_mutex.lock();
AllocTable *t = allocs;
size_t oldsize = 0;
while (t != 0) {
while (t != nullptr) {
for (int i = 0; i < 255; i++) {
if (t->allocs[i].addr == addr) {
oldsize = t->allocs[i].size;
......@@ -177,7 +177,7 @@ void *Heap::realloc(void *addr, size_t size, size_t align) {
}
heap_mutex.release();
if (oldsize == 0)
return 0;
return nullptr;
void *newptr = alloc(size, align);
Memory::copy(newptr, addr, oldsize);
free(addr);
......
......@@ -133,7 +133,7 @@ class ACPI {
void LapicOut(uint32_t reg, uint32_t data);
uint32_t IOapicIn(uint32_t reg);
void IOapicOut(uint32_t reg, uint32_t data);
void IOapicMap(uint32_t idx, IOApicRedir r);
void IOapicMap(uint32_t idx, const IOApicRedir &r);
IOApicRedir IOapicReadMap(uint32_t idx);
void activateCPU();
uint32_t getLapicIDOfCPU(uint32_t cpuId) PURE;
......
......@@ -107,7 +107,7 @@ class Interrupts {
uint64_t r8, r9, r10, r11;
uint64_t r12, r13, r14, r15;
};
typedef bool Callback(uint32_t intr, uint32_t code, CallbackRegs *regs);
typedef bool Callback(uint8_t intr, uint32_t code, CallbackRegs *regs);
struct REC32 {
uint16_t offset_low;
......@@ -135,9 +135,9 @@ class Interrupts {
present(0), offset_middle(0), offset_high(0), rsvd3(0) {}
REC64(uint64_t offset, uint16_t selector, uint8_t ist, uint8_t type,
uint8_t dpl, bool present) :
offset_low(offset), selector(selector), ist(ist), rsvd1(0),
offset_low(uint16_t(offset)), selector(selector), ist(ist), rsvd1(0),
type(type), rsvd2(0), dpl(dpl), present(present),
offset_middle(offset >> 16), offset_high(offset >> 32), rsvd3(0) {}
offset_middle(uint16_t(offset >> 16)), offset_high(offset >> 32), rsvd3(0) {}
ALIGNED_NEWARR(0x1000)
} PACKED;
......
......@@ -44,12 +44,12 @@ class Pagetable {
uint16_t pdpx = (ptr >> (12 + 9)) & 0x1FF;
uint16_t pml4x = (ptr >> (12)) & 0x1FF;
Entry *pde = pagetable[ptx].present ? pagetable[ptx].getPTE() : 0;
if (pde == 0) return 0;
Entry *pdpe = pde[pdx].present ? pde[pdx].getPTE() : 0;
if (pdpe == 0) return 0;
Entry *page = pdpe[pdpx].present ? pdpe[pdpx].getPTE() : 0;
if (page == 0) return 0;
Entry *pde = pagetable[ptx].present ? pagetable[ptx].getPTE() : nullptr;
if (pde == nullptr) return nullptr;
Entry *pdpe = pde[pdx].present ? pde[pdx].getPTE() : nullptr;
if (pdpe == nullptr) return nullptr;
Entry *page = pdpe[pdpx].present ? pdpe[pdpx].getPTE() : nullptr;
if (page == nullptr) return nullptr;
return &page[pml4x];
}
......
......@@ -24,13 +24,13 @@ struct Interrupts::Handler {
ALIGNED_NEWARR(0x1000)
} PACKED;
Interrupts::REC64 *Interrupts::idt = 0;
GDT *Interrupts::gdt = 0;
TSS64_ENT **Interrupts::tss = 0;
List<Interrupts::Callback*> *Interrupts::callbacks;
Interrupts::REC64 *Interrupts::idt = nullptr;
GDT *Interrupts::gdt = nullptr;
TSS64_ENT **Interrupts::tss = nullptr;
List<Interrupts::Callback*> *Interrupts::callbacks = nullptr;
Mutex Interrupts::callback_locks[256];
Mutex Interrupts::fault;
Interrupts::Handler* Interrupts::handlers = 0;
Interrupts::Handler* Interrupts::handlers = nullptr;
asm(
".global __interrupt_wrap;"
......@@ -227,10 +227,10 @@ uint64_t __attribute__((sysv_abi)) Interrupts::handle(
fault.release();
uint64_t *rsp = reinterpret_cast<uint64_t*>(stack);
bool has_code = (intr < 0x20) && FAULTS[intr].has_error_code;
uint64_t error_code = 0;
uint32_t error_code = 0;
int_regs *regs = reinterpret_cast<int_regs*>(rsp - (12 + 3) - 1);
if (has_code)
error_code = *(rsp++);
error_code = uint32_t(*(rsp++));
int_info *info = reinterpret_cast<int_info*>(rsp);
bool handled = false;
......@@ -253,10 +253,10 @@ uint64_t __attribute__((sysv_abi)) Interrupts::handle(
Callback *cb;
for (;;) {
callback_locks[intr].lock();
cb = (callbacks[intr].getCount() > idx) ? callbacks[intr][idx] : 0;
cb = (callbacks[intr].getCount() > idx) ? callbacks[intr][idx] : nullptr;
idx++;
callback_locks[intr].release();
if (cb == 0) break;
if (cb == nullptr) break;
handled = cb(intr, error_code, &cb_regs);
if (handled) break;
}
......@@ -346,10 +346,10 @@ void Interrupts::init() {
"mov %%eax, 2+__interrupt_pagetable_mov(%%rip)"
::"a"(lapic_eoi)
);
for (int i = 0; i < 256; i++) {
for (uint32_t i = 0; i < 256; i++) {
uintptr_t jmp_from = uintptr_t(&(handlers[i].reljmp));
uintptr_t diff = addr - jmp_from - 5;
handlers[i] = Handler(i, diff);
handlers[i] = Handler(i, uint32_t(diff));
uintptr_t hptr = uintptr_t(&handlers[i]);
idt[i] = REC64(hptr, 8, 1, 0xE, 0, true);
......@@ -382,13 +382,13 @@ void Interrupts::maskIRQ(uint16_t mask) {
}
void Interrupts::loadVector() {
if (idt == 0) {
if (idt == nullptr) {
init();
return;
}
DTREG idtreg = { sizeof(REC64) * 256 -1, &idt[0] };
uint32_t cpuid = ACPI::getController()->getCPUID();
uint16_t tr = 5 * sizeof(GDT::Entry) + cpuid * sizeof(GDT::SystemEntry);
uint16_t tr = uint16_t(5 * sizeof(GDT::Entry) + cpuid * sizeof(GDT::SystemEntry));
asm volatile(
"lidtq %0;"
"ltr %w1;"
......@@ -396,7 +396,9 @@ void Interrupts::loadVector() {
}
uint16_t Interrupts::getIRQmask() {
return Port<0x21>::in<uint8_t>() | (static_cast<uint16_t>(Port<0xA1>::in<uint8_t>()) << 8);
return uint16_t(
(uint16_t(Port<0x21>::in<uint8_t>())) |
(uint16_t(Port<0xA1>::in<uint8_t>()) << 8));
}
void Interrupts::addCallback(uint8_t intr, Callback* cb) {
......
......@@ -25,11 +25,11 @@ static inline void fillPages(void *low, void *top, PTE *pagetable, uint8_t flags
static void *efiAllocatePage(uintptr_t min, const struct EFI::SystemTable *ST) {
size_t mapSize = 0, entSize = 0;
EFI::MemoryDescriptor *map = 0, *ent;
EFI::MemoryDescriptor *map = nullptr, *ent;
uint64_t mapKey;
uint32_t entVer = 0;
void *ptr = 0;
void *ptr = nullptr;
ST->BootServices->GetMemoryMap(&mapSize, map, &mapKey, &entSize, &entVer);
map = static_cast<EFI::MemoryDescriptor*>(alloca(mapSize));
......@@ -97,7 +97,7 @@ void Pagetable::init() {
// Initialization of pagetables
if (ST) {
EFI::LoadedImage *loaded_image = 0;
EFI::LoadedImage *loaded_image = nullptr;
ST->BootServices->HandleProtocol(
EFI::getImageHandle(), &EFI::GUID_LoadedImageProtocol,