6 * Geoff Norton (gnorton@novell.com)
7 * Rodrigo Kumpera (kumpera@gmail.com)
9 * (C) 2010 Novell, Inc.
10 * (C) 2011 Xamarin, Inc.
19 #include "utils/mono-sigcontext.h"
20 #include "utils/mono-compiler.h"
21 #include "mach-support.h"
23 /* _mcontext.h now defines __darwin_mcontext32, not __darwin_mcontext, starting with Xcode 5.1 */
24 #ifdef _STRUCT_MCONTEXT32
25 #define __darwin_mcontext __darwin_mcontext32
29 mono_mach_arch_get_mcontext_size ()
31 return sizeof (struct __darwin_mcontext64
);
35 mono_mach_arch_thread_states_to_mcontext (thread_state_t state
, thread_state_t fpstate
, void *context
)
37 arm_unified_thread_state_t
*arch_state
= (arm_unified_thread_state_t
*) state
;
38 arm_neon_state64_t
*arch_fpstate
= (arm_neon_state64_t
*) fpstate
;
39 struct __darwin_mcontext64
*ctx
= (struct __darwin_mcontext64
*) context
;
41 ctx
->__ss
= arch_state
->ts_64
;
42 ctx
->__ns
= *arch_fpstate
;
46 mono_mach_arch_mcontext_to_thread_states (void *context
, thread_state_t state
, thread_state_t fpstate
)
48 arm_unified_thread_state_t
*arch_state
= (arm_unified_thread_state_t
*) state
;
49 arm_neon_state64_t
*arch_fpstate
= (arm_neon_state64_t
*) fpstate
;
50 struct __darwin_mcontext64
*ctx
= (struct __darwin_mcontext64
*) context
;
52 arch_state
->ts_64
= ctx
->__ss
;
53 *arch_fpstate
= ctx
->__ns
;
57 mono_mach_arch_thread_states_to_mono_context (thread_state_t state
, thread_state_t fpstate
, MonoContext
*context
)
60 arm_unified_thread_state_t
*arch_state
= (arm_unified_thread_state_t
*) state
;
61 arm_neon_state64_t
*arch_fpstate
= (arm_neon_state64_t
*) fpstate
;
63 for (i
= 0; i
< 29; ++i
)
64 context
->regs
[i
] = arch_state
->ts_64
.__x
[i
];
66 context
->regs
[ARMREG_R29
] = arch_state
->ts_64
.__fp
;
67 context
->regs
[ARMREG_R30
] = arch_state
->ts_64
.__lr
;
68 context
->regs
[ARMREG_SP
] = arch_state
->ts_64
.__sp
;
69 context
->pc
= arch_state
->ts_64
.__pc
;
71 for (i
= 0; i
< 32; ++i
)
72 context
->fregs
[i
] = arch_fpstate
->__v
[i
];
76 mono_mach_arch_get_thread_state_size ()
78 return sizeof (arm_unified_thread_state_t
);
82 mono_mach_arch_get_thread_fpstate_size ()
84 return sizeof (arm_neon_state64_t
);
88 mono_mach_arch_get_thread_states (thread_port_t thread
, thread_state_t state
, mach_msg_type_number_t
*count
, thread_state_t fpstate
, mach_msg_type_number_t
*fpcount
)
90 #if defined(HOST_WATCHOS)
91 g_error ("thread_get_state() is not supported by this platform");
93 arm_unified_thread_state_t
*arch_state
= (arm_unified_thread_state_t
*) state
;
94 arm_neon_state64_t
*arch_fpstate
= (arm_neon_state64_t
*) fpstate
;
97 *count
= ARM_UNIFIED_THREAD_STATE_COUNT
;
98 ret
= thread_get_state (thread
, ARM_UNIFIED_THREAD_STATE
, (thread_state_t
) arch_state
, count
);
99 if (ret
!= KERN_SUCCESS
)
102 *fpcount
= ARM_NEON_STATE64_COUNT
;
103 ret
= thread_get_state (thread
, ARM_NEON_STATE64
, (thread_state_t
) arch_fpstate
, fpcount
);
109 mono_mach_arch_set_thread_states (thread_port_t thread
, thread_state_t state
, mach_msg_type_number_t count
, thread_state_t fpstate
, mach_msg_type_number_t fpcount
)
111 #if defined(HOST_WATCHOS)
112 g_error ("thread_set_state() is not supported by this platform");
115 ret
= thread_set_state (thread
, ARM_UNIFIED_THREAD_STATE
, state
, count
);
116 if (ret
!= KERN_SUCCESS
)
118 ret
= thread_set_state (thread
, ARM_NEON_STATE64
, fpstate
, fpcount
);