what does this line in assembly arm does?
mrc p15, 0, %0, c9, c13, 0\" : : \"r\" (counter)
who is p15
isn\'t it should be
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:
counter
, and the register this is in should be used as %0
. The coprocessors in the arm are more obvious/visible perhaps than other processors. Nevertheless this is a coprocessor access function, the coprocessor interface is generic these instructions are generic as if you are just filling in items on a generic bus. Now arm does re-use things in that a coprocessor register in one core if present in another is more likely than not to be related or the same. The right answer is to go to the arm website (infocenter.arm.com) and find both the arm arm (arm architectural reference manual) and trm (technical reference manual) for the family and core of processor you are using or looking at code for, in one or both manuals it will have a section on coprocessors and as you push into that section you will see the coprocessor number then register within that coprocessor and some of the numbers will make sense. ARM generally will say, to read this register here is the exact instruction, to write this register here is the exact instruction, and it will take the form as you have presented it. If you are looking to go backwards from code to what it does you will see that you can very quickly work your way into that section of the manual and quickly find the instruction then see what it does for that particular core or family. The other way around is to look at chapter and section titles finding the register of interest then the syntax for the instruction used to manipulate it.
As far as the : : double colons, I am guessing you took this from inline assembly and that is related to inline assembly, a compiler thing and is not related at all to the arm instruction, the arm instruction ends with the c13, 0.