요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===========================
ARM64 CPU Feature Registers
===========================
Author: Suzuki K Poulose <suzuki.poulose@arm.com>
This file describes the ABI for exporting the AArch64 CPU ID/feature
registers to userspace. The availability of this ABI is advertised
via the HWCAP_CPUID in HWCAPs.
1. Motivation
-------------
The ARM architecture defines a set of feature registers, which describe
the capabilities of the CPU/system. Access to these system registers is
restricted from EL0 and there is no reliable way for an application to
extract this information to make better decisions at runtime. There is
limited information available to the application via HWCAPs, however
there are some issues with their usage.
a) Any change to the HWCAPs requires an update to userspace (e.g libc)
to detect the new changes, which can take a long time to appear in
distributions. Exposing the registers allows applications to get the
information without requiring updates to the toolchains.
b) Access to HWCAPs is sometimes limited (e.g prior to libc, or
when ld is initialised at startup time).
c) HWCAPs cannot represent non-boolean information effectively. The
architecture defines a canonical format for representing features
in the ID registers; this is well defined and is capable of
representing all valid architecture variations.
2. Requirements
---------------
a) Safety:
Applications should be able to use the information provided by the
infrastructure to run safely across the system. This has greater
implications on a system with heterogeneous CPUs.
The infrastructure exports a value that is safe across all the
available CPU on the system.
e.g, If at least one CPU doesn't implement CRC32 instructions, while
others do, we should report that the CRC32 is not implemented.
Otherwise an application could crash when scheduled on the CPU
which doesn't support CRC32.
b) Security:
Applications should only be able to receive information that is
relevant to the normal operation in userspace. Hence, some of the
fields are masked out(i.e, made invisible) and their values are set to
indicate the feature is 'not supported'. See Section 4 for the list
of visible features. Also, the kernel may manipulate the fields
based on what it supports. e.g, If FP is not supported by the
kernel, the values could indicate that the FP is not available
(even when the CPU provides it).
c) Implementation Defined Features
The infrastructure doesn't expose any register which is
IMPLEMENTATION DEFINED as per ARMv8-A Architecture.
d) CPU Identification:
MIDR_EL1 is exposed to help identify the processor. On a
heterogeneous system, this could be racy (just like getcpu()). The
process could be migrated to another CPU by the time it uses the
register value, unless the CPU affinity is set. Hence, there is no
guarantee that the value reflects the processor that it is
currently executing on. REVIDR and AIDR are not exposed due to this
constraint, as these registers only make sense in conjunction with
the MIDR. Alternately, MIDR_EL1, REVIDR_EL1, and AIDR_EL1 are exposed
via sysfs at::
/sys/devices/system/cpu/cpu$ID/regs/identification/
\- midr_el1
\- revidr_el1
\- aidr_el1
3. Implementation
--------------------
The infrastructure is built on the emulation of the 'MRS' instruction.
Accessing a restricted system register from an application generates an
exception and ends up in SIGILL being delivered to the process.
The infrastructure hooks into the exception handler and emulates the
operation if the source belongs to the supported system register space.
The infrastructure emulates only the following system register space::
Op0=3, Op1=0, CRn=0, CRm=0,2,3,4,5,6,7
(See Table C5-6 'System instruction encodings for non-Debug System
register accesses' in ARMv8 ARM DDI 0487A.h, for the list of
registers).
The following rules are applied to the value returned by the
infrastructure:
a) The value of an 'IMPLEMENTATION DEFINED' field is set to 0.
b) The value of a reserved field is populated with the reserved
value as defined by the architecture.
c) The value of a 'visible' field holds the system wide safe value
for the particular feature (except for MIDR_EL1, see section 4).
d) All other fields (i.e, invisible fields) are set to indicate
the feature is missing (as defined by the architecture).
4. List of registers with visible features
-------------------------------------------
1) ID_AA64ISAR0_EL1 - Instruction Set Attribute Register 0
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| RNDR | [63-60] | y |
+------------------------------+---------+---------+
| TS | [55-52] | y |
+------------------------------+---------+---------+
| FHM | [51-48] | y |
+------------------------------+---------+---------+
| DP | [47-44] | y |
+------------------------------+---------+---------+
| SM4 | [43-40] | y |
+------------------------------+---------+---------+
| SM3 | [39-36] | y |
+------------------------------+---------+---------+
| SHA3 | [35-32] | y |
+------------------------------+---------+---------+
| RDM | [31-28] | y |
+------------------------------+---------+---------+
| ATOMICS | [23-20] | y |
+------------------------------+---------+---------+
| CRC32 | [19-16] | y |
+------------------------------+---------+---------+
| SHA2 | [15-12] | y |
+------------------------------+---------+---------+
| SHA1 | [11-8] | y |
+------------------------------+---------+---------+
| AES | [7-4] | y |
+------------------------------+---------+---------+
2) ID_AA64PFR0_EL1 - Processor Feature Register 0
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| DIT | [51-48] | y |
+------------------------------+---------+---------+
| MPAM | [43-40] | n |
+------------------------------+---------+---------+
| SVE | [35-32] | y |
+------------------------------+---------+---------+
| GIC | [27-24] | n |
+------------------------------+---------+---------+
| AdvSIMD | [23-20] | y |
+------------------------------+---------+---------+
| FP | [19-16] | y |
+------------------------------+---------+---------+
| EL3 | [15-12] | n |
+------------------------------+---------+---------+
| EL2 | [11-8] | n |
+------------------------------+---------+---------+
| EL1 | [7-4] | n |
+------------------------------+---------+---------+
| EL0 | [3-0] | n |
+------------------------------+---------+---------+
3) ID_AA64PFR1_EL1 - Processor Feature Register 1
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| SME | [27-24] | y |
+------------------------------+---------+---------+
| MTE | [11-8] | y |
+------------------------------+---------+---------+
| SSBS | [7-4] | y |
+------------------------------+---------+---------+
| BT | [3-0] | y |
+------------------------------+---------+---------+
4) MIDR_EL1 - Main ID Register
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| Implementer | [31-24] | y |
+------------------------------+---------+---------+
| Variant | [23-20] | y |
+------------------------------+---------+---------+
| Architecture | [19-16] | y |
+------------------------------+---------+---------+
| PartNum | [15-4] | y |
+------------------------------+---------+---------+
| Revision | [3-0] | y |
+------------------------------+---------+---------+
NOTE: The 'visible' fields of MIDR_EL1 will contain the value
as available on the CPU where it is fetched and is not a system
wide safe value.
5) ID_AA64ISAR1_EL1 - Instruction set attribute register 1
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| I8MM | [55-52] | y |
+------------------------------+---------+---------+
| DGH | [51-48] | y |
+------------------------------+---------+---------+
| BF16 | [47-44] | y |
+------------------------------+---------+---------+
| SB | [39-36] | y |
+------------------------------+---------+---------+
| FRINTTS | [35-32] | y |
+------------------------------+---------+---------+
| GPI | [31-28] | y |
+------------------------------+---------+---------+
| GPA | [27-24] | y |
+------------------------------+---------+---------+
| LRCPC | [23-20] | y |
+------------------------------+---------+---------+
| FCMA | [19-16] | y |
+------------------------------+---------+---------+
| JSCVT | [15-12] | y |
+------------------------------+---------+---------+
| API | [11-8] | y |
+------------------------------+---------+---------+
| APA | [7-4] | y |
+------------------------------+---------+---------+
| DPB | [3-0] | y |
+------------------------------+---------+---------+
6) ID_AA64MMFR0_EL1 - Memory model feature register 0
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| ECV | [63-60] | y |
+------------------------------+---------+---------+
7) ID_AA64MMFR2_EL1 - Memory model feature register 2
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| AT | [35-32] | y |
+------------------------------+---------+---------+
8) ID_AA64ZFR0_EL1 - SVE feature ID register 0
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| F64MM | [59-56] | y |
+------------------------------+---------+---------+
| F32MM | [55-52] | y |
+------------------------------+---------+---------+
| I8MM | [47-44] | y |
+------------------------------+---------+---------+
| SM4 | [43-40] | y |
+------------------------------+---------+---------+
| SHA3 | [35-32] | y |
+------------------------------+---------+---------+
| B16B16 | [27-24] | y |
+------------------------------+---------+---------+
| BF16 | [23-20] | y |
+------------------------------+---------+---------+
| BitPerm | [19-16] | y |
+------------------------------+---------+---------+
| AES | [7-4] | y |
+------------------------------+---------+---------+
| SVEVer | [3-0] | y |
+------------------------------+---------+---------+
8) ID_AA64MMFR1_EL1 - Memory model feature register 1
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| AFP | [47-44] | y |
+------------------------------+---------+---------+
9) ID_AA64ISAR2_EL1 - Instruction set attribute register 2
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| CSSC | [55-52] | y |
+------------------------------+---------+---------+
| RPRFM | [51-48] | y |
+------------------------------+---------+---------+
| BC | [23-20] | y |
+------------------------------+---------+---------+
| MOPS | [19-16] | y |
+------------------------------+---------+---------+
| APA3 | [15-12] | y |
+------------------------------+---------+---------+
| GPA3 | [11-8] | y |
+------------------------------+---------+---------+
| RPRES | [7-4] | y |
+------------------------------+---------+---------+
| WFXT | [3-0] | y |
+------------------------------+---------+---------+
10) MVFR0_EL1 - AArch32 Media and VFP Feature Register 0
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| FPDP | [11-8] | y |
+------------------------------+---------+---------+
11) MVFR1_EL1 - AArch32 Media and VFP Feature Register 1
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| SIMDFMAC | [31-28] | y |
+------------------------------+---------+---------+
| SIMDSP | [19-16] | y |
+------------------------------+---------+---------+
| SIMDInt | [15-12] | y |
+------------------------------+---------+---------+
| SIMDLS | [11-8] | y |
+------------------------------+---------+---------+
12) ID_ISAR5_EL1 - AArch32 Instruction Set Attribute Register 5
+------------------------------+---------+---------+
| Name | bits | visible |
+------------------------------+---------+---------+
| CRC32 | [19-16] | y |
+------------------------------+---------+---------+
| SHA2 | [15-12] | y |
+------------------------------+---------+---------+
| SHA1 | [11-8] | y |
+------------------------------+---------+---------+
| AES | [7-4] | y |
+------------------------------+---------+---------+
Appendix I: Example
-------------------
::
/*
* Sample program to demonstrate the MRS emulation ABI.
*
* Copyright (C) 2015-2016, ARM Ltd
*
* Author: Suzuki K Poulose <suzuki.poulose@arm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <asm/hwcap.h>
#include <stdio.h>
#include <sys/auxv.h>
#define get_cpu_ftr(id) ({ \
unsigned long __val; \
asm("mrs %0, "#id : "=r" (__val)); \
printf("%-20s: 0x%016lx\n", #id, __val); \
})
int main(void)
{
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
fputs("CPUID registers unavailable\n", stderr);
return 1;
}
get_cpu_ftr(ID_AA64ISAR0_EL1);
get_cpu_ftr(ID_AA64ISAR1_EL1);
get_cpu_ftr(ID_AA64MMFR0_EL1);
get_cpu_ftr(ID_AA64MMFR1_EL1);
get_cpu_ftr(ID_AA64PFR0_EL1);
get_cpu_ftr(ID_AA64PFR1_EL1);
get_cpu_ftr(ID_AA64DFR0_EL1);
get_cpu_ftr(ID_AA64DFR1_EL1);
get_cpu_ftr(MIDR_EL1);
get_cpu_ftr(MPIDR_EL1);
get_cpu_ftr(REVIDR_EL1);
#if 0
/* Unexposed register access causes SIGILL */
get_cpu_ftr(ID_MMFR0_EL1);
#endif
return 0;
}
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
문서 목적과 ABI 광고
1-10문서 제목은 `ARM64 CPU Feature Registers`, 작성자는 Suzuki K Poulose `<suzuki.poulose@arm.com>`입니다.
이 문서는 AArch64 CPU ID/feature register를 userspace에 내보내는 ABI를 설명합니다. 이 ABI의 가용성은 HWCAP의 `HWCAP_CPUID`로 광고됩니다.
도입 동기
11-35Arm architecture는 CPU와 system의 능력을 설명하는 feature register 집합을 정의하지만, EL0에서 이 system register 접근은 제한됩니다. 따라서 application이 runtime에 더 나은 결정을 내리기 위해 정보를 안정적으로 추출할 방법이 없습니다. HWCAP도 일부 정보를 제공하지만 다음 한계가 있습니다.
- HWCAP 변경을 감지하려면 libc 같은 userspace 갱신이 필요하고, distribution에 반영되기까지 오래 걸릴 수 있습니다. Register를 공개하면 toolchain 갱신 없이 application이 정보를 얻을 수 있습니다.
- libc보다 앞선 실행 단계나 startup 중 ld 초기화 시점처럼 HWCAP 접근이 제한되는 경우가 있습니다.
- HWCAP은 boolean이 아닌 정보를 효과적으로 표현하지 못합니다. 반면 ID register의 architecture 표준 형식은 모든 유효한 architecture 변형을 표현할 수 있습니다.
안전성·보안·구현 정의 기능
36-67안전성 요구사항은 제공된 정보로 application이 system 전체 CPU에서 안전하게 실행될 수 있어야 한다는 것입니다. 이 조건은 heterogeneous CPU system에서 특히 중요하므로 infrastructure는 모든 가용 CPU에 안전한 system-wide 값을 내보냅니다.
예를 들어 일부 CPU만 CRC32 instruction을 지원한다면 CRC32가 구현되지 않은 것으로 보고해야 합니다. 그렇지 않으면 application이 CRC32 미지원 CPU에 schedule될 때 crash할 수 있습니다.
보안을 위해 userspace 정상 동작에 필요한 정보만 공개합니다. 일부 field는 보이지 않게 mask하고 architecture가 정의한 `not supported` 값으로 설정합니다. 공개 field 목록은 4절에 있으며, kernel이 실제로 지원하는 범위에 맞춰 값도 조정할 수 있습니다. CPU가 FP를 제공해도 kernel이 FP를 지원하지 않으면 FP를 사용할 수 없는 값으로 보일 수 있습니다.
Armv8-A Architecture에서 `IMPLEMENTATION DEFINED`로 정의된 register는 이 infrastructure가 공개하지 않습니다.
CPU 식별과 sysfs
68-84`MIDR_EL1`은 processor 식별을 돕기 위해 공개됩니다. Heterogeneous system에서는 `getcpu()`와 마찬가지로 race가 생길 수 있습니다. CPU affinity를 고정하지 않으면 값을 사용하기 전에 process가 다른 CPU로 migration될 수 있으므로, 읽은 값이 현재 실행 중인 processor를 반영한다는 보장은 없습니다.
`REVIDR`와 `AIDR`은 `MIDR`과 함께 사용해야 의미가 있어 이 ABI에서는 공개하지 않습니다. 대신 `MIDR_EL1`, `REVIDR_EL1`, `AIDR_EL1`은 다음 CPU별 sysfs 경로로 공개됩니다.
/sys/devices/system/cpu/cpu$ID/regs/identification/
\- midr_el1
\- revidr_el1
\- aidr_el1
MRS emulation 구현과 반환 규칙
85-112이 infrastructure는 `MRS` instruction emulation 위에 구현됩니다. Application이 제한된 system register에 접근하면 exception이 발생하고 보통 process에 `SIGILL`이 전달됩니다. Kernel은 exception handler에 연결되어 source가 지원 system-register 공간에 속하면 operation을 emulate합니다.
Emulation 대상 system-register 공간은 다음과 같습니다.
Op0=3, Op1=0, CRn=0, CRm=0,2,3,4,5,6,7
ARMv8 ARM `DDI 0487A.h`의 Table C5-6, `System instruction encodings for non-Debug System register accesses`에서 register 목록을 확인할 수 있습니다.
- `IMPLEMENTATION DEFINED` field 값은 `0`으로 설정합니다.
- Reserved field는 architecture가 정의한 reserved 값으로 채웁니다.
- 공개 field는 특정 기능의 system-wide safe 값을 가집니다. 단 `MIDR_EL1`은 4절의 예외를 따릅니다.
- 그 밖의 비공개 field는 architecture 정의에 따라 기능이 없음을 나타내는 값으로 설정합니다.
공개 feature register 1-4
113-210다음 표는 EL0에 보이는 field를 원문 순서대로 정리합니다. `비공개` field는 userspace 정상 동작에 필요하지 않아 mask됩니다.
`ID_AA64ISAR0_EL1` - Instruction Set Attribute Register 0
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `RNDR` | `[63-60]` | 공개 |
| `TS` | `[55-52]` | 공개 |
| `FHM` | `[51-48]` | 공개 |
| `DP` | `[47-44]` | 공개 |
| `SM4` | `[43-40]` | 공개 |
| `SM3` | `[39-36]` | 공개 |
| `SHA3` | `[35-32]` | 공개 |
| `RDM` | `[31-28]` | 공개 |
| `ATOMICS` | `[23-20]` | 공개 |
| `CRC32` | `[19-16]` | 공개 |
| `SHA2` | `[15-12]` | 공개 |
| `SHA1` | `[11-8]` | 공개 |
| `AES` | `[7-4]` | 공개 |
`ID_AA64PFR0_EL1` - Processor Feature Register 0
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `DIT` | `[51-48]` | 공개 |
| `MPAM` | `[43-40]` | 비공개 |
| `SVE` | `[35-32]` | 공개 |
| `GIC` | `[27-24]` | 비공개 |
| `AdvSIMD` | `[23-20]` | 공개 |
| `FP` | `[19-16]` | 공개 |
| `EL3` | `[15-12]` | 비공개 |
| `EL2` | `[11-8]` | 비공개 |
| `EL1` | `[7-4]` | 비공개 |
| `EL0` | `[3-0]` | 비공개 |
`ID_AA64PFR1_EL1` - Processor Feature Register 1
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `SME` | `[27-24]` | 공개 |
| `MTE` | `[11-8]` | 공개 |
| `SSBS` | `[7-4]` | 공개 |
| `BT` | `[3-0]` | 공개 |
`MIDR_EL1` - Main ID Register
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `Implementer` | `[31-24]` | 공개 |
| `Variant` | `[23-20]` | 공개 |
| `Architecture` | `[19-16]` | 공개 |
| `PartNum` | `[15-4]` | 공개 |
| `Revision` | `[3-0]` | 공개 |
`MIDR_EL1`의 공개 field는 읽기를 수행한 CPU의 실제 값을 포함하며 system-wide safe 값이 아닙니다.
공개 feature register 5-12
211-350나머지 공개 register와 field도 원문 순서와 bit 위치를 그대로 보존합니다. 원문의 번호는 `ID_AA64ZFR0_EL1`과 `ID_AA64MMFR1_EL1`에 모두 8번을 사용하지만, 여기서는 register 이름을 기준으로 구분합니다.
`ID_AA64ISAR1_EL1` - Instruction Set Attribute Register 1
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `I8MM` | `[55-52]` | 공개 |
| `DGH` | `[51-48]` | 공개 |
| `BF16` | `[47-44]` | 공개 |
| `SB` | `[39-36]` | 공개 |
| `FRINTTS` | `[35-32]` | 공개 |
| `GPI` | `[31-28]` | 공개 |
| `GPA` | `[27-24]` | 공개 |
| `LRCPC` | `[23-20]` | 공개 |
| `FCMA` | `[19-16]` | 공개 |
| `JSCVT` | `[15-12]` | 공개 |
| `API` | `[11-8]` | 공개 |
| `APA` | `[7-4]` | 공개 |
| `DPB` | `[3-0]` | 공개 |
`ID_AA64MMFR0_EL1` - Memory Model Feature Register 0
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `ECV` | `[63-60]` | 공개 |
`ID_AA64MMFR2_EL1` - Memory Model Feature Register 2
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `AT` | `[35-32]` | 공개 |
`ID_AA64ZFR0_EL1` - SVE Feature ID Register 0
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `F64MM` | `[59-56]` | 공개 |
| `F32MM` | `[55-52]` | 공개 |
| `I8MM` | `[47-44]` | 공개 |
| `SM4` | `[43-40]` | 공개 |
| `SHA3` | `[35-32]` | 공개 |
| `B16B16` | `[27-24]` | 공개 |
| `BF16` | `[23-20]` | 공개 |
| `BitPerm` | `[19-16]` | 공개 |
| `AES` | `[7-4]` | 공개 |
| `SVEVer` | `[3-0]` | 공개 |
`ID_AA64MMFR1_EL1` - Memory Model Feature Register 1
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `AFP` | `[47-44]` | 공개 |
`ID_AA64ISAR2_EL1` - Instruction Set Attribute Register 2
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `CSSC` | `[55-52]` | 공개 |
| `RPRFM` | `[51-48]` | 공개 |
| `BC` | `[23-20]` | 공개 |
| `MOPS` | `[19-16]` | 공개 |
| `APA3` | `[15-12]` | 공개 |
| `GPA3` | `[11-8]` | 공개 |
| `RPRES` | `[7-4]` | 공개 |
| `WFXT` | `[3-0]` | 공개 |
`MVFR0_EL1` - AArch32 Media and VFP Feature Register 0
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `FPDP` | `[11-8]` | 공개 |
`MVFR1_EL1` - AArch32 Media and VFP Feature Register 1
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `SIMDFMAC` | `[31-28]` | 공개 |
| `SIMDSP` | `[19-16]` | 공개 |
| `SIMDInt` | `[15-12]` | 공개 |
| `SIMDLS` | `[11-8]` | 공개 |
`ID_ISAR5_EL1` - AArch32 Instruction Set Attribute Register 5
| 필드 | 비트 | EL0 공개 |
|---|---|---|
| `CRC32` | `[19-16]` | 공개 |
| `SHA2` | `[15-12]` | 공개 |
| `SHA1` | `[11-8]` | 공개 |
| `AES` | `[7-4]` | 공개 |
MRS emulation ABI 예제
351-419부록의 sample program은 `getauxval(AT_HWCAP)`에서 `HWCAP_CPUID`를 먼저 확인한 뒤 inline assembly의 `mrs`로 ID register를 읽습니다. 공개되지 않은 `ID_MMFR0_EL1` 접근은 `SIGILL`을 일으키므로 `#if 0`으로 비활성화되어 있습니다.
/*
* Sample program to demonstrate the MRS emulation ABI.
*
* Copyright (C) 2015-2016, ARM Ltd
*
* Author: Suzuki K Poulose <suzuki.poulose@arm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <asm/hwcap.h>
#include <stdio.h>
#include <sys/auxv.h>
#define get_cpu_ftr(id) ({ \
unsigned long __val; \
asm("mrs %0, "#id : "=r" (__val)); \
printf("%-20s: 0x%016lx\n", #id, __val); \
})
int main(void)
{
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
fputs("CPUID registers unavailable\n", stderr);
return 1;
}
get_cpu_ftr(ID_AA64ISAR0_EL1);
get_cpu_ftr(ID_AA64ISAR1_EL1);
get_cpu_ftr(ID_AA64MMFR0_EL1);
get_cpu_ftr(ID_AA64MMFR1_EL1);
get_cpu_ftr(ID_AA64PFR0_EL1);
get_cpu_ftr(ID_AA64PFR1_EL1);
get_cpu_ftr(ID_AA64DFR0_EL1);
get_cpu_ftr(ID_AA64DFR1_EL1);
get_cpu_ftr(MIDR_EL1);
get_cpu_ftr(MPIDR_EL1);
get_cpu_ftr(REVIDR_EL1);
#if 0
/* Unexposed register access causes SIGILL */
get_cpu_ftr(ID_MMFR0_EL1);
#endif
return 0;
}
요약과 해설
cpu-feature-registers.rst:1-419이 ABI는 EL0의 제한된 `MRS`를 kernel이 emulate해 userspace에 CPU feature 정보를 제공합니다. Heterogeneous CPU에서도 안전하도록 대부분의 field는 system-wide 최소 공통값이며, 보안상 불필요하거나 kernel이 지원하지 않는 기능은 숨깁니다.
`HWCAP_CPUID` 확인부터 안전한 register 값 반환까지의 흐름입니다.
원본 hardware 값이 그대로 노출되는 것은 아닙니다.