clang-format alignment rules

This commit is contained in:
2025-12-21 23:10:21 +01:00
parent c85cbd0c01
commit 741d0fb9b0
10 changed files with 71 additions and 62 deletions

View File

@@ -40,9 +40,10 @@ PointerAlignment: Left
DerivePointerAlignment: false
# Alignment
AlignAfterOpenBracket: DontAlign
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignOperands: false
# Includes

View File

@@ -14,8 +14,8 @@ void bootmain (void) {
amd64_init ();
pmm_init ();
uacpi_setup_early_table_access (
(void*)uacpi_memory_buffer, sizeof (uacpi_memory_buffer));
uacpi_setup_early_table_access ((void*)uacpi_memory_buffer,
sizeof (uacpi_memory_buffer));
int* a = malloc (sizeof (int));
*a = 6969;

View File

@@ -5,7 +5,7 @@
#include <libk/string.h>
#include <sys/debug.h>
#define PORT_COM1 0x03F8
#define PORT_COM1 0x03F8
#define BUFFER_SIZE 1024
static bool amd64_debug_serial_tx_empty (void) {

View File

@@ -10,9 +10,9 @@
#define GDT_KDATA 0x10
#define GDT_UCODE 0x18
#define GDT_UDATA 0x20
#define GDT_TSS 0x28
#define GDT_TSS 0x28
#define TSS 0x80
#define TSS 0x80
#define TSS_PRESENT 0x89
#define KSTACK_SIZE (8 * 1024)
@@ -41,7 +41,7 @@ ALIGNED (16) static volatile uint8_t kernel_stack[KSTACK_SIZE];
ALIGNED (16) static volatile struct gdt_extended gdt;
static void amd64_gdt_set (volatile struct gdt_entry* ent, uint32_t base,
uint32_t limit, uint8_t acc, uint8_t gran) {
uint32_t limit, uint8_t acc, uint8_t gran) {
ent->baselow = (base & 0xFFFF);
ent->basemid = (base >> 16) & 0xFF;
ent->basehigh = (base >> 24) & 0xFF;
@@ -68,8 +68,8 @@ static void amd64_gdt_init (void) {
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[4], 0, 0xFFFFF, 0xF2, 0xC0);
amd64_gdt_set (
&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit, TSS_PRESENT | TSS, 0);
amd64_gdt_set (&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit,
TSS_PRESENT | TSS, 0);
uint32_t tssbasehigh = (tssbase >> 32);
gdt.tsshigh.limitlow = (tssbasehigh & 0xFFFF);
@@ -93,9 +93,9 @@ static void amd64_gdt_init (void) {
"movw %%ax, %%ds\n"
"movw %%ax, %%es\n"
"movw %%ax, %%ss\n"
:
: [kcode] "i"(GDT_KCODE), [kdata] "i"(GDT_KDATA)
: "rax", "memory");
:
: [kcode] "i"(GDT_KCODE), [kdata] "i"(GDT_KDATA)
: "rax", "memory");
__asm__ volatile ("ltr %0" ::"r"((uint16_t)GDT_TSS));
}

View File

@@ -6,25 +6,25 @@
#include <sys/debug.h>
/* 8259 PIC defs. */
#define PIC1 0x20
#define PIC2 0xA0
#define PIC1_CMD PIC1
#define PIC1 0x20
#define PIC2 0xA0
#define PIC1_CMD PIC1
#define PIC1_DATA (PIC1 + 1)
#define PIC2_CMD PIC2
#define PIC2_CMD PIC2
#define PIC2_DATA (PIC2 + 1)
#define PIC_EOI 0x20
#define PIC_EOI 0x20
#define ICW1_ICW4 0x01
#define ICW1_ICW4 0x01
#define ICW1_SINGLE 0x02
#define ICW1_INTVL4 0x04
#define ICW1_LEVEL 0x08
#define ICW1_INIT 0x10
#define ICW1_LEVEL 0x08
#define ICW1_INIT 0x10
#define ICW4_8086 0x01
#define ICW4_AUTO 0x02
#define ICW4_8086 0x01
#define ICW4_AUTO 0x02
#define ICW4_BUFSLAVE 0x08
#define ICW4_BUFMASER 0x0C
#define ICW4_SFNM 0x10
#define ICW4_SFNM 0x10
#define CASCADE_IRQ 2
@@ -77,8 +77,8 @@ static void amd64_init_pic (void) {
#undef IO_OP
}
static void amd64_idt_set (
volatile struct idt_entry* ent, uint64_t handler, uint8_t flags) {
static void amd64_idt_set (volatile struct idt_entry* ent, uint64_t handler,
uint8_t flags) {
ent->intrlow = (handler & 0xFFFF);
ent->kernel_cs = 0x08; // GDT_KCODE (init.c)
ent->ist = 0;
@@ -167,10 +167,11 @@ static void amd64_intr_exception (struct saved_regs* regs) {
"err=%016lx rip=%016lx cs =%016lx\n"
"rfl=%016lx rsp=%016lx ss =%016lx\n"
"cr2=%016lx cr3=%016lx rbx=%016lx\n",
regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10,
regs->r9, regs->r8, regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rcx,
regs->rax, regs->trap, regs->error, regs->rip, regs->cs, regs->rflags,
regs->rsp, regs->ss, cr2, cr3, regs->rbx);
regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10,
regs->r9, regs->r8, regs->rbp, regs->rdi, regs->rsi, regs->rdx,
regs->rcx, regs->rax, regs->trap, regs->error, regs->rip,
regs->cs, regs->rflags, regs->rsp, regs->ss, cr2, cr3,
regs->rbx);
amd64_spin ();
}

View File

@@ -15,9 +15,9 @@ void amd64_io_outl (uint16_t port, uint32_t v) {
void amd64_io_outsw (uint16_t port, const void* addr, int cnt) {
__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) {
@@ -40,9 +40,9 @@ uint32_t amd64_io_inl (uint16_t port) {
void amd64_io_insw (uint16_t port, void* addr, int cnt) {
__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); }

View File

@@ -1,8 +1,8 @@
#ifndef _KERNEL_AUX_COMPILER_H
#define _KERNEL_AUX_COMPILER_H
#define PACKED __attribute__((packed))
#define ALIGNED(N) __attribute__((aligned((N))))
#define SECTION(name) __attribute__((section(name)))
#define PACKED __attribute__ ((packed))
#define ALIGNED(N) __attribute__ ((aligned ((N))))
#define SECTION(name) __attribute__ ((section (name)))
#endif // _KERNEL_AUX_COMPILER_H

View File

@@ -2,7 +2,7 @@
#define _KERNEL_LIBK_ALIGN_H
#define div_align_up(x, div) (((x) + (div) - 1) / (div))
#define align_down(x, a) ((x) & ~((a) - 1))
#define align_up(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#define align_down(x, a) ((x) & ~((a) - 1))
#define align_up(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#endif // _KERNEL_LIBK_ALIGN_H

View File

@@ -46,11 +46,11 @@ int liballoc_free (void* ptr, int pages) {
//#define DEBUG
#define LIBALLOC_MAGIC 0xc001c0de
#define MAXCOMPLETE 5
#define MAXEXP 32
#define MINEXP 8
#define MAXCOMPLETE 5
#define MAXEXP 32
#define MINEXP 8
#define MODE_BEST 0
#define MODE_BEST 0
#define MODE_INSTANT 1
#define MODE MODE_BEST
@@ -95,7 +95,7 @@ static inline int getexp (unsigned int size) {
#ifdef DEBUG
printf ("getexp returns %i (%i bytes) for %i size\n", shift - 1,
(1 << (shift - 1)), size);
(1 << (shift - 1)), size);
#endif
return shift - 1;
@@ -226,8 +226,9 @@ static inline struct boundary_tag* split_tag (struct boundary_tag* tag) {
unsigned int remainder =
tag->real_size - sizeof (struct boundary_tag) - tag->size;
struct boundary_tag* new_tag = (struct boundary_tag*)((uintptr_t)tag +
sizeof (struct boundary_tag) + tag->size);
struct boundary_tag* new_tag =
(struct boundary_tag*)((uintptr_t)tag + sizeof (struct boundary_tag) +
tag->size);
new_tag->magic = LIBALLOC_MAGIC;
new_tag->real_size = remainder;
@@ -285,7 +286,7 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
#ifdef DEBUG
printf ("Resource allocated %x of %i pages (%i bytes) for %i size.\n", tag,
pages, pages * l_pageSize, size);
pages, pages * l_pageSize, size);
l_allocated += pages * l_pageSize;
@@ -325,8 +326,8 @@ void* malloc (size_t size) {
(size + sizeof (struct boundary_tag))) {
#ifdef DEBUG
printf ("Tag search found %i >= %i\n",
(tag->real_size - sizeof (struct boundary_tag)),
(size + sizeof (struct boundary_tag)));
(tag->real_size - sizeof (struct boundary_tag)),
(size + sizeof (struct boundary_tag)));
#endif
break;
}
@@ -366,13 +367,13 @@ void* malloc (size_t size) {
sizeof (struct boundary_tag) * 2; // Support a new tag + remainder
if (((int)(remainder) >
0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/) {
0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/) {
int childIndex = getexp (remainder);
if (childIndex >= 0) {
#ifdef DEBUG
printf ("Seems to be splittable: %i >= 2^%i .. %i\n", remainder,
childIndex, (1 << childIndex));
childIndex, (1 << childIndex));
#endif
struct boundary_tag* new_tag = split_tag (tag);
@@ -381,7 +382,7 @@ void* malloc (size_t size) {
#ifdef DEBUG
printf ("Old tag has become %i bytes, new tag is now %i bytes (%i exp)\n",
tag->real_size, new_tag->real_size, new_tag->index);
tag->real_size, new_tag->real_size, new_tag->index);
#endif
}
}
@@ -391,7 +392,7 @@ void* malloc (size_t size) {
#ifdef DEBUG
l_inuse += size;
printf ("malloc: %x, %i, %i\n", ptr, (int)l_inuse / 1024,
(int)l_allocated / 1024);
(int)l_allocated / 1024);
dump_array ();
#endif
@@ -417,8 +418,8 @@ void free (void* ptr) {
#ifdef DEBUG
l_inuse -= tag->size;
printf (
"free: %x, %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024);
printf ("free: %x, %i, %i\n", ptr, (int)l_inuse / 1024,
(int)l_allocated / 1024);
#endif
// MELT LEFT...

View File

@@ -21,12 +21,18 @@ void pmm_init (void) {
size_t region = 0;
for (size_t i = 0; i < memmap->entry_count; i++) {
struct limine_memmap_entry* entry = memmap->entries[i];
static const char* entry_strings[] = {"usable", "reserved",
"acpi reclaimable", "acpi nvs", "bad memory", "bootloader reclaimable",
"executable and modules", "framebuffer", "acpi tables"};
static const char* entry_strings[] = {"usable",
"reserved",
"acpi reclaimable",
"acpi nvs",
"bad memory",
"bootloader reclaimable",
"executable and modules",
"framebuffer",
"acpi tables"};
DEBUG ("memmap entry: %-25s %p (%zu bytes)\n", entry_strings[entry->type],
entry->base, entry->length);
entry->base, entry->length);
if (entry->type == LIMINE_MEMMAP_USABLE && region < PMM_REGIONS_MAX) {
struct pmm_region* pmm_region = &pmm.regions[region];
@@ -81,8 +87,8 @@ void pmm_init (void) {
* 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.
*/
static size_t pmm_find_free_space (
struct pmm_region* pmm_region, size_t nblks) {
static size_t pmm_find_free_space (struct pmm_region* pmm_region,
size_t nblks) {
for (size_t bit = 0; bit < pmm_region->bm.nbits; bit++) {
if (bm_test_region (&pmm_region->bm, bit, nblks)) {
continue;