GP2X Gpu940 - Sync


GernotFrisch

Member
Joined
Jan 2, 2007
Messages
445
hi,

2 questions:
- how can I call "void my_thread()" to run in 2nd cpu
- how can I have a variable to "lock" memory that is shared by both processors (one integer would suffice)
 
Well, you can copy your function into physical ram (>32MB, physical not logical address like that returned by memmap) and then have some started code call that. You can't use any library functions then though.

Or, you can make your own toolchain that is dedicated for writing for the 940. This gives you access to the C library. This way is very similar to GP32 development, so you can hackup a GP32 toolchain by just hacking up the linkerscript/etc.

To lock memory, you would have to have both processes (both the 920 and 940 versions) checking your "lock" variable to ensure they can write to that memory first, and then writing to it. Since both processors will be running at the same time (rather than time slicing) you really should use an operation which will execute in one instruction (atomic, like 'cmpxchg' on the x86, I'm not sure of the arm equivalent).
 
Squidge posted on Feb 14 2007 at 08:24 PM said:
Well, you can copy your function into physical ram (>32MB, physical not logical address like that returned by memmap) and then have some started code call that. You can't use any library functions then though.

Or, you can make your own toolchain that is dedicated for writing for the 940. This gives you access to the C library. This way is very similar to GP32 development, so you can hackup a GP32 toolchain by just hacking up the linkerscript/etc.

To lock memory, you would have to have both processes (both the 920 and 940 versions) checking your "lock" variable to ensure they can write to that memory first, and then writing to it. Since both processors will be running at the same time (rather than time slicing) you really should use an operation which will execute in one instruction (atomic, like 'cmpxchg' on the x86, I'm not sure of the arm equivalent).

How would I know the size of my function? sizeof(foo) returns sizeof (void*), ain't it?
 
Last edited by a moderator:
A trick is to create a dummy function right after the function which size you want to know:
Code:
void my_thread()
{
  // foobar
}
static void DummyFunction(void)
{
}
And then do this:
Code:
 my_thread_size = &DummyFunction - &my_thread;

EDIT:This is not the best idea though, because the linker can change the function order. But I think there is a flag to disallow it. I'm not sure. Anyways if you want to be on the safe side use a disassembler to determine the function size.
 
Yes, you can do it that way, but it's not the best. The best is either to use a disassembler to determine the size of the function (but obviously this breaks when you change the code or optimisation settings), or simply put your code into another file and compile seperately. You can then write a script which converts the elf code to binary and determines the size of this binary.

Remember, you can't easily use library functions (or call any other functions) without difficulty when the function to upload to the 940 is in the same file. Its a lot easier when compiled on its own, as everything will be with the function.
 
Squidge posted on Feb 15 2007 at 02:19 PM said:
Yes, you can do it that way, but it's not the best. The best is either to use a disassembler to determine the size of the function (but obviously this breaks when you change the code or optimisation settings), or simply put your code into another file and compile seperately. You can then write a script which converts the elf code to binary and determines the size of this binary.

Remember, you can't easily use library functions (or call any other functions) without difficulty when the function to upload to the 940 is in the same file. Its a lot easier when compiled on its own, as everything will be with the function.

I think I'm too dull to get the function size with a disassembler.
But if I want to share memory, I must use hardware addresses, right? That's pretty much work to do then...
 
Last edited by a moderator:
Yup, you can't use memory allocated by Linux if you want to share it between processors. You have to point it directly to physical memory.
 
KungPhoo posted on Feb 15 2007 at 08:07 AM said:
How would I know the size of my function? sizeof(foo) returns sizeof (void*), ain't it?
Use nm -S.
 
Last edited by a moderator:
Back
Top