2 ** Copyright 2002-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <kernel/kernel.h>
6 #include <kernel/cpu.h>
8 #include <kernel/time.h>
9 #include <boot/stage2.h>
13 /* global per-cpu structure */
14 cpu_ent cpu
[_MAX_CPUS
];
16 int cpu_init(kernel_args
*ka
)
20 memset(cpu
, 0, sizeof(cpu
));
21 for(i
= 0; i
< _MAX_CPUS
; i
++) {
25 return arch_cpu_init(ka
);
28 int cpu_init_percpu(kernel_args
*ka
, int curr_cpu
)
30 return arch_cpu_init_percpu(ka
, curr_cpu
);
33 int cpu_preboot_init(kernel_args
*ka
)
35 return arch_cpu_preboot_init(ka
);
38 void cpu_spin(bigtime_t interval
)
40 bigtime_t start
= system_time();
42 while(system_time() - start
< interval
)
46 int user_atomic_add(int *uval
, int incr
)
51 if(is_kernel_address(uval
))
54 if(user_memcpy(&val
, uval
, sizeof(val
)) < 0)
60 if(user_memcpy(uval
, &val
, sizeof(val
)) < 0)
70 int user_atomic_and(int *uval
, int incr
)
75 if(is_kernel_address(uval
))
78 if(user_memcpy(&val
, uval
, sizeof(val
)) < 0)
84 if(user_memcpy(uval
, &val
, sizeof(val
)) < 0)
94 int user_atomic_or(int *uval
, int incr
)
99 if(is_kernel_address(uval
))
102 if(user_memcpy(&val
, uval
, sizeof(val
)) < 0)
108 if(user_memcpy(uval
, &val
, sizeof(val
)) < 0)
118 int user_atomic_set(int *uval
, int set_to
)
123 if(is_kernel_address(uval
))
126 if(user_memcpy(&val
, uval
, sizeof(val
)) < 0)
132 if(user_memcpy(uval
, &val
, sizeof(val
)) < 0)
142 int user_test_and_set(int *uval
, int set_to
, int test_val
)
147 if(is_kernel_address(uval
))
150 if(user_memcpy(&val
, uval
, sizeof(val
)) < 0)
154 if(val
== test_val
) {
156 if(user_memcpy(uval
, &val
, sizeof(val
)) < 0)