]>
Commit | Line | Data |
---|---|---|
2f16ac9d AB |
1 | /* |
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> | |
4d93617d | 9 | #include <linux/linkage.h> |
2f16ac9d AB |
10 | #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 | |
e47d7338 IG |
61 | /* 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 */ | |
2f16ac9d | 64 | st %r0, [%sp] |
e47d7338 IG |
65 | st %sp, [%sp, -4] |
66 | /* now move %sp to reg->r0 position so we can do "push" automatically */ | |
67 | sub %sp, %sp, 8 | |
2f16ac9d AB |
68 | |
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 | ||
dcb431e7 AB |
82 | .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 | ||
4d93617d | 92 | ENTRY(_start) |
20a58ac0 IG |
93 | /* 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 | ||
104 | clear_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 | |
4d93617d | 111 | ENDPROC(_start) |
20a58ac0 | 112 | |
4d93617d | 113 | ENTRY(memory_error) |
2f16ac9d | 114 | SAVE_ALL_SYS |
dcb431e7 | 115 | SAVE_EXCEPTION_SOURCE |
2f16ac9d AB |
116 | mov %r1, %sp |
117 | j do_memory_error | |
4d93617d | 118 | ENDPROC(memory_error) |
2f16ac9d | 119 | |
4d93617d | 120 | ENTRY(instruction_error) |
2f16ac9d | 121 | SAVE_ALL_SYS |
dcb431e7 | 122 | SAVE_EXCEPTION_SOURCE |
2f16ac9d AB |
123 | mov %r1, %sp |
124 | j do_instruction_error | |
4d93617d | 125 | ENDPROC(instruction_error) |
2f16ac9d | 126 | |
4d93617d | 127 | ENTRY(interrupt_handler) |
2f16ac9d AB |
128 | /* Todo - save and restore CPU context when interrupts will be in use */ |
129 | bl do_interrupt_handler | |
130 | rtie | |
4d93617d | 131 | ENDPROC(interrupt_handler) |
2f16ac9d | 132 | |
4d93617d | 133 | ENTRY(EV_MachineCheck) |
2f16ac9d | 134 | SAVE_ALL_SYS |
dcb431e7 | 135 | SAVE_EXCEPTION_SOURCE |
2f16ac9d AB |
136 | mov %r1, %sp |
137 | j do_machine_check_fault | |
4d93617d | 138 | ENDPROC(EV_MachineCheck) |
2f16ac9d | 139 | |
4d93617d | 140 | ENTRY(EV_TLBMissI) |
2f16ac9d AB |
141 | SAVE_ALL_SYS |
142 | mov %r0, %sp | |
143 | j do_itlb_miss | |
4d93617d | 144 | ENDPROC(EV_TLBMissI) |
2f16ac9d | 145 | |
4d93617d | 146 | ENTRY(EV_TLBMissD) |
2f16ac9d AB |
147 | SAVE_ALL_SYS |
148 | mov %r0, %sp | |
149 | j do_dtlb_miss | |
4d93617d | 150 | ENDPROC(EV_TLBMissD) |
2f16ac9d | 151 | |
4d93617d | 152 | ENTRY(EV_TLBProtV) |
2f16ac9d | 153 | SAVE_ALL_SYS |
dcb431e7 | 154 | SAVE_EXCEPTION_SOURCE |
2f16ac9d AB |
155 | mov %r1, %sp |
156 | j do_tlb_prot_violation | |
4d93617d | 157 | ENDPROC(EV_TLBProtV) |
2f16ac9d | 158 | |
4d93617d | 159 | ENTRY(EV_PrivilegeV) |
2f16ac9d AB |
160 | SAVE_ALL_SYS |
161 | mov %r0, %sp | |
162 | j do_privilege_violation | |
4d93617d | 163 | ENDPROC(EV_PrivilegeV) |
2f16ac9d | 164 | |
4d93617d | 165 | ENTRY(EV_Trap) |
2f16ac9d AB |
166 | SAVE_ALL_SYS |
167 | mov %r0, %sp | |
168 | j do_trap | |
4d93617d | 169 | ENDPROC(EV_Trap) |
2f16ac9d | 170 | |
4d93617d | 171 | ENTRY(EV_Extension) |
2f16ac9d AB |
172 | SAVE_ALL_SYS |
173 | mov %r0, %sp | |
174 | j do_extension | |
4d93617d | 175 | ENDPROC(EV_Extension) |
2f16ac9d | 176 | |
2f16ac9d AB |
177 | /* |
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 | */ | |
4d93617d | 187 | ENTRY(relocate_code) |
2f16ac9d AB |
188 | /* |
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 */ | |
200 | stack_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] | |
218 | copy_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 | ||
234 | do_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] | |
4d93617d | 241 | ENDPROC(relocate_code) |