Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

gcc - What does the instruction mrc p15 do in ARM inline assembly?

What does this line in ARM assembly do?

mrc p15, 0, %0, c9, c13, 0" : : "r" (counter)

What is p15? Usually registers are prefixed with r such as in r15.

What is the symbol :: and what are the roles or c9, c1?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Whilst MRC is a generic co-processor inter-op instruction, cp15 is the control processor - which all modern ARM CPUs have and this has been used by ARM was a means of extending the instruction set for on-chip units such as the cache, MMU, performance monitoring and lots else besides.

Taking your instruction a bit at a time:

mrc p15, 0, %0, c9, c13, 0" : : "r" (counter)

According to the ARM Cortex A7 MPCore Reference the instruction format is:

MRC{cond} P15, <Opcode_1>, <Rd>, <CRn>, <CRm>, <Opcode_2>

And on Page 4-11 this is described as a transfer of a CPU register to the performance monitor count register (I guess count=0 and this is a reset of the performance counter).

As for the syntax of inline assembler. refer to this for a x86 overview - which is probably similar to ARM.

The : : "r" (counter) means that the instruction has:

  • No output in a register that needs to end up in a local variable
  • Takes input from variable counter, and the register this is in should be used as %0.
  • There are no side effects the compiler ought to be aware of (clobbers)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...