c - GCC inline assembly constants (ARM) -


is there way give constants inline assembly code "parameters"? i'm trying make co-processor access functions. tried 2 approaches: macro-replacement , extensions.

the use this:

unsigned int read_id_pfr1() {     read_cp15(0, 0, 1, 1);     return cp_reg_val; } 

the macro approach:

#define read_cp15(opc, crn, crm, opc2) \ asm volatile (\     "push {r0, r1}\n\t"\     "mrc p15, opc, r0, crn, crm, opc2\n\t"\     "ldr r1, =cp_reg_val\n\t"\     "str r0, [r1]\n\t"\     "pop {r0, r1}\n\t"\     ) 

i think parameters (opc, crn, ...) not expanded because used within quotation marks.

the extension approach looks this:

#define write_cp15(opc, crn, crm, opc2) \     asm volatile (\         "push {r0, r1}\n\t"\         "ldr r1, =cp_reg_val\n\t"\         "ldr r0, [r1]\n\t"\         "mcr p15, %[op], r0, c%[rn], c%[rm], %[op2]\n\t"\         "pop {r0, r1}\n\t"\         ::[op]"i"(opc), [rn]"i"(crn), [rm]"i"(crm), [op2]"i"(opc2):\     ) 

this seems better except '#'-marks. (c%[rn] expands c#0)

do not put push/pop in inline asm. not mean you're writing more junk in asm should have to; precludes using "m" type input/output constraints since effective addresses stack-pointer-relative. instead use like:

asm volatile ("mrc p15, opc, %0, crn, crm, opc2" : "=r"(cp_reg_val)); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -