]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arc/cpu/arcv2/start.S
arc: cache - build invalidate_icache_all() and invalidate_dcache_all()
[people/ms/u-boot.git] / arch / arc / cpu / arcv2 / start.S
1 /*
2 * Copyright (C) 2013-2015 Synopsys, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include <asm-offsets.h>
8 #include <config.h>
9 #include <asm/arcregs.h>
10
11 /*
12 * Note on the LD/ST addressing modes with address register write-back
13 *
14 * LD.a same as LD.aw
15 *
16 * LD.a reg1, [reg2, x] => Pre Incr
17 * Eff Addr for load = [reg2 + x]
18 *
19 * LD.ab reg1, [reg2, x] => Post Incr
20 * Eff Addr for load = [reg2]
21 */
22
23 .macro PUSH reg
24 st.a \reg, [%sp, -4]
25 .endm
26
27 .macro PUSHAX aux
28 lr %r9, [\aux]
29 PUSH %r9
30 .endm
31
32 .macro SAVE_R1_TO_R24
33 PUSH %r1
34 PUSH %r2
35 PUSH %r3
36 PUSH %r4
37 PUSH %r5
38 PUSH %r6
39 PUSH %r7
40 PUSH %r8
41 PUSH %r9
42 PUSH %r10
43 PUSH %r11
44 PUSH %r12
45 PUSH %r13
46 PUSH %r14
47 PUSH %r15
48 PUSH %r16
49 PUSH %r17
50 PUSH %r18
51 PUSH %r19
52 PUSH %r20
53 PUSH %r21
54 PUSH %r22
55 PUSH %r23
56 PUSH %r24
57 .endm
58
59 .macro SAVE_ALL_SYS
60 /* saving %r0 to reg->r0 in advance since weread %ecr into it */
61 st %r0, [%sp, -8]
62 lr %r0, [%ecr] /* all stack addressing is manual so far */
63 st %r0, [%sp]
64 st %sp, [%sp, -4]
65 /* now move %sp to reg->r0 position so we can do "push" automatically */
66 sub %sp, %sp, 8
67
68 SAVE_R1_TO_R24
69 PUSH %r25
70 PUSH %gp
71 PUSH %fp
72 PUSH %blink
73 PUSHAX %eret
74 PUSHAX %erstatus
75 PUSH %lp_count
76 PUSHAX %lp_end
77 PUSHAX %lp_start
78 PUSHAX %erbta
79 .endm
80
81 .macro SAVE_EXCEPTION_SOURCE
82 #ifdef CONFIG_MMU
83 /* If MMU exists exception faulting address is loaded in EFA reg */
84 lr %r0, [%efa]
85 #else
86 /* Otherwise in ERET (exception return) reg */
87 lr %r0, [%eret]
88 #endif
89 .endm
90
91 .section .ivt, "a",@progbits
92 .align 4
93 /* Critical system events */
94 .word _start /* 0 - 0x000 */
95 .word memory_error /* 1 - 0x008 */
96 .word instruction_error /* 2 - 0x010 */
97
98 /* Exceptions */
99 .word EV_MachineCheck /* 0x100, Fatal Machine check (0x20) */
100 .word EV_TLBMissI /* 0x108, Intruction TLB miss (0x21) */
101 .word EV_TLBMissD /* 0x110, Data TLB miss (0x22) */
102 .word EV_TLBProtV /* 0x118, Protection Violation (0x23)
103 or Misaligned Access */
104 .word EV_PrivilegeV /* 0x120, Privilege Violation (0x24) */
105 .word EV_Trap /* 0x128, Trap exception (0x25) */
106 .word EV_Extension /* 0x130, Extn Intruction Excp (0x26) */
107
108 /* Device interrupts */
109 .rept 29
110 j interrupt_handler /* 3:31 - 0x018:0xF8 */
111 .endr
112
113 .text
114 .globl _start
115 _start:
116 /* Setup interrupt vector base that matches "__text_start" */
117 sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
118
119 /* Setup stack pointer */
120 mov %sp, CONFIG_SYS_INIT_SP_ADDR
121 mov %fp, %sp
122
123 /* Clear bss */
124 mov %r0, __bss_start
125 mov %r1, __bss_end
126
127 clear_bss:
128 st.ab 0, [%r0, 4]
129 brlt %r0, %r1, clear_bss
130
131 /* Zero the one and only argument of "board_init_f" */
132 mov_s %r0, 0
133 j board_init_f
134
135 memory_error:
136 SAVE_ALL_SYS
137 SAVE_EXCEPTION_SOURCE
138 mov %r1, %sp
139 j do_memory_error
140
141 instruction_error:
142 SAVE_ALL_SYS
143 SAVE_EXCEPTION_SOURCE
144 mov %r1, %sp
145 j do_instruction_error
146
147 interrupt_handler:
148 /* Todo - save and restore CPU context when interrupts will be in use */
149 bl do_interrupt_handler
150 rtie
151
152 EV_MachineCheck:
153 SAVE_ALL_SYS
154 SAVE_EXCEPTION_SOURCE
155 mov %r1, %sp
156 j do_machine_check_fault
157
158 EV_TLBMissI:
159 SAVE_ALL_SYS
160 mov %r0, %sp
161 j do_itlb_miss
162
163 EV_TLBMissD:
164 SAVE_ALL_SYS
165 mov %r0, %sp
166 j do_dtlb_miss
167
168 EV_TLBProtV:
169 SAVE_ALL_SYS
170 SAVE_EXCEPTION_SOURCE
171 mov %r1, %sp
172 j do_tlb_prot_violation
173
174 EV_PrivilegeV:
175 SAVE_ALL_SYS
176 mov %r0, %sp
177 j do_privilege_violation
178
179 EV_Trap:
180 SAVE_ALL_SYS
181 mov %r0, %sp
182 j do_trap
183
184 EV_Extension:
185 SAVE_ALL_SYS
186 mov %r0, %sp
187 j do_extension
188
189 /*
190 * void relocate_code (addr_sp, gd, addr_moni)
191 *
192 * This "function" does not return, instead it continues in RAM
193 * after relocating the monitor code.
194 *
195 * r0 = start_addr_sp
196 * r1 = new__gd
197 * r2 = relocaddr
198 */
199 .align 4
200 .globl relocate_code
201 relocate_code:
202 /*
203 * r0-r12 might be clobbered by C functions
204 * so we use r13-r16 for storage here
205 */
206 mov %r13, %r0 /* save addr_sp */
207 mov %r14, %r1 /* save addr of gd */
208 mov %r15, %r2 /* save addr of destination */
209
210 mov %r16, %r2 /* %r9 - relocation offset */
211 sub %r16, %r16, __image_copy_start
212
213 /* Set up the stack */
214 stack_setup:
215 mov %sp, %r13
216 mov %fp, %sp
217
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 */
222
223 /* Copy data (__image_copy_start - __image_copy_end) to new location */
224 mov %r1, %r15
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 */
228 mov %lp_count, %r2
229 lp copy_end
230 ld.ab %r2,[%r0,4]
231 st.ab %r2,[%r1,4]
232 copy_end:
233
234 /* Fix relocations related issues */
235 bl do_elf_reloc_fixups
236 #ifndef CONFIG_SYS_ICACHE_OFF
237 bl invalidate_icache_all
238 #endif
239 #ifndef CONFIG_SYS_DCACHE_OFF
240 bl flush_dcache_all
241 #endif
242
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 */
247
248 do_board_init_r:
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 */
254 j [%r2]