dmidecode 1.0.1

Decode SMBIOS/DMI information into accessible data structures
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
//! Processor Information (Type 4)
//!
//! The information in this structure defines the attributes of a single processor; a separate
//! structure instance is provided for each system processor socket/slot. For example, a system
//! with an IntelDX2™ processor would have a single structure instance while a system with an
//! IntelSX2™ processor would have a structure to describe the main CPU and a second structure to
//! describe the 80487 co1021 processor.

use core::fmt;

use bitflags::bitflags;

use crate::{MalformedStructureError, RawStructure};

/// The processor types defined in the SMBIOS specification.
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum ProcessorType {
    Other,
    Unknown,
    CentralProcessor,
    MathProcessor,
    DspProcessor,
    VideoProcessor,
    Undefined(u8),
}

impl From<u8> for ProcessorType {
    fn from(_type: u8) -> ProcessorType {
        match _type {
            1 => ProcessorType::Other,
            2 => ProcessorType::Unknown,
            3 => ProcessorType::CentralProcessor,
            4 => ProcessorType::MathProcessor,
            5 => ProcessorType::DspProcessor,
            6 => ProcessorType::VideoProcessor,
            t => ProcessorType::Undefined(t),
        }
    }
}

bitflags! {
    /// The processor status flags defined in the SMBIOS specification.
    #[derive(Debug, Clone, PartialEq, Eq, Hash)]
    pub struct ProcessorStatus: u8 {
        const CPU_SOCKET_POPULATED = 0b0100_0000;
        const CPU_ENABLED = 0b0000_0001;
        const CPU_DISABLED_BY_USER = 0b0000_0010;
        const CPU_DISABLED_BY_BIOS = 0b0000_0011;
        const CPU_IDLE = 0b0000_0100;
        const CPU_OTHER = 0b000_0111;
    }
}

bitflags! {
    /// The processor characteristic flags defined in the SMBIOS specification.
    #[derive(Debug, Clone, PartialEq, Eq, Hash)]
    pub struct ProcessorCharacteristics: u16 {
        const RESERVED = 0b0000_0001;
        const UNKNOWN = 0b0000_0010;
        const CAPABLE_64BIT = 0b0000_0100;
        const MULTICORE = 0b0000_1000;
        const HARDWARE_THREAD = 0b0001_0000;
        const EXECUTE_PROTECTION = 0b0010_0000;
        const ENHANCED_VIRTUALIZATION = 0b0100_0000;
        const POWER_PERFORMANCE_CONTROL = 0b1000_0000;
        const ARM64_SOC_ID = 0b0000_0010_0000_0000;
    }
}

/// The `Processor` table defined in the SMBIOS specification.
///
/// Optional fields will only be set if the version of the parsed SMBIOS table
/// is high enough to have defined the field.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Processor<'buffer> {
    pub handle: u16,
    /// String number for Reference Designation EXAMPLE: ‘J202’,0
    pub socket_designation: &'buffer str,
    /// Processor Type field
    pub processor_type: ProcessorType,
    /// Processor Family field
    pub processor_family: ProcessorFamily,
    /// String number of Processor Manufacturer
    pub processor_manufacturer: &'buffer str,
    /// Raw processor identification data
    pub processor_id: u64,
    /// String number describing the Processor
    pub processor_version: &'buffer str,
    /// Voltage
    pub voltage: Voltage,
    /// External Clock Frequency, in MHz. If the value is unknown, the field is set to 0.
    pub external_clock: u16,
    /// Maximum processor speed (in MHz) supported by the system for this processor socket
    pub max_speed: u16,
    /// This field identifies the processor's speed at system boot; the processor may support more
    /// than one speed.
    pub current_speed: u16,
    /// Status
    pub status: ProcessorStatus,
    /// Processor Upgrade field
    pub processor_upgrade: ProcessorUpgrade,
    /// Handle of a Cache Information structure that defines the attributes of the primary
    /// (Level 1) cache for this processor
    pub l1_cache_handle: Option<u16>,
    /// Handle of a Cache Information structure that defines the attributes of the secondary
    /// (Level 2) cache for this processor
    pub l2_cache_handle: Option<u16>,
    /// Handle of a Cache Information structure that defines the attributes of the tertiary
    /// (Level 3) cache for this processor
    pub l3_cache_handle: Option<u16>,
    /// String number for the serial number of this processor
    pub serial_number: Option<&'buffer str>,
    /// String number for the asset tag of this processor
    pub asset_tag: Option<&'buffer str>,
    /// String number for the part number of this processor
    pub part_number: Option<&'buffer str>,
    /// Number of cores per processor socket
    pub core_count: Option<u16>,
    /// Number of enabled cores per processor socket
    pub core_enabled: Option<u16>,
    /// Number of threads per processor socket
    pub thread_count: Option<u16>,
    /// Defines which functions the processor supports
    pub processor_characteristics: Option<ProcessorCharacteristics>,
}

/// For processor family enumerations from 0 to FDh, *Processor Family* is identical to *Processor Family 2*.
/// For processor family enumerations from 100h to FFFDh, *Processor Family* has a value of FEh
/// and *Processor Family 2* has the enumerated value.
/// The following values are reserved:
/// • FFh Not used. FFh is the un-initialized value of Flash memory.
/// • FFFFh Not used. FFFFh is the un-initialized value of Flash memory.
/// • FFFEh For special use in the future, such as FEh as the extension indicator.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum ProcessorFamily {
    Other,
    Unknown,
    Intel8086,
    Intel80286,
    Intel386Processor,
    Intel486Processor,
    Intel8087,
    Intel80287,
    Intel80387,
    Intel80487,
    IntelPentiumProcessor,
    PentiumProProcessor,
    PentiumIIProcessor,
    PentiumProcessorWithMMXTechnology,
    IntelCeleronProcessor,
    PentiumIIXeonProcessor,
    PentiumIIIProcessor,
    M1Family,
    M2Family,
    IntelCeleronMProcessor,
    IntelPentium4HTProcessor,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    AMDDuronProcessorFamily,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    K5Family,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    K6Family,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    K62,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    K63,
    /// Note that the meaning associated with this value is different from the meaning defined in
    /// CIM_Processor.Family for the same value.
    AMDAthlonProcessorFamily,
    AMD29000Family,
    K62Plus,
    PowerPCFamily,
    PowerPC601,
    PowerPC603,
    PowerPC603Plus,
    PowerPC604,
    PowerPC620,
    PowerPCX704,
    PowerPC750,
    IntelCoreDuoProcessor,
    IntelCoreDuoMobileProcessor,
    IntelCoreSoloMobileProcessor,
    IntelAtomProcessor,
    IntelCoreMProcessor,
    IntelCoreM3Processor,
    IntelCoreM5Processor,
    IntelCoreM7Processor,
    /// Some version 2.0 specification implementations used Processor Family type value 30h to
    /// represent a Pentium® Pro processor.
    AlphaFamily,
    Alpha21064,
    Alpha21066,
    Alpha21164,
    Alpha21164PC,
    Alpha21164a,
    Alpha21264,
    Alpha21364,
    AMDTurionIIUltraDualCoreMobileMProcessorFamily,
    AMDTurionIIDualCoreMobileMProcessorFamily,
    AMDAthlonIIDualCoreMProcessorFamily,
    AMDOpteron6100SeriesProcessor,
    AMDOpteron4100SeriesProcessor,
    AMDOpteron6200SeriesProcessor,
    AMDOpteron4200SeriesProcessor,
    AMDFXSeriesProcessor,
    MIPSFamily,
    MIPSR4000,
    MIPSR4200,
    MIPSR4400,
    MIPSR4600,
    MIPSR10000,
    AMDCSeriesProcessor,
    AMDESeriesProcessor,
    AMDASeriesProcessor,
    AMDGSeriesProcessor,
    AMDZSeriesProcessor,
    AMDRSeriesProcessor,
    AMDOpteron4300SeriesProcessor,
    AMDOpteron6300SeriesProcessor,
    AMDOpteron3300SeriesProcessor,
    AMDFireProSeriesProcessor,
    SPARCFamily,
    SuperSPARC,
    MicroSPARCII,
    MicroSPARCIIep,
    UltraSPARC,
    UltraSPARCII,
    UltraSPARCIii,
    UltraSPARCIII,
    UltraSPARCIIIi,
    Motorola68040Family,
    Motorola68xxx,
    Motorola68000,
    Motorola68010,
    Motorola68020,
    Motorola68030,
    AMDAthlonX4QuadCoreProcessorFamily,
    AMDOpteronX1000SeriesProcessor,
    AMDOpteronX2000SeriesAPU,
    AMDOpteronASeriesProcessor,
    AMDOpteronX3000SeriesAPU,
    AMDZenProcessorFamily,
    HobbitFamily,
    CrusoeTM5000Family,
    CrusoeTM3000Family,
    EfficeonTM8000Family,
    Weitek,
    AvailableForAssignment,
    ItaniumProcessor,
    AMDAthlon64ProcessorFamily,
    AMDOpteronProcessorFamily,
    AMDSempronProcessorFamily,
    AMDTurion64MobileTechnology,
    DualCoreAMDOpteronProcessorFamily,
    AMDAthlon64X2DualCoreProcessorFamily,
    AMDTurion64X2MobileTechnology,
    QuadCoreAMDOpteronProcessorFamily,
    ThirdGenerationAMDOpteronProcessorFamily,
    AMDPhenomFXQuadCoreProcessorFamily,
    AMDPhenomX4QuadCoreProcessorFamily,
    AMDPhenomX2DualCoreProcessorFamily,
    AMDAthlonX2DualCoreProcessorFamily,
    PARISCFamily,
    PARISC8500,
    PARISC8000,
    PARISC7300LC,
    PARISC7200,
    PARISC7100LC,
    PARISC7100,
    V30Family,
    QuadCoreIntelXeonProcessor3200Series,
    DualCoreIntelXeonProcessor3000Series,
    QuadCoreIntelXeonProcessor5300Series,
    DualCoreIntelXeonProcessor5100Series,
    DualCoreIntelXeonProcessor5000Series,
    DualCoreIntelXeonProcessorLV,
    DualCoreIntelXeonProcessorULV,
    DualCoreIntelXeonProcessor7100Series,
    QuadCoreIntelXeonProcessor5400Series,
    QuadCoreIntelXeonProcessor,
    DualCoreIntelXeonProcessor5200Series,
    DualCoreIntelXeonProcessor7200Series,
    QuadCoreIntelXeonProcessor7300Series,
    QuadCoreIntelXeonProcessor7400Series,
    MultiCoreIntelXeonProcessor7400Series,
    PentiumIIIXeonProcessor,
    PentiumIIIProcessorWithIntelSpeedStepTechnology,
    Pentium4Processor,
    IntelXeonProcessor,
    AS400Family,
    IntelXeonProcessorMP,
    AMDAthlonXPProcessorFamily,
    AMDAthlonMPProcessorFamily,
    IntelItanium2Processor,
    IntelPentiumMProcessor,
    IntelCeleronDProcessor,
    IntelPentiumDProcessor,
    IntelPentiumProcessorExtremeEdition,
    IntelCoreSoloProcessor,
    /// Version 2.5 of this specification listed this value as “available for assignment”.
    /// CIM_Processor.mof files assigned this value to AMD K7 processors in the
    /// CIM_Processor.Family property, and an SMBIOS change request assigned it to Intel Core 2
    /// processors. Some implementations of the SMBIOS version 2.5 specification are known to use
    /// BEh to indicate Intel Core 2 processors. Some implementations of SMBIOS and some
    /// implementations of CIM-based software may also have used BEh to indicate AMD K7 processors.
    Ambiguous,
    IntelCore2DuoProcessor,
    IntelCore2SoloProcessor,
    IntelCore2ExtremeProcessor,
    IntelCore2QuadProcessor,
    IntelCore2ExtremeMobileProcessor,
    IntelCore2DuoMobileProcessor,
    IntelCore2SoloMobileProcessor,
    IntelCoreI7Processor,
    DualCoreIntelCeleronProcessor,
    IBM390Family,
    G4,
    G5,
    ESA390G6,
    ZArchitectureBase,
    IntelCoreI5Processor,
    IntelCoreI3Processor,
    IntelCoreI9Processor,
    VIAC7MProcessorFamily,
    VIAC7DProcessorFamily,
    VIAC7ProcessorFamily,
    VIAEdenProcessorFamily,
    MultiCoreIntelXeonProcessor,
    DualCoreIntelXeonProcessor3xxxSeries,
    QuadCoreIntelXeonProcessor3xxxSeries,
    VIANanoProcessorFamily,
    DualCoreIntelXeonProcessor5xxxSeries,
    QuadCoreIntelXeonProcessor5xxxSeries,
    DualCoreIntelXeonProcessor7xxxSeries,
    QuadCoreIntelXeonProcessor7xxxSeries,
    MultiCoreIntelXeonProcessor7xxxSeries,
    MultiCoreIntelXeonProcessor3400Series,
    AMDOpteron3000SeriesProcessor,
    AMDSempronIIProcessor,
    EmbeddedAMDOpteronQuadCoreProcessorFamily,
    AMDPhenomTripleCoreProcessorFamily,
    AMDTurionUltraDualCoreMobileProcessorFamily,
    AMDTurionDualCoreMobileProcessorFamily,
    AMDAthlonDualCoreProcessorFamily,
    AMDSempronSIProcessorFamily,
    AMDPhenomIIProcessorFamily,
    AMDAthlonIIProcessorFamily,
    SixCoreAMDOpteronProcessorFamily,
    AMDSempronMProcessorFamily,
    I860,
    I960,
    ARMv7,
    ARMv8,
    ARMv9,
    SH3,
    SH4,
    ARM,
    StrongARM,
    Cyrix6x86,
    MediaGX,
    MII,
    WinChip,
    DSP,
    VideoProcessor,
    RISCVRV32,
    RISCVRV64,
    RISCVRV128,
    Available(u16),
    NotUsed(u16),
    ForFutureUse,
    ProcessorFamily2,
    OutOfSpec,
}

