Skip to content

Commit cd8addb

Browse files
bugadaniCopilot
andauthored
Fix rare Xtensa crash (#4580)
* Fix offset of double exception handler * Fix initial PS value * Changelog PR number * Update esp-rtos/src/task/xtensa.rs Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent cee57fc commit cd8addb

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

esp-rtos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- Fixed an issue on ESP32 that prevented completing some interrupt handlers (#4459)
2828
- Fixed a possible deadlock on multi-core chips (#4478)
2929
- Fixed a memory leak of 48 bytes when deleting esp-radio timers (#4541)
30+
- Fixed a rare crash on Xtensa MCUs (#4580)
3031

3132
### Removed
3233

esp-rtos/src/task/xtensa.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ pub(crate) fn new_task_context(
8585
A6: task_fn as usize as u32,
8686
A7: param as usize as u32,
8787

88-
// For windowed ABI set WOE and CALLINC (pretend task was 'call4'd)
89-
PS: 0x00040000 | ((1 & 3) << 16),
88+
// For windowed ABI set WOE, UM, EXCM and CALLINC1 (pretend task was 'call4'd)
89+
// UM and EXCM are important, so that restoring context will correctly restore an exception
90+
// context (where the context switch happens).
91+
PS: 0x00050030,
9092

9193
..Default::default()
9294
}

xtensa-lx-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Fixed
1818

19+
- Fixed offset of `DoubleException` handler (#4580)
1920

2021
### Removed
2122

xtensa-lx-rt/exception-esp32.x.template

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,43 @@ SECTIONS {
5454

5555
.vectors :
5656
{
57-
/*
58-
Each vector has 64 bytes that it must fit inside. For each vector we calculate the size of the previous one,
57+
/*
58+
Each vector has 64 bytes that it must fit inside. For each vector we calculate the size of the previous one,
5959
and subtract that from 64 and start the new vector there.
6060
*/
6161
_init_start = ABSOLUTE(.);
62-
. = ALIGN(64);
62+
. = 0x0;
6363
KEEP(*(.WindowOverflow4.text));
64-
. = ALIGN(64);
64+
. = 0x40;
6565
KEEP(*(.WindowUnderflow4.text));
66-
. = ALIGN(64);
66+
. = 0x80;
6767
KEEP(*(.WindowOverflow8.text));
68-
. = ALIGN(64);
68+
. = 0xC0;
6969
KEEP(*(.WindowUnderflow8.text));
70-
. = ALIGN(64);
70+
. = 0x100;
7171
KEEP(*(.WindowOverflow12.text));
72-
. = ALIGN(64);
72+
. = 0x140;
7373
KEEP(*(.WindowUnderflow12.text));
74-
. = ALIGN(64);
74+
. = 0x180;
7575
KEEP(*(.Level2InterruptVector.text));
76-
. = ALIGN(64);
76+
. = 0x1C0;
7777
KEEP(*(.Level3InterruptVector.text));
78-
. = ALIGN(64);
78+
. = 0x200;
7979
KEEP(*(.Level4InterruptVector.text));
80-
. = ALIGN(64);
80+
. = 0x240;
8181
KEEP(*(.Level5InterruptVector.text));
82-
. = ALIGN(64);
82+
. = 0x280;
8383
KEEP(*(.DebugExceptionVector.text));
84-
. = ALIGN(64);
84+
. = 0x2C0;
8585
KEEP(*(.NMIExceptionVector.text));
86-
. = ALIGN(64);
86+
. = 0x300;
8787
KEEP(*(.KernelExceptionVector.text));
88-
. = ALIGN(64);
88+
. = 0x340;
8989
KEEP(*(.UserExceptionVector.text));
90-
. = ALIGN(128);
90+
/* mind the gap */
91+
. = 0x3C0;
9192
KEEP(*(.DoubleExceptionVector.text));
92-
. = ALIGN(64);
93-
. = ALIGN(0x400);
93+
. = 0x400;
9494
_init_end = ABSOLUTE(.);
9595
} > vectors_seg
9696
}

0 commit comments

Comments
 (0)