formatting

This commit is contained in:
trimill 2024-02-03 21:05:27 -05:00
parent 6b49a206c2
commit 85a9443704
No known key found for this signature in database
GPG key ID: 4F77A16E17E10BCB
14 changed files with 127 additions and 127 deletions

View file

@ -10,7 +10,7 @@ size_t backtrace(void **dst, size_t len);
size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp); size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp);
// Log a backtrace // Log a backtrace
void log_backtrace(); void log_backtrace(void);
// same as log_backtrace with specified insruction and base pointer // same as log_backtrace with specified insruction and base pointer
void log_backtrace_ex(void *ip, void *bp); void log_backtrace_ex(void *ip, void *bp);

View file

@ -1,3 +1,3 @@
#pragma once #pragma once
void enable_fpu(); void enable_fpu(void);

View file

@ -4,7 +4,7 @@
#define _PANIC_STR2(x) #x #define _PANIC_STR2(x) #x
#define panic(...) _panic_impl(_PANIC_STR(__LINE__), __FILE__, __VA_ARGS__) #define panic(...) _panic_impl(_PANIC_STR(__LINE__), __FILE__, __VA_ARGS__)
#define kassert(val, ...) do { if (!(val)) { panic(__VA_ARGS__); } } while(0) #define kassert(val, ...) do { if (!(val)) { panic(__VA_ARGS__); } } while (0)
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 3, 4)))
_Noreturn void _panic_impl(char *line, char *file, char *format, ...); _Noreturn void _panic_impl(char *line, char *file, char *format, ...);

View file

@ -26,7 +26,7 @@ size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp) {
return i; return i;
} }
void log_backtrace() { void log_backtrace(void) {
struct stackframe *rbp; struct stackframe *rbp;
__asm__ ("mov %%rbp, %0" : "=r"(rbp)); __asm__ ("mov %%rbp, %0" : "=r"(rbp));
log_backtrace_ex(rbp->rip, rbp->rbp); log_backtrace_ex(rbp->rip, rbp->rbp);

View file

@ -103,7 +103,7 @@ static size_t debugger_read(char *buf, size_t len) {
end: end:
result = p - buf; result = p - buf;
kputc('\n'); kputc('\n');
for(; p < buf + len; p++) { for (; p < buf + len; p++) {
*p = 0; *p = 0;
} }
return result; return result;
@ -161,24 +161,24 @@ static void debugger_print_regs(struct isr_regs *state) {
kprintf("rflags: %#016lx (%lu)\n", state->rflags, state->rflags); kprintf("rflags: %#016lx (%lu)\n", state->rflags, state->rflags);
struct rflags *rflags = (struct rflags *)state->rflags; struct rflags *rflags = (struct rflags *)state->rflags;
kputs("rflags: "); kputs("rflags: ");
if(rflags->cf) kputs("CF "); if (rflags->cf) kputs("CF ");
if(rflags->pf) kputs("PF "); if (rflags->pf) kputs("PF ");
if(rflags->af) kputs("AF "); if (rflags->af) kputs("AF ");
if(rflags->zf) kputs("ZF "); if (rflags->zf) kputs("ZF ");
if(rflags->sf) kputs("SF "); if (rflags->sf) kputs("SF ");
if(rflags->tf) kputs("TF "); if (rflags->tf) kputs("TF ");
if(rflags->if_) kputs("IF "); if (rflags->if_) kputs("IF ");
if(rflags->df) kputs("DF "); if (rflags->df) kputs("DF ");
if(rflags->of) kputs("OF "); if (rflags->of) kputs("OF ");
if(rflags->iopl) kputs("IOPL "); if (rflags->iopl) kputs("IOPL ");
if(rflags->nt) kputs("NT "); if (rflags->nt) kputs("NT ");
if(rflags->md) kputs("MD "); if (rflags->md) kputs("MD ");
if(rflags->rf) kputs("RF "); if (rflags->rf) kputs("RF ");
if(rflags->vm) kputs("VM "); if (rflags->vm) kputs("VM ");
if(rflags->ac) kputs("AC "); if (rflags->ac) kputs("AC ");
if(rflags->vif) kputs("VIF "); if (rflags->vif) kputs("VIF ");
if(rflags->vip) kputs("VIP "); if (rflags->vip) kputs("VIP ");
if(rflags->id) kputs("ID "); if (rflags->id) kputs("ID ");
kputs("\n"); kputs("\n");
} }
@ -189,7 +189,7 @@ static int debugger_handle_bkp_cmd(char *msg) {
// list breakpoints // list breakpoints
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
struct breakpoint bkp = bkps[i]; struct breakpoint bkp = bkps[i];
if(!bkp.used) { if (!bkp.used) {
kprintf("breakpoint %d: unset\n", i); kprintf("breakpoint %d: unset\n", i);
continue; continue;
} }
@ -278,7 +278,7 @@ static int debugger_handle_bkp_cmd(char *msg) {
} }
} }
static void debugger_load_bkps() { static void debugger_load_bkps(void) {
struct dr7 dr7; struct dr7 dr7;
__asm__ volatile ("mov %%dr7, %0" : "=r"(dr7)); __asm__ volatile ("mov %%dr7, %0" : "=r"(dr7));
dr7.g0 = bkps[0].enable & bkps[0].used; dr7.g0 = bkps[0].enable & bkps[0].used;

View file

@ -26,4 +26,4 @@ struct isr_regs {
uint64_t ss; uint64_t ss;
}; };
void idt_init(); void idt_init(void);

View file

@ -53,7 +53,7 @@ static void set_mode(uint16_t width, uint16_t height, uint16_t bit_depth, int lf
(clear ? 0 : DATA_NO_CLEAR_MEM)); (clear ? 0 : DATA_NO_CLEAR_MEM));
} }
volatile uint32_t* bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth) { volatile uint32_t *bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth) {
set_mode(width, height, bit_depth, true, true); set_mode(width, height, bit_depth, true, true);
@ -66,7 +66,7 @@ volatile uint32_t* bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth
return NULL; return NULL;
uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D); uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D);
uint32_t *addr = (uint32_t*) (uintptr_t) bar0; uint32_t *addr = (uint32_t *) (uintptr_t) bar0;
addr = mmap(addr, width * height * bit_depth); addr = mmap(addr, width * height * bit_depth);
return addr; return addr;

