Unverified Commit aa586c9d authored by PhoeniX's avatar PhoeniX

Refactor in c++ style

parent bedc498b
set noparent
filter=-build/include_what_you_use,-readability/todo
filter=-build/include_what_you_use,-readability/todo,-runtime/indentation_namespace
linelength=120
......@@ -4,7 +4,9 @@
#include "kernlib.hpp"
#include "efi.hpp"
const EFI_SYSTEM_TABLE *EFI::SystemTable = 0;
const void *EFI::ImageHandle = 0;
const EFI_SYSTEM_TABLE *EFI::getSystemTable() { return SystemTable; }
namespace EFI {
const struct EFI::SystemTable *SystemTable = 0;
const void *ImageHandle = 0;
}
const struct EFI::SystemTable *EFI::getSystemTable() { return SystemTable; }
const void *EFI::getImageHandle() { return ImageHandle; }
This diff is collapsed.
......@@ -4,55 +4,54 @@
#pragma once
#include "kernlib.hpp"
enum MUTLIBOOT_FLAGS: uint32_t {
MB_FLAG_MEM = (1 << 0),
MB_FLAG_BOOTDEV = (1 << 1),
MB_FLAG_CMDLINE = (1 << 2),
MB_FLAG_MODS = (1 << 3),
MB_FLAG_SYMTAB = (1 << 4),
MB_FLAG_ELFSYMTAB = (1 << 5),
MB_FLAG_MEMMAP = (1 << 6),
MB_FLAG_DRIVEMAP = (1 << 7),
MB_FLAG_CONFTAB = (1 << 8),
MB_FLAG_BLNAME = (1 << 9),
MB_FLAG_APMTAB = (1 << 10),
MB_FLAG_VBETAB = (1 << 11)
};
struct MULTIBOOT_PAYLOAD {
MUTLIBOOT_FLAGS flags;
size_t mem_lower:32, mem_upper:32;
uint32_t boot_device;
uint32_t pcmdline;
uint32_t mods_count;
uint32_t pmods_addr;
uint32_t syms[3];
uint32_t mmap_length;
uint32_t pmmap_addr;
uint32_t drives_length;
uint32_t pdrives_addr;
uint32_t pconfig_table;
uint32_t pboot_loader_name;
uint32_t papm_table;
uint64_t pvbe_control_info, pvbe_mode_info, pvbe_mode, pvbe_interface_seg,
pvbe_interface_off, pvbe_interface_len;
} PACKED;
struct MULTIBOOT_MODULE {
uint32_t start;
uint32_t end;
};
struct MULTIBOOT_MMAP_ENT {
uint32_t size;
void *base;
size_t length;
uint32_t type;
} PACKED;
class Multiboot {
public:
enum Flags: uint32_t {
MB_FLAG_MEM = (1 << 0),
MB_FLAG_BOOTDEV = (1 << 1),
MB_FLAG_CMDLINE = (1 << 2),
MB_FLAG_MODS = (1 << 3),
MB_FLAG_SYMTAB = (1 << 4),
MB_FLAG_ELFSYMTAB = (1 << 5),
MB_FLAG_MEMMAP = (1 << 6),
MB_FLAG_DRIVEMAP = (1 << 7),
MB_FLAG_CONFTAB = (1 << 8),
MB_FLAG_BLNAME = (1 << 9),
MB_FLAG_APMTAB = (1 << 10),
MB_FLAG_VBETAB = (1 << 11)
};
struct Payload {
Flags flags;
size_t mem_lower:32, mem_upper:32;
uint32_t boot_device;
uint32_t pcmdline;
uint32_t mods_count;
uint32_t pmods_addr;
uint32_t syms[3];
uint32_t mmap_length;
uint32_t pmmap_addr;
uint32_t drives_length;
uint32_t pdrives_addr;
uint32_t pconfig_table;
uint32_t pboot_loader_name;
uint32_t papm_table;
uint64_t pvbe_control_info, pvbe_mode_info, pvbe_mode, pvbe_interface_seg,
pvbe_interface_off, pvbe_interface_len;
} PACKED;
struct MmapEnt {
uint32_t size;
void *base;
size_t length;
uint32_t type;
} PACKED;
struct Module {
uint32_t start;
uint32_t end;
};
private:
static MULTIBOOT_PAYLOAD *payload;
static Payload *payload;
public:
static MULTIBOOT_PAYLOAD *getPayload() PURE;
static Payload *getPayload() PURE;
};
......@@ -3,7 +3,7 @@
#include "multiboot_info.hpp"
MULTIBOOT_PAYLOAD *Multiboot::payload = 0;
MULTIBOOT_PAYLOAD *Multiboot::getPayload() {
Multiboot::Payload *Multiboot::payload = 0;
Multiboot::Payload *Multiboot::getPayload() {
return payload;
}
......@@ -153,20 +153,20 @@ class SerialDisplay: public Display {
public:
SerialDisplay() {
// Disable interrupts
outportb(port + 1, 0);
Port<port + 1>::out<uint8_t>(0);
// Enable DLAB
outportb(port + 3, 0x80);
Port<port + 3>::out<uint8_t>(0x80);
// Set divisor
outportb(port + 0, divisor & 0xFF);
outportb(port + 1, (divisor >> 16) & 0xFF);
Port<port + 0>::out<uint8_t>(divisor & 0xFF);
Port<port + 1>::out<uint8_t>((divisor >> 16) & 0xFF);
// Set port mode (8N1), disable DLAB
outportb(port + 3, 0x03);
Port<port + 3>::out<uint8_t>(0x03);
}
void write(const char *str) {
uint64_t t = EnterCritical();
mutex.lock();
char c;
while ((c = *str++) != 0) outportb(port, c);
while ((c = *str++) != 0) Port<port>::out<uint8_t>(c);
mutex.release();
LeaveCritical(t);
}
......@@ -187,18 +187,18 @@ static Display *getSerialDisplay() { return &serialConsole; }
void Display::setup() {
if (instance != &serialConsole) return;
const EFI_SYSTEM_TABLE *ST = EFI::getSystemTable();
const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST) { // EFI Framebuffer
EFI_GRAPHICS_OUTPUT *graphics_output = 0;
EFI::GraphicsOutput *graphics_output = 0;
ST->BootServices->LocateProtocol(
&EFI_GRAPHICS_OUTPUT_PROTOCOL, 0,
&EFI::GUID_GraphicsOutputProtocol, 0,
reinterpret_cast<void**>(&graphics_output));
PixelFormat pixelFormat;
switch (graphics_output->Mode->Info->PixelFormat) {
case EFI_GRAPHICS_PIXEL_FORMAT_RGBX_8BPP:
case EFI::GRAPHICS_PIXEL_FORMAT_RGBX_8BPP:
pixelFormat = PixelFormatRGBX;
break;
case EFI_GRAPHICS_PIXEL_FORMAT_BGRX_8BPP:
case EFI::GRAPHICS_PIXEL_FORMAT_BGRX_8BPP:
pixelFormat = PixelFormatBGRX;
break;
default:
......
......@@ -4,11 +4,13 @@
#pragma once
#include "std.hpp"
inline static uint64_t rdtsc() {
uint32_t eax, edx;
asm volatile("rdtsc":"=a"(eax), "=d"(edx));
return ((uint64_t(edx) << 32) | eax);
}
namespace klib {
inline static uint64_t rdtsc() {
uint32_t eax, edx;
asm volatile("rdtsc":"=a"(eax), "=d"(edx));
return ((uint64_t(edx) << 32) | eax);
}
} // namespace klib
inline static uint64_t __attribute__((always_inline)) EnterCritical() {
uint64_t flags;
......
......@@ -4,32 +4,37 @@
#pragma once
#include "std.hpp"
inline static uint8_t inportb(uint16_t port) {
uint8_t c;
asm volatile("inb %w1, %b0":"=a"(c):"d"(port));
return c;
}
inline static uint16_t inports(uint16_t port) {
uint16_t c;
asm volatile("inw %w1, %w0":"=a"(c):"d"(port));
return c;
}
inline static uint32_t inportl(uint16_t port) {
uint32_t c;
asm volatile("inl %w1, %d0":"=a"(c):"d"(port));
return c;
}
inline static void outportb(uint16_t port, uint8_t c) {
asm volatile("outb %b0, %w1"::"a"(c), "d"(port));
}
inline static void outports(uint16_t port, uint16_t c) {
asm volatile("outw %w0, %w1"::"a"(c), "d"(port));
}
inline static void outportl(uint16_t port, uint32_t c) {
asm volatile("outl %d0, %w1"::"a"(c), "d"(port));
}
template<uint16_t port> struct Port {
template<typename T> inline static T in();
template<typename T> inline static void out(T value);
template<> inline static uint8_t in() {
uint8_t c;
asm volatile("inb %w1, %b0":"=a"(c):"d"(port));
return c;
}
template<> inline static uint16_t in() {
uint16_t c;
asm volatile("inw %w1, %w0":"=a"(c):"d"(port));
return c;
}
template<> inline static uint32_t in() {
uint32_t c;
asm volatile("inl %w1, %d0":"=a"(c):"d"(port));
return c;
}
template<> inline static void out(uint8_t c) {
asm volatile("outb %b0, %w1"::"a"(c), "d"(port));
}
template<> inline static void out(uint16_t c) {
asm volatile("outw %w0, %w1"::"a"(c), "d"(port));
}
template<> inline static void out(uint32_t c) {
asm volatile("outl %d0, %w1"::"a"(c), "d"(port));
}
};
......@@ -14,16 +14,18 @@
#define alloca(size) __builtin_alloca((size))
template<typename T> inline static T PURE MAX(T a, T b) { return a > b ? a : b; }
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; }
namespace klib {
template<typename T> inline static T PURE max(T a, T b) { return a > b ? a : b; }
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;
char* strdup(const char*);
int strcmp(const char*, const char*) PURE;
size_t strlen(const char*, size_t limit = -1) PURE;
char* strdup(const char*);
int strcmp(const char*, const char*) PURE;
inline static uintptr_t ALIGN(uintptr_t base, size_t align) {
if (base % align == 0)
return base;
return base + align - (base % align);
}
inline static uintptr_t __align(uintptr_t base, size_t align) {
if (base % align == 0)
return base;
return base + align - (base % align);
}
} // namespace klib
......@@ -15,7 +15,7 @@ class List {
Item& insert() {
if (count == capacity) {
capacity += MAX(256 / sizeof(Item), size_t(1));
capacity += klib::max(256 / sizeof(Item), size_t(1));
items = static_cast<Item*>(Heap::realloc(items, sizeof(Item) * capacity));
}
return items[count++];
......
......@@ -326,7 +326,7 @@ out_num:
out_str:
int pad = width - strlen(strval);
int pad = width - 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);
......
......@@ -16,7 +16,7 @@ static uint64_t _genseed() {
asm volatile("rdrandq %q0":"=r"(val));
return val;
}
return rdtsc();
return klib::rdtsc();
}
static uint64_t seed = _genseed();
......
......@@ -10,21 +10,23 @@ extern "C" {
int CONST __cxa_atexit(void (*)(void*), void*, void*) { return 0; }
}
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;
}
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;
}
char* strdup(const char* c) {
size_t len = strlen(c);
char* r = new char[len + 1]();
Memory::copy(r, c, len + 1);
return r;
}
char* strdup(const char* c) {
size_t len = strlen(c);
char* r = new char[len + 1]();
Memory::copy(r, c, len + 1);
return r;
}
int strcmp(const char* a, const char* b) {
size_t i = 0;
while (a[i] != 0 && b[i] != 0 && a[i] == b[i]) { i++; }
return a[i] - b[i];
}
int strcmp(const char* a, const char* b) {
size_t i = 0;
while (a[i] != 0 && b[i] != 0 && a[i] == b[i]) { i++; }
return a[i] - b[i];
}
} // namespace klib
......@@ -36,7 +36,7 @@ Stream* MemoryStream::substream(int64_t offset, size_t limit) {
return new MemoryStream(memory + size_t(offset), limit);
}
char* MemoryStream::readstr() {
size_t len = strlen(memory + offset, limit - offset);
size_t len = klib::strlen(memory + offset, limit - offset);
char* res = new char[len + 1]();
Memory::copy(res, memory + offset, len);
res[len] = 0;
......
......@@ -31,18 +31,18 @@ ACPI::ACPI() {
acpiCpuCount = 0;
activeCpuCount = 1;
if (!(CPU::getFeatures() & CPUID_FEAT_APIC)) {
if (!(CPU::getFeatures() & CPU::CPUID_FEAT_APIC)) {
acpiCpuCount = 1;
return;
}
const EFI_SYSTEM_TABLE *ST = EFI::getSystemTable();
const struct EFI::SystemTable *ST = EFI::getSystemTable();
if (ST && ST->ConfigurationTable) {
const EFI_CONFIGURATION_TABLE *acpi1 = 0, *acpi2 = 0;
const EFI::ConfigurationTable *acpi1 = 0, *acpi2 = 0;
for (uint64_t i = 0; i < ST->NumberOfTableEntries; i++) {
const EFI_CONFIGURATION_TABLE *tbl = ST->ConfigurationTable + i;
if (tbl->VendorGuid == EFI_CONF_TABLE_GUID_ACPI1) acpi1 = tbl;
if (tbl->VendorGuid == EFI_CONF_TABLE_GUID_ACPI2) acpi2 = tbl;
const EFI::ConfigurationTable *tbl = ST->ConfigurationTable + i;
if (tbl->VendorGuid == EFI::GUID_ConfigTableACPI1) acpi1 = tbl;
if (tbl->VendorGuid == EFI::GUID_ConfigTableACPI2) acpi2 = tbl;
}
bool found = 0;
......@@ -73,26 +73,26 @@ ACPI::ACPI() {
LapicOut(LAPIC_TMRDIV, 3);
LapicOut(LAPIC_LVT_TMR, 0x20 | LAPIC_SW_ENABLE);
outportb(0x61, (inportb(0x61) & 0xFD) | 1);
outportb(0x43, 0xB2);
outportb(0x42, 0x9B);
inportb(0x60);
outportb(0x42, 0x2E);
uint8_t t = inportb(0x61) & 0xFE;
outportb(0x61, t);
outportb(0x61, t | 1);
Port<0x61>::out<uint8_t>((Port<0x61>::in<uint8_t>() & 0xFD) | 1);
Port<0x43>::out<uint8_t>(0xB2);
Port<0x42>::out<uint8_t>(0x9B);
Port<0x60>::in<uint8_t>();
Port<0x42>::out<uint8_t>(0x2E);
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);
while ((inportb(0x61) & 0x20) == (t & 0x20)) {}
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;
}
void ACPI::ParseDT(const AcpiHeader *header) {
void ACPI::ParseDT(const Header *header) {
Pagetable::map(header);
if (header->signature == 0x43495041) // 'CIPA'
ParseApic(reinterpret_cast<const AcpiMadt*>(header));
ParseApic(reinterpret_cast<const Madt*>(header));
}
void ACPI::ParseRsdt(const AcpiHeader *rsdt) {
void ACPI::ParseRsdt(const Header *rsdt) {
Pagetable::map(rsdt);
const uint32_t *p = reinterpret_cast<const uint32_t*>(rsdt + 1);
const uint32_t *end = p + (rsdt->length - sizeof(*rsdt)) / sizeof(uint32_t);
......@@ -101,10 +101,10 @@ void ACPI::ParseRsdt(const AcpiHeader *rsdt) {
Pagetable::map(p);
Pagetable::map(p + 1);
uintptr_t address = ((*p++) & 0xFFFFFFFF);
ParseDT(reinterpret_cast<AcpiHeader*>(address));
ParseDT(reinterpret_cast<Header*>(address));
}
}
void ACPI::ParseXsdt(const AcpiHeader *xsdt) {
void ACPI::ParseXsdt(const Header *xsdt) {
Pagetable::map(xsdt);
const uint64_t *p = reinterpret_cast<const uint64_t*>(xsdt + 1);
const uint64_t *end = p + (xsdt->length - sizeof(*xsdt)) / sizeof(uint64_t);
......@@ -113,17 +113,17 @@ void ACPI::ParseXsdt(const AcpiHeader *xsdt) {
Pagetable::map(p);
Pagetable::map(p + 1);
uint64_t address = *p++;
ParseDT(reinterpret_cast<AcpiHeader*>(address));
ParseDT(reinterpret_cast<Header*>(address));
}
}
void ACPI::ParseApic(const AcpiMadt *madt) {
void ACPI::ParseApic(const Madt *madt) {
Pagetable::map(madt);
localApicAddr = reinterpret_cast<char*>(uintptr_t(madt->localApicAddr));
Pagetable::map(localApicAddr);
const uint8_t *p = reinterpret_cast<const uint8_t*>(madt + 1);
const uint8_t *end = p + (madt->header.length - sizeof(AcpiMadt));
const uint8_t *end = p + (madt->header.length - sizeof(Madt));
while (p < end) {
const ApicHeader *header = reinterpret_cast<const ApicHeader*>(p);
......@@ -171,16 +171,16 @@ bool ACPI::ParseRsdp(const void *ptr) {
Pagetable::map(rsdtPtr + 1);
uint32_t rsdtAddr = *rsdtPtr;
if (revision == 0) {
ParseRsdt(reinterpret_cast<AcpiHeader*>(uintptr_t(rsdtAddr)));
ParseRsdt(reinterpret_cast<Header*>(uintptr_t(rsdtAddr)));
} else if (revision == 2) {
Pagetable::map(xsdtPtr);
Pagetable::map(xsdtPtr + 1);
uint64_t xsdtAddr = *xsdtPtr;
if (xsdtAddr)
ParseXsdt(reinterpret_cast<AcpiHeader*>(xsdtAddr));
ParseXsdt(reinterpret_cast<Header*>(xsdtAddr));
else
ParseRsdt(reinterpret_cast<AcpiHeader*>(uintptr_t(rsdtAddr)));
ParseRsdt(reinterpret_cast<Header*>(uintptr_t(rsdtAddr)));
}
return true;
......@@ -231,20 +231,15 @@ void ACPI::IOapicOut(uint32_t reg, uint32_t data) {
MmioWrite32(ioApicAddr + IOAPIC_REGSEL, reg);
MmioWrite32(ioApicAddr + IOAPIC_REGWIN, data);
}
union ioapic_redir_ints {
ioapic_redir r;
uint32_t i[2];
};
void ACPI::IOapicMap(uint32_t idx, ioapic_redir r) {
ioapic_redir_ints a = { .r = r };
IOapicOut(IOAPIC_REDTBL + idx * 2 + 0, a.i[0]);
IOapicOut(IOAPIC_REDTBL + idx * 2 + 1, a.i[1]);
void ACPI::IOapicMap(uint32_t idx, IOApicRedir r) {
IOapicOut(IOAPIC_REDTBL + idx * 2 + 0, r.raw[0]);
IOapicOut(IOAPIC_REDTBL + idx * 2 + 1, r.raw[1]);
}
ioapic_redir ACPI::IOapicReadMap(uint32_t idx) {
ioapic_redir_ints a;
a.i[0] = IOapicIn(IOAPIC_REDTBL + idx * 2 + 0);
a.i[1] = IOapicIn(IOAPIC_REDTBL + idx * 2 + 1);
return a.r;
ACPI::IOApicRedir ACPI::IOapicReadMap(uint32_t idx) {
IOApicRedir a;
a.raw[0] = IOapicIn(IOAPIC_REDTBL + idx * 2 + 0);
a.raw[1] = IOapicIn(IOAPIC_REDTBL + idx * 2 + 1);
return a;
}
void* ACPI::getLapicAddr() {
return localApicAddr;
......@@ -313,7 +308,7 @@ void ACPI::initIOAPIC() {
if (ioApicAddr == 0)
return;
ioApicMaxCount = (IOapicIn(IOAPIC_VER) >> 16) & 0xFF;
ioapic_redir kbd;
IOApicRedir kbd;
kbd.vector = 0x21;
kbd.deliveryMode = 1;
kbd.destinationMode = 0;
......
......@@ -10,7 +10,7 @@ char CPU::brandString[52] = "";
uint64_t CPU::features = 0;
uint64_t CPU::features_ext = 0;
uint64_t CPU::ext_features = 0;
struct cpu_info CPU::info = { 0xFFFFFFFF, 0, 0, 0 };
CPU::Info CPU::info = { 0xFFFFFFFF, 0, 0, 0 };
uint32_t CPU::maxCPUID = 0;
static const char CPUID_FEAT_STR[64][16] = {
......@@ -149,7 +149,7 @@ uint64_t CPU::getExtFeatures() {
return ext_features;
}
struct cpu_info CPU::getInfo() {
CPU::Info CPU::getInfo() {
if (info.type == 0xFFFFFFFF)
getFeatures();
return info;
......@@ -193,7 +193,7 @@ char* CPU::getFeaturesStr() {
end--;
end[0] = 0;
buf = static_cast<char*>(Heap::realloc(buf, strlen(buf) + 1));
buf = static_cast<char*>(Heap::realloc(buf, klib::strlen(buf) + 1));
return buf;
}
......
......@@ -5,24 +5,24 @@
#include "multiboot_info.hpp"
#include "pagetable.hpp"
struct ALLOC {
struct Heap::Alloc {
void* addr;
size_t size;
};
struct ALLOCTABLE {
ALLOC allocs[255];
ALLOCTABLE* next;
struct Heap::AllocTable {
Alloc allocs[255];
AllocTable* next;
int64_t reserved;
};
struct HEAPPAGES {
struct Heap::HeapPage {
void *pages[511];
HEAPPAGES *next;
HeapPage *next;
};
ALLOCTABLE *Heap::allocs = 0;
HEAPPAGES* Heap::heap_pages = 0;
Heap::AllocTable *Heap::allocs = 0;
Heap::HeapPage* Heap::heap_pages = 0;
Mutex Heap::heap_mutex;
void* Heap::alloc(size_t size, size_t align) {
......@@ -31,14 +31,14 @@ void* Heap::alloc(size_t size, size_t align) {
heap_mutex.lock();
if (!heap_pages)
heap_pages = reinterpret_cast<HEAPPAGES*>(Pagetable::alloc());
heap_pages = reinterpret_cast<HeapPage*>(Pagetable::alloc());
if (!allocs)
allocs = reinterpret_cast<ALLOCTABLE*>(Pagetable::alloc());
allocs = reinterpret_cast<AllocTable*>(Pagetable::alloc());
uintptr_t ptr = 0, ptr_top;
HEAPPAGES *pages;
ALLOCTABLE *table;
HeapPage *pages;
AllocTable *table;
find_page:
// Find page
......@@ -67,13 +67,13 @@ new_page:
goto find_page;
}
if (!pages->next)
pages->next = reinterpret_cast<HEAPPAGES*>(Pagetable::alloc());
pages->next = reinterpret_cast<HeapPage*>(Pagetable::alloc());
pages = pages->next;
}
}
check_ptr:
if (ptr < page) ptr = page;
ptr = ALIGN(ptr, align);
ptr = klib::__align(ptr, align);
ptr_top = ptr + size;
for (uintptr_t pg = ptr & 0xFFFFFFFFFFFF000; pg < ptr_top; pg += 0x1000) {
pages = heap_pages;
......@@ -119,7 +119,7 @@ next_page:
goto done;
}
if (!table->next)
table->next = reinterpret_cast<ALLOCTABLE*>(Pagetable::alloc());
table->next = reinterpret_cast<AllocTable*>(Pagetable::alloc());
table = table->next;
}
done:
......@@ -134,7 +134,7 @@ void Heap::free(void* addr) {
if (addr == 0)
return;
heap_mutex.lock();
ALLOCTABLE *t = allocs;
AllocTable *t = allocs;
while (1) {
for (int i = 0; i < 255; i++) {
if (t->allocs[i].addr == addr) {
......@@ -157,7 +157,7 @@ void *Heap::realloc(void *addr, size_t size, size_t align) {
if (addr == 0)
return alloc(size, align);
heap_mutex.lock();
ALLOCTABLE *t = allocs;
AllocTable *t = allocs;
size_t oldsize = 0;
while (t != 0) {
for (int i = 0; i < 255; i++) {
......
......@@ -4,99 +4,105 @@
#pragma once
#include "kernlib.hpp"
enum LAPIC_FIELDS {
LAPIC_APICID = 0x20,
LAPIC_APICVER = 0x30,
LAPIC_TASKPRIOR = 0x80,
LAPIC_EOI = 0xB0,
LAPIC_LDR = 0xD0,
LAPIC_DFR = 0xE0,
LAPIC_SPURIOUS = 0xF0,
LAPIC_ESR = 0x280,
LAPIC_ICRL = 0x300,
LAPIC_ICRH = 0x310,
LAPIC_LVT_TMR = 0x320,
LAPIC_LVT_PERF = 0x340,
LAPIC_LVT_LINT0 = 0x350,
LAPIC_LVT_LINT1 = 0x360,
LAPIC_LVT_ERR = 0x370,
LAPIC_TMRINITCNT = 0x380,
LAPIC_TMRCURRCNT = 0x390,
LAPIC_TMRDIV = 0x3E0,
LAPIC_LAST = 0x38F,
};
enum LAPIC_VALUES {
LAPIC_DISABLE = 0x10000,
LAPIC_SW_ENABLE = 0x100,
LAPIC_CPUFOCUS = 0x200,
LAPIC_NMI = (4 << 8),
TMR_PERIODIC = 0x20000,
TMR_BASEDIV = (1 << 20),
};
class ACPI {
public:
enum LAPIC_FIELDS {
LAPIC_APICID = 0x20,
LAPIC_APICVER = 0x30,
LAPIC_TASKPRIOR = 0x80,
LAPIC_EOI = 0xB0,
LAPIC_LDR = 0xD0,