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);
// Log a backtrace
void log_backtrace();
void log_backtrace(void);
// same as log_backtrace with specified insruction and base pointer
void log_backtrace_ex(void *ip, void *bp);

View file

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

View file

@ -324,7 +324,7 @@ unsigned long long int strtoull(const char *str, char **endptr, int base);
* - If the value has two or three decimal digits, print it followed by the
* approprate suffix.
* - If the value has one decimal digit, print it along with a single fractional
* digit. This also applies if the value is zero.
* digit. This also applies if the value is zero.
*
* @param bytes - the bytes to convert
* @param buf - a pointer to the buffer to store it in (which must be at least five

View file

@ -4,7 +4,7 @@
#define _PANIC_STR2(x) #x
#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)))
_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;
}
void log_backtrace() {
void log_backtrace(void) {
struct stackframe *rbp;
__asm__ ("mov %%rbp, %0" : "=r"(rbp));
log_backtrace_ex(rbp->rip, rbp->rbp);

View file

@ -8,64 +8,64 @@
struct dr6 {
uint64_t b0 : 1,
b1 : 1,
b2 : 1,
b3 : 1,
: 7,
bld : 1,
: 1,
bd : 1,
bs : 1,
bt : 1,
rtm : 1,
: 47;
b2 : 1,
b3 : 1,
: 7,
bld : 1,
: 1,
bd : 1,
bs : 1,
bt : 1,
rtm : 1,
: 47;
};
struct dr7 {
uint64_t l0 : 1,
g0 : 1,
l1 : 1,
g1 : 1,
l2 : 1,
g2 : 1,
l3 : 1,
g3 : 1,
: 8,
rw0 : 2,
len0 : 2,
rw1 : 2,
len1 : 2,
rw2 : 2,
len2 : 2,
rw3 : 2,
len3 : 2,
: 32;
l1 : 1,
g1 : 1,
l2 : 1,
g2 : 1,
l3 : 1,
g3 : 1,
: 8,
rw0 : 2,
len0 : 2,
rw1 : 2,
len1 : 2,
rw2 : 2,
len2 : 2,
rw3 : 2,
len3 : 2,
: 32;
};
struct rflags {
uint64_t cf : 1,
: 1,
pf : 1,
: 1,
af : 1,
: 1,
zf : 1,
sf : 1,
: 1,
pf : 1,
: 1,
af : 1,
: 1,
zf : 1,
sf : 1,
tf : 1,
if_ : 1,
df : 1,
of : 1,
iopl : 2,
nt : 1,
md : 1,
tf : 1,
if_ : 1,
df : 1,
of : 1,
iopl : 2,
nt : 1,
md : 1,
rf : 1,
vm : 1,
ac : 1,
vif : 1,
vip : 1,
id : 1,
: 42;
rf : 1,
vm : 1,
ac : 1,
vif : 1,
vip : 1,
id : 1,
: 42;
};
struct breakpoint {
@ -103,7 +103,7 @@ static size_t debugger_read(char *buf, size_t len) {
end:
result = p - buf;
kputc('\n');
for(; p < buf + len; p++) {
for (; p < buf + len; p++) {
*p = 0;
}
return result;
@ -161,24 +161,24 @@ static void debugger_print_regs(struct isr_regs *state) {
kprintf("rflags: %#016lx (%lu)\n", state->rflags, state->rflags);
struct rflags *rflags = (struct rflags *)state->rflags;
kputs("rflags: ");
if(rflags->cf) kputs("CF ");
if(rflags->pf) kputs("PF ");
if(rflags->af) kputs("AF ");
if(rflags->zf) kputs("ZF ");
if(rflags->sf) kputs("SF ");
if(rflags->tf) kputs("TF ");
if(rflags->if_) kputs("IF ");
if(rflags->df) kputs("DF ");
if(rflags->of) kputs("OF ");
if(rflags->iopl) kputs("IOPL ");
if(rflags->nt) kputs("NT ");
if(rflags->md) kputs("MD ");
if(rflags->rf) kputs("RF ");
if(rflags->vm) kputs("VM ");
if(rflags->ac) kputs("AC ");
if(rflags->vif) kputs("VIF ");
if(rflags->vip) kputs("VIP ");
if(rflags->id) kputs("ID ");
if (rflags->cf) kputs("CF ");
if (rflags->pf) kputs("PF ");
if (rflags->af) kputs("AF ");
if (rflags->zf) kputs("ZF ");
if (rflags->sf) kputs("SF ");
if (rflags->tf) kputs("TF ");
if (rflags->if_) kputs("IF ");
if (rflags->df) kputs("DF ");
if (rflags->of) kputs("OF ");
if (rflags->iopl) kputs("IOPL ");
if (rflags->nt) kputs("NT ");
if (rflags->md) kputs("MD ");
if (rflags->rf) kputs("RF ");
if (rflags->vm) kputs("VM ");
if (rflags->ac) kputs("AC ");
if (rflags->vif) kputs("VIF ");
if (rflags->vip) kputs("VIP ");
if (rflags->id) kputs("ID ");
kputs("\n");
}
@ -189,7 +189,7 @@ static int debugger_handle_bkp_cmd(char *msg) {
// list breakpoints
for (int i = 0; i < 4; i++) {
struct breakpoint bkp = bkps[i];
if(!bkp.used) {
if (!bkp.used) {
kprintf("breakpoint %d: unset\n", i);
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;
__asm__ volatile ("mov %%dr7, %0" : "=r"(dr7));
dr7.g0 = bkps[0].enable & bkps[0].used;

View file

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

View file

@ -30,44 +30,44 @@
#define BOCHS_PCI_DEVICE 0x1111
static void write(uint16_t index, uint16_t data) {
outw(INDEX, index);
outw(DATA, data);
outw(INDEX, index);
outw(DATA, data);
}
static uint16_t read(uint16_t value) {
outw(INDEX, value);
return inw(DATA);
outw(INDEX, value);
return inw(DATA);
}
static int is_available(void) {
return (read(INDEX_ID) == 0xB0C5);
return (read(INDEX_ID) == 0xB0C5);
}
static void set_mode(uint16_t width, uint16_t height, uint16_t bit_depth, int lfb, int clear) {
write(INDEX_ENABLE, DATA_DISP_DISABLE);
write(INDEX_XRES, width);
write(INDEX_YRES, height);
write(INDEX_BPP, bit_depth);
write(INDEX_ENABLE, DATA_DISP_ENABLE |
(lfb ? DATA_LFB_ENABLE : 0) |
(clear ? 0 : DATA_NO_CLEAR_MEM));
write(INDEX_ENABLE, DATA_DISP_DISABLE);
write(INDEX_XRES, width);
write(INDEX_YRES, height);
write(INDEX_BPP, bit_depth);
write(INDEX_ENABLE, DATA_DISP_ENABLE |
(lfb ? DATA_LFB_ENABLE : 0) |
(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);
if (!is_available())
return NULL;
return NULL;
struct pci_device bochs = {0};
bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL);
if (!found)
return NULL;
struct pci_device bochs = {0};
bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL);
if (!found)
return NULL;
uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D);
uint32_t *addr = (uint32_t*) (uintptr_t) bar0;
addr = mmap(addr, width * height * bit_depth);
uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D);
uint32_t *addr = (uint32_t *) (uintptr_t) bar0;
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) {
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++];
entry->device = dev;
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) {
pci_table_next = 0;
struct pci_device pcidev;
for(int bus = 0; bus < 256; bus++) {
for (int bus = 0; bus < 256; bus++) {
pcidev.bus = bus;
for(int dev = 0; dev < 32; dev++) {
for (int dev = 0; dev < 32; dev++) {
pcidev.device = dev;
pcidev.function = 0;
uint16_t vendor = pci_rcfg_w(pcidev, 0);
if(vendor == 0xFFFF) continue;
if (vendor == 0xFFFF) continue;
load_device(pcidev);
uint8_t header_type = pci_rcfg_b(pcidev, 14);
if(!(header_type & 0x80)) continue;
for(int func = 1; func < 8; func++) {
if (!(header_type & 0x80)) continue;
for (int func = 1; func < 8; func++) {
pcidev.function = func;
uint16_t vendor = pci_rcfg_w(pcidev, 0);
if(vendor == 0xFFFF) continue;
if (vendor == 0xFFFF) continue;
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) {
size_t o = 0;
if(offset == NULL) offset = &o;
for(; *offset < pci_table_next; (*offset)++) {
if (offset == NULL) offset = &o;
for (; *offset < pci_table_next; (*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;
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) {
size_t o = 0;
if(offset == NULL) offset = &o;
for(; *offset < pci_table_next; (*offset)++) {
if (offset == NULL) offset = &o;
for (; *offset < pci_table_next; (*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;
return true;
}

View file

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

View file

@ -84,15 +84,15 @@ struct mboot_tag_cmdline {
};
struct mboot_tag_framebuffer {
uint32_t type;
uint32_t size;
uint64_t framebuffer_addr;
uint32_t framebuffer_pitch;
uint32_t framebuffer_width;
uint32_t framebuffer_height;
uint8_t framebuffer_bpp;
uint8_t framebuffer_type;
uint16_t reserved;
uint32_t type;
uint32_t size;
uint64_t framebuffer_addr;
uint32_t framebuffer_pitch;
uint32_t framebuffer_width;
uint32_t framebuffer_height;
uint8_t framebuffer_bpp;
uint8_t framebuffer_type;
uint16_t reserved;
};
static void read_symbols(
@ -174,7 +174,7 @@ static void read_memory_map(
uintptr_t i = (uintptr_t)map->entries;
kprintf("MEMORY MAP\n");
char buf[20];
for ( ;
for (;
i < (uintptr_t)map->entries + map->size;
i += map->entry_size, idx++
) {

View file

@ -8,9 +8,9 @@
struct page_header {
struct page_header *next;
struct page_header *prev;
size_t node_number; // all headers on the same page alloc have the same node number (so they can be merged)
size_t free; // free space after the node (if its the last node in the alloc block)
size_t used; // how much space this allocation is using
size_t node_number; // all headers on the same page alloc have the same node number (so they can be merged)
size_t free; // free space after the node (if its the last node in the alloc block)
size_t used; // how much space this allocation is using
uint64_t magic;
};
@ -52,7 +52,7 @@ void *kalloc_new(size_t size) {
}
struct page_header *header = addr;
header->magic = 0xBEEFCAFE;
header->magic = 0xBEEFCAFE;
header->used = size;
header->free = free;
header->prev = end_header;

View file

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

View file

@ -4,7 +4,7 @@
#include <stddef.h>
#include <stdint.h>
#define SCREEN_WIDTH 1024
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define SCREEN_BIT_DEPTH 32