Home | History | Annotate | Line # | Download | only in arch
aarch64.c revision 1.2
      1  1.2  ryo /*	$NetBSD: aarch64.c,v 1.2 2018/05/08 11:42:43 ryo Exp $	*/
      2  1.1  ryo 
      3  1.1  ryo /*
      4  1.1  ryo  * Copyright (c) 2018 Ryo Shimizu <ryo (at) nerv.org>
      5  1.1  ryo  * All rights reserved.
      6  1.1  ryo  *
      7  1.1  ryo  * Redistribution and use in source and binary forms, with or without
      8  1.1  ryo  * modification, are permitted provided that the following conditions
      9  1.1  ryo  * are met:
     10  1.1  ryo  * 1. Redistributions of source code must retain the above copyright
     11  1.1  ryo  *    notice, this list of conditions and the following disclaimer.
     12  1.1  ryo  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  ryo  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  ryo  *    documentation and/or other materials provided with the distribution.
     15  1.1  ryo  *
     16  1.1  ryo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  ryo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  1.1  ryo  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19  1.1  ryo  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  1.1  ryo  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  1.1  ryo  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  1.1  ryo  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  ryo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  1.1  ryo  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25  1.1  ryo  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  ryo  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  ryo  */
     28  1.1  ryo 
     29  1.1  ryo #include <sys/cdefs.h>
     30  1.1  ryo 
     31  1.1  ryo #ifndef lint
     32  1.2  ryo __RCSID("$NetBSD: aarch64.c,v 1.2 2018/05/08 11:42:43 ryo Exp $");
     33  1.1  ryo #endif /* no lint */
     34  1.1  ryo 
     35  1.1  ryo #include <sys/types.h>
     36  1.1  ryo #include <sys/cpuio.h>
     37  1.1  ryo #include <sys/sysctl.h>
     38  1.1  ryo #include <stdio.h>
     39  1.1  ryo #include <stdbool.h>
     40  1.1  ryo #include <stdlib.h>
     41  1.1  ryo #include <string.h>
     42  1.1  ryo #include <inttypes.h>
     43  1.1  ryo #include <err.h>
     44  1.1  ryo 
     45  1.1  ryo #include <arm/cputypes.h>
     46  1.1  ryo #include <aarch64/armreg.h>
     47  1.1  ryo 
     48  1.1  ryo #include "../cpuctl.h"
     49  1.1  ryo 
     50  1.1  ryo struct cpuidtab {
     51  1.1  ryo 	uint32_t cpu_partnum;
     52  1.1  ryo 	const char *cpu_name;
     53  1.1  ryo 	const char *cpu_class;
     54  1.1  ryo 	const char *cpu_architecture;
     55  1.1  ryo };
     56  1.1  ryo 
     57  1.1  ryo struct impltab {
     58  1.1  ryo 	uint32_t impl_id;
     59  1.1  ryo 	const char *impl_name;
     60  1.1  ryo };
     61  1.1  ryo 
     62  1.1  ryo struct fieldinfo {
     63  1.1  ryo 	int bitpos;
     64  1.1  ryo 	int bitwidth;
     65  1.1  ryo 	const char *name;
     66  1.1  ryo 	const char * const *info;
     67  1.1  ryo };
     68  1.1  ryo 
     69  1.1  ryo 
     70  1.1  ryo #define CPU_PARTMASK	(CPU_ID_IMPLEMENTOR_MASK | CPU_ID_PARTNO_MASK)
     71  1.1  ryo const struct cpuidtab cpuids[] = {
     72  1.1  ryo 	{ CPU_ID_CORTEXA53R0 & CPU_PARTMASK, "Cortex-A53", "Cortex", "V8-A" },
     73  1.1  ryo 	{ CPU_ID_CORTEXA57R0 & CPU_PARTMASK, "Cortex-A57", "Cortex", "V8-A" },
     74  1.1  ryo 	{ CPU_ID_CORTEXA72R0 & CPU_PARTMASK, "Cortex-A72", "Cortex", "V8-A" },
     75  1.1  ryo 	{ CPU_ID_CORTEXA73R0 & CPU_PARTMASK, "Cortex-A73", "Cortex", "V8-A" },
     76  1.1  ryo 	{ CPU_ID_CORTEXA55R1 & CPU_PARTMASK, "Cortex-A55", "Cortex", "V8.2-A" },
     77  1.1  ryo 	{ CPU_ID_CORTEXA75R2 & CPU_PARTMASK, "Cortex-A75", "Cortex", "V8.2-A" }
     78  1.1  ryo };
     79  1.1  ryo 
     80  1.1  ryo const struct impltab implids[] = {
     81  1.1  ryo 	{ CPU_ID_ARM_LTD,	"ARM Limited"				},
     82  1.1  ryo 	{ CPU_ID_BROADCOM,	"Broadcom Corporation"			},
     83  1.1  ryo 	{ CPU_ID_CAVIUM,	"Cavium Inc."				},
     84  1.1  ryo 	{ CPU_ID_DEC,		"Digital Equipment Corporation"		},
     85  1.1  ryo 	{ CPU_ID_INFINEON,	"Infineon Technologies AG"		},
     86  1.1  ryo 	{ CPU_ID_MOTOROLA,	"Motorola or Freescale Semiconductor Inc." },
     87  1.1  ryo 	{ CPU_ID_NVIDIA,	"NVIDIA Corporation"			},
     88  1.1  ryo 	{ CPU_ID_APM,		"Applied Micro Circuits Corporation"	},
     89  1.1  ryo 	{ CPU_ID_QUALCOMM,	"Qualcomm Inc."				},
     90  1.1  ryo 	{ CPU_ID_SAMSUNG,	"SAMSUNG"				},
     91  1.1  ryo 	{ CPU_ID_TI,		"Texas Instruments"			},
     92  1.1  ryo 	{ CPU_ID_MARVELL,	"Marvell International Ltd."		},
     93  1.1  ryo 	{ CPU_ID_APPLE,		"Apple Inc."				},
     94  1.1  ryo 	{ CPU_ID_FARADAY,	"Faraday Technology Corporation"	},
     95  1.1  ryo 	{ CPU_ID_INTEL,		"Intel Corporation"			}
     96  1.1  ryo };
     97  1.1  ryo 
     98  1.1  ryo /* ID_AA64PFR0_EL1 - AArch64 Processor Feature Register 0 */
     99  1.1  ryo struct fieldinfo id_aa64pfr0_fieldinfo[] = {
    100  1.1  ryo 	{
    101  1.1  ryo 		.bitpos = 0, .bitwidth = 4, .name = "EL0",
    102  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    103  1.1  ryo 			[0] = "No EL0",
    104  1.1  ryo 			[1] = "AArch64",
    105  1.1  ryo 			[2] = "AArch64/AArch32"
    106  1.1  ryo 		}
    107  1.1  ryo 	},
    108  1.1  ryo 	{
    109  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "EL1",
    110  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    111  1.1  ryo 			[0] = "No EL1",
    112  1.1  ryo 			[1] = "AArch64",
    113  1.1  ryo 			[2] = "AArch64/AArch32"
    114  1.1  ryo 		}
    115  1.1  ryo 	},
    116  1.1  ryo 	{
    117  1.1  ryo 		.bitpos = 8, .bitwidth = 4, .name = "EL2",
    118  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    119  1.1  ryo 			[0] = "No EL2",
    120  1.1  ryo 			[1] = "AArch64",
    121  1.1  ryo 			[2] = "AArch64/AArch32"
    122  1.1  ryo 		}
    123  1.1  ryo 	},
    124  1.1  ryo 	{
    125  1.1  ryo 		.bitpos = 12, .bitwidth = 4, .name = "EL3",
    126  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    127  1.1  ryo 			[0] = "No EL3",
    128  1.1  ryo 			[1] = "AArch64",
    129  1.1  ryo 			[2] = "AArch64/AArch32"
    130  1.1  ryo 		}
    131  1.1  ryo 	},
    132  1.1  ryo 	{
    133  1.1  ryo 		.bitpos = 16, .bitwidth = 4, .name = "FP",
    134  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    135  1.1  ryo 			[0] = "Floating Point",
    136  1.1  ryo 			[15] = "No Floating Point"
    137  1.1  ryo 		}
    138  1.1  ryo 	},
    139  1.1  ryo 	{
    140  1.1  ryo 		.bitpos = 20, .bitwidth = 4, .name = "AdvSIMD",
    141  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    142  1.1  ryo 			[0] = "Advanced SIMD",
    143  1.1  ryo 			[15] = "No Advanced SIMD"
    144  1.1  ryo 		}
    145  1.1  ryo 	},
    146  1.1  ryo 	{
    147  1.1  ryo 		.bitpos = 24, .bitwidth = 4, .name = "GIC",
    148  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    149  1.1  ryo 			[0] = "No GIC",
    150  1.1  ryo 			[1] = "GICv3"
    151  1.1  ryo 		}
    152  1.1  ryo 	},
    153  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    154  1.1  ryo };
    155  1.1  ryo 
    156  1.1  ryo /* ID_AA64ISAR0_EL1 - AArch64 Instruction Set Attribute Register 0 */
    157  1.1  ryo struct fieldinfo id_aa64isar0_fieldinfo[] = {
    158  1.1  ryo 	{
    159  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "AES",
    160  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    161  1.1  ryo 			[0] = "No AES",
    162  1.1  ryo 			[1] = "AESE/AESD/AESMC/AESIMC",
    163  1.1  ryo 			[2] = "AESE/AESD/AESMC/AESIMC+PMULL/PMULL2"
    164  1.1  ryo 		}
    165  1.1  ryo 	},
    166  1.1  ryo 	{
    167  1.1  ryo 		.bitpos = 8, .bitwidth = 4, .name = "SHA1",
    168  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    169  1.1  ryo 			[0] = "No SHA1",
    170  1.1  ryo 			[1] = "SHA1C/SHA1P/SHA1M/SHA1H/SHA1SU0/SHA1SU1"
    171  1.1  ryo 		}
    172  1.1  ryo 	},
    173  1.1  ryo 	{
    174  1.1  ryo 		.bitpos = 12, .bitwidth = 4, .name = "SHA2",
    175  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    176  1.1  ryo 			[0] = "No SHA2",
    177  1.1  ryo 			[1] = "SHA256H/SHA256H2/SHA256SU0/SHA256U1"
    178  1.1  ryo 		}
    179  1.1  ryo 	},
    180  1.1  ryo 	{
    181  1.1  ryo 		.bitpos = 16, .bitwidth = 4, .name = "CRC32",
    182  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    183  1.1  ryo 			[0] = "No CRC32",
    184  1.1  ryo 			[1] = "CRC32B/CRC32H/CRC32W/CRC32X"
    185  1.1  ryo 			    "/CRC32CB/CRC32CH/CRC32CW/CRC32CX"
    186  1.1  ryo 		}
    187  1.1  ryo 	},
    188  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    189  1.1  ryo };
    190  1.1  ryo 
    191  1.1  ryo /* ID_AA64MMFR0_EL1 - AArch64 Memory Model Feature Register 0 */
    192  1.1  ryo struct fieldinfo id_aa64mmfr0_fieldinfo[] = {
    193  1.1  ryo 	{
    194  1.1  ryo 		.bitpos = 0, .bitwidth = 4, .name = "PARange",
    195  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    196  1.1  ryo 			[0] = "32bits/4GB",
    197  1.1  ryo 			[1] = "36bits/64GB",
    198  1.1  ryo 			[2] = "40bits/1TB",
    199  1.1  ryo 			[3] = "42bits/4TB",
    200  1.1  ryo 			[4] = "44bits/16TB",
    201  1.1  ryo 			[5] = "48bits/256TB"
    202  1.1  ryo 		}
    203  1.1  ryo 	},
    204  1.1  ryo 	{
    205  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "ASIDBit",
    206  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    207  1.1  ryo 			[0] = "8bits",
    208  1.1  ryo 			[2] = "16bits"
    209  1.1  ryo 		}
    210  1.1  ryo 	},
    211  1.1  ryo 	{
    212  1.1  ryo 		.bitpos = 8, .bitwidth = 4, .name = "BigEnd",
    213  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    214  1.1  ryo 			[0] = "No mixed-endian",
    215  1.1  ryo 			[1] = "Mixed-endian"
    216  1.1  ryo 		}
    217  1.1  ryo 	},
    218  1.1  ryo 	{
    219  1.1  ryo 		.bitpos = 12, .bitwidth = 4, .name = "SNSMem",
    220  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    221  1.1  ryo 			[0] = "No distinction B/W Secure and Non-secure Memory",
    222  1.1  ryo 			[1] = "Distinction B/W Secure and Non-secure Memory"
    223  1.1  ryo 		}
    224  1.1  ryo 	},
    225  1.1  ryo 	{
    226  1.1  ryo 		.bitpos = 16, .bitwidth = 4, .name = "BigEndEL0",
    227  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    228  1.1  ryo 			[0] = "No mixed-endian at EL0",
    229  1.1  ryo 			[1] = "Mixed-endian at EL0"
    230  1.1  ryo 		}
    231  1.1  ryo 	},
    232  1.1  ryo 	{
    233  1.1  ryo 		.bitpos = 20, .bitwidth = 4, .name = "TGran16",
    234  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    235  1.1  ryo 			[0] = "No 16KB granule",
    236  1.1  ryo 			[1] = "16KB granule"
    237  1.1  ryo 		}
    238  1.1  ryo 	},
    239  1.1  ryo 	{
    240  1.1  ryo 		.bitpos = 24, .bitwidth = 4, .name = "TGran64",
    241  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    242  1.2  ryo 			[0] = "64KB granule",
    243  1.2  ryo 			[15] = "No 64KB granule"
    244  1.1  ryo 		}
    245  1.1  ryo 	},
    246  1.1  ryo 	{
    247  1.1  ryo 		.bitpos = 28, .bitwidth = 4, .name = "TGran4",
    248  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    249  1.1  ryo 			[0] = "4KB granule",
    250  1.1  ryo 			[15] = "No 4KB granule"
    251  1.1  ryo 		}
    252  1.1  ryo 	},
    253  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    254  1.1  ryo };
    255  1.1  ryo 
    256  1.1  ryo /* MVFR0_EL1 - Media and VFP Feature Register 0 */
    257  1.1  ryo struct fieldinfo mvfr0_fieldinfo[] = {
    258  1.1  ryo 	{
    259  1.1  ryo 		.bitpos = 0, .bitwidth = 4, .name = "SIMDreg",
    260  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    261  1.1  ryo 			[0] = "No SIMD",
    262  1.1  ryo 			[1] = "16x64-bit SIMD",
    263  1.1  ryo 			[2] = "32x64-bit SIMD"
    264  1.1  ryo 		}
    265  1.1  ryo 	},
    266  1.1  ryo 	{
    267  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "FPSP",
    268  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    269  1.1  ryo 			[0] = "No VFP support single precision",
    270  1.1  ryo 			[1] = "VFPv2 support single precision",
    271  1.1  ryo 			[2] = "VFPv2/VFPv3/VFPv4 support single precision"
    272  1.1  ryo 		}
    273  1.1  ryo 	},
    274  1.1  ryo 	{
    275  1.1  ryo 		.bitpos = 8, .bitwidth = 4, .name = "FPDP",
    276  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    277  1.1  ryo 			[0] = "No VFP support double precision",
    278  1.1  ryo 			[1] = "VFPv2 support double precision",
    279  1.1  ryo 			[2] = "VFPv2/VFPv3/VFPv4 support double precision"
    280  1.1  ryo 		}
    281  1.1  ryo 	},
    282  1.1  ryo 	{
    283  1.1  ryo 		.bitpos = 12, .bitwidth = 4, .name = "FPTrap",
    284  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    285  1.1  ryo 			[0] = "VFPv2 support exception trapping",
    286  1.1  ryo 			[1] = "VFPv2/VFPv3/VFPv4 support exception trapping"
    287  1.1  ryo 		}
    288  1.1  ryo 	},
    289  1.1  ryo 	{
    290  1.1  ryo 		.bitpos = 16, .bitwidth = 4, .name = "FPDivide",
    291  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    292  1.1  ryo 			[0] = "VDIV not supported",
    293  1.1  ryo 			[1] = "VDIV supported"
    294  1.1  ryo 		}
    295  1.1  ryo 	},
    296  1.1  ryo 	{
    297  1.1  ryo 		.bitpos = 20, .bitwidth = 4, .name = "FPSqrt",
    298  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    299  1.1  ryo 			[0] = "VSQRT not supported",
    300  1.1  ryo 			[1] = "VSQRT supported"
    301  1.1  ryo 		}
    302  1.1  ryo 	},
    303  1.1  ryo 	{
    304  1.1  ryo 		.bitpos = 24, .bitwidth = 4, .name = "FPShVec",
    305  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    306  1.1  ryo 			[0] = "Short Vectors not supported",
    307  1.1  ryo 			[1] = "Short Vectors supported"
    308  1.1  ryo 		}
    309  1.1  ryo 	},
    310  1.1  ryo 	{
    311  1.1  ryo 		.bitpos = 28, .bitwidth = 4, .name = "FPRound",
    312  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    313  1.1  ryo 			[0] = "Only Round to Nearest mode",
    314  1.1  ryo 			[1] = "All rounding modes"
    315  1.1  ryo 		}
    316  1.1  ryo 	},
    317  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    318  1.1  ryo };
    319  1.1  ryo 
    320  1.1  ryo /* MVFR1_EL1 - Media and VFP Feature Register 1 */
    321  1.1  ryo struct fieldinfo mvfr1_fieldinfo[] = {
    322  1.1  ryo 	{
    323  1.1  ryo 		.bitpos = 0, .bitwidth = 4, .name = "FPFtZ",
    324  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    325  1.1  ryo 			[0] = "only the Flush-to-Zero",
    326  1.1  ryo 			[1] = "full Denormalized number arithmetic"
    327  1.1  ryo 		}
    328  1.1  ryo 	},
    329  1.1  ryo 	{
    330  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "FPDNan",
    331  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    332  1.1  ryo 			[0] = "Default NaN",
    333  1.1  ryo 			[1] = "Propagation of NaN"
    334  1.1  ryo 		}
    335  1.1  ryo 	},
    336  1.1  ryo 	{
    337  1.1  ryo 		.bitpos = 8, .bitwidth = 4, .name = "SIMDLS",
    338  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    339  1.1  ryo 			[0] = "No Advanced SIMD Load/Store",
    340  1.1  ryo 			[1] = "Advanced SIMD Load/Store"
    341  1.1  ryo 		}
    342  1.1  ryo 	},
    343  1.1  ryo 	{
    344  1.1  ryo 		.bitpos = 12, .bitwidth = 4, .name = "SIMDInt",
    345  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    346  1.1  ryo 			[0] = "No Advanced SIMD Integer",
    347  1.1  ryo 			[1] = "Advanced SIMD Integer"
    348  1.1  ryo 		}
    349  1.1  ryo 	},
    350  1.1  ryo 	{
    351  1.1  ryo 		.bitpos = 16, .bitwidth = 4, .name = "SIMDSP",
    352  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    353  1.1  ryo 			[0] = "No Advanced SIMD single precision",
    354  1.1  ryo 			[1] = "Advanced SIMD single precision"
    355  1.1  ryo 		}
    356  1.1  ryo 	},
    357  1.1  ryo 	{
    358  1.1  ryo 		.bitpos = 20, .bitwidth = 4, .name = "SIMDHP",
    359  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    360  1.1  ryo 			[0] = "No Advanced SIMD half precision",
    361  1.1  ryo 			[1] = "Advanced SIMD half precision"
    362  1.1  ryo 		}
    363  1.1  ryo 	},
    364  1.1  ryo 	{
    365  1.1  ryo 		.bitpos = 24, .bitwidth = 4, .name = "FPHP",
    366  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    367  1.1  ryo 			[0] = "No half precision conversion",
    368  1.1  ryo 			[1] = "half/single precision conversion",
    369  1.1  ryo 			[2] = "half/single/double precision conversion"
    370  1.1  ryo 		}
    371  1.1  ryo 	},
    372  1.1  ryo 	{
    373  1.1  ryo 		.bitpos = 28, .bitwidth = 4, .name = "SIMDFMAC",
    374  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    375  1.1  ryo 			[0] = "No Fused Multiply-Accumulate",
    376  1.1  ryo 			[1] = "Fused Multiply-Accumulate"
    377  1.1  ryo 		}
    378  1.1  ryo 	},
    379  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    380  1.1  ryo };
    381  1.1  ryo 
    382  1.1  ryo /* MVFR2_EL1 - Media and VFP Feature Register 2 */
    383  1.1  ryo struct fieldinfo mvfr2_fieldinfo[] = {
    384  1.1  ryo 	{
    385  1.1  ryo 		.bitpos = 0, .bitwidth = 4, .name = "SIMDMisc",
    386  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    387  1.1  ryo 			[0] = "No miscellaneous features",
    388  1.1  ryo 			[1] = "Conversion to Integer w/Directed Rounding modes",
    389  1.1  ryo 			[2] = "Conversion to Integer w/Directed Rounding modes"
    390  1.1  ryo 			    ", Round to Integral floating point",
    391  1.1  ryo 			[3] = "Conversion to Integer w/Directed Rounding modes"
    392  1.1  ryo 			    ", Round to Integral floating point"
    393  1.1  ryo 			    ", MaxNum and MinNum"
    394  1.1  ryo 		}
    395  1.1  ryo 	},
    396  1.1  ryo 	{
    397  1.1  ryo 		.bitpos = 4, .bitwidth = 4, .name = "FPMisc",
    398  1.1  ryo 		.info = (const char *[16]) { /* 16=4bit */
    399  1.1  ryo 			[0] = "No miscellaneous features",
    400  1.1  ryo 			[1] = "Floating point selection",
    401  1.1  ryo 			[2] = "Floating point selection"
    402  1.1  ryo 			    ", Conversion to Integer w/Directed Rounding modes",
    403  1.1  ryo 			[3] = "Floating point selection"
    404  1.1  ryo 			    ", Conversion to Integer w/Directed Rounding modes"
    405  1.1  ryo 			    ", Round to Integral floating point",
    406  1.1  ryo 			[4] = "Floating point selection"
    407  1.1  ryo 			    ", Conversion to Integer w/Directed Rounding modes"
    408  1.1  ryo 			    ", Round to Integral floating point"
    409  1.1  ryo 			    ", MaxNum and MinNum"
    410  1.1  ryo 		}
    411  1.1  ryo 	},
    412  1.1  ryo 	{ .bitwidth = 0 }	/* end of table */
    413  1.1  ryo };
    414  1.1  ryo 
    415  1.1  ryo static void
    416  1.1  ryo print_fieldinfo(const char *cpuname, const char *setname,
    417  1.1  ryo     struct fieldinfo *fieldinfo, uint64_t data)
    418  1.1  ryo {
    419  1.1  ryo 	uint64_t v;
    420  1.1  ryo 	const char *info;
    421  1.1  ryo 	int i;
    422  1.1  ryo 
    423  1.1  ryo #define WIDTHMASK(w)	(0xffffffffffffffffULL >> (64 - (w)))
    424  1.1  ryo 
    425  1.1  ryo 	for (i = 0; fieldinfo[i].bitwidth != 0; i++) {
    426  1.1  ryo 		v = (data >> fieldinfo[i].bitpos) &
    427  1.1  ryo 		    WIDTHMASK(fieldinfo[i].bitwidth);
    428  1.1  ryo 
    429  1.1  ryo 		info = fieldinfo[i].info[v];
    430  1.1  ryo 		if (info == NULL)
    431  1.1  ryo 			printf("%s: %s: %s: 0x%"PRIx64"\n",
    432  1.1  ryo 			    cpuname, setname, fieldinfo[i].name, v);
    433  1.1  ryo 		else
    434  1.1  ryo 			printf("%s: %s: %s: %s\n",
    435  1.1  ryo 			    cpuname, setname, fieldinfo[i].name, info);
    436  1.1  ryo 	}
    437  1.1  ryo }
    438  1.1  ryo 
    439  1.1  ryo /* MIDR_EL1 - Main ID Register */
    440  1.1  ryo static void
    441  1.1  ryo identify_midr(const char *cpuname, uint32_t cpuid)
    442  1.1  ryo {
    443  1.1  ryo 	unsigned int i;
    444  1.1  ryo 	uint32_t implid, cpupart, variant, revision;
    445  1.1  ryo 	const char *implementer = NULL;
    446  1.1  ryo 	static char implbuf[128];
    447  1.1  ryo 
    448  1.1  ryo 	implid = cpuid & CPU_ID_IMPLEMENTOR_MASK;
    449  1.1  ryo 	cpupart = cpuid & CPU_PARTMASK;
    450  1.1  ryo 	variant = __SHIFTOUT(cpuid, CPU_ID_VARIANT_MASK);
    451  1.1  ryo 	revision = __SHIFTOUT(cpuid, CPU_ID_REVISION_MASK);
    452  1.1  ryo 
    453  1.1  ryo 	for (i = 0; i < __arraycount(implids); i++) {
    454  1.1  ryo 		if (implid == implids[i].impl_id) {
    455  1.1  ryo 			implementer = implids[i].impl_name;
    456  1.1  ryo 		}
    457  1.1  ryo 	}
    458  1.1  ryo 	if (implementer == NULL) {
    459  1.1  ryo 		snprintf(implbuf, sizeof(implbuf), "unknown implementer: 0x%02x",
    460  1.1  ryo 		    implid >> 24);
    461  1.1  ryo 		implementer = implbuf;
    462  1.1  ryo 	}
    463  1.1  ryo 
    464  1.1  ryo 	for (i = 0; i < __arraycount(cpuids); i++) {
    465  1.1  ryo 		if (cpupart == cpuids[i].cpu_partnum) {
    466  1.1  ryo 			printf("%s: %s, %s r%dp%d (%s %s core)\n",
    467  1.1  ryo 			    cpuname, implementer,
    468  1.1  ryo 			    cpuids[i].cpu_name, variant, revision,
    469  1.1  ryo 			    cpuids[i].cpu_class,
    470  1.1  ryo 			    cpuids[i].cpu_architecture);
    471  1.1  ryo 			return;
    472  1.1  ryo 		}
    473  1.1  ryo 	}
    474  1.1  ryo 	printf("%s: unknown CPU ID: 0x%08x\n", cpuname, cpuid);
    475  1.1  ryo }
    476  1.1  ryo 
    477  1.1  ryo /* REVIDR_EL1 - Revision ID Register */
    478  1.1  ryo static void
    479  1.1  ryo identify_revidr(const char *cpuname, uint32_t revidr)
    480  1.1  ryo {
    481  1.1  ryo 	printf("%s: revision: 0x%08x\n", cpuname, revidr);
    482  1.1  ryo }
    483  1.1  ryo 
    484  1.1  ryo /* MPIDR_EL1 - Multiprocessor Affinity Register */
    485  1.1  ryo static void
    486  1.1  ryo identify_mpidr(const char *cpuname, uint32_t mpidr)
    487  1.1  ryo {
    488  1.1  ryo 	const char *setname = "multiprocessor affinity";
    489  1.1  ryo 
    490  1.1  ryo 	printf("%s: %s: Affinity-Level: %"PRIu64"-%"PRIu64"-%"PRIu64"-%"PRIu64"\n",
    491  1.1  ryo 	    cpuname, setname,
    492  1.1  ryo 	    __SHIFTOUT(mpidr, MPIDR_AFF3),
    493  1.1  ryo 	    __SHIFTOUT(mpidr, MPIDR_AFF2),
    494  1.1  ryo 	    __SHIFTOUT(mpidr, MPIDR_AFF1),
    495  1.1  ryo 	    __SHIFTOUT(mpidr, MPIDR_AFF0));
    496  1.1  ryo 
    497  1.1  ryo 	if ((mpidr & MPIDR_U) == 0)
    498  1.1  ryo 		printf("%s: %s: Multiprocessor system\n", cpuname, setname);
    499  1.1  ryo 	else
    500  1.1  ryo 		printf("%s: %s: Uniprocessor system\n", cpuname, setname);
    501  1.1  ryo 
    502  1.1  ryo 	if ((mpidr & MPIDR_MT) == 0)
    503  1.1  ryo 		printf("%s: %s: Core Independent\n", cpuname, setname);
    504  1.1  ryo 	else
    505  1.1  ryo 		printf("%s: %s: Multi-Threading\n", cpuname, setname);
    506  1.1  ryo 
    507  1.1  ryo }
    508  1.1  ryo 
    509  1.1  ryo static void *
    510  1.1  ryo sysctlfetch(const char *sname, size_t *lenp)
    511  1.1  ryo {
    512  1.1  ryo 	size_t len;
    513  1.1  ryo 	void *data;
    514  1.1  ryo 
    515  1.1  ryo 	if (sysctlbyname(sname, NULL, &len, NULL, 0) != 0) {
    516  1.1  ryo 		warn("sysctlbyname: %s", sname);
    517  1.1  ryo 		return NULL;
    518  1.1  ryo 	}
    519  1.1  ryo 
    520  1.1  ryo 	data = malloc(len);
    521  1.1  ryo 	if (data == NULL) {
    522  1.1  ryo 		warn("malloc");
    523  1.1  ryo 		return NULL;
    524  1.1  ryo 	}
    525  1.1  ryo 
    526  1.1  ryo 	if (sysctlbyname(sname, data, &len, NULL, 0) != 0) {
    527  1.1  ryo 		warn("sysctlbyname: %s", sname);
    528  1.1  ryo 		free(data);
    529  1.1  ryo 		return NULL;
    530  1.1  ryo 	}
    531  1.1  ryo 
    532  1.1  ryo 	*lenp = len;
    533  1.1  ryo 	return data;
    534  1.1  ryo }
    535  1.1  ryo 
    536  1.1  ryo void
    537  1.1  ryo identifycpu(int fd, const char *cpuname)
    538  1.1  ryo {
    539  1.1  ryo 	void *regs;
    540  1.1  ryo 	size_t len;
    541  1.1  ryo 
    542  1.1  ryo 	/* MIDR_EL1 */
    543  1.1  ryo 	regs = sysctlfetch("machdep.cpu_id", &len);
    544  1.1  ryo 	if (regs != NULL) {
    545  1.1  ryo 		if (len >= sizeof(uint32_t))
    546  1.1  ryo 			identify_midr(cpuname, ((uint32_t *)regs)[0]);
    547  1.1  ryo 		free(regs);
    548  1.1  ryo 	}
    549  1.1  ryo 
    550  1.1  ryo 	/* REVIDR_EL1 */
    551  1.1  ryo 	regs = sysctlfetch("machdep.id_revidr", &len);
    552  1.1  ryo 	if (regs != NULL) {
    553  1.1  ryo 		if (len >= sizeof(uint32_t))
    554  1.1  ryo 			identify_revidr(cpuname, ((uint32_t *)regs)[0]);
    555  1.1  ryo 		free(regs);
    556  1.1  ryo 	}
    557  1.1  ryo 
    558  1.1  ryo 	/* MPIDR_EL1 */
    559  1.1  ryo 	regs = sysctlfetch("machdep.id_mpidr", &len);
    560  1.1  ryo 	if (regs != NULL) {
    561  1.1  ryo 		if (len >= sizeof(uint64_t))
    562  1.1  ryo 			identify_mpidr(cpuname, ((uint64_t *)regs)[0]);
    563  1.1  ryo 		free(regs);
    564  1.1  ryo 	}
    565  1.1  ryo 
    566  1.1  ryo 	/* ID_AA64ISAR0_EL1 */
    567  1.1  ryo 	regs = sysctlfetch("machdep.id_aa64isar", &len);
    568  1.1  ryo 	if (regs != NULL) {
    569  1.1  ryo 		if (len >= sizeof(uint64_t))
    570  1.1  ryo 			print_fieldinfo(cpuname, "isa features 0",
    571  1.1  ryo 			    id_aa64isar0_fieldinfo, ((uint64_t *)regs)[0]);
    572  1.1  ryo 		free(regs);
    573  1.1  ryo 	}
    574  1.1  ryo 
    575  1.1  ryo 	/* ID_AA64MMFR0_EL1 */
    576  1.1  ryo 	regs = sysctlfetch("machdep.id_aa64mmfr", &len);
    577  1.1  ryo 	if (regs != NULL) {
    578  1.1  ryo 		if (len >= sizeof(uint64_t))
    579  1.1  ryo 			print_fieldinfo(cpuname, "memory model 0",
    580  1.1  ryo 			    id_aa64mmfr0_fieldinfo, ((uint64_t *)regs)[0]);
    581  1.1  ryo 		free(regs);
    582  1.1  ryo 	}
    583  1.1  ryo 
    584  1.1  ryo 	/* ID_AA64PFR0_EL1 */
    585  1.1  ryo 	regs = sysctlfetch("machdep.id_aa64pfr", &len);
    586  1.1  ryo 	if (regs != NULL) {
    587  1.1  ryo 		if (len >= sizeof(uint64_t))
    588  1.1  ryo 			print_fieldinfo(cpuname, "processor feature 0",
    589  1.1  ryo 			    id_aa64pfr0_fieldinfo, ((uint64_t *)regs)[0]);
    590  1.1  ryo 		free(regs);
    591  1.1  ryo 	}
    592  1.1  ryo 
    593  1.1  ryo 	/* MVFR[012]_EL1 */
    594  1.1  ryo 	regs = sysctlfetch("machdep.id_mvfr", &len);
    595  1.1  ryo 	if (regs != NULL) {
    596  1.1  ryo 		if (len >= sizeof(uint32_t))
    597  1.1  ryo 			print_fieldinfo(cpuname, "media and VFP features 0",
    598  1.1  ryo 			    mvfr0_fieldinfo, ((uint32_t *)regs)[0]);
    599  1.1  ryo 		if (len >= sizeof(uint32_t) * 2)
    600  1.1  ryo 			print_fieldinfo(cpuname, "media and VFP features 1",
    601  1.1  ryo 			    mvfr1_fieldinfo, ((uint32_t *)regs)[1]);
    602  1.1  ryo 		if (len >= sizeof(uint32_t) * 3)
    603  1.1  ryo 			print_fieldinfo(cpuname, "media and VFP features 2",
    604  1.1  ryo 			    mvfr2_fieldinfo, ((uint32_t *)regs)[2]);
    605  1.1  ryo 		free(regs);
    606  1.1  ryo 	}
    607  1.1  ryo }
    608  1.1  ryo 
    609  1.1  ryo bool
    610  1.1  ryo identifycpu_bind(void)
    611  1.1  ryo {
    612  1.1  ryo 	return true;
    613  1.1  ryo }
    614  1.1  ryo 
    615  1.1  ryo int
    616  1.1  ryo ucodeupdate_check(int fd, struct cpu_ucode *uc)
    617  1.1  ryo {
    618  1.1  ryo 	return 0;
    619  1.1  ryo }
    620