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

Stuck at Startup code

Vectors LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr NOP ; Reserved Vector LDR PC, IRQ_Addr

LDR PC, [PC, #-0x0120] ; Vector

from VicVectAddr

LDR PC, FIQ_Addr

Reset_Addr DCD Reset_Handler

Undef_Addr DCD Undef_Handler

SWI_Addr DCD 0
PAbt_Addr DCD PAbt_Handler

DAbt_Addr DCD DAbt_Handler

DCD 0 ; Reserved Address

IRQ_Addr DCD 0

FIQ_Addr DCD FIQ_Handler

Undef_Handler B Undef_Handler

SWI_Handler B SWI_Handler

PAbt_Handler B PAbt_Handler

DAbt_Handler B DAbt_Handler

;IRQ_Handler B IRQ_Handler

FIQ_Handler B FIQ_Handler

; Reset Handler

EXPORT Reset_Handler

Reset_Handler

; Setup Stack for each mode

LDR R0, =Stack_Top

; Enter Undefined Instruction Mode and set its Stack

Pointer

MSR CPSR_c,

#Mode_UND:OR:I_Bit:OR:F_Bit

MOV SP, R0

SUB R0, R0, #UND_Stack_Size

; Enter Abort Mode and set its Stack Pointer

MSR CPSR_c,

#Mode_ABT:OR:I_Bit:OR:F_Bit

MOV SP, R0

SUB R0, R0, #ABT_Stack_Size

; Enter FIQ Mode and set its Stack Pointer

MSR CPSR_c,

#Mode_FIQ:OR:I_Bit:OR:F_Bit

MOV SP, R0

SUB R0, R0, #FIQ_Stack_Size

; Enter IRQ Mode and set its Stack Pointer

MSR CPSR_c,

#Mode_IRQ:OR:I_Bit:OR:F_Bit

MOV SP, R0

SUB R0, R0, #IRQ_Stack_Size

; Enter Supervisor Mode and set its Stack Pointer

MSR CPSR_c,

#Mode_SVC:OR:I_Bit:OR:F_Bit

MOV SP, R0

SUB R0, R0, #SVC_Stack_Size

; Enter User Mode and set its Stack Pointer

MSR CPSR_c, #Mode_USR

MOV SP, R0

SUB SL, SP, #USR_Stack_Size

; IMPORT TargetResetInit

; BL TargetResetInit

; Enter the C code

IMPORT __main

LDR R0, =__main

BX R0

; User Initial Stack & Heap

AREA |.text|, CODE, READONLY

IMPORT __use_two_region_memory

EXPORT __user_initial_stackheap
__user_initial_stackheap

LDR R0, = Heap_Mem

LDR R1, =(Stack_Mem +

USR_Stack_Size)

LDR R2, = (Heap_Mem +

Heap_Size)

LDR R3, = Stack_Mem

BX LR

END

This is my Startup code.
While debugging the execution stuck at "Enter the C Code part"
Instead of jump to main,program execution enter to below loop

0x0000012C E2522010 SUBS R2,R2,#0x00000010
0x00000130 28A10078 STMCSIA R1!,{R3-R6}
0x00000134 8AFFFFFC BHI 0x0000012C

I cant see the corresponding C code of this loop.
Plz give some suggestions or solution to this problem

Parents
  • Vectors             LDR     PC, Reset_Addr
                    LDR     PC, Undef_Addr
                    LDR     PC, SWI_Addr
                    LDR     PC, PAbt_Addr
                    LDR     PC, DAbt_Addr
                    NOP                            ; Reserved Vector
                    LDR     PC, IRQ_Addr
                    LDR     PC, [PC, #-0x0120]     ; Vector from VicVectAddr
                    LDR     PC, FIQ_Addr
    
    Reset_Addr      DCD     Reset_Handler
    Undef_Addr      DCD     Undef_Handler
    SWI_Addr
                    DCD     0
    PAbt_Addr       DCD     PAbt_Handler
    DAbt_Addr       DCD     DAbt_Handler
                    DCD             0            ; Reserved Address
    IRQ_Addr
                                     DCD     0
    FIQ_Addr        DCD     FIQ_Handler
    
    
    Undef_Handler   B       Undef_Handler
    SWI_Handler     B       SWI_Handler
    PAbt_Handler    B       PAbt_Handler
    DAbt_Handler    B       DAbt_Handler
    ;IRQ_Handler     B       IRQ_Handler
    FIQ_Handler     B       FIQ_Handler
    
    ; Reset Handler
    
                    EXPORT  Reset_Handler
    Reset_Handler
    
    ; Setup Stack for each mode
                    LDR     R0, =Stack_Top
    
    ;  Enter Undefined Instruction Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #UND_Stack_Size
    
    ;  Enter Abort Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #ABT_Stack_Size
    
    ;  Enter FIQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #FIQ_Stack_Size
    
    ;  Enter IRQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #IRQ_Stack_Size
    
    ;  Enter Supervisor Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #SVC_Stack_Size
    
    ;  Enter User Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_USR
                    MOV     SP, R0
                    SUB     SL, SP, #USR_Stack_Size
    
                            ;       IMPORT  TargetResetInit
                            ;       BL              TargetResetInit
    
    ; Enter the C code
    
                    IMPORT  __main
                    LDR     R0, =__main
                    BX      R0
    
    
    ; User Initial Stack & Heap
                    AREA    |.text|, CODE, READONLY
    
                    IMPORT  __use_two_region_memory
                    EXPORT  __user_initial_stackheap
    __user_initial_stackheap
    
                    LDR     R0, =  Heap_Mem
                    LDR     R1, =(Stack_Mem + USR_Stack_Size)
                    LDR     R2, = (Heap_Mem +      Heap_Size)
                    LDR     R3, = Stack_Mem
                    BX      LR
    
                    END
    

    While debugging the execution stuck at "BX R0"
    and instead of jump to main,program execution enter to below loop.

    0x0000012C E2522010 SUBS R2,R2,#0x00000010
    0x00000130 28A10078 STMCSIA R1!,{R3-R6}
    0x00000134 8AFFFFFC BHI 0x0000012C
    


    What will be the problem.
    Plz give some suggestions or solution to this problem

Reply
  • Vectors             LDR     PC, Reset_Addr
                    LDR     PC, Undef_Addr
                    LDR     PC, SWI_Addr
                    LDR     PC, PAbt_Addr
                    LDR     PC, DAbt_Addr
                    NOP                            ; Reserved Vector
                    LDR     PC, IRQ_Addr
                    LDR     PC, [PC, #-0x0120]     ; Vector from VicVectAddr
                    LDR     PC, FIQ_Addr
    
    Reset_Addr      DCD     Reset_Handler
    Undef_Addr      DCD     Undef_Handler
    SWI_Addr
                    DCD     0
    PAbt_Addr       DCD     PAbt_Handler
    DAbt_Addr       DCD     DAbt_Handler
                    DCD             0            ; Reserved Address
    IRQ_Addr
                                     DCD     0
    FIQ_Addr        DCD     FIQ_Handler
    
    
    Undef_Handler   B       Undef_Handler
    SWI_Handler     B       SWI_Handler
    PAbt_Handler    B       PAbt_Handler
    DAbt_Handler    B       DAbt_Handler
    ;IRQ_Handler     B       IRQ_Handler
    FIQ_Handler     B       FIQ_Handler
    
    ; Reset Handler
    
                    EXPORT  Reset_Handler
    Reset_Handler
    
    ; Setup Stack for each mode
                    LDR     R0, =Stack_Top
    
    ;  Enter Undefined Instruction Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #UND_Stack_Size
    
    ;  Enter Abort Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #ABT_Stack_Size
    
    ;  Enter FIQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #FIQ_Stack_Size
    
    ;  Enter IRQ Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #IRQ_Stack_Size
    
    ;  Enter Supervisor Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
                    MOV     SP, R0
                    SUB     R0, R0, #SVC_Stack_Size
    
    ;  Enter User Mode and set its Stack Pointer
                    MSR     CPSR_c, #Mode_USR
                    MOV     SP, R0
                    SUB     SL, SP, #USR_Stack_Size
    
                            ;       IMPORT  TargetResetInit
                            ;       BL              TargetResetInit
    
    ; Enter the C code
    
                    IMPORT  __main
                    LDR     R0, =__main
                    BX      R0
    
    
    ; User Initial Stack & Heap
                    AREA    |.text|, CODE, READONLY
    
                    IMPORT  __use_two_region_memory
                    EXPORT  __user_initial_stackheap
    __user_initial_stackheap
    
                    LDR     R0, =  Heap_Mem
                    LDR     R1, =(Stack_Mem + USR_Stack_Size)
                    LDR     R2, = (Heap_Mem +      Heap_Size)
                    LDR     R3, = Stack_Mem
                    BX      LR
    
                    END
    

    While debugging the execution stuck at "BX R0"
    and instead of jump to main,program execution enter to below loop.

    0x0000012C E2522010 SUBS R2,R2,#0x00000010
    0x00000130 28A10078 STMCSIA R1!,{R3-R6}
    0x00000134 8AFFFFFC BHI 0x0000012C
    


    What will be the problem.
    Plz give some suggestions or solution to this problem

Children