]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arc/cpu/arc700/start.S
arc: add ECR (exception cause register) output
[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
81.align 4
82.globl _start
83_start:
84 /* Critical system events */
85 j reset /* 0 - 0x000 */
86 j memory_error /* 1 - 0x008 */
87 j instruction_error /* 2 - 0x010 */
88
89 /* Device interrupts */
90.rept 29
91 j interrupt_handler /* 3:31 - 0x018:0xF8 */
92.endr
93 /* Exceptions */
94 j EV_MachineCheck /* 0x100, Fatal Machine check (0x20) */
95 j EV_TLBMissI /* 0x108, Intruction TLB miss (0x21) */
96 j EV_TLBMissD /* 0x110, Data TLB miss (0x22) */
97 j EV_TLBProtV /* 0x118, Protection Violation (0x23)
98 or Misaligned Access */
99 j EV_PrivilegeV /* 0x120, Privilege Violation (0x24) */
100 j EV_Trap /* 0x128, Trap exception (0x25) */
101 j EV_Extension /* 0x130, Extn Intruction Excp (0x26) */
102
103memory_error:
104 SAVE_ALL_SYS
105 lr %r0, [%efa]
106 mov %r1, %sp
107 j do_memory_error
108
109instruction_error:
110 SAVE_ALL_SYS
111 lr %r0, [%efa]
112 mov %r1, %sp
113 j do_instruction_error
114
115interrupt_handler:
116 /* Todo - save and restore CPU context when interrupts will be in use */
117 bl do_interrupt_handler
118 rtie
119
120EV_MachineCheck:
121 SAVE_ALL_SYS
122 lr %r0, [%efa]
123 mov %r1, %sp
124 j do_machine_check_fault
125
126EV_TLBMissI:
127 SAVE_ALL_SYS
128 mov %r0, %sp
129 j do_itlb_miss
130
131EV_TLBMissD:
132 SAVE_ALL_SYS
133 mov %r0, %sp
134 j do_dtlb_miss
135
136EV_TLBProtV:
137 SAVE_ALL_SYS
138 lr %r0, [%efa]
139 mov %r1, %sp
140 j do_tlb_prot_violation
141
142EV_PrivilegeV:
143 SAVE_ALL_SYS
144 mov %r0, %sp
145 j do_privilege_violation
146
147EV_Trap:
148 SAVE_ALL_SYS
149 mov %r0, %sp
150 j do_trap
151
152EV_Extension:
153 SAVE_ALL_SYS
154 mov %r0, %sp
155 j do_extension
156
157
158reset:
159 /* Setup interrupt vector base that matches "__text_start" */
160 sr __text_start, [ARC_AUX_INTR_VEC_BASE]
161
162 /* Setup stack pointer */
163 mov %sp, CONFIG_SYS_INIT_SP_ADDR
164 mov %fp, %sp
165
166 /* Clear bss */
167 mov %r0, __bss_start
168 mov %r1, __bss_end
169
170clear_bss:
171 st.ab 0, [%r0, 4]
172 brlt %r0, %r1, clear_bss
173
174 /* Zero the one and only argument of "board_init_f" */
175 mov_s %r0, 0
176 j board_init_f
177
178/*
179 * void relocate_code (addr_sp, gd, addr_moni)
180 *
181 * This "function" does not return, instead it continues in RAM
182 * after relocating the monitor code.
183 *
184 * r0 = start_addr_sp
185 * r1 = new__gd
186 * r2 = relocaddr
187 */
188.align 4
189.globl relocate_code
190relocate_code:
191 /*
192 * r0-r12 might be clobbered by C functions
193 * so we use r13-r16 for storage here
194 */
195 mov %r13, %r0 /* save addr_sp */
196 mov %r14, %r1 /* save addr of gd */
197 mov %r15, %r2 /* save addr of destination */
198
199 mov %r16, %r2 /* %r9 - relocation offset */
200 sub %r16, %r16, __image_copy_start
201
202/* Set up the stack */
203stack_setup:
204 mov %sp, %r13
205 mov %fp, %sp
206
207/* Check if monitor is loaded right in place for relocation */
208 mov %r0, __image_copy_start
209 cmp %r0, %r15 /* skip relocation if code loaded */
210 bz do_board_init_r /* in target location already */
211
212/* Copy data (__image_copy_start - __image_copy_end) to new location */
213 mov %r1, %r15
214 mov %r2, __image_copy_end
215 sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
216 asr %r2, %r2, 2 /* r3 <- amount of words to copy */
217 mov %lp_count, %r2
218 lp copy_end
219 ld.ab %r2,[%r0,4]
220 st.ab %r2,[%r1,4]
221copy_end:
222
223/* Fix relocations related issues */
224 bl do_elf_reloc_fixups
225#ifndef CONFIG_SYS_ICACHE_OFF
226 bl invalidate_icache_all
227#endif
228#ifndef CONFIG_SYS_DCACHE_OFF
229 bl flush_dcache_all
230#endif
231
232/* Update position of intterupt vector table */
233 lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
234 add %r0, %r0, %r16 /* Update address */
235 sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
236
237do_board_init_r:
238/* Prepare for exection of "board_init_r" in relocated monitor */
239 mov %r2, board_init_r /* old address of "board_init_r()" */
240 add %r2, %r2, %r16 /* new address of "board_init_r()" */
241 mov %r0, %r14 /* 1-st parameter: gd_t */
242 mov %r1, %r15 /* 2-nd parameter: dest_addr */
243 j [%r2]