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