Skip to content

Commit f44914d

Browse files
committed
Merge pull request #50 from dinau/lpc2368
LPC2368 [GCC_ARM, GCC_CR]: Startup codes
2 parents c9fc35f + 8503ccb commit f44914d

File tree

8 files changed

+184
-243
lines changed

8 files changed

+184
-243
lines changed

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/TOOLCHAIN_GCC_ARM/LPC2368.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ SECTIONS
142142
/* Heap starts here and grows up in memory */
143143
. = ALIGN( 8 ) ;
144144
__heap_start__ = . ;
145+
end = . ;
145146

146147
.stab 0 (NOLOAD) : { *(.stab) }
147148
.stabstr 0 (NOLOAD) : { *(.stabstr) }
Lines changed: 87 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,149 @@
1-
# 1 "vector_functions.s"
2-
# 1 "<built-in>"
3-
# 1 "<command line>"
4-
# 1 "vector_functions.s"
5-
;
6-
;
7-
;
1+
/* .include "vector_defns.h" */
82

9-
# 1 "vector_defns.h" 1
10-
# 6 "vector_functions.s" 2
113

124

5+
.section .privileged_code, "ax"
6+
.arm
137

148

9+
.weak __mbed_fiq
10+
.weak __mbed_undef
11+
.weak __mbed_prefetch_abort
12+
.weak __mbed_data_abort
13+
.weak __mbed_irq
14+
.weak __mbed_swi
15+
.weak __mbed_dcc_irq
16+
.weak __mbed_reset
17+
.global __mbed_init_realmonitor
18+
/* .global __mbed_init */
1519

1620

17-
.section VECFUNCS, "ax"
18-
.arm
1921

2022

