1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 // 6 // Provide common definitions between the Redhawk and the Redhawk PAL implementation. This header file is used 7 // (rather than PalRedhawk.h) since the PAL implementation is built in a different environment than Redhawk 8 // code. For instance both environments may provide a definition of various common macros such as NULL. 9 // 10 // This header contains only environment neutral definitions (i.e. using only base C++ types and compositions 11 // of those types) and can thus be included from either environment without issue. 12 // 13 14 #ifndef __PAL_REDHAWK_COMMON_INCLUDED 15 #define __PAL_REDHAWK_COMMON_INCLUDED 16 17 #include "rhassert.h" 18 19 // We define the notion of capabilities: optional functionality that the PAL may expose. Use 20 // PalHasCapability() with the constants below to determine what is supported at runtime. 21 enum PalCapability 22 { 23 WriteWatchCapability = 0x00000001, // GetWriteWatch() and friends 24 LowMemoryNotificationCapability = 0x00000002, // CreateMemoryResourceNotification() and friends 25 GetCurrentProcessorNumberCapability = 0x00000004, // GetCurrentProcessorNumber() 26 }; 27 28 #define DECLSPEC_ALIGN(x) __declspec(align(x)) 29 30 #ifdef _AMD64_ 31 #define AMD64_ALIGN_16 DECLSPEC_ALIGN(16) 32 #else // _AMD64_ 33 #define AMD64_ALIGN_16 34 #endif // _AMD64_ 35 36 struct AMD64_ALIGN_16 Fp128 { 37 UInt64 Low; 38 Int64 High; 39 }; 40 41 42 struct PAL_LIMITED_CONTEXT 43 { 44 // Includes special registers, callee saved registers and general purpose registers used to return values from functions (not floating point return registers) 45 #ifdef _TARGET_ARM_ 46 UIntNative R0; 47 UIntNative R4; 48 UIntNative R5; 49 UIntNative R6; 50 UIntNative R7; 51 UIntNative R8; 52 UIntNative R9; 53 UIntNative R10; 54 UIntNative R11; 55 56 UIntNative IP; 57 UIntNative SP; 58 UIntNative LR; 59 60 UInt64 D[16-8]; // D8 .. D15 registers (D16 .. D31 are volatile according to the ABI spec) 61 GetIpPAL_LIMITED_CONTEXT62 UIntNative GetIp() const { return IP; } GetSpPAL_LIMITED_CONTEXT63 UIntNative GetSp() const { return SP; } GetFpPAL_LIMITED_CONTEXT64 UIntNative GetFp() const { return R7; } GetLrPAL_LIMITED_CONTEXT65 UIntNative GetLr() const { return LR; } SetIpPAL_LIMITED_CONTEXT66 void SetIp(UIntNative ip) { IP = ip; } SetSpPAL_LIMITED_CONTEXT67 void SetSp(UIntNative sp) { SP = sp; } 68 #elif defined(_TARGET_ARM64_) 69 UIntNative FP; 70 UIntNative LR; 71 72 UIntNative X0; 73 UIntNative X1; 74 UIntNative X19; 75 UIntNative X20; 76 UIntNative X21; 77 UIntNative X22; 78 UIntNative X23; 79 UIntNative X24; 80 UIntNative X25; 81 UIntNative X26; 82 UIntNative X27; 83 UIntNative X28; 84 85 UIntNative SP; 86 UIntNative IP; 87 88 UInt64 D[16 - 8]; // Only the bottom 64-bit value of the V registers V8..V15 needs to be preserved 89 // (V0-V7 and V16-V31 are not preserved according to the ABI spec). 90 91 92 UIntNative GetIp() const { return IP; } 93 UIntNative GetSp() const { return SP; } 94 UIntNative GetFp() const { return FP; } 95 UIntNative GetLr() const { return LR; } 96 void SetIp(UIntNative ip) { IP = ip; } 97 void SetSp(UIntNative sp) { SP = sp; } 98 #elif defined(UNIX_AMD64_ABI) 99 // Param regs: rdi, rsi, rdx, rcx, r8, r9, scratch: rax, rdx (both return val), preserved: rbp, rbx, r12-r15 100 UIntNative IP; 101 UIntNative Rsp; 102 UIntNative Rbp; 103 UIntNative Rax; 104 UIntNative Rbx; 105 UIntNative Rdx; 106 UIntNative R12; 107 UIntNative R13; 108 UIntNative R14; 109 UIntNative R15; 110 111 UIntNative GetIp() const { return IP; } 112 UIntNative GetSp() const { return Rsp; } 113 void SetIp(UIntNative ip) { IP = ip; } 114 void SetSp(UIntNative sp) { Rsp = sp; } 115 UIntNative GetFp() const { return Rbp; } 116 #elif defined(_TARGET_X86_) || defined(_TARGET_AMD64_) 117 UIntNative IP; 118 UIntNative Rsp; 119 UIntNative Rbp; 120 UIntNative Rdi; 121 UIntNative Rsi; 122 UIntNative Rax; 123 UIntNative Rbx; 124 #ifdef _TARGET_AMD64_ 125 UIntNative R12; 126 UIntNative R13; 127 UIntNative R14; 128 UIntNative R15; 129 UIntNative __explicit_padding__; 130 Fp128 Xmm6; 131 Fp128 Xmm7; 132 Fp128 Xmm8; 133 Fp128 Xmm9; 134 Fp128 Xmm10; 135 Fp128 Xmm11; 136 Fp128 Xmm12; 137 Fp128 Xmm13; 138 Fp128 Xmm14; 139 Fp128 Xmm15; 140 #endif // _TARGET_AMD64_ 141 142 UIntNative GetIp() const { return IP; } 143 UIntNative GetSp() const { return Rsp; } 144 UIntNative GetFp() const { return Rbp; } 145 void SetIp(UIntNative ip) { IP = ip; } 146 void SetSp(UIntNative sp) { Rsp = sp; } 147 #else // _TARGET_ARM_ 148 UIntNative IP; 149 150 UIntNative GetIp() const { PORTABILITY_ASSERT("GetIp"); return 0; } 151 UIntNative GetSp() const { PORTABILITY_ASSERT("GetSp"); return 0; } 152 UIntNative GetFp() const { PORTABILITY_ASSERT("GetFp"); return 0; } 153 void SetIp(UIntNative ip) { PORTABILITY_ASSERT("SetIp"); } 154 void SetSp(UIntNative sp) { PORTABILITY_ASSERT("GetSp"); } 155 #endif // _TARGET_ARM_ 156 }; 157 158 void RuntimeThreadShutdown(void* thread); 159 160 #ifdef PLATFORM_UNIX 161 typedef void (__fastcall * ThreadExitCallback)(); 162 163 extern ThreadExitCallback g_threadExitCallback; 164 165 typedef Int32 (*PHARDWARE_EXCEPTION_HANDLER)(UIntNative faultCode, UIntNative faultAddress, PAL_LIMITED_CONTEXT* palContext, UIntNative* arg0Reg, UIntNative* arg1Reg); 166 #endif 167 168 #endif // __PAL_REDHAWK_COMMON_INCLUDED 169