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

[ loading the pc register ]

  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    You could simplify this to:
      LDR  pc, main_address

    How are you checking the pc value?  When running code the PC points at the instruction being fetched - not the one being executed.


    Hi, thanks for replying. I am using the following code:


    reset_handler:
      # copy from flash(0x00000000) to ram
      eor r0, r0
      ldr r1, ram_start
      ldr r2, ram_end
      sub r2, r2, r1
    1:
      ldr r3, [r0], #4
      str r3, [r1], #4
      subs r2, #4
      bne 1b

      # install a stack
      ldr sp, stack_top
      mov fp, sp

      # branch to main
      ldr pc, main_address
      b reset_handler

    ram_start:
      .extern __ram_start
      .word __ram_start // == 0x40000100
    ram_end:
      .extern __ram_end
      .word __ram_end  // == 0x40000200
    stack_top:
      .word __ram_end + 0x1000
    main_address:
      .extern main
      .word main


    Actually, pc is correctly loaded, and I guess there is
    a problem with my copy, but I dont see which one.
    main is a naked function and has no local variable,
    so it doesnot use the stack at all...
    When I replace the first sub to compute the size with
    a harcoded one (ie. mov r2, #0x1000), it works...

    Your help is really appreciated,

    Regards,
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    I am not familiar with the GNU assembler syntax as I use the ARM tools.  However, based on the ARM syntax it looks what you are doing is getting the address of the label.  Have you tried:

    .extern main
    ldr pc, =main


    thanks. this is actually the same as generating
    a word by ourself for storing the main actual
    address... but less painful to manage, so I will
    use this syntax.
    btw, it doesnot solve the problem...

    Fabien.
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    Hmm... Since you mention a hardcoded value works, and decrement by 4, I wonder if the size is actually not a multiple of 4 when working it out?  It looks like the code might loop if it wasn't.


    Hi, thanks for this remark but I already actually
    changed it to take that into account, by >> 2 and
    counting in term of words instead of bytes. Btw,
    the size was always a multiple of 4, so the bug
    doesnot come from here.
  • Note: This was originally posted on 21st July 2009 at http://forums.arm.com

    Please try using

            ldr r1, =ram_start
            ldr r2, =ram_end
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    Actually, pc is correctly loaded, and I guess there is
    a problem with my copy, but I dont see which one.
    main is a naked function and has no local variable,
    so it doesnot use the stack at all...
    When I replace the first sub to compute the size with
    a harcoded one (ie. mov r2, #0x1000), it works...


    Hmm... Since you mention a hardcoded value works, and decrement by 4, I wonder if the size is actually not a multiple of 4 when working it out?  It looks like the code might loop if it wasn't.
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    You could simplify this to:
      LDR  pc, main_address

    How are you checking the pc value?  When running code the PC points at the instruction being fetched - not the one being executed.
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    I am not familiar with the GNU assembler syntax as I use the ARM tools.  However, based on the ARM syntax it looks what you are doing is getting the address of the label.  Have you tried:

    .extern main
    ldr pc, =main