[snip]
I hate parse_r helper also, it is hard to understand, the kernel about
LoongArch has the same issue. How about using a fixed register like this?
/* GCSR */
static __always_inline u64 gcsr_read(u32 reg)
{
u64 val = 0;
BUILD_BUG_ON(!__builtin_constant_p(reg));
/* Instructions will be available in binutils later */
asm volatile (
"parse_r __reg, %[val]\n\t"
/*
* read val from guest csr register %[reg]
* gcsrrd %[val], %[reg]
*/
".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | __reg\n\t"
: [val] "+r" (val)
: [reg] "i" (reg)
: "memory");
return val;
}
/* GCSR */
static __always_inline u64 gcsr_read(u32 reg)
{
register unsigned long val asm("t0");
BUILD_BUG_ON(!__builtin_constant_p(reg));
/* Instructions will be available in binutils later */
asm volatile (
"parse_r __reg, %[val]\n\t"
/*
* read val from guest csr register %[reg]
* gcsrrd %[val], %[reg]
*/
".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | 12 \n\t"
: : [reg] "i" (reg)
: "memory", "t0");
return val;
}