Welcome to mirror list, hosted at ThFree Co, Russian Federation.

regdisplay.h « Runtime « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb96f400f4df148903f52c8d73f2f6f9e8868088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)

// These definitions are from our copy of libunwind. Including them directly here
// so that the REGDISPLAY code doesn't need to reference libunwind.
namespace LibunwindConstants
{
    // copied from Registers.hpp
    // Architecture independent register numbers
    enum {
      UNW_REG_IP = -1, // instruction pointer
      UNW_REG_SP = -2, // stack pointer
    };

    // copied from libunwind.h
    // 64-bit x86_64 registers
    enum {
      UNW_X86_64_RAX = 0,
      UNW_X86_64_RDX = 1,
      UNW_X86_64_RCX = 2,
      UNW_X86_64_RBX = 3,
      UNW_X86_64_RSI = 4,
      UNW_X86_64_RDI = 5,
      UNW_X86_64_RBP = 6,
      UNW_X86_64_RSP = 7,
      UNW_X86_64_R8  = 8,
      UNW_X86_64_R9  = 9,
      UNW_X86_64_R10 = 10,
      UNW_X86_64_R11 = 11,
      UNW_X86_64_R12 = 12,
      UNW_X86_64_R13 = 13,
      UNW_X86_64_R14 = 14,
      UNW_X86_64_R15 = 15
    };
}

struct REGDISPLAY 
{
    PTR_UIntNative pRax;
    PTR_UIntNative pRcx;
    PTR_UIntNative pRdx;
    PTR_UIntNative pRbx;
    //           pEsp;
    PTR_UIntNative pRbp;
    PTR_UIntNative pRsi;
    PTR_UIntNative pRdi;
#ifdef _TARGET_AMD64_
    PTR_UIntNative pR8;
    PTR_UIntNative pR9;
    PTR_UIntNative pR10;
    PTR_UIntNative pR11;
    PTR_UIntNative pR12;
    PTR_UIntNative pR13;
    PTR_UIntNative pR14;
    PTR_UIntNative pR15;
#endif // _TARGET_AMD64_

    UIntNative   SP;
    PTR_PCODE    pIP;
    PCODE        IP;

#if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI)
    Fp128          Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk
                              // these need to be unwound during a stack walk
                              // for EH, but not adjusted, so we only need
                              // their values, not their addresses
#endif // _TARGET_AMD64_ && !UNIX_AMD64_ABI

    inline PCODE GetIP() { return IP; }
    inline PTR_PCODE GetAddrOfIP() { return pIP; }
    inline UIntNative GetSP() { return SP; }
    inline UIntNative GetFP() { return *pRbp; }
    inline UIntNative GetPP() { return *pRbx; }

    inline void SetIP(PCODE IP) { this->IP = IP; }
    inline void SetAddrOfIP(PTR_PCODE pIP) { this->pIP = pIP; }
    inline void SetSP(UIntNative SP) { this->SP = SP; }

    // Everything below was added to enable libunwind to work with REGDISPLAYs.

#if defined(_TARGET_AMD64_)

    inline uint64_t getRegister(int regNum) const
    {
        switch (regNum) 
        {
        case LibunwindConstants::UNW_REG_IP:
            return IP;
        case LibunwindConstants::UNW_REG_SP:
            return SP;
        case LibunwindConstants::UNW_X86_64_RAX:
            return *pRax;
        case LibunwindConstants::UNW_X86_64_RDX:
            return *pRdx;
        case LibunwindConstants::UNW_X86_64_RCX:
            return *pRcx;
        case LibunwindConstants::UNW_X86_64_RBX:
            return *pRbx;
        case LibunwindConstants::UNW_X86_64_RSI:
            return *pRsi;
        case LibunwindConstants::UNW_X86_64_RDI:
            return *pRdi;
        case LibunwindConstants::UNW_X86_64_RBP:
            return *pRbp;
        case LibunwindConstants::UNW_X86_64_RSP:
            return SP;
        case LibunwindConstants::UNW_X86_64_R8:
            return *pR8;
        case LibunwindConstants::UNW_X86_64_R9:
            return *pR9;
        case LibunwindConstants::UNW_X86_64_R10:
            return *pR10;
        case LibunwindConstants::UNW_X86_64_R11:
            return *pR11;
        case LibunwindConstants::UNW_X86_64_R12:
            return *pR12;
        case LibunwindConstants::UNW_X86_64_R13:
            return *pR13;
        case LibunwindConstants::UNW_X86_64_R14:
            return *pR14;
        case LibunwindConstants::UNW_X86_64_R15:
            return *pR15;
        }

        // Unsupported register requested
        abort();
    }

