Skip to content

Commit 0da540e

Browse files
committed
pbio/platform/ev3: Copy only as much of the exception vector table as needed
1 parent 625e80b commit 0da540e

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

lib/pbio/platform/ev3/exceptionhandler.S

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@ SPDX-License-Identifier: MPL-1.0
22
@ Copyright (c) 2016 Tobias Schießl
3-
.global ExceptionHandler
3+
.global ExceptionHandlerStart
4+
.global ExceptionHandlerEnd
45
.global IRQHandler
56
.global SWIHandler
67
@@ -20,17 +21,23 @@
2021

2122
.code 32
2223

24+
@ XXX this code will be copied (in one chunk) to the 0xffff0000 internal RAM,
25+
@ but the assembler/linker *do not know this*. Access to things outside of this file
26+
@ (such as the reset via calling Entry) needs to be written in a position-independent way.
27+
2328
@ Default entry for all vectors except Reset is "B ExceptionHandler" so each interrupt would cause a reset
2429
@ Since I can only say that the IRQ Handler works, we leave the remaining ones as they are
25-
ExceptionHandler:
26-
B Entry
27-
B ExceptionHandler
30+
ExceptionHandlerStart:
31+
ldr pc, =Entry
32+
B ExceptionHandlerStart
2833
B SWIHandler
29-
B ExceptionHandler
30-
B ExceptionHandler
31-
B ExceptionHandler
34+
B ExceptionHandlerStart
35+
B ExceptionHandlerStart
36+
B ExceptionHandlerStart
3237
B IRQHandler
33-
NOP @ Fall to FIQHandler
38+
B FIQHandler
39+
40+
.pool
3441
3542
FIQHandler:
3643
STMFD r13!, {r0-r7, lr}
@@ -104,4 +111,7 @@ loop:
104111
@
105112
@ End of the file
106113
@
114+
115+
.pool
116+
ExceptionHandlerEnd:
107117
.end

lib/pbio/platform/ev3/platform.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,15 @@ const pbdrv_ioport_platform_data_t pbdrv_ioport_platform_data[PBDRV_CONFIG_IOPOR
394394
};
395395

396396
// See exceptionhandler.S
397-
extern void ExceptionHandler(void);
397+
extern void ExceptionHandlerStart(void);
398+
extern void ExceptionHandlerEnd(void);
398399

399400
void copy_vector_table(void) {
400-
unsigned int *dest = (unsigned int *)0xFFFF0000;
401-
unsigned int *addrExceptionHandler = (unsigned int *)ExceptionHandler;
402-
int i = 1;
401+
void *dest = (void *)0xFFFF0000;
402+
void *addrExceptionHandler = (void *)ExceptionHandlerStart;
403+
uint32_t sz = (uint32_t)ExceptionHandlerEnd - (uint32_t)ExceptionHandlerStart;
403404

404-
for (; i < 8 + 2048; ++i) {
405-
dest[i] = addrExceptionHandler[i];
406-
}
405+
memcpy(dest, addrExceptionHandler, sz);
407406
}
408407

409408
unsigned int EDMAVersionGet(void) {

0 commit comments

Comments
 (0)