blob: 3408f45d2ca8080877028cad3f8936eaf7b7011c [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>
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +03009#include <linux/linkage.h>
Alexey Brodkin3a59d912014-02-04 12:56:14 +040010#include <asm/arcregs.h>
11
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +030012ENTRY(_start)
Igor Guryanov4fec6aa2014-12-24 17:17:11 +030013 /* Setup interrupt vector base that matches "__text_start" */
14 sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
15
16 /* Setup stack pointer */
17 mov %sp, CONFIG_SYS_INIT_SP_ADDR
18 mov %fp, %sp
19
20 /* Clear bss */
21 mov %r0, __bss_start
22 mov %r1, __bss_end
23
24clear_bss:
25 st.ab 0, [%r0, 4]
26 brlt %r0, %r1, clear_bss
27
28 /* Zero the one and only argument of "board_init_f" */
29 mov_s %r0, 0
30 j board_init_f
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +030031ENDPROC(_start)
Igor Guryanov4fec6aa2014-12-24 17:17:11 +030032
Alexey Brodkin3a59d912014-02-04 12:56:14 +040033/*
34 * void relocate_code (addr_sp, gd, addr_moni)
35 *
36 * This "function" does not return, instead it continues in RAM
37 * after relocating the monitor code.
38 *
39 * r0 = start_addr_sp
40 * r1 = new__gd
41 * r2 = relocaddr
42 */
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +030043ENTRY(relocate_code)
Alexey Brodkin3a59d912014-02-04 12:56:14 +040044 /*
45 * r0-r12 might be clobbered by C functions
46 * so we use r13-r16 for storage here
47 */
48 mov %r13, %r0 /* save addr_sp */
49 mov %r14, %r1 /* save addr of gd */
50 mov %r15, %r2 /* save addr of destination */
51
52 mov %r16, %r2 /* %r9 - relocation offset */
53 sub %r16, %r16, __image_copy_start
54
55/* Set up the stack */
56stack_setup:
57 mov %sp, %r13
58 mov %fp, %sp
59
60/* Check if monitor is loaded right in place for relocation */
61 mov %r0, __image_copy_start
62 cmp %r0, %r15 /* skip relocation if code loaded */
63 bz do_board_init_r /* in target location already */
64
65/* Copy data (__image_copy_start - __image_copy_end) to new location */
66 mov %r1, %r15
67 mov %r2, __image_copy_end
68 sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
69 asr %r2, %r2, 2 /* r3 <- amount of words to copy */
70 mov %lp_count, %r2
71 lp copy_end
72 ld.ab %r2,[%r0,4]
73 st.ab %r2,[%r1,4]
74copy_end:
75
76/* Fix relocations related issues */
77 bl do_elf_reloc_fixups
78#ifndef CONFIG_SYS_ICACHE_OFF
79 bl invalidate_icache_all
80#endif
81#ifndef CONFIG_SYS_DCACHE_OFF
82 bl flush_dcache_all
83#endif
84
85/* Update position of intterupt vector table */
86 lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
87 add %r0, %r0, %r16 /* Update address */
88 sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
89
90do_board_init_r:
91/* Prepare for exection of "board_init_r" in relocated monitor */
92 mov %r2, board_init_r /* old address of "board_init_r()" */
93 add %r2, %r2, %r16 /* new address of "board_init_r()" */
94 mov %r0, %r14 /* 1-st parameter: gd_t */
95 mov %r1, %r15 /* 2-nd parameter: dest_addr */
96 j [%r2]
Alexey Brodkin7a5f30d2015-02-19 18:40:58 +030097ENDPROC(relocate_code)