    inline void setRegister(int regNum, uint64_t value, uint64_t location)
    {
        switch (regNum)
        {
        case LibunwindConstants::UNW_REG_IP:
            IP = value;
            pIP = (PTR_PCODE)location;
            return;
        case LibunwindConstants::UNW_REG_SP:
            SP = value;
            return;
        case LibunwindConstants::UNW_X86_64_RAX:
            pRax = (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RDX:
            pRdx = (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RCX:
            pRcx =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RBX:
            pRbx =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RSI:
            pRsi =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RDI:
            pRdi =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RBP:
            pRbp =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_RSP:
            SP = value;
            return;
        case LibunwindConstants::UNW_X86_64_R8:
            pR8 = (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R9:
            pR9 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R10:
            pR10 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R11:
            pR11 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R12:
            pR12 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R13:
            pR13 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R14:
            pR14 =  (PTR_UIntNative)location;
            return;
        case LibunwindConstants::UNW_X86_64_R15:
            pR15 =  (PTR_UIntNative)location;
            return;
        }

        // Unsupported x86_64 register
        abort();
    }

    // N/A for x86_64
    inline bool validFloatRegister(int) { return false; }
    inline bool validVectorRegister(int) { return false; }

    inline static int  lastDwarfRegNum() { return 16; }

    inline bool validRegister(int regNum) const
    {
        if (regNum == LibunwindConstants::UNW_REG_IP)
            return true;
        if (regNum == LibunwindConstants::UNW_REG_SP)
            return true;
        if (regNum < 0)
            return false;
        if (regNum > 15)
            return false;
        return true;
    }

    // N/A for x86_64
    inline double getFloatRegister(int) const   { abort(); }
    inline   void setFloatRegister(int, double) { abort(); }
    inline double getVectorRegister(int) const  { abort(); }
    inline   void setVectorRegister(int, ...)   { abort(); }

    uint64_t  getSP() const { return SP; }
    void      setSP(uint64_t value, uint64_t location) { SP = value; }

    uint64_t  getIP() const { return IP; }

    void      setIP(uint64_t value, uint64_t location)
    {
        IP = value;
        pIP = (PTR_PCODE)location;
    }

    uint64_t  getRBP() const         { return *pRbp; }
    void      setRBP(uint64_t value, uint64_t location) { pRbp = (PTR_UIntNative)location; }
    uint64_t  getRBX() const         { return *pRbx; }
    void      setRBX(uint64_t value, uint64_t location) { pRbx = (PTR_UIntNative)location; }
    uint64_t  getR12() const         { return *pR12; }
    void      setR12(uint64_t value, uint64_t location) { pR12 = (PTR_UIntNative)location; }
    uint64_t  getR13() const         { return *pR13; }
    void      setR13(uint64_t value, uint64_t location) { pR13 = (PTR_UIntNative)location; }
    uint64_t  getR14() const         { return *pR14; }
    void      setR14(uint64_t value, uint64_t location) { pR14 = (PTR_UIntNative)location; }
    uint64_t  getR15() const         { return *pR15; }
    void      setR15(uint64_t value, uint64_t location) { pR15 = (PTR_UIntNative)location; }

#endif // _TARGET_AMD64_

};

#elif defined(_TARGET_ARM_)

struct REGDISPLAY
{
    PTR_UIntNative pR0;
    PTR_UIntNative pR1;
    PTR_UIntNative pR2;
    PTR_UIntNative pR3;
    PTR_UIntNative pR4;
    PTR_UIntNative pR5;
    PTR_UIntNative pR6;
    PTR_UIntNative pR7;
    PTR_UIntNative pR8;
    PTR_UIntNative pR9;
    PTR_UIntNative pR10;
    PTR_UIntNative pR11;
    PTR_UIntNative pR12;
    PTR_UIntNative pLR;

    UIntNative   SP;
    PTR_PCODE    pIP;
    PCODE        IP;

    UInt64       D[16-8]; // preserved D registers D8..D15 (note that D16-D31 are not preserved according to the ABI spec)
                          // these need to be unwound during a stack walk
                          // for EH, but not adjusted, so we only need
                          // their values, not their addresses

    inline PCODE GetIP() { return IP; }
    inline PTR_PCODE GetAddrOfIP() { return pIP; }
    inline UIntNative GetSP() { return SP; }
    inline UIntNative GetFP() { return *pR7; }

    inline void SetIP(PCODE IP) { this->IP = IP; }
    inline void SetAddrOfIP(PTR_PCODE pIP) { this->pIP = pIP; }
    inline void SetSP(UIntNative SP) { this->SP = SP; }
};

#elif defined(_TARGET_ARM64_)

struct REGDISPLAY 
{
    PTR_UIntNative pX0;
    PTR_UIntNative pX1;
    PTR_UIntNative pX2;
    PTR_UIntNative pX3;
    PTR_UIntNative pX4;
    PTR_UIntNative pX5;
    PTR_UIntNative pX6;
    PTR_UIntNative pX7;
    PTR_UIntNative pX8;
    PTR_UIntNative pX9;
    PTR_UIntNative pX10;
    PTR_UIntNative pX11;
    PTR_UIntNative pX12;
    PTR_UIntNative pX13;
    PTR_UIntNative pX14;
    PTR_UIntNative pX15;
    PTR_UIntNative pX16;
    PTR_UIntNative pX17;
    PTR_UIntNative pX18;
    PTR_UIntNative pX19;
    PTR_UIntNative pX20;
    PTR_UIntNative pX21;
    PTR_UIntNative pX22;
    PTR_UIntNative pX23;
    PTR_UIntNative pX24;
    PTR_UIntNative pX25;
    PTR_UIntNative pX26;
    PTR_UIntNative pX27;
    PTR_UIntNative pX28;
    PTR_UIntNative pFP; // X29
    PTR_UIntNative pLR; // X30

    UIntNative   SP;
    PTR_PCODE    pIP;
    PCODE        IP;

    UInt64       D[16-8]; // Only the bottom 64-bit value of the V registers V8..V15 needs to be preserved
                          // (V0-V7 and V16-V31 are not preserved according to the ABI spec).
                          // These need to be unwound during a stack walk
                          // for EH, but not adjusted, so we only need
                          // their values, not their addresses

    inline PCODE GetIP() { return IP; }
    inline PTR_PCODE GetAddrOfIP() { return pIP; }
    inline UIntNative GetSP() { return SP; }
    inline UIntNative GetFP() { return *pFP; }

    inline void SetIP(PCODE IP) { this->IP = IP; }
    inline void SetAddrOfIP(PTR_PCODE pIP) { this->pIP = pIP; }
    inline void SetSP(UIntNative SP) { this->SP = SP; }
};
#elif defined(_TARGET_WASM_)

struct REGDISPLAY
{
    // TODO: WebAssembly doesn't really have registers. What exactly do we need here?

    UIntNative   SP;
    PTR_PCODE    pIP;
    PCODE        IP;

    inline PCODE GetIP() { return NULL; }
    inline PTR_PCODE GetAddrOfIP() { return NULL; }
    inline UIntNative GetSP() { return 0; }
    inline UIntNative GetFP() { return 0; }

    inline void SetIP(PCODE IP) { }
    inline void SetAddrOfIP(PTR_PCODE pIP) { }
    inline void SetSP(UIntNative SP) { }
};
#endif // _X86_ || _AMD64_ || _ARM_ || _ARM64_ || _WASM_

typedef REGDISPLAY * PREGDISPLAY;