From 0a0e830504319a19f1746bbb1538d63a2af79be1 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Wed, 17 Jan 2024 20:25:21 -0500 Subject: [PATCH] boards: rpi: remove naked_functions --- boards/nano_rp2040_connect/src/main.rs | 45 ++++++++++++++------------ boards/pico_explorer_base/src/main.rs | 44 +++++++++++++------------ boards/raspberry_pi_pico/src/main.rs | 44 +++++++++++++------------ 3 files changed, 72 insertions(+), 61 deletions(-) diff --git a/boards/nano_rp2040_connect/src/main.rs b/boards/nano_rp2040_connect/src/main.rs index a67d50d345..4cc18973c7 100644 --- a/boards/nano_rp2040_connect/src/main.rs +++ b/boards/nano_rp2040_connect/src/main.rs @@ -11,9 +11,8 @@ // https://github.com/rust-lang/rust/issues/62184. #![cfg_attr(not(doc), no_main)] #![deny(missing_docs)] -#![feature(naked_functions)] -use core::arch::asm; +use core::arch::global_asm; use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm; use components::gpio::GpioComponent; @@ -152,31 +151,35 @@ impl KernelResources>> for Nan } } -/// Entry point used for debuger -/// -/// When loaded using gdb, the Arduino Nano RP2040 Connect is not reset -/// by default. Without this function, gdb sets the PC to the -/// beginning of the flash. This is not correct, as the RP2040 -/// has a more complex boot process. -/// -/// This function is set to be the entry point for gdb and is used -/// to send the RP2040 back in the bootloader so that all the boot -/// sqeuence is performed. -#[no_mangle] -#[naked] -pub unsafe extern "C" fn jump_to_bootloader() { - asm!( - " +#[allow(dead_code)] +extern "C" { + /// Entry point used for debugger + /// + /// When loaded using gdb, the Arduino Nano RP2040 Connect is not reset + /// by default. Without this function, gdb sets the PC to the + /// beginning of the flash. This is not correct, as the RP2040 + /// has a more complex boot process. + /// + /// This function is set to be the entry point for gdb and is used + /// to send the RP2040 back in the bootloader so that all the boot + /// sequence is performed. + fn jump_to_bootloader(); +} + +global_asm!( + " + .section .jump_to_bootloader, \"ax\" + .global jump_to_bootloader + .thumb_func + jump_to_bootloader: movs r0, #0 ldr r1, =(0xe0000000 + 0x0000ed08) str r0, [r1] ldmia r0!, {{r1, r2}} msr msp, r1 bx r2 - ", - options(noreturn) - ); -} + " +); fn init_clocks(peripherals: &Rp2040DefaultPeripherals) { // Start tick in watchdog diff --git a/boards/pico_explorer_base/src/main.rs b/boards/pico_explorer_base/src/main.rs index 795bd2fb37..da47db1e0f 100644 --- a/boards/pico_explorer_base/src/main.rs +++ b/boards/pico_explorer_base/src/main.rs @@ -13,7 +13,7 @@ #![deny(missing_docs)] #![feature(naked_functions)] -use core::arch::asm; +use core::arch::global_asm; use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm; use components::gpio::GpioComponent; @@ -162,31 +162,35 @@ impl KernelResources>> for Pic } } -/// Entry point used for debuger -/// -/// When loaded using gdb, the Raspberry Pi Pico is not reset -/// by default. Without this function, gdb sets the PC to the -/// beginning of the flash. This is not correct, as the RP2040 -/// has a more complex boot process. -/// -/// This function is set to be the entry point for gdb and is used -/// to send the RP2040 back in the bootloader so that all the boot -/// sqeuence is performed. -#[no_mangle] -#[naked] -pub unsafe extern "C" fn jump_to_bootloader() { - asm!( - " +#[allow(dead_code)] +extern "C" { + /// Entry point used for debugger + /// + /// When loaded using gdb, the Raspberry Pi Pico is not reset + /// by default. Without this function, gdb sets the PC to the + /// beginning of the flash. This is not correct, as the RP2040 + /// has a more complex boot process. + /// + /// This function is set to be the entry point for gdb and is used + /// to send the RP2040 back in the bootloader so that all the boot + /// sequence is performed. + fn jump_to_bootloader(); +} + +global_asm!( + " + .section .jump_to_bootloader, \"ax\" + .global jump_to_bootloader + .thumb_func + jump_to_bootloader: movs r0, #0 ldr r1, =(0xe0000000 + 0x0000ed08) str r0, [r1] ldmia r0!, {{r1, r2}} msr msp, r1 bx r2 - ", - options(noreturn) - ); -} + " +); fn init_clocks(peripherals: &Rp2040DefaultPeripherals) { // Start tick in watchdog diff --git a/boards/raspberry_pi_pico/src/main.rs b/boards/raspberry_pi_pico/src/main.rs index f5e904c90b..02dda78d5b 100644 --- a/boards/raspberry_pi_pico/src/main.rs +++ b/boards/raspberry_pi_pico/src/main.rs @@ -13,7 +13,7 @@ #![deny(missing_docs)] #![feature(naked_functions)] -use core::arch::asm; +use core::arch::global_asm; use capsules_core::i2c_master::I2CMasterDriver; use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm; @@ -153,31 +153,35 @@ impl KernelResources>> for Ras } } -/// Entry point used for debugger -/// -/// When loaded using gdb, the Raspberry Pi Pico is not reset -/// by default. Without this function, gdb sets the PC to the -/// beginning of the flash. This is not correct, as the RP2040 -/// has a more complex boot process. -/// -/// This function is set to be the entry point for gdb and is used -/// to send the RP2040 back in the bootloader so that all the boot -/// sequence is performed. -#[no_mangle] -#[naked] -pub unsafe extern "C" fn jump_to_bootloader() { - asm!( - " +#[allow(dead_code)] +extern "C" { + /// Entry point used for debugger + /// + /// When loaded using gdb, the Raspberry Pi Pico is not reset + /// by default. Without this function, gdb sets the PC to the + /// beginning of the flash. This is not correct, as the RP2040 + /// has a more complex boot process. + /// + /// This function is set to be the entry point for gdb and is used + /// to send the RP2040 back in the bootloader so that all the boot + /// sequence is performed. + fn jump_to_bootloader(); +} + +global_asm!( + " + .section .jump_to_bootloader, \"ax\" + .global jump_to_bootloader + .thumb_func + jump_to_bootloader: movs r0, #0 ldr r1, =(0xe0000000 + 0x0000ed08) str r0, [r1] ldmia r0!, {{r1, r2}} msr msp, r1 bx r2 - ", - options(noreturn) - ); -} + " +); fn init_clocks(peripherals: &Rp2040DefaultPeripherals) { // Start tick in watchdog