Best way to locate some C code in work RAM?
Posted: Tue Aug 09, 2016 2:14 pm
I want to do some tests to see if I'm able to write to the flash chips of my WiFi cartridge from the Megadrive itself. As you cannot read data (e.g. program instructions) from the flash chips while data is being erased/written to them, I want to locate the code handling flash routines in RAM. So far I have successfully tested using function attributes, e.g.:
I can see on the map file that function foo is located in RAM. The code executes perfect, and I have verified the function is in RAM by printing on the screen the value of foo pointer (it was located at 0xFF0002 address BTW, exactly the same address indicated on the map file).
So this approach works if I want to place a function on RAM, but on the flash handling module I have a lot of functions I'd like to place on RAM. I could use the attribute definition above on each function, but I suppose there must be other way of putting all the code generated by the module on RAM. Also I'm not sure about how the section attribute will behave with inline functions.
So, is there any magic to place all the code of a module in RAM without having to "attribute" each function?
Also, on the test I did, I used ".data" section. I suppose there must be a better approach, like creating a new section and modifying the linker script to locate the section in RAM. But I'm not 100% this would work without modifying SGDK startup code to make sure the code is copied from the ROM to the appropiate RAM location before main() is executed.
And one last question... Is there any restriction I should be aware of while doing this trick? E.g. should I manually add an attribute to guarantee the code is aligned to a specific boundary?
Code: Select all
void foo(void) __attribute__((section(".data")));
void foo(void) {
// Some useful code here...
}
So this approach works if I want to place a function on RAM, but on the flash handling module I have a lot of functions I'd like to place on RAM. I could use the attribute definition above on each function, but I suppose there must be other way of putting all the code generated by the module on RAM. Also I'm not sure about how the section attribute will behave with inline functions.
So, is there any magic to place all the code of a module in RAM without having to "attribute" each function?
Also, on the test I did, I used ".data" section. I suppose there must be a better approach, like creating a new section and modifying the linker script to locate the section in RAM. But I'm not 100% this would work without modifying SGDK startup code to make sure the code is copied from the ROM to the appropiate RAM location before main() is executed.
And one last question... Is there any restriction I should be aware of while doing this trick? E.g. should I manually add an attribute to guarantee the code is aligned to a specific boundary?