Skip to content

Commit 319076c

Browse files
Initialize RAM in assembly
1 parent 7ac8f78 commit 319076c

10 files changed

+32
-32
lines changed

cortex-m-rt/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ autoexamples = true
1717
links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked
1818

1919
[dependencies]
20-
r0 = "1.0"
2120
cortex-m-rt-macros = { path = "macros", version = "=0.6.11" }
2221
# Note: Do not depend on `cortex-m` here. This crate is used for testing `cortex-m`, so we need to
2322
# avoid pulling in multiple versions of `cortex-m`.

cortex-m-rt/asm.s

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ PreResetTrampoline:
6262
# set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF)
6363
ldr r0,=0xffffffff
6464
mov lr,r0
65+
66+
# run the pre-init code
67+
bl __pre_init
68+
69+
# initialize .data and .bss memory
70+
ldr r0,=__sbss
71+
ldr r1,=__ebss
72+
ldr r2,=0
73+
0:
74+
cmp r1, r0
75+
beq 1f
76+
stm r0!, {r2}
77+
b 0b
78+
1:
79+
80+
# copy to here
81+
ldr r0,=__sdata
82+
# ...up to here
83+
ldr r1,=__edata
84+
# copy from here
85+
ldr r2,=__sidata
86+
2:
87+
cmp r1, r0
88+
beq 3f
89+
# load 1 word from r2 to r3, inc r2
90+
ldm r2!, {r3}
91+
# store 1 word from r3 to r0, inc r0
92+
stm r0!, {r3}
93+
b 2b
94+
3:
95+
96+
# jump to Rust
6597
b Reset
6698
.cfi_endproc
6799
.size PreResetTrampoline, . - PreResetTrampoline

cortex-m-rt/bin/thumbv6m-none-eabi.a

456 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7em-none-eabi.a

488 Bytes
Binary file not shown.
488 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7m-none-eabi.a

488 Bytes
Binary file not shown.
472 Bytes
Binary file not shown.
488 Bytes
Binary file not shown.
488 Bytes
Binary file not shown.

cortex-m-rt/src/lib.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@
438438
#![no_std]
439439

440440
extern crate cortex_m_rt_macros as macros;
441-
extern crate r0;
442441

443442
use core::fmt;
444443
use core::sync::atomic::{self, Ordering};
@@ -923,41 +922,12 @@ pub fn heap_start() -> *mut u32 {
923922
#[doc(hidden)]
924923
#[link_section = ".vector_table.reset_vector"]
925924
#[no_mangle]
926-
#[cfg(not(armv6m))]
927-
pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;
928-
929-
#[doc(hidden)]
930-
#[link_section = ".vector_table.reset_vector"]
931-
#[no_mangle]
932-
#[cfg(armv6m)]
933925
pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = PreResetTrampoline;
934926

935927
#[doc(hidden)]
936928
#[link_section = ".Reset"]
937929
#[no_mangle]
938930
pub unsafe extern "C" fn Reset() -> ! {
939-
extern "C" {
940-
941-
// These symbols come from `link.x`
942-
static mut __sbss: u32;
943-
static mut __ebss: u32;
944-
945-
static mut __sdata: u32;
946-
static mut __edata: u32;
947-
static __sidata: u32;
948-
}
949-
950-
extern "Rust" {
951-
// This symbol will be provided by the user via `#[pre_init]`
952-
fn __pre_init();
953-
}
954-
955-
__pre_init();
956-
957-
// Initialize RAM
958-
r0::zero_bss(&mut __sbss, &mut __ebss);
959-
r0::init_data(&mut __sdata, &mut __edata, &__sidata);
960-
961931
#[allow(clippy::match_single_binding)]
962932
match () {
963933
#[cfg(not(has_fpu))]
@@ -1038,7 +1008,6 @@ pub enum Exception {
10381008
pub use self::Exception as exception;
10391009

10401010
extern "C" {
1041-
#[cfg(armv6m)]
10421011
fn PreResetTrampoline() -> !;
10431012

10441013
fn NonMaskableInt();

0 commit comments

Comments
 (0)