ntdll/tests: Add some tests for registry path names.
[wine.git] / dlls / dbghelp / cpu_arm64.c
blob85d17da24805143d9f6e63c6e96a5feca36480b5
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,
67 CONTEXT* context, DWORD_PTR curr_pc)
69 DWORD_PTR xframe;
70 DWORD_PTR oldReturn = context->Lr;
72 if (dwarf2_virtual_unwind(csw, curr_pc, context, &xframe))
74 context->Sp = xframe;
75 context->Pc = oldReturn;
76 return TRUE;
79 if (context->Pc == context->Lr) return FALSE;
80 context->Pc = oldReturn;
82 return TRUE;
85 static BOOL arm64_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context)
87 unsigned deltapc = curr_count <= 1 ? 0 : 4;
89 /* sanity check */
90 if (curr_mode >= stm_done) return FALSE;
92 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s\n",
93 wine_dbgstr_addr(&frame->AddrPC),
94 wine_dbgstr_addr(&frame->AddrFrame),
95 wine_dbgstr_addr(&frame->AddrReturn),
96 wine_dbgstr_addr(&frame->AddrStack),
97 curr_mode == stm_start ? "start" : "ARM64",
98 wine_dbgstr_longlong(curr_count));
100 if (curr_mode == stm_start)
102 /* Init done */
103 set_curr_mode(stm_arm64);
104 frame->AddrReturn.Mode = frame->AddrStack.Mode = AddrModeFlat;
105 /* don't set up AddrStack on first call. Either the caller has set it up, or
106 * we will get it in the next frame
108 memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
110 else
112 if (context->Sp != frame->AddrStack.Offset) FIXME("inconsistent Stack Pointer\n");
113 if (context->Pc != frame->AddrPC.Offset) FIXME("inconsistent Program Counter\n");
115 if (frame->AddrReturn.Offset == 0) goto done_err;
116 if (!fetch_next_frame(csw, context, frame->AddrPC.Offset - deltapc))
117 goto done_err;
120 memset(&frame->Params, 0, sizeof(frame->Params));
122 /* set frame information */
123 frame->AddrStack.Offset = context->Sp;
124 frame->AddrReturn.Offset = context->Lr;
125 frame->AddrFrame.Offset = context->Fp;
126 frame->AddrPC.Offset = context->Pc;
128 frame->Far = TRUE;
129 frame->Virtual = TRUE;
130 inc_curr_count();
132 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s FuncTable=%p\n",
133 wine_dbgstr_addr(&frame->AddrPC),
134 wine_dbgstr_addr(&frame->AddrFrame),
135 wine_dbgstr_addr(&frame->AddrReturn),
136 wine_dbgstr_addr(&frame->AddrStack),
137 curr_mode == stm_start ? "start" : "ARM64",
138 wine_dbgstr_longlong(curr_count),
139 frame->FuncTableEntry);
141 return TRUE;
142 done_err:
143 set_curr_mode(stm_done);
144 return FALSE;
146 #else
147 static BOOL arm64_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context)
149 return FALSE;
151 #endif
153 static unsigned arm64_map_dwarf_register(unsigned regno, BOOL eh_frame)
155 if (regno <= 28) return CV_ARM64_X0 + regno;
156 if (regno == 29) return CV_ARM64_FP;
157 if (regno == 30) return CV_ARM64_LR;
158 if (regno == 31) return CV_ARM64_SP;
160 FIXME("Don't know how to map register %d\n", regno);
161 return CV_ARM64_NOREG;
164 static void* arm64_fetch_context_reg(CONTEXT* ctx, unsigned regno, unsigned* size)
166 #ifdef __aarch64__
167 switch (regno)
169 case CV_ARM64_PSTATE: *size = sizeof(ctx->Cpsr); return &ctx->Cpsr;
170 case CV_ARM64_X0 + 0: *size = sizeof(ctx->X0); return &ctx->X0;
171 case CV_ARM64_X0 + 1: *size = sizeof(ctx->X1); return &ctx->X1;
172 case CV_ARM64_X0 + 2: *size = sizeof(ctx->X2); return &ctx->X2;
173 case CV_ARM64_X0 + 3: *size = sizeof(ctx->X3); return &ctx->X3;
174 case CV_ARM64_X0 + 4: *size = sizeof(ctx->X4); return &ctx->X4;
175 case CV_ARM64_X0 + 5: *size = sizeof(ctx->X5); return &ctx->X5;
176 case CV_ARM64_X0 + 6: *size = sizeof(ctx->X6); return &ctx->X6;
177 case CV_ARM64_X0 + 7: *size = sizeof(ctx->X7); return &ctx->X7;
178 case CV_ARM64_X0 + 8: *size = sizeof(ctx->X8); return &ctx->X8;
179 case CV_ARM64_X0 + 9: *size = sizeof(ctx->X9); return &ctx->X9;
180 case CV_ARM64_X0 + 10: *size = sizeof(ctx->X10); return &ctx->X10;
181 case CV_ARM64_X0 + 11: *size = sizeof(ctx->X11); return &ctx->X11;
182 case CV_ARM64_X0 + 12: *size = sizeof(ctx->X12); return &ctx->X12;
183 case CV_ARM64_X0 + 13: *size = sizeof(ctx->X13); return &ctx->X13;
184 case CV_ARM64_X0 + 14: *size = sizeof(ctx->X14); return &ctx->X14;
185 case CV_ARM64_X0 + 15: *size = sizeof(ctx->X15); return &ctx->X15;
186 case CV_ARM64_X0 + 16: *size = sizeof(ctx->X16); return &ctx->X16;
187 case CV_ARM64_X0 + 17: *size = sizeof(ctx->X17); return &ctx->X17;
188 case CV_ARM64_X0 + 18: *size = sizeof(ctx->X18); return &ctx->X18;
189 case CV_ARM64_X0 + 19: *size = sizeof(ctx->X19); return &ctx->X19;
190 case CV_ARM64_X0 + 20: *size = sizeof(ctx->X20); return &ctx->X20;
191 case CV_ARM64_X0 + 21: *size = sizeof(ctx->X21); return &ctx->X21;
192 case CV_ARM64_X0 + 22: *size = sizeof(ctx->X22); return &ctx->X22;
193 case CV_ARM64_X0 + 23: *size = sizeof(ctx->X23); return &ctx->X23;
194 case CV_ARM64_X0 + 24: *size = sizeof(ctx->X24); return &ctx->X24;
195 case CV_ARM64_X0 + 25: *size = sizeof(ctx->X25); return &ctx->X25;
196 case CV_ARM64_X0 + 26: *size = sizeof(ctx->X26); return &ctx->X26;
197 case CV_ARM64_X0 + 27: *size = sizeof(ctx->X27); return &ctx->X27;
198 case CV_ARM64_X0 + 28: *size = sizeof(ctx->X28); return &ctx->X28;
200 case CV_ARM64_FP: *size = sizeof(ctx->Fp); return &ctx->Fp;
201 case CV_ARM64_LR: *size = sizeof(ctx->Lr); return &ctx->Lr;
202 case CV_ARM64_SP: *size = sizeof(ctx->Sp); return &ctx->Sp;
203 case CV_ARM64_PC: *size = sizeof(ctx->Pc); return &ctx->Pc;
205 #endif
206 FIXME("Unknown register %x\n", regno);
207 return NULL;
210 static const char* arm64_fetch_regname(unsigned regno)
212 switch (regno)
214 case CV_ARM64_PSTATE: return "cpsr";
215 case CV_ARM64_X0 + 0: return "x0";
216 case CV_ARM64_X0 + 1: return "x1";
217 case CV_ARM64_X0 + 2: return "x2";
218 case CV_ARM64_X0 + 3: return "x3";
219 case CV_ARM64_X0 + 4: return "x4";
220 case CV_ARM64_X0 + 5: return "x5";
221 case CV_ARM64_X0 + 6: return "x6";
222 case CV_ARM64_X0 + 7: return "x7";
223 case CV_ARM64_X0 + 8: return "x8";
224 case CV_ARM64_X0 + 9: return "x9";
225 case CV_ARM64_X0 + 10: return "x10";
226 case CV_ARM64_X0 + 11: return "x11";
227 case CV_ARM64_X0 + 12: return "x12";
228 case CV_ARM64_X0 + 13: return "x13";
229 case CV_ARM64_X0 + 14: return "x14";
230 case CV_ARM64_X0 + 15: return "x15";
231 case CV_ARM64_X0 + 16: return "x16";
232 case CV_ARM64_X0 + 17: return "x17";
233 case CV_ARM64_X0 + 18: return "x18";
234 case CV_ARM64_X0 + 19: return "x19";
235 case CV_ARM64_X0 + 20: return "x20";
236 case CV_ARM64_X0 + 21: return "x21";
237 case CV_ARM64_X0 + 22: return "x22";
238 case CV_ARM64_X0 + 23: return "x23";
239 case CV_ARM64_X0 + 24: return "x24";
240 case CV_ARM64_X0 + 25: return "x25";
241 case CV_ARM64_X0 + 26: return "x26";
242 case CV_ARM64_X0 + 27: return "x27";
243 case CV_ARM64_X0 + 28: return "x28";
245 case CV_ARM64_FP: return "fp";
246 case CV_ARM64_LR: return "lr";
247 case CV_ARM64_SP: return "sp";
248 case CV_ARM64_PC: return "pc";
250 FIXME("Unknown register %x\n", regno);
251 return NULL;
254 static BOOL arm64_fetch_minidump_thread(struct dump_context* dc, unsigned index, unsigned flags, const CONTEXT* ctx)
256 if (ctx->ContextFlags && (flags & ThreadWriteInstructionWindow))
258 /* FIXME: crop values across module boundaries, */
259 #ifdef __aarch64__
260 ULONG base = ctx->Pc <= 0x80 ? 0 : ctx->Pc - 0x80;
261 minidump_add_memory_block(dc, base, ctx->Pc + 0x80 - base, 0);
262 #endif
265 return TRUE;
268 static BOOL arm64_fetch_minidump_module(struct dump_context* dc, unsigned index, unsigned flags)
270 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
271 * function table minidump stream
273 return FALSE;
276 DECLSPEC_HIDDEN struct cpu cpu_arm64 = {
277 IMAGE_FILE_MACHINE_ARM64,
279 CV_ARM64_FP,
280 arm64_get_addr,
281 arm64_stack_walk,
282 NULL,
283 arm64_map_dwarf_register,
284 arm64_fetch_context_reg,
285 arm64_fetch_regname,
286 arm64_fetch_minidump_thread,
287 arm64_fetch_minidump_module,