C : Calling a pointer
Posted: Mon May 10, 2010 10:50 am
Hello,
I am currently working on the C library for my OS and I'm a bit stumped on one part.
Here is the C code. The b_smp_enqueue function works fine (It add the jobs to the queue and the available processors in the system start to execute them). This issue is the b_smp_dequeue function. While the other processors are running the jobs the calling program will just sit there spinning until all the work is done. b_smp_dequeue returns an unsigned long which is a pointer to a job.. but how can I get C to execute it? GCC returns "called object 'local' is not a function".. obviously Can I use an actual pointer?
Here is the ASM code that works as it is intended. The BSP executes jobs while the AP's are still processing:
If you need anything else please let me know.
Thanks,
-Ian
I am currently working on the C library for my OS and I'm a bit stumped on one part.
Here is the C code. The b_smp_enqueue function works fine (It add the jobs to the queue and the available processors in the system start to execute them). This issue is the b_smp_dequeue function. While the other processors are running the jobs the calling program will just sit there spinning until all the work is done. b_smp_dequeue returns an unsigned long which is a pointer to a job.. but how can I get C to execute it? GCC returns "called object 'local' is not a function".. obviously Can I use an actual pointer?
Code: Select all
int main()
{
unsigned long var1=0, var2=0, local=0;
b_smp_enqueue(&loop_a);
b_smp_enqueue(&loop_b);
b_smp_enqueue(&loop_a);
b_smp_enqueue(&loop_b);
b_smp_enqueue(&loop_a);
b_smp_enqueue(&loop_b);
b_smp_enqueue(&loop_a);
b_smp_enqueue(&loop_b);
while (b_smp_queuelen() != 0)
{
local = b_smp_dequeue();
local();
}
b_smp_wait();
b_print_string("end\n");
return 0;
}
Code: Select all
start: ; Start of program label
mov rax, ap_print_id ; Our code to run on all CPUs
xor rbx, rbx ; Clear RBX as there is no argument
mov rcx, 64 ; Number of instances to spawn
spawn:
call os_smp_enqueue
sub rcx, 1
cmp rcx, 0
jne spawn
bsp:
call os_smp_dequeue ; Try to dequeue a workload
jc emptyqueue ; If carry is set then the queue is empty
call rax ; Otherwise run the workload
call os_smp_queuelen ; Check the length of the queue
cmp rax, 0
jne bsp ; If it is not empty try to do another workload
emptyqueue:
call os_smp_wait ; Wait for all other processors to finish
call os_print_newline
ret ; Return to OS
Thanks,
-Ian