Question about accessing coprocesser register in prologue

Hi llvm-dev

I’m very new to llvm and was fiddling around with prologue injection part.
The function that I tried to modify is ARMFrameLowering::adjustForSegmentedStacks()
What I wanted to do was to get some value from TLS so needed to access ARM coprocessor register to get TLS address.

The assembly that I want to add into prologue is something like this

mrc p15, 0, r0, c13, c0, 3

add r0, r0, #253

str r0, [r1, #0]

I tried it using BuildMI() but couldn’t find a register symbol which is matched with the cp-register on the register table(ARMGenRegisterInfo.inc).

How can I add the assembly into prologue?
Any help getting this solved out would be appreciated.

201301101351858_QKNMBDIF.gif

Hi,

The assembly that I want to add into prologue is something like this

mrc p15, 0, r0, c13, c0, 3

I tried it using BuildMI() but couldn't find a register symbol which is
matched with the cp-register on the register table(ARMGenRegisterInfo.inc).

If you look at MRC's definition in ARMInstrInfo.td, most of the
operands are just immediates rather than registers as far as LLVM is
concerned.

Also, assembling an instruction gives:
$ echo "mrc p15, 0, r0, c13, c0, 3" | llvm-mc -arch=arm -show-inst
        mrc p15, #0, r0, c13, c0, #3 @ <MCInst #247 MRC
                                        @ <MCOperand Reg:60>
                                        @ <MCOperand Imm:15>
                                        @ <MCOperand Imm:0>
                                        @ <MCOperand Imm:13>
                                        @ <MCOperand Imm:0>
                                        @ <MCOperand Imm:3>
                                        @ <MCOperand Imm:14>
                                        @ <MCOperand Reg:0>>

The last two operands are the usual predication every ARM instruction
gets, so this confirms that your BuildMI should be:

AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::MRC), ARM::R0)
               .addImm(15).addImm(0).addImm(13).addImm(0).addImm(3));

Remember that r0 might be in use for a function argument though!

Hope this helps.

Tim.