2 * mono-context.h: plat independent machine state definitions
5 * Copyright (c) 2011 Novell, Inc (http://www.novell.com)
9 #ifndef __MONO_MONO_CONTEXT_H__
10 #define __MONO_MONO_CONTEXT_H__
12 #include "mono-compiler.h"
13 #include "mono-sigcontext.h"
14 #include "mono-machine.h"
20 #if defined (HOST_WATCHOS) || defined (HOST_APPLETVOS)
21 #include <libunwind.h>
25 * General notes about mono-context.
26 * Each arch defines a MonoContext struct with all GPR regs + IP/PC.
27 * IP/PC should be the last element of the struct (this is a mild sgen constraint we could drop if needed)
28 * Macros to get/set BP, SP and IP are defined too.
29 * MONO_CONTEXT_GET_CURRENT captures the current context as close as possible. One reg might be clobbered
30 * to hold the address of the target MonoContext. It will be a caller save one, so should not be a problem.
32 #if (defined(__i386__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_X86))
34 /*HACK, move this to an eventual mono-signal.c*/
35 #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \
36 defined(__FreeBSD__) || defined(__OpenBSD__)
38 #define MONO_SIGNAL_USE_SIGACTION 1
42 #if defined(__native_client__)
43 #undef MONO_SIGNAL_USE_SIGACTION
47 /* sigcontext surrogate */
61 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
62 # define SC_EAX sc_eax
63 # define SC_EBX sc_ebx
64 # define SC_ECX sc_ecx
65 # define SC_EDX sc_edx
66 # define SC_EBP sc_ebp
67 # define SC_EIP sc_eip
68 # define SC_ESP sc_esp
69 # define SC_EDI sc_edi
70 # define SC_ESI sc_esi
71 #elif defined(__HAIKU__)
72 # define SC_EAX regs.eax
73 # define SC_EBX regs._reserved_2[2]
74 # define SC_ECX regs.ecx
75 # define SC_EDX regs.edx
76 # define SC_EBP regs.ebp
77 # define SC_EIP regs.eip
78 # define SC_ESP regs.esp
79 # define SC_EDI regs._reserved_2[0]
80 # define SC_ESI regs._reserved_2[1]
105 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (mgreg_t)(ip); } while (0);
106 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (mgreg_t)(bp); } while (0);
107 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->esp = (mgreg_t)(sp); } while (0);
109 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
110 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
111 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
113 /*We set EAX to zero since we are clobering it anyway*/
115 #define MONO_CONTEXT_GET_CURRENT(ctx) do { \
116 void *_ptr = &(ctx); \
118 __asm mov eax, _ptr \
119 __asm mov [eax+0x00], eax \
120 __asm mov [eax+0x04], ebx \
121 __asm mov [eax+0x08], ecx \
122 __asm mov [eax+0x0c], edx \
123 __asm mov [eax+0x10], ebp \
124 __asm mov [eax+0x14], esp \
125 __asm mov [eax+0x18], esi \
126 __asm mov [eax+0x1c], edi \
127 __asm call __mono_context_get_ip \
128 __asm __mono_context_get_ip: \
129 __asm pop dword ptr [eax+0x20] \
133 #define MONO_CONTEXT_GET_CURRENT(ctx) \
134 __asm__ __volatile__( \
135 "movl $0x0, 0x00(%0)\n" \
136 "mov %%ebx, 0x04(%0)\n" \
137 "mov %%ecx, 0x08(%0)\n" \
138 "mov %%edx, 0x0c(%0)\n" \
139 "mov %%ebp, 0x10(%0)\n" \
140 "mov %%esp, 0x14(%0)\n" \
141 "mov %%esi, 0x18(%0)\n" \
142 "mov %%edi, 0x1c(%0)\n" \
144 "1: pop 0x20(%0)\n" \
150 #define MONO_ARCH_HAS_MONO_CONTEXT 1
152 #elif (defined(__x86_64__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_AMD64)) /* defined(__i386__) */
154 #include <mono/arch/amd64/amd64-codegen.h>
156 #if !defined( HOST_WIN32 ) && !defined(__native_client__) && !defined(__native_client_codegen__)
158 #ifdef HAVE_SIGACTION
159 #define MONO_SIGNAL_USE_SIGACTION 1
165 mgreg_t gregs [AMD64_NREG];
166 double fregs [AMD64_XMM_NREG];
169 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->gregs [AMD64_RIP] = (mgreg_t)(ip); } while (0);
170 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->gregs [AMD64_RBP] = (mgreg_t)(bp); } while (0);
171 #define MONO_CONTEXT_SET_SP(ctx,esp) do { (ctx)->gregs [AMD64_RSP] = (mgreg_t)(esp); } while (0);
173 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->gregs [AMD64_RIP]))
174 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->gregs [AMD64_RBP]))
175 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->gregs [AMD64_RSP]))
177 #if defined (HOST_WIN32) && !defined(__GNUC__)
178 /* msvc doesn't support inline assembly, so have to use a separate .asm file */
179 extern void mono_context_get_current (void *);
180 #define MONO_CONTEXT_GET_CURRENT(ctx) do { mono_context_get_current((void*)&(ctx)); } while (0)
182 #elif defined(__native_client__)
183 #define MONO_CONTEXT_GET_CURRENT(ctx) \
184 __asm__ __volatile__( \
185 "movq $0x0, %%nacl:0x00(%%r15, %0, 1)\n" \
186 "movq %%rcx, %%nacl:0x08(%%r15, %0, 1)\n" \
187 "movq %%rdx, %%nacl:0x10(%%r15, %0, 1)\n" \
188 "movq %%rbx, %%nacl:0x18(%%r15, %0, 1)\n" \
189 "movq %%rsp, %%nacl:0x20(%%r15, %0, 1)\n" \
190 "movq %%rbp, %%nacl:0x28(%%r15, %0, 1)\n" \
191 "movq %%rsi, %%nacl:0x30(%%r15, %0, 1)\n" \
192 "movq %%rdi, %%nacl:0x38(%%r15, %0, 1)\n" \
193 "movq %%r8, %%nacl:0x40(%%r15, %0, 1)\n" \
194 "movq %%r9, %%nacl:0x48(%%r15, %0, 1)\n" \
195 "movq %%r10, %%nacl:0x50(%%r15, %0, 1)\n" \
196 "movq %%r11, %%nacl:0x58(%%r15, %0, 1)\n" \
197 "movq %%r12, %%nacl:0x60(%%r15, %0, 1)\n" \
198 "movq %%r13, %%nacl:0x68(%%r15, %0, 1)\n" \
199 "movq %%r14, %%nacl:0x70(%%r15, %0, 1)\n" \
200 "movq %%r15, %%nacl:0x78(%%r15, %0, 1)\n" \
201 "leaq (%%rip), %%rdx\n" \
202 "movq %%rdx, %%nacl:0x80(%%r15, %0, 1)\n" \
204 : "a" ((int64_t)&(ctx)) \
208 #define MONO_CONTEXT_GET_CURRENT(ctx) \
209 __asm__ __volatile__( \
210 "movq $0x0, 0x00(%0)\n" \
211 "movq %%rcx, 0x08(%0)\n" \
212 "movq %%rdx, 0x10(%0)\n" \
213 "movq %%rbx, 0x18(%0)\n" \
214 "movq %%rsp, 0x20(%0)\n" \
215 "movq %%rbp, 0x28(%0)\n" \
216 "movq %%rsi, 0x30(%0)\n" \
217 "movq %%rdi, 0x38(%0)\n" \
218 "movq %%r8, 0x40(%0)\n" \
219 "movq %%r9, 0x48(%0)\n" \
220 "movq %%r10, 0x50(%0)\n" \
221 "movq %%r11, 0x58(%0)\n" \
222 "movq %%r12, 0x60(%0)\n" \
223 "movq %%r13, 0x68(%0)\n" \
224 "movq %%r14, 0x70(%0)\n" \
225 "movq %%r15, 0x78(%0)\n" \
226 /* "leaq (%%rip), %%rdx\n" is not understood by icc */ \
227 ".byte 0x48, 0x8d, 0x15, 0x00, 0x00, 0x00, 0x00\n" \
228 "movq %%rdx, 0x80(%0)\n" \
234 #define MONO_ARCH_HAS_MONO_CONTEXT 1
236 #elif (defined(__arm__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_ARM)) /* defined(__x86_64__) */
238 #include <mono/arch/arm/arm-codegen.h>
247 /* we have the stack pointer, not the base pointer in sigcontext */
248 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->pc = (mgreg_t)ip; } while (0);
249 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->regs [ARMREG_FP] = (mgreg_t)bp; } while (0);
250 #define MONO_CONTEXT_SET_SP(ctx,bp) do { (ctx)->regs [ARMREG_SP] = (mgreg_t)bp; } while (0);
252 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->pc))
253 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ARMREG_FP]))
254 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->regs [ARMREG_SP]))
256 #if defined(HOST_WATCHOS)
258 #define MONO_CONTEXT_GET_CURRENT(ctx) do { \
259 unw_context_t uctx; \
262 g_assert (unw_getcontext (&uctx) == 0); \
263 g_assert (unw_init_local (&c, &uctx) == 0); \
264 for (int reg = 0; reg < 13; ++reg) { \
265 unw_get_reg (&c, (unw_regnum_t) UNW_ARM_R0 + reg, &data); \
266 ctx.regs[reg] = data; \
268 unw_get_reg (&c, UNW_ARM_SP, &data); \
269 ctx.regs[ARMREG_SP] = data; \
270 unw_get_reg (&c, UNW_ARM_LR, &data); \
271 ctx.regs[ARMREG_LR] = data; \
272 unw_get_reg (&c, UNW_ARM_IP, &data); \
273 ctx.regs[ARMREG_PC] = data; \
274 ctx.pc = ctx.regs[ARMREG_PC]; \
275 for (int reg = 0; reg < 16; ++reg) { \
276 unw_get_reg (&c, (unw_regnum_t) UNW_ARM_D0 + reg, &data); \
277 ctx.fregs[reg] = data; \
283 #define MONO_CONTEXT_GET_CURRENT(ctx) do { \
284 __asm__ __volatile__( \
288 "ldr r1, [sp, #4]\n" \
290 "ldr r1, [sp, #0]\n" \
292 "stmia r0!, {r2-r12}\n" \
303 ctx.pc = ctx.regs [15]; \
308 #define MONO_ARCH_HAS_MONO_CONTEXT 1
310 #elif (defined(__aarch64__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_ARM64))
312 #include <mono/arch/arm64/arm64-codegen.h>
320 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->pc = (mgreg_t)ip; } while (0)
321 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->regs [ARMREG_FP] = (mgreg_t)bp; } while (0);
322 #define MONO_CONTEXT_SET_SP(ctx,bp) do { (ctx)->regs [ARMREG_SP] = (mgreg_t)bp; } while (0);
324 #define MONO_CONTEXT_GET_IP(ctx) (gpointer)((ctx)->pc)
325 #define MONO_CONTEXT_GET_BP(ctx) (gpointer)((ctx)->regs [ARMREG_FP])
326 #define MONO_CONTEXT_GET_SP(ctx) (gpointer)((ctx)->regs [ARMREG_SP])
328 #if defined (HOST_APPLETVOS)
330 #define MONO_CONTEXT_GET_CURRENT(ctx) do { \
331 fprintf (stderr, "MONO_CONTEXT_GET_CURRENT: Not implemented"); \
332 g_error ("MONO_CONTEXT_GET_CURRENT: Not implemented"); \
337 #define MONO_CONTEXT_GET_CURRENT(ctx) do { \
338 __asm__ __volatile__( \
340 "stp x0, x1, [x16], #16\n" \
341 "stp x2, x3, [x16], #16\n" \
342 "stp x4, x5, [x16], #16\n" \
343 "stp x6, x7, [x16], #16\n" \
344 "stp x8, x9, [x16], #16\n" \
345 "stp x10, x11, [x16], #16\n" \
346 "stp x12, x13, [x16], #16\n" \
347 "stp x14, x15, [x16], #16\n" \
348 "stp xzr, x17, [x16], #16\n" \
349 "stp x18, x19, [x16], #16\n" \
350 "stp x20, x21, [x16], #16\n" \
351 "stp x22, x23, [x16], #16\n" \
352 "stp x24, x25, [x16], #16\n" \
353 "stp x26, x27, [x16], #16\n" \
354 "stp x28, x29, [x16], #16\n" \
355 "stp x30, xzr, [x16]\n" \
357 "str x30, [x16, #8]\n" \
362 __asm__ __volatile__( \
373 #define MONO_ARCH_HAS_MONO_CONTEXT 1
375 #elif defined(__mono_ppc__) /* defined(__arm__) */
377 /* we define our own structure and we'll copy the data
378 * from sigcontext/ucontext/mach when we need it.
379 * This also makes us save stack space and time when copying
380 * We might also want to add an additional field to propagate
381 * the original context from the signal handler.
383 #ifdef __mono_ppc64__
392 /* we have the stack pointer, not the base pointer in sigcontext */
393 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (gulong)ip; } while (0);
394 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (gulong)bp; } while (0);
395 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->sc_sp = (gulong)sp; } while (0);
397 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
398 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ppc_r31-13]))
399 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
401 #define MONO_CONTEXT_GET_CURRENT(ctx) \
402 __asm__ __volatile__( \
405 "std 0, 8*0+16(%0)\n" \
406 "std 1, 8*1+16(%0)\n" \
407 "std 2, 8*2+16(%0)\n" \
408 "std 3, 8*3+16(%0)\n" \
409 "std 4, 8*4+16(%0)\n" \
410 "std 5, 8*5+16(%0)\n" \
411 "std 6, 8*6+16(%0)\n" \
412 "std 7, 8*7+16(%0)\n" \
413 "std 8, 8*8+16(%0)\n" \
414 "std 9, 8*9+16(%0)\n" \
415 "std 10, 8*10+16(%0)\n" \
416 "std 11, 8*11+16(%0)\n" \
417 "std 12, 8*12+16(%0)\n" \
418 "std 13, 8*13+16(%0)\n" \
419 "std 14, 8*14+16(%0)\n" \
420 "std 15, 8*15+16(%0)\n" \
421 "std 16, 8*16+16(%0)\n" \
422 "std 17, 8*17+16(%0)\n" \
423 "std 18, 8*18+16(%0)\n" \
424 "std 19, 8*19+16(%0)\n" \
425 "std 20, 8*20+16(%0)\n" \
426 "std 21, 8*21+16(%0)\n" \
427 "std 22, 8*22+16(%0)\n" \
428 "std 23, 8*23+16(%0)\n" \
429 "std 24, 8*24+16(%0)\n" \
430 "std 25, 8*25+16(%0)\n" \
431 "std 26, 8*26+16(%0)\n" \
432 "std 27, 8*27+16(%0)\n" \
433 "std 28, 8*28+16(%0)\n" \
434 "std 29, 8*29+16(%0)\n" \
435 "std 30, 8*30+16(%0)\n" \
436 "std 31, 8*31+16(%0)\n" \
437 "stfd 0, 8*0+8*32+16(%0)\n" \
438 "stfd 1, 8*1+8*32+16(%0)\n" \
439 "stfd 2, 8*2+8*32+16(%0)\n" \
440 "stfd 3, 8*3+8*32+16(%0)\n" \
441 "stfd 4, 8*4+8*32+16(%0)\n" \
442 "stfd 5, 8*5+8*32+16(%0)\n" \
443 "stfd 6, 8*6+8*32+16(%0)\n" \
444 "stfd 7, 8*7+8*32+16(%0)\n" \
445 "stfd 8, 8*8+8*32+16(%0)\n" \
446 "stfd 9, 8*9+8*32+16(%0)\n" \
447 "stfd 10, 8*10+8*32+16(%0)\n" \
448 "stfd 11, 8*11+8*32+16(%0)\n" \
449 "stfd 12, 8*12+8*32+16(%0)\n" \
450 "stfd 13, 8*13+8*32+16(%0)\n" \
451 "stfd 14, 8*14+8*32+16(%0)\n" \
452 "stfd 15, 8*15+8*32+16(%0)\n" \
453 "stfd 16, 8*16+8*32+16(%0)\n" \
454 "stfd 17, 8*17+8*32+16(%0)\n" \
455 "stfd 18, 8*18+8*32+16(%0)\n" \
456 "stfd 19, 8*19+8*32+16(%0)\n" \
457 "stfd 20, 8*20+8*32+16(%0)\n" \
458 "stfd 21, 8*21+8*32+16(%0)\n" \
459 "stfd 22, 8*22+8*32+16(%0)\n" \
460 "stfd 23, 8*23+8*32+16(%0)\n" \
461 "stfd 24, 8*24+8*32+16(%0)\n" \
462 "stfd 25, 8*25+8*32+16(%0)\n" \
463 "stfd 26, 8*26+8*32+16(%0)\n" \
464 "stfd 27, 8*27+8*32+16(%0)\n" \
465 "stfd 28, 8*28+8*32+16(%0)\n" \
466 "stfd 29, 8*29+8*32+16(%0)\n" \
467 "stfd 30, 8*30+8*32+16(%0)\n" \
468 "stfd 31, 8*31+8*32+16(%0)\n" \
473 #define MONO_ARCH_HAS_MONO_CONTEXT 1
480 mgreg_t regs [19]; /*FIXME, this must be changed to 32 for sgen*/
484 /* we have the stack pointer, not the base pointer in sigcontext */
485 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (gulong)ip; } while (0);
486 /* FIXME: should be called SET_SP */
487 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (gulong)bp; } while (0);
488 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->sc_sp = (gulong)sp; } while (0);
490 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
491 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ppc_r31-13]))
492 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
495 #elif defined(__sparc__) || defined(sparc) /* defined(__mono_ppc__) */
497 typedef struct MonoContext {
503 #define MONO_CONTEXT_SET_IP(ctx,eip) do { (ctx)->ip = (gpointer)(eip); } while (0);
504 #define MONO_CONTEXT_SET_BP(ctx,ebp) do { (ctx)->fp = (gpointer*)(ebp); } while (0);
505 #define MONO_CONTEXT_SET_SP(ctx,esp) do { (ctx)->sp = (gpointer*)(esp); } while (0);
507 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->ip))
508 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->fp))
509 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sp))
511 #elif defined(__ia64__) /*defined(__sparc__) || defined(sparc) */
513 #ifndef UNW_LOCAL_ONLY
515 #define UNW_LOCAL_ONLY
516 #include <libunwind.h>
520 typedef struct MonoContext {
522 /* Whenever the ip in 'cursor' points to the ip where the exception happened */
523 /* This is true for the initial context for exceptions thrown from signal handlers */
527 /*XXX SET_BP is missing*/
528 #define MONO_CONTEXT_SET_IP(ctx,eip) do { int err = unw_set_reg (&(ctx)->cursor, UNW_IA64_IP, (unw_word_t)(eip)); g_assert (err == 0); } while (0)
529 #define MONO_CONTEXT_SET_SP(ctx,esp) do { int err = unw_set_reg (&(ctx)->cursor, UNW_IA64_SP, (unw_word_t)(esp)); g_assert (err == 0); } while (0)
531 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)(mono_ia64_context_get_ip ((ctx))))
532 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)(mono_ia64_context_get_fp ((ctx))))
533 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)(mono_ia64_context_get_sp ((ctx))))
535 static inline unw_word_t
536 mono_ia64_context_get_ip (MonoContext *ctx)
541 err = unw_get_reg (&ctx->cursor, UNW_IA64_IP, &ip);
544 if (ctx->precise_ip) {
547 /* Subtrack 1 so ip points into the actual instruction */
552 static inline unw_word_t
553 mono_ia64_context_get_sp (MonoContext *ctx)
558 err = unw_get_reg (&ctx->cursor, UNW_IA64_SP, &sp);
564 static inline unw_word_t
565 mono_ia64_context_get_fp (MonoContext *ctx)
567 unw_cursor_t new_cursor;
574 err = unw_get_reg (&ctx->cursor, UNW_IA64_SP, &sp);
577 err = unw_get_reg (&ctx->cursor, UNW_IA64_IP, &ip);
581 /* fp is the SP of the parent frame */
582 new_cursor = ctx->cursor;
584 err = unw_step (&new_cursor);
587 err = unw_get_reg (&new_cursor, UNW_IA64_SP, &fp);
593 #elif ((defined(__mips__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_MIPS))) && SIZEOF_REGISTER == 4 /* defined(__ia64__) */
595 #include <mono/arch/mips/mips-codegen.h>
599 mgreg_t sc_regs [32];
600 gfloat sc_fpregs [32];
603 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_pc = (mgreg_t)(ip); } while (0);
604 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_regs[mips_fp] = (mgreg_t)(bp); } while (0);
605 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->sc_regs[mips_sp] = (mgreg_t)(sp); } while (0);
607 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_pc))
608 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->sc_regs[mips_fp]))
609 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_regs[mips_sp]))
611 #define MONO_CONTEXT_GET_CURRENT(ctx) \
612 __asm__ __volatile__( \
623 "sw $10,40(%0)\n\t" \
624 "sw $11,44(%0)\n\t" \
625 "sw $12,48(%0)\n\t" \
626 "sw $13,52(%0)\n\t" \
627 "sw $14,56(%0)\n\t" \
628 "sw $15,60(%0)\n\t" \
629 "sw $16,64(%0)\n\t" \
630 "sw $17,68(%0)\n\t" \
631 "sw $18,72(%0)\n\t" \
632 "sw $19,76(%0)\n\t" \
633 "sw $20,80(%0)\n\t" \
634 "sw $21,84(%0)\n\t" \
635 "sw $22,88(%0)\n\t" \
636 "sw $23,92(%0)\n\t" \
637 "sw $24,96(%0)\n\t" \
638 "sw $25,100(%0)\n\t" \
639 "sw $26,104(%0)\n\t" \
640 "sw $27,108(%0)\n\t" \
641 "sw $28,112(%0)\n\t" \
642 "sw $29,116(%0)\n\t" \
643 "sw $30,120(%0)\n\t" \
644 "sw $31,124(%0)\n\t" \
645 : : "r" (&(ctx).sc_regs [0]) \
649 #elif defined(__s390x__)
651 #define MONO_ARCH_HAS_MONO_CONTEXT 1
653 typedef struct ucontext MonoContext;
655 #define MONO_CONTEXT_SET_IP(ctx,ip) \
657 (ctx)->uc_mcontext.gregs[14] = (unsigned long)ip; \
658 (ctx)->uc_mcontext.psw.addr = (unsigned long)ip; \
661 #define MONO_CONTEXT_SET_SP(ctx,bp) MONO_CONTEXT_SET_BP((ctx),(bp))
662 #define MONO_CONTEXT_SET_BP(ctx,bp) \
664 (ctx)->uc_mcontext.gregs[15] = (unsigned long)bp; \
665 (ctx)->uc_stack.ss_sp = (void*)bp; \
668 #define MONO_CONTEXT_GET_IP(ctx) (gpointer) (ctx)->uc_mcontext.psw.addr
669 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->uc_mcontext.gregs[15]))
670 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->uc_mcontext.gregs[11]))
672 #define MONO_CONTEXT_GET_CURRENT(ctx) \
673 __asm__ __volatile__( \
674 "stmg %%r0,%%r15,0(%0)\n" \
675 : : "r" (&(ctx).uc_mcontext.gregs[0]) \
681 #error "Implement mono-context for the current arch"
686 * The naming is misleading, the SIGCTX argument should be the platform's context
687 * structure (ucontext_c on posix, CONTEXT on windows).
689 void mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx);
692 * This will not completely initialize SIGCTX since MonoContext contains less
693 * information that the system context. The caller should obtain a SIGCTX from
694 * the system, and use this function to override the parts of it which are
695 * also in MonoContext.
697 void mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx);
699 #endif /* __MONO_MONO_CONTEXT_H__ */