Skip to content

Commit 3f82fb1

Browse files
committed
remove redundant g_debug_interrupt_sp
1 parent 5499cc7 commit 3f82fb1

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

core/debug/src/core_armv7m/debug_box_armv7m.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ void debug_deprivilege_and_return(void * debug_handler, void * return_handler,
4848
xpsr = vmpu_unpriv_uint32_read((uint32_t) xpsr_p);
4949
}
5050

51-
/* FIXME: This makes the debug box overwrite the top of the interrupt stack! */
52-
g_context_current_states[dst_id].sp = g_debug_interrupt_sp[dst_id];
53-
5451
/* Destination box: Forge the destination stack frame. */
5552
/* Note: We manually have to set the 4 parameters on the destination stack,
5653
* so we will set the API to have nargs=0. */

core/debug/src/debug_box.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ uint32_t debug_get_version(void)
4545
return 0;
4646
}
4747

48-
uint32_t g_debug_interrupt_sp[UVISOR_MAX_BOXES];
49-
5048
void debug_halt_error(THaltError reason, const THaltInfo *halt_info)
5149
{
5250
static int debugged_once_before = 0;
53-
void *info = NULL;
51+
THaltInfo * dst_halt_info = NULL;
5452

5553
/* If the debug box does not exist (or it has not been initialized yet), or
5654
* the debug box was already called once, just loop forever. */
@@ -62,16 +60,20 @@ void debug_halt_error(THaltError reason, const THaltInfo *halt_info)
6260

6361
/* Place the halt info on the interrupt stack. */
6462
if (halt_info) {
65-
g_debug_interrupt_sp[g_debug_box.box_id] -= sizeof(THaltInfo);
66-
info = (void *)g_debug_interrupt_sp[g_debug_box.box_id];
67-
memcpy(info, halt_info, sizeof(THaltInfo));
63+
dst_halt_info = (THaltInfo *)(g_context_current_states[g_debug_box.box_id].sp - sizeof(*halt_info));
64+
if (vmpu_buffer_access_is_ok(g_debug_box.box_id, dst_halt_info, sizeof(*halt_info))) {
65+
g_context_current_states[g_debug_box.box_id].sp -= sizeof(*halt_info);
66+
memcpy(dst_halt_info, halt_info, sizeof(*halt_info));
67+
} else {
68+
while(1);
69+
}
6870
}
6971

7072
/* The following arguments are passed to the destination function:
7173
* 1. reason
7274
* 2. halt info
7375
* Upon return from the debug handler, the system will die. */
74-
debug_deprivilege_and_return(g_debug_box.driver->halt_error, debug_die, reason, (uint32_t)info, 0, 0);
76+
debug_deprivilege_and_return(g_debug_box.driver->halt_error, debug_die, reason, (uint32_t)dst_halt_info, 0, 0);
7577
}
7678
}
7779

@@ -107,11 +109,6 @@ void debug_register_driver(const TUvisorDebugDriver * const driver)
107109
}
108110
}
109111

110-
for (int ii = 0; ii < UVISOR_MAX_BOXES; ii++)
111-
{
112-
g_debug_interrupt_sp[ii] = g_context_current_states[ii].sp;
113-
}
114-
115112
/* Register the debug box.
116113
* The caller of this function is considered the owner of the debug box. */
117114
g_debug_box.driver = driver;

0 commit comments

Comments
 (0)