I want to write a function (ARM) that will run in a different initial RAM addresses. Part of the program in ASM, and part of C. The problem is that variables declared in the ASM, as seen in C are still in the same address.
EXP:
in asm file:
test_val dcd 0x5555555 export test_val BLX main_c_code
in C file:
extern int test_val; void main_c_code(void){ ... test_val = 0xAAAAAAAA; ... }
after build everything works, when it loads the applications to address eg 0x1000 (default) test_val is at addr. eg. 0x1004 but when you want to load applications to address eg 0x2000, Part C test_val still fits the data to addr 0x1004 instead of 0x2004. how to force the compiler to the use of
ADR R0, test_val
instead of
LDR R0, = 0x4
About English, I had no time and I used google translator,anyway created by people whose native language is English :) I'm trying to do project that using RAM like pc(computer), program's loaded from eg. SD-card, and I don't know where exactly program will be loaded, and how many programs will be work together, I have to find out free memory block, or relocate memory to free some, load program and run. result must always be on beginning of program, after first BL .. instruction. This is way I can't use predefined AREA absolute address. and all variables, and jumps must by relative to loading address only. It is possible in asm, but I can't do (can't find out) in C.
in debuger, ASM part, you can see
84: ADRL R0, mark1 0x000CB8B4 E24F0080 SUB R0,PC,#0x00000080 0x000CB8B8 E2400028 SUB R0,R0,#0x00000028 85: STR R1, [R0]
variable address is calculated based on PC register +/- offset.
in C part, you can see
40: mark1 = 0x12345678 0x000CB884 E59F0038 LDR R0,[PC,#0x0038] 0x000CB888 E59F1038 LDR R1,[PC,#0x0038] 0x000CB88C E5810000 STR R0,[R1]
address of mark1(R1) is loaded as constants (some label DCD address )form position [PC,#0x0038], and this is no good for me.
I think now everything is clear, I can't explain this easier.
If I good understand documentation of scatter file, then I can set regions almost in any place, but always is some constant entry point, from which compiler calculate absolute address of variable for C ?
I ran into a similar problem before and I was also told to use scatter file (please read forums.arm.com/index.php). Using a scatter file is the right solution, but for my problem, we had to write a bootloader because of some other hardware requirement. In any case, instead of using variables scattered around, put all of them in a struct and access them from there. This way, you have to deal with only 1 address. Good Luck :-)