Simulator-Constants-vixl.h (5742B)
1 // Copyright 2015, ARM Limited 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // 7 // * Redistributions of source code must retain the above copyright notice, 8 // this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above copyright notice 10 // this list of conditions and the following disclaimer in the documentation 11 // and/or other materials provided with the distribution. 12 // * Neither the name of ARM Limited nor the names of its contributors may be 13 // used to endorse or promote products derived from this software without 14 // specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 #ifndef VIXL_A64_SIMULATOR_CONSTANTS_A64_H_ 28 #define VIXL_A64_SIMULATOR_CONSTANTS_A64_H_ 29 30 namespace vixl { 31 32 // Debug instructions. 33 // 34 // VIXL's macro-assembler and simulator support a few pseudo instructions to 35 // make debugging easier. These pseudo instructions do not exist on real 36 // hardware. 37 // 38 // TODO: Also consider allowing these pseudo-instructions to be disabled in the 39 // simulator, so that users can check that the input is a valid native code. 40 // (This isn't possible in all cases. Printf won't work, for example.) 41 // 42 // Each debug pseudo instruction is represented by a HLT instruction. The HLT 43 // immediate field is used to identify the type of debug pseudo instruction. 44 45 enum DebugHltOpcodes { 46 kPrintfOpcode, 47 kTraceOpcode, 48 kLogOpcode, 49 // Aliases. 50 kDebugHltFirstOpcode = kPrintfOpcode, 51 kDebugHltLastOpcode = kLogOpcode 52 }; 53 54 // Each pseudo instruction uses a custom encoding for additional arguments, as 55 // described below. 56 57 // Unreachable - kUnreachableOpcode 58 // 59 // Instruction which should never be executed. This is used as a guard in parts 60 // of the code that should not be reachable, such as in data encoded inline in 61 // the instructions. 62 63 // Printf - kPrintfOpcode 64 // - arg_count: The number of arguments. 65 // - arg_pattern: A set of PrintfArgPattern values, packed into two-bit fields. 66 // 67 // Simulate a call to printf. 68 // 69 // Floating-point and integer arguments are passed in separate sets of registers 70 // in AAPCS64 (even for varargs functions), so it is not possible to determine 71 // the type of each argument without some information about the values that were 72 // passed in. This information could be retrieved from the printf format string, 73 // but the format string is not trivial to parse so we encode the relevant 74 // information with the HLT instruction. 75 // 76 // Also, the following registers are populated (as if for a native A64 call): 77 // x0: The format string 78 // x1-x7: Optional arguments, if type == CPURegister::kRegister 79 // d0-d7: Optional arguments, if type == CPURegister::kFPRegister 80 const unsigned kPrintfArgCountOffset = 1 * kInstructionSize; 81 const unsigned kPrintfArgPatternListOffset = 2 * kInstructionSize; 82 const unsigned kPrintfLength = 3 * kInstructionSize; 83 84 const unsigned kPrintfMaxArgCount = 4; 85 86 // The argument pattern is a set of two-bit-fields, each with one of the 87 // following values: 88 enum PrintfArgPattern { 89 kPrintfArgW = 1, 90 kPrintfArgX = 2, 91 // There is no kPrintfArgS because floats are always converted to doubles in C 92 // varargs calls. 93 kPrintfArgD = 3 94 }; 95 static const unsigned kPrintfArgPatternBits = 2; 96 97 // Trace - kTraceOpcode 98 // - parameter: TraceParameter stored as a uint32_t 99 // - command: TraceCommand stored as a uint32_t 100 // 101 // Allow for trace management in the generated code. This enables or disables 102 // automatic tracing of the specified information for every simulated 103 // instruction. 104 const unsigned kTraceParamsOffset = 1 * kInstructionSize; 105 const unsigned kTraceCommandOffset = 2 * kInstructionSize; 106 const unsigned kTraceLength = 3 * kInstructionSize; 107 108 // Trace parameters. 109 enum TraceParameters { 110 LOG_DISASM = 1 << 0, // Log disassembly. 111 LOG_REGS = 1 << 1, // Log general purpose registers. 112 LOG_VREGS = 1 << 2, // Log NEON and floating-point registers. 113 LOG_SYSREGS = 1 << 3, // Log the flags and system registers. 114 LOG_WRITE = 1 << 4, // Log writes to memory. 115 116 LOG_NONE = 0, 117 LOG_STATE = LOG_REGS | LOG_VREGS | LOG_SYSREGS, 118 LOG_ALL = LOG_DISASM | LOG_STATE | LOG_WRITE 119 }; 120 121 // Trace commands. 122 enum TraceCommand { 123 TRACE_ENABLE = 1, 124 TRACE_DISABLE = 2 125 }; 126 127 // Log - kLogOpcode 128 // - parameter: TraceParameter stored as a uint32_t 129 // 130 // Print the specified information once. This mechanism is separate from Trace. 131 // In particular, _all_ of the specified registers are printed, rather than just 132 // the registers that the instruction writes. 133 // 134 // Any combination of the TraceParameters values can be used, except that 135 // LOG_DISASM is not supported for Log. 136 const unsigned kLogParamsOffset = 1 * kInstructionSize; 137 const unsigned kLogLength = 2 * kInstructionSize; 138 } // namespace vixl 139 140 #endif // VIXL_A64_SIMULATOR_CONSTANTS_A64_H_