diff --git a/src/bare-metal/aps/aarch64-rt.md b/src/bare-metal/aps/aarch64-rt.md index 80963e06..ca348184 100644 --- a/src/bare-metal/aps/aarch64-rt.md +++ b/src/bare-metal/aps/aarch64-rt.md @@ -13,3 +13,10 @@ writing our own. ```rust,editable,compile_fail {{#include examples/src/main_rt.rs:main}} ``` + +
+ +- Run the example in QEMU with `make qemu_rt` under + `src/bare-metal/aps/examples`. + +
diff --git a/src/bare-metal/aps/examples/Cargo.lock b/src/bare-metal/aps/examples/Cargo.lock index 3a6622d1..cd92d984 100644 --- a/src/bare-metal/aps/examples/Cargo.lock +++ b/src/bare-metal/aps/examples/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "aarch64-rt" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be4edaff3b5ead5fb7e9ef0d72fa1e93b4052ec2410e0ebc93f6f360c9599ea" +checksum = "3ba0820a68948e3655dbde1071b421d9ae8c08afb58e274b72c22e8a981c548c" dependencies = [ "cfg-if", "smccc", diff --git a/src/bare-metal/aps/examples/Cargo.toml b/src/bare-metal/aps/examples/Cargo.toml index 555a5ce0..16573c5a 100644 --- a/src/bare-metal/aps/examples/Cargo.toml +++ b/src/bare-metal/aps/examples/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] aarch64-paging = { version = "0.9.1", default-features = false } -aarch64-rt = "0.1.3" +aarch64-rt = "0.2.0" arm-pl011-uart = "0.3.1" bitflags = "2.9.1" log = "0.4.27" diff --git a/src/bare-metal/aps/examples/Makefile b/src/bare-metal/aps/examples/Makefile index 6aea4aac..23f366f6 100644 --- a/src/bare-metal/aps/examples/Makefile +++ b/src/bare-metal/aps/examples/Makefile @@ -27,6 +27,8 @@ minimal.bin: build cargo objcopy --bin minimal -- -O binary $@ psci.bin: build cargo objcopy --bin psci -- -O binary $@ +rt.bin: build + cargo objcopy --bin rt -- -O binary $@ qemu: improved.bin qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s @@ -36,6 +38,8 @@ qemu_minimal: minimal.bin qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s qemu_psci: psci.bin qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s +qemu_rt: rt.bin + qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s clean: cargo clean diff --git a/src/bare-metal/aps/examples/src/main_improved.rs b/src/bare-metal/aps/examples/src/main_improved.rs index bb266014..777c7ac3 100644 --- a/src/bare-metal/aps/examples/src/main_improved.rs +++ b/src/bare-metal/aps/examples/src/main_improved.rs @@ -16,6 +16,7 @@ #![no_main] #![no_std] +mod asm; mod exceptions; mod pl011; diff --git a/src/bare-metal/aps/examples/src/main_logger.rs b/src/bare-metal/aps/examples/src/main_logger.rs index d036bbdf..9a939f9d 100644 --- a/src/bare-metal/aps/examples/src/main_logger.rs +++ b/src/bare-metal/aps/examples/src/main_logger.rs @@ -16,6 +16,7 @@ #![no_main] #![no_std] +mod asm; mod exceptions; mod logger; mod pl011; diff --git a/src/bare-metal/aps/examples/src/main_psci.rs b/src/bare-metal/aps/examples/src/main_psci.rs index 3529a85e..cf7e80ff 100644 --- a/src/bare-metal/aps/examples/src/main_psci.rs +++ b/src/bare-metal/aps/examples/src/main_psci.rs @@ -19,6 +19,7 @@ use core::arch::asm; use core::panic::PanicInfo; +mod asm; mod exceptions; const PSCI_SYSTEM_OFF: u32 = 0x84000008; diff --git a/src/bare-metal/aps/examples/src/main_rt.rs b/src/bare-metal/aps/examples/src/main_rt.rs index 4f63aedc..d4e7024d 100644 --- a/src/bare-metal/aps/examples/src/main_rt.rs +++ b/src/bare-metal/aps/examples/src/main_rt.rs @@ -24,7 +24,6 @@ use arm_pl011_uart::{PL011Registers, Uart, UniqueMmioPointer}; use core::fmt::Write; use core::panic::PanicInfo; use core::ptr::NonNull; -use log::error; use smccc::Hvc; use smccc::psci::system_off; @@ -67,11 +66,9 @@ fn main(x0: u64, x1: u64, x2: u64, x3: u64) -> ! { system_off::().unwrap(); panic!("system_off returned"); } -// ANCHOR_END: main #[panic_handler] fn panic(info: &PanicInfo) -> ! { - error!("{info}"); system_off::().unwrap(); loop {} } diff --git a/src/bare-metal/microcontrollers/debugging.md b/src/bare-metal/microcontrollers/debugging.md index 349e0918..57014f32 100644 --- a/src/bare-metal/microcontrollers/debugging.md +++ b/src/bare-metal/microcontrollers/debugging.md @@ -27,7 +27,7 @@ On gLinux or Debian: ```sh -gdb-multiarch target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1337" +gdb-multiarch target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1338" ``` On MacOS: @@ -35,7 +35,7 @@ On MacOS: ```sh -arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1337" +arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1338" ```
diff --git a/src/bare-metal/microcontrollers/examples/Embed.toml b/src/bare-metal/microcontrollers/examples/Embed.toml index 0f270ac8..a9a46521 100644 --- a/src/bare-metal/microcontrollers/examples/Embed.toml +++ b/src/bare-metal/microcontrollers/examples/Embed.toml @@ -3,6 +3,7 @@ chip = "nrf52833_xxAA" [debug.gdb] enabled = true +gdb_connection_string = "127.0.0.1:1338" [debug.reset] halt_afterwards = true diff --git a/src/exercises/bare-metal/rtc.md b/src/exercises/bare-metal/rtc.md index 7536f90f..95cd1bca 100644 --- a/src/exercises/bare-metal/rtc.md +++ b/src/exercises/bare-metal/rtc.md @@ -66,13 +66,22 @@ _Cargo.toml_ (you shouldn't need to change this): {{#include rtc/Cargo.toml}} ``` -_image.ld_ (you shouldn't need to change this): +_build.rs_ (you shouldn't need to change this): - + ```ld -{{#include rtc/image.ld}} +{{#include rtc/build.rs}} +``` + +_memory.ld_ (you shouldn't need to change this): + + + + +```ld +{{#include rtc/memory.ld}} ``` _Makefile_ (you shouldn't need to change this): diff --git a/src/exercises/bare-metal/rtc/.cargo/config.toml b/src/exercises/bare-metal/rtc/.cargo/config.toml index ffecab4e..724febae 100644 --- a/src/exercises/bare-metal/rtc/.cargo/config.toml +++ b/src/exercises/bare-metal/rtc/.cargo/config.toml @@ -1,3 +1,2 @@ [build] target = "aarch64-unknown-none" -rustflags = ["-C", "link-arg=-Timage.ld"] diff --git a/src/exercises/bare-metal/rtc/Cargo.lock b/src/exercises/bare-metal/rtc/Cargo.lock index 26501fbe..39e5fac1 100644 --- a/src/exercises/bare-metal/rtc/Cargo.lock +++ b/src/exercises/bare-metal/rtc/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "aarch64-rt" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be4edaff3b5ead5fb7e9ef0d72fa1e93b4052ec2410e0ebc93f6f360c9599ea" +checksum = "3ba0820a68948e3655dbde1071b421d9ae8c08afb58e274b72c22e8a981c548c" dependencies = [ "cfg-if", "smccc", diff --git a/src/exercises/bare-metal/rtc/Cargo.toml b/src/exercises/bare-metal/rtc/Cargo.toml index afaff5f5..c403e354 100644 --- a/src/exercises/bare-metal/rtc/Cargo.toml +++ b/src/exercises/bare-metal/rtc/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] aarch64-paging = { version = "0.9.1", default-features = false } -aarch64-rt = "0.1.3" +aarch64-rt = "0.2.0" arm-gic = "0.4.0" arm-pl011-uart = "0.3.1" bitflags = "2.9.1" diff --git a/src/exercises/bare-metal/rtc/build.rs b/src/exercises/bare-metal/rtc/build.rs new file mode 100644 index 00000000..361ac3c2 --- /dev/null +++ b/src/exercises/bare-metal/rtc/build.rs @@ -0,0 +1,19 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +fn main() { + println!("cargo:rustc-link-arg=-Timage.ld"); + println!("cargo:rustc-link-arg=-Tmemory.ld"); + println!("cargo:rerun-if-changed=memory.ld"); +} diff --git a/src/exercises/bare-metal/rtc/image.ld b/src/exercises/bare-metal/rtc/image.ld deleted file mode 100644 index 59c77527..00000000 --- a/src/exercises/bare-metal/rtc/image.ld +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Code will start running at this symbol which is placed at the start of the - * image. - */ -ENTRY(entry) - -MEMORY -{ - image : ORIGIN = 0x40080000, LENGTH = 2M -} - -SECTIONS -{ - /* - * Collect together the code. - */ - .init : ALIGN(4096) { - text_begin = .; - *(.init.entry) - *(.init.*) - } >image - .text : { - *(.text.*) - } >image - text_end = .; - - /* - * Collect together read-only data. - */ - .rodata : ALIGN(4096) { - rodata_begin = .; - *(.rodata.*) - } >image - .got : { - *(.got) - } >image - rodata_end = .; - - /* - * Collect together the read-write data including .bss at the end which - * will be zero'd by the entry code. - */ - .data : ALIGN(4096) { - data_begin = .; - *(.data.*) - /* - * The entry point code assumes that .data is a multiple of 32 - * bytes long. - */ - . = ALIGN(32); - data_end = .; - } >image - - /* Everything beyond this point will not be included in the binary. */ - bin_end = .; - - /* The entry point code assumes that .bss is 16-byte aligned. */ - .bss : ALIGN(16) { - bss_begin = .; - *(.bss.*) - *(COMMON) - . = ALIGN(16); - bss_end = .; - } >image - - .stack (NOLOAD) : ALIGN(4096) { - boot_stack_begin = .; - . += 40 * 4096; - . = ALIGN(4096); - boot_stack_end = .; - } >image - - . = ALIGN(4K); - PROVIDE(dma_region = .); - - /* - * Remove unused sections from the image. - */ - /DISCARD/ : { - /* The image loads itself so doesn't need these sections. */ - *(.gnu.hash) - *(.hash) - *(.interp) - *(.eh_frame_hdr) - *(.eh_frame) - *(.note.gnu.build-id) - } -} diff --git a/src/exercises/bare-metal/rtc/memory.ld b/src/exercises/bare-metal/rtc/memory.ld new file mode 100644 index 00000000..5165ba05 --- /dev/null +++ b/src/exercises/bare-metal/rtc/memory.ld @@ -0,0 +1,20 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +MEMORY +{ + image : ORIGIN = 0x40080000, LENGTH = 2M +} diff --git a/src/exercises/bare-metal/rtc/src/logger.rs b/src/exercises/bare-metal/rtc/src/logger.rs index aa64782e..3b144790 100644 --- a/src/exercises/bare-metal/rtc/src/logger.rs +++ b/src/exercises/bare-metal/rtc/src/logger.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// ANCHOR: main use arm_pl011_uart::Uart; use core::fmt::Write; use log::{LevelFilter, Log, Metadata, Record, SetLoggerError}; diff --git a/tests/src/slides/slide-exemptions.list.ts b/tests/src/slides/slide-exemptions.list.ts index d8ac8366..bf78c860 100644 --- a/tests/src/slides/slide-exemptions.list.ts +++ b/tests/src/slides/slide-exemptions.list.ts @@ -5,6 +5,7 @@ export const size_exemptions = [ "android/interoperability/java.html", "android/testing.html", "bare-metal/aps/entry-point.html", + "bare-metal/aps/aarch64-rt.html", "exercises/bare-metal/compass.html", "exercises/bare-metal/solutions-afternoon.html", "exercises/bare-metal/rtc.html",