I'm trying to write the following code :
#define CONFIG_PMP_SLOTS 16
#define PMPCFG_STRIDE 4
#define CSR_PMPCFG_BASE 0x3a0
void csr_pmp_check(){
for(int i = 0; i < (CONFIG_PMP_SLOTS / PMPCFG_STRIDE); i++)
{
int pmp_cfg;
__asm__ volatile("csrrs %0, %1, x0"
: "=r" (pmp_cfg) // output operand
: "r" (CSR_PMPCFG_BASE + PMPCFG_STRIDE * i ) // input operand
);
}
}
But when i try to compile I get the following error :
test.c: Assembler messages:
test.c:9: Error: unknown CSR `a5'
I tried to replace :
: "r" (CSR_PMPCFG_BASE + PMPCFG_STRIDE * i ) // input operand
By :
: "i" (CSR_PMPCFG_BASE + PMPCFG_STRIDE * i ) // input operand
But if i do so i got an error telling me warning: 'asm' operand 1 probably does not match constraints
.
Btw i compile like this :
riscv32-unknown-elf-gcc -nostdlib test.c