/// Two forms of information can be specified by the SMBIOS in this field, dependent on the value
/// present in bit 7 (the most-significant bit). If bit 7 is 0 (legacy mode), the remaining bits of
/// the field represent the specific voltages that the processor socket can accept. If bit 7 is set
/// to 1, the remaining seven bits of the field are set to contain the processor’s current voltage
/// times 10.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum Voltage {
    Legacy(VoltageLegacy),
    Current(u8),
    Undefined(u8),
}

bitflags! {
    /// Voltage Capability. A set bit indicates that the voltage is supported
    #[derive(Debug, Clone, PartialEq, Eq, Hash)]
    pub struct VoltageLegacy: u8 {
        const VOLTAGE_CAPABILITY_5V0  = 0b0000_0001;
        const VOLTAGE_CAPABILITY_3V3  = 0b0000_0010;
        const VOLTAGE_CAPABILITY_2V9  = 0b0000_0100;
    }
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ProcessorUpgrade {
    Other,
    Unknown,
    DaughterBoard,
    ZIFSocket,
    ReplaceablePiggyBack,
    None,
    LIFSocket,
    Slot1,
    Slot2,
    Socket370,
    SlotA,
    SlotM,
    Socket423,
    SocketA,
    Socket478,
    Socket754,
    Socket940,
    Socket939,
    SocketmPGA604,
    SocketLGA771,
    SocketLGA775,
    SocketS1,
    SocketAM2,
    SocketF,
    SocketLGA1366,
    SocketG34,
    SocketAM3,
    SocketC32,
    SocketLGA1156,
    SocketLGA1567,
    SocketPGA988A,
    SocketBGA1288,
    SocketrPGA988B,
    SocketBGA1023,
    SocketBGA1224,
    SocketLGA1155,
    SocketLGA1356,
    SocketLGA2011,
    SocketFS1,
    SocketFS2,
    SocketFM1,
    SocketFM2,
    SocketLGA2011Three,
    SocketLGA1356Three,
    SocketLGA1150,
    SocketBGA1168,
    SocketBGA1234,
    SocketBGA1364,
    SocketAM4,
    SocketLGA1151,
    SocketBGA1356,
    SocketBGA1440,
    SocketBGA1515,
    SocketLGA3647,
    SocketSP3,
    SocketSP3r2,
    SocketLGA2066,
    SocketBGA1392,
    SocketBGA1510,
    SocketBGA1528,
    SocketLGA4189,
    SocketLGA1200,
    Undefined(u8),
}

impl<'buffer> Processor<'buffer> {
    pub(crate) fn try_from(structure: RawStructure<'buffer>) -> Result<Processor<'buffer>, MalformedStructureError> {
        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked2_0 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
        }

        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked2_1 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
            l1_cache_handle: u16,
            l2_cache_handle: u16,
            l3_cache_handle: u16,
        }

        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked2_3 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
            l1_cache_handle: u16,
            l2_cache_handle: u16,
            l3_cache_handle: u16,
            serial_number: u8,
            asset_tag: u8,
            part_number: u8,
        }

        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked2_5 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
            l1_cache_handle: u16,
            l2_cache_handle: u16,
            l3_cache_handle: u16,
            serial_number: u8,
            asset_tag: u8,
            part_number: u8,
            core_count: u8,
            core_enabled: u8,
            thread_count: u8,
            processor_characteristics: u16,
        }

        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked2_6 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
            l1_cache_handle: u16,
            l2_cache_handle: u16,
            l3_cache_handle: u16,
            serial_number: u8,
            asset_tag: u8,
            part_number: u8,
            core_count: u8,
            core_enabled: u8,
            thread_count: u8,
            processor_characteristics: u16,
            processor_family_2: u16,
        }

        #[repr(C)]
        #[repr(packed)]
        struct ProcessorPacked3_0 {
            socket_designation: u8,
            processor_type: u8,
            processor_family: u8,
            processor_manufacturer: u8,
            processor_id: u64,
            processor_version: u8,
            voltage: u8,
            external_clock: u16,
            max_speed: u16,
            current_speed: u16,
            status: u8,
            processor_upgrade: u8,
            l1_cache_handle: u16,
            l2_cache_handle: u16,
            l3_cache_handle: u16,
            serial_number: u8,
            asset_tag: u8,
            part_number: u8,
            core_count: u8,
            core_enabled: u8,
            thread_count: u8,
            processor_characteristics: u16,
            processor_family_2: u16,
            core_count_2: u16,
            core_enabled_2: u16,
            thread_count_2: u16,
        }

        if structure.version < (2, 1).into() {
            let_as_struct!(packed, ProcessorPacked2_0, structure.data);

            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family: packed.processor_family.into(),
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: None,
                l2_cache_handle: None,
                l3_cache_handle: None,
                serial_number: None,
                asset_tag: None,
                part_number: None,
                core_count: None,
                core_enabled: None,
                thread_count: None,
                processor_characteristics: None,
            })
        } else if structure.version < (2, 3).into() {
            let_as_struct!(packed, ProcessorPacked2_1, structure.data);

            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family: packed.processor_family.into(),
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: Some(u16::from_le(packed.l1_cache_handle)),
                l2_cache_handle: Some(u16::from_le(packed.l2_cache_handle)),
                l3_cache_handle: Some(u16::from_le(packed.l3_cache_handle)),
                serial_number: None,
                asset_tag: None,
                part_number: None,
                core_count: None,
                core_enabled: None,
                thread_count: None,
                processor_characteristics: None,
            })
        } else if structure.version < (2, 5).into() {
            let_as_struct!(packed, ProcessorPacked2_3, structure.data);

            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family: packed.processor_family.into(),
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: Some(u16::from_le(packed.l1_cache_handle)),
                l2_cache_handle: Some(u16::from_le(packed.l2_cache_handle)),
                l3_cache_handle: Some(u16::from_le(packed.l3_cache_handle)),
                serial_number: Some(structure.find_string(packed.serial_number)?),
                asset_tag: Some(structure.find_string(packed.asset_tag)?),
                part_number: Some(structure.find_string(packed.part_number)?),
                core_count: None,
                core_enabled: None,
                thread_count: None,
                processor_characteristics: None,
            })
        } else if structure.version < (2, 6).into() {
            let_as_struct!(packed, ProcessorPacked2_5, structure.data);

            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family: packed.processor_family.into(),
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: Some(u16::from_le(packed.l1_cache_handle)),
                l2_cache_handle: Some(u16::from_le(packed.l2_cache_handle)),
                l3_cache_handle: Some(u16::from_le(packed.l3_cache_handle)),
                serial_number: Some(structure.find_string(packed.serial_number)?),
                asset_tag: Some(structure.find_string(packed.asset_tag)?),
                part_number: Some(structure.find_string(packed.part_number)?),
                core_count: Some(packed.core_count as u16),
                core_enabled: Some(packed.core_enabled as u16),
                thread_count: Some(packed.thread_count as u16),
                processor_characteristics: None,
            })
        } else if structure.version < (3, 0).into() {
            let_as_struct!(packed, ProcessorPacked2_6, structure.data);
            // smbios spec specifies 0xFE as an indicator to obtain processor
            // family from the Processor Family 2 field.
            let processor_family = match packed.processor_family.into() {
                ProcessorFamily::ProcessorFamily2 => u16::from_le(packed.processor_family_2).into(),
                family => family,
            };
            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family,
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: Some(u16::from_le(packed.l1_cache_handle)),
                l2_cache_handle: Some(u16::from_le(packed.l2_cache_handle)),
                l3_cache_handle: Some(u16::from_le(packed.l3_cache_handle)),
                serial_number: Some(structure.find_string(packed.serial_number)?),
                asset_tag: Some(structure.find_string(packed.asset_tag)?),
                part_number: Some(structure.find_string(packed.part_number)?),
                core_count: Some(packed.core_count as u16),
                core_enabled: Some(packed.core_enabled as u16),
                thread_count: Some(packed.thread_count as u16),
                processor_characteristics: Some(ProcessorCharacteristics::from_bits_truncate(u16::from_le(
                    packed.processor_characteristics,
                ))),
            })
        } else {
            let_as_struct!(packed, ProcessorPacked3_0, structure.data);
            // smbios spec specifies 0xFE as an indicator to obtain processor
            // family from the Processor Family 2 field.
            let processor_family = match packed.processor_family.into() {
                ProcessorFamily::ProcessorFamily2 => u16::from_le(packed.processor_family_2).into(),
                family => family,
            };

            // The Core Count 2 field supports core counts > 255. For core counts of 256 or greater, the Core Count
            // field is set to FFh and the Core Count 2 field is set to the number of cores. For core counts of 255 or
            // fewer, if Core Count 2 is present it shall be set the same value as Core Count
            //
            // The rule is same for Core Enabled and Thread Count as well.
            let core_count = if packed.core_count == 0xFF {
                Some(u16::from_le(packed.core_count_2))
            } else {
                Some(packed.core_count as u16)
            };
            let core_enabled = if packed.core_enabled == 0xFF {
                Some(u16::from_le(packed.core_enabled_2))
            } else {
                Some(packed.core_enabled as u16)
            };
            let thread_count = if packed.thread_count == 0xFF {
                Some(u16::from_le(packed.thread_count_2))
            } else {
                Some(packed.thread_count as u16)
            };
            Ok(Processor {
                handle: structure.handle,
                socket_designation: structure.find_string(packed.socket_designation)?,
                processor_type: packed.processor_type.into(),
                processor_family,
                processor_manufacturer: structure.find_string(packed.processor_manufacturer)?,
                processor_id: u64::from_le(packed.processor_id),
                processor_version: structure.find_string(packed.processor_version)?,
                voltage: packed.voltage.into(),
                external_clock: u16::from_le(packed.external_clock),
                max_speed: u16::from_le(packed.max_speed),
                current_speed: u16::from_le(packed.current_speed),
                status: ProcessorStatus::from_bits_truncate(packed.status),
                processor_upgrade: packed.processor_upgrade.into(),
                l1_cache_handle: Some(u16::from_le(packed.l1_cache_handle)),
                l2_cache_handle: Some(u16::from_le(packed.l2_cache_handle)),
                l3_cache_handle: Some(u16::from_le(packed.l3_cache_handle)),
                serial_number: Some(structure.find_string(packed.serial_number)?),
                asset_tag: Some(structure.find_string(packed.asset_tag)?),
                part_number: Some(structure.find_string(packed.part_number)?),
                core_count,
                core_enabled,
                thread_count,
                processor_characteristics: Some(ProcessorCharacteristics::from_bits_truncate(u16::from_le(
                    packed.processor_characteristics,
                ))),
            })
        }
    }
}

