2 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <asm-offsets.h>
9 #include <asm/arcregs.h>
12 * Note on the LD/ST addressing modes with address register write-back
16 * LD.a reg1, [reg2, x] => Pre Incr
17 * Eff Addr for load = [reg2 + x]
19 * LD.ab reg1, [reg2, x] => Post Incr
20 * Eff Addr for load = [reg2]
60 /* saving %r0 to reg->r0 in advance since we read %ecr into it */
62 lr %r0, [%ecr] /* all stack addressing is manual so far */
65 /* now move %sp to reg->r0 position so we can do "push" automatically */
81 .macro SAVE_EXCEPTION_SOURCE
83 /* If MMU exists exception faulting address is loaded in EFA reg */
86 /* Otherwise in ERET (exception return) reg */
91 .section .ivt, "ax",@progbits
94 /* Critical system events */
95 j _start /* 0 - 0x000 */
96 j memory_error /* 1 - 0x008 */
97 j instruction_error /* 2 - 0x010 */
99 /* Device interrupts */
101 j interrupt_handler /* 3:31 - 0x018:0xF8 */
104 j EV_MachineCheck /* 0x100, Fatal Machine check (0x20) */
105 j EV_TLBMissI /* 0x108, Intruction TLB miss (0x21) */
106 j EV_TLBMissD /* 0x110, Data TLB miss (0x22) */
107 j EV_TLBProtV /* 0x118, Protection Violation (0x23)
108 or Misaligned Access */
109 j EV_PrivilegeV /* 0x120, Privilege Violation (0x24) */
110 j EV_Trap /* 0x128, Trap exception (0x25) */
111 j EV_Extension /* 0x130, Extn Intruction Excp (0x26) */
116 /* Setup interrupt vector base that matches "__text_start" */
117 sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
119 /* Setup stack pointer */
120 mov %sp, CONFIG_SYS_INIT_SP_ADDR
129 brlt %r0, %r1, clear_bss
131 /* Zero the one and only argument of "board_init_f" */
137 SAVE_EXCEPTION_SOURCE
143 SAVE_EXCEPTION_SOURCE
145 j do_instruction_error
148 /* Todo - save and restore CPU context when interrupts will be in use */
149 bl do_interrupt_handler
154 SAVE_EXCEPTION_SOURCE
156 j do_machine_check_fault
170 SAVE_EXCEPTION_SOURCE
172 j do_tlb_prot_violation
177 j do_privilege_violation
190 * void relocate_code (addr_sp, gd, addr_moni)
192 * This "function" does not return, instead it continues in RAM
193 * after relocating the monitor code.
203 * r0-r12 might be clobbered by C functions
204 * so we use r13-r16 for storage here
206 mov %r13, %r0 /* save addr_sp */
207 mov %r14, %r1 /* save addr of gd */
208 mov %r15, %r2 /* save addr of destination */
210 mov %r16, %r2 /* %r9 - relocation offset */
211 sub %r16, %r16, __image_copy_start
213 /* Set up the stack */
218 /* Check if monitor is loaded right in place for relocation */
219 mov %r0, __image_copy_start
220 cmp %r0, %r15 /* skip relocation if code loaded */
221 bz do_board_init_r /* in target location already */
223 /* Copy data (__image_copy_start - __image_copy_end) to new location */
225 mov %r2, __image_copy_end
226 sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
227 asr %r2, %r2, 2 /* r3 <- amount of words to copy */
234 /* Fix relocations related issues */
235 bl do_elf_reloc_fixups
236 #ifndef CONFIG_SYS_ICACHE_OFF
237 bl invalidate_icache_all
239 #ifndef CONFIG_SYS_DCACHE_OFF
243 /* Update position of intterupt vector table */
244 lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
245 add %r0, %r0, %r16 /* Update address */
246 sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
249 /* Prepare for exection of "board_init_r" in relocated monitor */
250 mov %r2, board_init_r /* old address of "board_init_r()" */
251 add %r2, %r2, %r16 /* new address of "board_init_r()" */
252 mov %r0, %r14 /* 1-st parameter: gd_t */
253 mov %r1, %r15 /* 2-nd parameter: dest_addr */