- case ARM_DEBUG_STATE:{
- arm_debug_state_t *state;
- arm_debug_state_t *thread_state;
- boolean_t enabled = FALSE;
- unsigned int i;
-
- if (count < ARM_DEBUG_STATE_COUNT)
- return (KERN_INVALID_ARGUMENT);
-
- state = (arm_debug_state_t *) tstate;
- thread_state = find_debug_state(thread);
-
- if (count < ARM_DEBUG_STATE_COUNT)
- return (KERN_INVALID_ARGUMENT);
-
- for (i = 0; i < 16; i++) {
- /* do not allow context IDs to be set */
- if (((state->bcr[i] & ARM_DBGBCR_TYPE_MASK) != ARM_DBGBCR_TYPE_IVA)
- || ((state->bcr[i] & ARM_DBG_CR_LINKED_MASK) != ARM_DBG_CR_LINKED_UNLINKED)
- || ((state->wcr[i] & ARM_DBGBCR_TYPE_MASK) != ARM_DBGBCR_TYPE_IVA)
- || ((state->wcr[i] & ARM_DBG_CR_LINKED_MASK) != ARM_DBG_CR_LINKED_UNLINKED)) {
- return KERN_PROTECTION_FAILURE;
- }
- if ((((state->bcr[i] & ARM_DBG_CR_ENABLE_MASK) == ARM_DBG_CR_ENABLE_ENABLE))
- || ((state->wcr[i] & ARM_DBG_CR_ENABLE_MASK) == ARM_DBG_CR_ENABLE_ENABLE)) {
- enabled = TRUE;
- }
- }
-
- if (!enabled) {
- if (thread_state != NULL)
- {
- void *pTmp = thread->machine.DebugData;
- thread->machine.DebugData = NULL;
- zfree(ads_zone, pTmp);
- }
- }
- else
- {
- if (thread_state == NULL)
- thread_state = zalloc(ads_zone);
-
- for (i = 0; i < 16; i++) {
- /* set appropriate priviledge; mask out unknown bits */
- thread_state->bcr[i] = (state->bcr[i] & (ARM_DBG_CR_ADDRESS_MASK_MASK
- | ARM_DBGBCR_MATCH_MASK
- | ARM_DBG_CR_BYTE_ADDRESS_SELECT_MASK
- | ARM_DBG_CR_ENABLE_MASK))
- | ARM_DBGBCR_TYPE_IVA
- | ARM_DBG_CR_LINKED_UNLINKED
- | ARM_DBG_CR_SECURITY_STATE_BOTH
- | ARM_DBG_CR_MODE_CONTROL_USER;
- thread_state->bvr[i] = state->bvr[i] & ARM_DBG_VR_ADDRESS_MASK;
- thread_state->wcr[i] = (state->wcr[i] & (ARM_DBG_CR_ADDRESS_MASK_MASK
- | ARM_DBGWCR_BYTE_ADDRESS_SELECT_MASK
- | ARM_DBGWCR_ACCESS_CONTROL_MASK
- | ARM_DBG_CR_ENABLE_MASK))
- | ARM_DBG_CR_LINKED_UNLINKED
- | ARM_DBG_CR_SECURITY_STATE_BOTH
- | ARM_DBG_CR_MODE_CONTROL_USER;
- thread_state->wvr[i] = state->wvr[i] & ARM_DBG_VR_ADDRESS_MASK;
- }
-
- if (thread->machine.DebugData == NULL)
- thread->machine.DebugData = thread_state;
- }
-
- if (thread == current_thread()) {
- arm_debug_set(thread_state);
+
+ for (i = 0; i < 16; i++) {
+ /* do not allow context IDs to be set */
+ if (((state->bcr[i] & ARM_DBGBCR_TYPE_MASK) != ARM_DBGBCR_TYPE_IVA)
+ || ((state->bcr[i] & ARM_DBG_CR_LINKED_MASK) != ARM_DBG_CR_LINKED_UNLINKED)
+ || ((state->wcr[i] & ARM_DBGBCR_TYPE_MASK) != ARM_DBGBCR_TYPE_IVA)
+ || ((state->wcr[i] & ARM_DBG_CR_LINKED_MASK) != ARM_DBG_CR_LINKED_UNLINKED)) {
+ return KERN_PROTECTION_FAILURE;
+ }
+ if ((((state->bcr[i] & ARM_DBG_CR_ENABLE_MASK) == ARM_DBG_CR_ENABLE_ENABLE))
+ || ((state->wcr[i] & ARM_DBG_CR_ENABLE_MASK) == ARM_DBG_CR_ENABLE_ENABLE)) {
+ enabled = TRUE;
+ }
+ }
+
+ if (!enabled) {
+ if (thread_state != NULL) {
+ void *pTmp = thread->machine.DebugData;
+ thread->machine.DebugData = NULL;
+ zfree(ads_zone, pTmp);
+ }
+ } else {
+ if (thread_state == NULL) {
+ thread_state = zalloc(ads_zone);
+ }
+
+ for (i = 0; i < 16; i++) {
+ /* set appropriate priviledge; mask out unknown bits */
+ thread_state->bcr[i] = (state->bcr[i] & (ARM_DBG_CR_ADDRESS_MASK_MASK
+ | ARM_DBGBCR_MATCH_MASK
+ | ARM_DBG_CR_BYTE_ADDRESS_SELECT_MASK
+ | ARM_DBG_CR_ENABLE_MASK))
+ | ARM_DBGBCR_TYPE_IVA
+ | ARM_DBG_CR_LINKED_UNLINKED
+ | ARM_DBG_CR_SECURITY_STATE_BOTH
+ | ARM_DBG_CR_MODE_CONTROL_USER;
+ thread_state->bvr[i] = state->bvr[i] & ARM_DBG_VR_ADDRESS_MASK;
+ thread_state->wcr[i] = (state->wcr[i] & (ARM_DBG_CR_ADDRESS_MASK_MASK
+ | ARM_DBGWCR_BYTE_ADDRESS_SELECT_MASK
+ | ARM_DBGWCR_ACCESS_CONTROL_MASK
+ | ARM_DBG_CR_ENABLE_MASK))
+ | ARM_DBG_CR_LINKED_UNLINKED
+ | ARM_DBG_CR_SECURITY_STATE_BOTH
+ | ARM_DBG_CR_MODE_CONTROL_USER;
+ thread_state->wvr[i] = state->wvr[i] & ARM_DBG_VR_ADDRESS_MASK;
+ }
+
+ if (thread->machine.DebugData == NULL) {
+ thread->machine.DebugData = thread_state;