#include <grub/i18n.h>
#include <grub/loongarch64/reloc.h>
+/*
+ * LoongArch relocations documentation:
+ * https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#relocations
+ */
static void grub_loongarch64_stack_push (grub_loongarch64_stack_t stack, grub_uint64_t x);
static grub_uint64_t grub_loongarch64_stack_pop (grub_loongarch64_stack_t stack);
*place =(*place) | ((a >> 18) & 0x3ff);
}
+/*
+ * B26 relocation for the 28-bit PC-relative jump
+ * (*(uint32_t *) PC) [9 ... 0] = (S + A - PC) [27 ... 18]
+ * (*(uint32_t *) PC) [25 ... 10] = (S + A - PC) [17 ... 2]
+ */
void grub_loongarch64_b26 (grub_uint32_t *place, grub_int64_t offset)
{
grub_uint32_t val;
*place |= grub_cpu_to_le32 (val) & ~insmask;
}
+/*
+ * ABS_HI20/PCALA_HI20 relocations for 32/64-bit absolute address/PC-relative offset
+ * (*(uint32_t *) PC) [24 ... 5] = (S + A) [31 ... 12]
+ */
void grub_loongarch64_xxx_hi20 (grub_uint32_t *place, grub_int64_t offset)
{
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfe00001f);
*place |= grub_cpu_to_le32 (val) & ~insmask;
}
+/*
+ * ABS_LO12/PCALA_LO12 relocations for 32/64-bit absolute address
+ * (*(uint32_t *) PC) [21 ... 10] = (S + A) [11 ... 0]
+ */
void grub_loongarch64_xxx_lo12 (grub_uint32_t *place, grub_int64_t offset)
{
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff);
*place |= grub_cpu_to_le32 (offset << 10) & ~insmask;
}
+/*
+ * ABS64_HI12 relocation for the 64-bit absolute address
+ * (*(uint32_t *) PC) [21 ... 10] = (S + A) [63 ... 52]
+ */
void grub_loongarch64_abs64_hi12 (grub_uint32_t *place, grub_int64_t offset)
{
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff);
*place |= grub_cpu_to_le32 (val) & ~insmask;
}
+/*
+ * ABS64_LO20 relocation for the 64-bit absolute address
+ * (*(uint32_t *) PC) [24 ... 5] = (S + A) [51 ... 32]
+ */
void grub_loongarch64_abs64_lo20 (grub_uint32_t *place, grub_int64_t offset)
{
const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfe00001f);