Skip to content

Commit 13208cb

Browse files
committed
feat(11): Adapt exception demo for Raspberry Pi 5 memory layout
Adjusts the tutorial's exception-triggering demonstration to ensure it produces the intended translation fault on the Raspberry Pi 5. The Pi 5 port uses a 128 GiB virtual address space to accommodate the RP1 peripheral map. The original tutorial's faulting address of 8 GiB falls within this space, which would lead to an identity mapping and a bus error instead of the desired translation fault. This commit changes the faulting addresses to 129 GiB and 130 GiB, placing them outside the defined virtual address space. The exception handler is updated accordingly to catch the new 129 GiB address for the recoverable fault demonstration.
1 parent b69fca7 commit 13208cb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ extern "C" fn current_elx_synchronous(e: &mut ExceptionContext) {
9090
if e.fault_address_valid() {
9191
let far_el1 = FAR_EL1.get();
9292

93-
// This catches the demo case for this tutorial. If the fault address happens to be 8 GiB,
94-
// advance the exception link register for one instruction, so that execution can continue.
95-
if far_el1 == 8 * 1024 * 1024 * 1024 {
93+
// This catches the demo case for this tutorial. If the fault address happens to be
94+
// 129 GiB, advance the exception link register for one instruction, so that execution
95+
// can continue.
96+
if far_el1 == 129 * 1024 * 1024 * 1024 {
9697
e.elr_el1 += 4;
9798

9899
return;

11_exceptions_part1_groundwork/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,13 @@ fn kernel_main() -> ! {
195195
info!("Timer test, spinning for 1 second");
196196
time::time_manager().spin_for(Duration::from_secs(1));
197197

198-
// Cause an exception by accessing a virtual address for which no translation was set up. This
199-
// code accesses the address 8 GiB, which is outside the mapped address space.
198+
// Cause an exception by accessing a virtual address for which no translation was set up.
200199
//
201-
// For demo purposes, the exception handler will catch the faulting 8 GiB address and allow
202-
// execution to continue.
200+
// For RPi5, the address space is 128 GiB. We must pick an address outside this range
201+
// to guarantee a translation fault. Let's use 129 GiB.
203202
info!("");
204-
info!("Trying to read from address 8 GiB...");
205-
let mut big_addr: u64 = 8 * 1024 * 1024 * 1024;
203+
info!("Trying to read from address 129 GiB...");
204+
let mut big_addr: u64 = 129 * 1024 * 1024 * 1024;
206205
unsafe { core::ptr::read_volatile(big_addr as *mut u64) };
207206

208207
info!("************************************************");
@@ -211,9 +210,9 @@ fn kernel_main() -> ! {
211210
info!("");
212211
info!("Let's try again");
213212

214-
// Now use address 9 GiB. The exception handler won't forgive us this time.
215-
info!("Trying to read from address 9 GiB...");
216-
big_addr = 9 * 1024 * 1024 * 1024;
213+
// Now use address 130 GiB. The exception handler won't forgive us this time.
214+
info!("Trying to read from address 130 GiB...");
215+
big_addr = 130 * 1024 * 1024 * 1024;
217216
unsafe { core::ptr::read_volatile(big_addr as *mut u64) };
218217

219218
// Will never reach here in this tutorial.
@@ -226,3 +225,4 @@ fn kernel_main() -> ! {
226225
console().write_char(c);
227226
}
228227
}
228+

0 commit comments

Comments
 (0)