如何使用汇编将变量的地址加载到寄存器中? (arm64 linux内核代码)

问题描述 投票:0回答:0

一段时间后回到汇编代码..
我把这段代码放在 linux 内核启动后 (linux-5.15.68)。

.global mydebug2
....(skip)
SYM_CODE_START(primary_entry)
    mov x27, #0x3333
    ldr x28, mydebug2
    add x28, x28, #8
    str x27, [x28], #8
    ldr x26, =myptr
    str x28, [x26]
    b .

    bl  preserve_boot_args
    bl  init_kernel_el          // w0=cpu_boot_mode

缓冲区“mydebug2”在 init/main.c 中这样定义。

#include <test/mwtest.h>
uint64_t mydebug2[MWBUF_LENGTH] = {0,};
uint32_t myidx = 0;
uint64_t mycnt = 0; // for left shift, 64bit

asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
{
    char *command_line;
    char *after_dashes;

当我编译它时,我最后得到这个错误。

LD .tmp_vmlinux.kallsyms1 arch/arm64/kernel/head.o: 在函数中

primary_entry': /home/ckim/prj1/LinuxDevDrv/linux-5.15.68/arch/arm64/kernel/head.S:97:(.init.text+0x4): relocation truncated to fit: R_AARCH64_LD_PREL_LO19 against symbol 
mydebug2' 在 init/main.o 的 .bss 部分定义:*** [Makefile:1214: vmlinux] 错误 1

我猜 mydebug2 是虚拟地址(比如 0xffffffc008c4b028),

ldr x28, mydebug2
指令无法将该地址加载到 x28 中。如何将地址加载到 x28?

(顺便说一句,我知道在当前设置中,物理地址是如何映射到内核虚拟地址的。我看到 0xffffffc008000000 对应于物理内存 0x80200000)。

ADD:正如 Nate Eldredge 所建议的那样,我尝试使用 adrp 和 add 对,它在 arch/arm64/include/asm/assembler.h 中定义如下。

/*
 * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
 * <symbol> is within the range +/- 4 GB of the PC.
 */
    /*
     * @dst: destination register (64 bit wide)
     * @sym: name of the symbol
     */
    .macro  adr_l, dst, sym
    adrp    \dst, \sym
    add \dst, \dst, :lo12:\sym
    .endm
    .... more (skip) ...
linux assembly linux-kernel arm arm64
© www.soinside.com 2019 - 2024. All rights reserved.