分析代码
/* EL2 debug */
mrs x1, id_aa64dfr0_el1
sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4
cmp x0, #1
b.lt 4f // Skip if no PMU present
mrs x0, pmcr_el0 // Disable debug access traps
ubfx x0, x0, #11, #5 // to EL2 and allow access to
4:
csel x3, xzr, x0, lt // all PMU counters from EL1
/* Statistical profiling */
ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4
cbz x0, 7f // Skip if SPE not present
cbnz x2, 6f // VHE?
mrs_s x4, SYS_PMBIDR_EL1 // If SPE available at EL2,
and x4, x4, #(1 << SYS_PMBIDR_EL1_P_SHIFT)
cbnz x4, 5f // then permit sampling of physical
mov x4, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \
1 << SYS_PMSCR_EL2_PA_SHIFT)
msr_s SYS_PMSCR_EL2, x4 // addresses and physical counter
5:
mov x1, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)
orr x3, x3, x1 // If we don't have VHE, then
b 7f // use EL1&0 translation.
6: // For VHE, use EL2 translation
orr x3, x3, #MDCR_EL2_TPMS // and disable access from EL1
7:
msr mdcr_el2, x3 // Configure debug traps
分析完毕 ID 的解析部分,我们继续分析调试寄存器的解析
第1行的注释开门见山地解释该段代码与异常等级EL1的调试相关。
id_aa64dfr0_el1
第2行涉及的寄存器 id_aa64dfr0_el1 的含义如下:
ID_AA64DFR0_EL1, AArch64 Debug Feature Register 0
Provides top level information about the debug system in AArch64 state.
该寄存器提供了arm64体系结构EL1异常等级下的调试信息
所以该行代码读取该寄存器的内容并存放到x1寄存器里
第3行代码涉及到如下宏定义
#define ID_AA64DFR0_PMUVER_SHIFT 8
而 sbfx 指令是 ARM64 架构中的一个位字段提取(Signed Bitfield Extract)指令
用于从源寄存器中提取一个指定长度和偏移的位字段,并将该位字段的值(符号扩展后)存入目标寄存器。
所以,该指令的含义是将 id_aa64dfr0_el1 的 位域bits[11:8]经过符号扩展存放到 x0 寄存器中
查找寄存器手册,bits[11:8]的含义如下:
PMUVer, bits [11:8]
Performance Monitors Extension version.
This field does not follow the standard ID scheme,
but uses the Alternative ID scheme described in Alternative ID scheme used for the Performance Monitors Extension version on page D12-2682.
Defined values are:
0b'0000 Performance Monitors Extension not implemented.
0b'0001 Performance Monitors Extension implemented, PMUv3.
0b'0100 PMUv3 for ARMv8.1. As 0b0001, and also includes support for:
•Extended 16-bit PMEVTYPER<n>_EL0.evtCount field.
•If EL2 is implemented, the MDCR_EL2.HPMD control bit.
0b'0101 PMUv3 for ARMv8.4. As 0b0100 and also includes support for the PMMIR_EL1 register.
0b'1111 IMPLEMENTATION DEFINED form of performance monitors supported, PMUv3 not supported. Arm does not recommend this value in new implementations.
第4行的含义是上述位域bits[11:8]与立即数1进行比较,如果位域bits[11:8]的值小于1, 我的理解就是位域的值为 0b'0000 或者 0b'1111 的时候,表示不支持 PMU,直接跳转到第8行
根据位域bits[11:8]的表述,0b'0000 表示 在该体系架构中,PMU没有实现;
0b'1111 则表示该ARM64实现支持一种由具体实现定义的性能监视器形式。不同的ARM处理器实现(如不同的核心型号、不同的制造商等)可能会有不同的性能监视器实现。这些实现可能不完全遵循ARM架构规范中定义的通用性能监视器接口(如PMUv3),而是采用了特定的、自定义的设计。
由于有两个值表示系统没有使用标准PMU,所以位提取指令采用sbfx而不是ubfx。
PMCR_EL0
第6行涉及到寄存器 pmcr_el0, 该寄存器的含义如下:
PMCR_EL0, Performance Monitors Control Register
Provides details of the Performance Monitors implementation, including the number of counters implemented, and configures and controls the counters.
在ARM64架构中,PMCR_EL0寄存器是性能监视控制寄存器(Performance Monitors Control Register)的一部分,
它位于EL0(非特权模式)级别。这个寄存器用于控制性能监视单元(Performance Monitor Unit, PMU)的行为,
允许在软件层面开启或关闭性能监视功能,以及配置其他与性能监视相关的参数。
PMCR_EL0寄存器的功能主要包括:
控制性能监视的启用和禁用:通过修改PMCR_EL0寄存器中的相应位,可以启用或禁用性能监视功能。这对于控制性能监视对系统性能的影响以及管理监视数据的收集至关重要;
配置性能监视事件:虽然PMCR_EL0寄存器本身可能不直接配置监视事件,但它可能与其他性能监视相关的寄存器一起工作,以控制哪些事件被监视以及监视的方式;
监视状态控制:PMCR_EL0寄存器还可能包含控制监视状态(如复位监视器、清除溢出标志等)的位;
第7行的含义是提取该寄存器的位域bits[15:11], 并存放在x0寄存器里,该位域的含义如下:
N, bits [15:11]
An RO field that indicates the number of event counters implemented. This value is in the range of 0b00000-0b111111.
If the value is 0b00000 then only PMCCNTR_EL0 is implemented.
If the value is 0b111111 PMCCNTR_EL0 and 31 event counters are implemented.
When EL2 is implemented and enabled for the current Security state, reads of this field from EL1 and EL0 return the value of MDCR_EL2.HPMN.
详细解释如下:
性能监控控制寄存器(PMCR_EL0)的位域 N(位于位 [15:11])用于指示处理器实现的事件计数器数量。以下是该位域的详细解释:
位域 N [15:11] 的含义
功能:只读字段

最低0.47元/天 解锁文章
3514

被折叠的 条评论
为什么被折叠?



