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