Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 2 | /* |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 3 | * (C) Copyright 2007 Michal Simek |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 4 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 5 | * |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 6 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 7 | * Yasushi SHOJI <yashi@atmark-techno.com> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 10 | #include <asm-offsets.h> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 11 | #include <config.h> |
| 12 | |
Michal Simek | f942ebb | 2022-06-24 14:15:01 +0200 | [diff] [blame] | 13 | #if defined(CONFIG_STATIC_RELA) |
| 14 | #define SYM_ADDR(reg, reg_add, symbol) \ |
| 15 | mfs r20, rpc; \ |
| 16 | addik r20, r20, _GLOBAL_OFFSET_TABLE_ + 8; \ |
| 17 | lwi reg, r20, symbol@GOT; \ |
| 18 | addk reg, reg reg_add; |
| 19 | #else |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 20 | #define SYM_ADDR(reg, reg_add, symbol) \ |
| 21 | addi reg, reg_add, symbol |
Michal Simek | f942ebb | 2022-06-24 14:15:01 +0200 | [diff] [blame] | 22 | #endif |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 23 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 24 | .text |
| 25 | .global _start |
| 26 | _start: |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 27 | mts rmsr, r0 /* disable cache */ |
Michal Simek | e7d1e44 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 28 | mfs r20, rpc |
| 29 | addi r20, r20, -4 |
Michal Simek | 26acb3e | 2014-01-21 07:30:37 +0100 | [diff] [blame] | 30 | |
Michal Simek | 2d92f87 | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 31 | mts rslr, r0 |
Michal Simek | e7d1e44 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 32 | mts rshr, r20 |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 33 | |
Michal Simek | 26acb3e | 2014-01-21 07:30:37 +0100 | [diff] [blame] | 34 | #if defined(CONFIG_SPL_BUILD) |
| 35 | addi r1, r0, CONFIG_SPL_STACK_ADDR |
Michal Simek | 9ea6744 | 2015-01-30 15:46:43 +0100 | [diff] [blame] | 36 | #else |
Michal Simek | e7d1e44 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 37 | add r1, r0, r20 |
Michal Simek | f942ebb | 2022-06-24 14:15:01 +0200 | [diff] [blame] | 38 | #if defined(CONFIG_STATIC_RELA) |
| 39 | bri 1f |
| 40 | |
| 41 | /* Force alignment for easier ASM code below */ |
| 42 | #define ALIGNMENT_ADDR 0x20 |
| 43 | .align 4 |
| 44 | uboot_dyn_start: |
| 45 | .word __rel_dyn_start |
| 46 | |
| 47 | uboot_dyn_end: |
| 48 | .word __rel_dyn_end |
| 49 | |
| 50 | uboot_sym_start: |
| 51 | .word __dyn_sym_start |
| 52 | 1: |
| 53 | |
| 54 | addi r5, r20, 0 |
| 55 | add r6, r0, r0 |
| 56 | |
| 57 | lwi r7, r20, ALIGNMENT_ADDR |
| 58 | addi r7, r7, -CONFIG_SYS_TEXT_BASE |
| 59 | add r7, r7, r5 |
| 60 | lwi r8, r20, ALIGNMENT_ADDR + 0x4 |
| 61 | addi r8, r8, -CONFIG_SYS_TEXT_BASE |
| 62 | add r8, r8, r5 |
| 63 | lwi r9, r20, ALIGNMENT_ADDR + 0x8 |
| 64 | addi r9, r9, -CONFIG_SYS_TEXT_BASE |
| 65 | add r9, r9, r5 |
| 66 | addi r10, r0, CONFIG_SYS_TEXT_BASE |
| 67 | |
| 68 | brlid r15, mb_fix_rela |
| 69 | nop |
| 70 | #endif |
Michal Simek | 9ea6744 | 2015-01-30 15:46:43 +0100 | [diff] [blame] | 71 | #endif |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 72 | |
Michal Simek | 1f0c40c | 2007-03-26 01:39:07 +0200 | [diff] [blame] | 73 | addi r1, r1, -4 /* Decrement SP to top of memory */ |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 74 | |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 75 | /* Call board_init_f_alloc_reserve with the current stack pointer as |
| 76 | * parameter. */ |
| 77 | add r5, r0, r1 |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 78 | brlid r15, board_init_f_alloc_reserve |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 79 | nop |
| 80 | |
| 81 | /* board_init_f_alloc_reserve returns a pointer to the allocated area |
| 82 | * in r3. Set the new stack pointer below this area. */ |
| 83 | add r1, r0, r3 |
| 84 | mts rshr, r1 |
| 85 | addi r1, r1, -4 |
| 86 | |
| 87 | /* Call board_init_f_init_reserve with the address returned by |
| 88 | * board_init_f_alloc_reserve as parameter. */ |
| 89 | add r5, r0, r3 |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 90 | brlid r15, board_init_f_init_reserve |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 91 | nop |
| 92 | |
| 93 | #if !defined(CONFIG_SPL_BUILD) |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 94 | /* Setup vectors with pre-relocation symbols */ |
| 95 | or r5, r0, r0 |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 96 | brlid r15, __setup_exceptions |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 97 | nop |
Ovidiu Panait | e6dbb8b | 2020-09-24 11:54:37 +0300 | [diff] [blame] | 98 | #endif |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 99 | |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame^] | 100 | /* |
| 101 | * Initialize global data cpuinfo with default values (cache |
| 102 | * size, cache line size, etc). |
| 103 | */ |
| 104 | brlid r15, microblaze_early_cpuinfo_init |
| 105 | nop |
| 106 | |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 107 | /* Flush cache before enable cache */ |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 108 | brlid r15, flush_cache_all |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 109 | nop |
| 110 | |
| 111 | /* enable instruction and data cache */ |
| 112 | mfs r12, rmsr |
| 113 | ori r12, r12, 0x1a0 |
| 114 | mts rmsr, r12 |
| 115 | |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 116 | clear_bss: |
| 117 | /* clear BSS segments */ |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 118 | SYM_ADDR(r5, r0, __bss_start) |
| 119 | SYM_ADDR(r4, r0, __bss_end) |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 120 | cmp r6, r5, r4 |
| 121 | beqi r6, 3f |
| 122 | 2: |
| 123 | swi r0, r5, 0 /* write zero to loc */ |
| 124 | addi r5, r5, 4 /* increment to next loc */ |
| 125 | cmp r6, r5, r4 /* check if we have reach the end */ |
| 126 | bnei r6, 2b |
| 127 | 3: /* jumping to board_init */ |
| 128 | #ifdef CONFIG_DEBUG_UART |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 129 | brlid r15, debug_uart_init |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 130 | nop |
| 131 | #endif |
| 132 | #ifndef CONFIG_SPL_BUILD |
| 133 | or r5, r0, r0 /* flags - empty */ |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 134 | bri board_init_f |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 135 | #else |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 136 | bri board_init_r |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 137 | #endif |
| 138 | 1: bri 1b |
| 139 | |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 140 | #ifndef CONFIG_SPL_BUILD |
| 141 | .text |
| 142 | .ent __setup_exceptions |
| 143 | .align 2 |
| 144 | /* |
| 145 | * Set up reset, interrupt, user exception and hardware exception vectors. |
| 146 | * |
| 147 | * Parameters: |
| 148 | * r5 - relocation offset (zero when setting up vectors before |
| 149 | * relocation, and gd->reloc_off when setting up vectors after |
| 150 | * relocation) |
| 151 | * - the relocation offset is added to the _exception_handler, |
| 152 | * _interrupt_handler and _hw_exception_handler symbols to reflect the |
| 153 | * post-relocation memory addresses |
| 154 | * |
| 155 | * Reserve registers: |
| 156 | * r10: Stores little/big endian offset for vectors |
| 157 | * r2: Stores imm opcode |
| 158 | * r3: Stores brai opcode |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 159 | * r4: Stores the vector base address |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 160 | */ |
| 161 | __setup_exceptions: |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 162 | addik r1, r1, -32 |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 163 | swi r2, r1, 4 |
| 164 | swi r3, r1, 8 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 165 | swi r4, r1, 12 |
| 166 | swi r6, r1, 16 |
| 167 | swi r7, r1, 20 |
| 168 | swi r8, r1, 24 |
| 169 | swi r10, r1, 28 |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 170 | |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 171 | /* Find-out if u-boot is running on BIG/LITTLE endian platform |
| 172 | * There are some steps which is necessary to keep in mind: |
| 173 | * 1. Setup offset value to r6 |
| 174 | * 2. Store word offset value to address 0x0 |
| 175 | * 3. Load just byte from address 0x0 |
| 176 | * 4a) LITTLE endian - r10 contains 0x2 because it is the smallest |
| 177 | * value that's why is on address 0x0 |
| 178 | * 4b) BIG endian - r10 contains 0x0 because 0x2 offset is on addr 0x3 |
| 179 | */ |
| 180 | addik r6, r0, 0x2 /* BIG/LITTLE endian offset */ |
Ovidiu Panait | ff759b3 | 2021-11-30 18:33:52 +0200 | [diff] [blame] | 181 | sw r6, r1, r0 |
| 182 | lbu r10, r1, r0 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 183 | |
Michal Simek | 4a30db9 | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 184 | /* add opcode instruction for 32bit jump - 2 instruction imm & brai */ |
| 185 | addi r2, r0, 0xb0000000 /* hex b000 opcode imm */ |
| 186 | addi r3, r0, 0xb8080000 /* hew b808 opcode brai */ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 187 | |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 188 | /* Store the vector base address in r4 */ |
| 189 | addi r4, r0, CONFIG_XILINX_MICROBLAZE0_VECTOR_BASE_ADDR |
| 190 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 191 | /* reset address */ |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 192 | swi r2, r4, 0x0 /* reset address - imm opcode */ |
| 193 | swi r3, r4, 0x4 /* reset address - brai opcode */ |
Michal Simek | 4a30db9 | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 194 | |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 195 | SYM_ADDR(r6, r0, _start) |
Michal Simek | fa43ada | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 196 | /* Intentionally keep reset vector back to origin u-boot location */ |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 197 | sw r6, r1, r0 |
Michal Simek | 8daf0c3 | 2011-08-30 15:22:24 +0200 | [diff] [blame] | 198 | lhu r7, r1, r10 |
| 199 | rsubi r8, r10, 0x2 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 200 | sh r7, r4, r8 |
Michal Simek | 8daf0c3 | 2011-08-30 15:22:24 +0200 | [diff] [blame] | 201 | rsubi r8, r10, 0x6 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 202 | sh r6, r4, r8 |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 203 | |
Ovidiu Panait | 39415f7 | 2021-11-30 18:33:54 +0200 | [diff] [blame] | 204 | #if CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USR_EXCEP) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 205 | /* user_vector_exception */ |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 206 | swi r2, r4, 0x8 /* user vector exception - imm opcode */ |
| 207 | swi r3, r4, 0xC /* user vector exception - brai opcode */ |
Michal Simek | 4a30db9 | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 208 | |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 209 | SYM_ADDR(r6, r5, _exception_handler) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 210 | sw r6, r1, r0 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 211 | /* |
| 212 | * BIG ENDIAN memory map for user exception |
| 213 | * 0x8: 0xB000XXXX |
| 214 | * 0xC: 0xB808XXXX |
| 215 | * |
| 216 | * then it is necessary to count address for storing the most significant |
Wolfgang Denk | 1136f69 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 217 | * 16bits from _exception_handler address and copy it to |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 218 | * 0xa address. Big endian use offset in r10=0 that's why is it just |
| 219 | * 0xa address. The same is done for the least significant 16 bits |
| 220 | * for 0xe address. |
| 221 | * |
| 222 | * LITTLE ENDIAN memory map for user exception |
| 223 | * 0x8: 0xXXXX00B0 |
| 224 | * 0xC: 0xXXXX08B8 |
| 225 | * |
| 226 | * Offset is for little endian setup to 0x2. rsubi instruction decrease |
| 227 | * address value to ensure that points to proper place which is |
| 228 | * 0x8 for the most significant 16 bits and |
| 229 | * 0xC for the least significant 16 bits |
| 230 | */ |
| 231 | lhu r7, r1, r10 |
| 232 | rsubi r8, r10, 0xa |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 233 | sh r7, r4, r8 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 234 | rsubi r8, r10, 0xe |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 235 | sh r6, r4, r8 |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 236 | #endif |
| 237 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 238 | /* interrupt_handler */ |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 239 | swi r2, r4, 0x10 /* interrupt - imm opcode */ |
| 240 | swi r3, r4, 0x14 /* interrupt - brai opcode */ |
Michal Simek | 4a30db9 | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 241 | |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 242 | SYM_ADDR(r6, r5, _interrupt_handler) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 243 | sw r6, r1, r0 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 244 | lhu r7, r1, r10 |
| 245 | rsubi r8, r10, 0x12 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 246 | sh r7, r4, r8 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 247 | rsubi r8, r10, 0x16 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 248 | sh r6, r4, r8 |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 249 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 250 | /* hardware exception */ |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 251 | swi r2, r4, 0x20 /* hardware exception - imm opcode */ |
| 252 | swi r3, r4, 0x24 /* hardware exception - brai opcode */ |
Michal Simek | 4a30db9 | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 253 | |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 254 | SYM_ADDR(r6, r5, _hw_exception_handler) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 255 | sw r6, r1, r0 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 256 | lhu r7, r1, r10 |
| 257 | rsubi r8, r10, 0x22 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 258 | sh r7, r4, r8 |
Michal Simek | ead124a | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 259 | rsubi r8, r10, 0x26 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 260 | sh r6, r4, r8 |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 261 | |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 262 | lwi r10, r1, 28 |
| 263 | lwi r8, r1, 24 |
| 264 | lwi r7, r1, 20 |
| 265 | lwi r6, r1, 16 |
| 266 | lwi r4, r1, 12 |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 267 | lwi r3, r1, 8 |
| 268 | lwi r2, r1, 4 |
Ovidiu Panait | e165fa5 | 2021-11-30 18:33:56 +0200 | [diff] [blame] | 269 | addik r1, r1, 32 |
Michal Simek | e3aa3d5 | 2012-09-25 10:13:35 +0200 | [diff] [blame] | 270 | |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 271 | rtsd r15, 8 |
| 272 | or r0, r0, r0 |
| 273 | .end __setup_exceptions |
Michal Simek | a79d658 | 2015-01-30 15:45:02 +0100 | [diff] [blame] | 274 | |
Michal Simek | 04ae75f | 2007-04-21 21:02:40 +0200 | [diff] [blame] | 275 | /* |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 276 | * Relocate u-boot |
| 277 | */ |
| 278 | .text |
| 279 | .global relocate_code |
| 280 | .ent relocate_code |
| 281 | .align 2 |
| 282 | relocate_code: |
| 283 | /* |
| 284 | * r5 - start_addr_sp |
| 285 | * r6 - new_gd |
| 286 | * r7 - reloc_addr |
| 287 | */ |
| 288 | addi r1, r5, 0 /* Start to use new SP */ |
Michal Simek | 32b80be | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 289 | mts rshr, r1 |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 290 | addi r31, r6, 0 /* Start to use new GD */ |
| 291 | |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 292 | /* Relocate text and data - r12 temp value */ |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 293 | SYM_ADDR(r21, r0, _start) |
| 294 | SYM_ADDR(r22, r0, _end) /* Include BSS too */ |
Michal Simek | 9873008 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 295 | addi r22, r22, -4 |
Michal Simek | a9228f6 | 2015-01-27 15:10:37 +0100 | [diff] [blame] | 296 | |
| 297 | rsub r6, r21, r22 |
| 298 | or r5, r0, r0 |
| 299 | 1: lw r12, r21, r5 /* Load u-boot data */ |
Michal Simek | ca0fe05 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 300 | sw r12, r7, r5 /* Write zero to loc */ |
Michal Simek | a9228f6 | 2015-01-27 15:10:37 +0100 | [diff] [blame] | 301 | cmp r12, r5, r6 /* Check if we have reach the end */ |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 302 | bneid r12, 1b |
Michal Simek | a9228f6 | 2015-01-27 15:10:37 +0100 | [diff] [blame] | 303 | addi r5, r5, 4 /* Increment to next loc - relocate code */ |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 304 | |
Michal Simek | 55df7da | 2019-10-21 12:20:16 +0200 | [diff] [blame] | 305 | /* R23 points to the base address. */ |
Michal Simek | ca0fe05 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 306 | rsub r23, r21, r7 /* keep - this is already here gd->reloc_off */ |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 307 | |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 308 | /* Setup vectors with post-relocation symbols */ |
| 309 | add r5, r0, r23 /* load gd->reloc_off to r5 */ |
Michal Simek | 8f57aec | 2022-06-24 14:14:59 +0200 | [diff] [blame] | 310 | brlid r15, __setup_exceptions |
Ovidiu Panait | 9855835 | 2020-09-24 11:54:36 +0300 | [diff] [blame] | 311 | nop |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 312 | |
Michal Simek | f942ebb | 2022-06-24 14:15:01 +0200 | [diff] [blame] | 313 | #if defined(CONFIG_STATIC_RELA) |
| 314 | /* reloc_offset is current location */ |
| 315 | SYM_ADDR(r10, r0, _start) |
| 316 | |
| 317 | /* r5 new address where I should copy code */ |
| 318 | add r5, r0, r7 /* Move reloc addr to r5 */ |
| 319 | |
| 320 | /* Verbose message */ |
| 321 | addi r6, r0, 0 |
| 322 | |
| 323 | SYM_ADDR(r7, r0, __rel_dyn_start) |
| 324 | rsub r7, r10, r7 |
| 325 | add r7, r7, r5 |
| 326 | SYM_ADDR(r8, r0, __rel_dyn_end) |
| 327 | rsub r8, r10, r8 |
| 328 | add r8, r8, r5 |
| 329 | SYM_ADDR(r9, r0, __dyn_sym_start) |
| 330 | rsub r9, r10, r9 |
| 331 | add r9, r9, r5 |
| 332 | brlid r15, mb_fix_rela |
| 333 | nop |
| 334 | |
| 335 | /* end of code which does relocation */ |
| 336 | #else |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 337 | /* Check if GOT exist */ |
| 338 | addik r21, r23, _got_start |
| 339 | addik r22, r23, _got_end |
| 340 | cmpu r12, r21, r22 |
| 341 | beqi r12, 2f /* No GOT table - jump over */ |
| 342 | |
| 343 | /* Skip last 3 entries plus 1 because of loop boundary below */ |
| 344 | addik r22, r22, -0x10 |
| 345 | |
| 346 | /* Relocate the GOT. */ |
| 347 | 3: lw r12, r21, r0 /* Load entry */ |
| 348 | addk r12, r12, r23 /* Add reloc offset */ |
| 349 | sw r12, r21, r0 /* Save entry back */ |
| 350 | |
| 351 | cmpu r12, r21, r22 /* Check if this cross boundary */ |
| 352 | bneid r12, 3b |
| 353 | addik r21. r21, 4 |
Michal Simek | f942ebb | 2022-06-24 14:15:01 +0200 | [diff] [blame] | 354 | #endif |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 355 | |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 356 | /* Flush caches to ensure consistency */ |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 357 | brlid r15, flush_cache_all |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 358 | nop |
| 359 | |
| 360 | 2: addi r5, r31, 0 /* gd is initialized in board_r.c */ |
Michal Simek | a8e5d75 | 2022-06-24 14:15:00 +0200 | [diff] [blame] | 361 | SYM_ADDR(r6, r0, _start) |
| 362 | SYM_ADDR(r12, r23, board_init_r) |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 363 | bra r12 /* Jump to relocated code */ |
| 364 | |
| 365 | .end relocate_code |
Michal Simek | 26acb3e | 2014-01-21 07:30:37 +0100 | [diff] [blame] | 366 | #endif |