Skip to content

Commit 93d17c1

Browse files
Fix the undef handler again
1 parent f1ad209 commit 93d17c1

17 files changed

+271
-97
lines changed

cortex-a-rt/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,26 +432,38 @@ core::arch::global_asm!(
432432
_asm_default_undefined_handler:
433433
// state save from compiled code
434434
srsfd sp!, {und_mode}
435-
"#,
436-
save_context!(),
437-
r#"
435+
// to work out what mode we're in, we need R0
436+
push {{r0}}
438437
// First adjust LR for two purposes: Passing the faulting instruction to the C handler,
439438
// and to return to the failing instruction after the C handler returns.
440439
// Load processor status for the calling code
441-
mrs r4, spsr
440+
mrs r0, spsr
442441
// Was the code that triggered the exception in Thumb state?
443-
tst r4, {t_bit}
442+
tst r0, {t_bit}
444443
// Subtract 2 in Thumb Mode, 4 in Arm Mode - see p.1206 of the ARMv7-A architecture manual.
445444
ite eq
446445
subeq lr, lr, #4
447446
subne lr, lr, #2
447+
// save the newly computed LR
448+
push {{lr}}
449+
// now do our standard exception save
450+
"#,
451+
save_context!(),
452+
r#"
448453
// Pass the faulting instruction address to the handler.
449454
mov r0, lr
450455
// call C handler
451456
bl _undefined_handler
457+
// do our standard restore
452458
"#,
453459
restore_context!(),
454460
r#"
461+
// get our saved LR
462+
pop {{lr}}
463+
// get our real saved R0
464+
pop {{r0}}
465+
// overwrite the saved LR with the adjusted one
466+
str lr, [sp]
455467
// Return to the failing instruction which is the recommended approach by ARM.
456468
rfefd sp!
457469
.size _asm_default_undefined_handler, . - _asm_default_undefined_handler

cortex-r-rt/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,38 @@ core::arch::global_asm!(
364364
_asm_default_undefined_handler:
365365
// state save from compiled code
366366
srsfd sp!, {und_mode}
367-
"#,
368-
save_context!(),
369-
r#"
367+
// to work out what mode we're in, we need R0
368+
push {{r0}}
370369
// First adjust LR for two purposes: Passing the faulting instruction to the C handler,
371370
// and to return to the failing instruction after the C handler returns.
372371
// Load processor status for the calling code
373-
mrs r4, spsr
372+
mrs r0, spsr
374373
// Was the code that triggered the exception in Thumb state?
375-
tst r4, {t_bit}
374+
tst r0, {t_bit}
376375
// Subtract 2 in Thumb Mode, 4 in Arm Mode - see p.1206 of the ARMv7-A architecture manual.
377376
ite eq
378377
subeq lr, lr, #4
379378
subne lr, lr, #2
379+
// save the newly computed LR
380+
push {{lr}}
381+
// now do our standard exception save
382+
"#,
383+
save_context!(),
384+
r#"
380385
// Pass the faulting instruction address to the handler.
381386
mov r0, lr
382387
// call C handler
383388
bl _undefined_handler
389+
// do our standard restore
384390
"#,
385391
restore_context!(),
386392
r#"
393+
// get our saved LR
394+
pop {{lr}}
395+
// get our real saved R0
396+
pop {{r0}}
397+
// overwrite the saved LR with the adjusted one
398+
str lr, [sp]
387399
// Return to the failing instruction which is the recommended approach by ARM.
388400
rfefd sp!
389401
.size _asm_default_undefined_handler, . - _asm_default_undefined_handler
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Hello, this is an data abort exception example
2+
data abort occurred
3+
DFSR (Fault Status Register): DFSR { ext=false wnr=false Domain=0b0000 Status=0b00001 }
4+
DFSR Status: Ok(AlignmentFault)
5+
DFAR (Faulting Address Register): Dfar(4097)
6+
data abort occurred
7+
DFSR (Fault Status Register): DFSR { ext=false wnr=false Domain=0b0000 Status=0b00001 }
8+
DFSR Status: Ok(AlignmentFault)
9+
DFAR (Faulting Address Register): Dfar(4097)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Hello, this is a prefetch exception example
2+
prefetch abort occurred
3+
IFSR (Fault Status Register): IFSR { ext=false Domain=0b0000 Status=0b00010 }
4+
IFSR Status: Ok(DebugEvent)
5+
IFAR (Faulting Address Register): Ifar(0)
6+
caught bkpt_from_a32
7+
prefetch abort occurred
8+
IFSR (Fault Status Register): IFSR { ext=false Domain=0b0000 Status=0b00010 }
9+
IFSR Status: Ok(DebugEvent)
10+
IFAR (Faulting Address Register): Ifar(0)
11+
caught bkpt_from_a32
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Hello, this is a prefetch exception example
2+
prefetch abort occurred
3+
IFSR (Fault Status Register): IFSR { ext=false Domain=0b0000 Status=0b00010 }
4+
IFSR Status: Ok(DebugEvent)
5+
IFAR (Faulting Address Register): Ifar(0)
6+
caught bkpt_from_t32
7+
prefetch abort occurred
8+
IFSR (Fault Status Register): IFSR { ext=false Domain=0b0000 Status=0b00010 }
9+
IFSR Status: Ok(DebugEvent)
10+
IFAR (Faulting Address Register): Ifar(0)
11+
caught bkpt_from_t32
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello, this is a undef exception example
2+
undefined abort occurred
3+
caught udf_from_a32
4+
undefined abort occurred
5+
caught udf_from_a32
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello, this is a undef exception example
2+
undefined abort occurred
3+
caught udf_from_a32
4+
undefined abort occurred
5+
caught udf_from_a32
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello, this is a undef exception example
2+
undefined abort occurred
3+
caught udf_from_a32
4+
undefined abort occurred
5+
caught udf_from_a32

examples/versatileab/reference/undef-exception-armv7a-none-eabi.out

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/versatileab/reference/undef-exception-armv7r-none-eabihf.out

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)