1 /*
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2016, 2019 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
30 #include "runtime/abstract_vm_version.hpp"
31 #include "runtime/globals_extension.hpp"
32
33 class VM_Version: public Abstract_VM_Version {
34
35 protected:
36 // z/Architecture is the name of the 64-bit extension of the 31-bit s390
37 // architecture.
38 //
39 // For information concerning the life span of the individual
40 // z/Architecture models, please check out the comments/tables
41 // in vm_version_s390.cpp
42
43 // ----------------------------------------------
44 // --- FeatureBitString Bits 0.. 63 (DW[0]) ---
45 // ----------------------------------------------
46 // 11222334445566
47 // 04826048260482604
48 #define StoreFacilityListExtendedMask 0x0100000000000000UL // z9
49 #define ETF2Mask 0x0000800000000000UL // z900
50 #define CryptoFacilityMask 0x0000400000000000UL // z990
51 #define LongDispFacilityMask 0x0000200000000000UL // z900 with microcode update
52 #define LongDispFacilityHighPerfMask 0x0000300000000000UL // z990
53 #define HFPMultiplyAndAddMask 0x0000080000000000UL // z990
54 #define ExtImmedFacilityMask 0x0000040000000000UL // z9
55 #define ETF3Mask 0x0000020000000000UL // z990/z9 (?)
56 #define HFPUnnormalizedMask 0x0000010000000000UL // z9
57 #define ETF2EnhancementMask 0x0000008000000000UL // z9
58 #define StoreClockFastMask 0x0000004000000000UL // z9
59 #define ParsingEnhancementsMask 0x0000002000000000UL // z10(?)
60 #define ETF3EnhancementMask 0x0000000200000000UL // z9
61 #define ExtractCPUTimeMask 0x0000000100000000UL // z10
62 #define CompareSwapStoreMask 0x00000000c0000000UL // z10
63 #define GnrlInstrExtFacilityMask 0x0000000020000000UL // z10
64 #define ExecuteExtensionsMask 0x0000000010000000UL // z10
65 #define FPExtensionsMask 0x0000000004000000UL // z196
66 #define FPSupportEnhancementsMask 0x0000000000400000UL // z10
67 #define DecimalFloatingPointMask 0x0000000000300000UL // z10
68 // z196 begin
69 #define DistinctOpndsMask 0x0000000000040000UL // z196
70 #define FastBCRSerializationMask DistinctOpndsMask
79 #define ExecutionHintMask MiscInstrExtMask
80 #define LoadAndTrapMask MiscInstrExtMask
81 #define ProcessorAssistMask MiscInstrExtMask
82 #define ConstrainedTxExecutionMask 0x0000000000002000UL // ec12
83 #define InterlockedAccess2Mask 0x0000000000000800UL // ec12
84 // EC12 end
85 // z13 begin
86 #define LoadStoreConditional2Mask 0x0000000000000400UL // z13
87 #define CryptoExtension5Mask 0x0000000000000040UL // z13
88 // z13 end
89 #define MiscInstrExt2Mask 0x0000000000000020UL // z14
90 #define MiscInstrExt3Mask 0x0000000000000004UL // z15
91 // ----------------------------------------------
92 // --- FeatureBitString Bits 64..127 (DW[1]) ---
93 // ----------------------------------------------
94 // 11111111
95 // 66778889900011222
96 // 48260482604826048
97 #define TransactionalExecutionMask 0x0040000000000000UL // ec12
98 #define CryptoExtension3Mask 0x0008000000000000UL // z196
99 #define CryptoExtension4Mask 0x0004000000000000UL // z196
100 #define DFPPackedConversionMask 0x0000800000000000UL // z13
101 // ----------------------------------------------
102 // --- FeatureBitString Bits 128..192 (DW[2]) ---
103 // ----------------------------------------------
104 // 11111111111111111
105 // 23344455666778889
106 // 82604826048260482
107 #define VectorFacilityMask 0x4000000000000000UL // z13, not avail in VM guest mode!
108 #define ExecutionProtectionMask 0x2000000000000000UL // z14
109 #define GuardedStorageMask 0x0400000000000000UL // z14
110 #define VectorEnhancements1Mask 0x0100000000000000UL // z14
111 #define VectorPackedDecimalMask 0x0200000000000000UL // z14
112 #define CryptoExtension8Mask 0x0000200000000040UL // z14
113 #define VectorEnhancements2Mask 0x0000080000000000UL // z15
114 #define VectorPackedDecimalEnhMask 0x0000008000000000UL // z15
115 #define CryptoExtension9Mask 0x0000001000000040UL // z15
116 #define DeflateMask 0x0000010000000040UL // z15
117
118 enum {
119 _max_cache_levels = 8, // As limited by ECAG instruction.
120 _features_buffer_len = 4, // in DW
121 _code_buffer_len = 2*256 // For feature detection code.
122 };
123 static unsigned long _features[_features_buffer_len];
124 static unsigned long _cipher_features[_features_buffer_len];
125 static unsigned long _msgdigest_features[_features_buffer_len];
126 static unsigned int _nfeatures;
127 static unsigned int _ncipher_features;
128 static unsigned int _nmsgdigest_features;
129 static unsigned int _Dcache_lineSize;
130 static unsigned int _Icache_lineSize;
131 static bool _is_determine_features_test_running;
132 static const char* _model_string;
133
134 static bool test_feature_bit(unsigned long* featureBuffer, int featureNum, unsigned int bufLen);
135 static void set_features_string();
136 static void print_features_internal(const char* text, bool print_anyway=false);
137 static void determine_features();
138 static long call_getFeatures(unsigned long* buffer, int buflen, int functionCode);
139 static void set_getFeatures(address entryPoint);
140 static int calculate_ECAG_functionCode(unsigned int attributeIndication,
141 unsigned int levelIndication,
142 unsigned int typeIndication);
143
144 // Setting features via march=z900|z990|z9|z10|z196|ec12|z13|z14|z15 commandline option.
145 static void reset_features(bool reset);
146 static void set_features_z900(bool reset = true);
147 static void set_features_z990(bool reset = true);
148 static void set_features_z9(bool reset = true);
149 static void set_features_z10(bool reset = true);
150 static void set_features_z196(bool reset = true);
151 static void set_features_ec12(bool reset = true);
152 static void set_features_z13(bool reset = true);
153 static void set_features_z14(bool reset = true);
154 static void set_features_z15(bool reset = true);
155 static void set_features_from(const char* march);
156
157 // Get information about cache line sizes.
158 // As of now and the foreseeable future, line size of all levels will be the same and 256.
159 static unsigned int Dcache_lineSize(unsigned int level = 0) { return _Dcache_lineSize; }
254 _AES128_dataBlk = 16,
255 _AES192_dataBlk = 16,
256 _AES256_dataBlk = 16,
257 _EnccryptedAES128_dataBlk = 16,
258 _EnccryptedAES192_dataBlk = 16,
259 _EnccryptedAES256_dataBlk = 16,
260 _XTSAES128_dataBlk = 16,
261 _XTSAES256_dataBlk = 16,
262 _EncryptedXTSAES128_dataBlk = 16,
263 _EncryptedXTSAES256_dataBlk = 16,
264 _PRNG_dataBlk = 8,
265 };
266 };
267 class MsgDigest {
268 public:
269 enum {
270 _Query = 0,
271 _SHA1 = 1,
272 _SHA256 = 2,
273 _SHA512 = 3,
274 _GHASH = 65,
275 _featureBits = 128,
276
277 // Parameter block sizes (in bytes) for KIMD.
278 _Query_parmBlk_I = 16,
279 _SHA1_parmBlk_I = 20,
280 _SHA256_parmBlk_I = 32,
281 _SHA512_parmBlk_I = 64,
282 _GHASH_parmBlk_I = 32,
283
284 // Parameter block sizes (in bytes) for KLMD.
285 _Query_parmBlk_L = 16,
286 _SHA1_parmBlk_L = 28,
287 _SHA256_parmBlk_L = 40,
288 _SHA512_parmBlk_L = 80,
289
290 // Data block sizes (in bytes).
291 _Query_dataBlk = 0,
292 _SHA1_dataBlk = 64,
293 _SHA256_dataBlk = 64,
294 _SHA512_dataBlk = 128,
295 _GHASH_dataBlk = 16
296 };
297 };
298 class MsgAuthent {
299 public:
300 enum {
301 _Query = 0,
302 _DEA = 1,
303 _TDEA128 = 2,
304 _TDEA192 = 3,
305 _EncryptedDEA = 9,
306 _EncryptedDEA128 = 10,
307 _EncryptedDEA192 = 11,
308 _AES128 = 18,
309 _AES192 = 19,
310 _AES256 = 20,
311 _EnccryptedAES128 = 26,
312 _EnccryptedAES192 = 27,
313 _EnccryptedAES256 = 28,
314 _featureBits = 128,
379 static bool has_Prefetch() { return has_GnrlInstrExtensions() && (AllocatePrefetchStyle > 0); }
380 static bool has_PrefetchRaw() { return has_GnrlInstrExtensions(); }
381 static bool has_MoveImmToMem() { return has_GnrlInstrExtensions(); }
382 static bool has_ExtractCPUAttributes() { return has_GnrlInstrExtensions(); }
383 static bool has_ExecuteExtensions() { return (_features[0] & ExecuteExtensionsMask) == ExecuteExtensionsMask; }
384 // Memory-immediate arithmetic instructions. There is no performance penalty in using them.
385 // Moreover, these memory-immediate instructions are quasi-atomic (>99.99%) on z10
386 // and 100% atomic from z196 onwards, thanks to the specific operand serialization that comes new with z196.
387 static bool has_MemWithImmALUOps() { return has_GnrlInstrExtensions(); }
388 static bool has_AtomicMemWithImmALUOps() { return has_MemWithImmALUOps() && has_InterlockedAccessV1(); }
389 static bool has_FPExtensions() { return (_features[0] & FPExtensionsMask) == FPExtensionsMask; }
390 static bool has_FPSupportEnhancements() { return (_features[0] & FPSupportEnhancementsMask) == FPSupportEnhancementsMask; }
391 static bool has_DecimalFloatingPoint() { return (_features[0] & DecimalFloatingPointMask) == DecimalFloatingPointMask; }
392 static bool has_InterlockedAccessV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; }
393 static bool has_LoadAndALUAtomicV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; }
394 static bool has_PopCount() { return (_features[0] & PopulationCountMask) == PopulationCountMask; }
395 static bool has_LoadStoreConditional() { return (_features[0] & LoadStoreConditionalMask) == LoadStoreConditionalMask; }
396 static bool has_HighWordInstr() { return (_features[0] & HighWordMask) == HighWordMask; }
397 static bool has_FastSync() { return (_features[0] & FastBCRSerializationMask) == FastBCRSerializationMask; }
398 static bool has_DistinctOpnds() { return (_features[0] & DistinctOpndsMask) == DistinctOpndsMask; }
399 static bool has_CryptoExt3() { return (_features[1] & CryptoExtension3Mask) == CryptoExtension3Mask; }
400 static bool has_CryptoExt4() { return (_features[1] & CryptoExtension4Mask) == CryptoExtension4Mask; }
401 static bool has_DFPZonedConversion() { return (_features[0] & DFPZonedConversionMask) == DFPZonedConversionMask; }
402 static bool has_DFPPackedConversion() { return (_features[1] & DFPPackedConversionMask) == DFPPackedConversionMask; }
403 static bool has_MiscInstrExt() { return (_features[0] & MiscInstrExtMask) == MiscInstrExtMask; }
404 static bool has_MiscInstrExt2() { return (_features[0] & MiscInstrExt2Mask) == MiscInstrExt2Mask; }
405 static bool has_MiscInstrExt3() { return (_features[0] & MiscInstrExt3Mask) == MiscInstrExt3Mask; }
406 static bool has_ExecutionHint() { return (_features[0] & ExecutionHintMask) == ExecutionHintMask; }
407 static bool has_LoadAndTrap() { return (_features[0] & LoadAndTrapMask) == LoadAndTrapMask; }
408 static bool has_ProcessorAssist() { return (_features[0] & ProcessorAssistMask) == ProcessorAssistMask; }
409 static bool has_InterlockedAccessV2() { return (_features[0] & InterlockedAccess2Mask) == InterlockedAccess2Mask; }
410 static bool has_LoadAndALUAtomicV2() { return (_features[0] & InterlockedAccess2Mask) == InterlockedAccess2Mask; }
411 static bool has_TxMem() { return ((_features[1] & TransactionalExecutionMask) == TransactionalExecutionMask) &&
412 ((_features[0] & ConstrainedTxExecutionMask) == ConstrainedTxExecutionMask); }
413 static bool has_CryptoExt5() { return (_features[0] & CryptoExtension5Mask) == CryptoExtension5Mask; }
414 static bool has_CryptoExt8() { return (_features[2] & CryptoExtension8Mask) == CryptoExtension8Mask; }
415 static bool has_CryptoExt9() { return (_features[2] & CryptoExtension9Mask) == CryptoExtension9Mask; }
416 static bool has_LoadStoreConditional2() { return (_features[0] & LoadStoreConditional2Mask) == LoadStoreConditional2Mask; }
417 static bool has_VectorFacility() { return (_features[2] & VectorFacilityMask) == VectorFacilityMask; }
418 static bool has_VectorEnhancements1() { return (_features[2] & VectorEnhancements1Mask) == VectorEnhancements1Mask; }
419 static bool has_VectorEnhancements2() { return (_features[2] & VectorEnhancements2Mask) == VectorEnhancements2Mask; }
420 static bool has_VectorPackedDecimal() { return (_features[2] & VectorPackedDecimalMask) == VectorPackedDecimalMask; }
421 static bool has_VectorPackedDecimalEnh() { return (_features[2] & VectorPackedDecimalEnhMask) == VectorPackedDecimalEnhMask; }
422
423 // Crypto features query functions.
424 static bool has_Crypto_AES128() { return has_Crypto() && test_feature_bit(&_cipher_features[0], Cipher::_AES128, Cipher::_featureBits); }
425 static bool has_Crypto_AES192() { return has_Crypto() && test_feature_bit(&_cipher_features[0], Cipher::_AES192, Cipher::_featureBits); }
426 static bool has_Crypto_AES256() { return has_Crypto() && test_feature_bit(&_cipher_features[0], Cipher::_AES256, Cipher::_featureBits); }
427 static bool has_Crypto_AES() { return has_Crypto_AES128() || has_Crypto_AES192() || has_Crypto_AES256(); }
428
429 static bool has_Crypto_SHA1() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA1, MsgDigest::_featureBits); }
430 static bool has_Crypto_SHA256() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA256, MsgDigest::_featureBits); }
431 static bool has_Crypto_SHA512() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA512, MsgDigest::_featureBits); }
432 static bool has_Crypto_GHASH() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_GHASH, MsgDigest::_featureBits); }
433 static bool has_Crypto_SHA() { return has_Crypto_SHA1() || has_Crypto_SHA256() || has_Crypto_SHA512() || has_Crypto_GHASH(); }
434
435 // CPU feature setters (to force model-specific behaviour). Test/debugging only.
436 static void set_has_DecimalFloatingPoint() { _features[0] |= DecimalFloatingPointMask; }
437 static void set_has_FPSupportEnhancements() { _features[0] |= FPSupportEnhancementsMask; }
438 static void set_has_ExecuteExtensions() { _features[0] |= ExecuteExtensionsMask; }
439 static void set_has_MemWithImmALUOps() { _features[0] |= GnrlInstrExtFacilityMask; }
440 static void set_has_MoveImmToMem() { _features[0] |= GnrlInstrExtFacilityMask; }
441 static void set_has_Prefetch() { _features[0] |= GnrlInstrExtFacilityMask; }
442 static void set_has_MultiplySingleImm32() { _features[0] |= GnrlInstrExtFacilityMask; }
443 static void set_has_CompareBranch() { _features[0] |= GnrlInstrExtFacilityMask; }
444 static void set_has_CompareTrap() { _features[0] |= GnrlInstrExtFacilityMask; }
445 static void set_has_RelativeLoadStore() { _features[0] |= GnrlInstrExtFacilityMask; }
446 static void set_has_GnrlInstrExtensions() { _features[0] |= GnrlInstrExtFacilityMask; }
456 static void set_has_ETF3() { _features[0] |= ETF3Mask; }
457 static void set_has_ETF2Enhancements() { _features[0] |= ETF2EnhancementMask; }
458 static void set_has_ETF3Enhancements() { _features[0] |= ETF3EnhancementMask; }
459 static void set_has_Crypto() { _features[0] |= CryptoFacilityMask; }
460 static void set_has_StoreFacilityListExtended() { _features[0] |= StoreFacilityListExtendedMask; }
461
462 static void set_has_InterlockedAccessV1() { _features[0] |= InterlockedAccess1Mask; }
463 static void set_has_PopCount() { _features[0] |= PopulationCountMask; }
464 static void set_has_LoadStoreConditional() { _features[0] |= LoadStoreConditionalMask; }
465 static void set_has_HighWordInstr() { _features[0] |= HighWordMask; }
466 static void set_has_FastSync() { _features[0] |= FastBCRSerializationMask; }
467 static void set_has_DistinctOpnds() { _features[0] |= DistinctOpndsMask; }
468 static void set_has_FPExtensions() { _features[0] |= FPExtensionsMask; }
469 static void set_has_MiscInstrExt() { _features[0] |= MiscInstrExtMask; }
470 static void set_has_MiscInstrExt2() { _features[0] |= MiscInstrExt2Mask; }
471 static void set_has_MiscInstrExt3() { _features[0] |= MiscInstrExt3Mask; }
472 static void set_has_ProcessorAssist() { _features[0] |= ProcessorAssistMask; }
473 static void set_has_InterlockedAccessV2() { _features[0] |= InterlockedAccess2Mask; }
474 static void set_has_LoadAndALUAtomicV2() { _features[0] |= InterlockedAccess2Mask; }
475 static void set_has_TxMem() { _features[0] |= ConstrainedTxExecutionMask; _features[1] |= TransactionalExecutionMask; }
476 static void set_has_CryptoExt3() { _features[1] |= CryptoExtension3Mask; }
477 static void set_has_CryptoExt4() { _features[1] |= CryptoExtension4Mask; }
478 static void set_has_LoadStoreConditional2() { _features[0] |= LoadStoreConditional2Mask; }
479 static void set_has_CryptoExt5() { _features[0] |= CryptoExtension5Mask; }
480 static void set_has_CryptoExt8() { _features[2] |= CryptoExtension8Mask; }
481 static void set_has_CryptoExt9() { _features[2] |= CryptoExtension9Mask; }
482 static void set_has_VectorFacility() { _features[2] |= VectorFacilityMask; }
483 static void set_has_VectorEnhancements1() { _features[2] |= VectorEnhancements1Mask; }
484 static void set_has_VectorEnhancements2() { _features[2] |= VectorEnhancements2Mask; }
485 static void set_has_VectorPackedDecimal() { _features[2] |= VectorPackedDecimalMask; }
486 static void set_has_VectorPackedDecimalEnh() { _features[2] |= VectorPackedDecimalEnhMask; }
487
488 static void reset_has_VectorFacility() { _features[2] &= ~VectorFacilityMask; }
489
490 // Assembler testing.
491 static void allow_all();
492 static void revert();
493
494 // Generate trapping instructions into C-code.
495 // Sometimes helpful for debugging.
496 static unsigned long z_SIGILL();
497 static unsigned long z_SIGSEGV();
498 };
|
1 /*
2 * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2016, 2021 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
30 #include "runtime/abstract_vm_version.hpp"
31 #include "runtime/globals_extension.hpp"
32
33 class VM_Version: public Abstract_VM_Version {
34
35 protected:
36 // z/Architecture is the name of the 64-bit extension of the 31-bit s390
37 // architecture.
38 //
39 // For information concerning the life span of the individual
40 // z/Architecture models, please check out the comments/tables
41 // in vm_version_s390.cpp
42
43 // ----------------------------------------------
44 // --- FeatureBitString Bits 0.. 63 (DW[0]) ---
45 // ----------------------------------------------
46 // 11222334445566
47 // 04826048260482604
48 #define StoreFacilityListExtendedMask 0x0100000000000000UL // z9
49 #define ETF2Mask 0x0000800000000000UL // z900
50 #define CryptoFacilityMask 0x0000400000000000UL // z990 (aka message-security assist)
51 #define LongDispFacilityMask 0x0000200000000000UL // z900 with microcode update
52 #define LongDispFacilityHighPerfMask 0x0000300000000000UL // z990
53 #define HFPMultiplyAndAddMask 0x0000080000000000UL // z990
54 #define ExtImmedFacilityMask 0x0000040000000000UL // z9
55 #define ETF3Mask 0x0000020000000000UL // z990/z9 (?)
56 #define HFPUnnormalizedMask 0x0000010000000000UL // z9
57 #define ETF2EnhancementMask 0x0000008000000000UL // z9
58 #define StoreClockFastMask 0x0000004000000000UL // z9
59 #define ParsingEnhancementsMask 0x0000002000000000UL // z10(?)
60 #define ETF3EnhancementMask 0x0000000200000000UL // z9
61 #define ExtractCPUTimeMask 0x0000000100000000UL // z10
62 #define CompareSwapStoreMask 0x00000000c0000000UL // z10
63 #define GnrlInstrExtFacilityMask 0x0000000020000000UL // z10
64 #define ExecuteExtensionsMask 0x0000000010000000UL // z10
65 #define FPExtensionsMask 0x0000000004000000UL // z196
66 #define FPSupportEnhancementsMask 0x0000000000400000UL // z10
67 #define DecimalFloatingPointMask 0x0000000000300000UL // z10
68 // z196 begin
69 #define DistinctOpndsMask 0x0000000000040000UL // z196
70 #define FastBCRSerializationMask DistinctOpndsMask
79 #define ExecutionHintMask MiscInstrExtMask
80 #define LoadAndTrapMask MiscInstrExtMask
81 #define ProcessorAssistMask MiscInstrExtMask
82 #define ConstrainedTxExecutionMask 0x0000000000002000UL // ec12
83 #define InterlockedAccess2Mask 0x0000000000000800UL // ec12
84 // EC12 end
85 // z13 begin
86 #define LoadStoreConditional2Mask 0x0000000000000400UL // z13
87 #define CryptoExtension5Mask 0x0000000000000040UL // z13
88 // z13 end
89 #define MiscInstrExt2Mask 0x0000000000000020UL // z14
90 #define MiscInstrExt3Mask 0x0000000000000004UL // z15
91 // ----------------------------------------------
92 // --- FeatureBitString Bits 64..127 (DW[1]) ---
93 // ----------------------------------------------
94 // 11111111
95 // 66778889900011222
96 // 48260482604826048
97 #define TransactionalExecutionMask 0x0040000000000000UL // ec12
98 #define CryptoExtension3Mask 0x0008000000000000UL // z196
99 #define CryptoExtension4Mask 0x0004000000000000UL // z196 (aka message-security assist extension 4, for KMF, KMCTR, KMO)
100 #define DFPPackedConversionMask 0x0000800000000000UL // z13
101 // ----------------------------------------------
102 // --- FeatureBitString Bits 128..192 (DW[2]) ---
103 // ----------------------------------------------
104 // 11111111111111111
105 // 23344455666778889
106 // 82604826048260482
107 #define VectorFacilityMask 0x4000000000000000UL // z13, not avail in VM guest mode!
108 #define ExecutionProtectionMask 0x2000000000000000UL // z14
109 #define GuardedStorageMask 0x0400000000000000UL // z14
110 #define VectorEnhancements1Mask 0x0100000000000000UL // z14
111 #define VectorPackedDecimalMask 0x0200000000000000UL // z14
112 #define CryptoExtension8Mask 0x0000200000000000UL // z14 (aka message-security assist extension 8, for KMA)
113 #define VectorEnhancements2Mask 0x0000080000000000UL // z15
114 #define VectorPackedDecimalEnhMask 0x0000008000000000UL // z15
115 #define CryptoExtension9Mask 0x0000001000000000UL // z15 (aka message-security assist extension 9)
116 #define DeflateMask 0x0000010000000000UL // z15
117
118 enum {
119 _max_cache_levels = 8, // As limited by ECAG instruction.
120 _features_buffer_len = 4, // in DW
121 _code_buffer_len = 2*256 // For feature detection code.
122 };
123 static unsigned long _features[_features_buffer_len];
124 static unsigned long _cipher_features_KM[_features_buffer_len];
125 static unsigned long _cipher_features_KMA[_features_buffer_len];
126 static unsigned long _cipher_features_KMF[_features_buffer_len];
127 static unsigned long _cipher_features_KMCTR[_features_buffer_len];
128 static unsigned long _cipher_features_KMO[_features_buffer_len];
129 static unsigned long _msgdigest_features[_features_buffer_len];
130 static unsigned int _nfeatures;
131 static unsigned int _ncipher_features_KM;
132 static unsigned int _ncipher_features_KMA;
133 static unsigned int _ncipher_features_KMF;
134 static unsigned int _ncipher_features_KMCTR;
135 static unsigned int _ncipher_features_KMO;
136 static unsigned int _nmsgdigest_features;
137 static unsigned int _Dcache_lineSize;
138 static unsigned int _Icache_lineSize;
139 static bool _is_determine_features_test_running;
140 static const char* _model_string;
141
142 static bool test_feature_bit(unsigned long* featureBuffer, int featureNum, unsigned int bufLen);
143 static int get_model_index();
144 static void set_features_string();
145 static void print_features_internal(const char* text, bool print_anyway=false);
146 static void determine_features();
147 static long call_getFeatures(unsigned long* buffer, int buflen, int functionCode);
148 static void set_getFeatures(address entryPoint);
149 static void clear_buffer(unsigned long* buffer, unsigned int len);
150 static void copy_buffer(unsigned long* to, unsigned long* from, unsigned int len);
151 static int calculate_ECAG_functionCode(unsigned int attributeIndication,
152 unsigned int levelIndication,
153 unsigned int typeIndication);
154
155 // Setting features via march=z900|z990|z9|z10|z196|ec12|z13|z14|z15 commandline option.
156 static void reset_features(bool reset);
157 static void set_features_z900(bool reset = true);
158 static void set_features_z990(bool reset = true);
159 static void set_features_z9(bool reset = true);
160 static void set_features_z10(bool reset = true);
161 static void set_features_z196(bool reset = true);
162 static void set_features_ec12(bool reset = true);
163 static void set_features_z13(bool reset = true);
164 static void set_features_z14(bool reset = true);
165 static void set_features_z15(bool reset = true);
166 static void set_features_from(const char* march);
167
168 // Get information about cache line sizes.
169 // As of now and the foreseeable future, line size of all levels will be the same and 256.
170 static unsigned int Dcache_lineSize(unsigned int level = 0) { return _Dcache_lineSize; }
265 _AES128_dataBlk = 16,
266 _AES192_dataBlk = 16,
267 _AES256_dataBlk = 16,
268 _EnccryptedAES128_dataBlk = 16,
269 _EnccryptedAES192_dataBlk = 16,
270 _EnccryptedAES256_dataBlk = 16,
271 _XTSAES128_dataBlk = 16,
272 _XTSAES256_dataBlk = 16,
273 _EncryptedXTSAES128_dataBlk = 16,
274 _EncryptedXTSAES256_dataBlk = 16,
275 _PRNG_dataBlk = 8,
276 };
277 };
278 class MsgDigest {
279 public:
280 enum {
281 _Query = 0,
282 _SHA1 = 1,
283 _SHA256 = 2,
284 _SHA512 = 3,
285 _SHA3_224 = 32,
286 _SHA3_256 = 33,
287 _SHA3_384 = 34,
288 _SHA3_512 = 35,
289 _SHAKE_128 = 36,
290 _SHAKE_256 = 37,
291 _GHASH = 65,
292 _featureBits = 128,
293
294 // Parameter block sizes (in bytes) for KIMD.
295 _Query_parmBlk_I = 16,
296 _SHA1_parmBlk_I = 20,
297 _SHA256_parmBlk_I = 32,
298 _SHA512_parmBlk_I = 64,
299 _SHA3_224_parmBlk_I = 200,
300 _SHA3_256_parmBlk_I = 200,
301 _SHA3_384_parmBlk_I = 200,
302 _SHA3_512_parmBlk_I = 200,
303 _SHAKE_128_parmBlk_I = 200,
304 _SHAKE_256_parmBlk_I = 200,
305 _GHASH_parmBlk_I = 32,
306
307 // Parameter block sizes (in bytes) for KLMD.
308 _Query_parmBlk_L = 16,
309 _SHA1_parmBlk_L = 28,
310 _SHA256_parmBlk_L = 40,
311 _SHA512_parmBlk_L = 80,
312 _SHA3_224_parmBlk_L = 200,
313 _SHA3_256_parmBlk_L = 200,
314 _SHA3_384_parmBlk_L = 200,
315 _SHA3_512_parmBlk_L = 200,
316 _SHAKE_128_parmBlk_L = 200,
317 _SHAKE_256_parmBlk_L = 200,
318
319 // Data block sizes (in bytes).
320 _Query_dataBlk = 0,
321 _SHA1_dataBlk = 64,
322 _SHA256_dataBlk = 64,
323 _SHA512_dataBlk = 128,
324 _SHA3_224_dataBlk = 144,
325 _SHA3_256_dataBlk = 136,
326 _SHA3_384_dataBlk = 104,
327 _SHA3_512_dataBlk = 72,
328 _SHAKE_128_dataBlk = 168,
329 _SHAKE_256_dataBlk = 136,
330 _GHASH_dataBlk = 16
331 };
332 };
333 class MsgAuthent {
334 public:
335 enum {
336 _Query = 0,
337 _DEA = 1,
338 _TDEA128 = 2,
339 _TDEA192 = 3,
340 _EncryptedDEA = 9,
341 _EncryptedDEA128 = 10,
342 _EncryptedDEA192 = 11,
343 _AES128 = 18,
344 _AES192 = 19,
345 _AES256 = 20,
346 _EnccryptedAES128 = 26,
347 _EnccryptedAES192 = 27,
348 _EnccryptedAES256 = 28,
349 _featureBits = 128,
414 static bool has_Prefetch() { return has_GnrlInstrExtensions() && (AllocatePrefetchStyle > 0); }
415 static bool has_PrefetchRaw() { return has_GnrlInstrExtensions(); }
416 static bool has_MoveImmToMem() { return has_GnrlInstrExtensions(); }
417 static bool has_ExtractCPUAttributes() { return has_GnrlInstrExtensions(); }
418 static bool has_ExecuteExtensions() { return (_features[0] & ExecuteExtensionsMask) == ExecuteExtensionsMask; }
419 // Memory-immediate arithmetic instructions. There is no performance penalty in using them.
420 // Moreover, these memory-immediate instructions are quasi-atomic (>99.99%) on z10
421 // and 100% atomic from z196 onwards, thanks to the specific operand serialization that comes new with z196.
422 static bool has_MemWithImmALUOps() { return has_GnrlInstrExtensions(); }
423 static bool has_AtomicMemWithImmALUOps() { return has_MemWithImmALUOps() && has_InterlockedAccessV1(); }
424 static bool has_FPExtensions() { return (_features[0] & FPExtensionsMask) == FPExtensionsMask; }
425 static bool has_FPSupportEnhancements() { return (_features[0] & FPSupportEnhancementsMask) == FPSupportEnhancementsMask; }
426 static bool has_DecimalFloatingPoint() { return (_features[0] & DecimalFloatingPointMask) == DecimalFloatingPointMask; }
427 static bool has_InterlockedAccessV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; }
428 static bool has_LoadAndALUAtomicV1() { return (_features[0] & InterlockedAccess1Mask) == InterlockedAccess1Mask; }
429 static bool has_PopCount() { return (_features[0] & PopulationCountMask) == PopulationCountMask; }
430 static bool has_LoadStoreConditional() { return (_features[0] & LoadStoreConditionalMask) == LoadStoreConditionalMask; }
431 static bool has_HighWordInstr() { return (_features[0] & HighWordMask) == HighWordMask; }
432 static bool has_FastSync() { return (_features[0] & FastBCRSerializationMask) == FastBCRSerializationMask; }
433 static bool has_DistinctOpnds() { return (_features[0] & DistinctOpndsMask) == DistinctOpndsMask; }
434 static bool has_DFPZonedConversion() { return (_features[0] & DFPZonedConversionMask) == DFPZonedConversionMask; }
435 static bool has_DFPPackedConversion() { return (_features[1] & DFPPackedConversionMask) == DFPPackedConversionMask; }
436 static bool has_MiscInstrExt() { return (_features[0] & MiscInstrExtMask) == MiscInstrExtMask; }
437 static bool has_MiscInstrExt2() { return (_features[0] & MiscInstrExt2Mask) == MiscInstrExt2Mask; }
438 static bool has_MiscInstrExt3() { return (_features[0] & MiscInstrExt3Mask) == MiscInstrExt3Mask; }
439 static bool has_ExecutionHint() { return (_features[0] & ExecutionHintMask) == ExecutionHintMask; }
440 static bool has_LoadAndTrap() { return (_features[0] & LoadAndTrapMask) == LoadAndTrapMask; }
441 static bool has_ProcessorAssist() { return (_features[0] & ProcessorAssistMask) == ProcessorAssistMask; }
442 static bool has_InterlockedAccessV2() { return (_features[0] & InterlockedAccess2Mask) == InterlockedAccess2Mask; }
443 static bool has_LoadAndALUAtomicV2() { return (_features[0] & InterlockedAccess2Mask) == InterlockedAccess2Mask; }
444 static bool has_TxMem() { return ((_features[1] & TransactionalExecutionMask) == TransactionalExecutionMask) &&
445 ((_features[0] & ConstrainedTxExecutionMask) == ConstrainedTxExecutionMask); }
446 static bool has_CryptoExt3() { return (_features[1] & CryptoExtension3Mask) == CryptoExtension3Mask; }
447 static bool has_CryptoExt4() { return (_features[1] & CryptoExtension4Mask) == CryptoExtension4Mask; }
448 static bool has_CryptoExt5() { return (_features[0] & CryptoExtension5Mask) == CryptoExtension5Mask; }
449 static bool has_CryptoExt8() { return (_features[2] & CryptoExtension8Mask) == CryptoExtension8Mask; }
450 static bool has_CryptoExt9() { return (_features[2] & CryptoExtension9Mask) == CryptoExtension9Mask; }
451 static bool has_LoadStoreConditional2() { return (_features[0] & LoadStoreConditional2Mask) == LoadStoreConditional2Mask; }
452 static bool has_VectorFacility() { return (_features[2] & VectorFacilityMask) == VectorFacilityMask; }
453 static bool has_VectorEnhancements1() { return (_features[2] & VectorEnhancements1Mask) == VectorEnhancements1Mask; }
454 static bool has_VectorEnhancements2() { return (_features[2] & VectorEnhancements2Mask) == VectorEnhancements2Mask; }
455 static bool has_VectorPackedDecimal() { return (_features[2] & VectorPackedDecimalMask) == VectorPackedDecimalMask; }
456 static bool has_VectorPackedDecimalEnh() { return (_features[2] & VectorPackedDecimalEnhMask) == VectorPackedDecimalEnhMask; }
457
458 // Crypto features query functions.
459 static bool has_Crypto_AES128() { return has_Crypto() && test_feature_bit(&_cipher_features_KM[0], Cipher::_AES128, Cipher::_featureBits); }
460 static bool has_Crypto_AES192() { return has_Crypto() && test_feature_bit(&_cipher_features_KM[0], Cipher::_AES192, Cipher::_featureBits); }
461 static bool has_Crypto_AES256() { return has_Crypto() && test_feature_bit(&_cipher_features_KM[0], Cipher::_AES256, Cipher::_featureBits); }
462 static bool has_Crypto_AES() { return has_Crypto_AES128() || has_Crypto_AES192() || has_Crypto_AES256(); }
463
464 static bool has_Crypto_SHA1() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA1, MsgDigest::_featureBits); }
465 static bool has_Crypto_SHA256() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA256, MsgDigest::_featureBits); }
466 static bool has_Crypto_SHA512() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_SHA512, MsgDigest::_featureBits); }
467 static bool has_Crypto_GHASH() { return has_Crypto() && test_feature_bit(&_msgdigest_features[0], MsgDigest::_GHASH, MsgDigest::_featureBits); }
468 static bool has_Crypto_SHA() { return has_Crypto_SHA1() || has_Crypto_SHA256() || has_Crypto_SHA512() || has_Crypto_GHASH(); }
469
470 // CPU feature setters (to force model-specific behaviour). Test/debugging only.
471 static void set_has_DecimalFloatingPoint() { _features[0] |= DecimalFloatingPointMask; }
472 static void set_has_FPSupportEnhancements() { _features[0] |= FPSupportEnhancementsMask; }
473 static void set_has_ExecuteExtensions() { _features[0] |= ExecuteExtensionsMask; }
474 static void set_has_MemWithImmALUOps() { _features[0] |= GnrlInstrExtFacilityMask; }
475 static void set_has_MoveImmToMem() { _features[0] |= GnrlInstrExtFacilityMask; }
476 static void set_has_Prefetch() { _features[0] |= GnrlInstrExtFacilityMask; }
477 static void set_has_MultiplySingleImm32() { _features[0] |= GnrlInstrExtFacilityMask; }
478 static void set_has_CompareBranch() { _features[0] |= GnrlInstrExtFacilityMask; }
479 static void set_has_CompareTrap() { _features[0] |= GnrlInstrExtFacilityMask; }
480 static void set_has_RelativeLoadStore() { _features[0] |= GnrlInstrExtFacilityMask; }
481 static void set_has_GnrlInstrExtensions() { _features[0] |= GnrlInstrExtFacilityMask; }
491 static void set_has_ETF3() { _features[0] |= ETF3Mask; }
492 static void set_has_ETF2Enhancements() { _features[0] |= ETF2EnhancementMask; }
493 static void set_has_ETF3Enhancements() { _features[0] |= ETF3EnhancementMask; }
494 static void set_has_Crypto() { _features[0] |= CryptoFacilityMask; }
495 static void set_has_StoreFacilityListExtended() { _features[0] |= StoreFacilityListExtendedMask; }
496
497 static void set_has_InterlockedAccessV1() { _features[0] |= InterlockedAccess1Mask; }
498 static void set_has_PopCount() { _features[0] |= PopulationCountMask; }
499 static void set_has_LoadStoreConditional() { _features[0] |= LoadStoreConditionalMask; }
500 static void set_has_HighWordInstr() { _features[0] |= HighWordMask; }
501 static void set_has_FastSync() { _features[0] |= FastBCRSerializationMask; }
502 static void set_has_DistinctOpnds() { _features[0] |= DistinctOpndsMask; }
503 static void set_has_FPExtensions() { _features[0] |= FPExtensionsMask; }
504 static void set_has_MiscInstrExt() { _features[0] |= MiscInstrExtMask; }
505 static void set_has_MiscInstrExt2() { _features[0] |= MiscInstrExt2Mask; }
506 static void set_has_MiscInstrExt3() { _features[0] |= MiscInstrExt3Mask; }
507 static void set_has_ProcessorAssist() { _features[0] |= ProcessorAssistMask; }
508 static void set_has_InterlockedAccessV2() { _features[0] |= InterlockedAccess2Mask; }
509 static void set_has_LoadAndALUAtomicV2() { _features[0] |= InterlockedAccess2Mask; }
510 static void set_has_TxMem() { _features[0] |= ConstrainedTxExecutionMask; _features[1] |= TransactionalExecutionMask; }
511 static void set_has_LoadStoreConditional2() { _features[0] |= LoadStoreConditional2Mask; }
512 static void set_has_CryptoExt3() { _features[1] |= CryptoExtension3Mask; }
513 static void set_has_CryptoExt4() { _features[1] |= CryptoExtension4Mask; }
514 static void set_has_CryptoExt5() { _features[0] |= CryptoExtension5Mask; }
515 static void set_has_CryptoExt8() { _features[2] |= CryptoExtension8Mask; }
516 static void set_has_CryptoExt9() { _features[2] |= CryptoExtension9Mask; }
517 static void set_has_VectorFacility() { _features[2] |= VectorFacilityMask; }
518 static void set_has_VectorEnhancements1() { _features[2] |= VectorEnhancements1Mask; }
519 static void set_has_VectorEnhancements2() { _features[2] |= VectorEnhancements2Mask; }
520 static void set_has_VectorPackedDecimal() { _features[2] |= VectorPackedDecimalMask; }
521 static void set_has_VectorPackedDecimalEnh() { _features[2] |= VectorPackedDecimalEnhMask; }
522
523 static void reset_has_VectorFacility() { _features[2] &= ~VectorFacilityMask; }
524
525 // Assembler testing.
526 static void allow_all();
527 static void revert();
528
529 // Generate trapping instructions into C-code.
530 // Sometimes helpful for debugging.
531 static unsigned long z_SIGILL();
532 static unsigned long z_SIGSEGV();
533 };
|