ARM架构中如何读取协处理器寄存器 [英] How read coprocessor registers in ARM architecture

查看:40
本文介绍了ARM架构中如何读取协处理器寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取以下片上系统中的 CP15 协处理器

I'm trying to read CP15 coprocessor in the following System-on-chip

Cortex A7 - ARMv7-A

Cortex A7 - ARMv7-A

在我的片段下方

void main (void)
{
    unsigned int reg_value = 0;
    asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r"(reg_value) );
    printf("reg_value: %d", reg_value);
}

我不知道这是否是读取协处理器寄存器的正确方法,但它的编译完成没有错误.问题是在其执行过程中出现的(代码在root中执行):

I don't know if this is the correct way to read the coprocessor register but its compilation is completed without errors. The problem is arisen during its execution (the code is executed in root):

Illegal instruction

如果我使用 gdb,我会得到以下结果:

If I use gdb I obtain the following result:

   0x000086a0 <+16>:    str r3, [r11, #-40] ; 0x28
=> 0x000086a4 <+20>:    mrc 15, 0, r3, cr0, cr0, {0}
   0x000086a8 <+24>:    str r3, [r11, #-40] ; 0x28

为什么我无法读取协处理器寄存器?我的代码有什么问题?

Why I'm not able to read coprocessor registers? What's wrong with my code?

推荐答案

您似乎正在尝试使用指令访问 MIDR: Main ID Register (from ARMARMv7 B4.1.105)

It seems that you are trying to access MIDR: Main ID Register (from the ARMARMv7 B4.1.105) using the instruction

MRC p15, 0, <Rt>, c0, c0, 0    ; Read MIDR into Rt

但是,当您在 Linux 中执行应用程序时,您处于用户模式 ​​(PL0)和 ARMARMv7 在 MIDR 的使用限制中指定

However, as you are in Linux and executing an application, you are in usermode (PL0) and ARMARMv7 specifies in the usage constraints of MIDR that

只能从 PL1 或更高版本访问.

Only accessible from PL1 or higher.

所以只能在 PL1、PL2、PL3 访问.要访问它,您需要创建一个在 PL1 上运行的驱动程序,它将读取 MIDR.然后,在您的应用程序中,打开此驱动程序以使用 IOCTL 获取数据.

So only accessible at PL1, PL2, PL3. To access it you need to create a driver running at PL1 which will do the read of MIDR. Then, in your application, open this driver to get the data using IOCTL for example.

您也可以尝试使用来自 PL0 的 SVC 调用访问内核模式 (PL1),但这意味着修改您的内核 SVC 处理程序.

You can also try to access the kernel mode (PL1) using a SVC call from PL0, but this would imply modifying your kernel SVC handler.

这篇关于ARM架构中如何读取协处理器寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