clang-format set column width to 100 chars

This commit is contained in:
2025-12-22 19:38:32 +01:00
parent 7b33d0757a
commit 69feceaaae
17 changed files with 77 additions and 120 deletions

View File

@@ -22,7 +22,7 @@ AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never AllowShortBlocksOnASingleLine: Never
# Line breaking # Line breaking
ColumnLimit: 80 ColumnLimit: 100
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakStringLiterals: false BreakStringLiterals: false

View File

@@ -36,8 +36,7 @@ static struct acpi_madt_ioapic* amd64_ioapic_find (uint8_t irq) {
for (size_t i = 0; i < ioapic_entries; i++) { for (size_t i = 0; i < ioapic_entries; i++) {
apic = &apics[i]; apic = &apics[i];
uint32_t version = amd64_ioapic_read ( uint32_t version = amd64_ioapic_read ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, 1);
(uintptr_t)hhdm->offset + (uintptr_t)apic->address, 1);
uint32_t max = (version >> 16); uint32_t max = (version >> 16);
if ((apic->gsi_base <= irq) && ((apic->gsi_base + max) > irq)) if ((apic->gsi_base <= irq) && ((apic->gsi_base + max) > irq))
@@ -47,8 +46,7 @@ static struct acpi_madt_ioapic* amd64_ioapic_find (uint8_t irq) {
return apic; return apic;
} }
void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags, void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags, uint64_t lapic_id) {
uint64_t lapic_id) {
struct acpi_madt_ioapic* apic; struct acpi_madt_ioapic* apic;
struct acpi_madt_interrupt_source_override* override; struct acpi_madt_interrupt_source_override* override;
bool found_override = false; bool found_override = false;
@@ -67,8 +65,7 @@ void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags,
if (found_override) { if (found_override) {
uint8_t polarity = ((override->flags & 0x03) == 0x03) ? 1 : 0; uint8_t polarity = ((override->flags & 0x03) == 0x03) ? 1 : 0;
uint8_t mode = (((override->flags >> 2) & 0x03) == 0x03) ? 1 : 0; uint8_t mode = (((override->flags >> 2) & 0x03) == 0x03) ? 1 : 0;
calc_flags = (lapic_id << 56) | (mode << 15) | (polarity << 14) | calc_flags = (lapic_id << 56) | (mode << 15) | (polarity << 14) | (vec & 0xFF) | flags;
(vec & 0xFF) | flags;
} }
apic = amd64_ioapic_find (irq); apic = amd64_ioapic_find (irq);
@@ -78,11 +75,11 @@ void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags,
uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10; uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10;
amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg,
irq_reg, (uint32_t)calc_flags); (uint32_t)calc_flags);
amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg + 1,
irq_reg + 1, (uint32_t)(calc_flags >> 32)); (uint32_t)(calc_flags >> 32));
} }
void amd64_ioapic_mask (uint8_t irq) { void amd64_ioapic_mask (uint8_t irq) {
@@ -96,10 +93,9 @@ void amd64_ioapic_mask (uint8_t irq) {
uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10; uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10;
uint32_t value = amd64_ioapic_read ( uint32_t value = amd64_ioapic_read ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg);
(uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg); amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg,
amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, value | (1 << 16));
irq_reg, value | (1 << 16));
} }
void amd64_ioapic_unmask (uint8_t irq) { void amd64_ioapic_unmask (uint8_t irq) {
@@ -113,18 +109,16 @@ void amd64_ioapic_unmask (uint8_t irq) {
uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10; uint32_t irq_reg = ((irq - apic->gsi_base) * 2) + 0x10;
uint32_t value = amd64_ioapic_read ( uint32_t value = amd64_ioapic_read ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg);
(uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg); amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, irq_reg,
amd64_ioapic_write ((uintptr_t)hhdm->offset + (uintptr_t)apic->address, value & ~(1 << 16));
irq_reg, value & ~(1 << 16));
} }
void amd64_ioapic_init (void) { void amd64_ioapic_init (void) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response; struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
struct uacpi_table apic_table; struct uacpi_table apic_table;
uacpi_status status = uacpi_status status = uacpi_table_find_by_signature (ACPI_MADT_SIGNATURE, &apic_table);
uacpi_table_find_by_signature (ACPI_MADT_SIGNATURE, &apic_table);
if (status != UACPI_STATUS_OK) { if (status != UACPI_STATUS_OK) {
DEBUG ("Could not find MADT table!\n"); DEBUG ("Could not find MADT table!\n");
amd64_spin (); amd64_spin ();
@@ -134,8 +128,8 @@ void amd64_ioapic_init (void) {
struct acpi_entry_hdr* current = (struct acpi_entry_hdr*)apic->entries; struct acpi_entry_hdr* current = (struct acpi_entry_hdr*)apic->entries;
for (;;) { for (;;) {
if ((uintptr_t)current >= ((uintptr_t)apic->entries + apic->hdr.length - if ((uintptr_t)current >=
sizeof (struct acpi_madt))) ((uintptr_t)apic->entries + apic->hdr.length - sizeof (struct acpi_madt)))
break; break;
switch (current->type) { switch (current->type) {

View File

@@ -3,8 +3,7 @@
#include <libk/std.h> #include <libk/std.h>
void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags, void amd64_ioapic_route_irq (uint8_t vec, uint8_t irq, uint64_t flags, uint64_t lapic_id);
uint64_t lapic_id);
void amd64_ioapic_mask (uint8_t irq); void amd64_ioapic_mask (uint8_t irq);
void amd64_ioapic_unmask (uint8_t irq); void amd64_ioapic_unmask (uint8_t irq);
void amd64_ioapic_init (void); void amd64_ioapic_init (void);

View File

@@ -18,8 +18,7 @@ void bootmain (void) {
pmm_init (); pmm_init ();
mm_init (); mm_init ();
uacpi_setup_early_table_access ((void*)uacpi_memory_buffer, uacpi_setup_early_table_access ((void*)uacpi_memory_buffer, sizeof (uacpi_memory_buffer));
sizeof (uacpi_memory_buffer));
amd64_ioapic_init (); amd64_ioapic_init ();
amd64_hpet_init (); amd64_hpet_init ();

View File

@@ -34,13 +34,9 @@ static void amd64_hpet_write (uint32_t reg, uint64_t value) {
*(volatile uint64_t*)(hpet_vaddr + reg) = value; *(volatile uint64_t*)(hpet_vaddr + reg) = value;
} }
static uint64_t amd64_hpet_timestamp (void) { static uint64_t amd64_hpet_timestamp (void) { return amd64_hpet_read (HPET_MCVR); }
return amd64_hpet_read (HPET_MCVR);
}
uint64_t amd64_hpet_current_nano (void) { uint64_t amd64_hpet_current_nano (void) { return amd64_hpet_timestamp () * hpet_clock_nano; }
return amd64_hpet_timestamp () * hpet_clock_nano;
}
void amd64_hpet_sleep_micro (uint64_t us) { void amd64_hpet_sleep_micro (uint64_t us) {
uint64_t start = amd64_hpet_timestamp (); uint64_t start = amd64_hpet_timestamp ();
@@ -51,8 +47,7 @@ void amd64_hpet_sleep_micro (uint64_t us) {
void amd64_hpet_init (void) { void amd64_hpet_init (void) {
struct uacpi_table hpet_table; struct uacpi_table hpet_table;
uacpi_status status = uacpi_status status = uacpi_table_find_by_signature (ACPI_HPET_SIGNATURE, &hpet_table);
uacpi_table_find_by_signature (ACPI_HPET_SIGNATURE, &hpet_table);
if (status != UACPI_STATUS_OK) { if (status != UACPI_STATUS_OK) {
DEBUG ("Could not find HPET table!\n"); DEBUG ("Could not find HPET table!\n");
amd64_spin (); amd64_spin ();
@@ -62,8 +57,7 @@ void amd64_hpet_init (void) {
hpet_paddr = (uintptr_t)hpet->address.address; hpet_paddr = (uintptr_t)hpet->address.address;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response; struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
mm_map_kernel_page (hpet_paddr, (uintptr_t)hhdm->offset + hpet_paddr, mm_map_kernel_page (hpet_paddr, (uintptr_t)hhdm->offset + hpet_paddr, MM_PG_PRESENT | MM_PG_RW);
MM_PG_PRESENT | MM_PG_RW);
hpet_32bits = (amd64_hpet_read (HPET_GCIDR) & (1 << 13)) ? 0 : 1; hpet_32bits = (amd64_hpet_read (HPET_GCIDR) & (1 << 13)) ? 0 : 1;

View File

@@ -40,8 +40,8 @@ struct gdt_extended {
ALIGNED (16) static volatile uint8_t kernel_stack[KSTACK_SIZE]; ALIGNED (16) static volatile uint8_t kernel_stack[KSTACK_SIZE];
ALIGNED (16) static volatile struct gdt_extended gdt; ALIGNED (16) static volatile struct gdt_extended gdt;
static void amd64_gdt_set (volatile struct gdt_entry* ent, uint32_t base, static void amd64_gdt_set (volatile struct gdt_entry* ent, uint32_t base, uint32_t limit,
uint32_t limit, uint8_t acc, uint8_t gran) { uint8_t acc, uint8_t gran) {
ent->baselow = (base & 0xFFFF); ent->baselow = (base & 0xFFFF);
ent->basemid = (base >> 16) & 0xFF; ent->basemid = (base >> 16) & 0xFF;
ent->basehigh = (base >> 24) & 0xFF; ent->basehigh = (base >> 24) & 0xFF;
@@ -68,8 +68,7 @@ static void amd64_gdt_init (void) {
amd64_gdt_set (&gdt.old[2], 0, 0xFFFFF, 0x92, 0xC0); amd64_gdt_set (&gdt.old[2], 0, 0xFFFFF, 0x92, 0xC0);
amd64_gdt_set (&gdt.old[3], 0, 0xFFFFF, 0xFA, 0xA0); amd64_gdt_set (&gdt.old[3], 0, 0xFFFFF, 0xFA, 0xA0);
amd64_gdt_set (&gdt.old[4], 0, 0xFFFFF, 0xF2, 0xC0); amd64_gdt_set (&gdt.old[4], 0, 0xFFFFF, 0xF2, 0xC0);
amd64_gdt_set (&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit, amd64_gdt_set (&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit, TSS_PRESENT | TSS, 0);
TSS_PRESENT | TSS, 0);
uint32_t tssbasehigh = (tssbase >> 32); uint32_t tssbasehigh = (tssbase >> 32);
gdt.tsshigh.limitlow = (tssbasehigh & 0xFFFF); gdt.tsshigh.limitlow = (tssbasehigh & 0xFFFF);

View File

@@ -54,8 +54,8 @@ extern void amd64_spin (void);
/* Remaps and disables old 8259 PIC, since we'll be using APIC. */ /* Remaps and disables old 8259 PIC, since we'll be using APIC. */
static void amd64_init_pic (void) { static void amd64_init_pic (void) {
#define IO_OP(fn, ...) \ #define IO_OP(fn, ...) \
fn (__VA_ARGS__); \ fn (__VA_ARGS__); \
amd64_io_wait () amd64_io_wait ()
IO_OP (amd64_io_outb, PIC1_CMD, (ICW1_INIT | ICW1_ICW4)); IO_OP (amd64_io_outb, PIC1_CMD, (ICW1_INIT | ICW1_ICW4));
@@ -77,8 +77,7 @@ static void amd64_init_pic (void) {
#undef IO_OP #undef IO_OP
} }
static void amd64_idt_set (volatile struct idt_entry* ent, uint64_t handler, static void amd64_idt_set (volatile struct idt_entry* ent, uint64_t handler, uint8_t flags) {
uint8_t flags) {
ent->intrlow = (handler & 0xFFFF); ent->intrlow = (handler & 0xFFFF);
ent->kernel_cs = 0x08; // GDT_KCODE (init.c) ent->kernel_cs = 0x08; // GDT_KCODE (init.c)
ent->ist = 0; ent->ist = 0;
@@ -91,8 +90,8 @@ static void amd64_idt_set (volatile struct idt_entry* ent, uint64_t handler,
static void amd64_idt_init (void) { static void amd64_idt_init (void) {
memset ((void*)idt_entries, 0, sizeof (idt_entries)); memset ((void*)idt_entries, 0, sizeof (idt_entries));
#define IDT_ENTRY(n) \ #define IDT_ENTRY(n) \
extern void amd64_intr##n (void); \ extern void amd64_intr##n (void); \
amd64_idt_set (&idt_entries[(n)], (uint64_t)&amd64_intr##n, 0x8E) amd64_idt_set (&idt_entries[(n)], (uint64_t)&amd64_intr##n, 0x8E)
IDT_ENTRY (0); IDT_ENTRY (0);
IDT_ENTRY (1); IDT_ENTRY (1);
@@ -167,10 +166,9 @@ static void amd64_intr_exception (struct saved_regs* regs) {
"err=%016lx rip=%016lx cs =%016lx\n" "err=%016lx rip=%016lx cs =%016lx\n"
"rfl=%016lx rsp=%016lx ss =%016lx\n" "rfl=%016lx rsp=%016lx ss =%016lx\n"
"cr2=%016lx cr3=%016lx rbx=%016lx\n", "cr2=%016lx cr3=%016lx rbx=%016lx\n",
regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10, regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10, regs->r9, regs->r8,
regs->r9, regs->r8, regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rcx, regs->rax, regs->trap,
regs->rcx, regs->rax, regs->trap, regs->error, regs->rip, regs->error, regs->rip, regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3,
regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3,
regs->rbx); regs->rbx);
amd64_spin (); amd64_spin ();

View File

@@ -14,10 +14,7 @@ void amd64_io_outl (uint16_t port, uint32_t v) {
} }
void amd64_io_outsw (uint16_t port, const void* addr, int cnt) { void amd64_io_outsw (uint16_t port, const void* addr, int cnt) {
__asm__ volatile ("cld; rep outsw" __asm__ volatile ("cld; rep outsw" : "+S"(addr), "+c"(cnt) : "d"(port) : "memory", "cc");
: "+S"(addr), "+c"(cnt)
: "d"(port)
: "memory", "cc");
} }
uint8_t amd64_io_inb (uint16_t port) { uint8_t amd64_io_inb (uint16_t port) {
@@ -39,10 +36,7 @@ uint32_t amd64_io_inl (uint16_t port) {
} }
void amd64_io_insw (uint16_t port, void* addr, int cnt) { void amd64_io_insw (uint16_t port, void* addr, int cnt) {
__asm__ volatile ("cld; rep insw" __asm__ volatile ("cld; rep insw" : "+D"(addr), "+c"(cnt) : "d"(port) : "memory", "cc");
: "+D"(addr), "+c"(cnt)
: "d"(port)
: "memory", "cc");
} }
void amd64_io_wait (void) { amd64_io_outb (0x80, 0); } void amd64_io_wait (void) { amd64_io_outb (0x80, 0); }

View File

@@ -35,8 +35,7 @@ static struct pg_index amd64_mm_page_index (uint64_t vaddr) {
return ret; return ret;
} }
static uint64_t* amd64_mm_next_table (uint64_t* table, uint64_t entry_idx, static uint64_t* amd64_mm_next_table (uint64_t* table, uint64_t entry_idx, bool alloc) {
bool alloc) {
uint64_t entry = table[entry_idx]; uint64_t entry = table[entry_idx];
uint64_t paddr; uint64_t paddr;
@@ -75,8 +74,7 @@ static void amd64_reload_cr3 (void) {
__asm__ volatile ("movq %%cr3, %0; movq %0, %%cr3" : "=r"(cr3)::"memory"); __asm__ volatile ("movq %%cr3, %0; movq %0, %%cr3" : "=r"(cr3)::"memory");
} }
void mm_map_page (struct pd* pd, uintptr_t paddr, uintptr_t vaddr, void mm_map_page (struct pd* pd, uintptr_t paddr, uintptr_t vaddr, uint32_t flags) {
uint32_t flags) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response; struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
bool do_reload = false; bool do_reload = false;

View File

@@ -1,10 +1,10 @@
#include <aux/compiler.h> #include <aux/compiler.h>
#include <limine/limine.h> #include <limine/limine.h>
#define DECL_REQ(small, big) \ #define DECL_REQ(small, big) \
SECTION (".limine_requests") \ SECTION (".limine_requests") \
struct limine_##small##_request limine_##small##_request = { \ struct limine_##small##_request limine_##small##_request = {.id = LIMINE_##big##_REQUEST_ID, \
.id = LIMINE_##big##_REQUEST_ID, .revision = 4} .revision = 4}
SECTION (".limine_requests") SECTION (".limine_requests")
volatile uint64_t limine_base_revision[] = LIMINE_BASE_REVISION (4); volatile uint64_t limine_base_revision[] = LIMINE_BASE_REVISION (4);

View File

@@ -3,8 +3,7 @@
#include <limine/limine.h> #include <limine/limine.h>
#define EXTERN_REQ(small) \ #define EXTERN_REQ(small) extern struct limine_##small##_request limine_##small##_request
extern struct limine_##small##_request limine_##small##_request
EXTERN_REQ (hhdm); EXTERN_REQ (hhdm);
EXTERN_REQ (memmap); EXTERN_REQ (memmap);

View File

@@ -94,8 +94,7 @@ static inline int getexp (unsigned int size) {
} }
#ifdef DEBUG #ifdef DEBUG
printf ("getexp returns %i (%i bytes) for %i size\n", shift - 1, printf ("getexp returns %i (%i bytes) for %i size\n", shift - 1, (1 << (shift - 1)), size);
(1 << (shift - 1)), size);
#endif #endif
return shift - 1; return shift - 1;
@@ -223,12 +222,10 @@ static inline struct boundary_tag* absorb_right (struct boundary_tag* tag) {
} }
static inline struct boundary_tag* split_tag (struct boundary_tag* tag) { static inline struct boundary_tag* split_tag (struct boundary_tag* tag) {
unsigned int remainder = unsigned int remainder = tag->real_size - sizeof (struct boundary_tag) - tag->size;
tag->real_size - sizeof (struct boundary_tag) - tag->size;
struct boundary_tag* new_tag = struct boundary_tag* new_tag =
(struct boundary_tag*)((uintptr_t)tag + sizeof (struct boundary_tag) + (struct boundary_tag*)((uintptr_t)tag + sizeof (struct boundary_tag) + tag->size);
tag->size);
new_tag->magic = LIBALLOC_MAGIC; new_tag->magic = LIBALLOC_MAGIC;
new_tag->real_size = remainder; new_tag->real_size = remainder;
@@ -285,8 +282,8 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
tag->split_right = NULL; tag->split_right = NULL;
#ifdef DEBUG #ifdef DEBUG
printf ("Resource allocated %x of %i pages (%i bytes) for %i size.\n", tag, printf ("Resource allocated %x of %i pages (%i bytes) for %i size.\n", tag, pages,
pages, pages * l_pageSize, size); pages * l_pageSize, size);
l_allocated += pages * l_pageSize; l_allocated += pages * l_pageSize;
@@ -322,11 +319,9 @@ void* malloc (size_t size) {
tag = l_freePages[index]; // Start at the front of the list. tag = l_freePages[index]; // Start at the front of the list.
while (tag != NULL) { while (tag != NULL) {
// If there's enough space in this tag. // If there's enough space in this tag.
if ((tag->real_size - sizeof (struct boundary_tag)) >= if ((tag->real_size - sizeof (struct boundary_tag)) >= (size + sizeof (struct boundary_tag))) {
(size + sizeof (struct boundary_tag))) {
#ifdef DEBUG #ifdef DEBUG
printf ("Tag search found %i >= %i\n", printf ("Tag search found %i >= %i\n", (tag->real_size - sizeof (struct boundary_tag)),
(tag->real_size - sizeof (struct boundary_tag)),
(size + sizeof (struct boundary_tag))); (size + sizeof (struct boundary_tag)));
#endif #endif
break; break;
@@ -363,17 +358,16 @@ void* malloc (size_t size) {
tag->real_size - size - sizeof (struct boundary_tag), index, 1 << index); tag->real_size - size - sizeof (struct boundary_tag), index, 1 << index);
#endif #endif
unsigned int remainder = tag->real_size - size - unsigned int remainder =
sizeof (struct boundary_tag) * 2; // Support a new tag + remainder tag->real_size - size - sizeof (struct boundary_tag) * 2; // Support a new tag + remainder
if (((int)(remainder) > if (((int)(remainder) > 0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/) {
0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/) {
int childIndex = getexp (remainder); int childIndex = getexp (remainder);
if (childIndex >= 0) { if (childIndex >= 0) {
#ifdef DEBUG #ifdef DEBUG
printf ("Seems to be splittable: %i >= 2^%i .. %i\n", remainder, printf ("Seems to be splittable: %i >= 2^%i .. %i\n", remainder, childIndex,
childIndex, (1 << childIndex)); (1 << childIndex));
#endif #endif
struct boundary_tag* new_tag = split_tag (tag); struct boundary_tag* new_tag = split_tag (tag);
@@ -381,8 +375,8 @@ void* malloc (size_t size) {
(void)new_tag; (void)new_tag;
#ifdef DEBUG #ifdef DEBUG
printf ("Old tag has become %i bytes, new tag is now %i bytes (%i exp)\n", printf ("Old tag has become %i bytes, new tag is now %i bytes (%i exp)\n", tag->real_size,
tag->real_size, new_tag->real_size, new_tag->index); new_tag->real_size, new_tag->index);
#endif #endif
} }
} }
@@ -391,8 +385,7 @@ void* malloc (size_t size) {
#ifdef DEBUG #ifdef DEBUG
l_inuse += size; l_inuse += size;
printf ("malloc: %x, %i, %i\n", ptr, (int)l_inuse / 1024, printf ("malloc: %x, %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024);
(int)l_allocated / 1024);
dump_array (); dump_array ();
#endif #endif
@@ -418,17 +411,15 @@ void free (void* ptr) {
#ifdef DEBUG #ifdef DEBUG
l_inuse -= tag->size; l_inuse -= tag->size;
printf ("free: %x, %i, %i\n", ptr, (int)l_inuse / 1024, printf ("free: %x, %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024);
(int)l_allocated / 1024);
#endif #endif
// MELT LEFT... // MELT LEFT...
while ((tag->split_left != NULL) && (tag->split_left->index >= 0)) { while ((tag->split_left != NULL) && (tag->split_left->index >= 0)) {
#ifdef DEBUG #ifdef DEBUG
printf ( printf ("Melting tag left into available memory. Left was %i, becomes %i (%i)\n",
"Melting tag left into available memory. Left was %i, becomes %i (%i)\n", tag->split_left->real_size, tag->split_left->real_size + tag->real_size,
tag->split_left->real_size, tag->split_left->real_size + tag->real_size, tag->split_left->real_size);
tag->split_left->real_size);
#endif #endif
tag = melt_left (tag); tag = melt_left (tag);
remove_tag (tag); remove_tag (tag);
@@ -437,10 +428,9 @@ void free (void* ptr) {
// MELT RIGHT... // MELT RIGHT...
while ((tag->split_right != NULL) && (tag->split_right->index >= 0)) { while ((tag->split_right != NULL) && (tag->split_right->index >= 0)) {
#ifdef DEBUG #ifdef DEBUG
printf ( printf ("Melting tag right into available memory. This was was %i, becomes %i (%i)\n",
"Melting tag right into available memory. This was was %i, becomes %i (%i)\n", tag->real_size, tag->split_right->real_size + tag->real_size,
tag->real_size, tag->split_right->real_size + tag->real_size, tag->split_right->real_size);
tag->split_right->real_size);
#endif #endif
tag = absorb_right (tag); tag = absorb_right (tag);
} }
@@ -481,9 +471,8 @@ void free (void* ptr) {
insert_tag (tag, index); insert_tag (tag, index);
#ifdef DEBUG #ifdef DEBUG
printf ( printf ("Returning tag with %i bytes (requested %i bytes), which has exponent: %i\n",
"Returning tag with %i bytes (requested %i bytes), which has exponent: %i\n", tag->real_size, tag->size, index);
tag->real_size, tag->size, index);
dump_array (); dump_array ();
#endif #endif

View File

@@ -31,8 +31,8 @@ void pmm_init (void) {
"framebuffer", "framebuffer",
"acpi tables"}; "acpi tables"};
DEBUG ("memmap entry: %-25s %p (%zu bytes)\n", entry_strings[entry->type], DEBUG ("memmap entry: %-25s %p (%zu bytes)\n", entry_strings[entry->type], entry->base,
entry->base, entry->length); entry->length);
if (entry->type == LIMINE_MEMMAP_USABLE && region < PMM_REGIONS_MAX) { if (entry->type == LIMINE_MEMMAP_USABLE && region < PMM_REGIONS_MAX) {
struct pmm_region* pmm_region = &pmm.regions[region]; struct pmm_region* pmm_region = &pmm.regions[region];
@@ -87,8 +87,7 @@ void pmm_init (void) {
* Find free space for a block range. For every bit of the bitmap, we test nblks bits forward. * Find free space for a block range. For every bit of the bitmap, we test nblks bits forward.
* bm_test_region helps us out, because it automatically does range checks. See comments there. * bm_test_region helps us out, because it automatically does range checks. See comments there.
*/ */
static size_t pmm_find_free_space (struct pmm_region* pmm_region, static size_t pmm_find_free_space (struct pmm_region* pmm_region, size_t nblks) {
size_t nblks) {
for (size_t bit = 0; bit < pmm_region->bm.nbits; bit++) { for (size_t bit = 0; bit < pmm_region->bm.nbits; bit++) {
if (bm_test_region (&pmm_region->bm, bit, nblks)) { if (bm_test_region (&pmm_region->bm, bit, nblks)) {
continue; continue;
@@ -140,8 +139,7 @@ void pmm_free (physaddr_t p_addr, size_t nblks) {
continue; continue;
/* If aligned_p_addr is within the range if this region, it belongs to it. */ /* If aligned_p_addr is within the range if this region, it belongs to it. */
if (aligned_p_addr >= pmm_region->membase && if (aligned_p_addr >= pmm_region->membase && aligned_p_addr < pmm_region->size) {
aligned_p_addr < pmm_region->size) {
physaddr_t addr = aligned_p_addr - pmm_region->membase; physaddr_t addr = aligned_p_addr - pmm_region->membase;
size_t bit = div_align_up (addr, PAGE_SIZE); size_t bit = div_align_up (addr, PAGE_SIZE);

View File

@@ -7,6 +7,4 @@ void spin_lock (spin_lock_t* sl) {
spin_lock_relax (); spin_lock_relax ();
} }
void spin_unlock (spin_lock_t* sl) { void spin_unlock (spin_lock_t* sl) { atomic_flag_clear_explicit (sl, memory_order_release); }
atomic_flag_clear_explicit (sl, memory_order_release);
}

View File

@@ -3,9 +3,9 @@
void debugprintf (const char* fmt, ...); void debugprintf (const char* fmt, ...);
#define DEBUG(fmt, ...) \ #define DEBUG(fmt, ...) \
do { \ do { \
debugprintf ("%s: " fmt, __func__, ##__VA_ARGS__); \ debugprintf ("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0) } while (0)
#endif // _KERNEL_SYS_DEBUG_H #endif // _KERNEL_SYS_DEBUG_H

View File

@@ -12,8 +12,7 @@
#define MM_PG_USER (1 << 2) #define MM_PG_USER (1 << 2)
#define MM_PD_LOCK (1 << 31) #define MM_PD_LOCK (1 << 31)
void mm_map_page (struct pd* pd, uintptr_t paddr, uintptr_t vaddr, void mm_map_page (struct pd* pd, uintptr_t paddr, uintptr_t vaddr, uint32_t flags);
uint32_t flags);
void mm_map_kernel_page (uintptr_t paddr, uintptr_t vaddr, uint32_t flags); void mm_map_kernel_page (uintptr_t paddr, uintptr_t vaddr, uint32_t flags);
void mm_unmap_page (struct pd* pd, uintptr_t vaddr, uint32_t flags); void mm_unmap_page (struct pd* pd, uintptr_t vaddr, uint32_t flags);
void mm_unmap_kernel_page (uintptr_t vaddr, uint32_t flags); void mm_unmap_kernel_page (uintptr_t vaddr, uint32_t flags);

View File

@@ -11,8 +11,7 @@ uacpi_status uacpi_kernel_get_rsdp (uacpi_phys_addr* out_rsdp_address) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response; struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
struct limine_rsdp_response* rsdp = limine_rsdp_request.response; struct limine_rsdp_response* rsdp = limine_rsdp_request.response;
*out_rsdp_address = *out_rsdp_address = (uacpi_phys_addr)((uintptr_t)rsdp->address - (uintptr_t)hhdm->offset);
(uacpi_phys_addr)((uintptr_t)rsdp->address - (uintptr_t)hhdm->offset);
return UACPI_STATUS_OK; return UACPI_STATUS_OK;
} }