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