-
Notifications
You must be signed in to change notification settings - Fork 85
Support user thread mode in hard fault handler #77
Conversation
Thanks for the PR, @crawford. I more or less understand what the assembly routine is doing but could you add a comment indicating with text (or the equivalent Rust code) what the instructions are doing and another comment mentioning the difference between the MSP and the PSP (a link to ARM docs is fine)? bors try ^ to check if this works on ARMv6-M |
tryBuild failed |
Sorry, I've been busy at work. I'll fix up this PR. |
bors try EDIT: It was worth a shot. |
🔒 Permission denied Existing reviewers: click here to make crawford a reviewer |
I switched to a slower implementation that will work on ARM v6 and v7. We could use two different implementations, but I don't think it's worth the complexity. |
hardfault.s
Outdated
HardFault: | ||
movs r0, #4 | ||
mov r1, lr | ||
tst r0, r1 // Test bit[3] of EXC_RETURN to determine thread mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this say "bit[2]"? Bit positions start at 0 to have bitmasks match 1 << $pos
(bit 0 -> mask = (1 << 0); bit 1 -> mask = (1 << 1); etc.)
I think you can use bmi
instead of tst
to use less registers. For example, this code
#![no_std]
#![feature(asm)]
#![feature(core_intrinsics)]
use core::intrinsics;
pub fn foo(x: u32) {
unsafe {
if x & (1 << 2) == 0 {
asm!("mrs r0, MSP
bl UserHardFault" :::: "volatile");
intrinsics::unreachable();
} else {
asm!("mrs r0, PSP
bl UserHardFault" :::: "volatile");
intrinsics::unreachable();
}
}
}
produces this machine code when compiled with optimizations:
00000000 <foo::foo>:
0: 0740 lsls r0, r0, #29
2: d404 bmi.n e <foo::foo+0xe>
4: f3ef 8008 mrs r0, MSP
8: f7ff fffe bl 0 <UserHardFault>
c: defe udf #254 ; 0xfe
e: f3ef 8009 mrs r0, PSP
12: f7ff fffe bl 0 <UserHardFault>
16: defe udf #254 ; 0xfe
The defe udf
instruction can be omitted.
bors try |
tryBuild failed |
Updated. I haven't tested this implementation on real hardware though. I'll be able to test it tomorrow. |
This looks good on the Cortex M4 I tested. While attempting to write to address 0x3000_0000, I hit a hardfault:
|
It appears this still doesn't compile for ARMv6-M when using
bors try |
bors r+ |
Build failed |
Shoot. I hadn't noticed the individual failures were different. I'm on vacation at the moment, but I can fix this in a couple days. |
Hello @crawford! We haven't heard from you in a while so I'm going to close this PR to clear up the PR queue. Feel free to open a new rebased PR and we'll be happy to review it! |
No problem. Sorry I went AWOL. |
No description provided.