kernel: don't use typedef for enums or non-opaque structs

This commit is contained in:
2023-04-12 20:17:11 +01:00
parent 0d75e347e9
commit b6f8c1ccaa
51 changed files with 663 additions and 665 deletions

View File

@@ -48,7 +48,7 @@ int ml_init(uintptr_t arg)
memblock_add(0, PMEM_SIZE);
vm_zone_descriptor_t vm_zones[] = {
struct vm_zone_descriptor vm_zones[] = {
{ .zd_id = VM_ZONE_DMA, .zd_node = 0, .zd_name = "dma", .zd_base = 0x00, .zd_limit = 0xffffff },
{ .zd_id = VM_ZONE_NORMAL, .zd_node = 0, .zd_name = "normal", .zd_base = 0x1000000, .zd_limit = UINTPTR_MAX },
};

View File

@@ -6,14 +6,14 @@
#include <socks/vm.h>
#include <socks/printk.h>
static void stdcon_write(console_t *con, const char *s, unsigned int len)
static void stdcon_write(struct console *con, const char *s, unsigned int len)
{
for (unsigned int i = 0; i < len; i++) {
fputc(s[i], stdout);
}
}
static console_t stdcon = {
static struct console stdcon = {
.c_name = "stdcon",
.c_flags = CON_BOOT,
.c_write = stdcon_write,

View File

@@ -20,7 +20,7 @@ static int apic_enabled = 0;
using namespace arch::acpi;
static uint32_t *lapic_base;
static queue_t io_apics;
static struct queue io_apics;
extern "C" {
/* defined in apic_ctrl.S */

View File

@@ -10,7 +10,7 @@ namespace arch::acpi {
uint32_t *io_base = nullptr;
unsigned int io_first_irq = 0;
unsigned int io_nr_irq = 0;
queue_entry_t io_entry;
struct queue_entry io_entry;
struct irq_entry {
uint64_t irq_vec : 8;

View File

@@ -11,7 +11,7 @@ extern "C" {
#define NR_IDT_ENTRIES 48
typedef enum irq_vector {
enum irq_vector {
IRQ0 = 32,
IRQ1,
IRQ2,
@@ -28,12 +28,12 @@ typedef enum irq_vector {
IRQ13,
IRQ14,
IRQ15,
} irq_vector_t;
};
typedef struct irq_hook {
queue_entry_t irq_entry;
struct irq_hook {
struct queue_entry irq_entry;
int (*irq_callback)(void);
} irq_hook_t;
};
struct cpu_context {
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
@@ -69,8 +69,8 @@ typedef void (*int_hook)(struct cpu_context *);
extern int idt_init(struct idt_ptr *idtp);
extern int idt_load(struct idt_ptr *idtp);
extern void hook_irq(irq_vector_t vec, irq_hook_t *hook);
extern void unhook_irq(irq_vector_t vec, irq_hook_t *hook);
extern void hook_irq(enum irq_vector vec, struct irq_hook *hook);
extern void unhook_irq(enum irq_vector vec, struct irq_hook *hook);
#ifdef __cplusplus
}

View File

@@ -19,37 +19,37 @@ extern "C" {
typedef phys_addr_t pml4t_ptr_t;
typedef uint64_t pte_t;
typedef struct pml4t {
struct pml4t {
phys_addr_t p_entries[512];
} __packed pml4t_t;
} __packed;
typedef struct pdpt {
struct pdpt {
union {
/* 4KiB and 2MiB pages */
phys_addr_t p_entries[512];
/* 1GiB pages */
pte_t p_pages[512];
};
} __packed pdpt_t;
} __packed;
typedef struct pdir {
struct pdir {
union {
/* 4KiB pages */
phys_addr_t p_entries[512];
/* 2MiB pages */
pte_t p_pages[512];
};
} __packed pdir_t;
} __packed;
typedef struct ptab {
struct ptab {
pte_t p_pages[512];
} __packed ptab_t;
} __packed;
typedef enum page_size {
enum page_size {
PS_4K,
PS_2M,
PS_1G,
} page_size_t;
};
/* returns 1 if gigabyte pages are supported by the CPU, 0 otherwise.
defined in pmap_ctrl.S */

View File

@@ -58,13 +58,13 @@ int ml_init(uintptr_t arg)
acpi_scan_cpu_topology();
init_per_cpu_areas();
cpu_data_t *this_cpu = get_this_cpu();
struct cpu_data *this_cpu = get_this_cpu();
this_cpu->c_flags = CPU_ONLINE;
this_cpu->c_id = this_cpu();
g_bootstrap_cpu.c_data = this_cpu;
put_cpu(this_cpu);
vm_zone_descriptor_t vm_zones[] = {
struct vm_zone_descriptor vm_zones[] = {
{ .zd_id = VM_ZONE_DMA, .zd_node = 0, .zd_name = "dma", .zd_base = 0x00, .zd_limit = 0xffffff },
{ .zd_id = VM_ZONE_NORMAL, .zd_node = 0, .zd_name = "normal", .zd_base = 0x1000000, .zd_limit = UINTPTR_MAX },
};

View File

@@ -64,7 +64,7 @@ extern void syscall_gate();
extern uintptr_t pf_faultptr(void);
static int_hook isr_handlers[NR_IDT_ENTRIES];
static queue_t irq_hooks[32];
static struct queue irq_hooks[32];
static struct idt idt;
static int idt_initialised = 0;
@@ -233,8 +233,8 @@ void isr_dispatch(struct cpu_context *regs)
void irq_dispatch(struct cpu_context *regs)
{
irq_ack(regs->int_no);
queue_t *hooks = &irq_hooks[regs->int_no - IRQ0];
queue_foreach(irq_hook_t, hook, hooks, irq_entry) {
struct queue *hooks = &irq_hooks[regs->int_no - IRQ0];
queue_foreach(struct irq_hook, hook, hooks, irq_entry) {
hook->irq_callback();
}
}
@@ -244,14 +244,14 @@ void syscall_dispatch(struct cpu_context *regs)
}
void hook_irq(irq_vector_t vec, irq_hook_t *hook)
void hook_irq(enum irq_vector vec, struct irq_hook *hook)
{
queue_t *hook_queue = &irq_hooks[vec - IRQ0];
struct queue *hook_queue = &irq_hooks[vec - IRQ0];
queue_push_back(hook_queue, &hook->irq_entry);
}
void unhook_irq(irq_vector_t vec, irq_hook_t *hook)
void unhook_irq(enum irq_vector vec, struct irq_hook *hook)
{
queue_t *hook_queue = &irq_hooks[vec - IRQ0];
struct queue *hook_queue = &irq_hooks[vec - IRQ0];
queue_delete(hook_queue, &hook->irq_entry);
}

View File

@@ -11,7 +11,7 @@ static int pit_callback(void)
return 0;
}
static irq_hook_t pit_irq_hook = {
static struct irq_hook pit_irq_hook = {
.irq_callback = pit_callback
};

View File

@@ -19,7 +19,7 @@
static int can_use_gbpages = 0;
static pmap_t kernel_pmap;
static size_t ps_size(page_size_t ps)
static size_t ps_size(enum page_size ps)
{
switch (ps) {
case PS_4K:
@@ -35,11 +35,11 @@ static size_t ps_size(page_size_t ps)
static pmap_t alloc_pmap()
{
pml4t_t *p = kzalloc(sizeof *p, 0);
struct pml4t *p = kzalloc(sizeof *p, 0);
return vm_virt_to_phys(p);
}
static pte_t make_pte(pfn_t pfn, vm_prot_t prot, page_size_t size)
static pte_t make_pte(pfn_t pfn, enum vm_prot prot, enum page_size size)
{
pte_t v = pfn;
@@ -95,7 +95,7 @@ static void delete_ptab(phys_addr_t pt)
return;
}
ptab_t *ptab = vm_phys_to_virt(pt);
struct ptab *ptab = vm_phys_to_virt(pt);
kfree(ptab);
}
@@ -112,7 +112,7 @@ static void delete_pdir(phys_addr_t pd)
return;
}
pdir_t *pdir = vm_phys_to_virt(pd);
struct pdir *pdir = vm_phys_to_virt(pd);
for (int i = 0; i < 512; i++) {
if (pdir->p_pages[i] & PTE_PAGESIZE) {
/* this is a hugepage, there is nothing to delete */
@@ -125,7 +125,7 @@ static void delete_pdir(phys_addr_t pd)
kfree(pdir);
}
static kern_status_t do_pmap_add(pmap_t pmap, void *p, pfn_t pfn, vm_prot_t prot, page_size_t size)
static kern_status_t do_pmap_add(pmap_t pmap, void *p, pfn_t pfn, enum vm_prot prot, enum page_size size)
{
uintptr_t pv = (uintptr_t)p;
unsigned int
@@ -158,13 +158,13 @@ static kern_status_t do_pmap_add(pmap_t pmap, void *p, pfn_t pfn, vm_prot_t prot
}
/* 1. get PML4T (mandatory) */
pml4t_t *pml4t = vm_phys_to_virt(ENTRY_TO_PTR(pmap));
struct pml4t *pml4t = vm_phys_to_virt(ENTRY_TO_PTR(pmap));
if (!pml4t) {
return KERN_INVALID_ARGUMENT;
}
/* 2. traverse PML4T, get PDPT (mandatory) */
pdpt_t *pdpt = NULL;
struct pdpt *pdpt = NULL;
if (!pml4t->p_entries[pml4t_index]) {
pdpt = kzalloc(sizeof *pdpt, 0);
pml4t->p_entries[pml4t_index] = PTR_TO_ENTRY(vm_virt_to_phys(pdpt));
@@ -187,7 +187,7 @@ static kern_status_t do_pmap_add(pmap_t pmap, void *p, pfn_t pfn, vm_prot_t prot
/* 3. traverse PDPT, get PDIR (optional, 4K and 2M only) */
pdir_t *pdir = NULL;
struct pdir *pdir = NULL;
if (!pdpt->p_entries[pdpt_index] || pdpt->p_pages[pdpt_index] & PTE_PAGESIZE) {
/* entry is null, or points to a hugepage */
pdir = kzalloc(sizeof *pdir, 0);
@@ -209,7 +209,7 @@ static kern_status_t do_pmap_add(pmap_t pmap, void *p, pfn_t pfn, vm_prot_t prot
}
/* 4. traverse PDIR, get PTAB (optional, 4K only) */
ptab_t *ptab = NULL;
struct ptab *ptab = NULL;
if (!pdir->p_entries[pd_index] || pdir->p_pages[pd_index] & PTE_PAGESIZE) {
/* entry is null, or points to a hugepage */
ptab = kzalloc(sizeof *ptab, 0);
@@ -234,7 +234,7 @@ void pmap_bootstrap(void)
enable_nx();
printk("pmap: NX protection enabled");
page_size_t hugepage = PS_2M;
enum page_size hugepage = PS_2M;
if (can_use_gbpages) {
hugepage = PS_1G;
}
@@ -255,7 +255,7 @@ void pmap_bootstrap(void)
}
phys_addr_t pmem_limit = 0x0;
memblock_iter_t it;
struct memblock_iter it;
for_each_mem_range(&it, 0x00, UINTPTR_MAX) {
if (it.it_limit > pmem_limit) {
pmem_limit = it.it_limit;
@@ -283,12 +283,12 @@ void pmap_destroy(pmap_t pmap)
}
kern_status_t pmap_add(pmap_t pmap, void *p, pfn_t pfn, vm_prot_t prot, pmap_flags_t flags)
kern_status_t pmap_add(pmap_t pmap, void *p, pfn_t pfn, enum vm_prot prot, enum pmap_flags flags)
{
return KERN_OK;
}
kern_status_t pmap_add_block(pmap_t pmap, void *p, pfn_t pfn, size_t len, vm_prot_t prot, pmap_flags_t flags)
kern_status_t pmap_add_block(pmap_t pmap, void *p, pfn_t pfn, size_t len, enum vm_prot prot, enum pmap_flags flags)
{
return KERN_OK;
}

View File

@@ -101,14 +101,14 @@ static void vgacon_putchar(int c)
move_vga_cursor(g_console_cursor_xpos, g_console_cursor_ypos);
}
static void vgacon_write(console_t *con, const char *s, unsigned int len)
static void vgacon_write(struct console *con, const char *s, unsigned int len)
{
for (unsigned int i = 0; i < len; i++) {
vgacon_putchar(s[i]);
}
}
static console_t vgacon = {
static struct console vgacon = {
.c_name = "vgacon",
.c_flags = CON_BOOT,
.c_write = vgacon_write,