This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

program run from different RAM address (ARM)

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

Parents
  • "You can of course perform relative address computations. But computations relative to what? "

    Maybe relative to register PC,Code structure is constant, then exp: PC-30 always is address of my global variable, how to do this in C function, or better how to set compiler or set variable do to this automatic.
    in asm it easy. Must by way to do this in C.
    This is not only one variable,and not only one program which must work, (will be loaded) to ram in same time, and some of result must by available at load address as structure.
    I am a beginner in Keil. so the example project of this problem can be very helpful.

    Please help.

Reply
  • "You can of course perform relative address computations. But computations relative to what? "

    Maybe relative to register PC,Code structure is constant, then exp: PC-30 always is address of my global variable, how to do this in C function, or better how to set compiler or set variable do to this automatic.
    in asm it easy. Must by way to do this in C.
    This is not only one variable,and not only one program which must work, (will be loaded) to ram in same time, and some of result must by available at load address as structure.
    I am a beginner in Keil. so the example project of this problem can be very helpful.

    Please help.

Children
  • Did you start by looking at the "Read-Only Position Independent" and "Read-Write Position Independent" project settings?

  • Yes, last night, before the thread:)
    but after compilation is still the same problem. Maybe I'm doing something wrong ... for sure I do. :)

  • Next step then must be to check the documentation for the compiler - or contact Keil support - to find out what the limitations are for the compiler/linker.

  • Seeking a solution for several hours, searched this forum, all the help files, sample programs, google, without success.

  • What are you trying to do? Am I reading this right?

    Do you think you can declare a variable and then write code and have them coexist in the same memory region?

    One is .text and the other is .data They are handled completely different. Check your .map file

  • I said already that I'm new at Keil. So how to declare the region and set the compiler in order to arm the program was fully position independent of the load address.
    and that the address of variables were always in same offset from loading address, not absolute address?

  • So how to declare the region and set the compiler order to arm the program was fully position independent of the load address.

    Is this what is called pig-english? Can you understand this statement when you read it? I cannot (and most likely anyone else reading your post).

    You can place data and code at specific locations within memory using what is called a linker scatter file.

    Search on 'scatter file' or variants thereof. There is well documented information.

    Why do you want multiple resident programs to access the same memory through predefined locations?

    On second thought - never mind.

  • 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 :-)