We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am trying to migrate my source code compilation from armcc compiler v5.06 to armclang v6. And I see armclang errors out saying it can not recognize cp15 registers. It looks like there might be a change in armcc vs clang as how to declare the registers. However, I could not find anything on the migration docs or in compiler doc.
Here is the code snippet -
void reset_clock_count(void) { register uint32_t reg_cp15_pmcr __asm("cp15:0:c9:c12:0"); reg_cp15_pmcr |= RESET_CYCLE_COUNTER; }
And error snippet -
error: unknown register name 'cp15:0:c9:c12:0' in asm register uint32_t reg_cp15_pmcr __asm("cp15:0:c9:c12:0"); ^
I see same errors for other places for similarly declared register. Any pointer on what might have gone wrong will be helpful.
Hi Anupam,
I worry that this code may not be easily portable in the current form.
The register definition as you do above is only for r6-r11:
https://developer.arm.com/documentation/101754/0615/armclang-Reference/Compiler-specific-Keywords-and-Operators/Global-named-register-variables
I assume you have Arm Development Studio? I recommend you look at the PMU_AArch64 example, which includes a range of functions (in pmu.c) to implement the above and similar operations (via macros of explicit instructions from pmu_macros.h).
(If you don't have Development Studio, a 30-day evaluation is available)developer.arm.com/.../arm-development-studio
Hi Ronan,
I am using Cortex A5 and I do not use dev studio. However, I could not find such examples in ARM docs.
I saw some example in linux repo : https://github.com/torvalds/linux/blob/8808cf8cbc4da1ceef9307fba7e499563908c211/arch/arm/kernel/perf_event_v7.c
The way it is being accessed is
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value));
I had tried this way but no luck -
reg_cp15_pmcr __asm("mcr cp15, 0, c9, c12, 0"); // experiment 1
reg_cp15_pmcr __asm("mcr cp15:0:c9:c12:0"); // experiment 2
All I see here in programmer's guide - https://www.macs.hw.ac.uk/~hwloidl/Courses/F28HS/Docu/DEN0013D_cortex_a_series_PG.pdf
There is no example for calling from c for clang.
I see cp15 is accessed as p15 in the doc.
For clang:
https://godbolt.org/z/YWsTe4
Thanks for the explanation and snippet. This is what I was looking for.