2010-04-28 02:53 PM
access R0-R4 in C
2011-05-17 04:49 AM
If you want to exercise this level of control you simply need to write the function in assembler. In C you could cast an address to a function call and also provide it with parameters. This would in effect permit you to define r0-r4, and pc. You could also use assembler inline within your function(s).
2011-05-17 04:49 AM
If you are using GCC it is not difficult nor dangerous, you can enforce a variable into a specific register, you just declare it like this:
register unsigned int n asm(''r2''); You may also need to declare the variable ''volatile'' or the compiler may optimize out assignments to the variable if it is not explicitly used after the assignment. GCC is very effective if you need to do inline assembler. Giovanni --- ChibiOS/RT http://chibios.sourceforge.net2011-05-17 04:49 AM
Thanks, I would do this but I cannot grantee we will be using GCC where this code is going to run.
I ended up doing something similar to what clive1 suggested, which is just copy all the 4 parameters into the registers whether they are used by the function or not , which seems to work well enough, eg:typedef void (*internal_task)(uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3);
void SYS_Run(void (*task), uint8_t argc, uint32_t argv[])
{
internal_task t = (internal_task)task;
t(argv[0], argv[1], argv[2], argv[3]);
}