Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 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> |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame] | 9 | #include <linux/linkage.h> |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 10 | #include <asm/arcregs.h> |
| 11 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame] | 12 | ENTRY(_start) |
Igor Guryanov | 4fec6aa | 2014-12-24 17:17:11 +0300 | [diff] [blame] | 13 | /* 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 | |
| 24 | clear_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 Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame] | 31 | ENDPROC(_start) |
Igor Guryanov | 4fec6aa | 2014-12-24 17:17:11 +0300 | [diff] [blame] | 32 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 33 | /* |
| 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 Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame] | 43 | ENTRY(relocate_code) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 44 | /* |
| 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 */ |
| 56 | stack_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] |
| 74 | copy_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 | |
| 90 | do_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 Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame] | 97 | ENDPROC(relocate_code) |