aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-01-31 11:14:00 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-01-31 11:14:49 +0000
commitc7064fe0cebbf4b0556b4d99d0bfa92ec920ecb6 (patch)
tree3e44af31fd3cb0683dc9c5fe8f53d48dc07fa913
parentf4c37813adf272b457d15ceb8c0301421f010343 (diff)
test5: Abort if we failed to get back to privileged mode
This test switches between unprivileged and privileged modes, which use different stack pointers. If we failed to get back to privileged mode at the end of the test, then returning from main() will cause a guest crash (which will result in an infinite loop of exceptions). Avoid this by calling abort() if we didn't manage to get back to the stack pointer we need to safely return from main(). Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--test5.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/test5.c b/test5.c
index f3a4eba..6881d37 100644
--- a/test5.c
+++ b/test5.c
@@ -182,5 +182,20 @@ void main(void)
}
show_control(0, 0);
+ /* If we didn't manage to get back into privileged mode
+ * for some reason then we're still running on the PSP stack,
+ * and trying to return from this function will crash.
+ * To avoid that, abort if we're still in user mode.
+ */
+ {
+ uint32_t actrl;
+ __asm__ ("mrs %0,CONTROL" : "=r"(actrl) ::);
+
+ if (actrl != 0) {
+ testDiag("failed to return to privileged stack: aborting");
+ abort();
+ }
+ }
+
testDiag("Done.");
}