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 ]

Parents
  • 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,
Reply
  • 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,
Children
No data