2 * Copyright (C) 2005-2008 Atmel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
6 #include <asm-offsets.h>
8 #include <asm/ptrace.h>
9 #include <asm/sysreg.h>
11 #define SYSREG_MMUCR_I_OFFSET 2
12 #define SYSREG_MMUCR_S_OFFSET 4
14 #define SR_INIT (SYSREG_BIT(GM) | SYSREG_BIT(EM) | SYSREG_BIT(M0))
15 /* due to errata (unreliable branch folding) clear FE bit explicitly */
16 #define CPUCR_INIT ((SYSREG_BIT(BI) | SYSREG_BIT(BE) \
17 | SYSREG_BIT(RE) | SYSREG_BIT(IBE) \
18 | SYSREG_BIT(IEE)) & ~SYSREG_BIT(FE))
21 * To save some space, we use the same entry point for
22 * exceptions and reset. This avoids lots of alignment padding
23 * since the reset vector is always suitably aligned.
25 .section .exception.text, "ax", @progbits
28 .type _start, @function
29 .type _evba, @function
34 rjmp unknown_exception /* Unrecoverable exception */
36 rjmp unknown_exception /* TLB multiple hit */
38 rjmp unknown_exception /* Bus error data fetch */
40 rjmp unknown_exception /* Bus error instruction fetch */
42 rjmp unknown_exception /* NMI */
44 rjmp unknown_exception /* Instruction address */
46 rjmp unknown_exception /* ITLB protection */
48 rjmp unknown_exception /* Breakpoint */
50 rjmp unknown_exception /* Illegal opcode */
52 rjmp unknown_exception /* Unimplemented instruction */
54 rjmp unknown_exception /* Privilege violation */
56 rjmp unknown_exception /* Floating-point */
58 rjmp unknown_exception /* Coprocessor absent */
60 rjmp unknown_exception /* Data Address (read) */
62 rjmp unknown_exception /* Data Address (write) */
64 rjmp unknown_exception /* DTLB Protection (read) */
66 rjmp unknown_exception /* DTLB Protection (write) */
68 rjmp unknown_exception /* DTLB Modified */
70 .org 0x50 /* ITLB Miss */
73 .org 0x60 /* DTLB Miss (read) */
76 .org 0x70 /* DTLB Miss (write) */
79 rcall mmu_handle_tlb_miss
81 brne unknown_exception
84 .size _evba, . - _evba
87 .type unknown_exception, @function
89 /* Figure out whether we're handling an exception (Exception
90 * mode) or just booting (Supervisor mode). */
91 csrfcz SYSREG_M1_OFFSET
92 brcc at32ap_cpu_bootstrap
94 /* This is an exception. Complain. */
96 sub r8, sp, REG_R12 - REG_R0 - 4
98 mfsr r10, SYSREG_RAR_EX
99 mfsr r11, SYSREG_RSR_EX
103 rcall do_unknown_exception
106 /* The COUNT/COMPARE timer interrupt handler */
107 .global timer_interrupt_handler
108 .type timer_interrupt_handler,@function
110 timer_interrupt_handler:
112 * Increment timer_overflow and re-write COMPARE with 0xffffffff.
114 * We're running at interrupt level 3, so we don't need to save
115 * r8-r12 or lr to the stack.
117 lda.w r8, timer_overflow
120 mtsr SYSREG_COMPARE, r10
126 * CPU bootstrap after reset is handled here. SoC code may
127 * override this in case they need to initialize oscillators,
130 .section .text.at32ap_cpu_bootstrap, "ax", @progbits
131 .global at32ap_cpu_bootstrap
132 .weak at32ap_cpu_bootstrap
133 .type at32ap_cpu_bootstrap, @function
135 at32ap_cpu_bootstrap:
136 /* Reset the Status Register */
141 /* Reset CPUCR and invalidate the BTB */
143 mtsr SYSREG_CPUCR, r2
145 /* Flush the caches */
151 /* Reset the MMU to default settings */
152 mov r0, SYSREG_BIT(MMUCR_S) | SYSREG_BIT(MMUCR_I)
153 mtsr SYSREG_MMUCR, r0
155 /* Internal RAM should not need any initialization. We might
156 have to initialize external RAM here if the part doesn't
157 have internal RAM (or we may use the data cache) */
159 /* Jump to cacheable segment */
163 1: .long at32ap_low_level_init
164 .size _start, . - _start
166 /* Common CPU bootstrap code after oscillator/cache/etc. init */
167 .section .text.avr32ap_low_level_init, "ax", @progbits
168 .global at32ap_low_level_init
169 .type at32ap_low_level_init, @function
171 at32ap_low_level_init:
174 /* Initialize the GOT pointer */
182 .type sp_init,@object
184 .long CONFIG_SYS_INIT_SP_ADDR
186 .long 3b - _GLOBAL_OFFSET_TABLE_
189 * void relocate_code(new_sp, new_gd, monitor_addr)
191 * Relocate the u-boot image into RAM and continue from there.
194 .section .text.relocate_code,"ax",@progbits
195 .global relocate_code
196 .type relocate_code,@function
198 mov sp, r12 /* use new stack */
199 mov r12, r11 /* save new_gd */
200 mov r11, r10 /* save destination address */
202 /* copy .text section and flush the cache along the way */
205 sub lr, r10, r8 /* relocation offset */
214 cache r10[-4], 0x0d /* dcache clean/invalidate */
215 cache r10[-4], 0x01 /* icache invalidate */
218 /* flush write buffer */
221 /* copy data sections */
238 sub r0, pc, . - in_ram
243 /* find the new GOT and relocate it */
244 lddpc r6, got_init_reloc
256 /* Move the exception handlers */
261 /* Do the rest of the initialization sequence */
266 .long 3b - _GLOBAL_OFFSET_TABLE_
268 .size relocate_code, . - relocate_code