diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | arch/riscv64/config.h | 14 | ||||
| -rw-r--r-- | arch/riscv64/include/sbi.h | 13 | ||||
| -rw-r--r-- | arch/riscv64/include/vmem.h | 16 | ||||
| -rw-r--r-- | arch/riscv64/init/init.c | 7 | ||||
| -rw-r--r-- | arch/riscv64/kernel/power.c | 22 | ||||
| -rw-r--r-- | arch/riscv64/kernel/sbi.c | 30 | ||||
| -rw-r--r-- | common/nodes.c | 5 | ||||
| -rw-r--r-- | common/tcb.c | 2 | ||||
| -rw-r--r-- | common/timer.c | 10 | ||||
| -rw-r--r-- | common/uapi/conf.c | 8 | ||||
| -rw-r--r-- | include/apos/mem.h | 4 | ||||
| -rw-r--r-- | include/apos/nodes.h | 2 | ||||
| -rw-r--r-- | include/apos/power.h | 2 | ||||
| -rw-r--r-- | include/apos/uapi.h | 78 | ||||
| -rw-r--r-- | include/apos/utils.h | 5 |
16 files changed, 114 insertions, 106 deletions
@@ -90,7 +90,7 @@ apos.bin: init.bin kernel.bin format: find arch lib common include -iname '*.[ch]' \ - -exec clang-format -i -style=file {} \; + -exec clang-format -i -style=file {} \+ clean: $(RM) -r $(CLEANUP) diff --git a/arch/riscv64/config.h b/arch/riscv64/config.h index b52585b..ee337b4 100644 --- a/arch/riscv64/config.h +++ b/arch/riscv64/config.h @@ -2,17 +2,17 @@ /* --- START ARCH USER CONFIG VALUES --- */ /* physical address to which the kernel will be loaded */ -#define RAM_BASE 0x80000000 -#define PM_KERN_BASE (RAM_BASE + SZ_512K) -#define PM_KERN_SIZE (SZ_256K) -#define PM_KERN_TOP (PM_KERN_BASE + PM_KERN_SIZE) +#define RAM_BASE 0x80000000 +#define PM_KERN_BASE (RAM_BASE + SZ_512K) +#define PM_KERN_SIZE (SZ_256K) +#define PM_KERN_TOP (PM_KERN_BASE + PM_KERN_SIZE) /* --- END ARCH USER CONFIG VALUES --- */ /* don't touch >:( */ -#define PM_STACK_BASE (PM_KERN_BASE + SZ_256K) -#define PM_STACK_SIZE (SZ_256K) -#define PM_STACK_TOP (PM_STACK_BASE + PM_STACK_SIZE) +#define PM_STACK_BASE (PM_KERN_BASE + SZ_256K) +#define PM_STACK_SIZE (SZ_256K) +#define PM_STACK_TOP (PM_STACK_BASE + PM_STACK_SIZE) #if __riscv_xlen == 64 /* 64bit */ diff --git a/arch/riscv64/include/sbi.h b/arch/riscv64/include/sbi.h index b750475..3beedd2 100644 --- a/arch/riscv64/include/sbi.h +++ b/arch/riscv64/include/sbi.h @@ -26,24 +26,27 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); -#define EID_TIME 0x54494D45 +#define EID_TIME 0x54494D45 #define FID_SET_TIMER 0 static inline struct sbiret sbi_set_timer(uint64_t stime_value) { /* TODO: read timebase from fdt, seems to be clocks/sec for accurate * timers */ #if __riscv_xlen == 32 - return sbi_ecall(EID_TIME, FID_SET_TIMER, stime_value, stime_value >> 32, 0, 0, 0, 0); + return sbi_ecall(EID_TIME, FID_SET_TIMER, stime_value, + stime_value >> 32, 0, 0, 0, 0); #else return sbi_ecall(EID_TIME, FID_SET_TIMER, stime_value, 0, 0, 0, 0, 0); #endif } -#define EID_SRST 0x53525354 +#define EID_SRST 0x53525354 #define FID_RESET 0 -static inline struct sbiret sbi_system_reset(uint32_t reset_type, uint32_t reset_reason) +static inline struct sbiret sbi_system_reset(uint32_t reset_type, + uint32_t reset_reason) { - return sbi_ecall(EID_SRST, FID_RESET, reset_type, reset_reason, 0, 0, 0, 0); + return sbi_ecall(EID_SRST, FID_RESET, reset_type, reset_reason, 0, 0, 0, + 0); } #endif /* APOS_RISCV_SBI_H */ diff --git a/arch/riscv64/include/vmem.h b/arch/riscv64/include/vmem.h index 4446aef..9816110 100644 --- a/arch/riscv64/include/vmem.h +++ b/arch/riscv64/include/vmem.h @@ -6,14 +6,14 @@ #define RISCV_NUM_LEAVES (4096 / sizeof(void *)) -#define VM_V (1 << 0) -#define VM_R (1 << 1) -#define VM_W (1 << 2) -#define VM_X (1 << 3) -#define VM_U (1 << 4) -#define VM_G (1 << 5) -#define VM_A (1 << 6) -#define VM_D (1 << 7) +#define VM_V (1 << 0) +#define VM_R (1 << 1) +#define VM_W (1 << 2) +#define VM_X (1 << 3) +#define VM_U (1 << 4) +#define VM_G (1 << 5) +#define VM_A (1 << 6) +#define VM_D (1 << 7) enum mm_mode { Sv48, diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c index b28c581..31a9155 100644 --- a/arch/riscv64/init/init.c +++ b/arch/riscv64/init/init.c @@ -21,13 +21,14 @@ void init_bootmem() /* direct mapping (temp) */ for (size_t i = 0; i < CSTACK_PAGE; ++i) - root_branch->leaf[i] = (struct vm_branch *)to_pte(SZ_1G * i, flags); + root_branch->leaf[i] = + (struct vm_branch *)to_pte(SZ_1G * i, flags); /* kernel (also sort of direct mapping) */ flags |= VM_G; for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i) - root_branch->leaf[i] = - (struct vm_branch *)to_pte(RAM_BASE + SZ_1G * (i - 256), flags); + root_branch->leaf[i] = (struct vm_branch *)to_pte( + RAM_BASE + SZ_1G * (i - 256), flags); /* kernel IO, map to 0 for now, will be updated in the future */ root_branch->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags); diff --git a/arch/riscv64/kernel/power.c b/arch/riscv64/kernel/power.c index 877c001..a4d6568 100644 --- a/arch/riscv64/kernel/power.c +++ b/arch/riscv64/kernel/power.c @@ -2,10 +2,10 @@ #include <sbi.h> /* shutdown reason */ -#define SBI_NO_REASON 0 +#define SBI_NO_REASON 0 /* shutdown type */ -#define SBI_SHUTDOWN 0 +#define SBI_SHUTDOWN 0 #define SBI_COLD_REBOOT 1 #define SBI_WARM_REBOOT 2 @@ -14,17 +14,17 @@ stat_t poweroff(enum poweroff_type type) /* TODO: this only shuts down the cpu itself, but may leave the SOC * active. Should read from fdt poweroff and syscon-poweroff etc */ switch (type) { - case SHUTDOWN: - sbi_system_reset(SBI_SHUTDOWN, SBI_NO_REASON); - return ERR_MISC; + case SHUTDOWN: + sbi_system_reset(SBI_SHUTDOWN, SBI_NO_REASON); + return ERR_MISC; - case COLD_REBOOT: - sbi_system_reset(SBI_COLD_REBOOT, SBI_NO_REASON); - return ERR_MISC; + case COLD_REBOOT: + sbi_system_reset(SBI_COLD_REBOOT, SBI_NO_REASON); + return ERR_MISC; - case WARM_REBOOT: - sbi_system_reset(SBI_WARM_REBOOT, SBI_NO_REASON); - return ERR_MISC; + case WARM_REBOOT: + sbi_system_reset(SBI_WARM_REBOOT, SBI_NO_REASON); + return ERR_MISC; }; return ERR_INVAL; diff --git a/arch/riscv64/kernel/sbi.c b/arch/riscv64/kernel/sbi.c index cd3eb1b..93f5785 100644 --- a/arch/riscv64/kernel/sbi.c +++ b/arch/riscv64/kernel/sbi.c @@ -1,25 +1,25 @@ #include <sbi.h> struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, - unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, - unsigned long arg5) + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) { struct sbiret ret; - register uintptr_t a0 __asm__ ("a0") = (uintptr_t)(arg0); - register uintptr_t a1 __asm__ ("a1") = (uintptr_t)(arg1); - register uintptr_t a2 __asm__ ("a2") = (uintptr_t)(arg2); - register uintptr_t a3 __asm__ ("a3") = (uintptr_t)(arg3); - register uintptr_t a4 __asm__ ("a4") = (uintptr_t)(arg4); - register uintptr_t a5 __asm__ ("a5") = (uintptr_t)(arg5); - register uintptr_t a6 __asm__ ("a6") = (uintptr_t)(fid); - register uintptr_t a7 __asm__ ("a7") = (uintptr_t)(ext); + register uintptr_t a0 __asm__("a0") = (uintptr_t)(arg0); + register uintptr_t a1 __asm__("a1") = (uintptr_t)(arg1); + register uintptr_t a2 __asm__("a2") = (uintptr_t)(arg2); + register uintptr_t a3 __asm__("a3") = (uintptr_t)(arg3); + register uintptr_t a4 __asm__("a4") = (uintptr_t)(arg4); + register uintptr_t a5 __asm__("a5") = (uintptr_t)(arg5); + register uintptr_t a6 __asm__("a6") = (uintptr_t)(fid); + register uintptr_t a7 __asm__("a7") = (uintptr_t)(ext); - __asm__ volatile ("ecall" - : "+r" (a0), "+r" (a1) - : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) - : "memory"); + __asm__ volatile("ecall" + : "+r"(a0), "+r"(a1) + : "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7) + : "memory"); ret.error = a0; ret.value = a1; diff --git a/common/nodes.c b/common/nodes.c index 6ff42b1..0c6f7ce 100644 --- a/common/nodes.c +++ b/common/nodes.c @@ -13,7 +13,7 @@ * being free) */ -#define node_region(r)\ +#define node_region(r) \ ((struct node_region *)((uintptr_t)(r) & ~(BASE_PAGE_SIZE - 1))) static struct node_region *__create_region() @@ -144,7 +144,8 @@ void free_node(struct node_root *r, void *p) { struct node_region *nr = node_region(p); uint8_t *bitmap = r->bitmap + (uint8_t *)nr; - size_t i = ((uintptr_t)p - (r->first_node + (uintptr_t)nr)) / r->node_size; + size_t i = + ((uintptr_t)p - (r->first_node + (uintptr_t)nr)) / r->node_size; bitmap_clear(bitmap, i); if (--nr->used_nodes == 0) { diff --git a/common/tcb.c b/common/tcb.c index 4a69df6..5d6b8a2 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -15,7 +15,7 @@ static struct tcb **tcbs; /* if we ever support systems with massive amounts of cpus, this should probably * be allocated at runtime */ -static struct tcb *cpu_tcb[MAX_CPUS] = {0}; +static struct tcb *cpu_tcb[MAX_CPUS] = { 0 }; void init_tcbs() { diff --git a/common/timer.c b/common/timer.c index f35c983..2006a6c 100644 --- a/common/timer.c +++ b/common/timer.c @@ -7,7 +7,7 @@ #include <arch/cpu.h> static ticks_t ticks_per_sec = 0; -static struct sp_root cpu_timers[MAX_CPUS] = {0}; +static struct sp_root cpu_timers[MAX_CPUS] = { 0 }; static struct node_root node_root; struct timer_node { @@ -15,11 +15,9 @@ struct timer_node { struct timer timer; }; -#define timer_container(ptr)\ - container_of(ptr, struct timer_node, sp_n) +#define timer_container(ptr) container_of(ptr, struct timer_node, sp_n) -#define timer_node_container(ptr)\ - container_of(ptr, struct timer_node, timer) +#define timer_node_container(ptr) container_of(ptr, struct timer_node, timer) static struct sp_root *__cpu_timers() { @@ -61,7 +59,7 @@ static id_t __insert_timer(struct timer_node *ti) d = RIGHT; } } - + if (sp_root(root)) sp_insert(&sp_root(root), p, &ti->sp_n, d); else diff --git a/common/uapi/conf.c b/common/uapi/conf.c index 3002fc2..3fe6481 100644 --- a/common/uapi/conf.c +++ b/common/uapi/conf.c @@ -17,10 +17,10 @@ SYSCALL_DEFINE2(conf)(vm_t param, vm_t val) SYSCALL_DEFINE1(poweroff)(vm_t type) { switch (type) { - case SHUTDOWN: - case COLD_REBOOT: - case WARM_REBOOT: - return poweroff(type); + case SHUTDOWN: + case COLD_REBOOT: + case WARM_REBOOT: + return poweroff(type); }; return ERR_INVAL; diff --git a/include/apos/mem.h b/include/apos/mem.h index be44104..ece8ee3 100644 --- a/include/apos/mem.h +++ b/include/apos/mem.h @@ -35,8 +35,8 @@ #define __page(x) ((x) / BASE_PAGE_SIZE) #define __addr(x) ((x)*BASE_PAGE_SIZE) #define __pages(x) \ - (aligned((x), BASE_PAGE_SIZE) ? __page((x)) : \ - __page((x) + BASE_PAGE_SIZE)) + (is_aligned((x), BASE_PAGE_SIZE) ? __page((x)) : \ + __page((x) + BASE_PAGE_SIZE)) #define __bytes(x) (__addr(x)) extern size_t __mm_shifts[10]; diff --git a/include/apos/nodes.h b/include/apos/nodes.h index 0780f75..9cf6728 100644 --- a/include/apos/nodes.h +++ b/include/apos/nodes.h @@ -3,7 +3,7 @@ #include <apos/types.h> -enum node_status { FREE = 0, USED = 1}; +enum node_status { FREE = 0, USED = 1 }; struct node_region { size_t used_nodes; diff --git a/include/apos/power.h b/include/apos/power.h index e0ca518..31f199d 100644 --- a/include/apos/power.h +++ b/include/apos/power.h @@ -4,7 +4,7 @@ #include <apos/types.h> #include <apos/attrs.h> -enum poweroff_type {SHUTDOWN, COLD_REBOOT, WARM_REBOOT}; +enum poweroff_type { SHUTDOWN, COLD_REBOOT, WARM_REBOOT }; stat_t poweroff(enum poweroff_type type); #endif diff --git a/include/apos/uapi.h b/include/apos/uapi.h index 18f086c..fa66b31 100644 --- a/include/apos/uapi.h +++ b/include/apos/uapi.h @@ -8,52 +8,56 @@ * goes */ typedef vm_t (*sys_t)(vm_t, vm_t, vm_t, vm_t); -#define SYSCALL_DECLARE(name)\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d); +#define SYSCALL_DECLARE(name) vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d); -#define SYSCALL_DEFINE0(name)\ - static vm_t __##name();\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \ - UNUSED(a);\ - UNUSED(b);\ - UNUSED(c);\ - UNUSED(d);\ - return __##name();\ - }\ +#define SYSCALL_DEFINE0(name) \ + static vm_t __##name(); \ + vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d) \ + { \ + UNUSED(a); \ + UNUSED(b); \ + UNUSED(c); \ + UNUSED(d); \ + return __##name(); \ + } \ static vm_t __##name -#define SYSCALL_DEFINE1(name)\ - static vm_t __##name(vm_t);\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \ - UNUSED(b);\ - UNUSED(c);\ - UNUSED(d);\ - return __##name(a);\ - }\ +#define SYSCALL_DEFINE1(name) \ + static vm_t __##name(vm_t); \ + vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d) \ + { \ + UNUSED(b); \ + UNUSED(c); \ + UNUSED(d); \ + return __##name(a); \ + } \ static vm_t __##name -#define SYSCALL_DEFINE2(name)\ - static vm_t __##name(vm_t, vm_t);\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \ - UNUSED(c);\ - UNUSED(d);\ - return __##name(a, b);\ - }\ +#define SYSCALL_DEFINE2(name) \ + static vm_t __##name(vm_t, vm_t); \ + vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d) \ + { \ + UNUSED(c); \ + UNUSED(d); \ + return __##name(a, b); \ + } \ static vm_t __##name -#define SYSCALL_DEFINE3(name)\ - static vm_t __##name(vm_t, vm_t, vm_t);\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \ - UNUSED(d);\ - return __##name(a, b, c);\ - }\ +#define SYSCALL_DEFINE3(name) \ + static vm_t __##name(vm_t, vm_t, vm_t); \ + vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d) \ + { \ + UNUSED(d); \ + return __##name(a, b, c); \ + } \ static vm_t __##name -#define SYSCALL_DEFINE4(name)\ - static vm_t __##name(vm_t, vm_t, vm_t, vm_t);\ - vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d){ \ - return __##name(a, b, c, d);\ - }\ +#define SYSCALL_DEFINE4(name) \ + static vm_t __##name(vm_t, vm_t, vm_t, vm_t); \ + vm_t sys_##name(vm_t a, vm_t b, vm_t c, vm_t d) \ + { \ + return __##name(a, b, c, d); \ + } \ static vm_t __##name /* memory */ diff --git a/include/apos/utils.h b/include/apos/utils.h index ce48776..03e1a59 100644 --- a/include/apos/utils.h +++ b/include/apos/utils.h @@ -32,10 +32,10 @@ #endif #if __has_builtin(__builtin_expect) -#define likely(x) __builtin_expect(!!(x), 1) +#define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else -#define likely(x) (x) +#define likely(x) (x) #define unlikely(x) (x) #endif @@ -49,6 +49,7 @@ #include <apos/types.h> +/* clang-format doesn't like _Generic, but I guess that's fine. */ #define align_up(x, y) \ _Generic((x), int8_t \ : align_up_int8_t, int16_t \ |
