diff --git a/src/kernel/core/cpu.c b/src/kernel/core/cpu.c index ff8db47e50..54ed148f70 100644 --- a/src/kernel/core/cpu.c +++ b/src/kernel/core/cpu.c @@ -4,11 +4,17 @@ ** Copyright 2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ + +// ToDo: fix the atomic_*() functions and possibly move them elsewhere; +// they are exported in libroot.so anyway, so the best place would +// probably there. + + #include #include #include #include -#include +#include #include #include @@ -16,7 +22,9 @@ /* global per-cpu structure */ cpu_ent cpu[MAX_BOOT_CPUS]; -int cpu_init(kernel_args *ka) + +int +cpu_init(kernel_args *ka) { int i; @@ -28,20 +36,24 @@ int cpu_init(kernel_args *ka) return arch_cpu_init(ka); } -int cpu_preboot_init(kernel_args *ka) + +int +cpu_preboot_init(kernel_args *ka) { return arch_cpu_preboot_init(ka); } -int32 user_atomic_add(vint32 *uval, int32 incr) + +int32 +user_atomic_add(vint32 *uval, int32 incr) { int32 val; int32 ret; - if((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) + if ((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) goto error; - if(user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) + if (user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) goto error; // XXX broken on non SH4-systems, or when interrupts are enabled @@ -49,7 +61,7 @@ int32 user_atomic_add(vint32 *uval, int32 incr) ret = val; val += incr; - if(user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) + if (user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) goto error; return ret; @@ -59,15 +71,17 @@ error: return -1; } -int32 user_atomic_and(vint32 *uval, int32 incr) + +int32 +user_atomic_and(vint32 *uval, int32 incr) { int val; int ret; - if((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) + if ((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) goto error; - if(user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) + if (user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) goto error; // XXX broken on non SH4-systems, or when interrupts are enabled @@ -75,7 +89,7 @@ int32 user_atomic_and(vint32 *uval, int32 incr) ret = val; val &= incr; - if(user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) + if (user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) goto error; return ret; @@ -85,15 +99,17 @@ error: return -1; } -int32 user_atomic_or(vint32 *uval, int32 incr) + +int32 +user_atomic_or(vint32 *uval, int32 incr) { int val; int ret; - if((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) + if ((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) goto error; - if(user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) + if (user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) goto error; // XXX broken on non SH4-systems, or when interrupts are enabled @@ -101,7 +117,7 @@ int32 user_atomic_or(vint32 *uval, int32 incr) ret = val; val |= incr; - if(user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) + if (user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) goto error; return ret; @@ -111,15 +127,17 @@ error: return -1; } -int32 user_atomic_set(vint32 *uval, int32 set_to) + +int32 +user_atomic_set(vint32 *uval, int32 set_to) { int val; int ret; - if((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) + if ((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) goto error; - if(user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) + if (user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) goto error; // XXX broken on non SH4-systems, or when interrupts are enabled @@ -127,7 +145,7 @@ int32 user_atomic_set(vint32 *uval, int32 set_to) ret = val; val = set_to; - if(user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) + if (user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) goto error; return ret; @@ -137,23 +155,25 @@ error: return -1; } -int32 user_test_and_set(vint32 *uval, int32 set_to, int32 test_val) + +int32 +user_test_and_set(vint32 *uval, int32 set_to, int32 test_val) { int val; int ret; - if((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) + if ((addr)uval >= KERNEL_BASE && (addr)uval <= KERNEL_TOP) goto error; - if(user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) + if (user_memcpy(&val, (int32 *)uval, sizeof(val)) < 0) goto error; // XXX broken on non SH4-systems, or when interrupts are enabled // XXX x86 must use the assembly functions directly in userspace and not this ones ret = val; - if(val == test_val) { + if (val == test_val) { val = set_to; - if(user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) + if (user_memcpy((int32 *)uval, &val, sizeof(val)) < 0) goto error; } diff --git a/src/kernel/core/debug.c b/src/kernel/core/debug.c index df072b8eea..1f6cf553f8 100644 --- a/src/kernel/core/debug.c +++ b/src/kernel/core/debug.c @@ -260,7 +260,7 @@ kernel_debugger_loop() void kernel_debugger(const char * message) { - dbg_save_registers(&(dbg_register_file[smp_get_current_cpu()][0])); + arch_dbg_save_registers(&(dbg_register_file[smp_get_current_cpu()][0])); if (message) { dprintf(message); diff --git a/src/kernel/core/faults.c b/src/kernel/core/faults.c index cdf53003b1..f98239b87b 100644 --- a/src/kernel/core/faults.c +++ b/src/kernel/core/faults.c @@ -4,34 +4,40 @@ ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ + + #include -#include #include #include #include #include #include -#include +#include #include #include -int faults_init(kernel_args *ka) + +int +faults_init(kernel_args *ka) { dprintf("init_fault_handlers: entry\n"); return arch_faults_init(ka); } -int general_protection_fault(int errorcode) +int +general_protection_fault(int errorcode) { panic("GENERAL PROTECTION FAULT: errcode 0x%x. Killing system.\n", errorcode); return B_HANDLED_INTERRUPT; } -static const char *fpu_fault_to_str(enum fpu_faults fpu_fault) + +static const char * +fpu_fault_to_str(enum fpu_faults fpu_fault) { - switch(fpu_fault) { + switch (fpu_fault) { default: case FPU_FAULT_CODE_UNKNOWN: return "unknown"; @@ -48,14 +54,18 @@ static const char *fpu_fault_to_str(enum fpu_faults fpu_fault) } } -int fpu_fault(int fpu_fault) + +int +fpu_fault(int fpu_fault) { panic("FPU FAULT: errcode 0x%x (%s), Killing system.\n", fpu_fault, fpu_fault_to_str(fpu_fault)); return B_HANDLED_INTERRUPT; } -int fpu_disable_fault(void) + +int +fpu_disable_fault(void) { panic("FPU DISABLE FAULT: Killing system.\n"); diff --git a/src/kernel/core/heap.c b/src/kernel/core/heap.c index f8e8dbce55..f4d731f834 100644 --- a/src/kernel/core/heap.c +++ b/src/kernel/core/heap.c @@ -11,10 +11,8 @@ #include #include #include - #include - -#include +#include #include diff --git a/src/kernel/core/int.c b/src/kernel/core/int.c index a49c90e29a..59027aef91 100644 --- a/src/kernel/core/int.c +++ b/src/kernel/core/int.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/core/main.c b/src/kernel/core/main.c index 9169a8869f..4574acdc42 100644 --- a/src/kernel/core/main.c +++ b/src/kernel/core/main.c @@ -5,13 +5,14 @@ ** Distributed under the terms of the NewOS License. */ -#include +#include #include #include #include #include -#include +#include #include +#include #include #include #include @@ -31,9 +32,6 @@ #include -#include -#include - #define TRACE_BOOT 1 #if TRACE_BOOT @@ -47,9 +45,9 @@ bool kernel_startup; static kernel_args ka; static int32 main2(void *); - int _start(kernel_args *oldka, int cpu); /* keep compiler happy */ + int _start(kernel_args *oldka, int cpu_num) { diff --git a/src/kernel/core/sem.c b/src/kernel/core/sem.c index bcd7d75063..dd000760ad 100644 --- a/src/kernel/core/sem.c +++ b/src/kernel/core/sem.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include diff --git a/src/kernel/core/smp.c b/src/kernel/core/smp.c index 4a5ecea0d2..9c89719667 100644 --- a/src/kernel/core/smp.c +++ b/src/kernel/core/smp.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -20,7 +19,6 @@ #include #include #include -//#include #include diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index cc22dfb1ef..13e0256654 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -5,6 +5,9 @@ ** Distributed under the terms of the NewOS License. */ +#include +#include + #include #include #include @@ -18,15 +21,13 @@ #include #include #include -#include #include #include #include #include #include #include -#include -#include +#include #include #include #include diff --git a/src/kernel/core/timer.c b/src/kernel/core/timer.c index b909d97256..23a7e4136f 100644 --- a/src/kernel/core/timer.c +++ b/src/kernel/core/timer.c @@ -3,6 +3,9 @@ ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ + +#include + #include #include #include @@ -12,9 +15,7 @@ #include #include #include -#include -#include -#include +#include #include #include @@ -23,6 +24,7 @@ static timer * volatile events[SMP_MAX_CPUS] = { NULL, }; static spinlock timer_spinlock[SMP_MAX_CPUS] = { 0, }; + int timer_init(kernel_args *ka) { dprintf("init_timer: entry\n");