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