blob: 2f914e9b4e2fd6317861831af025693990c9495a [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * armboot - Startup Code for ARM720 CPU-core
3 *
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02004 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
5 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
wdenkfe8c2802002-11-03 00:38:21 +00006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenkcdc7fea2004-07-11 22:27:55 +000017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkfe8c2802002-11-03 00:38:21 +000018 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020026#include <asm-offsets.h>
wdenkfe8c2802002-11-03 00:38:21 +000027#include <config.h>
28#include <version.h>
wdenk39539882004-07-01 16:30:44 +000029#include <asm/hardware.h>
wdenkfe8c2802002-11-03 00:38:21 +000030
31/*
32 *************************************************************************
33 *
34 * Jump vector table as in table 3.1 in [1]
35 *
36 *************************************************************************
37 */
38
39
40.globl _start
wdenkcdc7fea2004-07-11 22:27:55 +000041_start: b reset
wdenkfe8c2802002-11-03 00:38:21 +000042 ldr pc, _undefined_instruction
43 ldr pc, _software_interrupt
44 ldr pc, _prefetch_abort
45 ldr pc, _data_abort
Gary Jennejohn6bd24472007-01-24 12:16:56 +010046#ifdef CONFIG_LPC2292
47 .word 0xB4405F76 /* 2's complement of the checksum of the vectors */
48#else
wdenkfe8c2802002-11-03 00:38:21 +000049 ldr pc, _not_used
Gary Jennejohn6bd24472007-01-24 12:16:56 +010050#endif
wdenkfe8c2802002-11-03 00:38:21 +000051 ldr pc, _irq
52 ldr pc, _fiq
53
Allen Martinc7da6c62012-08-31 08:30:07 +000054#ifdef CONFIG_SPL_BUILD
55_undefined_instruction: .word _undefined_instruction
56_software_interrupt: .word _software_interrupt
57_prefetch_abort: .word _prefetch_abort
58_data_abort: .word _data_abort
59_not_used: .word _not_used
60_irq: .word _irq
61_fiq: .word _fiq
Allen Martinc037c932012-08-31 08:30:09 +000062_pad: .word 0x12345678 /* now 16*4=64 */
Allen Martinc7da6c62012-08-31 08:30:07 +000063#else
wdenkcdc7fea2004-07-11 22:27:55 +000064_undefined_instruction: .word undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +000065_software_interrupt: .word software_interrupt
66_prefetch_abort: .word prefetch_abort
67_data_abort: .word data_abort
68_not_used: .word not_used
69_irq: .word irq
70_fiq: .word fiq
Allen Martinc037c932012-08-31 08:30:09 +000071_pad: .word 0x12345678 /* now 16*4=64 */
Allen Martinc7da6c62012-08-31 08:30:07 +000072#endif /* CONFIG_SPL_BUILD */
wdenkfe8c2802002-11-03 00:38:21 +000073
74 .balignl 16,0xdeadbeef
75
76
77/*
78 *************************************************************************
79 *
80 * Startup Code (reset vector)
81 *
wdenkf6e20fc2004-02-08 19:38:38 +000082 * do important init only if we don't start from RAM!
wdenkfe8c2802002-11-03 00:38:21 +000083 * relocate armboot to ram
84 * setup stack
85 * jump to second stage
86 *
87 *************************************************************************
88 */
89
Heiko Schocherabef7b82010-09-17 13:10:52 +020090.globl _TEXT_BASE
wdenkfe8c2802002-11-03 00:38:21 +000091_TEXT_BASE:
Allen Martinc037c932012-08-31 08:30:09 +000092#ifdef CONFIG_SPL_BUILD
93 .word CONFIG_SPL_TEXT_BASE
94#else
Wolfgang Denk14d0a022010-10-07 21:51:12 +020095 .word CONFIG_SYS_TEXT_BASE
Allen Martinc037c932012-08-31 08:30:09 +000096#endif
wdenkfe8c2802002-11-03 00:38:21 +000097
wdenkfe8c2802002-11-03 00:38:21 +000098/*
wdenkf6e20fc2004-02-08 19:38:38 +000099 * These are defined in the board-specific linker script.
Albert Aribaud3336ca62010-11-25 22:45:02 +0100100 * Subtracting _start from them lets the linker put their
101 * relative position in the executable instead of leaving
102 * them null.
wdenkfe8c2802002-11-03 00:38:21 +0000103 */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100104.globl _bss_start_ofs
105_bss_start_ofs:
106 .word __bss_start - _start
wdenkf6e20fc2004-02-08 19:38:38 +0000107
Albert Aribaud3336ca62010-11-25 22:45:02 +0100108.globl _bss_end_ofs
109_bss_end_ofs:
Po-Yu Chuang44c6e652011-03-01 22:59:59 +0000110 .word __bss_end__ - _start
wdenkfe8c2802002-11-03 00:38:21 +0000111
Po-Yu Chuangf326cbb2011-03-01 23:02:04 +0000112.globl _end_ofs
113_end_ofs:
114 .word _end - _start
115
wdenkfe8c2802002-11-03 00:38:21 +0000116#ifdef CONFIG_USE_IRQ
117/* IRQ stack memory (calculated at run-time) */
118.globl IRQ_STACK_START
119IRQ_STACK_START:
120 .word 0x0badc0de
121
122/* IRQ stack memory (calculated at run-time) */
123.globl FIQ_STACK_START
124FIQ_STACK_START:
125 .word 0x0badc0de
126#endif
127
Heiko Schocherabef7b82010-09-17 13:10:52 +0200128/* IRQ stack memory (calculated at run-time) + 8 bytes */
129.globl IRQ_STACK_START_IN
130IRQ_STACK_START_IN:
131 .word 0x0badc0de
132
Heiko Schocherabef7b82010-09-17 13:10:52 +0200133/*
134 * the actual reset code
135 */
136
137reset:
138 /*
139 * set the cpu to SVC32 mode
140 */
141 mrs r0,cpsr
142 bic r0,r0,#0x1f
143 orr r0,r0,#0xd3
144 msr cpsr,r0
145
146 /*
147 * we do sys-critical inits only at reboot,
148 * not when booting from ram!
149 */
150#ifndef CONFIG_SKIP_LOWLEVEL_INIT
151 bl cpu_init_crit
152#endif
153
154#ifdef CONFIG_LPC2292
155 bl lowlevel_init
156#endif
157
158/* Set stackpointer in internal RAM to call board_init_f */
159call_board_init_f:
160 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
Heiko Schocher296cae72010-11-12 07:53:55 +0100161 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200162 ldr r0,=0x00000000
163 bl board_init_f
164
165/*------------------------------------------------------------------------------*/
166
167/*
168 * void relocate_code (addr_sp, gd, addr_moni)
169 *
170 * This "function" does not return, instead it continues in RAM
171 * after relocating the monitor code.
172 *
173 */
174 .globl relocate_code
175relocate_code:
176 mov r4, r0 /* save addr_sp */
177 mov r5, r1 /* save addr of gd */
178 mov r6, r2 /* save addr of destination */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200179
180 /* Set up the stack */
181stack_setup:
182 mov sp, r4
183
184 adr r0, _start
Andreas Bießmanna1a47d32010-12-01 00:58:34 +0100185 cmp r0, r6
Allen Martinc7da6c62012-08-31 08:30:07 +0000186 moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */
Andreas Bießmanna1a47d32010-12-01 00:58:34 +0100187 beq clear_bss /* skip relocation */
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100188 mov r1, r6 /* r1 <- scratch for copy_loop */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100189 ldr r3, _bss_start_ofs
190 add r2, r0, r3 /* r2 <- source end address */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200191
Heiko Schocherabef7b82010-09-17 13:10:52 +0200192copy_loop:
193 ldmia r0!, {r9-r10} /* copy from source address [r0] */
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100194 stmia r1!, {r9-r10} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200195 cmp r0, r2 /* until source end address [r2] */
196 blo copy_loop
Heiko Schocherabef7b82010-09-17 13:10:52 +0200197
Aneesh V401bb302011-07-13 05:11:07 +0000198#ifndef CONFIG_SPL_BUILD
Albert Aribaud3336ca62010-11-25 22:45:02 +0100199 /*
200 * fix .rel.dyn relocations
201 */
202 ldr r0, _TEXT_BASE /* r0 <- Text base */
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100203 sub r9, r6, r0 /* r9 <- relocation offset */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100204 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
205 add r10, r10, r0 /* r10 <- sym table in FLASH */
206 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
207 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
208 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
209 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200210fixloop:
Albert Aribaud3336ca62010-11-25 22:45:02 +0100211 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
212 add r0, r0, r9 /* r0 <- location to fix up in RAM */
213 ldr r1, [r2, #4]
Andreas Bießmann1f52d892010-12-01 00:58:35 +0100214 and r7, r1, #0xff
215 cmp r7, #23 /* relative fixup? */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100216 beq fixrel
Andreas Bießmann1f52d892010-12-01 00:58:35 +0100217 cmp r7, #2 /* absolute fixup? */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100218 beq fixabs
219 /* ignore unknown type of fixup */
220 b fixnext
221fixabs:
222 /* absolute fix: set location to (offset) symbol value */
223 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
224 add r1, r10, r1 /* r1 <- address of symbol in table */
225 ldr r1, [r1, #4] /* r1 <- symbol value */
Wolfgang Denk36009452010-12-09 11:26:24 +0100226 add r1, r1, r9 /* r1 <- relocated sym addr */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100227 b fixnext
228fixrel:
229 /* relative fix: increase location by offset */
230 ldr r1, [r0]
231 add r1, r1, r9
232fixnext:
233 str r1, [r0]
234 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200235 cmp r2, r3
Wolfgang Denk79e63132010-10-23 23:22:38 +0200236 blo fixloop
Heiko Schocherabef7b82010-09-17 13:10:52 +0200237#endif
Heiko Schocherabef7b82010-09-17 13:10:52 +0200238
239clear_bss:
Aneesh V401bb302011-07-13 05:11:07 +0000240#ifndef CONFIG_SPL_BUILD
Albert Aribaud3336ca62010-11-25 22:45:02 +0100241 ldr r0, _bss_start_ofs
242 ldr r1, _bss_end_ofs
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100243 mov r4, r6 /* reloc addr */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200244 add r0, r0, r4
Heiko Schocherabef7b82010-09-17 13:10:52 +0200245 add r1, r1, r4
246 mov r2, #0x00000000 /* clear */
247
Zhong Hongbo448217d2012-07-07 03:24:33 +0000248clbss_l:cmp r0, r1 /* clear loop... */
249 bhs clbss_e /* if reached end of bss, exit */
250 str r2, [r0]
Heiko Schocherabef7b82010-09-17 13:10:52 +0200251 add r0, r0, #4
Zhong Hongbo448217d2012-07-07 03:24:33 +0000252 b clbss_l
253clbss_e:
Heiko Schocherabef7b82010-09-17 13:10:52 +0200254
255 bl coloured_LED_init
Jason Kridner2d3be7c2011-09-04 14:40:16 -0400256 bl red_led_on
Heiko Schocherabef7b82010-09-17 13:10:52 +0200257#endif
258
259/*
260 * We are done. Do not return, instead branch to second part of board
261 * initialization, now running from RAM.
262 */
Albert Aribaud3336ca62010-11-25 22:45:02 +0100263 ldr r0, _board_init_r_ofs
264 adr r1, _start
265 add lr, r0, r1
266 add lr, lr, r9
Heiko Schocherabef7b82010-09-17 13:10:52 +0200267 /* setup parameters for board_init_r */
268 mov r0, r5 /* gd_t */
Andreas Bießmanna78fb682010-12-01 00:58:33 +0100269 mov r1, r6 /* dest_addr */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200270 /* jump to it ... */
Heiko Schocherabef7b82010-09-17 13:10:52 +0200271 mov pc, lr
272
Albert Aribaud3336ca62010-11-25 22:45:02 +0100273_board_init_r_ofs:
274 .word board_init_r - _start
275
276_rel_dyn_start_ofs:
277 .word __rel_dyn_start - _start
278_rel_dyn_end_ofs:
279 .word __rel_dyn_end - _start
280_dynsym_start_ofs:
281 .word __dynsym_start - _start
Heiko Schocherabef7b82010-09-17 13:10:52 +0200282
wdenkfe8c2802002-11-03 00:38:21 +0000283/*
284 *************************************************************************
285 *
286 * CPU_init_critical registers
287 *
288 * setup important registers
289 * setup memory timing
290 *
291 *************************************************************************
292 */
293
Wolfgang Denkc1f87502011-09-05 14:37:30 +0200294#if defined(CONFIG_LPC2292)
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100295PLLCFG_ADR: .word PLLCFG
296PLLFEED_ADR: .word PLLFEED
297PLLCON_ADR: .word PLLCON
298PLLSTAT_ADR: .word PLLSTAT
299VPBDIV_ADR: .word VPBDIV
300MEMMAP_ADR: .word MEMMAP
301
wdenk39539882004-07-01 16:30:44 +0000302#endif
303
wdenkfe8c2802002-11-03 00:38:21 +0000304cpu_init_crit:
Wolfgang Denkc1f87502011-09-05 14:37:30 +0200305#if defined(CONFIG_NETARM)
wdenk2d1a5372004-02-23 19:30:57 +0000306 /*
307 * prior to software reset : need to set pin PORTC4 to be *HRESET
308 */
309 ldr r0, =NETARM_GEN_MODULE_BASE
310 ldr r1, =(NETARM_GEN_PORT_MODE(0x10) | \
311 NETARM_GEN_PORT_DIR(0x10))
312 str r1, [r0, #+NETARM_GEN_PORTC]
313 /*
314 * software reset : see HW Ref. Guide 8.2.4 : Software Service register
wdenkcdc7fea2004-07-11 22:27:55 +0000315 * for an explanation of this process
wdenk2d1a5372004-02-23 19:30:57 +0000316 */
317 ldr r0, =NETARM_GEN_MODULE_BASE
318 ldr r1, =NETARM_GEN_SW_SVC_RESETA
319 str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
320 ldr r1, =NETARM_GEN_SW_SVC_RESETB
321 str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
322 ldr r1, =NETARM_GEN_SW_SVC_RESETA
323 str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
324 ldr r1, =NETARM_GEN_SW_SVC_RESETB
325 str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
326 /*
327 * setup PLL and System Config
328 */
329 ldr r0, =NETARM_GEN_MODULE_BASE
330
331 ldr r1, =( NETARM_GEN_SYS_CFG_LENDIAN | \
332 NETARM_GEN_SYS_CFG_BUSFULL | \
333 NETARM_GEN_SYS_CFG_USER_EN | \
334 NETARM_GEN_SYS_CFG_ALIGN_ABORT | \
335 NETARM_GEN_SYS_CFG_BUSARB_INT | \
336 NETARM_GEN_SYS_CFG_BUSMON_EN )
337
338 str r1, [r0, #+NETARM_GEN_SYSTEM_CONTROL]
339
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200340#ifndef CONFIG_NETARM_PLL_BYPASS
wdenk2d1a5372004-02-23 19:30:57 +0000341 ldr r1, =( NETARM_GEN_PLL_CTL_PLLCNT(NETARM_PLL_COUNT_VAL) | \
342 NETARM_GEN_PLL_CTL_POLTST_DEF | \
343 NETARM_GEN_PLL_CTL_INDIV(1) | \
344 NETARM_GEN_PLL_CTL_ICP_DEF | \
345 NETARM_GEN_PLL_CTL_OUTDIV(2) )
346 str r1, [r0, #+NETARM_GEN_PLL_CONTROL]
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200347#endif
348
wdenk2d1a5372004-02-23 19:30:57 +0000349 /*
350 * mask all IRQs by clearing all bits in the INTMRs
351 */
352 mov r1, #0
353 ldr r0, =NETARM_GEN_MODULE_BASE
354 str r1, [r0, #+NETARM_GEN_INTR_ENABLE]
wdenk39539882004-07-01 16:30:44 +0000355
356#elif defined(CONFIG_S3C4510B)
357
358 /*
359 * Mask off all IRQ sources
360 */
361 ldr r1, =REG_INTMASK
362 ldr r0, =0x3FFFFF
363 str r0, [r1]
364
365 /*
366 * Disable Cache
367 */
368 ldr r0, =REG_SYSCFG
wdenkcdc7fea2004-07-11 22:27:55 +0000369 ldr r1, =0x83ffffa0 /* cache-disabled */
wdenk39539882004-07-01 16:30:44 +0000370 str r1, [r0]
371
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200372#elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
373 /* No specific initialisation for IntegratorAP/CM720T as yet */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100374#elif defined(CONFIG_LPC2292)
375 /* Set-up PLL */
376 mov r3, #0xAA
377 mov r4, #0x55
Wolfgang Denkf8db84f2007-01-30 00:50:40 +0100378 /* First disconnect and disable the PLL */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100379 ldr r0, PLLCON_ADR
380 mov r1, #0x00
381 str r1, [r0]
382 ldr r0, PLLFEED_ADR /* start feed sequence */
383 str r3, [r0]
Wolfgang Denkf8db84f2007-01-30 00:50:40 +0100384 str r4, [r0] /* feed sequence done */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100385 /* Set new M and P values */
386 ldr r0, PLLCFG_ADR
387 mov r1, #0x23 /* M=4 and P=2 */
388 str r1, [r0]
389 ldr r0, PLLFEED_ADR /* start feed sequence */
390 str r3, [r0]
391 str r4, [r0] /* feed sequence done */
392 /* Then enable the PLL */
393 ldr r0, PLLCON_ADR
394 mov r1, #0x01 /* PLL enable bit */
395 str r1, [r0]
396 ldr r0, PLLFEED_ADR /* start feed sequence */
397 str r3, [r0]
398 str r4, [r0] /* feed sequence done */
Wolfgang Denkf8db84f2007-01-30 00:50:40 +0100399 /* Wait for the lock */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100400 ldr r0, PLLSTAT_ADR
401 mov r1, #0x400 /* lock bit */
Wolfgang Denkf8db84f2007-01-30 00:50:40 +0100402lock_loop:
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100403 ldr r2, [r0]
404 and r2, r1, r2
405 cmp r2, #0
406 beq lock_loop
407 /* And finally connect the PLL */
408 ldr r0, PLLCON_ADR
409 mov r1, #0x03 /* PLL enable bit and connect bit */
410 str r1, [r0]
411 ldr r0, PLLFEED_ADR /* start feed sequence */
412 str r3, [r0]
Wolfgang Denkf8db84f2007-01-30 00:50:40 +0100413 str r4, [r0] /* feed sequence done */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100414 /* Set-up VPBDIV register */
415 ldr r0, VPBDIV_ADR
416 mov r1, #0x01 /* VPB clock is same as process clock */
417 str r1, [r0]
Allen Martinc037c932012-08-31 08:30:09 +0000418#elif defined(CONFIG_TEGRA)
419 /* No cpu_init_crit for tegra as yet */
wdenk39539882004-07-01 16:30:44 +0000420#else
421#error No cpu_init_crit() defined for current CPU type
422#endif
wdenkfe8c2802002-11-03 00:38:21 +0000423
424#ifdef CONFIG_ARM7_REVD
425 /* set clock speed */
426 /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
427 /* !!! not doing DRAM refresh properly! */
428 ldr r0, SYSCON3
429 ldr r1, [r0]
430 bic r1, r1, #CLKCTL
431 orr r1, r1, #CLKCTL_36
432 str r1, [r0]
433#endif
434
Allen Martinc037c932012-08-31 08:30:09 +0000435#if !defined(CONFIG_LPC2292) && !defined(CONFIG_TEGRA)
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200436 mov ip, lr
wdenkfe8c2802002-11-03 00:38:21 +0000437 /*
438 * before relocating, we have to setup RAM timing
wdenkf6e20fc2004-02-08 19:38:38 +0000439 * because memory timing is board-dependent, you will
wdenk400558b2005-04-02 23:52:25 +0000440 * find a lowlevel_init.S in your board directory.
wdenkfe8c2802002-11-03 00:38:21 +0000441 */
wdenk400558b2005-04-02 23:52:25 +0000442 bl lowlevel_init
wdenkfe8c2802002-11-03 00:38:21 +0000443 mov lr, ip
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100444#endif
wdenkfe8c2802002-11-03 00:38:21 +0000445
446 mov pc, lr
447
448
Allen Martinc7da6c62012-08-31 08:30:07 +0000449#ifndef CONFIG_SPL_BUILD
wdenkfe8c2802002-11-03 00:38:21 +0000450/*
451 *************************************************************************
452 *
453 * Interrupt handling
454 *
455 *************************************************************************
456 */
457
458@
459@ IRQ stack frame.
460@
461#define S_FRAME_SIZE 72
462
463#define S_OLD_R0 68
464#define S_PSR 64
465#define S_PC 60
466#define S_LR 56
467#define S_SP 52
468
469#define S_IP 48
470#define S_FP 44
471#define S_R10 40
472#define S_R9 36
473#define S_R8 32
474#define S_R7 28
475#define S_R6 24
476#define S_R5 20
477#define S_R4 16
478#define S_R3 12
479#define S_R2 8
480#define S_R1 4
481#define S_R0 0
482
483#define MODE_SVC 0x13
484#define I_BIT 0x80
485
486/*
487 * use bad_save_user_regs for abort/prefetch/undef/swi ...
488 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
489 */
490
491 .macro bad_save_user_regs
492 sub sp, sp, #S_FRAME_SIZE
493 stmia sp, {r0 - r12} @ Calling r0-r12
wdenkcdc7fea2004-07-11 22:27:55 +0000494 add r8, sp, #S_PC
wdenkfe8c2802002-11-03 00:38:21 +0000495
Heiko Schocherabef7b82010-09-17 13:10:52 +0200496 ldr r2, IRQ_STACK_START_IN
wdenkcdc7fea2004-07-11 22:27:55 +0000497 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
wdenkfe8c2802002-11-03 00:38:21 +0000498 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
499
500 add r5, sp, #S_SP
501 mov r1, lr
wdenkcdc7fea2004-07-11 22:27:55 +0000502 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
wdenkfe8c2802002-11-03 00:38:21 +0000503 mov r0, sp
504 .endm
505
506 .macro irq_save_user_regs
507 sub sp, sp, #S_FRAME_SIZE
508 stmia sp, {r0 - r12} @ Calling r0-r12
wdenkcdc7fea2004-07-11 22:27:55 +0000509 add r8, sp, #S_PC
510 stmdb r8, {sp, lr}^ @ Calling SP, LR
511 str lr, [r8, #0] @ Save calling PC
512 mrs r6, spsr
513 str r6, [r8, #4] @ Save CPSR
514 str r0, [r8, #8] @ Save OLD_R0
wdenkfe8c2802002-11-03 00:38:21 +0000515 mov r0, sp
516 .endm
517
518 .macro irq_restore_user_regs
519 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
520 mov r0, r0
521 ldr lr, [sp, #S_PC] @ Get PC
522 add sp, sp, #S_FRAME_SIZE
523 subs pc, lr, #4 @ return & move spsr_svc into cpsr
524 .endm
525
526 .macro get_bad_stack
Heiko Schocherabef7b82010-09-17 13:10:52 +0200527 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
wdenkfe8c2802002-11-03 00:38:21 +0000528
529 str lr, [r13] @ save caller lr / spsr
530 mrs lr, spsr
wdenkcdc7fea2004-07-11 22:27:55 +0000531 str lr, [r13, #4]
wdenkfe8c2802002-11-03 00:38:21 +0000532
533 mov r13, #MODE_SVC @ prepare SVC-Mode
534 msr spsr_c, r13
535 mov lr, pc
536 movs pc, lr
537 .endm
538
539 .macro get_irq_stack @ setup IRQ stack
540 ldr sp, IRQ_STACK_START
541 .endm
542
543 .macro get_fiq_stack @ setup FIQ stack
544 ldr sp, FIQ_STACK_START
545 .endm
546
547/*
548 * exception handlers
549 */
wdenkcdc7fea2004-07-11 22:27:55 +0000550 .align 5
wdenkfe8c2802002-11-03 00:38:21 +0000551undefined_instruction:
552 get_bad_stack
553 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000554 bl do_undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +0000555
556 .align 5
557software_interrupt:
558 get_bad_stack
559 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000560 bl do_software_interrupt
wdenkfe8c2802002-11-03 00:38:21 +0000561
562 .align 5
563prefetch_abort:
564 get_bad_stack
565 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000566 bl do_prefetch_abort
wdenkfe8c2802002-11-03 00:38:21 +0000567
568 .align 5
569data_abort:
570 get_bad_stack
571 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000572 bl do_data_abort
wdenkfe8c2802002-11-03 00:38:21 +0000573
574 .align 5
575not_used:
576 get_bad_stack
577 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000578 bl do_not_used
wdenkfe8c2802002-11-03 00:38:21 +0000579
580#ifdef CONFIG_USE_IRQ
581
582 .align 5
583irq:
584 get_irq_stack
585 irq_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000586 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000587 irq_restore_user_regs
588
589 .align 5
590fiq:
591 get_fiq_stack
592 /* someone ought to write a more effiction fiq_save_user_regs */
593 irq_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000594 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000595 irq_restore_user_regs
596
597#else
598
599 .align 5
600irq:
601 get_bad_stack
602 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000603 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000604
605 .align 5
606fiq:
607 get_bad_stack
608 bad_save_user_regs
wdenkcdc7fea2004-07-11 22:27:55 +0000609 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000610
611#endif
Allen Martinc7da6c62012-08-31 08:30:07 +0000612#endif /* CONFIG_SPL_BUILD */
wdenkfe8c2802002-11-03 00:38:21 +0000613
Wolfgang Denkc1f87502011-09-05 14:37:30 +0200614#if defined(CONFIG_NETARM)
wdenk39539882004-07-01 16:30:44 +0000615 .align 5
616.globl reset_cpu
617reset_cpu:
wdenk2d1a5372004-02-23 19:30:57 +0000618 ldr r1, =NETARM_MEM_MODULE_BASE
619 ldr r0, [r1, #+NETARM_MEM_CS0_BASE_ADDR]
620 ldr r1, =0xFFFFF000
621 and r0, r1, r0
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200622 ldr r1, =(relocate-CONFIG_SYS_TEXT_BASE)
wdenk2d1a5372004-02-23 19:30:57 +0000623 add r0, r1, r0
624 ldr r4, =NETARM_GEN_MODULE_BASE
625 ldr r1, =NETARM_GEN_SW_SVC_RESETA
626 str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
627 ldr r1, =NETARM_GEN_SW_SVC_RESETB
628 str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
629 ldr r1, =NETARM_GEN_SW_SVC_RESETA
630 str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
631 ldr r1, =NETARM_GEN_SW_SVC_RESETB
632 str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
633 mov pc, r0
wdenk39539882004-07-01 16:30:44 +0000634#elif defined(CONFIG_S3C4510B)
635/* Nothing done here as reseting the CPU is board specific, depending
636 * on external peripherals such as watchdog timers, etc. */
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200637#elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
638 /* No specific reset actions for IntegratorAP/CM720T as yet */
Gary Jennejohn6bd24472007-01-24 12:16:56 +0100639#elif defined(CONFIG_LPC2292)
640 .align 5
641.globl reset_cpu
642reset_cpu:
643 mov pc, r0
Allen Martinc037c932012-08-31 08:30:09 +0000644#elif defined(CONFIG_TEGRA)
645 /* No specific reset actions for tegra as yet */
wdenk39539882004-07-01 16:30:44 +0000646#else
647#error No reset_cpu() defined for current CPU type
wdenk2d1a5372004-02-23 19:30:57 +0000648#endif