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