impl From<u8> for ProcessorFamily {
    fn from(byte: u8) -> ProcessorFamily {
        ProcessorFamily::from(byte as u16)
    }
}

impl From<u16> for ProcessorFamily {
    fn from(word: u16) -> Self {
        match word {
            0x00 => ProcessorFamily::OutOfSpec,
            0x01 => ProcessorFamily::Other,
            0x02 => ProcessorFamily::Unknown,
            0x03 => ProcessorFamily::Intel8086,
            0x04 => ProcessorFamily::Intel80286,
            0x05 => ProcessorFamily::Intel386Processor,
            0x06 => ProcessorFamily::Intel486Processor,
            0x07 => ProcessorFamily::Intel8087,
            0x08 => ProcessorFamily::Intel80287,
            0x09 => ProcessorFamily::Intel80387,
            0x0A => ProcessorFamily::Intel80487,
            0x0B => ProcessorFamily::IntelPentiumProcessor,
            0x0C => ProcessorFamily::PentiumProProcessor,
            0x0D => ProcessorFamily::PentiumIIProcessor,
            0x0E => ProcessorFamily::PentiumProcessorWithMMXTechnology,
            0x0F => ProcessorFamily::IntelCeleronProcessor,
            0x10 => ProcessorFamily::PentiumIIXeonProcessor,
            0x11 => ProcessorFamily::PentiumIIIProcessor,
            0x12 => ProcessorFamily::M1Family,
            0x13 => ProcessorFamily::M2Family,
            0x14 => ProcessorFamily::IntelCeleronMProcessor,
            0x15 => ProcessorFamily::IntelPentium4HTProcessor,
            n @ 0x16..=0x17 => ProcessorFamily::Available(n),
            0x18 => ProcessorFamily::AMDDuronProcessorFamily,
            0x19 => ProcessorFamily::K5Family,
            0x1A => ProcessorFamily::K6Family,
            0x1B => ProcessorFamily::K62,
            0x1C => ProcessorFamily::K63,
            0x1D => ProcessorFamily::AMDAthlonProcessorFamily,
            0x1E => ProcessorFamily::AMD29000Family,
            0x1F => ProcessorFamily::K62Plus,
            0x20 => ProcessorFamily::PowerPCFamily,
            0x21 => ProcessorFamily::PowerPC601,
            0x22 => ProcessorFamily::PowerPC603,
            0x23 => ProcessorFamily::PowerPC603Plus,
            0x24 => ProcessorFamily::PowerPC604,
            0x25 => ProcessorFamily::PowerPC620,
            0x26 => ProcessorFamily::PowerPCX704,
            0x27 => ProcessorFamily::PowerPC750,
            0x28 => ProcessorFamily::IntelCoreDuoProcessor,
            0x29 => ProcessorFamily::IntelCoreDuoMobileProcessor,
            0x2A => ProcessorFamily::IntelCoreSoloMobileProcessor,
            0x2B => ProcessorFamily::IntelAtomProcessor,
            0x2C => ProcessorFamily::IntelCoreMProcessor,
            0x2D => ProcessorFamily::IntelCoreM3Processor,
            0x2E => ProcessorFamily::IntelCoreM5Processor,
            0x2F => ProcessorFamily::IntelCoreM7Processor,
            0x30 => ProcessorFamily::AlphaFamily,
            0x31 => ProcessorFamily::Alpha21064,
            0x32 => ProcessorFamily::Alpha21066,
            0x33 => ProcessorFamily::Alpha21164,
            0x34 => ProcessorFamily::Alpha21164PC,
            0x35 => ProcessorFamily::Alpha21164a,
            0x36 => ProcessorFamily::Alpha21264,
            0x37 => ProcessorFamily::Alpha21364,
            0x38 => ProcessorFamily::AMDTurionIIUltraDualCoreMobileMProcessorFamily,
            0x39 => ProcessorFamily::AMDTurionIIDualCoreMobileMProcessorFamily,
            0x3A => ProcessorFamily::AMDAthlonIIDualCoreMProcessorFamily,
            0x3B => ProcessorFamily::AMDOpteron6100SeriesProcessor,
            0x3C => ProcessorFamily::AMDOpteron4100SeriesProcessor,
            0x3D => ProcessorFamily::AMDOpteron6200SeriesProcessor,
            0x3E => ProcessorFamily::AMDOpteron4200SeriesProcessor,
            0x3F => ProcessorFamily::AMDFXSeriesProcessor,
            0x40 => ProcessorFamily::MIPSFamily,
            0x41 => ProcessorFamily::MIPSR4000,
            0x42 => ProcessorFamily::MIPSR4200,
            0x43 => ProcessorFamily::MIPSR4400,
            0x44 => ProcessorFamily::MIPSR4600,
            0x45 => ProcessorFamily::MIPSR10000,
            0x46 => ProcessorFamily::AMDCSeriesProcessor,
            0x47 => ProcessorFamily::AMDESeriesProcessor,
            0x48 => ProcessorFamily::AMDASeriesProcessor,
            0x49 => ProcessorFamily::AMDGSeriesProcessor,
            0x4A => ProcessorFamily::AMDZSeriesProcessor,
            0x4B => ProcessorFamily::AMDRSeriesProcessor,
            0x4C => ProcessorFamily::AMDOpteron4300SeriesProcessor,
            0x4D => ProcessorFamily::AMDOpteron6300SeriesProcessor,
            0x4E => ProcessorFamily::AMDOpteron3300SeriesProcessor,
            0x4F => ProcessorFamily::AMDFireProSeriesProcessor,
            0x50 => ProcessorFamily::SPARCFamily,
            0x51 => ProcessorFamily::SuperSPARC,
            0x52 => ProcessorFamily::MicroSPARCII,
            0x53 => ProcessorFamily::MicroSPARCIIep,
            0x54 => ProcessorFamily::UltraSPARC,
            0x55 => ProcessorFamily::UltraSPARCII,
            0x56 => ProcessorFamily::UltraSPARCIii,
            0x57 => ProcessorFamily::UltraSPARCIII,
            0x58 => ProcessorFamily::UltraSPARCIIIi,
            n @ 0x59..=0x5F => ProcessorFamily::Available(n),
            0x60 => ProcessorFamily::Motorola68040Family,
            0x61 => ProcessorFamily::Motorola68xxx,
            0x62 => ProcessorFamily::Motorola68000,
            0x63 => ProcessorFamily::Motorola68010,
            0x64 => ProcessorFamily::Motorola68020,
            0x65 => ProcessorFamily::Motorola68030,
            0x66 => ProcessorFamily::AMDAthlonX4QuadCoreProcessorFamily,
            0x67 => ProcessorFamily::AMDOpteronX1000SeriesProcessor,
            0x68 => ProcessorFamily::AMDOpteronX2000SeriesAPU,
            0x69 => ProcessorFamily::AMDOpteronASeriesProcessor,
            0x6A => ProcessorFamily::AMDOpteronX3000SeriesAPU,
            0x6B => ProcessorFamily::AMDZenProcessorFamily,
            n @ 0x6C..=0x6F => ProcessorFamily::Available(n),
            0x70 => ProcessorFamily::HobbitFamily,
            n @ 0x71..=0x77 => ProcessorFamily::Available(n),
            0x78 => ProcessorFamily::CrusoeTM5000Family,
            0x79 => ProcessorFamily::CrusoeTM3000Family,
            0x7A => ProcessorFamily::EfficeonTM8000Family,
            n @ 0x7B..=0x7F => ProcessorFamily::Available(n),
            0x80 => ProcessorFamily::Weitek,
            n @ 0x81 => ProcessorFamily::Available(n),
            0x82 => ProcessorFamily::ItaniumProcessor,
            0x83 => ProcessorFamily::AMDAthlon64ProcessorFamily,
            0x84 => ProcessorFamily::AMDOpteronProcessorFamily,
            0x85 => ProcessorFamily::AMDSempronProcessorFamily,
            0x86 => ProcessorFamily::AMDTurion64MobileTechnology,
            0x87 => ProcessorFamily::DualCoreAMDOpteronProcessorFamily,
            0x88 => ProcessorFamily::AMDAthlon64X2DualCoreProcessorFamily,
            0x89 => ProcessorFamily::AMDTurion64X2MobileTechnology,
            0x8A => ProcessorFamily::QuadCoreAMDOpteronProcessorFamily,
            0x8B => ProcessorFamily::ThirdGenerationAMDOpteronProcessorFamily,
            0x8C => ProcessorFamily::AMDPhenomFXQuadCoreProcessorFamily,
            0x8D => ProcessorFamily::AMDPhenomX4QuadCoreProcessorFamily,
            0x8E => ProcessorFamily::AMDPhenomX2DualCoreProcessorFamily,
            0x8F => ProcessorFamily::AMDAthlonX2DualCoreProcessorFamily,
            0x90 => ProcessorFamily::PARISCFamily,
            0x91 => ProcessorFamily::PARISC8500,
            0x92 => ProcessorFamily::PARISC8000,
            0x93 => ProcessorFamily::PARISC7300LC,
            0x94 => ProcessorFamily::PARISC7200,
            0x95 => ProcessorFamily::PARISC7100LC,
            0x96 => ProcessorFamily::PARISC7100,
            n @ 0x97..=0x9F => ProcessorFamily::Available(n),
            0xA0 => ProcessorFamily::V30Family,
            0xA1 => ProcessorFamily::QuadCoreIntelXeonProcessor3200Series,
            0xA2 => ProcessorFamily::DualCoreIntelXeonProcessor3000Series,
            0xA3 => ProcessorFamily::QuadCoreIntelXeonProcessor5300Series,
            0xA4 => ProcessorFamily::DualCoreIntelXeonProcessor5100Series,
            0xA5 => ProcessorFamily::DualCoreIntelXeonProcessor5000Series,
            0xA6 => ProcessorFamily::DualCoreIntelXeonProcessorLV,
            0xA7 => ProcessorFamily::DualCoreIntelXeonProcessorULV,
            0xA8 => ProcessorFamily::DualCoreIntelXeonProcessor7100Series,
            0xA9 => ProcessorFamily::QuadCoreIntelXeonProcessor5400Series,
            0xAA => ProcessorFamily::QuadCoreIntelXeonProcessor,
            0xAB => ProcessorFamily::DualCoreIntelXeonProcessor5200Series,
            0xAC => ProcessorFamily::DualCoreIntelXeonProcessor7200Series,
            0xAD => ProcessorFamily::QuadCoreIntelXeonProcessor7300Series,
            0xAE => ProcessorFamily::QuadCoreIntelXeonProcessor7400Series,
            0xAF => ProcessorFamily::MultiCoreIntelXeonProcessor7400Series,
            0xB0 => ProcessorFamily::PentiumIIIXeonProcessor,
            0xB1 => ProcessorFamily::PentiumIIIProcessorWithIntelSpeedStepTechnology,
            0xB2 => ProcessorFamily::Pentium4Processor,
            0xB3 => ProcessorFamily::IntelXeonProcessor,
            0xB4 => ProcessorFamily::AS400Family,
            0xB5 => ProcessorFamily::IntelXeonProcessorMP,
            0xB6 => ProcessorFamily::AMDAthlonXPProcessorFamily,
            0xB7 => ProcessorFamily::AMDAthlonMPProcessorFamily,
            0xB8 => ProcessorFamily::IntelItanium2Processor,
            0xB9 => ProcessorFamily::IntelPentiumMProcessor,
            0xBA => ProcessorFamily::IntelCeleronDProcessor,
            0xBB => ProcessorFamily::IntelPentiumDProcessor,
            0xBC => ProcessorFamily::IntelPentiumProcessorExtremeEdition,
            0xBD => ProcessorFamily::IntelCoreSoloProcessor,
            0xBE => ProcessorFamily::Ambiguous,
            0xBF => ProcessorFamily::IntelCore2DuoProcessor,
            0xC0 => ProcessorFamily::IntelCore2SoloProcessor,
            0xC1 => ProcessorFamily::IntelCore2ExtremeProcessor,
            0xC2 => ProcessorFamily::IntelCore2QuadProcessor,
            0xC3 => ProcessorFamily::IntelCore2ExtremeMobileProcessor,
            0xC4 => ProcessorFamily::IntelCore2DuoMobileProcessor,
            0xC5 => ProcessorFamily::IntelCore2SoloMobileProcessor,
            0xC6 => ProcessorFamily::IntelCoreI7Processor,
            0xC7 => ProcessorFamily::DualCoreIntelCeleronProcessor,
            0xC8 => ProcessorFamily::IBM390Family,
            0xC9 => ProcessorFamily::G4,
            0xCA => ProcessorFamily::G5,
            0xCB => ProcessorFamily::ESA390G6,
            0xCC => ProcessorFamily::ZArchitectureBase,
            0xCD => ProcessorFamily::IntelCoreI5Processor,
            0xCE => ProcessorFamily::IntelCoreI3Processor,
            0xCF => ProcessorFamily::IntelCoreI9Processor,
            n @ 0xD0..=0xD1 => ProcessorFamily::Available(n),
            0xD2 => ProcessorFamily::VIAC7MProcessorFamily,
            0xD3 => ProcessorFamily::VIAC7DProcessorFamily,
            0xD4 => ProcessorFamily::VIAC7ProcessorFamily,
            0xD5 => ProcessorFamily::VIAEdenProcessorFamily,
            0xD6 => ProcessorFamily::MultiCoreIntelXeonProcessor,
            0xD7 => ProcessorFamily::DualCoreIntelXeonProcessor3xxxSeries,
            0xD8 => ProcessorFamily::QuadCoreIntelXeonProcessor3xxxSeries,
            0xD9 => ProcessorFamily::VIANanoProcessorFamily,
            0xDA => ProcessorFamily::DualCoreIntelXeonProcessor5xxxSeries,
            0xDB => ProcessorFamily::QuadCoreIntelXeonProcessor5xxxSeries,
            n @ 0xDC => ProcessorFamily::Available(n),
            0xDD => ProcessorFamily::DualCoreIntelXeonProcessor7xxxSeries,
            0xDE => ProcessorFamily::QuadCoreIntelXeonProcessor7xxxSeries,
            0xDF => ProcessorFamily::MultiCoreIntelXeonProcessor7xxxSeries,
            0xE0 => ProcessorFamily::MultiCoreIntelXeonProcessor3400Series,
            n @ 0xE1..=0xE3 => ProcessorFamily::Available(n),
            0xE4 => ProcessorFamily::AMDOpteron3000SeriesProcessor,
            0xE5 => ProcessorFamily::AMDSempronIIProcessor,
            0xE6 => ProcessorFamily::EmbeddedAMDOpteronQuadCoreProcessorFamily,
            0xE7 => ProcessorFamily::AMDPhenomTripleCoreProcessorFamily,
            0xE8 => ProcessorFamily::AMDTurionUltraDualCoreMobileProcessorFamily,
            0xE9 => ProcessorFamily::AMDTurionDualCoreMobileProcessorFamily,
            0xEA => ProcessorFamily::AMDAthlonDualCoreProcessorFamily,
            0xEB => ProcessorFamily::AMDSempronSIProcessorFamily,
            0xEC => ProcessorFamily::AMDPhenomIIProcessorFamily,
            0xED => ProcessorFamily::AMDAthlonIIProcessorFamily,
            0xEE => ProcessorFamily::SixCoreAMDOpteronProcessorFamily,
            0xEF => ProcessorFamily::AMDSempronMProcessorFamily,
            n @ 0xF0..=0xF9 => ProcessorFamily::Available(n),
            0xFA => ProcessorFamily::I860,
            0xFB => ProcessorFamily::I960,
            n @ 0xFC..=0xFD => ProcessorFamily::Available(n),
            0xFE => ProcessorFamily::ProcessorFamily2,
            n @ 0xFF => ProcessorFamily::NotUsed(n),
            0x100 => ProcessorFamily::ARMv7,
            0x101 => ProcessorFamily::ARMv8,
            0x102 => ProcessorFamily::ARMv9,
            0x103 => ProcessorFamily::Available(0x103),
            0x104 => ProcessorFamily::SH3,
            0x105 => ProcessorFamily::SH4,
            n @ 0x106..=0x117 => ProcessorFamily::Available(n),
            0x118 => ProcessorFamily::ARM,
            0x119 => ProcessorFamily::StrongARM,
            n @ 0x11A..=0x12B => ProcessorFamily::Available(n),
            0x12C => ProcessorFamily::Cyrix6x86,
            0x12D => ProcessorFamily::MediaGX,
            0x12E => ProcessorFamily::MII,
            n @ 0x12F..=0x13F => ProcessorFamily::Available(n),
            0x140 => ProcessorFamily::WinChip,
            n @ 0x141..=0x15D => ProcessorFamily::Available(n),
            0x15E => ProcessorFamily::DSP,
            n @ 0x15F..=0x1F3 => ProcessorFamily::Available(n),
            0x1F4 => ProcessorFamily::VideoProcessor,
            n @ 0x1F5..=0x1FF => ProcessorFamily::Available(n),
            0x200 => ProcessorFamily::RISCVRV32,
            0x201 => ProcessorFamily::RISCVRV64,
            0x202 => ProcessorFamily::RISCVRV128,
            n @ 0x203..=0xFFFD => ProcessorFamily::Available(n),
            0xFFFE => ProcessorFamily::ForFutureUse,
            n @ 0xFFFF => ProcessorFamily::NotUsed(n),
        }
    }
}
impl fmt::Display for ProcessorFamily {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ProcessorFamily::Other => write!(f, "Other"),
            ProcessorFamily::Unknown => write!(f, "Unknown"),
            ProcessorFamily::Intel8086 => write!(f, "8086"),
            ProcessorFamily::Intel80286 => write!(f, "80286"),
            ProcessorFamily::Intel386Processor => write!(f, "Intel386™ processor"),
            ProcessorFamily::Intel486Processor => write!(f, "Intel486™ processor"),
            ProcessorFamily::Intel8087 => write!(f, "8087"),
            ProcessorFamily::Intel80287 => write!(f, "80287"),
            ProcessorFamily::Intel80387 => write!(f, "80387"),
            ProcessorFamily::Intel80487 => write!(f, "80487"),
            ProcessorFamily::IntelPentiumProcessor => write!(f, "Intel® Pentium® processor"),
            ProcessorFamily::PentiumProProcessor => write!(f, "Pentium® Pro processor"),
            ProcessorFamily::PentiumIIProcessor => write!(f, "Pentium® II processor"),
            ProcessorFamily::PentiumProcessorWithMMXTechnology => {
                write!(f, "Pentium® processor with MMX™ technology")
            }
            ProcessorFamily::IntelCeleronProcessor => write!(f, "Intel® Celeron® processor"),
            ProcessorFamily::PentiumIIXeonProcessor => write!(f, "Pentium® II Xeon™ processor"),
            ProcessorFamily::PentiumIIIProcessor => write!(f, "Pentium® III processor"),
            ProcessorFamily::M1Family => write!(f, "M1 Family"),
            ProcessorFamily::M2Family => write!(f, "M2 Family"),
            ProcessorFamily::IntelCeleronMProcessor => write!(f, "Intel® Celeron® M processor"),
            ProcessorFamily::IntelPentium4HTProcessor => {
                write!(f, "Intel® Pentium® 4 HT processor")
            }
            ProcessorFamily::AMDDuronProcessorFamily => {
                write!(f, "AMD Duron™ Processor Family [1]")
            }
            ProcessorFamily::K5Family => write!(f, "K5 Family [1]"),
            ProcessorFamily::K6Family => write!(f, "K6 Family [1]"),
            ProcessorFamily::K62 => write!(f, "K6-2"),
            ProcessorFamily::K63 => write!(f, "K6-3"),
            ProcessorFamily::AMDAthlonProcessorFamily => {
                write!(f, "AMD Athlon™ Processor Family [1]")
            }
            ProcessorFamily::AMD29000Family => write!(f, "AMD29000 Family"),
            ProcessorFamily::K62Plus => write!(f, "K6-2+"),
            ProcessorFamily::PowerPCFamily => write!(f, "Power PC Family"),
            ProcessorFamily::PowerPC601 => write!(f, "Power PC 601"),
            ProcessorFamily::PowerPC603 => write!(f, "Power PC 603"),
            ProcessorFamily::PowerPC603Plus => write!(f, "Power PC 603+"),
            ProcessorFamily::PowerPC604 => write!(f, "Power PC 604"),
            ProcessorFamily::PowerPC620 => write!(f, "Power PC 620"),
            ProcessorFamily::PowerPCX704 => write!(f, "Power PC x704"),
            ProcessorFamily::PowerPC750 => write!(f, "Power PC 750"),
            ProcessorFamily::IntelCoreDuoProcessor => write!(f, "Intel® Core™ Duo processor"),
            ProcessorFamily::IntelCoreDuoMobileProcessor => {
                write!(f, "Intel® Core™ Duo mobile processor")
            }
            ProcessorFamily::IntelCoreSoloMobileProcessor => {
                write!(f, "Intel® Core™ Solo mobile processor")
            }
            ProcessorFamily::IntelAtomProcessor => write!(f, "Intel® Atom™ processor"),
            ProcessorFamily::IntelCoreMProcessor => write!(f, "Intel® Core™ M processor"),
            ProcessorFamily::IntelCoreM3Processor => write!(f, "Intel(R) Core(TM) m3 processor"),
            ProcessorFamily::IntelCoreM5Processor => write!(f, "Intel(R) Core(TM) m5 processor"),
            ProcessorFamily::IntelCoreM7Processor => write!(f, "Intel(R) Core(TM) m7 processor"),
            ProcessorFamily::AlphaFamily => write!(f, "Alpha Family [2]"),
            ProcessorFamily::Alpha21064 => write!(f, "Alpha 21064"),
            ProcessorFamily::Alpha21066 => write!(f, "Alpha 21066"),
            ProcessorFamily::Alpha21164 => write!(f, "Alpha 21164"),
            ProcessorFamily::Alpha21164PC => write!(f, "Alpha 21164PC"),
            ProcessorFamily::Alpha21164a => write!(f, "Alpha 21164a"),
            ProcessorFamily::Alpha21264 => write!(f, "Alpha 21264"),
            ProcessorFamily::Alpha21364 => write!(f, "Alpha 21364"),
            ProcessorFamily::AMDTurionIIUltraDualCoreMobileMProcessorFamily => {
                write!(f, "AMD Turion™ II Ultra Dual-Core Mobile M Processor Family")
            }
            ProcessorFamily::AMDTurionIIDualCoreMobileMProcessorFamily => {
                write!(f, "AMD Turion™ II Dual-Core Mobile M Processor Family")
            }
            ProcessorFamily::AMDAthlonIIDualCoreMProcessorFamily => {
                write!(f, "AMD Athlon™ II Dual-Core M Processor Family")
            }
            ProcessorFamily::AMDOpteron6100SeriesProcessor => {
                write!(f, "AMD Opteron™ 6100 Series Processor")
            }
            ProcessorFamily::AMDOpteron4100SeriesProcessor => {
                write!(f, "AMD Opteron™ 4100 Series Processor")
            }
            ProcessorFamily::AMDOpteron6200SeriesProcessor => {
                write!(f, "AMD Opteron™ 6200 Series Processor")
            }
            ProcessorFamily::AMDOpteron4200SeriesProcessor => {
                write!(f, "AMD Opteron™ 4200 Series Processor")
            }
            ProcessorFamily::AMDFXSeriesProcessor => write!(f, "AMD FX™ Series Processor"),
            ProcessorFamily::MIPSFamily => write!(f, "MIPS Family"),
            ProcessorFamily::MIPSR4000 => write!(f, "MIPS R4000"),
            ProcessorFamily::MIPSR4200 => write!(f, "MIPS R4200"),
            ProcessorFamily::MIPSR4400 => write!(f, "MIPS R4400"),
            ProcessorFamily::MIPSR4600 => write!(f, "MIPS R4600"),
            ProcessorFamily::MIPSR10000 => write!(f, "MIPS R10000"),
            ProcessorFamily::AMDCSeriesProcessor => write!(f, "AMD C-Series Processor"),
            ProcessorFamily::AMDESeriesProcessor => write!(f, "AMD E-Series Processor"),
            ProcessorFamily::AMDASeriesProcessor => write!(f, "AMD A-Series Processor"),
            ProcessorFamily::AMDGSeriesProcessor => write!(f, "AMD G-Series Processor"),
            ProcessorFamily::AMDZSeriesProcessor => write!(f, "AMD Z-Series Processor"),
            ProcessorFamily::AMDRSeriesProcessor => write!(f, "AMD R-Series Processor"),
            ProcessorFamily::AMDOpteron4300SeriesProcessor => {
                write!(f, "AMD Opteron™ 4300 Series Processor")
            }
            ProcessorFamily::AMDOpteron6300SeriesProcessor => {
                write!(f, "AMD Opteron™ 6300 Series Processor")
            }
            ProcessorFamily::AMDOpteron3300SeriesProcessor => {
                write!(f, "AMD Opteron™ 3300 Series Processor")
            }
            ProcessorFamily::AMDFireProSeriesProcessor => {
                write!(f, "AMD FirePro™ Series Processor")
            }
            ProcessorFamily::SPARCFamily => write!(f, "SPARC Family"),
            ProcessorFamily::SuperSPARC => write!(f, "SuperSPARC"),
            ProcessorFamily::MicroSPARCII => write!(f, "microSPARC II"),
            ProcessorFamily::MicroSPARCIIep => write!(f, "microSPARC IIep"),
            ProcessorFamily::UltraSPARC => write!(f, "UltraSPARC"),
            ProcessorFamily::UltraSPARCII => write!(f, "UltraSPARC II"),
            ProcessorFamily::UltraSPARCIii => write!(f, "UltraSPARC Iii"),
            ProcessorFamily::UltraSPARCIII => write!(f, "UltraSPARC III"),
            ProcessorFamily::UltraSPARCIIIi => write!(f, "UltraSPARC IIIi"),
            ProcessorFamily::Motorola68040Family => write!(f, "68040 Family"),
            ProcessorFamily::Motorola68xxx => write!(f, "68xxx"),
            ProcessorFamily::Motorola68000 => write!(f, "68000"),
            ProcessorFamily::Motorola68010 => write!(f, "68010"),
            ProcessorFamily::Motorola68020 => write!(f, "68020"),
            ProcessorFamily::Motorola68030 => write!(f, "68030"),
            ProcessorFamily::AMDAthlonX4QuadCoreProcessorFamily => {
                write!(f, "AMD Athlon(TM) X4 Quad-Core Processor Family")
            }
            ProcessorFamily::AMDOpteronX1000SeriesProcessor => {
                write!(f, "AMD Opteron(TM) X1000 Series Processor")
            }
            ProcessorFamily::AMDOpteronX2000SeriesAPU => {
                write!(f, "AMD Opteron(TM) X2000 Series APU")
            }
            ProcessorFamily::AMDOpteronASeriesProcessor => {
                write!(f, "AMD Opteron(TM) A-Series Processor")
            }
            ProcessorFamily::AMDOpteronX3000SeriesAPU => {
                write!(f, "AMD Opteron(TM) X3000 Series APU")
            }
            ProcessorFamily::AMDZenProcessorFamily => write!(f, "AMD Zen Processor Family"),
            ProcessorFamily::HobbitFamily => write!(f, "Hobbit Family"),
            ProcessorFamily::CrusoeTM5000Family => write!(f, "Crusoe™ TM5000 Family"),
            ProcessorFamily::CrusoeTM3000Family => write!(f, "Crusoe™ TM3000 Family"),
            ProcessorFamily::EfficeonTM8000Family => write!(f, "Efficeon™ TM8000 Family"),
            ProcessorFamily::Weitek => write!(f, "Weitek"),
            ProcessorFamily::AvailableForAssignment => write!(f, "Available for assignment"),
            ProcessorFamily::ItaniumProcessor => write!(f, "Itanium™ processor"),
            ProcessorFamily::AMDAthlon64ProcessorFamily => {
                write!(f, "AMD Athlon™ 64 Processor Family")
            }
            ProcessorFamily::AMDOpteronProcessorFamily => {
                write!(f, "AMD Opteron™ Processor Family")
            }
            ProcessorFamily::AMDSempronProcessorFamily => {
                write!(f, "AMD Sempron™ Processor Family")
            }
            ProcessorFamily::AMDTurion64MobileTechnology => {
                write!(f, "AMD Turion™ 64 Mobile Technology")
            }
            ProcessorFamily::DualCoreAMDOpteronProcessorFamily => {
                write!(f, "Dual-Core AMD Opteron™ Processor Family")
            }
            ProcessorFamily::AMDAthlon64X2DualCoreProcessorFamily => {
                write!(f, "AMD Athlon™ 64 X2 Dual-Core Processor Family")
            }
            ProcessorFamily::AMDTurion64X2MobileTechnology => {
                write!(f, "AMD Turion™ 64 X2 Mobile Technology")
            }
            ProcessorFamily::QuadCoreAMDOpteronProcessorFamily => {
                write!(f, "Quad-Core AMD Opteron™ Processor Family")
            }
            ProcessorFamily::ThirdGenerationAMDOpteronProcessorFamily => {
                write!(f, "Third-Generation AMD Opteron™ Processor Family")
            }
            ProcessorFamily::AMDPhenomFXQuadCoreProcessorFamily => {
                write!(f, "AMD Phenom™ FX Quad-Core Processor Family")
            }
            ProcessorFamily::AMDPhenomX4QuadCoreProcessorFamily => {
                write!(f, "AMD Phenom™ X4 Quad-Core Processor Family")
            }
            ProcessorFamily::AMDPhenomX2DualCoreProcessorFamily => {
                write!(f, "AMD Phenom™ X2 Dual-Core Processor Family")
            }
            ProcessorFamily::AMDAthlonX2DualCoreProcessorFamily => {
                write!(f, "AMD Athlon™ X2 Dual-Core Processor Family")
            }
            ProcessorFamily::PARISCFamily => write!(f, "PA-RISC Family"),
            ProcessorFamily::PARISC8500 => write!(f, "PA-RISC 8500"),
            ProcessorFamily::PARISC8000 => write!(f, "PA-RISC 8000"),
            ProcessorFamily::PARISC7300LC => write!(f, "PA-RISC 7300LC"),
            ProcessorFamily::PARISC7200 => write!(f, "PA-RISC 7200"),
            ProcessorFamily::PARISC7100LC => write!(f, "PA-RISC 7100LC"),
            ProcessorFamily::PARISC7100 => write!(f, "PA-RISC 7100"),
            ProcessorFamily::V30Family => write!(f, "V30 Family"),
            ProcessorFamily::QuadCoreIntelXeonProcessor3200Series => {
                write!(f, "Quad-Core Intel® Xeon® processor 3200 Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor3000Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 3000 Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor5300Series => {
                write!(f, "Quad-Core Intel® Xeon® processor 5300 Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor5100Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 5100 Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor5000Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 5000 Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessorLV => {
                write!(f, "Dual-Core Intel® Xeon® processor LV")
            }
            ProcessorFamily::DualCoreIntelXeonProcessorULV => {
                write!(f, "Dual-Core Intel® Xeon® processor ULV")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor7100Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 7100 Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor5400Series => {
                write!(f, "Quad-Core Intel® Xeon® processor 5400 Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor => {
                write!(f, "Quad-Core Intel® Xeon® processor")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor5200Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 5200 Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor7200Series => {
                write!(f, "Dual-Core Intel® Xeon® processor 7200 Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor7300Series => {
                write!(f, "Quad-Core Intel® Xeon® processor 7300 Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor7400Series => {
                write!(f, "Quad-Core Intel® Xeon® processor 7400 Series")
            }
            ProcessorFamily::MultiCoreIntelXeonProcessor7400Series => {
                write!(f, "Multi-Core Intel® Xeon® processor 7400 Series")
            }
            ProcessorFamily::PentiumIIIXeonProcessor => write!(f, "Pentium® III Xeon™ processor"),
            ProcessorFamily::PentiumIIIProcessorWithIntelSpeedStepTechnology => {
                write!(f, "Pentium® III Processor with Intel® SpeedStep™ Technology")
            }
            ProcessorFamily::Pentium4Processor => write!(f, "Pentium® 4 Processor"),
            ProcessorFamily::IntelXeonProcessor => write!(f, "Intel® Xeon® processor"),
            ProcessorFamily::AS400Family => write!(f, "AS400 Family"),
            ProcessorFamily::IntelXeonProcessorMP => write!(f, "Intel® Xeon™ processor MP"),
            ProcessorFamily::AMDAthlonXPProcessorFamily => {
                write!(f, "AMD Athlon™ XP Processor Family")
            }
            ProcessorFamily::AMDAthlonMPProcessorFamily => {
                write!(f, "AMD Athlon™ MP Processor Family")
            }
            ProcessorFamily::IntelItanium2Processor => write!(f, "Intel® Itanium® 2 processor"),
            ProcessorFamily::IntelPentiumMProcessor => write!(f, "Intel® Pentium® M processor"),
            ProcessorFamily::IntelCeleronDProcessor => write!(f, "Intel® Celeron® D processor"),
            ProcessorFamily::IntelPentiumDProcessor => write!(f, "Intel® Pentium® D processor"),
            ProcessorFamily::IntelPentiumProcessorExtremeEdition => {
                write!(f, "Intel® Pentium® Processor Extreme Edition")
            }
            ProcessorFamily::IntelCoreSoloProcessor => write!(f, "Intel® Core™ Solo Processor"),
            ProcessorFamily::Ambiguous => write!(f, "Ambiguous"),
            ProcessorFamily::IntelCore2DuoProcessor => write!(f, "Intel® Core™ 2 Duo Processor"),
            ProcessorFamily::IntelCore2SoloProcessor => write!(f, "Intel® Core™ 2 Solo processor"),
            ProcessorFamily::IntelCore2ExtremeProcessor => {
                write!(f, "Intel® Core™ 2 Extreme processor")
            }
            ProcessorFamily::IntelCore2QuadProcessor => write!(f, "Intel® Core™ 2 Quad processor"),
            ProcessorFamily::IntelCore2ExtremeMobileProcessor => {
                write!(f, "Intel® Core™ 2 Extreme mobile processor")
            }
            ProcessorFamily::IntelCore2DuoMobileProcessor => {
                write!(f, "Intel® Core™ 2 Duo mobile processor")
            }
            ProcessorFamily::IntelCore2SoloMobileProcessor => {
                write!(f, "Intel® Core™ 2 Solo mobile processor")
            }
            ProcessorFamily::IntelCoreI7Processor => write!(f, "Intel® Core™ i7 processor"),
            ProcessorFamily::DualCoreIntelCeleronProcessor => {
                write!(f, "Dual-Core Intel® Celeron® processor")
            }
            ProcessorFamily::IBM390Family => write!(f, "IBM390 Family"),
            ProcessorFamily::G4 => write!(f, "G4"),
            ProcessorFamily::G5 => write!(f, "G5"),
            ProcessorFamily::ESA390G6 => write!(f, "ESA/390 G6"),
            ProcessorFamily::ZArchitectureBase => write!(f, "z/Architecture base"),
            ProcessorFamily::IntelCoreI5Processor => write!(f, "Intel® Core™ i5 processor"),
            ProcessorFamily::IntelCoreI3Processor => write!(f, "Intel® Core™ i3 processor"),
            ProcessorFamily::IntelCoreI9Processor => write!(f, "Intel® Core™ i9 processor"),
            ProcessorFamily::VIAC7MProcessorFamily => write!(f, "VIA C7™-M Processor Family"),
            ProcessorFamily::VIAC7DProcessorFamily => write!(f, "VIA C7™-D Processor Family"),
            ProcessorFamily::VIAC7ProcessorFamily => write!(f, "VIA C7™ Processor Family"),
            ProcessorFamily::VIAEdenProcessorFamily => write!(f, "VIA Eden™ Processor Family"),
            ProcessorFamily::MultiCoreIntelXeonProcessor => {
                write!(f, "Multi-Core Intel® Xeon® processor")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor3xxxSeries => {
                write!(f, "Dual-Core Intel® Xeon® processor 3xxx Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor3xxxSeries => {
                write!(f, "Quad-Core Intel® Xeon® processor 3xxx Series")
            }
            ProcessorFamily::VIANanoProcessorFamily => write!(f, "VIA Nano™ Processor Family"),
            ProcessorFamily::DualCoreIntelXeonProcessor5xxxSeries => {
                write!(f, "Dual-Core Intel® Xeon® processor 5xxx Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor5xxxSeries => {
                write!(f, "Quad-Core Intel® Xeon® processor 5xxx Series")
            }
            ProcessorFamily::DualCoreIntelXeonProcessor7xxxSeries => {
                write!(f, "Dual-Core Intel® Xeon® processor 7xxx Series")
            }
            ProcessorFamily::QuadCoreIntelXeonProcessor7xxxSeries => {
                write!(f, "Quad-Core Intel® Xeon® processor 7xxx Series")
            }
            ProcessorFamily::MultiCoreIntelXeonProcessor7xxxSeries => {
                write!(f, "Multi-Core Intel® Xeon® processor 7xxx Series")
            }
            ProcessorFamily::MultiCoreIntelXeonProcessor3400Series => {
                write!(f, "Multi-Core Intel® Xeon® processor 3400 Series")
            }
            ProcessorFamily::AMDOpteron3000SeriesProcessor => {
                write!(f, "AMD Opteron™ 3000 Series Processor")
            }
            ProcessorFamily::AMDSempronIIProcessor => write!(f, "AMD Sempron™ II Processor"),
            ProcessorFamily::EmbeddedAMDOpteronQuadCoreProcessorFamily => {
                write!(f, "Embedded AMD Opteron™ Quad-Core Processor Family")
            }
            ProcessorFamily::AMDPhenomTripleCoreProcessorFamily => {
                write!(f, "AMD Phenom™ Triple-Core Processor Family")
            }
            ProcessorFamily::AMDTurionUltraDualCoreMobileProcessorFamily => {
                write!(f, "AMD Turion™ Ultra Dual-Core Mobile Processor Family")
            }
            ProcessorFamily::AMDTurionDualCoreMobileProcessorFamily => {
                write!(f, "AMD Turion™ Dual-Core Mobile Processor Family")
            }
            ProcessorFamily::AMDAthlonDualCoreProcessorFamily => {
                write!(f, "AMD Athlon™ Dual-Core Processor Family")
            }
            ProcessorFamily::AMDSempronSIProcessorFamily => {
                write!(f, "AMD Sempron™ SI Processor Family")
            }
            ProcessorFamily::AMDPhenomIIProcessorFamily => {
                write!(f, "AMD Phenom™ II Processor Family")
            }
            ProcessorFamily::AMDAthlonIIProcessorFamily => {
                write!(f, "AMD Athlon™ II Processor Family")
            }
            ProcessorFamily::SixCoreAMDOpteronProcessorFamily => {
                write!(f, "Six-Core AMD Opteron™ Processor Family")
            }
            ProcessorFamily::AMDSempronMProcessorFamily => {
                write!(f, "AMD Sempron™ M Processor Family")
            }
            ProcessorFamily::I860 => write!(f, "i860"),
            ProcessorFamily::I960 => write!(f, "i960"),
            ProcessorFamily::ARMv7 => write!(f, "ARMv7"),
            ProcessorFamily::ARMv8 => write!(f, "ARMv8"),
            ProcessorFamily::ARMv9 => write!(f, "ARMv9"),
            ProcessorFamily::SH3 => write!(f, "SH-3"),
            ProcessorFamily::SH4 => write!(f, "SH-4"),
            ProcessorFamily::ARM => write!(f, "ARM"),
            ProcessorFamily::StrongARM => write!(f, "StrongARM"),
            ProcessorFamily::Cyrix6x86 => write!(f, "6x86"),
            ProcessorFamily::MediaGX => write!(f, "MediaGX"),
            ProcessorFamily::MII => write!(f, "MII"),
            ProcessorFamily::WinChip => write!(f, "WinChip"),
            ProcessorFamily::DSP => write!(f, "DSP"),
            ProcessorFamily::VideoProcessor => write!(f, "Video Processor"),
            ProcessorFamily::RISCVRV32 => write!(f, "RISC-V RV32"),
            ProcessorFamily::RISCVRV64 => write!(f, "RISC-V RV64"),
            ProcessorFamily::RISCVRV128 => write!(f, "RISC-V RV128"),
            ProcessorFamily::ForFutureUse => write!(f, "For special use in the future"),
            ProcessorFamily::ProcessorFamily2 => {
                write!(f, "Processor Family 2 has the enumerated value")
            }
            ProcessorFamily::Available(n) => write!(f, "Available {n:#X}"),
            ProcessorFamily::NotUsed(n) => write!(f, "Not used. {n:X}h is the un-initialized value of Flash memory."),
            ProcessorFamily::OutOfSpec => write!(f, "OUT OF SPEC"),
        }
    }
}

impl From<u8> for Voltage {
    fn from(byte: u8) -> Self {
        if (byte & 0b1000_0000) == 0 {
            if (byte & 0b0111_1000) != 0 {
                Self::Undefined(byte)
            } else {
                Self::Legacy(VoltageLegacy::from_bits_truncate(byte))
            }
        } else {
            Self::Current(byte & 0b0111_1111)
        }
    }
}
impl fmt::Display for Voltage {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Current(v) => write!(f, "Current voltage: {:.1} V", *v as f32 / 10.0),
            Self::Undefined(n) => write!(f, "Undefined {n:#b}"),
            Self::Legacy(legacy) => {
                let s55 = if legacy.contains(VoltageLegacy::VOLTAGE_CAPABILITY_5V0) {
                    "5.5V "
                } else {
                    ""
                };
                let s33 = if legacy.contains(VoltageLegacy::VOLTAGE_CAPABILITY_3V3) {
                    "3.3V "
                } else {
                    ""
                };
                let s29 = if legacy.contains(VoltageLegacy::VOLTAGE_CAPABILITY_2V9) {
                    "2.9V "
                } else {
                    ""
                };
                if s55.is_empty() && s33.is_empty() && s29.is_empty() {
                    write!(f, "Voltage capability unknown")
                } else {
                    write!(f, "Processor socket accept: {s55}{s33}{s29}")
                }
            }
        }
    }
}

impl From<u8> for ProcessorUpgrade {
    fn from(byte: u8) -> Self {
        match byte {
            0x01 => ProcessorUpgrade::Other,
            0x02 => ProcessorUpgrade::Unknown,
            0x03 => ProcessorUpgrade::DaughterBoard,
            0x04 => ProcessorUpgrade::ZIFSocket,
            0x05 => ProcessorUpgrade::ReplaceablePiggyBack,
            0x06 => ProcessorUpgrade::None,
            0x07 => ProcessorUpgrade::LIFSocket,
            0x08 => ProcessorUpgrade::Slot1,
            0x09 => ProcessorUpgrade::Slot2,
            0x0a => ProcessorUpgrade::Socket370,
            0x0b => ProcessorUpgrade::SlotA,
            0x0c => ProcessorUpgrade::SlotM,
            0x0d => ProcessorUpgrade::Socket423,
            0x0e => ProcessorUpgrade::SocketA,
            0x0f => ProcessorUpgrade::Socket478,
            0x10 => ProcessorUpgrade::Socket754,
            0x11 => ProcessorUpgrade::Socket940,
            0x12 => ProcessorUpgrade::Socket939,
            0x13 => ProcessorUpgrade::SocketmPGA604,
            0x14 => ProcessorUpgrade::SocketLGA771,
            0x15 => ProcessorUpgrade::SocketLGA775,
            0x16 => ProcessorUpgrade::SocketS1,
            0x17 => ProcessorUpgrade::SocketAM2,
            0x18 => ProcessorUpgrade::SocketF,
            0x19 => ProcessorUpgrade::SocketLGA1366,
            0x1a => ProcessorUpgrade::SocketG34,
            0x1b => ProcessorUpgrade::SocketAM3,
            0x1c => ProcessorUpgrade::SocketC32,
            0x1d => ProcessorUpgrade::SocketLGA1156,
            0x1e => ProcessorUpgrade::SocketLGA1567,
            0x1f => ProcessorUpgrade::SocketPGA988A,
            0x20 => ProcessorUpgrade::SocketBGA1288,
            0x21 => ProcessorUpgrade::SocketrPGA988B,
            0x22 => ProcessorUpgrade::SocketBGA1023,
            0x23 => ProcessorUpgrade::SocketBGA1224,
            0x24 => ProcessorUpgrade::SocketLGA1155,
            0x25 => ProcessorUpgrade::SocketLGA1356,
            0x26 => ProcessorUpgrade::SocketLGA2011,
            0x27 => ProcessorUpgrade::SocketFS1,
            0x28 => ProcessorUpgrade::SocketFS2,
            0x29 => ProcessorUpgrade::SocketFM1,
            0x2a => ProcessorUpgrade::SocketFM2,
            0x2b => ProcessorUpgrade::SocketLGA2011Three,
            0x2c => ProcessorUpgrade::SocketLGA1356Three,
            0x2d => ProcessorUpgrade::SocketLGA1150,
            0x2e => ProcessorUpgrade::SocketBGA1168,
            0x2f => ProcessorUpgrade::SocketBGA1234,
            0x30 => ProcessorUpgrade::SocketBGA1364,
            0x31 => ProcessorUpgrade::SocketAM4,
            0x32 => ProcessorUpgrade::SocketLGA1151,
            0x33 => ProcessorUpgrade::SocketBGA1356,
            0x34 => ProcessorUpgrade::SocketBGA1440,
            0x35 => ProcessorUpgrade::SocketBGA1515,
            0x36 => ProcessorUpgrade::SocketLGA3647,
            0x37 => ProcessorUpgrade::SocketSP3,
            0x38 => ProcessorUpgrade::SocketSP3r2,
            0x39 => ProcessorUpgrade::SocketLGA2066,
            0x3a => ProcessorUpgrade::SocketBGA1392,
            0x3b => ProcessorUpgrade::SocketBGA1510,
            0x3c => ProcessorUpgrade::SocketBGA1528,
            0x3d => ProcessorUpgrade::SocketLGA4189,
            0x3e => ProcessorUpgrade::SocketLGA1200,
            n => ProcessorUpgrade::Undefined(n),
        }
    }
}
impl fmt::Display for ProcessorUpgrade {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ProcessorUpgrade::Other => write!(f, "Other"),
            ProcessorUpgrade::Unknown => write!(f, "Unknown"),
            ProcessorUpgrade::DaughterBoard => write!(f, "Daughter Board"),
            ProcessorUpgrade::ZIFSocket => write!(f, "ZIF Socket"),
            ProcessorUpgrade::ReplaceablePiggyBack => write!(f, "Replaceable Piggy Back"),
            ProcessorUpgrade::None => write!(f, "None"),
            ProcessorUpgrade::LIFSocket => write!(f, "LIF Socket"),
            ProcessorUpgrade::Slot1 => write!(f, "Slot 1"),
            ProcessorUpgrade::Slot2 => write!(f, "Slot 2"),
            ProcessorUpgrade::Socket370 => write!(f, "370-pin socket"),
            ProcessorUpgrade::SlotA => write!(f, "Slot A"),
            ProcessorUpgrade::SlotM => write!(f, "Slot M"),
            ProcessorUpgrade::Socket423 => write!(f, "Socket 423"),
            ProcessorUpgrade::SocketA => write!(f, "Socket A (Socket 462)"),
            ProcessorUpgrade::Socket478 => write!(f, "Socket 478"),
            ProcessorUpgrade::Socket754 => write!(f, "Socket 754"),
            ProcessorUpgrade::Socket940 => write!(f, "Socket 940"),
            ProcessorUpgrade::Socket939 => write!(f, "Socket 939"),
            ProcessorUpgrade::SocketmPGA604 => write!(f, "Socket mPGA604"),
            ProcessorUpgrade::SocketLGA771 => write!(f, "Socket LGA771"),
            ProcessorUpgrade::SocketLGA775 => write!(f, "Socket LGA775"),
            ProcessorUpgrade::SocketS1 => write!(f, "Socket S1"),
            ProcessorUpgrade::SocketAM2 => write!(f, "Socket AM2"),
            ProcessorUpgrade::SocketF => write!(f, "Socket F (1207)"),
            ProcessorUpgrade::SocketLGA1366 => write!(f, "Socket LGA1366"),
            ProcessorUpgrade::SocketG34 => write!(f, "Socket G34"),
            ProcessorUpgrade::SocketAM3 => write!(f, "Socket AM3"),
            ProcessorUpgrade::SocketC32 => write!(f, "Socket C32"),
            ProcessorUpgrade::SocketLGA1156 => write!(f, "Socket LGA1156"),
            ProcessorUpgrade::SocketLGA1567 => write!(f, "Socket LGA1567"),
            ProcessorUpgrade::SocketPGA988A => write!(f, "Socket PGA988A"),
            ProcessorUpgrade::SocketBGA1288 => write!(f, "Socket BGA1288"),
            ProcessorUpgrade::SocketrPGA988B => write!(f, "Socket rPGA988B"),
            ProcessorUpgrade::SocketBGA1023 => write!(f, "Socket BGA1023"),
            ProcessorUpgrade::SocketBGA1224 => write!(f, "Socket BGA1224"),
            ProcessorUpgrade::SocketLGA1155 => write!(f, "Socket LGA1155"),
            ProcessorUpgrade::SocketLGA1356 => write!(f, "Socket LGA1356"),
            ProcessorUpgrade::SocketLGA2011 => write!(f, "Socket LGA2011"),
            ProcessorUpgrade::SocketFS1 => write!(f, "Socket FS1"),
            ProcessorUpgrade::SocketFS2 => write!(f, "Socket FS2"),
            ProcessorUpgrade::SocketFM1 => write!(f, "Socket FM1"),
            ProcessorUpgrade::SocketFM2 => write!(f, "Socket FM2"),
            ProcessorUpgrade::SocketLGA2011Three => write!(f, "Socket LGA2011-3"),
            ProcessorUpgrade::SocketLGA1356Three => write!(f, "Socket LGA1356-3"),
            ProcessorUpgrade::SocketLGA1150 => write!(f, "Socket LGA1150"),
            ProcessorUpgrade::SocketBGA1168 => write!(f, "Socket BGA1168"),
            ProcessorUpgrade::SocketBGA1234 => write!(f, "Socket BGA1234"),
            ProcessorUpgrade::SocketBGA1364 => write!(f, "Socket BGA1364"),
            ProcessorUpgrade::SocketAM4 => write!(f, "Socket AM4"),
            ProcessorUpgrade::SocketLGA1151 => write!(f, "Socket LGA1151"),
            ProcessorUpgrade::SocketBGA1356 => write!(f, "Socket BGA1356"),
            ProcessorUpgrade::SocketBGA1440 => write!(f, "Socket BGA1440"),
            ProcessorUpgrade::SocketBGA1515 => write!(f, "Socket BGA1515"),
            ProcessorUpgrade::SocketLGA3647 => write!(f, "Socket LGA3647-1"),
            ProcessorUpgrade::SocketSP3 => write!(f, "Socket SP3"),
            ProcessorUpgrade::SocketSP3r2 => write!(f, "Socket SP3r2"),
            ProcessorUpgrade::SocketLGA2066 => write!(f, "Socket LGA2066"),
            ProcessorUpgrade::SocketBGA1392 => write!(f, "Socket BGA1392"),
            ProcessorUpgrade::SocketBGA1510 => write!(f, "Socket BGA1510"),
            ProcessorUpgrade::SocketBGA1528 => write!(f, "Socket BGA1528"),
            ProcessorUpgrade::SocketLGA4189 => write!(f, "Socket LGA4189"),
            ProcessorUpgrade::SocketLGA1200 => write!(f, "Socket LGA1200"),
            ProcessorUpgrade::Undefined(n) => write!(f, "Undefined {n}"),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::InfoType;

    #[test]
    fn processor_family() {
        use super::ProcessorFamily::*;
        for i in 0..=0xFFFF {
            let (e, s) = match i {
                0x01 => (Other, "Other".into()),
                0x15 => (IntelPentium4HTProcessor, "Intel® Pentium® 4 HT processor".into()),
                0x0D => (PentiumIIProcessor, "Pentium® II processor".into()),
                0x28 => (IntelCoreDuoProcessor, "Intel® Core™ Duo processor".into()),
                0x3D => (
                    AMDOpteron6200SeriesProcessor,
                    "AMD Opteron™ 6200 Series Processor".into(),
                ),
                0x50 => (SPARCFamily, "SPARC Family".into()),
                0x65 => (Motorola68030, "68030".into()),
                0x8F => (
                    AMDAthlonX2DualCoreProcessorFamily,
                    "AMD Athlon™ X2 Dual-Core Processor Family".into(),
                ),
                0xBE => (Ambiguous, "Ambiguous".into()),
                0xC9 => (G4, "G4".into()),
                0xFB => (I960, "i960".into()),
                0x100 => (ARMv7, "ARMv7".into()),
                0x104 => (SH3, "SH-3".into()),
                0x118 => (ARM, "ARM".into()),
                0x140 => (WinChip, "WinChip".into()),
                n @ 0x16..=0x17 => (Available(n), format!("Available {n:#X}")),
                n @ 0x59..=0x5F => (Available(n), format!("Available {n:#X}")),
                n @ 0x6C..=0x6F => (Available(n), format!("Available {n:#X}")),
                n @ 0x71..=0x77 => (Available(n), format!("Available {n:#X}")),
                n @ 0x7B..=0x7F => (Available(n), format!("Available {n:#X}")),
                n @ 0x81 => (Available(n), format!("Available {n:#X}")),
                n @ 0x97..=0x9F => (Available(n), format!("Available {n:#X}")),
                n @ 0xD0..=0xD1 => (Available(n), format!("Available {n:#X}")),
                n @ 0xDC => (Available(n), format!("Available {n:#X}")),
                n @ 0xE1..=0xE3 => (Available(n), format!("Available {n:#X}")),
                n @ 0xF0..=0xF9 => (Available(n), format!("Available {n:#X}")),
                n @ 0xFC..=0xFD => (Available(n), format!("Available {n:#X}")),
                n @ 0x1F5..=0x1FF => (Available(n), format!("Available {n:#X}")),
                n @ 0x203..=0xFFFD => (Available(n), format!("Available {n:#X}")),
                n @ 0xFF => (
                    NotUsed(n),
                    format!("Not used. {n:X}h is the un-initialized value of Flash memory."),
                ),
                0xFFFE => (ForFutureUse, "For special use in the future".into()),
                n @ 0xFFFF => (
                    NotUsed(n),
                    format!("Not used. {n:X}h is the un-initialized value of Flash memory."),
                ),
                _ => continue,
            };
            assert_eq!(e, i.into(), "{i:#x}");
            assert_eq!(s, format!("{e}"));
        }
    }

    #[test]
    fn processor_voltage() {
        let test_data = [
            (
                0b0000_0000,
                Voltage::Legacy(VoltageLegacy::empty()),
                "Voltage capability unknown",
            ),
            (
                0b0000_0001,
                Voltage::Legacy(VoltageLegacy::VOLTAGE_CAPABILITY_5V0),
                "Processor socket accept: 5.5V ",
            ),
            (
                0b0000_0010,
                Voltage::Legacy(VoltageLegacy::VOLTAGE_CAPABILITY_3V3),
                "Processor socket accept: 3.3V ",
            ),
            (
                0b0000_0111,
                Voltage::Legacy(
                    VoltageLegacy::VOLTAGE_CAPABILITY_5V0
                        | VoltageLegacy::VOLTAGE_CAPABILITY_3V3
                        | VoltageLegacy::VOLTAGE_CAPABILITY_2V9,
                ),
                "Processor socket accept: 5.5V 3.3V 2.9V ",
            ),
            (0b0000_1000, Voltage::Undefined(8), "Undefined 0b1000"),
            (0b1001_0010, Voltage::Current(18), "Current voltage: 1.8 V"),
            (0b1111_1111, Voltage::Current(127), "Current voltage: 12.7 V"),
        ];
        for (byte, sample, display) in test_data.iter() {
            let result = Voltage::from(*byte);
            assert_eq!(*sample, result, "Byte: {byte:#b}");
            assert_eq!(format!("{result}"), format!("{}", display), "Byte: {:#b}", byte);
        }
    }

    #[test]
    fn processor_upgrade() {
        use super::ProcessorUpgrade::*;
        for i in 0..=0xFF {
            let (e, s) = match i {
                0x01 => (Other, "Other".into()),
                0x13 => (SocketmPGA604, "Socket mPGA604".into()),
                0x18 => (SocketF, "Socket F (1207)".into()),
                0x2B => (SocketLGA2011Three, "Socket LGA2011-3".into()),
                0x3E => (SocketLGA1200, "Socket LGA1200".into()),
                n @ 0x3F..=0xFF => (Undefined(n), format!("Undefined {n}")),
                _ => continue,
            };
            assert_eq!(e, i.into(), "{i:#x}");
            assert_eq!(s, format!("{e}"));
        }
    }

    #[test]
    fn smbios_2_8_processor_intel_atom_parses() {
        let structure = RawStructure {
            version: (2, 8).into(),
            info: InfoType::Processor,
            length: 0x2a,
            handle: 0x48,
            // data and strings from processor handler, eg: dmidecode -H 0x48 -u
            data: &[
                // omit first 4 header bytes
                // 04 // type
                // 2a // length
                // 48 00 // handle
                0x01, // socket_designation
                0x03, // processor_type
                0x2b, // processor_family
                0x02, // processor_manufacturer
                0xd8, 0x06, 0x04, 0x00, 0xff, 0xfb, 0xeb, 0xbf, // processor_id
                0x03, // processor_version
                0x90, // voltage
                0x64, 0x00, // external_clock
                0x28, 0x0a, // max_speed
                0x60, 0x09, // current_speed
                0x41, // status
                0x01, // processor_upgrade
                0x46, 0x00, // l1_cache
                0x47, 0x00, // l2_cache
                0xff, 0xff, // l3_cache
                0x00, // serial_number
                0x04, // asset_tag
                0x00, // part_number
                0x08, // core_count
                0x08, // core_enabled
                0x08, // thread_count
                0x04, 0x00, // processor_characteristics
                0x00, 0x00, // processor_family2
            ],
            strings: &[
                // CPU0
                0x43, 0x50, 0x55, 0x30, 0x00, // Intel(R) Corporation
                0x49, 0x6E, 0x74, 0x65, 0x6C, 0x28, 0x52, 0x29, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61, 0x74,
                0x69, 0x6F, 0x6E, 0x00, // Intel(R) Atom(TM) CPU  C2750  @ 2.40GHz
                0x49, 0x6E, 0x74, 0x65, 0x6C, 0x28, 0x52, 0x29, 0x20, 0x41, 0x74, 0x6F, 0x6D, 0x28, 0x54, 0x4D, 0x29,
                0x20, 0x43, 0x50, 0x55, 0x20, 0x20, 0x43, 0x32, 0x37, 0x35, 0x30, 0x20, 0x20, 0x40, 0x20, 0x32, 0x2E,
                0x34, 0x30, 0x47, 0x48, 0x7A, 0x00, // ProcessorInfo_ASSET_TAG
                0x50, 0x72, 0x6F, 0x63, 0x65, 0x73, 0x73, 0x6F, 0x72, 0x49, 0x6E, 0x66, 0x6F, 0x5F, 0x41, 0x53, 0x53,
                0x45, 0x54, 0x5F, 0x54, 0x41, 0x47, 0x00,
            ],
        };

        assert_eq!(
            Processor {
                handle: 0x48,
                socket_designation: "CPU0",
                processor_type: ProcessorType::CentralProcessor,
                processor_family: ProcessorFamily::IntelAtomProcessor,
                processor_manufacturer: "Intel(R) Corporation",
                processor_id: 13829424153406736088,
                processor_version: "Intel(R) Atom(TM) CPU  C2750  @ 2.40GHz",
                voltage: Voltage::Current(16),
                external_clock: 100,
                max_speed: 2600,
                current_speed: 2400,
                status: ProcessorStatus::from_bits_truncate(0b0100_0001),
                processor_upgrade: ProcessorUpgrade::Other,
                l1_cache_handle: Some(70),
                l2_cache_handle: Some(71),
                l3_cache_handle: Some(65535),
                serial_number: Some(""),
                asset_tag: Some("ProcessorInfo_ASSET_TAG"),
                part_number: Some(""),
                core_count: Some(8),
                core_enabled: Some(8),
                thread_count: Some(8),
                processor_characteristics: Some(ProcessorCharacteristics::from_bits_truncate(0b0000_0100)),
            },
            Processor::try_from(structure).unwrap()
        );
    }

    #[test]
    // Processor info was manipulated to exercise processor_family_2 parsing
    fn smbios_2_8_processor_parses_with_processor_family_2() {
        let structure = RawStructure {
            version: (2, 8).into(),
            info: InfoType::Processor,
            length: 0x2a,
            handle: 0x48,
            // data and strings from processor handler, eg: dmidecode -H 0x48 -u
            // $ hexdump -s 0x4c6 -n 42 -C processor_bin
            data: &[
                // 04 // type
                // 2a // length
                // 48 00 // handle
                0x01, // socket_designation
                0x03, // processor_type
                0xfe, // processor_family
                0x02, // processor_manufacturer
                0xd8, 0x06, 0x04, 0x00, 0xff, 0xfb, 0xeb, 0xbf, // processor_id
                0x03, // processor_version
                0x90, // voltage
                0x64, 0x00, // external_clock
                0x28, 0x0a, // max_speed
                0x60, 0x09, // current_speed
                0x41, // status
                0x01, // processor_upgrade
                0x46, 0x00, // l1_cache
                0x47, 0x00, // l2_cache
                0xff, 0xff, // l3_cache
                0x00, // serial_number
                0x04, // asset_tag
                0x00, // part_number
                0x08, // core_count
                0x08, // core_enabled
                0x08, // thread_count
                0x04, 0x00, // processor_characteristics
                0x18, 0x01, // processor_family2
            ],
            strings: &[
                // CPU0
                0x43, 0x50, 0x55, 0x30, 0x00, // FAKE MANUFACTURER
                0x46, 0x41, 0x4b, 0x45, 0x20, 0x4d, 0x41, 0x4e, 0x55, 0x46, 0x41, 0x43, 0x54, 0x55, 0x52, 0x45, 0x52,
                0x00, // FAKE VERSION
                0x46, 0x41, 0x4b, 0x45, 0x20, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x00, // FAKE ASSET
                0x46, 0x41, 0x4b, 0x45, 0x20, 0x41, 0x53, 0x53, 0x45, 0x54, 0x20, 0x54, 0x41, 0x47, 0x00,
            ],
        };

        assert_eq!(
            Processor {
                handle: 0x48,
                socket_designation: "CPU0",
                processor_type: ProcessorType::CentralProcessor,
                processor_family: ProcessorFamily::ARM,
                processor_manufacturer: "FAKE MANUFACTURER",
                processor_id: 13829424153406736088,
                processor_version: "FAKE VERSION",
                voltage: Voltage::Current(16),
                external_clock: 100,
                max_speed: 2600,
                current_speed: 2400,
                status: ProcessorStatus::from_bits_truncate(0b0100_0001),
                processor_upgrade: ProcessorUpgrade::Other,
                l1_cache_handle: Some(70),
                l2_cache_handle: Some(71),
                l3_cache_handle: Some(65535),
                serial_number: Some(""),
                asset_tag: Some("FAKE ASSET TAG"),
                part_number: Some(""),
                core_count: Some(8),
                core_enabled: Some(8),
                thread_count: Some(8),
                processor_characteristics: Some(ProcessorCharacteristics::from_bits_truncate(0b0000_0100)),
            },
            Processor::try_from(structure).unwrap()
        );
    }

    #[test]
    fn zero_process_family() {
        let structure = RawStructure {
            version: (3, 2).into(),
            info: InfoType::Processor,
            length: 0x32,
            handle: 0x000c,
            // data and strings from processor handler, eg: dmidecode -H 0x48 -u
            // $ hexdump -s 0x4c6 -n 42 -C processor_bin
            data: &[
                // 04 // type
                // 32 // length
                // 0c 00 // handle
                0x01, // socket_designation
                0x03, // processor_type
                0x00, // processor_family
                0x00, // processor_manufacturer
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // processor_id
                0x00, // processor_version
                0x00, // voltage
                0x00, 0x00, // external_clock
                0xa0, 0x0f, // max_speed
                0x00, 0x00, // current_speed
                0x00, // status
                0x3f, // processor_upgrade
                0xff, 0xff, // l1_cache
                0xff, 0xff, // l2_cache
                0xff, 0xff, // l3_cache
                0x00, // serial_number
                0x00, // asset_tag
                0x00, // part_number
                0x00, // core_count
                0x00, // core_enabled
                0x00, // thread_count
                0x00, 0x00, // processor_characteristics
                0x00, 0x00, // processor_family2
                0x00, 0x00, // core count 2
                0x00, 0x00, // core enabled 2
                0x00, 0x00, // thread count 2
                0x00, 0x00,
            ],
            strings: &[
                // CPU0
                0x43, 0x50, 0x55, 0x30, 0x00,
            ],
        };

        assert_eq!(
            Processor {
                handle: 0x000c,
                socket_designation: "CPU0",
                processor_type: ProcessorType::CentralProcessor,
                processor_family: ProcessorFamily::OutOfSpec,
                processor_manufacturer: "",
                processor_id: 0,
                processor_version: "",
                voltage: Voltage::Legacy(VoltageLegacy::empty()),
                external_clock: 0,
                max_speed: 4000,
                current_speed: 0,
                status: ProcessorStatus::from_bits_truncate(0b0),
                processor_upgrade: ProcessorUpgrade::Undefined(0x3f),
                l1_cache_handle: Some(0xffff),
                l2_cache_handle: Some(0xffff),
                l3_cache_handle: Some(0xffff),
                serial_number: Some(""),
                asset_tag: Some(""),
                part_number: Some(""),
                core_count: Some(0),
                core_enabled: Some(0),
                thread_count: Some(0),
                processor_characteristics: Some(ProcessorCharacteristics::from_bits_truncate(0b0)),
            },
            Processor::try_from(structure).unwrap()
        );
    }
}