Subversion Repositories NaviCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
#*****************************************************************************
2
#*
3
#*      Project:    Generic include file for ARM startup
4
#*      Filename:   startup.inc
5
#*      Date:       11.05.2004
6
#*      Rights:     Hitex Development Tools GmbH
7
#*                  Greschbachstr. 12
8
#*                  76229  Karlsruhe
9
#*
10
#****************************************************************************
11
 
12
# *** Startup Code (executed after Reset) ***
13
 
14
 
15
# Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
16
 
17
        .equ    Mode_USR,   0x10
18
        .equ    Mode_FIQ,   0x11
19
        .equ    Mode_IRQ,   0x12
20
        .equ    Mode_SVC,   0x13
21
        .equ    Mode_ABT,   0x17
22
        .equ    Mode_UND,   0x1B
23
        .equ    Mode_SYS,   0x1F
24
	    .equ	T_BIT, 0x20	   /* when T bit is set, thumb mode active */
25
        .equ    I_BIT, 0x80        /* when I bit is set, IRQ is disabled */
26
        .equ    F_BIT, 0x40        /* when F bit is set, FIQ is disabled */
27
 
28
# ---------------------------------------------
29
# macro definition for stack memory reservation
30
# ---------------------------------------------
31
# use this macro to setup the stack
32
            .macro  setup_stack label1, size, mode_bits
33
 
34
            .lcomm  __range_\label1, (\size - 1) * 4
35
            .global \label1
36
            .lcomm  \label1, 4
37
 
38
 		    ldr     r0, adr_\label1
39
            msr     CPSR_c, \mode_bits
40
            mov     r13, r0
41
 
42
            .endm
43
 
44
# use this macro to define the label for the setup_stack mcaro!
45
            .macro  stack_adr label1
46
adr_\label1:
47
            .word   \label1
48
            .endm
49
# ---------------------------------------------
50
# copy section
51
# use this macro to copy a section
52
# parameters:
53
# - individual name, used to create labels
54
# - source pointer
55
# - destination pointer
56
# - source pointer + length > end address of source
57
# ---------------------------------------------
58
            .macro  copy_section sec_name, source, destination, source_end
59
 
60
            ldr     R1, =\source
61
            ldr     R2, =\destination
62
            ldr     R3, =\source_end
63
_cplp_\sec_name:
64
            cmp     R1, R3
65
            ldrlo   R0, [R1], #4
66
            strlo   R0, [R2], #4
67
            blo     _cplp_\sec_name
68
 
69
            .endm
70
 
71
# ---------------------------------------------
72
# copy section 2
73
# use this macro to copy a section
74
# parameters:
75
# - individual name, used to create labels
76
# - source pointer
77
# - destination pointer
78
# - destination pointer + length > end address of destination
79
# ---------------------------------------------
80
            .macro  copy_section2 sec_name, source, destination, destination_end
81
 
82
            ldr     R1, =\source
83
            ldr     R2, =\destination
84
            ldr     R3, =\destination_end
85
_cplp_\sec_name:
86
            cmp     R2, R3
87
            ldrlo   R0, [R1], #4
88
            strlo   R0, [R2], #4
89
            blo     _cplp_\sec_name
90
 
91
            .endm
92
 
93
# ---------------------------------------------
94
# clear section
95
# use this macro to clear bss sections
96
# ---------------------------------------------
97
            .macro  clear_section sec_name, source, source_end
98
 
99
            mov     R0, #0
100
            ldr     R1, =\source
101
	        ldr     R2, =\source_end
102
_cllp_\sec_name:
103
            cmp     R1, R2
104
            strlo   R0, [R1], #4
105
	        blo     _cllp_\sec_name
106
            .endm
107
 
108
# ---------------------------------------------
109
# examples how to use the macros
110
# ---------------------------------------------
111
# Setup stacks for the operating modes
112
# ---------------------------------------------
113
 
114
#            setup_stack  UND_Stack, UND_Stack_Size, #Mode_UND|I_BIT|F_BIT
115
#            setup_stack  SVC_Stack, SVC_Stack_Size, #Mode_SVC|I_BIT|F_BIT
116
#            setup_stack  ABT_Stack, ABT_Stack_Size, #Mode_ABT|I_BIT|F_BIT
117
#            setup_stack  FIQ_Stack, FIQ_Stack_Size, #Mode_FIQ|I_BIT|F_BIT
118
#            setup_stack  IRQ_Stack, IRQ_Stack_Size, #Mode_IRQ|I_BIT|F_BIT
119
#            setup_stack  USR_Stack, USR_Stack_Size, #Mode_USR
120
 
121
# ---------------------------------------------
122
# copy sections
123
# ---------------------------------------------
124
 
125
# copy code into internal ram
126
#            copy_section code, __code_start__, RAM_Base_Boot, __code_end__
127
 
128
# Relocate .data section (Copy from ROM to RAM)
129
#            copy_section data, __data_start__, __data_start__+RAM_Base_Boot, __data_end__
130
 
131
# ---------------------------------------------
132
# Clear .bss section
133
# ---------------------------------------------
134
 
135
# Clear .bss section (Zero init)
136
#            clear_section bss, __bss_start__, __bss_end__
137
 
138
# ---------------------------------------------
139
# startup delay
140
# use this macro if you are working with an debugger
141
# the startup delay avoid problems while
142
# the application start before the debug interface
143
# becomes controled by the debugger
144
# ---------------------------------------------
145
 
146
# a goodf choice for the delay value is
147
# cpu clock / 100 with ATMEL controllers
148
# cpu clock / 40  with Philips controllers
149
 
150
            .macro  StartupDelay delay_value
151
 
152
            ldr     R1, =\delay_value
153
            ldr     R2, =0
154
__StartDelay:
155
            sub     R1, R1, #1
156
            cmp     R1, R2
157
            bhi     __StartDelay
158
 
159
            .endm
160
 
161
# ---------------------------------------------