2 * Copyright (C) 2005-2008 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #include <asm-offsets.h>
24 #include <asm/ptrace.h>
25 #include <asm/sysreg.h>
27 #define SYSREG_MMUCR_I_OFFSET 2
28 #define SYSREG_MMUCR_S_OFFSET 4
30 #define SR_INIT (SYSREG_BIT(GM) | SYSREG_BIT(EM) | SYSREG_BIT(M0))
31 /* due to errata (unreliable branch folding) clear FE bit explicitly */
32 #define CPUCR_INIT ((SYSREG_BIT(BI) | SYSREG_BIT(BE) \
33 | SYSREG_BIT(RE) | SYSREG_BIT(IBE) \
34 | SYSREG_BIT(IEE)) & ~SYSREG_BIT(FE))
37 * To save some space, we use the same entry point for
38 * exceptions and reset. This avoids lots of alignment padding
39 * since the reset vector is always suitably aligned.
41 .section .exception.text, "ax", @progbits
44 .type _start, @function
45 .type _evba, @function
50 rjmp unknown_exception /* Unrecoverable exception */
52 rjmp unknown_exception /* TLB multiple hit */
54 rjmp unknown_exception /* Bus error data fetch */
56 rjmp unknown_exception /* Bus error instruction fetch */
58 rjmp unknown_exception /* NMI */
60 rjmp unknown_exception /* Instruction address */
62 rjmp unknown_exception /* ITLB protection */
64 rjmp unknown_exception /* Breakpoint */
66 rjmp unknown_exception /* Illegal opcode */
68 rjmp unknown_exception /* Unimplemented instruction */
70 rjmp unknown_exception /* Privilege violation */
72 rjmp unknown_exception /* Floating-point */
74 rjmp unknown_exception /* Coprocessor absent */
76 rjmp unknown_exception /* Data Address (read) */
78 rjmp unknown_exception /* Data Address (write) */
80 rjmp unknown_exception /* DTLB Protection (read) */
82 rjmp unknown_exception /* DTLB Protection (write) */
84 rjmp unknown_exception /* DTLB Modified */
86 .org 0x50 /* ITLB Miss */
89 .org 0x60 /* DTLB Miss (read) */
92 .org 0x70 /* DTLB Miss (write) */
95 rcall mmu_handle_tlb_miss
97 brne unknown_exception
100 .size _evba, . - _evba
103 .type unknown_exception, @function
105 /* Figure out whether we're handling an exception (Exception
106 * mode) or just booting (Supervisor mode). */
107 csrfcz SYSREG_M1_OFFSET
108 brcc at32ap_cpu_bootstrap
110 /* This is an exception. Complain. */
112 sub r8, sp, REG_R12 - REG_R0 - 4
114 mfsr r10, SYSREG_RAR_EX
115 mfsr r11, SYSREG_RSR_EX
119 rcall do_unknown_exception
122 /* The COUNT/COMPARE timer interrupt handler */
123 .global timer_interrupt_handler
124 .type timer_interrupt_handler,@function
126 timer_interrupt_handler:
128 * Increment timer_overflow and re-write COMPARE with 0xffffffff.
130 * We're running at interrupt level 3, so we don't need to save
131 * r8-r12 or lr to the stack.
133 lda.w r8, timer_overflow
136 mtsr SYSREG_COMPARE, r10
142 * CPU bootstrap after reset is handled here. SoC code may
143 * override this in case they need to initialize oscillators,
146 .section .text.at32ap_cpu_bootstrap, "ax", @progbits
147 .global at32ap_cpu_bootstrap
148 .weak at32ap_cpu_bootstrap
149 .type at32ap_cpu_bootstrap, @function
151 at32ap_cpu_bootstrap:
152 /* Reset the Status Register */
157 /* Reset CPUCR and invalidate the BTB */
159 mtsr SYSREG_CPUCR, r2
161 /* Flush the caches */
167 /* Reset the MMU to default settings */
168 mov r0, SYSREG_BIT(MMUCR_S) | SYSREG_BIT(MMUCR_I)
169 mtsr SYSREG_MMUCR, r0
171 /* Internal RAM should not need any initialization. We might
172 have to initialize external RAM here if the part doesn't
173 have internal RAM (or we may use the data cache) */
175 /* Jump to cacheable segment */
179 1: .long at32ap_low_level_init
180 .size _start, . - _start
182 /* Common CPU bootstrap code after oscillator/cache/etc. init */
183 .section .text.avr32ap_low_level_init, "ax", @progbits
184 .global at32ap_low_level_init
185 .type at32ap_low_level_init, @function
187 at32ap_low_level_init:
190 /* Initialize the GOT pointer */
198 .type sp_init,@object
200 .long CONFIG_SYS_INIT_SP_ADDR
202 .long 3b - _GLOBAL_OFFSET_TABLE_
205 * void relocate_code(new_sp, new_gd, monitor_addr)
207 * Relocate the u-boot image into RAM and continue from there.
210 .section .text.relocate_code,"ax",@progbits
211 .global relocate_code
212 .type relocate_code,@function
214 mov sp, r12 /* use new stack */
215 mov r12, r11 /* save new_gd */
216 mov r11, r10 /* save destination address */
218 /* copy .text section and flush the cache along the way */
221 sub lr, r10, r8 /* relocation offset */
230 cache r10[-4], 0x0d /* dcache clean/invalidate */
231 cache r10[-4], 0x01 /* icache invalidate */
234 /* flush write buffer */
237 /* copy data sections */
254 sub r0, pc, . - in_ram
259 /* find the new GOT and relocate it */
260 lddpc r6, got_init_reloc
272 /* Move the exception handlers */
277 /* Do the rest of the initialization sequence */
282 .long 3b - _GLOBAL_OFFSET_TABLE_
284 .size relocate_code, . - relocate_code