简体   繁体   English

QEMU是否模拟ARM协处理器

[英]Does QEMU emulate ARM coprocessor

I need to implement a kernel module that involves reading the ARM Cortex-A9 coprocessor's register: 我需要实现一个内核模块,其中涉及读取ARM Cortex-A9协处理器的寄存器:

register int reg asm ("r6");
reg = -2;
volatile printk(KERN_INFO "reg: %d\n", reg);
volatile  asm("MRC p15, 0,r6, c1, c0, 2;"); //Read Coprocessor Access Control Register
volatile  printk(KERN_INFO "reg: %d\n", reg);

However, when i run this on QEMU, it always print out: 但是,当我在QEMU上运行它时,它总是打印出来:

reg: -2
reg: -2

Is this because of my code or is it because of QEMU? 是因为我的代码还是因为QEMU?

Thanks in advance. 提前致谢。

Your code should work fine (though you need to remove volatile from printk lines, and ASM command should be asm volatile , not the other way around). 您的代码应该可以正常工作(尽管您需要从printk行中删除volatile ,而ASM命令应该是asm volatile ,而不是相反)。 Try to check next things: 尝试检查以下内容:

  1. QEMU version. QEMU版本。 I'm using 2.12 and your code works. 我正在使用2.12,并且您的代码有效。 So if you're using older version, try 2.12 too. 因此,如果您使用的是旧版本,也请尝试2.12。
  2. Emulated machine and cpu. 模拟机和CPU。 Not sure if it affects CP registers, but I'm using "virt" machine with no CPU specified, you can try this configuration too. 不知道它是否影响CP寄存器,但我使用的是未指定CPU的“虚拟”计算机,您也可以尝试这种配置。
  3. If this doesn't help, check more details about my configuration below. 如果这样做没有帮助,请在下面查看有关我的配置的更多详细信息。

My configuration 我的配置

I'm using next command to run QEMU: 我正在使用下一个命令来运行QEMU:

$ qemu-system-arm -kernel $zimage -initrd $rootfs \
    -machine virt -nographic -m 512 \
    --append "root=/dev/ram0 rw console=ttyAMA0,115200 mem=512M"

where: 哪里:

  • $zimage is path to zImage file (my kernel is linux-mainline on tag v4.18 , built with multi_v7_defconfig configuration) $zimagezImage文件的路径(我的内核是标记为v4.18 linux-mainline,使用multi_v7_defconfig配置构建)
  • $rootfs is path to CPIO archive with minimal BusyBox rootfs $rootfs是使用最少BusyBox rootfs的CPIO存档的路径

My kernel module code is next: 接下来是我的内核模块代码:

#include <linux/module.h>

static int __init mrc_init(void)
{
    u32 acr;

    /*
     * Read Coprocessor Access Control Register.
     * See Cortex-A9 TRM for details.
     */
    asm volatile ("mrc p15, 0, %0, c1, c0, 2\n" : "=r" (acr));

    pr_info("ACR = 0x%x\n", acr);

    return 0;
}

static void __exit mrc_exit(void)
{
}

module_init(mrc_init);
module_exit(mrc_exit);

MODULE_AUTHOR("Sam Protsenko");
MODULE_DESCRIPTION("Test MRC on QEMU");
MODULE_LICENSE("GPL");

After loading this module I can see next output in dmesg : 加载此模块后,我可以在dmesg看到下一个输出:

ACR = 0xf00000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM