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 | |
| 12 | /* |
| 13 | * Note on the LD/ST addressing modes with address register write-back |
| 14 | * |
| 15 | * LD.a same as LD.aw |
| 16 | * |
| 17 | * LD.a reg1, [reg2, x] => Pre Incr |
| 18 | * Eff Addr for load = [reg2 + x] |
| 19 | * |
| 20 | * LD.ab reg1, [reg2, x] => Post Incr |
| 21 | * Eff Addr for load = [reg2] |
| 22 | */ |
| 23 | |
| 24 | .macro PUSH reg |
| 25 | st.a \reg, [%sp, -4] |
| 26 | .endm |
| 27 | |
| 28 | .macro PUSHAX aux |
| 29 | lr %r9, [\aux] |
| 30 | PUSH %r9 |
| 31 | .endm |
| 32 | |
| 33 | .macro SAVE_R1_TO_R24 |
| 34 | PUSH %r1 |
| 35 | PUSH %r2 |
| 36 | PUSH %r3 |
| 37 | PUSH %r4 |
| 38 | PUSH %r5 |
| 39 | PUSH %r6 |
| 40 | PUSH %r7 |
| 41 | PUSH %r8 |
| 42 | PUSH %r9 |
| 43 | PUSH %r10 |
| 44 | PUSH %r11 |
| 45 | PUSH %r12 |
| 46 | PUSH %r13 |
| 47 | PUSH %r14 |
| 48 | PUSH %r15 |
| 49 | PUSH %r16 |
| 50 | PUSH %r17 |
| 51 | PUSH %r18 |
| 52 | PUSH %r19 |
| 53 | PUSH %r20 |
| 54 | PUSH %r21 |
| 55 | PUSH %r22 |
| 56 | PUSH %r23 |
| 57 | PUSH %r24 |
| 58 | .endm |
| 59 | |
| 60 | .macro SAVE_ALL_SYS |
Igor Guryanov | 742bc74 | 2014-12-24 16:26:14 +0300 | [diff] [blame] | 61 | /* saving %r0 to reg->r0 in advance since we read %ecr into it */ |
| 62 | st %r0, [%sp, -8] |
| 63 | lr %r0, [%ecr] /* all stack addressing is manual so far */ |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 64 | st %r0, [%sp] |
Igor Guryanov | 742bc74 | 2014-12-24 16:26:14 +0300 | [diff] [blame] | 65 | st %sp, [%sp, -4] |
| 66 | /* now move %sp to reg->r0 position so we can do "push" automatically */ |
| 67 | sub %sp, %sp, 8 |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 68 | |
| 69 | SAVE_R1_TO_R24 |
| 70 | PUSH %r25 |
| 71 | PUSH %gp |
| 72 | PUSH %fp |
| 73 | PUSH %blink |
| 74 | PUSHAX %eret |
| 75 | PUSHAX %erstatus |
| 76 | PUSH %lp_count |
| 77 | PUSHAX %lp_end |
| 78 | PUSHAX %lp_start |
| 79 | PUSHAX %erbta |
| 80 | .endm |
| 81 | |
Alexey Brodkin | 5e4931f | 2014-12-24 17:00:29 +0300 | [diff] [blame] | 82 | .macro SAVE_EXCEPTION_SOURCE |
| 83 | #ifdef CONFIG_MMU |
| 84 | /* If MMU exists exception faulting address is loaded in EFA reg */ |
| 85 | lr %r0, [%efa] |
| 86 | #else |
| 87 | /* Otherwise in ERET (exception return) reg */ |
| 88 | lr %r0, [%eret] |
| 89 | #endif |
| 90 | .endm |
| 91 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 92 | ENTRY(_start) |
Igor Guryanov | 4fec6aa | 2014-12-24 17:17:11 +0300 | [diff] [blame] | 93 | /* Setup interrupt vector base that matches "__text_start" */ |
| 94 | sr __ivt_start, [ARC_AUX_INTR_VEC_BASE] |
| 95 | |
| 96 | /* Setup stack pointer */ |
| 97 | mov %sp, CONFIG_SYS_INIT_SP_ADDR |
| 98 | mov %fp, %sp |
| 99 | |
| 100 | /* Clear bss */ |
| 101 | mov %r0, __bss_start |
| 102 | mov %r1, __bss_end |
| 103 | |
| 104 | clear_bss: |
| 105 | st.ab 0, [%r0, 4] |
| 106 | brlt %r0, %r1, clear_bss |
| 107 | |
| 108 | /* Zero the one and only argument of "board_init_f" */ |
| 109 | mov_s %r0, 0 |
| 110 | j board_init_f |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 111 | ENDPROC(_start) |
Igor Guryanov | 4fec6aa | 2014-12-24 17:17:11 +0300 | [diff] [blame] | 112 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 113 | ENTRY(memory_error) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 114 | SAVE_ALL_SYS |
Alexey Brodkin | 5e4931f | 2014-12-24 17:00:29 +0300 | [diff] [blame] | 115 | SAVE_EXCEPTION_SOURCE |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 116 | mov %r1, %sp |
| 117 | j do_memory_error |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 118 | ENDPROC(memory_error) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 119 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 120 | ENTRY(instruction_error) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 121 | SAVE_ALL_SYS |
Alexey Brodkin | 5e4931f | 2014-12-24 17:00:29 +0300 | [diff] [blame] | 122 | SAVE_EXCEPTION_SOURCE |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 123 | mov %r1, %sp |
| 124 | j do_instruction_error |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 125 | ENDPROC(instruction_error) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 126 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 127 | ENTRY(interrupt_handler) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 128 | /* Todo - save and restore CPU context when interrupts will be in use */ |
| 129 | bl do_interrupt_handler |
| 130 | rtie |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 131 | ENDPROC(interrupt_handler) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 132 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 133 | ENTRY(EV_MachineCheck) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 134 | SAVE_ALL_SYS |
Alexey Brodkin | 5e4931f | 2014-12-24 17:00:29 +0300 | [diff] [blame] | 135 | SAVE_EXCEPTION_SOURCE |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 136 | mov %r1, %sp |
| 137 | j do_machine_check_fault |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 138 | ENDPROC(EV_MachineCheck) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 139 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 140 | ENTRY(EV_TLBMissI) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 141 | SAVE_ALL_SYS |
| 142 | mov %r0, %sp |
| 143 | j do_itlb_miss |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 144 | ENDPROC(EV_TLBMissI) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 145 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 146 | ENTRY(EV_TLBMissD) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 147 | SAVE_ALL_SYS |
| 148 | mov %r0, %sp |
| 149 | j do_dtlb_miss |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 150 | ENDPROC(EV_TLBMissD) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 151 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 152 | ENTRY(EV_TLBProtV) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 153 | SAVE_ALL_SYS |
Alexey Brodkin | 5e4931f | 2014-12-24 17:00:29 +0300 | [diff] [blame] | 154 | SAVE_EXCEPTION_SOURCE |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 155 | mov %r1, %sp |
| 156 | j do_tlb_prot_violation |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 157 | ENDPROC(EV_TLBProtV) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 158 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 159 | ENTRY(EV_PrivilegeV) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 160 | SAVE_ALL_SYS |
| 161 | mov %r0, %sp |
| 162 | j do_privilege_violation |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 163 | ENDPROC(EV_PrivilegeV) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 164 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 165 | ENTRY(EV_Trap) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 166 | SAVE_ALL_SYS |
| 167 | mov %r0, %sp |
| 168 | j do_trap |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 169 | ENDPROC(EV_Trap) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 170 | |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 171 | ENTRY(EV_Extension) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 172 | SAVE_ALL_SYS |
| 173 | mov %r0, %sp |
| 174 | j do_extension |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 175 | ENDPROC(EV_Extension) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 176 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 177 | /* |
| 178 | * void relocate_code (addr_sp, gd, addr_moni) |
| 179 | * |
| 180 | * This "function" does not return, instead it continues in RAM |
| 181 | * after relocating the monitor code. |
| 182 | * |
| 183 | * r0 = start_addr_sp |
| 184 | * r1 = new__gd |
| 185 | * r2 = relocaddr |
| 186 | */ |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 187 | ENTRY(relocate_code) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 188 | /* |
| 189 | * r0-r12 might be clobbered by C functions |
| 190 | * so we use r13-r16 for storage here |
| 191 | */ |
| 192 | mov %r13, %r0 /* save addr_sp */ |
| 193 | mov %r14, %r1 /* save addr of gd */ |
| 194 | mov %r15, %r2 /* save addr of destination */ |
| 195 | |
| 196 | mov %r16, %r2 /* %r9 - relocation offset */ |
| 197 | sub %r16, %r16, __image_copy_start |
| 198 | |
| 199 | /* Set up the stack */ |
| 200 | stack_setup: |
| 201 | mov %sp, %r13 |
| 202 | mov %fp, %sp |
| 203 | |
| 204 | /* Check if monitor is loaded right in place for relocation */ |
| 205 | mov %r0, __image_copy_start |
| 206 | cmp %r0, %r15 /* skip relocation if code loaded */ |
| 207 | bz do_board_init_r /* in target location already */ |
| 208 | |
| 209 | /* Copy data (__image_copy_start - __image_copy_end) to new location */ |
| 210 | mov %r1, %r15 |
| 211 | mov %r2, __image_copy_end |
| 212 | sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */ |
| 213 | asr %r2, %r2, 2 /* r3 <- amount of words to copy */ |
| 214 | mov %lp_count, %r2 |
| 215 | lp copy_end |
| 216 | ld.ab %r2,[%r0,4] |
| 217 | st.ab %r2,[%r1,4] |
| 218 | copy_end: |
| 219 | |
| 220 | /* Fix relocations related issues */ |
| 221 | bl do_elf_reloc_fixups |
| 222 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 223 | bl invalidate_icache_all |
| 224 | #endif |
| 225 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 226 | bl flush_dcache_all |
| 227 | #endif |
| 228 | |
| 229 | /* Update position of intterupt vector table */ |
| 230 | lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */ |
| 231 | add %r0, %r0, %r16 /* Update address */ |
| 232 | sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */ |
| 233 | |
| 234 | do_board_init_r: |
| 235 | /* Prepare for exection of "board_init_r" in relocated monitor */ |
| 236 | mov %r2, board_init_r /* old address of "board_init_r()" */ |
| 237 | add %r2, %r2, %r16 /* new address of "board_init_r()" */ |
| 238 | mov %r0, %r14 /* 1-st parameter: gd_t */ |
| 239 | mov %r1, %r15 /* 2-nd parameter: dest_addr */ |
| 240 | j [%r2] |
Alexey Brodkin | 7a5f30d | 2015-02-19 18:40:58 +0300 | [diff] [blame^] | 241 | ENDPROC(relocate_code) |