summaryrefslogtreecommitdiffstats
path: root/arch/arc/cpu/arcv2/start.S
blob: 3ce689675f590ff4fe0b4cf74e78fda9dabe671f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
 * Copyright (C) 2013-2015 Synopsys, Inc. All rights reserved.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <asm-offsets.h>
#include <config.h>
#include <asm/arcregs.h>

/*
 * Note on the LD/ST addressing modes with address register write-back
 *
 * LD.a same as LD.aw
 *
 * LD.a    reg1, [reg2, x]  => Pre Incr
 *      Eff Addr for load = [reg2 + x]
 *
 * LD.ab   reg1, [reg2, x]  => Post Incr
 *      Eff Addr for load = [reg2]
 */

.macro PUSH reg
	st.a	\reg, [%sp, -4]
.endm

.macro PUSHAX aux
	lr	%r9, [\aux]
	PUSH	%r9
.endm

.macro  SAVE_R1_TO_R24
	PUSH	%r1
	PUSH	%r2
	PUSH	%r3
	PUSH	%r4
	PUSH	%r5
	PUSH	%r6
	PUSH	%r7
	PUSH	%r8
	PUSH	%r9
	PUSH	%r10
	PUSH	%r11
	PUSH	%r12
	PUSH	%r13
	PUSH	%r14
	PUSH	%r15
	PUSH	%r16
	PUSH	%r17
	PUSH	%r18
	PUSH	%r19
	PUSH	%r20
	PUSH	%r21
	PUSH	%r22
	PUSH	%r23
	PUSH	%r24
.endm

.macro SAVE_ALL_SYS
	/* saving %r0 to reg->r0 in advance since weread %ecr into it */
	st	%r0, [%sp, -8]
	lr	%r0, [%ecr]	/* all stack addressing is manual so far */
	st	%r0, [%sp]
	st	%sp, [%sp, -4]
	/* now move %sp to reg->r0 position so we can do "push" automatically */
	sub	%sp, %sp, 8

	SAVE_R1_TO_R24
	PUSH	%r25
	PUSH	%gp
	PUSH	%fp
	PUSH	%blink
	PUSHAX	%eret
	PUSHAX	%erstatus
	PUSH	%lp_count
	PUSHAX	%lp_end
	PUSHAX	%lp_start
	PUSHAX	%erbta
.endm

.macro SAVE_EXCEPTION_SOURCE
#ifdef CONFIG_MMU
	/* If MMU exists exception faulting address is loaded in EFA reg */
	lr	%r0, [%efa]
#else
	/* Otherwise in ERET (exception return) reg */
	lr	%r0, [%eret]
#endif
.endm

.section .ivt, "a",@progbits
.align 4
	/* Critical system events */
.word	_start			/* 0 - 0x000 */
.word	memory_error		/* 1 - 0x008 */
.word	instruction_error	/* 2 - 0x010 */

	/* Exceptions */
.word	EV_MachineCheck		/* 0x100, Fatal Machine check  (0x20) */
.word	EV_TLBMissI		/* 0x108, Intruction TLB miss  (0x21) */
.word	EV_TLBMissD		/* 0x110, Data TLB miss        (0x22) */
.word	EV_TLBProtV		/* 0x118, Protection Violation (0x23)
							or Misaligned Access  */
.word	EV_PrivilegeV		/* 0x120, Privilege Violation  (0x24) */
.word	EV_Trap			/* 0x128, Trap exception       (0x25) */
.word	EV_Extension		/* 0x130, Extn Intruction Excp (0x26) */

	/* Device interrupts */
.rept	29
	j	interrupt_handler	/* 3:31 - 0x018:0xF8 */
.endr

.text
.globl _start
_start:
	/* Setup interrupt vector base that matches "__text_start" */
	sr	__ivt_start, [ARC_AUX_INTR_VEC_BASE]

	/* Setup stack pointer */
	mov	%sp, CONFIG_SYS_INIT_SP_ADDR
	mov	%fp, %sp

	/* Clear bss */
	mov	%r0, __bss_start
	mov	%r1, __bss_end