View file

@ -88,7 +88,7 @@ static void print_device(struct pci_table_entry *entry) {
} }
static struct pci_table_entry *load_device(struct pci_device dev) { static struct pci_table_entry *load_device(struct pci_device dev) {
if(pci_table_next >= TABLE_LEN) panic("Too many PCI devices: limit is %d", TABLE_LEN); if (pci_table_next >= TABLE_LEN) panic("Too many PCI devices: limit is %d", TABLE_LEN);
struct pci_table_entry *entry = &pci_table[pci_table_next++]; struct pci_table_entry *entry = &pci_table[pci_table_next++];
entry->device = dev; entry->device = dev;
uint32_t dword0 = pci_rcfg_d(dev, 0); uint32_t dword0 = pci_rcfg_d(dev, 0);
@ -108,25 +108,25 @@ static struct pci_table_entry *load_device(struct pci_device dev) {
void pci_init(void) { void pci_init(void) {
pci_table_next = 0; pci_table_next = 0;
struct pci_device pcidev; struct pci_device pcidev;
for(int bus = 0; bus < 256; bus++) { for (int bus = 0; bus < 256; bus++) {
pcidev.bus = bus; pcidev.bus = bus;
for(int dev = 0; dev < 32; dev++) { for (int dev = 0; dev < 32; dev++) {
pcidev.device = dev; pcidev.device = dev;
pcidev.function = 0; pcidev.function = 0;
uint16_t vendor = pci_rcfg_w(pcidev, 0); uint16_t vendor = pci_rcfg_w(pcidev, 0);
if(vendor == 0xFFFF) continue; if (vendor == 0xFFFF) continue;
load_device(pcidev); load_device(pcidev);
uint8_t header_type = pci_rcfg_b(pcidev, 14); uint8_t header_type = pci_rcfg_b(pcidev, 14);
if(!(header_type & 0x80)) continue; if (!(header_type & 0x80)) continue;
for(int func = 1; func < 8; func++) { for (int func = 1; func < 8; func++) {
pcidev.function = func; pcidev.function = func;
uint16_t vendor = pci_rcfg_w(pcidev, 0); uint16_t vendor = pci_rcfg_w(pcidev, 0);
if(vendor == 0xFFFF) continue; if (vendor == 0xFFFF) continue;
load_device(pcidev); load_device(pcidev);
} }
@ -141,10 +141,10 @@ void pci_init(void) {
bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass, size_t *offset) { bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass, size_t *offset) {
size_t o = 0; size_t o = 0;
if(offset == NULL) offset = &o; if (offset == NULL) offset = &o;
for(; *offset < pci_table_next; (*offset)++) { for (; *offset < pci_table_next; (*offset)++) {
struct pci_table_entry *entry = &pci_table[*offset]; struct pci_table_entry *entry = &pci_table[*offset];
if(entry->class == class && entry->subclass == subclass) { if (entry->class == class && entry->subclass == subclass) {
*dest = entry->device; *dest = entry->device;
return true; return true;
} }
@ -154,10 +154,10 @@ bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass,
bool pci_findby_id(struct pci_device *dest, uint16_t device, uint16_t vendor, size_t *offset) { bool pci_findby_id(struct pci_device *dest, uint16_t device, uint16_t vendor, size_t *offset) {
size_t o = 0; size_t o = 0;
if(offset == NULL) offset = &o; if (offset == NULL) offset = &o;
for(; *offset < pci_table_next; (*offset)++) { for (; *offset < pci_table_next; (*offset)++) {
struct pci_table_entry *entry = &pci_table[*offset]; struct pci_table_entry *entry = &pci_table[*offset];
if(entry->device_id == device && entry->vendor_id == vendor) { if (entry->device_id == device && entry->vendor_id == vendor) {
*dest = entry->device; *dest = entry->device;
return true; return true;
} }

View file

@ -3,7 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <lib.h> #include <lib.h>
void enable_fpu() { void enable_fpu(void) {
size_t cr4; size_t cr4;
uint16_t cw = 0x37F; uint16_t cw = 0x37F;
__asm__ volatile ("mov %%cr4, %0" : "=r"(cr4)); __asm__ volatile ("mov %%cr4, %0" : "=r"(cr4));

View file

@ -174,7 +174,7 @@ static void read_memory_map(
uintptr_t i = (uintptr_t)map->entries; uintptr_t i = (uintptr_t)map->entries;
kprintf("MEMORY MAP\n"); kprintf("MEMORY MAP\n");
char buf[20]; char buf[20];
for ( ; for (;
i < (uintptr_t)map->entries + map->size; i < (uintptr_t)map->entries + map->size;
i += map->entry_size, idx++ i += map->entry_size, idx++
) { ) {

View file

@ -113,7 +113,7 @@ void virtaddr_init(void) {
} }
static void merge_back(struct addr_node *node) { static void merge_back(struct addr_node *node) {
while(node->prev) { while (node->prev) {
if (node->is_alloc != node->prev->is_alloc) if (node->is_alloc != node->prev->is_alloc)
break; break;
struct addr_node *temp = node->prev; struct addr_node *temp = node->prev;
@ -129,7 +129,7 @@ static void merge_back(struct addr_node *node) {
} }
static void merge_forward(struct addr_node *node) { static void merge_forward(struct addr_node *node) {
while(node->next) { while (node->next) {
if (node->is_alloc != node->next->is_alloc) if (node->is_alloc != node->next->is_alloc)
break; break;
struct addr_node *temp = node->next; struct addr_node *temp = node->next;