blob: 39eace36a92366f697890f2a336a9a63aa4429a9 [file] [log] [blame]
Alexey Brodkin3a59d912014-02-04 12:56:14 +04001/*
2 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <asm-offsets.h>
8#include <config.h>
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +03009#include <linux/linkage.h>
Alexey Brodkin3a59d912014-02-04 12:56:14 +040010#include <asm/arcregs.h>
11
12/*
13 * Note on the LD/ST addressing modes with address register write-back
14 *
15 * LD.a same as LD.aw
16 *
17 * LD.a reg1, [reg2, x] => Pre Incr
18 * Eff Addr for load = [reg2 + x]
19 *
20 * LD.ab reg1, [reg2, x] => Post Incr
21 * Eff Addr for load = [reg2]
22 */
23
24.macro PUSH reg
25 st.a \reg, [%sp, -4]
26.endm
27
28.macro PUSHAX aux
29 lr %r9, [\aux]
30 PUSH %r9
31.endm
32
33.macro SAVE_R1_TO_R24
34 PUSH %r1
35 PUSH %r2
36 PUSH %r3
37 PUSH %r4
38 PUSH %r5
39 PUSH %r6
40 PUSH %r7
41 PUSH %r8
42 PUSH %r9
43 PUSH %r10
44 PUSH %r11
45 PUSH %r12
46 PUSH %r13
47 PUSH %r14
48 PUSH %r15
49 PUSH %r16
50 PUSH %r17
51 PUSH %r18
52 PUSH %r19
53 PUSH %r20
54 PUSH %r21
55 PUSH %r22
56 PUSH %r23
57 PUSH %r24
58.endm
59
60.macro SAVE_ALL_SYS
Igor Guryanov742bc742014-12-24 16:26:14 +030061 /* saving %r0 to reg->r0 in advance since we read %ecr into it */
62 st %r0, [%sp, -8]
63 lr %r0, [%ecr] /* all stack addressing is manual so far */
Alexey Brodkin3a59d912014-02-04 12:56:14 +040064 st %r0, [%sp]
Igor Guryanov742bc742014-12-24 16:26:14 +030065 st %sp, [%sp, -4]
66 /* now move %sp to reg->r0 position so we can do "push" automatically */
67 sub %sp, %sp, 8
Alexey Brodkin3a59d912014-02-04 12:56:14 +040068
69 SAVE_R1_TO_R24
70 PUSH %r25
71 PUSH %gp
72 PUSH %fp
73 PUSH %blink
74 PUSHAX %eret
75 PUSHAX %erstatus
76 PUSH %lp_count
77 PUSHAX %lp_end
78 PUSHAX %lp_start
79 PUSHAX %erbta
80.endm
81
Alexey Brodkin5e4931f2014-12-24 17:00:29 +030082.macro SAVE_EXCEPTION_SOURCE
83#ifdef CONFIG_MMU
84 /* If MMU exists exception faulting address is loaded in EFA reg */
85 lr %r0, [%efa]
86#else
87 /* Otherwise in ERET (exception return) reg */
88 lr %r0, [%eret]
89#endif
90.endm
91
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +030092ENTRY(_start)
Igor Guryanov4fec6aa2014-12-24 17:17:11 +030093 /* Setup interrupt vector base that matches "__text_start" */
94 sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
95
96 /* Setup stack pointer */
97 mov %sp, CONFIG_SYS_INIT_SP_ADDR
98 mov %fp, %sp
99
100 /* Clear bss */
101 mov %r0, __bss_start
102 mov %r1, __bss_end
103
104clear_bss:
105 st.ab 0, [%r0, 4]
106 brlt %r0, %r1, clear_bss
107
108 /* Zero the one and only argument of "board_init_f" */
109 mov_s %r0, 0
110 j board_init_f
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300111ENDPROC(_start)
Igor Guryanov4fec6aa2014-12-24 17:17:11 +0300112
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300113ENTRY(memory_error)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400114 SAVE_ALL_SYS
Alexey Brodkin5e4931f2014-12-24 17:00:29 +0300115 SAVE_EXCEPTION_SOURCE
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400116 mov %r1, %sp
117 j do_memory_error
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300118ENDPROC(memory_error)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400119
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300120ENTRY(instruction_error)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400121 SAVE_ALL_SYS
Alexey Brodkin5e4931f2014-12-24 17:00:29 +0300122 SAVE_EXCEPTION_SOURCE
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400123 mov %r1, %sp
124 j do_instruction_error
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300125ENDPROC(instruction_error)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400126
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300127ENTRY(interrupt_handler)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400128 /* Todo - save and restore CPU context when interrupts will be in use */
129 bl do_interrupt_handler
130 rtie
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300131ENDPROC(interrupt_handler)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400132
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300133ENTRY(EV_MachineCheck)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400134 SAVE_ALL_SYS
Alexey Brodkin5e4931f2014-12-24 17:00:29 +0300135 SAVE_EXCEPTION_SOURCE
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400136 mov %r1, %sp
137 j do_machine_check_fault
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300138ENDPROC(EV_MachineCheck)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400139
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300140ENTRY(EV_TLBMissI)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400141 SAVE_ALL_SYS
142 mov %r0, %sp
143 j do_itlb_miss
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300144ENDPROC(EV_TLBMissI)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400145
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300146ENTRY(EV_TLBMissD)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400147 SAVE_ALL_SYS
148 mov %r0, %sp
149 j do_dtlb_miss
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300150ENDPROC(EV_TLBMissD)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400151
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300152ENTRY(EV_TLBProtV)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400153 SAVE_ALL_SYS
Alexey Brodkin5e4931f2014-12-24 17:00:29 +0300154 SAVE_EXCEPTION_SOURCE
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400155 mov %r1, %sp
156 j do_tlb_prot_violation
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300157ENDPROC(EV_TLBProtV)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400158
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300159ENTRY(EV_PrivilegeV)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400160 SAVE_ALL_SYS
161 mov %r0, %sp
162 j do_privilege_violation
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300163ENDPROC(EV_PrivilegeV)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400164
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300165ENTRY(EV_Trap)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400166 SAVE_ALL_SYS
167 mov %r0, %sp
168 j do_trap
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300169ENDPROC(EV_Trap)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400170
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300171ENTRY(EV_Extension)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400172 SAVE_ALL_SYS
173 mov %r0, %sp
174 j do_extension
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300175ENDPROC(EV_Extension)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400176
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400177/*
178 * void relocate_code (addr_sp, gd, addr_moni)
179 *
180 * This "function" does not return, instead it continues in RAM
181 * after relocating the monitor code.
182 *
183 * r0 = start_addr_sp
184 * r1 = new__gd
185 * r2 = relocaddr
186 */
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300187ENTRY(relocate_code)
Alexey Brodkin3a59d912014-02-04 12:56:14 +0400188 /*
189 * r0-r12 might be clobbered by C functions
190 * so we use r13-r16 for storage here
191 */
192 mov %r13, %r0 /* save addr_sp */
193 mov %r14, %r1 /* save addr of gd */
194 mov %r15, %r2 /* save addr of destination */
195
196 mov %r16, %r2 /* %r9 - relocation offset */
197 sub %r16, %r16, __image_copy_start
198
199/* Set up the stack */
200stack_setup:
201 mov %sp, %r13
202 mov %fp, %sp
203
204/* Check if monitor is loaded right in place for relocation */
205 mov %r0, __image_copy_start
206 cmp %r0, %r15 /* skip relocation if code loaded */
207 bz do_board_init_r /* in target location already */
208
209/* Copy data (__image_copy_start - __image_copy_end) to new location */
210 mov %r1, %r15
211 mov %r2, __image_copy_end
212 sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
213 asr %r2, %r2, 2 /* r3 <- amount of words to copy */
214 mov %lp_count, %r2
215 lp copy_end
216 ld.ab %r2,[%r0,4]
217 st.ab %r2,[%r1,4]
218copy_end:
219
220/* Fix relocations related issues */
221 bl do_elf_reloc_fixups
222#ifndef CONFIG_SYS_ICACHE_OFF
223 bl invalidate_icache_all
224#endif
225#ifndef CONFIG_SYS_DCACHE_OFF
226 bl flush_dcache_all
227#endif
228
229/* Update position of intterupt vector table */
230 lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
231 add %r0, %r0, %r16 /* Update address */
232 sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
233
234do_board_init_r:
235/* Prepare for exection of "board_init_r" in relocated monitor */
236 mov %r2, board_init_r /* old address of "board_init_r()" */
237 add %r2, %r2, %r16 /* new address of "board_init_r()" */
238 mov %r0, %r14 /* 1-st parameter: gd_t */
239 mov %r1, %r15 /* 2-nd parameter: dest_addr */
240 j [%r2]
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +0300241ENDPROC(relocate_code)