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