clear_bss:
	st.ab	0, [%r0, 4]
	brlt	%r0, %r1, clear_bss

	/* Zero the one and only argument of "board_init_f" */
	mov_s	%r0, 0
	j	board_init_f

memory_error:
	SAVE_ALL_SYS
	SAVE_EXCEPTION_SOURCE
	mov	%r1, %sp
	j	do_memory_error

instruction_error:
	SAVE_ALL_SYS
	SAVE_EXCEPTION_SOURCE
	mov	%r1, %sp
	j	do_instruction_error

interrupt_handler:
	/* Todo - save and restore CPU context when interrupts will be in use */
	bl	do_interrupt_handler
	rtie

EV_MachineCheck:
	SAVE_ALL_SYS
	SAVE_EXCEPTION_SOURCE
	mov	%r1, %sp
	j	do_machine_check_fault

EV_TLBMissI:
	SAVE_ALL_SYS
	mov	%r0, %sp
	j	do_itlb_miss

EV_TLBMissD:
	SAVE_ALL_SYS
	mov	%r0, %sp
	j	do_dtlb_miss

EV_TLBProtV:
	SAVE_ALL_SYS
	SAVE_EXCEPTION_SOURCE
	mov	%r1, %sp
	j	do_tlb_prot_violation

EV_PrivilegeV:
	SAVE_ALL_SYS
	mov	%r0, %sp
	j	do_privilege_violation

EV_Trap:
	SAVE_ALL_SYS
	mov	%r0, %sp
	j	do_trap

EV_Extension:
	SAVE_ALL_SYS
	mov	%r0, %sp
	j	do_extension

/*
 * void relocate_code (addr_sp, gd, addr_moni)
 *
 * This "function" does not return, instead it continues in RAM
 * after relocating the monitor code.
 *
 * r0 = start_addr_sp
 * r1 = new__gd
 * r2 = relocaddr
 */
.align 4
.globl	relocate_code
relocate_code:
	/*
	 * r0-r12 might be clobbered by C functions
	 * so we use r13-r16 for storage here
	 */
	mov	%r13, %r0		/* save addr_sp */
	mov	%r14, %r1		/* save addr of gd */
	mov	%r15, %r2		/* save addr of destination */

	mov	%r16, %r2		/* %r9 - relocation offset */
	sub	%r16, %r16, __image_copy_start

/* Set up the stack */
stack_setup:
	mov	%sp, %r13
	mov	%fp, %sp

/* Check if monitor is loaded right in place for relocation */
	mov	%r0, __image_copy_start
	cmp	%r0, %r15		/* skip relocation if code loaded */
	bz	do_board_init_r		/* in target location already */

/* Copy data (__image_copy_start - __image_copy_end) to new location */
	mov	%r1, %r15
	mov	%r2, __image_copy_end
	sub	%r2, %r2, %r0		/* r3 <- amount of bytes to copy */
	asr	%r2, %r2, 2		/* r3 <- amount of words to copy */
	mov	%lp_count, %r2
	lp	copy_end
	ld.ab	%r2,[%r0,4]
	st.ab	%r2,[%r1,4]
copy_end:

/* Fix relocations related issues */
	bl	do_elf_reloc_fixups
#ifndef CONFIG_SYS_ICACHE_OFF
	bl	invalidate_icache_all
#endif
#ifndef CONFIG_SYS_DCACHE_OFF
	bl	flush_dcache_all
#endif

/* Update position of intterupt vector table */
	lr	%r0, [ARC_AUX_INTR_VEC_BASE]	/* Read current position */
	add	%r0, %r0, %r16			/* Update address */
	sr	%r0, [ARC_AUX_INTR_VEC_BASE]	/* Write new position */

do_board_init_r:
/* Prepare for exection of "board_init_r" in relocated monitor */
	mov	%r2, board_init_r	/* old address of "board_init_r()" */
	add	%r2, %r2, %r16		/* new address of "board_init_r()" */
	mov	%r0, %r14		/* 1-st parameter: gd_t */
	mov	%r1, %r15		/* 2-nd parameter: dest_addr */
	j	[%r2]
OpenPOWER on IntegriCloud