dxdiagn: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / dbghelp / cpu_arm64.c
blobc68ade2eb1247499e1320a57976d6cb66967cd37
1 /*
2 * File cpu_arm64.c
4 * Copyright (C) 2009 Eric Pouech
5 * Copyright (C) 2010-2013 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
24 #include "ntstatus.h"
25 #define WIN32_NO_STATUS
26 #include "dbghelp_private.h"
27 #include "winternl.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
32 static BOOL arm64_get_addr(HANDLE hThread, const CONTEXT* ctx,
33 enum cpu_addr ca, ADDRESS64* addr)
35 addr->Mode = AddrModeFlat;
36 addr->Segment = 0; /* don't need segment */
37 switch (ca)
39 #ifdef __aarch64__
40 case cpu_addr_pc: addr->Offset = ctx->Pc; return TRUE;
41 case cpu_addr_stack: addr->Offset = ctx->Sp; return TRUE;
42 case cpu_addr_frame: addr->Offset = ctx->Fp; return TRUE;
43 #endif
44 default: addr->Mode = -1;
45 return FALSE;
49 #ifdef __aarch64__
50 enum st_mode {stm_start, stm_arm64, stm_done};
52 /* indexes in Reserved array */
53 #define __CurrentModeCount 0
55 #define curr_mode (frame->Reserved[__CurrentModeCount] & 0x0F)
56 #define curr_count (frame->Reserved[__CurrentModeCount] >> 4)
58 #define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);}
59 #define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10)
61 /* fetch_next_frame()
63 * modify (at least) context.Pc using unwind information
64 * either out of debug info (dwarf), or simple Lr trace
66 static BOOL fetch_next_frame(struct cpu_stack_walk* csw, union ctx *pcontext,
67 DWORD_PTR curr_pc)
69 DWORD64 xframe;
70 CONTEXT *context = &pcontext->ctx;
71 DWORD_PTR oldReturn = context->Lr;
73 if (dwarf2_virtual_unwind(csw, curr_pc, pcontext, &xframe))
75 context->Sp = xframe;
76 context->Pc = oldReturn;
77 return TRUE;
80 if (context->Pc == context->Lr) return FALSE;
81 context->Pc = oldReturn;
83 return TRUE;
86 static BOOL arm64_stack_walk(struct cpu_stack_walk *csw, STACKFRAME64 *frame,
87 union ctx *context)
89 unsigned deltapc = curr_count <= 1 ? 0 : 4;
91 /* sanity check */
92 if (curr_mode >= stm_done) return FALSE;
94 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%I64u\n",
95 wine_dbgstr_addr(&frame->AddrPC),
96 wine_dbgstr_addr(&frame->AddrFrame),
97 wine_dbgstr_addr(&frame->AddrReturn),
98 wine_dbgstr_addr(&frame->AddrStack),
99 curr_mode == stm_start ? "start" : "ARM64",
100 curr_count);
102 if (curr_mode == stm_start)
104 /* Init done */
105 set_curr_mode(stm_arm64);
106 frame->AddrReturn.Mode = frame->AddrStack.Mode = AddrModeFlat;
107 /* don't set up AddrStack on first call. Either the caller has set it up, or
108 * we will get it in the next frame
110 memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
112 else
114 if (context->ctx.Sp != frame->AddrStack.Offset) FIXME("inconsistent Stack Pointer\n");
115 if (context->ctx.Pc != frame->AddrPC.Offset) FIXME("inconsistent Program Counter\n");
117 if (frame->AddrReturn.Offset == 0) goto done_err;
118 if (!fetch_next_frame(csw, context, frame->AddrPC.Offset - deltapc))
119 goto done_err;
122 memset(&frame->Params, 0, sizeof(frame->Params));
124 /* set frame information */
125 frame->AddrStack.Offset = context->ctx.Sp;
126 frame->AddrReturn.Offset = context->ctx.Lr;
127 frame->AddrFrame.Offset = context->ctx.Fp;
128 frame->AddrPC.Offset = context->ctx.Pc;
130 frame->Far = TRUE;
131 frame->Virtual = TRUE;
132 inc_curr_count();
134 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%I64u FuncTable=%p\n",
135 wine_dbgstr_addr(&frame->AddrPC),
136 wine_dbgstr_addr(&frame->AddrFrame),
137 wine_dbgstr_addr(&frame->AddrReturn),
138 wine_dbgstr_addr(&frame->AddrStack),
139 curr_mode == stm_start ? "start" : "ARM64",
140 curr_count,
141 frame->FuncTableEntry);
143 return TRUE;
144 done_err:
145 set_curr_mode(stm_done);
146 return FALSE;
148 #else
149 static BOOL arm64_stack_walk(struct cpu_stack_walk* csw, STACKFRAME64 *frame,
150 union ctx *ctx)
152 return FALSE;
154 #endif
156 static unsigned arm64_map_dwarf_register(unsigned regno, const struct module* module, BOOL eh_frame)
158 if (regno <= 28) return CV_ARM64_X0 + regno;
159 if (regno == 29) return CV_ARM64_FP;
160 if (regno == 30) return CV_ARM64_LR;
161 if (regno == 31) return CV_ARM64_SP;
162 if (regno >= 64 && regno <= 95) return CV_ARM64_Q0 + regno - 64;
164 FIXME("Don't know how to map register %d\n", regno);
165 return CV_ARM64_NOREG;
168 static void *arm64_fetch_context_reg(union ctx *pctx, unsigned regno, unsigned *size)
170 #ifdef __aarch64__
171 CONTEXT *ctx = pctx;
173 switch (regno)
175 case CV_ARM64_X0 + 0:
176 case CV_ARM64_X0 + 1:
177 case CV_ARM64_X0 + 2:
178 case CV_ARM64_X0 + 3:
179 case CV_ARM64_X0 + 4:
180 case CV_ARM64_X0 + 5:
181 case CV_ARM64_X0 + 6:
182 case CV_ARM64_X0 + 7:
183 case CV_ARM64_X0 + 8:
184 case CV_ARM64_X0 + 9:
185 case CV_ARM64_X0 + 10:
186 case CV_ARM64_X0 + 11:
187 case CV_ARM64_X0 + 12:
188 case CV_ARM64_X0 + 13:
189 case CV_ARM64_X0 + 14:
190 case CV_ARM64_X0 + 15:
191 case CV_ARM64_X0 + 16:
192 case CV_ARM64_X0 + 17:
193 case CV_ARM64_X0 + 18:
194 case CV_ARM64_X0 + 19:
195 case CV_ARM64_X0 + 20:
196 case CV_ARM64_X0 + 21:
197 case CV_ARM64_X0 + 22:
198 case CV_ARM64_X0 + 23:
199 case CV_ARM64_X0 + 24:
200 case CV_ARM64_X0 + 25:
201 case CV_ARM64_X0 + 26:
202 case CV_ARM64_X0 + 27:
203 case CV_ARM64_X0 + 28: *size = sizeof(ctx->X[0]); return &ctx->X[regno - CV_ARM64_X0];
204 case CV_ARM64_PSTATE: *size = sizeof(ctx->Cpsr); return &ctx->Cpsr;
205 case CV_ARM64_FP: *size = sizeof(ctx->Fp); return &ctx->Fp;
206 case CV_ARM64_LR: *size = sizeof(ctx->Lr); return &ctx->Lr;
207 case CV_ARM64_SP: *size = sizeof(ctx->Sp); return &ctx->Sp;
208 case CV_ARM64_PC: *size = sizeof(ctx->Pc); return &ctx->Pc;
210 #endif
211 FIXME("Unknown register %x\n", regno);
212 return NULL;
215 static const char* arm64_fetch_regname(unsigned regno)
217 switch (regno)
219 case CV_ARM64_PSTATE: return "cpsr";
220 case CV_ARM64_X0 + 0: return "x0";
221 case CV_ARM64_X0 + 1: return "x1";
222 case CV_ARM64_X0 + 2: return "x2";
223 case CV_ARM64_X0 + 3: return "x3";
224 case CV_ARM64_X0 + 4: return "x4";
225 case CV_ARM64_X0 + 5: return "x5";
226 case CV_ARM64_X0 + 6: return "x6";
227 case CV_ARM64_X0 + 7: return "x7";
228 case CV_ARM64_X0 + 8: return "x8";
229 case CV_ARM64_X0 + 9: return "x9";
230 case CV_ARM64_X0 + 10: return "x10";
231 case CV_ARM64_X0 + 11: return "x11";
232 case CV_ARM64_X0 + 12: return "x12";
233 case CV_ARM64_X0 + 13: return "x13";
234 case CV_ARM64_X0 + 14: return "x14";
235 case CV_ARM64_X0 + 15: return "x15";
236 case CV_ARM64_X0 + 16: return "x16";
237 case CV_ARM64_X0 + 17: return "x17";
238 case CV_ARM64_X0 + 18: return "x18";
239 case CV_ARM64_X0 + 19: return "x19";
240 case CV_ARM64_X0 + 20: return "x20";
241 case CV_ARM64_X0 + 21: return "x21";
242 case CV_ARM64_X0 + 22: return "x22";
243 case CV_ARM64_X0 + 23: return "x23";
244 case CV_ARM64_X0 + 24: return "x24";
245 case CV_ARM64_X0 + 25: return "x25";
246 case CV_ARM64_X0 + 26: return "x26";
247 case CV_ARM64_X0 + 27: return "x27";
248 case CV_ARM64_X0 + 28: return "x28";
250 case CV_ARM64_FP: return "fp";
251 case CV_ARM64_LR: return "lr";
252 case CV_ARM64_SP: return "sp";
253 case CV_ARM64_PC: return "pc";
255 FIXME("Unknown register %x\n", regno);
256 return NULL;
259 static BOOL arm64_fetch_minidump_thread(struct dump_context* dc, unsigned index, unsigned flags, const CONTEXT* ctx)
261 if (ctx->ContextFlags && (flags & ThreadWriteInstructionWindow))
263 /* FIXME: crop values across module boundaries, */
264 #ifdef __aarch64__
265 ULONG64 base = ctx->Pc <= 0x80 ? 0 : ctx->Pc - 0x80;
266 minidump_add_memory_block(dc, base, ctx->Pc + 0x80 - base, 0);
267 #endif
270 return TRUE;
273 static BOOL arm64_fetch_minidump_module(struct dump_context* dc, unsigned index, unsigned flags)
275 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
276 * function table minidump stream
278 return FALSE;
281 DECLSPEC_HIDDEN struct cpu cpu_arm64 = {
282 IMAGE_FILE_MACHINE_ARM64,
284 CV_ARM64_FP,
285 arm64_get_addr,
286 arm64_stack_walk,
287 NULL,
288 arm64_map_dwarf_register,
289 arm64_fetch_context_reg,
290 arm64_fetch_regname,
291 arm64_fetch_minidump_thread,
292 arm64_fetch_minidump_module,