21-
.weak __mbed_fiq
22-
.weak __mbed_undef
23-
.weak __mbed_prefetch_abort
24-
.weak __mbed_data_abort
25-
.weak __mbed_irq
26-
.weak __mbed_swi
27-
.weak __mbed_dcc_irq
28-
.weak __mbed_reset
29-
.global __mbed_init_realmonitor
30-
.global __mbed_init
31-
32-
;
33-
;
3423
__mbed_fiq:
3524
B __mbed_fiq
36-
37-
;
38-
;
3925
__mbed_undef:
4026
LDR PC, =0x7fffffa0
41-
42-
;
43-
;
4427
__mbed_prefetch_abort:
4528
LDR PC, =0x7fffffb0
46-
47-
;
48-
;
4929
__mbed_data_abort:
5030
LDR PC, =0x7fffffc0
51-
52-
;
53-
;
54-
;
55-
;
56-
;
57-
;
58-
;
59-
;
60-
;
6131
__mbed_irq:
62-
;
6332
MSR CPSR_c, #0x1F|0x80|0x40
64-
65-
;
33+
6634
STMDB sp!, {r0-r3,r12,lr}
67-
68-
;
35+
6936
MOV r0, #0xFFFFFF00
7037
LDR r0, [r0]
71-
72-
;
38+
7339
MOV lr, pc
7440
BX r0
75-
76-
;
41+
7742
MOV r0, #0xFFFFFF00
78-
STR r0, [r0] ;
79-
80-
;
43+
STR r0, [r0]
44+
8145
LDMFD sp!,{r0-r3,r12,lr}
82-
83-
;
46+
8447
MSR CPSR_c, #0x12|0x80|0x40
85-
86-
;
48+
8749
SUBS pc, lr, #4
88-
89-
;
90-
;
91-
;
92-
;
9350
__mbed_swi:
94-
;
95-
;
9651
STMFD sp!, {a4, r4, ip, lr}
97-
98-
;
52+
9953
LDR r4, =0x40000040
100-
101-
;
102-
;
54+
10355
LDR a4, =0x00940000
10456
LDR PC, =0x7ffff820
105-
106-
;
107-
;
108-
;
109-
;
11057
__mbed_dcc_irq:
111-
112-
;
113-
114-
;
11558
LDMFD sp!,{r0-r3,r12,lr}
116-
117-
;
59+
11860
MSR CPSR_c, #0x12|0x80|0x40
119-
120-
;
121-
122-
;
123-
SUB lr, lr, #4 ;
124-
STMFD sp!, {ip,lr} ;
125-
126-
;
61+
62+
SUB lr, lr, #4
63+
STMFD sp!, {ip,lr}
64+
12765
LDR LR, =0xfffff000
12866
STR LR, [LR, #0xf00]
129-
130-
;
131-
;
132-
;
133-
;
67+
13468
LDR PC, =0x7fffffe0
69+
/*
70+
__mbed_reset is called after reset
71+
we setup the stacks and realmonitor, then call Reset_Handler like on M3
72+
*/
73+
74+
.section .text, "ax"
75+
.arm
76+
.global Reset_handler
77+
Reset_Handler:
78+
.extern __libc_init_array
79+
.extern SystemInit
80+
.extern __wrap_main
81+
LDR R0, =SystemInit
82+
MOV LR, PC
83+
BX R0
84+
85+
LDR R0, =__libc_init_array
86+
MOV LR, PC
87+
BX R0
88+
89+
LDR R0, =__wrap_main
90+
BX R0
13591

136-
;
137-
;
13892
__mbed_reset:
139-
140-
;
141-
142-
LDR R0, =(0x40000000 + 0x8000)
143-
144-
;
93+
LDR R0, =( __SRAM_segment_end__ )
94+
14595
MSR CPSR_c, #0x1B|0x80|0x40
14696
MOV SP, R0
14797
SUB R0, R0, #0x00000040
148-
149-
;
98+
15099
MSR CPSR_c, #0x17|0x80|0x40
151100
MOV SP, R0
152101
SUB R0, R0, #0x00000040
153-
154-
;
102+
155103
MSR CPSR_c, #0x11|0x80|0x40
156104
MOV SP, R0
157105
SUB R0, R0, #0x00000000
158-
159-
;
106+
160107
MSR CPSR_c, #0x12|0x80|0x40
161108
MOV SP, R0
162109
SUB R0, R0, #0x00000040
163-
164-
;
110+
165111
MSR CPSR_c, #0x13|0x80|0x40
166112
MOV SP, R0
167113
SUB R0, R0, #0x00000040
168-
169-
;
114+
170115
MSR CPSR_c, #0x10
171116
MOV SP, R0
172-
173-
;
117+
118+
/* Relocate .data section (Copy from ROM to RAM) */
119+
LDR R1, =__text_end__ /* _etext */
120+
LDR R2, =__data_start__ /* _data */
121+
LDR R3, =__data_end__ /* _edata */
122+
CMP R2, R3
123+
BEQ DataIsEmpty
124+
LoopRel: CMP R2, R3
125+
LDRLO R0, [R1], #4
126+
STRLO R0, [R2], #4
127+
BLO LoopRel
128+
DataIsEmpty:
129+
130+
/* Clear .bss section (Zero init) */
131+
MOV R0, #0
132+
LDR R1, =__bss_start__
133+
LDR R2, =__bss_end__
134+
CMP R1,R2
135+
BEQ BSSIsEmpty
136+
LoopZI: CMP R1, R2
137+
STRLO R0, [R1], #4
138+
BLO LoopZI
139+
BSSIsEmpty:
140+
141+
142+
/* Init realmonitor */
174143
LDR R0, =__mbed_init_realmonitor
175144
MOV LR, PC
176145
BX R0
177-
178-
;
179-
LDR R0, =__mbed_init
146+
147+
/* Go to Reset_Handler */
148+
LDR R0, =Reset_Handler
180149
BX R0

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/TOOLCHAIN_GCC_ARM/vector_table.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020

21-
.section VECTOR_TABLE, "ax"
21+
.section .vectors, "ax"
2222
.arm
2323

2424

@@ -34,7 +34,7 @@
3434
;
3535

3636

37-
__main:
37+
_start:
3838
LDR PC, =__mbed_reset
3939
LDR PC, =__mbed_undef
4040
LDR PC, =__mbed_swi

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/TOOLCHAIN_GCC_CR/LPC2368.ld

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
22
OUTPUT_ARCH(arm)
33
ENTRY(vectors)
44

5-
GROUP(-lsupc++ -lm -lc -lgcc)
5+
GROUP( libgcc.a libc.a libm.a libcr_newlib_nohost.a crti.o crtn.o crtbegin.o crtend.o )
66

77
/* Memory Definitions: */
88
MEMORY
@@ -144,6 +144,8 @@ SECTIONS
144144
/* Heap starts here and grows up in memory */
145145
. = ALIGN( 8 ) ;
146146
__heap_start__ = . ;
147+
_pvHeapStart = . ;
148+
end = . ;
147149

148150
.stab 0 (NOLOAD) : { *(.stab) }
149151
.stabstr 0 (NOLOAD) : { *(.stabstr) }

0 commit comments

Comments
 (0)