Skip to content

Commit 901bff9

Browse files
Add japaric review comments
1 parent 04b67a2 commit 901bff9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/exceptions.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ handler, and so on.
2626
As mentioned before, the processor expects the vector table to be at some specific location in memory,
2727
and each entry in it can potentially be used by the processor at runtime. Hence, the entries must always
2828
contain valid values. Furthermore, we want the `rt` crate to be flexible so the end user can customize the
29-
behavior of each exception handler. Finally, the vector table is read only memory, or rather in not
29+
behavior of each exception handler. Finally, the vector table resides in read only memory, or rather in not
3030
easily modified memory, so the user has to register the handler statically, rather than at runtime.
3131

3232
To satisfy all these constraints, we'll assign a *default* value to all the entries of the vector
@@ -66,7 +66,9 @@ pub static EXCEPTIONS: [Vector; 14] = [
6666
Vector { handler: HardFault },
6767
Vector { handler: MemManage },
6868
Vector { handler: BusFault },
69-
Vector { handler: UsageFault },
69+
Vector {
70+
handler: UsageFault,
71+
},
7072
Vector { reserved: 0 },
7173
Vector { reserved: 0 },
7274
Vector { reserved: 0 },
@@ -131,8 +133,9 @@ PROVIDE(PendSV = DefaultExceptionHandler);
131133
PROVIDE(SysTick = DefaultExceptionHandler);
132134
```
133135

134-
`PROVIDE` only takes effect when a symbol on the RHS is still undefined after inspecting all the input
135-
object files. This is the scenario where the user didn't implement the handler for the respective exception.
136+
`PROVIDE` only takes effect when the symbol to the left of the equal sign is still undefined after
137+
inspecting all the input object files. This is the scenario where the user didn't implement the
138+
handler for the respective exception.
136139

137140
## Testing it
138141

@@ -215,6 +218,20 @@ Contents of section .vector_table:
215218
0030 00000000 00000000 79000000 79000000 ........y...y...
216219
```
217220

221+
The vector table now resembles the results of all the code snippets in this book so far. To summarize:
222+
- In the [_Inspecting it_] section of the earlier memory chapter, we learned that:
223+
- The first entry in the vector table contains the initial value of the stack pointer.
224+
- Objdump prints in `little endian` format, so the stack starts at `0x2001_0000`.
225+
- The second entry points to address `0x0000_0041`, the Reset handler.
226+
- The address of the Reset handler can be seen in the disassembly above, being `0x40`.
227+
- The first bit being set to 1 does not alter the address due to alignment requirements. Instead, it causes the function to be executed in _thumb mode_.
228+
- Afterwards, a pattern of addresses alternating between `0x79` and `0x00` is visible.
229+
- Looking at the disassembly above, it is clear that `0x79` refers to the `DefaultExceptionHandler` (`0x78` executed in thumb mode).
230+
- Cross referncing the pattern to the vector table that was set up earlier in this chapter (see the definition of `pub static EXCEPTIONS`) with [the vector table layout for the Cortex-M], it is clear that the address of the `DefaultExceptionHandler` is present each time a respective handler entry is present in the table.
231+
232+
[_Inspecting it_]: https://rust-embedded.github.io/embedonomicon/memory-layout.html#inspecting-it
233+
[the vector table layout for the Cortex-M]: https://developer.arm.com/docs/dui0552/latest/the-cortex-m3-processor/exception-model/vector-table
234+
218235
## Overriding a handler
219236

220237
To override an exception handler, the user has to provide a function whose symbol name exactly

0 commit comments

Comments
 (0)