blob: f95fb6ed5d1fa1e2bde693e7a3711bf061168be0 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
AlexeiFedorovbd8b1bb2024-03-13 17:07:03 +00002 * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Dan Handley2bd4ef22014-04-09 13:14:54 +01007#include <arch.h>
Andrew Thoelke38bde412014-03-18 13:46:55 +00008#include <asm_macros.S>
Soby Mathew041f62a2014-07-14 16:58:03 +01009#include <assert_macros.S>
Varun Wadekar17425d32019-01-10 15:46:34 -080010#include <common/bl_common.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <lib/xlat_tables/xlat_tables_defs.h>
Achin Gupta4a826dd2013-11-25 14:00:56 +000012
Achin Gupta4f6ad662013-10-25 09:08:21 +010013 .globl smc
14
Douglas Raillard21362a92016-12-02 13:51:54 +000015 .globl zero_normalmem
16 .globl zeromem
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000017 .globl memcpy16
Achin Gupta4f6ad662013-10-25 09:08:21 +010018
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +010019 .globl disable_mmu_el1
Andrew Thoelke438c63a2014-04-28 12:06:18 +010020 .globl disable_mmu_el3
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +010021 .globl disable_mmu_icache_el1
Andrew Thoelke438c63a2014-04-28 12:06:18 +010022 .globl disable_mmu_icache_el3
Soby Mathew4e28c202018-10-14 08:09:22 +010023 .globl fixup_gdt_reloc
Andrew Thoelke38bde412014-03-18 13:46:55 +000024func smc
Achin Gupta4f6ad662013-10-25 09:08:21 +010025 smc #0
Kévin Petita877c252015-03-24 14:03:57 +000026endfunc smc
Sandrine Bailleux65f546a2013-11-28 09:43:06 +000027
28/* -----------------------------------------------------------------------
Douglas Raillard21362a92016-12-02 13:51:54 +000029 * void zero_normalmem(void *mem, unsigned int length);
30 *
31 * Initialise a region in normal memory to 0. This functions complies with the
32 * AAPCS and can be called from C code.
33 *
34 * NOTE: MMU must be enabled when using this function as it can only operate on
35 * normal memory. It is intended to be mainly used from C code when MMU
36 * is usually enabled.
37 * -----------------------------------------------------------------------
38 */
39.equ zero_normalmem, zeromem_dczva
40
41/* -----------------------------------------------------------------------
42 * void zeromem(void *mem, unsigned int length);
43 *
44 * Initialise a region of device memory to 0. This functions complies with the
45 * AAPCS and can be called from C code.
46 *
47 * NOTE: When data caches and MMU are enabled, zero_normalmem can usually be
48 * used instead for faster zeroing.
49 *
50 * -----------------------------------------------------------------------
51 */
52func zeromem
53 /* x2 is the address past the last zeroed address */
54 add x2, x0, x1
55 /*
56 * Uses the fallback path that does not use DC ZVA instruction and
57 * therefore does not need enabled MMU
58 */
59 b .Lzeromem_dczva_fallback_entry
60endfunc zeromem
61
62/* -----------------------------------------------------------------------
63 * void zeromem_dczva(void *mem, unsigned int length);
64 *
65 * Fill a region of normal memory of size "length" in bytes with null bytes.
66 * MMU must be enabled and the memory be of
67 * normal type. This is because this function internally uses the DC ZVA
68 * instruction, which generates an Alignment fault if used on any type of
69 * Device memory (see section D3.4.9 of the ARMv8 ARM, issue k). When the MMU
70 * is disabled, all memory behaves like Device-nGnRnE memory (see section
71 * D4.2.8), hence the requirement on the MMU being enabled.
72 * NOTE: The code assumes that the block size as defined in DCZID_EL0
73 * register is at least 16 bytes.
74 *
75 * -----------------------------------------------------------------------
76 */
77func zeromem_dczva
78
79 /*
80 * The function consists of a series of loops that zero memory one byte
81 * at a time, 16 bytes at a time or using the DC ZVA instruction to
82 * zero aligned block of bytes, which is assumed to be more than 16.
83 * In the case where the DC ZVA instruction cannot be used or if the
84 * first 16 bytes loop would overflow, there is fallback path that does
85 * not use DC ZVA.
86 * Note: The fallback path is also used by the zeromem function that
87 * branches to it directly.
88 *
89 * +---------+ zeromem_dczva
90 * | entry |
91 * +----+----+
92 * |
93 * v
94 * +---------+
95 * | checks |>o-------+ (If any check fails, fallback)
96 * +----+----+ |
97 * | |---------------+
98 * v | Fallback path |
99 * +------+------+ |---------------+
100 * | 1 byte loop | |
101 * +------+------+ .Lzeromem_dczva_initial_1byte_aligned_end
102 * | |
103 * v |
104 * +-------+-------+ |
105 * | 16 bytes loop | |
106 * +-------+-------+ |
107 * | |
108 * v |
109 * +------+------+ .Lzeromem_dczva_blocksize_aligned
110 * | DC ZVA loop | |
111 * +------+------+ |
112 * +--------+ | |
113 * | | | |
114 * | v v |
115 * | +-------+-------+ .Lzeromem_dczva_final_16bytes_aligned
116 * | | 16 bytes loop | |
117 * | +-------+-------+ |
118 * | | |
119 * | v |
120 * | +------+------+ .Lzeromem_dczva_final_1byte_aligned
121 * | | 1 byte loop | |
122 * | +-------------+ |
123 * | | |
124 * | v |
125 * | +---+--+ |
126 * | | exit | |
127 * | +------+ |
128 * | |
129 * | +--------------+ +------------------+ zeromem
130 * | | +----------------| zeromem function |
131 * | | | +------------------+
132 * | v v
133 * | +-------------+ .Lzeromem_dczva_fallback_entry
134 * | | 1 byte loop |
135 * | +------+------+
136 * | |
137 * +-----------+
138 */
139
140 /*
141 * Readable names for registers
142 *
143 * Registers x0, x1 and x2 are also set by zeromem which
144 * branches into the fallback path directly, so cursor, length and
145 * stop_address should not be retargeted to other registers.
146 */
147 cursor .req x0 /* Start address and then current address */
148 length .req x1 /* Length in bytes of the region to zero out */
149 /* Reusing x1 as length is never used after block_mask is set */
150 block_mask .req x1 /* Bitmask of the block size read in DCZID_EL0 */
151 stop_address .req x2 /* Address past the last zeroed byte */
152 block_size .req x3 /* Size of a block in bytes as read in DCZID_EL0 */
153 tmp1 .req x4
154 tmp2 .req x5
155
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100156#if ENABLE_ASSERTIONS
Douglas Raillard21362a92016-12-02 13:51:54 +0000157 /*
158 * Check for M bit (MMU enabled) of the current SCTLR_EL(1|3)
159 * register value and panic if the MMU is disabled.
160 */
Zelalem Aweke688fbf72021-07-09 11:37:10 -0500161#if defined(IMAGE_BL1) || defined(IMAGE_BL31) || (defined(IMAGE_BL2) && \
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -0600162 BL2_RUNS_AT_EL3)
Douglas Raillard21362a92016-12-02 13:51:54 +0000163 mrs tmp1, sctlr_el3
164#else
165 mrs tmp1, sctlr_el1
Soby Mathew041f62a2014-07-14 16:58:03 +0100166#endif
Douglas Raillard21362a92016-12-02 13:51:54 +0000167
168 tst tmp1, #SCTLR_M_BIT
169 ASM_ASSERT(ne)
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100170#endif /* ENABLE_ASSERTIONS */
Douglas Raillard21362a92016-12-02 13:51:54 +0000171
172 /* stop_address is the address past the last to zero */
173 add stop_address, cursor, length
174
175 /*
176 * Get block_size = (log2(<block size>) >> 2) (see encoding of
177 * dczid_el0 reg)
178 */
179 mrs block_size, dczid_el0
180
181 /*
182 * Select the 4 lowest bits and convert the extracted log2(<block size
183 * in words>) to <block size in bytes>
184 */
185 ubfx block_size, block_size, #0, #4
186 mov tmp2, #(1 << 2)
187 lsl block_size, tmp2, block_size
188
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100189#if ENABLE_ASSERTIONS
Douglas Raillard21362a92016-12-02 13:51:54 +0000190 /*
191 * Assumes block size is at least 16 bytes to avoid manual realignment
192 * of the cursor at the end of the DCZVA loop.
193 */
194 cmp block_size, #16
195 ASM_ASSERT(hs)
196#endif
197 /*
198 * Not worth doing all the setup for a region less than a block and
199 * protects against zeroing a whole block when the area to zero is
200 * smaller than that. Also, as it is assumed that the block size is at
201 * least 16 bytes, this also protects the initial aligning loops from
202 * trying to zero 16 bytes when length is less than 16.
203 */
204 cmp length, block_size
205 b.lo .Lzeromem_dczva_fallback_entry
206
207 /*
208 * Calculate the bitmask of the block alignment. It will never
209 * underflow as the block size is between 4 bytes and 2kB.
210 * block_mask = block_size - 1
211 */
212 sub block_mask, block_size, #1
213
214 /*
215 * length alias should not be used after this point unless it is
216 * defined as a register other than block_mask's.
217 */
218 .unreq length
219
220 /*
221 * If the start address is already aligned to zero block size, go
222 * straight to the cache zeroing loop. This is safe because at this
223 * point, the length cannot be smaller than a block size.
224 */
225 tst cursor, block_mask
226 b.eq .Lzeromem_dczva_blocksize_aligned
227
228 /*
229 * Calculate the first block-size-aligned address. It is assumed that
230 * the zero block size is at least 16 bytes. This address is the last
231 * address of this initial loop.
232 */
233 orr tmp1, cursor, block_mask
234 add tmp1, tmp1, #1
235
236 /*
237 * If the addition overflows, skip the cache zeroing loops. This is
238 * quite unlikely however.
239 */
240 cbz tmp1, .Lzeromem_dczva_fallback_entry
241
242 /*
243 * If the first block-size-aligned address is past the last address,
244 * fallback to the simpler code.
245 */
246 cmp tmp1, stop_address
247 b.hi .Lzeromem_dczva_fallback_entry
248
249 /*
250 * If the start address is already aligned to 16 bytes, skip this loop.
251 * It is safe to do this because tmp1 (the stop address of the initial
252 * 16 bytes loop) will never be greater than the final stop address.
253 */
254 tst cursor, #0xf
255 b.eq .Lzeromem_dczva_initial_1byte_aligned_end
256
257 /* Calculate the next address aligned to 16 bytes */
258 orr tmp2, cursor, #0xf
259 add tmp2, tmp2, #1
260 /* If it overflows, fallback to the simple path (unlikely) */
261 cbz tmp2, .Lzeromem_dczva_fallback_entry
262 /*
263 * Next aligned address cannot be after the stop address because the
264 * length cannot be smaller than 16 at this point.
265 */
266
267 /* First loop: zero byte per byte */
2681:
269 strb wzr, [cursor], #1
270 cmp cursor, tmp2
271 b.ne 1b
272.Lzeromem_dczva_initial_1byte_aligned_end:
273
274 /*
275 * Second loop: we need to zero 16 bytes at a time from cursor to tmp1
276 * before being able to use the code that deals with block-size-aligned
277 * addresses.
278 */
279 cmp cursor, tmp1
280 b.hs 2f
2811:
282 stp xzr, xzr, [cursor], #16
283 cmp cursor, tmp1
284 b.lo 1b
2852:
286
287 /*
288 * Third loop: zero a block at a time using DC ZVA cache block zeroing
289 * instruction.
290 */
291.Lzeromem_dczva_blocksize_aligned:
292 /*
293 * Calculate the last block-size-aligned address. If the result equals
294 * to the start address, the loop will exit immediately.
295 */
296 bic tmp1, stop_address, block_mask
297
298 cmp cursor, tmp1
299 b.hs 2f
3001:
301 /* Zero the block containing the cursor */
302 dc zva, cursor
303 /* Increment the cursor by the size of a block */
304 add cursor, cursor, block_size
305 cmp cursor, tmp1
306 b.lo 1b
3072:
308
309 /*
310 * Fourth loop: zero 16 bytes at a time and then byte per byte the
311 * remaining area
312 */
313.Lzeromem_dczva_final_16bytes_aligned:
314 /*
315 * Calculate the last 16 bytes aligned address. It is assumed that the
316 * block size will never be smaller than 16 bytes so that the current
317 * cursor is aligned to at least 16 bytes boundary.
318 */
319 bic tmp1, stop_address, #15
320
321 cmp cursor, tmp1
322 b.hs 2f
3231:
324 stp xzr, xzr, [cursor], #16
325 cmp cursor, tmp1
326 b.lo 1b
3272:
328
329 /* Fifth and final loop: zero byte per byte */
330.Lzeromem_dczva_final_1byte_aligned:
331 cmp cursor, stop_address
332 b.eq 2f
3331:
334 strb wzr, [cursor], #1
335 cmp cursor, stop_address
336 b.ne 1b
3372:
Kévin Petita877c252015-03-24 14:03:57 +0000338 ret
Douglas Raillard21362a92016-12-02 13:51:54 +0000339
340 /* Fallback for unaligned start addresses */
341.Lzeromem_dczva_fallback_entry:
342 /*
343 * If the start address is already aligned to 16 bytes, skip this loop.
344 */
345 tst cursor, #0xf
346 b.eq .Lzeromem_dczva_final_16bytes_aligned
347
348 /* Calculate the next address aligned to 16 bytes */
349 orr tmp1, cursor, #15
350 add tmp1, tmp1, #1
351 /* If it overflows, fallback to byte per byte zeroing */
352 cbz tmp1, .Lzeromem_dczva_final_1byte_aligned
353 /* If the next aligned address is after the stop address, fall back */
354 cmp tmp1, stop_address
355 b.hs .Lzeromem_dczva_final_1byte_aligned
356
357 /* Fallback entry loop: zero byte per byte */
3581:
359 strb wzr, [cursor], #1
360 cmp cursor, tmp1
361 b.ne 1b
362
363 b .Lzeromem_dczva_final_16bytes_aligned
Sandrine Bailleux65f546a2013-11-28 09:43:06 +0000364
Douglas Raillard21362a92016-12-02 13:51:54 +0000365 .unreq cursor
366 /*
367 * length is already unreq'ed to reuse the register for another
368 * variable.
369 */
370 .unreq stop_address
371 .unreq block_size
372 .unreq block_mask
373 .unreq tmp1
374 .unreq tmp2
375endfunc zeromem_dczva
Sandrine Bailleux65f546a2013-11-28 09:43:06 +0000376
377/* --------------------------------------------------------------------------
378 * void memcpy16(void *dest, const void *src, unsigned int length)
379 *
380 * Copy length bytes from memory area src to memory area dest.
381 * The memory areas should not overlap.
382 * Destination and source addresses must be 16-byte aligned.
383 * --------------------------------------------------------------------------
384 */
Andrew Thoelke38bde412014-03-18 13:46:55 +0000385func memcpy16
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100386#if ENABLE_ASSERTIONS
Soby Mathew041f62a2014-07-14 16:58:03 +0100387 orr x3, x0, x1
388 tst x3, #0xf
389 ASM_ASSERT(eq)
390#endif
Sandrine Bailleux65f546a2013-11-28 09:43:06 +0000391/* copy 16 bytes at a time */
392m_loop16:
393 cmp x2, #16
Douglas Raillard861be8e2016-12-02 13:56:06 +0000394 b.lo m_loop1
Sandrine Bailleux65f546a2013-11-28 09:43:06 +0000395 ldp x3, x4, [x1], #16
396 stp x3, x4, [x0], #16
397 sub x2, x2, #16
398 b m_loop16
399/* copy byte per byte */
400m_loop1:
401 cbz x2, m_end
402 ldrb w3, [x1], #1
403 strb w3, [x0], #1
404 subs x2, x2, #1
405 b.ne m_loop1
Kévin Petita877c252015-03-24 14:03:57 +0000406m_end:
407 ret
408endfunc memcpy16
Andrew Thoelke438c63a2014-04-28 12:06:18 +0100409
410/* ---------------------------------------------------------------------------
411 * Disable the MMU at EL3
Andrew Thoelke438c63a2014-04-28 12:06:18 +0100412 * ---------------------------------------------------------------------------
413 */
414
415func disable_mmu_el3
416 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT)
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +0100417do_disable_mmu_el3:
Andrew Thoelke438c63a2014-04-28 12:06:18 +0100418 mrs x0, sctlr_el3
419 bic x0, x0, x1
420 msr sctlr_el3, x0
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +0100421 isb /* ensure MMU is off */
Achin Guptae9c4a642015-09-11 16:03:13 +0100422 dsb sy
423 ret
Kévin Petita877c252015-03-24 14:03:57 +0000424endfunc disable_mmu_el3
Andrew Thoelke438c63a2014-04-28 12:06:18 +0100425
426
427func disable_mmu_icache_el3
428 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT)
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +0100429 b do_disable_mmu_el3
Kévin Petita877c252015-03-24 14:03:57 +0000430endfunc disable_mmu_icache_el3
Andrew Thoelke438c63a2014-04-28 12:06:18 +0100431
Andrew Thoelke3f78dc32014-06-02 15:44:43 +0100432/* ---------------------------------------------------------------------------
Antonio Nino Diaz4613d5f2017-10-05 15:19:42 +0100433 * Disable the MMU at EL1
434 * ---------------------------------------------------------------------------
435 */
436
437func disable_mmu_el1
438 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT)
439do_disable_mmu_el1:
440 mrs x0, sctlr_el1
441 bic x0, x0, x1
442 msr sctlr_el1, x0
443 isb /* ensure MMU is off */
444 dsb sy
445 ret
446endfunc disable_mmu_el1
447
448
449func disable_mmu_icache_el1
450 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT)
451 b do_disable_mmu_el1
452endfunc disable_mmu_icache_el1
453
454/* ---------------------------------------------------------------------------
Soby Mathew4e28c202018-10-14 08:09:22 +0100455 * Helper to fixup Global Descriptor table (GDT) and dynamic relocations
456 * (.rela.dyn) at runtime.
457 *
458 * This function is meant to be used when the firmware is compiled with -fpie
459 * and linked with -pie options. We rely on the linker script exporting
460 * appropriate markers for start and end of the section. For GOT, we
461 * expect __GOT_START__ and __GOT_END__. Similarly for .rela.dyn, we expect
462 * __RELA_START__ and __RELA_END__.
463 *
464 * The function takes the limits of the memory to apply fixups to as
465 * arguments (which is usually the limits of the relocable BL image).
466 * x0 - the start of the fixup region
467 * x1 - the limit of the fixup region
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000468 * These addresses have to be 4KB page aligned.
Soby Mathew4e28c202018-10-14 08:09:22 +0100469 * ---------------------------------------------------------------------------
470 */
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000471
472/* Relocation codes */
473#define R_AARCH64_NONE 0
474#define R_AARCH64_RELATIVE 1027
475
Soby Mathew4e28c202018-10-14 08:09:22 +0100476func fixup_gdt_reloc
477 mov x6, x0
478 mov x7, x1
479
Soby Mathew4e28c202018-10-14 08:09:22 +0100480#if ENABLE_ASSERTIONS
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000481 /* Test if the limits are 4KB aligned */
Soby Mathew4e28c202018-10-14 08:09:22 +0100482 orr x0, x0, x1
Jimmy Brissoned202072020-08-04 16:18:52 -0500483 tst x0, #(PAGE_SIZE_MASK)
Soby Mathew4e28c202018-10-14 08:09:22 +0100484 ASM_ASSERT(eq)
485#endif
486 /*
487 * Calculate the offset based on return address in x30.
Louis Mayencourt462ec472019-03-01 14:36:46 +0000488 * Assume that this function is called within a page at the start of
489 * fixup region.
Soby Mathew4e28c202018-10-14 08:09:22 +0100490 */
Jimmy Brissoned202072020-08-04 16:18:52 -0500491 and x2, x30, #~(PAGE_SIZE_MASK)
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000492 subs x0, x2, x6 /* Diff(S) = Current Address - Compiled Address */
493 b.eq 3f /* Diff(S) = 0. No relocation needed */
Soby Mathew4e28c202018-10-14 08:09:22 +0100494
495 adrp x1, __GOT_START__
496 add x1, x1, :lo12:__GOT_START__
497 adrp x2, __GOT_END__
498 add x2, x2, :lo12:__GOT_END__
499
500 /*
501 * GOT is an array of 64_bit addresses which must be fixed up as
502 * new_addr = old_addr + Diff(S).
503 * The new_addr is the address currently the binary is executing from
504 * and old_addr is the address at compile time.
505 */
Alexei Fedorovc69b7a92020-12-25 10:52:56 +00005061: ldr x3, [x1]
507
Soby Mathew4e28c202018-10-14 08:09:22 +0100508 /* Skip adding offset if address is < lower limit */
509 cmp x3, x6
510 b.lo 2f
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000511
Yann Gautier8c25dc72021-10-27 17:16:09 +0200512 /* Skip adding offset if address is > upper limit */
Soby Mathew4e28c202018-10-14 08:09:22 +0100513 cmp x3, x7
Yann Gautier8c25dc72021-10-27 17:16:09 +0200514 b.hi 2f
Soby Mathew4e28c202018-10-14 08:09:22 +0100515 add x3, x3, x0
516 str x3, [x1]
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000517
5182: add x1, x1, #8
Soby Mathew4e28c202018-10-14 08:09:22 +0100519 cmp x1, x2
520 b.lo 1b
521
522 /* Starting dynamic relocations. Use adrp/adr to get RELA_START and END */
Alexei Fedorovc69b7a92020-12-25 10:52:56 +00005233: adrp x1, __RELA_START__
Soby Mathew4e28c202018-10-14 08:09:22 +0100524 add x1, x1, :lo12:__RELA_START__
525 adrp x2, __RELA_END__
526 add x2, x2, :lo12:__RELA_END__
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000527
Soby Mathew4e28c202018-10-14 08:09:22 +0100528 /*
529 * According to ELF-64 specification, the RELA data structure is as
530 * follows:
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000531 * typedef struct {
Soby Mathew4e28c202018-10-14 08:09:22 +0100532 * Elf64_Addr r_offset;
533 * Elf64_Xword r_info;
534 * Elf64_Sxword r_addend;
535 * } Elf64_Rela;
536 *
537 * r_offset is address of reference
538 * r_info is symbol index and type of relocation (in this case
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000539 * code 1027 which corresponds to R_AARCH64_RELATIVE).
Soby Mathew4e28c202018-10-14 08:09:22 +0100540 * r_addend is constant part of expression.
541 *
542 * Size of Elf64_Rela structure is 24 bytes.
543 */
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000544
545 /* Skip R_AARCH64_NONE entry with code 0 */
5461: ldr x3, [x1, #8]
547 cbz x3, 2f
548
Soby Mathew4e28c202018-10-14 08:09:22 +0100549#if ENABLE_ASSERTIONS
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000550 /* Assert that the relocation type is R_AARCH64_RELATIVE */
551 cmp x3, #R_AARCH64_RELATIVE
Soby Mathew4e28c202018-10-14 08:09:22 +0100552 ASM_ASSERT(eq)
553#endif
554 ldr x3, [x1] /* r_offset */
555 add x3, x0, x3
556 ldr x4, [x1, #16] /* r_addend */
557
558 /* Skip adding offset if r_addend is < lower limit */
559 cmp x4, x6
560 b.lo 2f
Alexei Fedorovc69b7a92020-12-25 10:52:56 +0000561
Yann Gautier8c25dc72021-10-27 17:16:09 +0200562 /* Skip adding offset if r_addend entry is > upper limit */
Soby Mathew4e28c202018-10-14 08:09:22 +0100563 cmp x4, x7
Yann Gautier8c25dc72021-10-27 17:16:09 +0200564 b.hi 2f
Soby Mathew4e28c202018-10-14 08:09:22 +0100565
566 add x4, x0, x4 /* Diff(S) + r_addend */
567 str x4, [x3]
568
5692: add x1, x1, #24
570 cmp x1, x2
571 b.lo 1b
Soby Mathew4e28c202018-10-14 08:09:22 +0100572 ret
573endfunc fixup_gdt_reloc