Skip to content

Commit ad74b36

Browse files
committed
pbio/platform/ev3/platform.c: Offset address for abort exceptions
The actual faulting instruction for these exceptions is offset (due to CPU pipelining in this core, later as part of compatibility). Print the actual faulting instruction address so that the developer doesn't have to manually subtract 8.
1 parent 9d3b9bd commit ad74b36

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

lib/pbio/platform/ev3/exceptionhandler.S

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@ SPDX-License-Identifier: MPL-1.0
22
@ Copyright (c) 2016 Tobias Schießl
3+
#include "exceptionhandler.h"
4+
35
.set MODE_USR, 0x10
46
.set MODE_FIQ, 0x11
57
.set MODE_IRQ, 0x12
@@ -12,10 +14,6 @@
1214
.equ I_F_BIT, 0xC0
1315
.equ MASK_SWI_NUM, 0xFF000000
1416
.equ MASK_SR_MODE, 0x1F
15-
.equ EXCEPT_TYPE_UNKNOWN, 0
16-
.equ EXCEPT_TYPE_UNDEF, 1
17-
.equ EXCEPT_TYPE_PREFETCH_ABORT, 2
18-
.equ EXCEPT_TYPE_DATA_ABORT, 3
1917

2018
@ This will be placed at 0xffff0000 by the linker script
2119
.section .vector,"ax",%progbits
@@ -35,25 +33,25 @@ ResetToEntry:
3533
UndefHandlder:
3634
@ Save r0-r12, lr
3735
stmfd sp!, {r0-r12, lr}
38-
mov r7, #EXCEPT_TYPE_UNDEF
36+
mov r7, #EV3_PANIC_UNDEFINED_INSTR
3937
b CommonPanicHandler
4038

4139
PrefetchAbortHandler:
4240
@ Save r0-r12, lr
4341
stmfd sp!, {r0-r12, lr}
44-
mov r7, #EXCEPT_TYPE_PREFETCH_ABORT
42+
mov r7, #EV3_PANIC_PREFETCH_ABORT
4543
b CommonPanicHandler
4644

4745
DataAbortHandler:
4846
@ Save r0-r12, lr
4947
stmfd sp!, {r0-r12, lr}
50-
mov r7, #EXCEPT_TYPE_DATA_ABORT
48+
mov r7, #EV3_PANIC_DATA_ABORT
5149
b CommonPanicHandler
5250

5351
UnknownExceptionHandler:
5452
@ Save r0-r12, lr
5553
stmfd sp!, {r0-r12, lr}
56-
mov r7, #EXCEPT_TYPE_UNKNOWN
54+
mov r7, #EV3_PANIC_UNKNOWN
5755
@ b CommonPanicHandler
5856
@ fall through
5957

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef PBIO_EV3_EXCEPTIONHANDLER_H_
2+
#define PBIO_EV3_EXCEPTIONHANDLER_H_
3+
4+
#define EV3_PANIC_UNKNOWN 0
5+
#define EV3_PANIC_UNDEFINED_INSTR 1
6+
#define EV3_PANIC_PREFETCH_ABORT 2
7+
#define EV3_PANIC_DATA_ABORT 3
8+
9+
#endif // PBIO_EV3_EXCEPTIONHANDLER_H_

lib/pbio/platform/ev3/platform.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#include <pbdrv/ioport.h>
6060
#include <pbio/port_interface.h>
6161

62+
#include "exceptionhandler.h"
63+
6264
#include "../../drv/block_device/block_device_ev3.h"
6365
#include "../../drv/button/button_gpio.h"
6466
#include "../../drv/display/display_ev3.h"
@@ -417,6 +419,7 @@ static const char *const panic_types[] = {
417419
"Prefetch Abort",
418420
"Data Abort",
419421
};
422+
420423
typedef struct {
421424
uint32_t r13;
422425
uint32_t r14;
@@ -481,7 +484,17 @@ void ev3_panic_handler(int except_type, ev3_panic_ctx *except_data) {
481484
panic_puts("\r\nR14: 0x");
482485
panic_putu32(except_data->r14);
483486
panic_puts("\r\nR15: 0x");
484-
panic_putu32(except_data->exc_lr);
487+
switch (except_type) {
488+
case EV3_PANIC_PREFETCH_ABORT:
489+
panic_putu32(except_data->exc_lr - 4);
490+
break;
491+
case EV3_PANIC_DATA_ABORT:
492+
panic_putu32(except_data->exc_lr - 8);
493+
break;
494+
default:
495+
panic_putu32(except_data->exc_lr);
496+
break;
497+
}
485498
panic_puts("\r\nSPSR: 0x");
486499
panic_putu32(except_data->spsr);
487500

0 commit comments

Comments
 (0)