Skip to content

Commit

Permalink
AArch64 macOS: Implement omrsignal_context.c
Browse files Browse the repository at this point in the history
This commit implements omrsignal_context.c for AArch64 macOS.

Signed-off-by: KONNO Kazuhiro <konno@jp.ibm.com>
  • Loading branch information
knn-k committed Oct 29, 2021
1 parent a623525 commit 229496b
Showing 1 changed file with 82 additions and 7 deletions.
89 changes: 82 additions & 7 deletions port/osx/omrsignal_context.c
Expand Up @@ -166,8 +166,27 @@ infoForFPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#elif defined(OMR_ARCH_AARCH64) /* defined(OMR_ARCH_X86) */
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_ARM_NEON_STATE64 *neonState = &(*context)->__ns;

static const char *fpr_names[] = {
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
"v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
};

if ((0 <= index) && (index < (sizeof(fpr_names) / sizeof(fpr_names[0])))) {
*name = fpr_names[index];
*value = &neonState->__v[index];
return OMRPORT_SIG_VALUE_FLOAT_64;
} else {
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#error Unsupported processor
#endif /* defined(OMR_ARCH_X86) */
}

Expand Down Expand Up @@ -253,8 +272,41 @@ infoForGPR(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#elif defined(OMR_ARCH_AARCH64) /* defined(OMR_ARCH_X86) */
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_ARM_THREAD_STATE64 *threadState = &(*context)->__ss;

static const char *gpr_names[] = {
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
"x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
"x24", "x25", "x26", "x27", "x28"
};

if ((0 <= index) && (index < (sizeof(gpr_names) / sizeof(gpr_names[0])))) {
*name = gpr_names[index];
*value = &threadState->__x[index];
return OMRPORT_SIG_VALUE_ADDRESS;
}
switch (index) {
case 29:
*name = "x29(FP)";
*value = &threadState->__fp;
return OMRPORT_SIG_VALUE_ADDRESS;
case 30:
*name = "x30(LR)";
*value = &threadState->__lr;
return OMRPORT_SIG_VALUE_ADDRESS;
case 31:
*name = "x31(SP)";
*value = &threadState->__sp;
return OMRPORT_SIG_VALUE_ADDRESS;
default:
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#error Unsupported processor
#endif /* defined(OMR_ARCH_X86) */
}

Expand Down Expand Up @@ -319,18 +371,41 @@ infoForControl(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int3
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#elif defined(OMR_ARCH_AARCH64) /* defined(OMR_ARCH_X86) */
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
_STRUCT_ARM_THREAD_STATE64 *threadState = &(*context)->__ss;

switch (index) {
case OMRPORT_SIG_CONTROL_PC:
case 0:
*name = "PC";
*value = &threadState->__pc;
return OMRPORT_SIG_VALUE_ADDRESS;
case OMRPORT_SIG_CONTROL_SP:
case 1:
*name = "SP";
*value = &threadState->__sp;
return OMRPORT_SIG_VALUE_ADDRESS;
default:
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#error Unsupported processor
#endif /* defined(OMR_ARCH_X86) */
}

uint32_t
infoForModule(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32_t index, const char **name, void **value)
{
#if defined(OMR_ARCH_X86)
#if defined(OMR_ARCH_X86) || defined(OMR_ARCH_AARCH64)
Dl_info *dl_info = &(info->platformSignalInfo.dl_info);
mcontext_t *context = (mcontext_t *)&info->platformSignalInfo.context->uc_mcontext;
#if defined(OMR_ARCH_X86)
int dl_result = dladdr((void *)(*context)->__ss.__rip, dl_info);
#else /* defined(OMR_ARCH_X86) */
int dl_result = dladdr((void *)(*context)->__ss.__pc, dl_info);
#endif /* defined(OMR_ARCH_X86) */

switch (index) {
case OMRPORT_SIG_MODULE_NAME:
Expand Down Expand Up @@ -368,7 +443,7 @@ infoForModule(struct OMRPortLibrary *portLibrary, OMRUnixSignalInfo *info, int32
*name = "";
return OMRPORT_SIG_VALUE_UNDEFINED;
}
#else /* defined(OMR_ARCH_X86) */
return OMRPORT_SIG_VALUE_UNDEFINED;
#endif /* defined(OMR_ARCH_X86) */
#else /* defined(OMR_ARCH_X86) || defined(OMR_ARCH_AARCH64) */
#error Unsupported processor
#endif /* defined(OMR_ARCH_X86) || defined(OMR_ARCH_AARCH64) */
}

0 comments on commit 229496b

Please sign in to comment.