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

jump to a location

can i jump from a bootloader designed by me to an application program by changing the ProgramCounter .. i have an address location in a variable ..

mov pc, addr .. is this possible or any other options

... there is no return from application to bootloader program..
plz help me

Parents Reply Children
  • plz help me .. how can i do that ..
    when i used the move function it returned error
    i am using GNU compiler

    asm("MOV PC,=ADDR"); returns error as shifting register expected
    no error when asm("MOV PC,0x8000");

    how can i jump to code block whose address is in global variable

    i have also tried LDR R0 and BX r0 as in startup.s

  • To jump to a function whose address is in a global var, you don't need to go low-level. Declare your var as a function pointer:

        // declare pmain var as a function pointer to a int(void) function
        int (*pmain)(void);
    
    
        // do whatever you do, and load the target address in pmain
        pmain = (int (*)(void)) 0x40000000; // cast it to the func ptr type
    
        // ...
    
        // now call the code pointed by pmain.
        pmain();
    
        // pmain will never return ...
    

    This produces code like:

    0x00000250  E3A00101  MOV       R0,#0x40000000
    0x00000254  E1A0E00F  MOV       R14,PC
    0x00000258  E12FFF10  BX        R0
    

    That is only one extra instruction from doing MOV PC, R0, generally irrelevant in a ARM processor.

    Another point in your post is to optimize for a function that never returns. The RVCT has the function qualifier __declspec(noreturn) to tell the compiler that it is OK to remove the function return code from the target function.