How to read coprocessor registers in ARM architecture

I am trying to read the CP15 coprocessor in the following System on a chip

Cortex A7 - ARMv7-A

Below my snippet

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);
}

I do not know if this is the correct way to read the coprocessor register, but its compilation completed without errors. The problem occurs during its execution (the code is executed in the root directory):

Illegal instruction

If I use gdb, I get 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 can't I read the coprocessor registers? What is wrong with my code?

+5
source share
2 answers

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

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

, Linux , (PL0), ARMARMv7 MIDR,

PL1 .

PL1, PL2, PL3. , PL1, MIDR. , , , IOCTL.

(PL1) SVC PL0, SVC.

+2

Source: https://habr.com/ru/post/1694295/


All Articles