urlmon/tests: Use BOOL type where appropriate.
[wine/multimedia.git] / dlls / dbghelp / cpu_arm64.c
blobd80e60800ad5e3ea10f559434616abe79c773281
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->X29; 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->X30;
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->X30) 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->X30;
125 frame->AddrFrame.Offset = context->X29;
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" : "ARM",
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)
155 if (regno <= 30) return CV_ARM64_X0 + regno;
156 if (regno == 31) return CV_ARM64_SP;
158 FIXME("Don't know how to map register %d\n", regno);
159 return CV_ARM64_NOREG;
162 static void* arm64_fetch_context_reg(CONTEXT* ctx, unsigned regno, unsigned* size)
164 #ifdef __aarch64__
165 switch (regno)
168 case CV_ARM64_X0 + 0: *size = sizeof(ctx->X0); return &ctx->X0;
169 case CV_ARM64_X0 + 1: *size = sizeof(ctx->X1); return &ctx->X1;
170 case CV_ARM64_X0 + 2: *size = sizeof(ctx->X2); return &ctx->X2;
171 case CV_ARM64_X0 + 3: *size = sizeof(ctx->X3); return &ctx->X3;
172 case CV_ARM64_X0 + 4: *size = sizeof(ctx->X4); return &ctx->X4;
173 case CV_ARM64_X0 + 5: *size = sizeof(ctx->X5); return &ctx->X5;
174 case CV_ARM64_X0 + 6: *size = sizeof(ctx->X6); return &ctx->X6;
175 case CV_ARM64_X0 + 7: *size = sizeof(ctx->X7); return &ctx->X7;
176 case CV_ARM64_X0 + 8: *size = sizeof(ctx->X8); return &ctx->X8;
177 case CV_ARM64_X0 + 9: *size = sizeof(ctx->X9); return &ctx->X9;
178 case CV_ARM64_X0 + 10: *size = sizeof(ctx->X10); return &ctx->X10;
179 case CV_ARM64_X0 + 11: *size = sizeof(ctx->X11); return &ctx->X11;
180 case CV_ARM64_X0 + 12: *size = sizeof(ctx->X12); return &ctx->X12;
181 case CV_ARM64_X0 + 13: *size = sizeof(ctx->X13); return &ctx->X13;
182 case CV_ARM64_X0 + 14: *size = sizeof(ctx->X14); return &ctx->X14;
183 case CV_ARM64_X0 + 15: *size = sizeof(ctx->X15); return &ctx->X15;
184 case CV_ARM64_X0 + 16: *size = sizeof(ctx->X16); return &ctx->X16;
185 case CV_ARM64_X0 + 17: *size = sizeof(ctx->X17); return &ctx->X17;
186 case CV_ARM64_X0 + 18: *size = sizeof(ctx->X18); return &ctx->X18;
187 case CV_ARM64_X0 + 19: *size = sizeof(ctx->X19); return &ctx->X19;
188 case CV_ARM64_X0 + 20: *size = sizeof(ctx->X20); return &ctx->X20;
189 case CV_ARM64_X0 + 21: *size = sizeof(ctx->X21); return &ctx->X21;
190 case CV_ARM64_X0 + 22: *size = sizeof(ctx->X22); return &ctx->X22;
191 case CV_ARM64_X0 + 23: *size = sizeof(ctx->X23); return &ctx->X23;
192 case CV_ARM64_X0 + 24: *size = sizeof(ctx->X24); return &ctx->X24;
193 case CV_ARM64_X0 + 25: *size = sizeof(ctx->X25); return &ctx->X25;
194 case CV_ARM64_X0 + 26: *size = sizeof(ctx->X26); return &ctx->X26;
195 case CV_ARM64_X0 + 27: *size = sizeof(ctx->X27); return &ctx->X27;
196 case CV_ARM64_X0 + 28: *size = sizeof(ctx->X28); return &ctx->X28;
197 case CV_ARM64_X0 + 29: *size = sizeof(ctx->X29); return &ctx->X29;
198 case CV_ARM64_X0 + 30: *size = sizeof(ctx->X30); return &ctx->X30;
200 case CV_ARM64_SP: *size = sizeof(ctx->Sp); return &ctx->Sp;
201 case CV_ARM64_PC: *size = sizeof(ctx->Pc); return &ctx->Pc;
202 case CV_ARM64_PSTATE: *size = sizeof(ctx->PState); return &ctx->PState;
204 #endif
205 FIXME("Unknown register %x\n", regno);
206 return NULL;
209 static const char* arm64_fetch_regname(unsigned regno)
211 switch (regno)
213 case CV_ARM64_X0 + 0: return "x0";
214 case CV_ARM64_X0 + 1: return "x1";
215 case CV_ARM64_X0 + 2: return "x2";
216 case CV_ARM64_X0 + 3: return "x3";
217 case CV_ARM64_X0 + 4: return "x4";
218 case CV_ARM64_X0 + 5: return "x5";
219 case CV_ARM64_X0 + 6: return "x6";
220 case CV_ARM64_X0 + 7: return "x7";
221 case CV_ARM64_X0 + 8: return "x8";
222 case CV_ARM64_X0 + 9: return "x9";
223 case CV_ARM64_X0 + 10: return "x10";
224 case CV_ARM64_X0 + 11: return "x11";
225 case CV_ARM64_X0 + 12: return "x12";
226 case CV_ARM64_X0 + 13: return "x13";
227 case CV_ARM64_X0 + 14: return "x14";
228 case CV_ARM64_X0 + 15: return "x15";
229 case CV_ARM64_X0 + 16: return "x16";
230 case CV_ARM64_X0 + 17: return "x17";
231 case CV_ARM64_X0 + 18: return "x18";
232 case CV_ARM64_X0 + 19: return "x19";
233 case CV_ARM64_X0 + 20: return "x20";
234 case CV_ARM64_X0 + 21: return "x21";
235 case CV_ARM64_X0 + 22: return "x22";
236 case CV_ARM64_X0 + 23: return "x23";
237 case CV_ARM64_X0 + 24: return "x24";
238 case CV_ARM64_X0 + 25: return "x25";
239 case CV_ARM64_X0 + 26: return "x26";
240 case CV_ARM64_X0 + 27: return "x27";
241 case CV_ARM64_X0 + 28: return "x28";
242 case CV_ARM64_X0 + 29: return "x29";
243 case CV_ARM64_X0 + 30: return "x30";
245 case CV_ARM64_SP: return "sp";
246 case CV_ARM64_PC: return "pc";
247 case CV_ARM64_PSTATE: return "cpsr";
249 FIXME("Unknown register %x\n", regno);
250 return NULL;
253 static BOOL arm64_fetch_minidump_thread(struct dump_context* dc, unsigned index, unsigned flags, const CONTEXT* ctx)
255 if (ctx->ContextFlags && (flags & ThreadWriteInstructionWindow))
257 /* FIXME: crop values across module boundaries, */
258 #ifdef __aarch64__
259 ULONG base = ctx->Pc <= 0x80 ? 0 : ctx->Pc - 0x80;
260 minidump_add_memory_block(dc, base, ctx->Pc + 0x80 - base, 0);
261 #endif
264 return TRUE;
267 static BOOL arm64_fetch_minidump_module(struct dump_context* dc, unsigned index, unsigned flags)
269 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
270 * function table minidump stream
272 return FALSE;
275 DECLSPEC_HIDDEN struct cpu cpu_arm64 = {
276 IMAGE_FILE_MACHINE_ARM64,
278 CV_ARM64_X0 + 29,
279 arm64_get_addr,
280 arm64_stack_walk,
281 NULL,
282 arm64_map_dwarf_register,
283 arm64_fetch_context_reg,
284 arm64_fetch_regname,
285 arm64_fetch_minidump_thread,
286 arm64_fetch_minidump_module,