diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-01-31 11:14:00 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-01-31 11:14:49 +0000 |
commit | c7064fe0cebbf4b0556b4d99d0bfa92ec920ecb6 (patch) | |
tree | 3e44af31fd3cb0683dc9c5fe8f53d48dc07fa913 | |
parent | f4c37813adf272b457d15ceb8c0301421f010343 (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.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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."); } |