[sdks] Bump Android NDK, build tools and platform tools versions
[mono-project.git] / mono / utils / mach-support-arm64.c
blob2cf906679dc1ba516148127482da685c4cd9f262
1 /**
2 * \file
3 * mach support for ARM
5 * Authors:
6 * Geoff Norton (gnorton@novell.com)
7 * Rodrigo Kumpera (kumpera@gmail.com)
9 * (C) 2010 Novell, Inc.
10 * (C) 2011 Xamarin, Inc.
13 #include <config.h>
15 #if defined(__MACH__)
16 #include <stdint.h>
17 #include <glib.h>
18 #include <pthread.h>
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
26 #endif
28 int
29 mono_mach_arch_get_mcontext_size ()
31 return sizeof (struct __darwin_mcontext64);
34 void
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;
45 void
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;
56 void
57 mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state_t fpstate, MonoContext *context)
59 int i;
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];
75 int
76 mono_mach_arch_get_thread_state_size ()
78 return sizeof (arm_unified_thread_state_t);
81 int
82 mono_mach_arch_get_thread_fpstate_size ()
84 return sizeof (arm_neon_state64_t);
87 kern_return_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");
92 #else
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;
95 kern_return_t ret;
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)
100 return ret;
102 *fpcount = ARM_NEON_STATE64_COUNT;
103 ret = thread_get_state (thread, ARM_NEON_STATE64, (thread_state_t) arch_fpstate, fpcount);
104 return ret;
105 #endif
108 kern_return_t
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");
113 #else
114 kern_return_t ret;
115 ret = thread_set_state (thread, ARM_UNIFIED_THREAD_STATE, state, count);
116 if (ret != KERN_SUCCESS)
117 return ret;
118 ret = thread_set_state (thread, ARM_NEON_STATE64, fpstate, fpcount);
119 return ret;
120 #endif
123 #endif