1 /* 2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2016, 2020 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 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "jvm.h" 28 #include "asm/assembler.inline.hpp" 29 #include "compiler/disassembler.hpp" 30 #include "code/compiledIC.hpp" 31 #include "memory/resourceArea.hpp" 32 #include "runtime/java.hpp" 33 #include "runtime/stubCodeGenerator.hpp" 34 #include "runtime/vm_version.hpp" 35 36 # include <sys/sysinfo.h> 37 38 bool VM_Version::_is_determine_features_test_running = false; 39 const char* VM_Version::_model_string; 40 41 unsigned long VM_Version::_features[_features_buffer_len] = {0, 0, 0, 0}; 42 unsigned long VM_Version::_cipher_features[_features_buffer_len] = {0, 0, 0, 0}; 43 unsigned long VM_Version::_msgdigest_features[_features_buffer_len] = {0, 0, 0, 0}; 44 unsigned int VM_Version::_nfeatures = 0; 45 unsigned int VM_Version::_ncipher_features = 0; 46 unsigned int VM_Version::_nmsgdigest_features = 0; 47 unsigned int VM_Version::_Dcache_lineSize = DEFAULT_CACHE_LINE_SIZE; 48 unsigned int VM_Version::_Icache_lineSize = DEFAULT_CACHE_LINE_SIZE; 49 50 static const char* z_gen[] = {" ", "G1", "G2", "G3", "G4", "G5", "G6", "G7" }; 51 static const char* z_machine[] = {" ", "2064", "2084", "2094", "2097", "2817", " ", "2964" }; 52 static const char* z_name[] = {" ", "z900", "z990", "z9 EC", "z10 EC", "z196 EC", "ec12", "z13" }; 53 54 void VM_Version::initialize() { 55 determine_features(); // Get processor capabilities. 56 set_features_string(); // Set a descriptive feature indication. 57 58 if (Verbose) { 59 print_features(); 60 } 61 62 intx cache_line_size = Dcache_lineSize(0); 63 64 #ifdef COMPILER2 65 MaxVectorSize = 8; 66 #endif 67 68 if (has_PrefetchRaw()) { 69 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { // not preset 70 // 0 = no prefetch. 71 // 1 = Prefetch instructions for each allocation. 72 // 2 = Use TLAB watermark to gate allocation prefetch. 73 AllocatePrefetchStyle = 1; 74 } 75 76 if (AllocatePrefetchStyle > 0) { // Prefetching turned on at all? 77 // Distance to prefetch ahead of allocation pointer. 78 if (FLAG_IS_DEFAULT(AllocatePrefetchDistance) || (AllocatePrefetchDistance < 0)) { // not preset 79 AllocatePrefetchDistance = 0; 80 } 81 82 // Number of lines to prefetch ahead of allocation pointer. 83 if (FLAG_IS_DEFAULT(AllocatePrefetchLines) || (AllocatePrefetchLines <= 0)) { // not preset 84 AllocatePrefetchLines = 3; 85 } 86 87 // Step size in bytes of sequential prefetch instructions. 88 if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize) || (AllocatePrefetchStepSize <= 0)) { // not preset 89 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size); 90 } else if (AllocatePrefetchStepSize < cache_line_size) { 91 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size); 92 } else { 93 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size); 94 } 95 } else { 96 FLAG_SET_DEFAULT(AllocatePrefetchStyle, 0); 97 AllocatePrefetchDistance = 0; 98 AllocatePrefetchLines = 0; 99 // Can't be zero. Will SIGFPE during constraints checking. 100 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size); 101 } 102 103 } else { 104 FLAG_SET_DEFAULT(AllocatePrefetchStyle, 0); 105 AllocatePrefetchDistance = 0; 106 AllocatePrefetchLines = 0; 107 // Can't be zero. Will SIGFPE during constraints checking. 108 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size); 109 } 110 111 // TODO: 112 // On z/Architecture, cache line size is significantly large (256 bytes). Do we really need 113 // to keep contended members that far apart? Performance tests are required. 114 if (FLAG_IS_DEFAULT(ContendedPaddingWidth) && (cache_line_size > ContendedPaddingWidth)) { 115 ContendedPaddingWidth = cache_line_size; 116 } 117 118 // On z/Architecture, the CRC32/CRC32C intrinsics are implemented "by hand". 119 // TODO: Provide implementation based on the vector instructions available from z13. 120 // Note: The CHECKSUM instruction, which has been there since the very beginning 121 // (of z/Architecture), computes "some kind of" a checksum. 122 // It has nothing to do with the CRC32 algorithm. 123 if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) { 124 FLAG_SET_DEFAULT(UseCRC32Intrinsics, true); 125 } 126 if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) { 127 FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true); 128 } 129 130 // TODO: Provide implementation. 131 if (UseAdler32Intrinsics) { 132 warning("Adler32Intrinsics not available on this CPU."); 133 FLAG_SET_DEFAULT(UseAdler32Intrinsics, false); 134 } 135 136 // On z/Architecture, we take UseAES as the general switch to enable/disable the AES intrinsics. 137 // The specific, and yet to be defined, switches UseAESxxxIntrinsics will then be set 138 // depending on the actual machine capabilities. 139 // Explicitly setting them via CmdLine option takes precedence, of course. 140 // TODO: UseAESIntrinsics must be made keylength specific. 141 // As of March 2015 and Java8, only AES128 is supported by the Java Cryptographic Extensions. 142 // Therefore, UseAESIntrinsics is of minimal use at the moment. 143 if (FLAG_IS_DEFAULT(UseAES) && has_Crypto_AES()) { 144 FLAG_SET_DEFAULT(UseAES, true); 145 } 146 if (UseAES && !has_Crypto_AES()) { 147 warning("AES instructions are not available on this CPU"); 148 FLAG_SET_DEFAULT(UseAES, false); 149 } 150 if (UseAES) { 151 if (FLAG_IS_DEFAULT(UseAESIntrinsics)) { 152 FLAG_SET_DEFAULT(UseAESIntrinsics, true); 153 } 154 } 155 if (UseAESIntrinsics && !has_Crypto_AES()) { 156 warning("AES intrinsics are not available on this CPU"); 157 FLAG_SET_DEFAULT(UseAESIntrinsics, false); 158 } 159 if (UseAESIntrinsics && !UseAES) { 160 warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled."); 161 FLAG_SET_DEFAULT(UseAESIntrinsics, false); 162 } 163 164 // TODO: implement AES/CTR intrinsics 165 if (UseAESCTRIntrinsics) { 166 warning("AES/CTR intrinsics are not available on this CPU"); 167 FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false); 168 } 169 170 if (FLAG_IS_DEFAULT(UseGHASHIntrinsics) && has_Crypto_GHASH()) { 171 FLAG_SET_DEFAULT(UseGHASHIntrinsics, true); 172 } 173 if (UseGHASHIntrinsics && !has_Crypto_GHASH()) { 174 warning("GHASH intrinsics are not available on this CPU"); 175 FLAG_SET_DEFAULT(UseGHASHIntrinsics, false); 176 } 177 178 if (FLAG_IS_DEFAULT(UseFMA)) { 179 FLAG_SET_DEFAULT(UseFMA, true); 180 } 181 182 if (UseMD5Intrinsics) { 183 warning("MD5 intrinsics are not available on this CPU"); 184 FLAG_SET_DEFAULT(UseMD5Intrinsics, false); 185 } 186 187 // On z/Architecture, we take UseSHA as the general switch to enable/disable the SHA intrinsics. 188 // The specific switches UseSHAxxxIntrinsics will then be set depending on the actual 189 // machine capabilities. 190 // Explicitly setting them via CmdLine option takes precedence, of course. 191 if (FLAG_IS_DEFAULT(UseSHA) && has_Crypto_SHA()) { 192 FLAG_SET_DEFAULT(UseSHA, true); 193 } 194 if (UseSHA && !has_Crypto_SHA()) { 195 warning("SHA instructions are not available on this CPU"); 196 FLAG_SET_DEFAULT(UseSHA, false); 197 } 198 if (UseSHA && has_Crypto_SHA1()) { 199 if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) { 200 FLAG_SET_DEFAULT(UseSHA1Intrinsics, true); 201 } 202 } else if (UseSHA1Intrinsics) { 203 warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU."); 204 FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); 205 } 206 if (UseSHA && has_Crypto_SHA256()) { 207 if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) { 208 FLAG_SET_DEFAULT(UseSHA256Intrinsics, true); 209 } 210 } else if (UseSHA256Intrinsics) { 211 warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU."); 212 FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); 213 } 214 if (UseSHA && has_Crypto_SHA512()) { 215 if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) { 216 FLAG_SET_DEFAULT(UseSHA512Intrinsics, true); 217 } 218 } else if (UseSHA512Intrinsics) { 219 warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU."); 220 FLAG_SET_DEFAULT(UseSHA512Intrinsics, false); 221 } 222 223 if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) { 224 FLAG_SET_DEFAULT(UseSHA, false); 225 } 226 227 #ifdef COMPILER2 228 if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) { 229 FLAG_SET_DEFAULT(UseMultiplyToLenIntrinsic, true); 230 } 231 if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) { 232 FLAG_SET_DEFAULT(UseMontgomeryMultiplyIntrinsic, true); 233 } 234 if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) { 235 FLAG_SET_DEFAULT(UseMontgomerySquareIntrinsic, true); 236 } 237 #endif 238 if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { 239 FLAG_SET_DEFAULT(UsePopCountInstruction, true); 240 } 241 242 // z/Architecture supports 8-byte compare-exchange operations 243 // (see Atomic::cmpxchg) 244 // and 'atomic long memory ops' (see Unsafe_GetLongVolatile). 245 _supports_cx8 = true; 246 247 _supports_atomic_getadd4 = VM_Version::has_LoadAndALUAtomicV1(); 248 _supports_atomic_getadd8 = VM_Version::has_LoadAndALUAtomicV1(); 249 250 // z/Architecture supports unaligned memory accesses. 251 // Performance penalty is negligible. An additional tick or so 252 // is lost if the accessed data spans a cache line boundary. 253 // Unaligned accesses are not atomic, of course. 254 if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) { 255 FLAG_SET_DEFAULT(UseUnalignedAccesses, true); 256 } 257 } 258 259 260 void VM_Version::set_features_string() { 261 // A note on the _features_string format: 262 // There are jtreg tests checking the _features_string for various properties. 263 // For some strange reason, these tests require the string to contain 264 // only _lowercase_ characters. Keep that in mind when being surprised 265 // about the unusual notation of features - and when adding new ones. 266 // Features may have one comma at the end. 267 // Furthermore, use one, and only one, separator space between features. 268 // Multiple spaces are considered separate tokens, messing up everything. 269 unsigned int ambiguity = 0; 270 _model_string = z_name[0]; 271 if (is_z13()) { 272 _features_string = "system-z, g7-z13, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm, vectorinstr"; 273 _model_string = z_name[7]; 274 ambiguity++; 275 } 276 if (is_ec12()) { 277 _features_string = "system-z, g6-ec12, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update, txm"; 278 _model_string = z_name[6]; 279 ambiguity++; 280 } 281 if (is_z196()) { 282 _features_string = "system-z, g5-z196, ldisp_fast, extimm, pcrel_load/store, cmpb, cond_load/store, interlocked_update"; 283 _model_string = z_name[5]; 284 ambiguity++; 285 } 286 if (is_z10()) { 287 _features_string = "system-z, g4-z10, ldisp_fast, extimm, pcrel_load/store, cmpb"; 288 _model_string = z_name[4]; 289 ambiguity++; 290 } 291 if (is_z9()) { 292 _features_string = "system-z, g3-z9, ldisp_fast, extimm, out-of-support as of 2016-04-01"; 293 _model_string = z_name[3]; 294 ambiguity++; 295 } 296 if (is_z990()) { 297 _features_string = "system-z, g2-z990, ldisp_fast, out-of-support as of 2014-07-01"; 298 _model_string = z_name[2]; 299 ambiguity++; 300 } 301 if (is_z900()) { 302 _features_string = "system-z, g1-z900, ldisp, out-of-support as of 2014-07-01"; 303 _model_string = z_name[1]; 304 ambiguity++; 305 } 306 307 if (ambiguity == 0) { 308 _features_string = "z/Architecture (unknown generation)"; 309 } else if (ambiguity > 1) { 310 tty->print_cr("*** WARNING *** Ambiguous z/Architecture detection, ambiguity = %d", ambiguity); 311 tty->print_cr(" oldest detected generation is %s", _features_string); 312 _features_string = "z/Architecture (ambiguous detection)"; 313 } 314 315 if (has_Crypto_AES()) { 316 char buf[256]; 317 assert(strlen(_features_string) + 3*8 < sizeof(buf), "increase buffer size"); 318 jio_snprintf(buf, sizeof(buf), "%s%s%s%s", 319 _features_string, 320 has_Crypto_AES128() ? ", aes128" : "", 321 has_Crypto_AES192() ? ", aes192" : "", 322 has_Crypto_AES256() ? ", aes256" : ""); 323 _features_string = os::strdup(buf); 324 } 325 326 if (has_Crypto_SHA()) { 327 char buf[256]; 328 assert(strlen(_features_string) + 6 + 2*8 + 7 < sizeof(buf), "increase buffer size"); 329 jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s", 330 _features_string, 331 has_Crypto_SHA1() ? ", sha1" : "", 332 has_Crypto_SHA256() ? ", sha256" : "", 333 has_Crypto_SHA512() ? ", sha512" : "", 334 has_Crypto_GHASH() ? ", ghash" : ""); 335 if (has_Crypto_AES()) { os::free((void *)_features_string); } 336 _features_string = os::strdup(buf); 337 } 338 } 339 340 // featureBuffer - bit array indicating availability of various features 341 // featureNum - bit index of feature to be tested 342 // Featurenum < 0 requests test for any nonzero bit in featureBuffer. 343 // bufLen - length of featureBuffer in bits 344 bool VM_Version::test_feature_bit(unsigned long* featureBuffer, int featureNum, unsigned int bufLen) { 345 assert(bufLen > 0, "buffer len must be positive"); 346 assert((bufLen & 0x0007) == 0, "unaligned buffer len"); 347 assert(((intptr_t)featureBuffer&0x0007) == 0, "unaligned feature buffer"); 348 if (featureNum < 0) { 349 // Any bit set at all? 350 bool anyBit = false; 351 for (size_t i = 0; i < bufLen/(8*sizeof(long)); i++) { 352 anyBit = anyBit || (featureBuffer[i] != 0); 353 } 354 return anyBit; 355 } else { 356 assert((unsigned int)featureNum < bufLen, "feature index out of range"); 357 unsigned char* byteBuffer = (unsigned char*)featureBuffer; 358 int byteIndex = featureNum/(8*sizeof(char)); 359 int bitIndex = featureNum%(8*sizeof(char)); 360 // Indexed bit set? 361 return (byteBuffer[byteIndex] & (1U<<(7-bitIndex))) != 0; 362 } 363 } 364 365 void VM_Version::print_features_internal(const char* text, bool print_anyway) { 366 tty->print_cr("%s %s", text, features_string()); 367 tty->print("%s", text); 368 for (unsigned int i = 0; i < _nfeatures; i++) { 369 tty->print(" 0x%16.16lx", _features[i]); 370 } 371 tty->cr(); 372 373 if (Verbose || print_anyway) { 374 // z900 375 if (has_long_displacement() ) tty->print_cr("available: %s", "LongDispFacility"); 376 // z990 377 if (has_long_displacement_fast() ) tty->print_cr("available: %s", "LongDispFacilityHighPerf"); 378 if (has_ETF2() && has_ETF3() ) tty->print_cr("available: %s", "ETF2 and ETF3"); 379 if (has_Crypto() ) tty->print_cr("available: %s", "CryptoFacility"); 380 // z9 381 if (has_extended_immediate() ) tty->print_cr("available: %s", "ExtImmedFacility"); 382 if (has_StoreFacilityListExtended()) tty->print_cr("available: %s", "StoreFacilityListExtended"); 383 if (has_StoreClockFast() ) tty->print_cr("available: %s", "StoreClockFast"); 384 if (has_ETF2Enhancements() ) tty->print_cr("available: %s", "ETF2 Enhancements"); 385 if (has_ETF3Enhancements() ) tty->print_cr("available: %s", "ETF3 Enhancements"); 386 if (has_HFPUnnormalized() ) tty->print_cr("available: %s", "HFPUnnormalizedFacility"); 387 if (has_HFPMultiplyAndAdd() ) tty->print_cr("available: %s", "HFPMultiplyAndAddFacility"); 388 // z10 389 if (has_ParsingEnhancements() ) tty->print_cr("available: %s", "Parsing Enhancements"); 390 if (has_ExtractCPUtime() ) tty->print_cr("available: %s", "ExtractCPUTime"); 391 if (has_CompareSwapStore() ) tty->print_cr("available: %s", "CompareSwapStore"); 392 if (has_GnrlInstrExtensions() ) tty->print_cr("available: %s", "General Instruction Extensions"); 393 if (has_CompareBranch() ) tty->print_cr(" available: %s", "Compare and Branch"); 394 if (has_CompareTrap() ) tty->print_cr(" available: %s", "Compare and Trap"); 395 if (has_RelativeLoadStore() ) tty->print_cr(" available: %s", "Relative Load/Store"); 396 if (has_MultiplySingleImm32() ) tty->print_cr(" available: %s", "MultiplySingleImm32"); 397 if (has_Prefetch() ) tty->print_cr(" available: %s", "Prefetch"); 398 if (has_MoveImmToMem() ) tty->print_cr(" available: %s", "Direct Moves Immediate to Memory"); 399 if (has_MemWithImmALUOps() ) tty->print_cr(" available: %s", "Direct ALU Ops Memory .op. Immediate"); 400 if (has_ExtractCPUAttributes() ) tty->print_cr(" available: %s", "Extract CPU Atributes"); 401 if (has_ExecuteExtensions() ) tty->print_cr("available: %s", "ExecuteExtensions"); 402 if (has_FPSupportEnhancements() ) tty->print_cr("available: %s", "FPSupportEnhancements"); 403 if (has_DecimalFloatingPoint() ) tty->print_cr("available: %s", "DecimalFloatingPoint"); 404 // z196 405 if (has_DistinctOpnds() ) tty->print_cr("available: %s", "Distinct Operands"); 406 if (has_InterlockedAccessV1() ) tty->print_cr(" available: %s", "InterlockedAccess V1 (fast)"); 407 if (has_PopCount() ) tty->print_cr(" available: %s", "PopCount"); 408 if (has_LoadStoreConditional() ) tty->print_cr(" available: %s", "LoadStoreConditional"); 409 if (has_HighWordInstr() ) tty->print_cr(" available: %s", "HighWord Instructions"); 410 if (has_FastSync() ) tty->print_cr(" available: %s", "FastSync (bcr 14,0)"); 411 if (has_AtomicMemWithImmALUOps() ) tty->print_cr("available: %s", "Atomic Direct ALU Ops Memory .op. Immediate"); 412 if (has_FPExtensions() ) tty->print_cr("available: %s", "Floatingpoint Extensions"); 413 if (has_CryptoExt3() ) tty->print_cr("available: %s", "Crypto Extensions 3"); 414 if (has_CryptoExt4() ) tty->print_cr("available: %s", "Crypto Extensions 4"); 415 // EC12 416 if (has_MiscInstrExt() ) tty->print_cr("available: %s", "Miscelaneous Instruction Extensions"); 417 if (has_ExecutionHint() ) tty->print_cr(" available: %s", "Execution Hints (branch prediction)"); 418 if (has_ProcessorAssist() ) tty->print_cr(" available: %s", "Processor Assists"); 419 if (has_LoadAndTrap() ) tty->print_cr(" available: %s", "Load and Trap"); 420 if (has_TxMem() ) tty->print_cr("available: %s", "Transactional Memory"); 421 if (has_InterlockedAccessV2() ) tty->print_cr(" available: %s", "InterlockedAccess V2 (fast)"); 422 if (has_DFPZonedConversion() ) tty->print_cr(" available: %s", "DFP Zoned Conversions"); 423 // z13 424 if (has_LoadStoreConditional2() ) tty->print_cr("available: %s", "Load/Store Conditional 2"); 425 if (has_CryptoExt5() ) tty->print_cr("available: %s", "Crypto Extensions 5"); 426 if (has_DFPPackedConversion() ) tty->print_cr("available: %s", "DFP Packed Conversions"); 427 if (has_VectorFacility() ) tty->print_cr("available: %s", "Vector Facility"); 428 // test switches 429 if (has_TestFeature1Impl() ) tty->print_cr("available: %s", "TestFeature1Impl"); 430 if (has_TestFeature2Impl() ) tty->print_cr("available: %s", "TestFeature2Impl"); 431 if (has_TestFeature4Impl() ) tty->print_cr("available: %s", "TestFeature4Impl"); 432 if (has_TestFeature8Impl() ) tty->print_cr("available: %s", "TestFeature8Impl"); 433 434 if (has_Crypto()) { 435 tty->cr(); 436 tty->print_cr("detailed availability of %s capabilities:", "CryptoFacility"); 437 if (test_feature_bit(&_cipher_features[0], -1, 2*Cipher::_featureBits)) { 438 tty->cr(); 439 tty->print_cr(" available: %s", "Message Cipher Functions"); 440 } 441 if (test_feature_bit(&_cipher_features[0], -1, (int)Cipher::_featureBits)) { 442 tty->print_cr(" available Crypto Features of KM (Cipher Message):"); 443 for (unsigned int i = 0; i < Cipher::_featureBits; i++) { 444 if (test_feature_bit(&_cipher_features[0], i, (int)Cipher::_featureBits)) { 445 switch (i) { 446 case Cipher::_Query: tty->print_cr(" available: KM Query"); break; 447 case Cipher::_DEA: tty->print_cr(" available: KM DEA"); break; 448 case Cipher::_TDEA128: tty->print_cr(" available: KM TDEA-128"); break; 449 case Cipher::_TDEA192: tty->print_cr(" available: KM TDEA-192"); break; 450 case Cipher::_EncryptedDEA: tty->print_cr(" available: KM Encrypted DEA"); break; 451 case Cipher::_EncryptedDEA128: tty->print_cr(" available: KM Encrypted DEA-128"); break; 452 case Cipher::_EncryptedDEA192: tty->print_cr(" available: KM Encrypted DEA-192"); break; 453 case Cipher::_AES128: tty->print_cr(" available: KM AES-128"); break; 454 case Cipher::_AES192: tty->print_cr(" available: KM AES-192"); break; 455 case Cipher::_AES256: tty->print_cr(" available: KM AES-256"); break; 456 case Cipher::_EnccryptedAES128: tty->print_cr(" available: KM Encrypted-AES-128"); break; 457 case Cipher::_EnccryptedAES192: tty->print_cr(" available: KM Encrypted-AES-192"); break; 458 case Cipher::_EnccryptedAES256: tty->print_cr(" available: KM Encrypted-AES-256"); break; 459 case Cipher::_XTSAES128: tty->print_cr(" available: KM XTS-AES-128"); break; 460 case Cipher::_XTSAES256: tty->print_cr(" available: KM XTS-AES-256"); break; 461 case Cipher::_EncryptedXTSAES128: tty->print_cr(" available: KM XTS-Encrypted-AES-128"); break; 462 case Cipher::_EncryptedXTSAES256: tty->print_cr(" available: KM XTS-Encrypted-AES-256"); break; 463 default: tty->print_cr(" available: unknown KM code %d", i); break; 464 } 465 } 466 } 467 } 468 if (test_feature_bit(&_cipher_features[2], -1, (int)Cipher::_featureBits)) { 469 tty->print_cr(" available Crypto Features of KMC (Cipher Message with Chaining):"); 470 for (unsigned int i = 0; i < Cipher::_featureBits; i++) { 471 if (test_feature_bit(&_cipher_features[2], i, (int)Cipher::_featureBits)) { 472 switch (i) { 473 case Cipher::_Query: tty->print_cr(" available: KMC Query"); break; 474 case Cipher::_DEA: tty->print_cr(" available: KMC DEA"); break; 475 case Cipher::_TDEA128: tty->print_cr(" available: KMC TDEA-128"); break; 476 case Cipher::_TDEA192: tty->print_cr(" available: KMC TDEA-192"); break; 477 case Cipher::_EncryptedDEA: tty->print_cr(" available: KMC Encrypted DEA"); break; 478 case Cipher::_EncryptedDEA128: tty->print_cr(" available: KMC Encrypted DEA-128"); break; 479 case Cipher::_EncryptedDEA192: tty->print_cr(" available: KMC Encrypted DEA-192"); break; 480 case Cipher::_AES128: tty->print_cr(" available: KMC AES-128"); break; 481 case Cipher::_AES192: tty->print_cr(" available: KMC AES-192"); break; 482 case Cipher::_AES256: tty->print_cr(" available: KMC AES-256"); break; 483 case Cipher::_EnccryptedAES128: tty->print_cr(" available: KMC Encrypted-AES-128"); break; 484 case Cipher::_EnccryptedAES192: tty->print_cr(" available: KMC Encrypted-AES-192"); break; 485 case Cipher::_EnccryptedAES256: tty->print_cr(" available: KMC Encrypted-AES-256"); break; 486 case Cipher::_PRNG: tty->print_cr(" available: KMC PRNG"); break; 487 default: tty->print_cr(" available: unknown KMC code %d", i); break; 488 } 489 } 490 } 491 } 492 493 if (test_feature_bit(&_msgdigest_features[0], -1, 2*MsgDigest::_featureBits)) { 494 tty->cr(); 495 tty->print_cr(" available: %s", "Message Digest Functions for SHA"); 496 } 497 if (test_feature_bit(&_msgdigest_features[0], -1, (int)MsgDigest::_featureBits)) { 498 tty->print_cr(" available Features of KIMD (Msg Digest):"); 499 for (unsigned int i = 0; i < MsgDigest::_featureBits; i++) { 500 if (test_feature_bit(&_msgdigest_features[0], i, (int)MsgDigest::_featureBits)) { 501 switch (i) { 502 case MsgDigest::_Query: tty->print_cr(" available: KIMD Query"); break; 503 case MsgDigest::_SHA1: tty->print_cr(" available: KIMD SHA-1"); break; 504 case MsgDigest::_SHA256: tty->print_cr(" available: KIMD SHA-256"); break; 505 case MsgDigest::_SHA512: tty->print_cr(" available: KIMD SHA-512"); break; 506 case MsgDigest::_GHASH: tty->print_cr(" available: KIMD GHASH"); break; 507 default: tty->print_cr(" available: unknown code %d", i); break; 508 } 509 } 510 } 511 } 512 if (test_feature_bit(&_msgdigest_features[2], -1, (int)MsgDigest::_featureBits)) { 513 tty->print_cr(" available Features of KLMD (Msg Digest):"); 514 for (unsigned int i = 0; i < MsgDigest::_featureBits; i++) { 515 if (test_feature_bit(&_msgdigest_features[2], i, (int)MsgDigest::_featureBits)) { 516 switch (i) { 517 case MsgDigest::_Query: tty->print_cr(" available: KLMD Query"); break; 518 case MsgDigest::_SHA1: tty->print_cr(" available: KLMD SHA-1"); break; 519 case MsgDigest::_SHA256: tty->print_cr(" available: KLMD SHA-256"); break; 520 case MsgDigest::_SHA512: tty->print_cr(" available: KLMD SHA-512"); break; 521 default: tty->print_cr(" available: unknown code %d", i); break; 522 } 523 } 524 } 525 } 526 } 527 if (ContendedPaddingWidth > 0) { 528 tty->cr(); 529 tty->print_cr("ContendedPaddingWidth " INTX_FORMAT, ContendedPaddingWidth); 530 } 531 } 532 } 533 534 void VM_Version::print_platform_virtualization_info(outputStream* st) { 535 // /proc/sysinfo contains interesting information about 536 // - LPAR 537 // - whole "Box" (CPUs ) 538 // - z/VM / KVM (VM<nn>); this is not available in an LPAR-only setup 539 const char* kw[] = { "LPAR", "CPUs", "VM", NULL }; 540 const char* info_file = "/proc/sysinfo"; 541 542 if (!print_matching_lines_from_file(info_file, st, kw)) { 543 st->print_cr(" <%s Not Available>", info_file); 544 } 545 } 546 547 void VM_Version::print_features() { 548 print_features_internal("Version:"); 549 } 550 551 void VM_Version::reset_features(bool reset) { 552 if (reset) { 553 for (unsigned int i = 0; i < _features_buffer_len; i++) { 554 VM_Version::_features[i] = 0; 555 } 556 } 557 } 558 559 void VM_Version::set_features_z900(bool reset) { 560 reset_features(reset); 561 562 set_has_long_displacement(); 563 set_has_ETF2(); 564 } 565 566 void VM_Version::set_features_z990(bool reset) { 567 reset_features(reset); 568 569 set_features_z900(false); 570 set_has_ETF3(); 571 set_has_long_displacement_fast(); 572 set_has_HFPMultiplyAndAdd(); 573 } 574 575 void VM_Version::set_features_z9(bool reset) { 576 reset_features(reset); 577 578 set_features_z990(false); 579 set_has_StoreFacilityListExtended(); 580 // set_has_Crypto(); // Do not set, crypto features must be retrieved separately. 581 set_has_ETF2Enhancements(); 582 set_has_ETF3Enhancements(); 583 set_has_extended_immediate(); 584 set_has_StoreClockFast(); 585 set_has_HFPUnnormalized(); 586 } 587 588 void VM_Version::set_features_z10(bool reset) { 589 reset_features(reset); 590 591 set_features_z9(false); 592 set_has_CompareSwapStore(); 593 set_has_RelativeLoadStore(); 594 set_has_CompareBranch(); 595 set_has_CompareTrap(); 596 set_has_MultiplySingleImm32(); 597 set_has_Prefetch(); 598 set_has_MoveImmToMem(); 599 set_has_MemWithImmALUOps(); 600 set_has_ExecuteExtensions(); 601 set_has_FPSupportEnhancements(); 602 set_has_DecimalFloatingPoint(); 603 set_has_ExtractCPUtime(); 604 set_has_CryptoExt3(); 605 } 606 607 void VM_Version::set_features_z196(bool reset) { 608 reset_features(reset); 609 610 set_features_z10(false); 611 set_has_InterlockedAccessV1(); 612 set_has_PopCount(); 613 set_has_LoadStoreConditional(); 614 set_has_HighWordInstr(); 615 set_has_FastSync(); 616 set_has_FPExtensions(); 617 set_has_DistinctOpnds(); 618 set_has_CryptoExt4(); 619 } 620 621 void VM_Version::set_features_ec12(bool reset) { 622 reset_features(reset); 623 624 set_features_z196(false); 625 set_has_MiscInstrExt(); 626 set_has_InterlockedAccessV2(); 627 set_has_LoadAndALUAtomicV2(); 628 set_has_TxMem(); 629 } 630 631 void VM_Version::set_features_z13(bool reset) { 632 reset_features(reset); 633 634 set_features_ec12(false); 635 set_has_LoadStoreConditional2(); 636 set_has_CryptoExt5(); 637 set_has_VectorFacility(); 638 } 639 640 void VM_Version::set_features_from(const char* march) { 641 bool err = false; 642 bool prt = false; 643 644 if ((march != NULL) && (march[0] != '\0')) { 645 const int buf_len = 16; 646 const int hdr_len = 5; 647 char buf[buf_len]; 648 if (strlen(march) >= hdr_len) { 649 memcpy(buf, march, hdr_len); 650 buf[hdr_len] = '\00'; 651 } else { 652 buf[0] = '\00'; 653 } 654 655 if (!strcmp(march, "z900")) { 656 set_features_z900(); 657 } else if (!strcmp(march, "z990")) { 658 set_features_z990(); 659 } else if (!strcmp(march, "z9")) { 660 set_features_z9(); 661 } else if (!strcmp(march, "z10")) { 662 set_features_z10(); 663 } else if (!strcmp(march, "z196")) { 664 set_features_z196(); 665 } else if (!strcmp(march, "ec12")) { 666 set_features_ec12(); 667 } else if (!strcmp(march, "z13")) { 668 set_features_z13(); 669 } else if (!strcmp(buf, "ztest")) { 670 assert(!has_TestFeaturesImpl(), "possible facility list flag conflict"); 671 if (strlen(march) > hdr_len) { 672 int itest = 0; 673 if ((strlen(march)-hdr_len) >= buf_len) err = true; 674 if (!err) { 675 memcpy(buf, &march[hdr_len], strlen(march)-hdr_len); 676 buf[strlen(march)-hdr_len] = '\00'; 677 for (size_t i = 0; !err && (i < strlen(buf)); i++) { 678 itest = itest*10 + buf[i]-'0'; 679 err = err || ((buf[i]-'0') < 0) || ((buf[i]-'0') > 9) || (itest > 15); 680 } 681 } 682 if (!err) { 683 prt = true; 684 if (itest & 0x01) { set_has_TestFeature1Impl(); } 685 if (itest & 0x02) { set_has_TestFeature2Impl(); } 686 if (itest & 0x04) { set_has_TestFeature4Impl(); } 687 if (itest & 0x08) { set_has_TestFeature8Impl(); } 688 } 689 } else { 690 prt = true; 691 set_has_TestFeature1Impl(); 692 set_has_TestFeature2Impl(); 693 set_has_TestFeature4Impl(); 694 set_has_TestFeature8Impl(); 695 } 696 } else { 697 err = true; 698 } 699 if (!err) { 700 set_features_string(); 701 if (prt || PrintAssembly) { 702 print_features_internal("CPU Version as set by cmdline option:", prt); 703 } 704 } else { 705 tty->print_cr("***Warning: Unsupported ProcessorArchitecture: %s, internal settings left undisturbed.", march); 706 } 707 } 708 709 } 710 711 static long (*getFeatures)(unsigned long*, int, int) = NULL; 712 713 void VM_Version::set_getFeatures(address entryPoint) { 714 if (getFeatures == NULL) { 715 getFeatures = (long(*)(unsigned long*, int, int))entryPoint; 716 } 717 } 718 719 long VM_Version::call_getFeatures(unsigned long* buffer, int buflen, int functionCode) { 720 VM_Version::_is_determine_features_test_running = true; 721 long functionResult = (*getFeatures)(buffer, buflen, functionCode); 722 VM_Version::_is_determine_features_test_running = false; 723 return functionResult; 724 } 725 726 // Helper function for "extract cache attribute" instruction. 727 int VM_Version::calculate_ECAG_functionCode(unsigned int attributeIndication, 728 unsigned int levelIndication, 729 unsigned int typeIndication) { 730 return (attributeIndication<<4) | (levelIndication<<1) | typeIndication; 731 } 732 733 void VM_Version::determine_features() { 734 735 const int cbuf_size = _code_buffer_len; 736 const int buf_len = _features_buffer_len; 737 738 // Allocate code buffer space for the detection code. 739 ResourceMark rm; 740 CodeBuffer cbuf("determine CPU features", cbuf_size, 0); 741 MacroAssembler* a = new MacroAssembler(&cbuf); 742 743 // Emit code. 744 set_getFeatures(a->pc()); 745 address code = a->pc(); 746 747 // Try STFLE. Possible INVOP will cause defaults to be used. 748 Label getFEATURES; 749 Label getCPUFEATURES; // fcode = -1 (cache) 750 Label getCIPHERFEATURES; // fcode = -2 (cipher) 751 Label getMSGDIGESTFEATURES; // fcode = -3 (SHA) 752 Label getVECTORFEATURES; // fcode = -4 (OS support for vector instructions) 753 Label errRTN; 754 a->z_ltgfr(Z_R0, Z_ARG2); // Buf len to r0 and test. 755 a->z_brl(getFEATURES); // negative -> Get machine features not covered by facility list. 756 a->z_lghi(Z_R1,0); 757 a->z_brz(errRTN); // zero -> Function code currently not used, indicate "aborted". 758 759 a->z_aghi(Z_R0, -1); 760 a->z_stfle(0, Z_ARG1); 761 a->z_lg(Z_R1, 0, Z_ARG1); // Get first DW of facility list. 762 a->z_lgr(Z_RET, Z_R0); // Calculate rtn value for success. 763 a->z_la(Z_RET, 1, Z_RET); 764 a->z_brnz(errRTN); // Instr failed if non-zero CC. 765 a->z_ltgr(Z_R1, Z_R1); // Instr failed if first DW == 0. 766 a->z_bcr(Assembler::bcondNotZero, Z_R14); // Successful return. 767 768 a->bind(errRTN); 769 a->z_lngr(Z_RET, Z_RET); 770 a->z_ltgr(Z_R1, Z_R1); 771 a->z_bcr(Assembler::bcondNotZero, Z_R14); // Return "buffer too small". 772 a->z_xgr(Z_RET, Z_RET); 773 a->z_br(Z_R14); // Return "operation aborted". 774 775 a->bind(getFEATURES); 776 a->z_cghi(Z_R0, -1); // -1: Extract CPU attributes, currently: cache layout only. 777 a->z_bre(getCPUFEATURES); 778 a->z_cghi(Z_R0, -2); // -2: Extract detailed crypto capabilities (cipher instructions). 779 a->z_bre(getCIPHERFEATURES); 780 a->z_cghi(Z_R0, -3); // -3: Extract detailed crypto capabilities (msg digest instructions). 781 a->z_bre(getMSGDIGESTFEATURES); 782 a->z_cghi(Z_R0, -4); // -4: Verify vector instruction availability (OS support). 783 a->z_bre(getVECTORFEATURES); 784 785 a->z_xgr(Z_RET, Z_RET); // Not a valid function code. 786 a->z_br(Z_R14); // Return "operation aborted". 787 788 // Try KIMD/KLMD query function to get details about msg digest (secure hash, SHA) instructions. 789 a->bind(getMSGDIGESTFEATURES); 790 a->z_lghi(Z_R0,(int)MsgDigest::_Query); // query function code 791 a->z_lgr(Z_R1,Z_R2); // param block addr, 2*16 bytes min size 792 a->z_kimd(Z_R2,Z_R2); // Get available KIMD functions (bit pattern in param blk). 793 a->z_la(Z_R1,16,Z_R1); // next param block addr 794 a->z_klmd(Z_R2,Z_R2); // Get available KLMD functions (bit pattern in param blk). 795 a->z_lghi(Z_RET,4); 796 a->z_br(Z_R14); 797 798 // Try KM/KMC query function to get details about crypto instructions. 799 a->bind(getCIPHERFEATURES); 800 a->z_lghi(Z_R0,(int)Cipher::_Query); // query function code 801 a->z_lgr(Z_R1,Z_R2); // param block addr, 2*16 bytes min size (KIMD/KLMD output) 802 a->z_km(Z_R2,Z_R2); // get available KM functions 803 a->z_la(Z_R1,16,Z_R1); // next param block addr 804 a->z_kmc(Z_R2,Z_R2); // get available KMC functions 805 a->z_lghi(Z_RET,4); 806 a->z_br(Z_R14); 807 808 // Use EXTRACT CPU ATTRIBUTE instruction to get information about cache layout. 809 a->bind(getCPUFEATURES); 810 a->z_xgr(Z_R0,Z_R0); // as recommended in instruction documentation 811 a->z_ecag(Z_RET,Z_R0,0,Z_ARG3); // Extract information as requested by Z_ARG1 contents. 812 a->z_br(Z_R14); 813 814 // Use a vector instruction to verify OS support. Will fail with SIGFPE if OS support is missing. 815 a->bind(getVECTORFEATURES); 816 a->z_vtm(Z_V0,Z_V0); // non-destructive vector instruction. Will cause SIGFPE if not supported. 817 a->z_br(Z_R14); 818 819 address code_end = a->pc(); 820 a->flush(); 821 822 cbuf.insts()->set_end(code_end); 823 824 // Print the detection code. 825 bool printVerbose = Verbose || PrintAssembly || PrintStubCode; 826 if (printVerbose) { 827 ttyLocker ttyl; 828 tty->print_cr("Decoding CPU feature detection stub at " INTPTR_FORMAT " before execution:", p2i(code)); 829 tty->print_cr("Stub length is %ld bytes, codebuffer reserves %d bytes, %ld bytes spare.", 830 code_end-code, cbuf_size, cbuf_size-(code_end-code)); 831 832 // Use existing decode function. This enables the [MachCode] format which is needed to DecodeErrorFile. 833 Disassembler::decode(&cbuf, code, code_end, tty); 834 } 835 836 // Prepare for detection code execution and clear work buffer. 837 _nfeatures = 0; 838 _ncipher_features = 0; 839 unsigned long buffer[buf_len]; 840 841 for (int i = 0; i < buf_len; i++) { 842 buffer[i] = 0L; 843 } 844 845 // execute code 846 // Illegal instructions will be replaced by 0 in signal handler. 847 // In case of problems, call_getFeatures will return a not-positive result. 848 long used_len = call_getFeatures(buffer, buf_len, 0); 849 850 bool ok; 851 if (used_len == 1) { 852 ok = true; 853 } else if (used_len > 1) { 854 unsigned int used_lenU = (unsigned int)used_len; 855 ok = true; 856 for (unsigned int i = 1; i < used_lenU; i++) { 857 ok = ok && (buffer[i] == 0L); 858 } 859 if (printVerbose && !ok) { 860 bool compact = false; 861 tty->print_cr("Note: feature list has %d (i.e. more than one) array elements.", used_lenU); 862 if (compact) { 863 tty->print("non-zero feature list elements:"); 864 for (unsigned int i = 0; i < used_lenU; i++) { 865 tty->print(" [%d]: 0x%16.16lx", i, buffer[i]); 866 } 867 tty->cr(); 868 } else { 869 for (unsigned int i = 0; i < used_lenU; i++) { 870 tty->print_cr("non-zero feature list[%d]: 0x%16.16lx", i, buffer[i]); 871 } 872 } 873 874 if (compact) { 875 tty->print_cr("Active features (compact view):"); 876 for (unsigned int k = 0; k < used_lenU; k++) { 877 tty->print_cr(" buffer[%d]:", k); 878 for (unsigned int j = k*sizeof(long); j < (k+1)*sizeof(long); j++) { 879 bool line = false; 880 for (unsigned int i = j*8; i < (j+1)*8; i++) { 881 bool bit = test_feature_bit(buffer, i, used_lenU*sizeof(long)*8); 882 if (bit) { 883 if (!line) { 884 tty->print(" byte[%d]:", j); 885 line = true; 886 } 887 tty->print(" [%3.3d]", i); 888 } 889 } 890 if (line) { 891 tty->cr(); 892 } 893 } 894 } 895 } else { 896 tty->print_cr("Active features (full view):"); 897 for (unsigned int k = 0; k < used_lenU; k++) { 898 tty->print_cr(" buffer[%d]:", k); 899 for (unsigned int j = k*sizeof(long); j < (k+1)*sizeof(long); j++) { 900 tty->print(" byte[%d]:", j); 901 for (unsigned int i = j*8; i < (j+1)*8; i++) { 902 bool bit = test_feature_bit(buffer, i, used_lenU*sizeof(long)*8); 903 if (bit) { 904 tty->print(" [%3.3d]", i); 905 } else { 906 tty->print(" "); 907 } 908 } 909 tty->cr(); 910 } 911 } 912 } 913 } 914 ok = true; 915 } else { // No features retrieved if we reach here. Buffer too short or instr not available. 916 if (used_len < 0) { 917 ok = false; 918 if (printVerbose) { 919 tty->print_cr("feature list buffer[%d] too short, required: buffer[%ld]", buf_len, -used_len); 920 } 921 } else { 922 if (printVerbose) { 923 tty->print_cr("feature list could not be retrieved. Running on z900 or z990? Trying to find out..."); 924 } 925 used_len = call_getFeatures(buffer, 0, 0); // Must provide at least two DW buffer elements!!!! 926 927 ok = used_len > 0; 928 if (ok) { 929 if (buffer[1]*10 < buffer[0]) { 930 set_features_z900(); 931 } else { 932 set_features_z990(); 933 } 934 935 if (printVerbose) { 936 tty->print_cr("Note: high-speed long displacement test used %ld iterations.", used_len); 937 tty->print_cr(" Positive displacement loads took %8.8lu microseconds.", buffer[1]); 938 tty->print_cr(" Negative displacement loads took %8.8lu microseconds.", buffer[0]); 939 if (has_long_displacement_fast()) { 940 tty->print_cr(" assuming high-speed long displacement IS available."); 941 } else { 942 tty->print_cr(" assuming high-speed long displacement is NOT available."); 943 } 944 } 945 } else { 946 if (printVerbose) { 947 tty->print_cr("Note: high-speed long displacement test was not successful."); 948 tty->print_cr(" assuming long displacement is NOT available."); 949 } 950 } 951 return; // Do not copy buffer to _features, no test for cipher features. 952 } 953 } 954 955 if (ok) { 956 // Fill features buffer. 957 // Clear work buffer. 958 for (int i = 0; i < buf_len; i++) { 959 _features[i] = buffer[i]; 960 _cipher_features[i] = 0; 961 _msgdigest_features[i] = 0; 962 buffer[i] = 0L; 963 } 964 _nfeatures = used_len; 965 } else { 966 for (int i = 0; i < buf_len; i++) { 967 _features[i] = 0; 968 _cipher_features[i] = 0; 969 _msgdigest_features[i] = 0; 970 buffer[i] = 0L; 971 } 972 _nfeatures = 0; 973 } 974 975 if (has_VectorFacility()) { 976 // Verify that feature can actually be used. OS support required. 977 call_getFeatures(buffer, -4, 0); 978 if (printVerbose) { 979 ttyLocker ttyl; 980 if (has_VectorFacility()) { 981 tty->print_cr(" Vector Facility has been verified to be supported by OS"); 982 } else { 983 tty->print_cr(" Vector Facility has been disabled - not supported by OS"); 984 } 985 } 986 } 987 988 // Extract Crypto Facility details. 989 if (has_Crypto()) { 990 // Get cipher features. 991 used_len = call_getFeatures(buffer, -2, 0); 992 for (int i = 0; i < buf_len; i++) { 993 _cipher_features[i] = buffer[i]; 994 } 995 _ncipher_features = used_len; 996 997 // Get msg digest features. 998 used_len = call_getFeatures(buffer, -3, 0); 999 for (int i = 0; i < buf_len; i++) { 1000 _msgdigest_features[i] = buffer[i]; 1001 } 1002 _nmsgdigest_features = used_len; 1003 } 1004 1005 static int levelProperties[_max_cache_levels]; // All property indications per level. 1006 static int levelScope[_max_cache_levels]; // private/shared 1007 static const char* levelScopeText[4] = {"No cache ", 1008 "CPU private", 1009 "shared ", 1010 "reserved "}; 1011 1012 static int levelType[_max_cache_levels]; // D/I/mixed 1013 static const char* levelTypeText[4] = {"separate D and I caches", 1014 "I cache only ", 1015 "D-cache only ", 1016 "combined D/I cache "}; 1017 1018 static unsigned int levelReserved[_max_cache_levels]; // reserved property bits 1019 static unsigned int levelLineSize[_max_cache_levels]; 1020 static unsigned int levelTotalSize[_max_cache_levels]; 1021 static unsigned int levelAssociativity[_max_cache_levels]; 1022 1023 1024 // Extract Cache Layout details. 1025 if (has_ExtractCPUAttributes() && printVerbose) { // For information only, as of now. 1026 bool lineSize_mismatch; 1027 bool print_something; 1028 long functionResult; 1029 unsigned int attributeIndication = 0; // 0..15 1030 unsigned int levelIndication = 0; // 0..8 1031 unsigned int typeIndication = 0; // 0..1 (D-Cache, I-Cache) 1032 int functionCode = calculate_ECAG_functionCode(attributeIndication, levelIndication, typeIndication); 1033 1034 // Get cache topology. 1035 functionResult = call_getFeatures(buffer, -1, functionCode); 1036 1037 for (unsigned int i = 0; i < _max_cache_levels; i++) { 1038 if (functionResult > 0) { 1039 int shiftVal = 8*(_max_cache_levels-(i+1)); 1040 levelProperties[i] = (functionResult & (0xffUL<<shiftVal)) >> shiftVal; 1041 levelReserved[i] = (levelProperties[i] & 0xf0) >> 4; 1042 levelScope[i] = (levelProperties[i] & 0x0c) >> 2; 1043 levelType[i] = (levelProperties[i] & 0x03); 1044 } else { 1045 levelProperties[i] = 0; 1046 levelReserved[i] = 0; 1047 levelScope[i] = 0; 1048 levelType[i] = 0; 1049 } 1050 levelLineSize[i] = 0; 1051 levelTotalSize[i] = 0; 1052 levelAssociativity[i] = 0; 1053 } 1054 1055 tty->cr(); 1056 tty->print_cr("------------------------------------"); 1057 tty->print_cr("--- Cache Topology Information ---"); 1058 tty->print_cr("------------------------------------"); 1059 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1060 tty->print_cr(" Cache Level %d: <scope> %s | <type> %s", 1061 i+1, levelScopeText[levelScope[i]], levelTypeText[levelType[i]]); 1062 } 1063 1064 // Get D-cache details per level. 1065 _Dcache_lineSize = 0; 1066 lineSize_mismatch = false; 1067 print_something = false; 1068 typeIndication = 0; // 0..1 (D-Cache, I-Cache) 1069 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1070 if ((levelType[i] == 0) || (levelType[i] == 2)) { 1071 print_something = true; 1072 1073 // Get cache line size of level i. 1074 attributeIndication = 1; 1075 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1076 levelLineSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1077 1078 // Get cache total size of level i. 1079 attributeIndication = 2; 1080 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1081 levelTotalSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1082 1083 // Get cache associativity of level i. 1084 attributeIndication = 3; 1085 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1086 levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1087 1088 _Dcache_lineSize = _Dcache_lineSize == 0 ? levelLineSize[i] : _Dcache_lineSize; 1089 lineSize_mismatch = lineSize_mismatch || (_Dcache_lineSize != levelLineSize[i]); 1090 } else { 1091 levelLineSize[i] = 0; 1092 } 1093 } 1094 1095 if (print_something) { 1096 tty->cr(); 1097 tty->print_cr("------------------------------------"); 1098 tty->print_cr("--- D-Cache Detail Information ---"); 1099 tty->print_cr("------------------------------------"); 1100 if (lineSize_mismatch) { 1101 tty->print_cr("WARNING: D-Cache line size mismatch!"); 1102 } 1103 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1104 if (levelLineSize[i] > 0) { 1105 tty->print_cr(" D-Cache Level %d: line size = %4d, total size = %6dKB, associativity = %2d", 1106 i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]); 1107 } 1108 } 1109 } 1110 1111 // Get I-cache details per level. 1112 _Icache_lineSize = 0; 1113 lineSize_mismatch = false; 1114 print_something = false; 1115 typeIndication = 1; // 0..1 (D-Cache, I-Cache) 1116 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1117 if ((levelType[i] == 0) || (levelType[i] == 1)) { 1118 print_something = true; 1119 1120 // Get cache line size of level i. 1121 attributeIndication = 1; 1122 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1123 levelLineSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1124 1125 // Get cache total size of level i. 1126 attributeIndication = 2; 1127 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1128 levelTotalSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1129 1130 // Get cache associativity of level i. 1131 attributeIndication = 3; 1132 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1133 levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1134 1135 _Icache_lineSize = _Icache_lineSize == 0 ? levelLineSize[i] : _Icache_lineSize; 1136 lineSize_mismatch = lineSize_mismatch || (_Icache_lineSize != levelLineSize[i]); 1137 } else { 1138 levelLineSize[i] = 0; 1139 } 1140 } 1141 1142 if (print_something) { 1143 tty->cr(); 1144 tty->print_cr("------------------------------------"); 1145 tty->print_cr("--- I-Cache Detail Information ---"); 1146 tty->print_cr("------------------------------------"); 1147 if (lineSize_mismatch) { 1148 tty->print_cr("WARNING: I-Cache line size mismatch!"); 1149 } 1150 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1151 if (levelLineSize[i] > 0) { 1152 tty->print_cr(" I-Cache Level %d: line size = %4d, total size = %6dKB, associativity = %2d", 1153 i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]); 1154 } 1155 } 1156 } 1157 1158 // Get D/I-cache details per level. 1159 lineSize_mismatch = false; 1160 print_something = false; 1161 typeIndication = 0; // 0..1 (D-Cache, I-Cache) 1162 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1163 if (levelType[i] == 3) { 1164 print_something = true; 1165 1166 // Get cache line size of level i. 1167 attributeIndication = 1; 1168 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1169 levelLineSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1170 1171 // Get cache total size of level i. 1172 attributeIndication = 2; 1173 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1174 levelTotalSize[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1175 1176 // Get cache associativity of level i. 1177 attributeIndication = 3; 1178 functionCode = calculate_ECAG_functionCode(attributeIndication, i, typeIndication); 1179 levelAssociativity[i] = (unsigned int)call_getFeatures(buffer, -1, functionCode); 1180 1181 _Dcache_lineSize = _Dcache_lineSize == 0 ? levelLineSize[i] : _Dcache_lineSize; 1182 _Icache_lineSize = _Icache_lineSize == 0 ? levelLineSize[i] : _Icache_lineSize; 1183 lineSize_mismatch = lineSize_mismatch || (_Dcache_lineSize != levelLineSize[i]) 1184 || (_Icache_lineSize != levelLineSize[i]); 1185 } else { 1186 levelLineSize[i] = 0; 1187 } 1188 } 1189 1190 if (print_something) { 1191 tty->cr(); 1192 tty->print_cr("--------------------------------------"); 1193 tty->print_cr("--- D/I-Cache Detail Information ---"); 1194 tty->print_cr("--------------------------------------"); 1195 if (lineSize_mismatch) { 1196 tty->print_cr("WARNING: D/I-Cache line size mismatch!"); 1197 } 1198 for (unsigned int i = 0; (i < _max_cache_levels) && (levelProperties[i] != 0); i++) { 1199 if (levelLineSize[i] > 0) { 1200 tty->print_cr(" D/I-Cache Level %d: line size = %4d, total size = %6dKB, associativity = %2d", 1201 i+1, levelLineSize[i], levelTotalSize[i]/(int)K, levelAssociativity[i]); 1202 } 1203 } 1204 } 1205 tty->cr(); 1206 } 1207 return; 1208 } 1209 1210 unsigned long VM_Version::z_SIGILL() { 1211 unsigned long ZeroBuffer = 0; 1212 unsigned long work; 1213 asm( 1214 " LA %[work],%[buffer] \n\t" // Load address of buffer. 1215 " LARL 14,+6 \n\t" // Load address of faulting instruction. 1216 " BCR 15,%[work] \n\t" // Branch into buffer, execute whatever is in there. 1217 : [buffer] "+Q" (ZeroBuffer) /* outputs */ 1218 , [work] "=&a" (work) /* outputs */ 1219 : /* inputs */ 1220 : "cc" /* clobbered */ 1221 ); 1222 return ZeroBuffer; 1223 } 1224 1225 unsigned long VM_Version::z_SIGSEGV() { 1226 unsigned long ZeroBuffer = 0; 1227 unsigned long work; 1228 asm( 1229 " LG %[work],%[buffer] \n\t" // Load zero address. 1230 " STG %[work],0(,%[work])\n\t" // Store to address zero. 1231 : [buffer] "+Q" (ZeroBuffer) /* outputs */ 1232 , [work] "=&a" (work) /* outputs */ 1233 : /* inputs */ 1234 : "cc" /* clobbered */ 1235 ); 1236 return ZeroBuffer; 1237 } 1238