Project

General

Profile

Download (4.9 KB) Statistics
| Branch: | Revision:

root / fw / boot / board_cstartup_iar.s @ 14:d3713e2e39d0

1
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support 
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 * All rights reserved.
6

    
7
 * ----------------------------------------------------------------------------
8
 */
9

    
10
/*
11
     IAR startup file for AT91SAM7S microcontrollers.
12
 */
13

    
14
        MODULE  ?cstartup
15

    
16
        ;; Forward declaration of sections.
17
        SECTION IRQ_STACK:DATA:NOROOT(2)
18
        SECTION CSTACK:DATA:NOROOT(3)
19

    
20
//------------------------------------------------------------------------------
21
//         Headers
22
//------------------------------------------------------------------------------
23

    
24
#define __ASSEMBLY__
25
#include "board.h"
26

    
27
//------------------------------------------------------------------------------
28
//         Definitions
29
//------------------------------------------------------------------------------
30

    
31
#define ARM_MODE_ABT     0x17
32
#define ARM_MODE_FIQ     0x11
33
#define ARM_MODE_IRQ     0x12
34
#define ARM_MODE_SVC     0x13
35
#define ARM_MODE_SYS     0x1F
36

    
37
#define I_BIT            0x80
38
#define F_BIT            0x40
39

    
40
//------------------------------------------------------------------------------
41
//         Startup routine
42
//------------------------------------------------------------------------------
43

    
44
/*
45
   Exception vectors
46
 */
47
        SECTION .vectors:CODE:NOROOT(2)
48

    
49
        PUBLIC  resetVector
50
        PUBLIC  irqHandler
51

    
52
        EXTERN  Undefined_Handler
53
        EXTERN  SWI_Handler
54
        EXTERN  Prefetch_Handler
55
        EXTERN  Abort_Handler
56
        EXTERN  FIQ_Handler
57

    
58
        ARM
59

    
60
__iar_init$$done:               ; The interrupt vector is not needed
61
                                ; until after copy initialization is done
62

    
63
resetVector:
64
        ; All default exception handlers (except reset) are
65
        ; defined as weak symbol definitions.
66
        ; If a handler is defined by the application it will take precedence.
67
        LDR     pc, =resetHandler        ; Reset
68
        LDR     pc, Undefined_Addr       ; Undefined instructions
69
        LDR     pc, SWI_Addr             ; Software interrupt (SWI/SVC)
70
        LDR     pc, Prefetch_Addr        ; Prefetch abort
71
        LDR     pc, Abort_Addr           ; Data abort
72
        B       .                        ; RESERVED
73
        LDR     pc, =irqHandler          ; IRQ
74
        LDR     pc, FIQ_Addr             ; FIQ
75

    
76
Undefined_Addr: DCD   Undefined_Handler
77
SWI_Addr:       DCD   SWI_Handler
78
Prefetch_Addr:  DCD   Prefetch_Handler
79
Abort_Addr:     DCD   Abort_Handler
80
FIQ_Addr:       DCD   FIQ_Handler
81
	
82
/*
83
   Handles incoming interrupt requests by branching to the corresponding
84
   handler, as defined in the AIC. Supports interrupt nesting.
85
 */
86
irqHandler:
87
        /* Save interrupt context on the stack to allow nesting */
88
        SUB     lr, lr, #4
89
        STMFD   sp!, {lr}
90
        MRS     lr, SPSR
91
        STMFD   sp!, {r0, lr}
92

    
93
        /* Write in the IVR to support Protect Mode */
94
        LDR     lr, =AT91C_BASE_AIC
95
        LDR     r0, [r14, #AIC_IVR]
96
        STR     lr, [r14, #AIC_IVR]
97

    
98
        /* Branch to interrupt handler in Supervisor mode */
99
        MSR     CPSR_c, #ARM_MODE_SVC
100
        STMFD   sp!, {r1-r3, r12, lr}
101
        MOV     lr, pc
102
        BX      r0
103
        LDMIA   sp!, {r1-r3, r12, lr}
104
        MSR     CPSR_c, #ARM_MODE_IRQ | I_BIT
105

    
106
        /* Acknowledge interrupt */
107
        LDR     lr, =AT91C_BASE_AIC
108
        STR     lr, [r14, #AIC_EOICR]
109

    
110
        /* Restore interrupt context and branch back to calling code */
111
        LDMIA   sp!, {r0, lr}
112
        MSR     SPSR_cxsf, lr
113
        LDMIA   sp!, {pc}^
114

    
115

    
116
/*
117
   After a reset, execution starts here, the mode is ARM, supervisor
118
   with interrupts disabled.
119
   Initializes the chip and branches to the main() function.
120
 */
121
        SECTION .cstartup:CODE:NOROOT(2)
122

    
123
        PUBLIC  resetHandler
124
        EXTERN  LowLevelInit
125
        EXTERN  ?main
126
        REQUIRE resetVector
127
        ARM
128

    
129
resetHandler:
130

    
131
        /* Set pc to actual code location (i.e. not in remap zone) */
132
rf	    LDR     pc, =label
133

    
134
        /* Perform low-level initialization of the chip using LowLevelInit() */
135
label:
136
	    LDR     r0, =LowLevelInit
137
        LDR     r4, =SFE(CSTACK)
138
        MOV     sp, r4
139
        MOV     lr, pc
140
        BX      r0
141

    
142
        /* Set up the interrupt stack pointer. */
143
        MSR     cpsr_c, #ARM_MODE_IRQ | I_BIT | F_BIT      ; Change the mode
144
        LDR     sp, =SFE(IRQ_STACK)
145

    
146
        /* Set up the SVC stack pointer. */
147
        MSR     cpsr_c, #ARM_MODE_SVC | F_BIT              ; Change the mode
148
        LDR     sp, =SFE(CSTACK)
149

    
150
        /* Branch to main() */
151
        LDR     r0, =?main
152
        MOV     lr, pc
153
        BX      r0
154

    
155
        /* Loop indefinitely when program is finished */
156
loop4:
157
        B       loop4
158

    
159
        END
(4-4/7)