[arm64] Scan simd registers on apple
[mono.git] / mono / utils / mach-support-arm64.c
index 5033eb19d66807abf1b506ce51700085d5858517..33c076974114e42346192fd12c7ed6503408e3d5 100644 (file)
@@ -70,18 +70,22 @@ void
 mono_mach_arch_thread_states_to_mcontext (thread_state_t state, thread_state_t fpstate, void *context)
 {
        arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state;
+       arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate;
        struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context;
 
        ctx->__ss = arch_state->ts_64;
+       ctx->__ns = *arch_fpstate;
 }
 
 void
 mono_mach_arch_mcontext_to_thread_states (void *context, thread_state_t state, thread_state_t fpstate)
 {
        arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state;
+       arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate;
        struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context;
 
        arch_state->ts_64 = ctx->__ss;
+       *arch_fpstate = ctx->__ns;
 }
 
 void
@@ -89,6 +93,8 @@ mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state
 {
        int i;
        arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state;
+       arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate;
+
        for (i = 0; i < 29; ++i)
                context->regs [i] = arch_state->ts_64.__x [i];
 
@@ -96,6 +102,9 @@ mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state
        context->regs [ARMREG_R30] = arch_state->ts_64.__lr;
        context->regs [ARMREG_SP] = arch_state->ts_64.__sp;
        context->pc = arch_state->ts_64.__pc;
+
+       for (i = 0; i < 32; ++i)
+               context->fregs [i] = arch_fpstate->__v [i];
 }
 
 int
@@ -114,18 +123,28 @@ kern_return_t
 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)
 {
        arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state;
+       arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t *) fpstate;
        kern_return_t ret;
 
        *count = ARM_UNIFIED_THREAD_STATE_COUNT;
-
        ret = thread_get_state (thread, ARM_UNIFIED_THREAD_STATE, (thread_state_t) arch_state, count);
+       if (ret != KERN_SUCCESS)
+               return ret;
+
+       *fpcount = ARM_NEON_STATE64_COUNT;
+       ret = thread_get_state (thread, ARM_NEON_STATE64, (thread_state_t) arch_fpstate, fpcount);
        return ret;
 }
 
 kern_return_t
 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)
 {
-       return thread_set_state (thread, ARM_UNIFIED_THREAD_STATE, state, count);
+       kern_return_t ret;
+       ret = thread_set_state (thread, ARM_UNIFIED_THREAD_STATE, state, count);
+       if (ret != KERN_SUCCESS)
+               return ret;
+       ret = thread_set_state (thread, ARM_NEON_STATE64, fpstate, fpcount);
+       return ret;
 }
 
 void *