]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arc/cpu/arc700/start.S
arc: add dependences on MMU presence
[people/ms/u-boot.git] / arch / arc / cpu / arc700 / start.S
CommitLineData
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>
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
e47d7338
IG
60 /* saving %r0 to reg->r0 in advance since we read %ecr into it */
61 st %r0, [%sp, -8]
62 lr %r0, [%ecr] /* all stack addressing is manual so far */
2f16ac9d 63 st %r0, [%sp]
e47d7338
IG
64 st %sp, [%sp, -4]
65 /* now move %sp to reg->r0 position so we can do "push" automatically */
66 sub %sp, %sp, 8
2f16ac9d
AB
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
dcb431e7
AB
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
2f16ac9d
AB
91.align 4
92.globl _start
93_start:
94 /* Critical system events */
95 j reset /* 0 - 0x000 */
96 j memory_error /* 1 - 0x008 */
97 j instruction_error /* 2 - 0x010 */
98
99 /* Device interrupts */
100.rept 29
101 j interrupt_handler /* 3:31 - 0x018:0xF8 */
102.endr
103 /* Exceptions */
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) */
112
113memory_error:
114 SAVE_ALL_SYS
dcb431e7 115 SAVE_EXCEPTION_SOURCE
2f16ac9d
AB
116 mov %r1, %sp
117 j do_memory_error
118
119instruction_error:
120 SAVE_ALL_SYS
dcb431e7 121 SAVE_EXCEPTION_SOURCE
2f16ac9d
AB
122 mov %r1, %sp
123 j do_instruction_error
124
125interrupt_handler:
126 /* Todo - save and restore CPU context when interrupts will be in use */
127 bl do_interrupt_handler
128 rtie
129
130EV_MachineCheck:
131 SAVE_ALL_SYS
dcb431e7 132 SAVE_EXCEPTION_SOURCE
2f16ac9d
AB
133 mov %r1, %sp
134 j do_machine_check_fault
135
136EV_TLBMissI:
137 SAVE_ALL_SYS
138 mov %r0, %sp
139 j do_itlb_miss
140
141EV_TLBMissD:
142 SAVE_ALL_SYS
143 mov %r0, %sp
144 j do_dtlb_miss
145
146EV_TLBProtV:
147 SAVE_ALL_SYS
dcb431e7 148 SAVE_EXCEPTION_SOURCE
2f16ac9d
AB
149 mov %r1, %sp
150 j do_tlb_prot_violation
151
152EV_PrivilegeV:
153 SAVE_ALL_SYS
154 mov %r0, %sp
155 j do_privilege_violation
156
157EV_Trap:
158 SAVE_ALL_SYS
159 mov %r0, %sp
160 j do_trap
161
162EV_Extension:
163 SAVE_ALL_SYS
164 mov %r0, %sp
165 j do_extension
166
167
168reset:
169 /* Setup interrupt vector base that matches "__text_start" */
170 sr __text_start, [ARC_AUX_INTR_VEC_BASE]
171
172 /* Setup stack pointer */
173 mov %sp, CONFIG_SYS_INIT_SP_ADDR
174 mov %fp, %sp
175
176 /* Clear bss */
177 mov %r0, __bss_start
178 mov %r1, __bss_end
179
180clear_bss:
181 st.ab 0, [%r0, 4]
182 brlt %r0, %r1, clear_bss
183
184 /* Zero the one and only argument of "board_init_f" */
185 mov_s %r0, 0
186 j board_init_f
187
188/*
189 * void relocate_code (addr_sp, gd, addr_moni)
190 *
191 * This "function" does not return, instead it continues in RAM
192 * after relocating the monitor code.
193 *
194 * r0 = start_addr_sp
195 * r1 = new__gd
196 * r2 = relocaddr
197 */
198.align 4
199.globl relocate_code
200relocate_code:
201 /*
202 * r0-r12 might be clobbered by C functions
203 * so we use r13-r16 for storage here
204 */
205 mov %r13, %r0 /* save addr_sp */
206 mov %r14, %r1 /* save addr of gd */
207 mov %r15, %r2 /* save addr of destination */
208
209 mov %r16, %r2 /* %r9 - relocation offset */
210 sub %r16, %r16, __image_copy_start
211
212/* Set up the stack */
213stack_setup:
214 mov %sp, %r13
215 mov %fp, %sp
216
217/* Check if monitor is loaded right in place for relocation */
218 mov %r0, __image_copy_start
219 cmp %r0, %r15 /* skip relocation if code loaded */
220 bz do_board_init_r /* in target location already */
221
222/* Copy data (__image_copy_start - __image_copy_end) to new location */
223 mov %r1, %r15
224 mov %r2, __image_copy_end
225 sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
226 asr %r2, %r2, 2 /* r3 <- amount of words to copy */
227 mov %lp_count, %r2
228 lp copy_end
229 ld.ab %r2,[%r0,4]
230 st.ab %r2,[%r1,4]
231copy_end:
232
233/* Fix relocations related issues */
234 bl do_elf_reloc_fixups
235#ifndef CONFIG_SYS_ICACHE_OFF
236 bl invalidate_icache_all
237#endif
238#ifndef CONFIG_SYS_DCACHE_OFF
239 bl flush_dcache_all
240#endif
241
242/* Update position of intterupt vector table */
243 lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
244 add %r0, %r0, %r16 /* Update address */
245 sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
246
247do_board_init_r:
248/* Prepare for exection of "board_init_r" in relocated monitor */
249 mov %r2, board_init_r /* old address of "board_init_r()" */
250 add %r2, %r2, %r16 /* new address of "board_init_r()" */
251 mov %r0, %r14 /* 1-st parameter: gd_t */
252 mov %r1, %r15 /* 2-nd parameter: dest_addr */
253 j [%r2]