From 06ac005e0b2091d65c9ac6dba526c96e577d2568 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 25 Nov 2020 01:21:50 +0100 Subject: [PATCH 1/6] Initialize RAM in assembly --- Cargo.toml | 1 - asm.s | 32 ++++++++++++++++++++++++++++++++ bin/thumbv6m-none-eabi.a | Bin 1490 -> 1946 bytes bin/thumbv7em-none-eabi.a | Bin 1434 -> 1922 bytes bin/thumbv7em-none-eabihf.a | Bin 1434 -> 1922 bytes bin/thumbv7m-none-eabi.a | Bin 1434 -> 1922 bytes bin/thumbv8m.base-none-eabi.a | Bin 1494 -> 1966 bytes bin/thumbv8m.main-none-eabi.a | Bin 1438 -> 1926 bytes bin/thumbv8m.main-none-eabihf.a | Bin 1438 -> 1926 bytes src/lib.rs | 31 ------------------------------- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa5e775c..bbb6254b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ autoexamples = true links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked [dependencies] -r0 = "1.0" cortex-m-rt-macros = { path = "macros", version = "=0.6.11" } # Note: Do not depend on `cortex-m` here. This crate is used for testing `cortex-m`, so we need to # avoid pulling in multiple versions of `cortex-m`. diff --git a/asm.s b/asm.s index 58ed2741..7a361973 100644 --- a/asm.s +++ b/asm.s @@ -62,6 +62,38 @@ PreResetTrampoline: # set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF) ldr r0,=0xffffffff mov lr,r0 + + # run the pre-init code + bl __pre_init + + # initialize .data and .bss memory + ldr r0,=__sbss + ldr r1,=__ebss + ldr r2,=0 +0: + cmp r1, r0 + beq 1f + stm r0!, {r2} + b 0b +1: + + # copy to here + ldr r0,=__sdata + # ...up to here + ldr r1,=__edata + # copy from here + ldr r2,=__sidata +2: + cmp r1, r0 + beq 3f + # load 1 word from r2 to r3, inc r2 + ldm r2!, {r3} + # store 1 word from r3 to r0, inc r0 + stm r0!, {r3} + b 2b +3: + + # jump to Rust b Reset .cfi_endproc .size PreResetTrampoline, . - PreResetTrampoline diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a index 65684dad795ec305667e182e3c1c36d53c3698d8..674b34a3cdc3270ea16a914882ec7561127d68b7 100644 GIT binary patch delta 715 zcmZ8e&nrYx6h801H@t_LQGN}HG}2ojixDx4Nn%KeWTEt$Y2IkcujY-SNK#gWZc%pj z7M6-MYb)_b%*NiYGQRW7L-W=5zWbef&$;j1^HhBiJh@c|B7>**X5E}d3}3_*lWHk= z`rhAd#1F=buU|zyZcG@Hdn3xDmj5j1aou&|QGd|$ABC?%5s;T^C{}}fHVTRDK#iZ+ zd#K0azi%w_CcGR{@`@>|#c;Ei#;PK*5~_gpa$2-2jdBfNQyz<^nRz}^LM?RBGf?)a zGQV8rb7g)baUERe?(y{b%ofOR z?BNQFm}j7TjOn8$q-$&wb(09l~e7@xMR)2I1CaS^xk5 delta 280 zcmbQme~Ej-Ze}A(qlx=8gzqphfB>rrn9^Y2W8j_m)0BtNqs{H#a|VY0Krnd|;{ic7 zusn$1U|<1}lZ%#V5ykQ$!a;-k#!@d3D9N%pjz(9zggWmU4T3eFwdJ!nUQC*B9pLXERYW}&H;!) zzz3!V$Ofqey8}p<0x>fKLjjNigObVI?CP8ofb0OE<9H@pv&*wS0I~un$FnO-gaA!x Mg{lNmVD|%Q0LOwW%>V!Z diff --git a/bin/thumbv7em-none-eabi.a b/bin/thumbv7em-none-eabi.a index c4e1f47a90797702255d445357cc8adbb94ff630..a0302b105346b43061b38e2e2bf087831ffc85c9 100644 GIT binary patch delta 727 zcmZ9K-zx-B6vxlKv$JL~yV%9bg9l%`Y8vegEMur$CL8Kcs5Gk<=?Ve5V1@nIx7f4@*v!3 z5^FDFDE{lXPY*(?5m6F@>P-xEcx_A#jdh?v##FoP5^eD%&-t_6BPai5vt{hp`PQkYF+xa3{mb2zKfL(=?%NDaNYjpB%v1mIsy!h1X5q{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pOMxY8Q1P?&Y^D$}aqA92X=Vw9A^J!_a=mk`P^RJYF!sqDC?FA}z__YpS?eL%E zp?F>Myp4+QmEV`ERXA5zcx|w zi<|Gfl}ce<*7bS$NB5eC delta 316 zcmZ3-e~o*>Ze}A(vx)mOgdZ?5fB>rrn9^Y2W8j_m)0BtNqs{H#a|VY0Krnd|;}JnN zusn$1U|<1}liQiBIoW|MMv&m-+f4F|43mE|$#a6ZLO@mClbe~N)PqusQ%gWXJV2Z# z0Fpw`TtE)Uur!g$Q&=h{%d%Qd4rSfQX#sQ-P$dKRWPUbxP7ffD1I&wOQ)c9u+{~t| z82}Rlii709E&|e}K+Md*PynRBpk%TEuXih^ diff --git a/bin/thumbv8m.main-none-eabi.a b/bin/thumbv8m.main-none-eabi.a index cb216dcf1f911e326a581b2435c923b586e791fa..02bcf0280afbe913f5e51d621821acb65ae933d9 100644 GIT binary patch delta 787 zcmZ8fK}#D!82xs36F2H6TBD|TP%%hQTZ#w<>S2+BS`UJULJzV;vr51g%|=jY2~zM} z8SvQl;K8GJp?K)27yS`JuHHli<9i#|mVNN{eQ##IZ+5?*_rCN#h zNrOrlEc=0v9oUQY3=hy!_NTpDBuVWN8RIzGz(XobzM=MtOi}wpiqw95XBeQHETB-8 zja9hH{F5(GQ8i4&e3)qKE47=h`kSxI{_4(#w_YuM(jUzkePo`d3TCTsj$X3nQbjl$ zH5~oZ8gX1i5iEUS_19g@v!(-b9bXZ359EzSI7Z+`2Fi8B4wwR6kk~~%9+vgm!KmH= yVoYs8LR{fHgg4Wh7=C48qhDYeVL|#b6TVKLDdUBoP1r diff --git a/bin/thumbv8m.main-none-eabihf.a b/bin/thumbv8m.main-none-eabihf.a index cb216dcf1f911e326a581b2435c923b586e791fa..02bcf0280afbe913f5e51d621821acb65ae933d9 100644 GIT binary patch delta 787 zcmZ8fK}#D!82xs36F2H6TBD|TP%%hQTZ#w<>S2+BS`UJULJzV;vr51g%|=jY2~zM} z8SvQl;K8GJp?K)27yS`JuHHli<9i#|mVNN{eQ##IZ+5?*_rCN#h zNrOrlEc=0v9oUQY3=hy!_NTpDBuVWN8RIzGz(XobzM=MtOi}wpiqw95XBeQHETB-8 zja9hH{F5(GQ8i4&e3)qKE47=h`kSxI{_4(#w_YuM(jUzkePo`d3TCTsj$X3nQbjl$ zH5~oZ8gX1i5iEUS_19g@v!(-b9bXZ359EzSI7Z+`2Fi8B4wwR6kk~~%9+vgm!KmH= yVoYs8LR{fHgg4Wh7=C48qhDYeVL|#b6TVKLDdUBoP1r diff --git a/src/lib.rs b/src/lib.rs index ab4bc3f2..5285bd17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -438,7 +438,6 @@ #![no_std] extern crate cortex_m_rt_macros as macros; -extern crate r0; use core::fmt; use core::sync::atomic::{self, Ordering}; @@ -923,41 +922,12 @@ pub fn heap_start() -> *mut u32 { #[doc(hidden)] #[link_section = ".vector_table.reset_vector"] #[no_mangle] -#[cfg(not(armv6m))] -pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset; - -#[doc(hidden)] -#[link_section = ".vector_table.reset_vector"] -#[no_mangle] -#[cfg(armv6m)] pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = PreResetTrampoline; #[doc(hidden)] #[link_section = ".Reset"] #[no_mangle] pub unsafe extern "C" fn Reset() -> ! { - extern "C" { - - // These symbols come from `link.x` - static mut __sbss: u32; - static mut __ebss: u32; - - static mut __sdata: u32; - static mut __edata: u32; - static __sidata: u32; - } - - extern "Rust" { - // This symbol will be provided by the user via `#[pre_init]` - fn __pre_init(); - } - - __pre_init(); - - // Initialize RAM - r0::zero_bss(&mut __sbss, &mut __ebss); - r0::init_data(&mut __sdata, &mut __edata, &__sidata); - #[allow(clippy::match_single_binding)] match () { #[cfg(not(has_fpu))] @@ -1038,7 +1008,6 @@ pub enum Exception { pub use self::Exception as exception; extern "C" { - #[cfg(armv6m)] fn PreResetTrampoline() -> !; fn NonMaskableInt(); From 35651307472e59f18cad7b5a6e1dfeed81df9efb Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 25 Nov 2020 01:29:05 +0100 Subject: [PATCH 2/6] Update compile-fail test --- tests/compile-fail/interrupt-not-reexported.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compile-fail/interrupt-not-reexported.rs b/tests/compile-fail/interrupt-not-reexported.rs index 1ac674bd..6a1dd6e8 100644 --- a/tests/compile-fail/interrupt-not-reexported.rs +++ b/tests/compile-fail/interrupt-not-reexported.rs @@ -11,5 +11,5 @@ fn foo() -> ! { loop {} } -#[interrupt] //~ ERROR failed to resolve: use of undeclared type or module `interrupt` +#[interrupt] //~ ERROR failed to resolve: use of undeclared crate or module `interrupt` fn USART1() {} From 90ca1e37c6d3acca99c9b499afa5ab806a6b85c5 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 6 Jan 2021 17:38:26 +0100 Subject: [PATCH 3/6] Restore LR after __pre_init call --- asm.s | 8 ++++++-- bin/thumbv6m-none-eabi.a | Bin 1946 -> 1950 bytes bin/thumbv7em-none-eabi.a | Bin 1922 -> 1926 bytes bin/thumbv7em-none-eabihf.a | Bin 1922 -> 1926 bytes bin/thumbv7m-none-eabi.a | Bin 1922 -> 1926 bytes bin/thumbv8m.base-none-eabi.a | Bin 1966 -> 1970 bytes bin/thumbv8m.main-none-eabi.a | Bin 1926 -> 1930 bytes bin/thumbv8m.main-none-eabihf.a | Bin 1926 -> 1930 bytes 8 files changed, 6 insertions(+), 2 deletions(-) diff --git a/asm.s b/asm.s index 7a361973..1cb310a7 100644 --- a/asm.s +++ b/asm.s @@ -60,12 +60,16 @@ FpuTrampoline: .cfi_startproc PreResetTrampoline: # set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF) - ldr r0,=0xffffffff - mov lr,r0 + ldr r4,=0xffffffff + mov lr,r4 # run the pre-init code bl __pre_init + # the call above clobbers LR, but tools may expect LR to be 0xFFFFFFFF when reaching the first + # call frame, so we restore it to its previous value (r4 is preserved by subroutines) + mov lr,r4 + # initialize .data and .bss memory ldr r0,=__sbss ldr r1,=__ebss diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a index 674b34a3cdc3270ea16a914882ec7561127d68b7..207dad2cd5e306e4e9010bdbb2bfec409a3444a2 100644 GIT binary patch delta 139 zcmbQmKaYRH9wt+xiTgAdBPKrgVDecu*^seNM1TPSG=NMOPCk~+n;0Ef7#${mX7y(b znC#5v&loXzGMhG|%Vb3+VZlC$RL6m?=MkpHqi{To3 delta 119 zcmbQoKZ}3D9wrluiTgAdLnc1=VDf02Y{*zBz{7w58bIdeZHx{qj5d?Mv-&goOm=7U zXAGGWoV!JF}}xtYBtfn1(Qnff33E E0RNsDQUCw| delta 99 zcmZqUZ{nY@m(gV6J`F~jiO=1b4B95^GiD3$Fd%>qkhyssqX7$}%H;d3{){G*_1XLx sZ6?>VX)`)ZUd^V=STgxMn>yo@$=`t_!(@4Ob;bpg-GSti$@%Q!0N1b?EdT%j diff --git a/bin/thumbv7em-none-eabihf.a b/bin/thumbv7em-none-eabihf.a index a0302b105346b43061b38e2e2bf087831ffc85c9..18509c15be0a375804fd8560ca395cb429a328a6 100644 GIT binary patch delta 122 zcmZqTZ{we^m(gP4J`F~PiO=1bOqNa7XUrB6U_byJAk&qTk7e^JMgtZ`jmfuJ{TVGL zYqR+?I!vx+(`Iy;yqry$v10ORHg(1qlRpDVmdVoW>WoV!JF}}xtYBtfn1(Qnff33E E0RNsDQUCw| delta 99 zcmZqUZ{nY@m(gV6J`F~jiO=1b4B95^GiD3$Fd%>qkhyssqX7$}%H;d3{){G*_1XLx sZ6?>VX)`)ZUd^V=STgxMn>yo@$=`t_!(@4Ob;bpg-GSti$@%Q!0N1b?EdT%j diff --git a/bin/thumbv7m-none-eabi.a b/bin/thumbv7m-none-eabi.a index 0298e6493885d0cefe1d878cdd7e93b1bcb3d2f2..59fdb28108aa63477a4047cf0fdb4392197fac8a 100644 GIT binary patch delta 122 zcmZqTZ{we^m(gP4J`F~PiO=1bOqNa7XUrB6U_byJAk&qTk7e^JMgtZ`jmfuJ{TVGL zYqR+?I!vx+(`Iy;yqry$v10ORHg(1qlRpDVmdVoW>WoV!JF}}xtYBtfn1(Qnff33E E0RNsDQUCw| delta 99 zcmZqUZ{nY@m(gV6J`F~jiO=1b4B95^GiD3$Fd%>qkhyssqX7$}%H;d3{){G*_1XLx sZ6?>VX)`)ZUd^V=STgxMn>yo@$=`t_!(@4Ob;bpg-GSti$@%Q!0N1b?EdT%j diff --git a/bin/thumbv8m.base-none-eabi.a b/bin/thumbv8m.base-none-eabi.a index 8a3cfcffaf72829860b72edf076869220ba33d76..4c287214f9d0fd6de990fc3b5a403f4d348dc872 100644 GIT binary patch delta 125 zcmZ3-zlnds9wu|6iTgAdb0$9bVDecu*^seNM1TPSw17+(PCk~+n;1h_7(*trv-vZo zOb!Q`5U?b delta 119 zcmdnQzm9*x9wsx3iTgAdGbTRwVDf02Y{*zBz{7w5T0rLJZHyr-i~*Cm+58z3CPxFw zjLECnv>6>HUuRQhTrl}Jn>yp0$;#~Nj69RQf#jLV#q8=57nm6srXdVsV1%*(C+HeR diff --git a/bin/thumbv8m.main-none-eabi.a b/bin/thumbv8m.main-none-eabi.a index 02bcf0280afbe913f5e51d621821acb65ae933d9..5a23da5ded162b745f0f1bb3e3226089a7e95fd4 100644 GIT binary patch delta 104 zcmZqU@8X}ZhsoGz;yw*Vmx<5am`s*U)@RHX5nw<79U#+{laFQdDn=6)MxDv`S^XJp wChN2LGrCN!XVV6ftJ#zpYbKv(Q)hfJ`8$y0m@Ln(&bVT-JCIy6IiFn|06`5JIsgCw delta 135 zcmeC;Z{we^hsnrd;yw*Vhl$VKm<-w`>oaBx@Gu~N4v@Kd9is^gqsHXNtp1D^la1N@ z8674!vuOiKMJ8dvQlJV>Aa(#^5U7}ZnN6MX$>iTal4Y_oyE@~N$=>Yh5-XS)7^Xp# JfJsIu8vy6#8EgOm diff --git a/bin/thumbv8m.main-none-eabihf.a b/bin/thumbv8m.main-none-eabihf.a index 02bcf0280afbe913f5e51d621821acb65ae933d9..5a23da5ded162b745f0f1bb3e3226089a7e95fd4 100644 GIT binary patch delta 104 zcmZqU@8X}ZhsoGz;yw*Vmx<5am`s*U)@RHX5nw<79U#+{laFQdDn=6)MxDv`S^XJp wChN2LGrCN!XVV6ftJ#zpYbKv(Q)hfJ`8$y0m@Ln(&bVT-JCIy6IiFn|06`5JIsgCw delta 135 zcmeC;Z{we^hsnrd;yw*Vhl$VKm<-w`>oaBx@Gu~N4v@Kd9is^gqsHXNtp1D^la1N@ z8674!vuOiKMJ8dvQlJV>Aa(#^5U7}ZnN6MX$>iTal4Y_oyE@~N$=>Yh5-XS)7^Xp# JfJsIu8vy6#8EgOm From b687c61a74d6c353dea858ed8bd7089b899a3773 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 6 Jan 2021 17:40:40 +0100 Subject: [PATCH 4/6] Document `__pre_init` call constraints --- asm.s | 5 +++++ bin/thumbv6m-none-eabi.a | Bin 1950 -> 1966 bytes bin/thumbv7em-none-eabi.a | Bin 1926 -> 1942 bytes bin/thumbv7em-none-eabihf.a | Bin 1926 -> 1942 bytes bin/thumbv7m-none-eabi.a | Bin 1926 -> 1942 bytes bin/thumbv8m.base-none-eabi.a | Bin 1970 -> 1950 bytes bin/thumbv8m.main-none-eabi.a | Bin 1930 -> 1946 bytes bin/thumbv8m.main-none-eabihf.a | Bin 1930 -> 1946 bytes 8 files changed, 5 insertions(+) diff --git a/asm.s b/asm.s index 1cb310a7..a5c340e0 100644 --- a/asm.s +++ b/asm.s @@ -64,6 +64,11 @@ PreResetTrampoline: mov lr,r4 # run the pre-init code + # use cases of __pre_init include + # a) disabling an on-by-default watchdog and + # b) enabling off-by-default RAM + # this means it must be done before the potentially slow RAM init code below is executed, and RAM + # must not be accessed before this call bl __pre_init # the call above clobbers LR, but tools may expect LR to be 0xFFFFFFFF when reaching the first diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv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nY@ni0He<2dZuPZoyE+|jGFum3_?J;G$1Vkq`3qc7}!9xFav`YNL-SE z0i>5nWU>m2k{U<}6AuG}1c+u~U{HbbH9#~_p9z@1xrC*Pkx^svdscr&i^=wE+Kdj9 zv)Pn^WIvla>k^#C;l!0TZA5iY{~G@Zj|H|G>c1=)`z|<-qUfY#!{B-5Hf9XD}KG z@Gu~N9*{YC9peE(5CZ}@7+8P|gUR_!&5U}BKQl2Z3NSDT0fo|lv_uG?1eM z5|^4R!=j|;0Aw;rLX-50jC_#C;l!4ilgI3UhdHc=~@}U}|(?yufnc_j5K6w#lB1%9HaL4MYSO z5I_gWbmin@nY@ni0He<2dZuPZoyE+|jGFum3_?J;G$1Vkq`3qc7}!9xFav`YNL-SE z0i>5nWU>m2k{U<}6AuG}1c+u~U{HbbH9#~_p9z@1xrC*Pkx^svdscr&i^=wE+Kdj9 zv)Pn^WIvla>k^v&CO-GqSmws*!RhJniGiuniSYuxpb!HS z&=3_UUjsz5LG=UW!TLFXf_lZ3o9D6QFfuw!=4SI}4451ZBqJuTX43|WTxU~eoG|$} zn>yp0$;#~NnmmjQ3>$!$52%qJh(WFdI+}qKh?#*H2KG!YW>=Ru02G=A69UpejbH!( DgOfK< delta 344 zcmbQozlnds9!B$tdo>wzCO-Gq;Pl|~boj);)ab-`f#tyO=jqMDX$A%ZAk8Gkz+eKR#TghZK(qt{gAIt5WMFUr(NYWyA|RTN zfdMGRzyvfz1qEIi6iz;tEh` M8cYaC12uvH0G_uvrvLx| diff --git a/bin/thumbv8m.main-none-eabi.a b/bin/thumbv8m.main-none-eabi.a index 5a23da5ded162b745f0f1bb3e3226089a7e95fd4..691a09575338a53bf61701af7b9c9118e63affcc 100644 GIT binary patch delta 303 zcmeC;pT$3650i<-#C;l!ArqhbiY{~G@Zj|H|G>c1=)`z|<-qUfY#!{B-5Hf9XD}KG z@Gu~N9*{YC9pe!}5CZ}@7+8P|gUQ8A&5U}BzcVo^3NSDT0fo|lv_uG?1eM z5|^5+z@nt*0Aw;rLXo3UhdHc=~@}U}|(?yufnc_j5K6w#lB1%9HaL4MYSO z5I_gWbmin@nY@ni2&2yAW~OFFoyF|TjGFum3_?J;G$1Vkq`3qc7}!9xFav`YNL-SE z0i>5nWU>Z}k{U<}6AuG}1c+u~U{HbbH9#~_p9z@1xq_vN5opV2R)0pD$;S|d;4*nKn>yc1=)`z|<-qUfY#!{B-5Hf9XD}KG z@Gu~N9*{YC9pe!}5CZ}@7+8P|gUQ8A&5U}BzcVo^3NSDT0fo|lv_uG?1eM z5|^5+z@nt*0Aw;rLXo3UhdHc=~@}U}|(?yufnc_j5K6w#lB1%9HaL4MYSO z5I_gWbmin@nY@ni2&2yAW~OFFoyF|TjGFum3_?J;G$1Vkq`3qc7}!9xFav`YNL-SE z0i>5nWU>Z}k{U<}6AuG}1c+u~U{HbbH9#~_p9z@1xq_vN5opV2R)0pD$;S|d;4*nKn>y Date: Wed, 6 Jan 2021 17:43:05 +0100 Subject: [PATCH 5/6] Update `PreResetTrampoline` docs --- asm.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asm.s b/asm.s index a5c340e0..6cae842a 100644 --- a/asm.s +++ b/asm.s @@ -49,8 +49,6 @@ FpuTrampoline: .cfi_endproc .size FpuTrampoline, . - FpuTrampoline - # ARMv6-M leaves LR in an unknown state on Reset - # this trampoline sets LR before it's pushed onto the stack by Reset .section .PreResetTrampoline, "ax" .global PreResetTrampoline # .type and .thumb_func are both required; otherwise its Thumb bit does not @@ -58,6 +56,8 @@ FpuTrampoline: .type PreResetTrampoline,%function .thumb_func .cfi_startproc + # Main entry point. This initializes RAM and invokes __pre_init, which cannot be done in Rust code + # without invoking UB. It then jumps to the Rust `Reset` function. PreResetTrampoline: # set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF) ldr r4,=0xffffffff From 599c58db70c5dd4eb1dfb92e1dad7c80ed848937 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Thu, 21 Jan 2021 02:39:12 +0000 Subject: [PATCH 6/6] Update Reset-in-asm. * Use arm-none-eabi-gcc to assemble, allowing use of preprocessor to conditionally enable the FPU for eabihf targets. * Remove has_fpu configuration from build.rs. * Remove FpuTrampoline as no longer required. * Remove the Rust Reset method entirely, since the asm Reset can now enable FPU and jump to user main. --- asm.S | 105 +++++++++++++++++++++++++++++++ asm.s | 108 -------------------------------- assemble.sh | 14 +++-- bin/thumbv6m-none-eabi.a | Bin 1966 -> 1618 bytes bin/thumbv7em-none-eabi.a | Bin 1942 -> 1598 bytes bin/thumbv7em-none-eabihf.a | Bin 1942 -> 1622 bytes bin/thumbv7m-none-eabi.a | Bin 1942 -> 1598 bytes bin/thumbv8m.base-none-eabi.a | Bin 1950 -> 1622 bytes bin/thumbv8m.main-none-eabi.a | Bin 1946 -> 1602 bytes bin/thumbv8m.main-none-eabihf.a | Bin 1946 -> 1626 bytes build.rs | 8 --- link.x.in | 9 ++- src/lib.rs | 63 +++++-------------- 13 files changed, 134 insertions(+), 173 deletions(-) create mode 100644 asm.S delete mode 100644 asm.s diff --git a/asm.S b/asm.S new file mode 100644 index 00000000..62541298 --- /dev/null +++ b/asm.S @@ -0,0 +1,105 @@ + .cfi_sections .debug_frame + + # Notes for function attributes: + # .type and .thumb_func are _both_ required, otherwise the Thumb mode bit + # will not be set and an invalid vector table is generated. + # LLD requires that section flags are set explicitly. + + .section .HardFaultTrampoline, "ax" + .global HardFaultTrampoline + .type HardFaultTrampoline,%function + .thumb_func + .cfi_startproc + # HardFault exceptions are bounced through this trampoline which grabs the + # stack pointer at the time of the exception and passes it to the user's + # HardFault handler in r0. +HardFaultTrampoline: + # Depending on the stack mode in EXC_RETURN, fetch stack pointer from + # PSP or MSP. + mov r0, lr + mov r1, #4 + tst r0, r1 + bne 0f + mrs r0, MSP + b HardFault +0: + mrs r0, PSP + b HardFault + .cfi_endproc + .size HardFaultTrampoline, . - HardFaultTrampoline + + .section .Reset, "ax" + .global Reset + .type Reset,%function + .thumb_func + .cfi_startproc + # Main entry point after reset. This jumps to the user __pre_init function, + # which cannot be called from Rust code without invoking UB, then + # initialises RAM. If the target has an FPU, it is enabled. Finally, jumps + # to the user main function. +Reset: + # ARMv6-M does not initialise LR, but many tools expect it to be 0xFFFF_FFFF + # when reaching the first call frame, so we set it at startup. + # ARMv7-M and above initialise LR to 0xFFFF_FFFF at reset. + ldr r4,=0xffffffff + mov lr,r4 + + # Run user pre-init code, which must be executed immediately after startup, + # before the potentially time-consuming memory initialisation takes place. + # Example use cases include disabling default watchdogs or enabling RAM. + bl __pre_init + + # Restore LR after calling __pre_init (r4 is preserved by subroutines). + mov lr,r4 + + # Initialise .bss memory. `__sbss` and `__ebss` come from the linker script. + ldr r0,=__sbss + ldr r1,=__ebss + mov r2,#0 +0: + cmp r1, r0 + beq 1f + stm r0!, {r2} + b 0b +1: + + # Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the + # linker script. Copy from r2 into r0 until r0 reaches r1. + ldr r0,=__sdata + ldr r1,=__edata + ldr r2,=__sidata +2: + cmp r1, r0 + beq 3f + # load 1 word from r2 to r3, inc r2 + ldm r2!, {r3} + # store 1 word from r3 to r0, inc r0 + stm r0!, {r3} + b 2b +3: + +#ifdef HAS_FPU + # Conditionally enable the FPU. + # Address of SCB.CPACR. + ldr r0, =0xE000ED88 + # Enable access to CP10 and CP11 from both privileged and unprivileged mode. + ldr r1, =(0b1111 << 20) + # RMW. + ldr r2, [r0] + orr r2, r2, r1 + str r2, [r0] + # Barrier is required on some processors. + dsb + isb +#endif + +4: + # Jump to user main function. We use bl for the extended range, but the + # user main function may not return. + bl main + + # Trap on return. + udf + + .cfi_endproc + .size Reset, . - Reset diff --git a/asm.s b/asm.s deleted file mode 100644 index 6cae842a..00000000 --- a/asm.s +++ /dev/null @@ -1,108 +0,0 @@ - .cfi_sections .debug_frame - - # LLD requires that the section flags are explicitly set here - .section .HardFaultTrampoline, "ax" - .global HardFaultTrampoline - # .type and .thumb_func are both required; otherwise its Thumb bit does not - # get set and an invalid vector table is generated - .type HardFaultTrampoline,%function - .thumb_func - .cfi_startproc -HardFaultTrampoline: - # depending on the stack mode in EXC_RETURN, fetch stack pointer from - # PSP or MSP - mov r0, lr - mov r1, #4 - tst r0, r1 - bne 0f - mrs r0, MSP - b HardFault -0: - mrs r0, PSP - b HardFault - .cfi_endproc - .size HardFaultTrampoline, . - HardFaultTrampoline - - .section .text.FpuTrampoline, "ax" - .global FpuTrampoline - # .type and .thumb_func are both required; otherwise its Thumb bit does not - # get set and an invalid vector table is generated - .type FpuTrampoline,%function - .thumb_func - .cfi_startproc - # This enables the FPU and jumps to the main function. -FpuTrampoline: - # Address of SCB.CPACR. - ldr r0, =0xE000ED88 - # Enable access to CP10 and CP11 from both privileged and unprivileged mode. - ldr r1, =(0b1111 << 20) - # RMW. - ldr r2, [r0] - orr r2, r2, r1 - str r2, [r0] - # Barrier is required on some processors. - dsb - isb - # Hand execution over to `main`. - bl main - # Note: `main` must not return. `bl` is used only because it has a wider range than `b`. - .cfi_endproc - .size FpuTrampoline, . - FpuTrampoline - - .section .PreResetTrampoline, "ax" - .global PreResetTrampoline - # .type and .thumb_func are both required; otherwise its Thumb bit does not - # get set and an invalid vector table is generated - .type PreResetTrampoline,%function - .thumb_func - .cfi_startproc - # Main entry point. This initializes RAM and invokes __pre_init, which cannot be done in Rust code - # without invoking UB. It then jumps to the Rust `Reset` function. -PreResetTrampoline: - # set LR to the initial value used by the ARMv7-M (0xFFFF_FFFF) - ldr r4,=0xffffffff - mov lr,r4 - - # run the pre-init code - # use cases of __pre_init include - # a) disabling an on-by-default watchdog and - # b) enabling off-by-default RAM - # this means it must be done before the potentially slow RAM init code below is executed, and RAM - # must not be accessed before this call - bl __pre_init - - # the call above clobbers LR, but tools may expect LR to be 0xFFFFFFFF when reaching the first - # call frame, so we restore it to its previous value (r4 is preserved by subroutines) - mov lr,r4 - - # initialize .data and .bss memory - ldr r0,=__sbss - ldr r1,=__ebss - ldr r2,=0 -0: - cmp r1, r0 - beq 1f - stm r0!, {r2} - b 0b -1: - - # copy to here - ldr r0,=__sdata - # ...up to here - ldr r1,=__edata - # copy from here - ldr r2,=__sidata -2: - cmp r1, r0 - beq 3f - # load 1 word from r2 to r3, inc r2 - ldm r2!, {r3} - # store 1 word from r3 to r0, inc r0 - stm r0!, {r3} - b 2b -3: - - # jump to Rust - b Reset - .cfi_endproc - .size PreResetTrampoline, . - PreResetTrampoline diff --git a/assemble.sh b/assemble.sh index cdb32054..b914fedd 100755 --- a/assemble.sh +++ b/assemble.sh @@ -9,21 +9,25 @@ crate=cortex-m-rt # remove existing blobs because otherwise this will append object files to the old blobs rm -f bin/*.a -arm-none-eabi-as -march=armv6s-m asm.s -o bin/$crate.o +arm-none-eabi-gcc -c -march=armv6s-m asm.S -o bin/$crate.o ar crs bin/thumbv6m-none-eabi.a bin/$crate.o -arm-none-eabi-as -march=armv7-m asm.s -o bin/$crate.o +arm-none-eabi-gcc -c -march=armv7-m asm.S -o bin/$crate.o ar crs bin/thumbv7m-none-eabi.a bin/$crate.o -arm-none-eabi-as -march=armv7e-m asm.s -o bin/$crate.o +arm-none-eabi-gcc -c -march=armv7e-m asm.S -o bin/$crate.o ar crs bin/thumbv7em-none-eabi.a bin/$crate.o + +arm-none-eabi-gcc -c -march=armv7e-m asm.S -DHAS_FPU -o bin/$crate.o ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o -arm-none-eabi-as -march=armv8-m.base asm.s -o bin/$crate.o +arm-none-eabi-gcc -c -march=armv8-m.base asm.S -o bin/$crate.o ar crs bin/thumbv8m.base-none-eabi.a bin/$crate.o -arm-none-eabi-as -march=armv8-m.main asm.s -o bin/$crate.o +arm-none-eabi-gcc -c -march=armv8-m.main asm.S -o bin/$crate.o ar crs bin/thumbv8m.main-none-eabi.a bin/$crate.o + +arm-none-eabi-gcc -c -march=armv8-m.main -DHAS_FPU asm.S -o bin/$crate.o ar crs bin/thumbv8m.main-none-eabihf.a bin/$crate.o rm bin/$crate.o diff --git a/bin/thumbv6m-none-eabi.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>kyK3u`ELUd`sZt^~}dTkbEY5KVK2}4pfTd<2U8! zTLB;64d!EB$+rcc`J}vuGbaJ8K0pWI4?&ra`^kHPuPq<3=w%yqY9Gd&KkpO3yB>Le0IQtjSpWb4 diff --git a/build.rs b/build.rs index 67cdfaba..c56f14c4 100644 --- a/build.rs +++ b/build.rs @@ -7,8 +7,6 @@ fn main() { let target = env::var("TARGET").unwrap(); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - has_fpu(&target); - if target.starts_with("thumbv") { fs::copy( format!("bin/{}.a", target), @@ -81,9 +79,3 @@ handlers."); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=link.x.in"); } - -fn has_fpu(target: &str) { - if target.ends_with("eabihf") { - println!("cargo:rustc-cfg=has_fpu"); - } -} diff --git a/link.x.in b/link.x.in index f1a921d0..78fa8255 100644 --- a/link.x.in +++ b/link.x.in @@ -23,8 +23,9 @@ INCLUDE memory.x /* # Entry point = reset vector */ +EXTERN(__RESET_VECTOR); +EXTERN(Reset); ENTRY(Reset); -EXTERN(__RESET_VECTOR); /* depends on the `Reset` symbol */ /* # Exception vectors */ /* This is effectively weak aliasing at the linker level */ @@ -85,13 +86,15 @@ SECTIONS /* ### .text */ .text _stext : { - /* place these 2 close to each other or the `b` instruction will fail to link */ - *(.PreResetTrampoline); *(.Reset); *(.text .text.*); + + /* The HardFaultTrampoline uses the `b` instruction to enter `HardFault`, + so must be placed close to it. */ *(.HardFaultTrampoline); *(.HardFault.*); + . = ALIGN(4); /* Pad .text to the alignment to workaround overlapping load section bug in old lld */ } > FLASH . = ALIGN(4); /* Ensure __etext is aligned if something unaligned is inserted after .text */ diff --git a/src/lib.rs b/src/lib.rs index 5285bd17..e5e290d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,11 +192,9 @@ //! //! One will always find the following (unmangled) symbols in `cortex-m-rt` applications: //! -//! - `Reset`. This is the reset handler. The microcontroller will executed this function upon +//! - `Reset`. This is the reset handler. The microcontroller will execute this function upon //! booting. This function will call the user program entry point (cf. [`#[entry]`][attr-entry]) -//! using the `main` symbol so you may also find that symbol in your program; if you do, `main` -//! will contain your application code. Some other times `main` gets inlined into `Reset` so you -//! won't find it. +//! using the `main` symbol so you will also find that symbol in your program. //! //! - `DefaultHandler`. This is the default handler. If not overridden using `#[exception] fn //! DefaultHandler(..` this will be an infinite loop. @@ -212,8 +210,8 @@ //! the initial value of the stack pointer; this is where the stack will be located -- the stack //! grows downwards towards smaller addresses. //! -//! - `__RESET_VECTOR`. This is the reset vector, a pointer into the `Reset` handler. This vector is -//! located in the `.vector_table` section after `__STACK_START`. +//! - `__RESET_VECTOR`. This is the reset vector, a pointer to the `Reset` function. This vector +//! is located in the `.vector_table` section after `__STACK_START`. //! //! - `__EXCEPTIONS`. This is the core exceptions portion of the vector table; it's an array of 14 //! exception vectors, which includes exceptions like `HardFault` and `SysTick`. This array is @@ -226,19 +224,11 @@ //! //! - `__pre_init`. This is a function to be run before RAM is initialized. It defaults to an empty //! function. The function called can be changed by applying the [`#[pre_init]`][attr-pre_init] -//! attribute to a function. The empty function is not optimized out by default, but if an empty -//! function is passed to [`#[pre_init]`][attr-pre_init] the function call will be optimized out. +//! attribute to a function. //! //! If you override any exception handler you'll find it as an unmangled symbol, e.g. `SysTick` or //! `SVCall`, in the output of `objdump`, //! -//! If you are targeting the `thumbv7em-none-eabihf` target you'll also see a `ResetTrampoline` -//! symbol in the output. To avoid the compiler placing FPU instructions before the FPU has been -//! enabled (cf. `vpush`) `Reset` calls the function `ResetTrampoline` which is marked as -//! `#[inline(never)]` and `ResetTrampoline` calls `main`. The compiler is free to inline `main` -//! into `ResetTrampoline` but it can't inline `ResetTrampoline` into `Reset` -- the FPU is enabled -//! in `Reset`. -//! //! # Advanced usage //! //! ## Setting the program entry point @@ -248,9 +238,9 @@ //! guarantees. //! //! The `Reset` handler will call a symbol named `main` (unmangled) *after* initializing `.bss` and -//! `.data`, and enabling the FPU (if the target is `thumbv7em-none-eabihf`). A function with the -//! `entry` attribute will be set to have the export name "`main`"; in addition, its mutable -//! statics are turned into safe mutable references (see [`#[entry]`][attr-entry] for details). +//! `.data`, and enabling the FPU (if the target has an FPU). A function with the `entry` attribute +//! will be set to have the export name "`main`"; in addition, its mutable statics are turned into +//! safe mutable references (see [`#[entry]`][attr-entry] for details). //! //! The unmangled `main` symbol must have signature `extern "C" fn() -> !` or its invocation from //! `Reset` will result in undefined behavior. @@ -411,7 +401,7 @@ //! *(.ccmram .ccmram.*); //! . = ALIGN(4); //! } > CCMRAM -//! } INSERT AFTER .bss; +//! } //! ``` //! //! You can then use something like this to place a variable into this specific section of memory: @@ -700,8 +690,8 @@ pub use macros::exception; /// /// # Safety /// -/// The function will be called before static variables are initialized. Any access of static -/// variables will result in undefined behavior. +/// The function will be called before memory is initialized, as soon as possible after reset. Any +/// access of memory, including any static variables, will result in undefined behavior. /// /// **Warning**: Due to [rvalue static promotion][rfc1414] static variables may be accessed whenever /// taking a reference to a constant. This means that even trivial expressions such as `&1` in the @@ -918,36 +908,11 @@ pub fn heap_start() -> *mut u32 { unsafe { &mut __sheap } } -/* Entry point */ +// Entry point is Reset. #[doc(hidden)] #[link_section = ".vector_table.reset_vector"] #[no_mangle] -pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = PreResetTrampoline; - -#[doc(hidden)] -#[link_section = ".Reset"] -#[no_mangle] -pub unsafe extern "C" fn Reset() -> ! { - #[allow(clippy::match_single_binding)] - match () { - #[cfg(not(has_fpu))] - () => { - extern "C" { - // This symbol will be provided by the user via `#[entry]` - fn main() -> !; - } - main() - } - #[cfg(has_fpu)] - () => { - extern "C" { - fn FpuTrampoline() -> !; - } - - FpuTrampoline() - } - } -} +pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset; #[allow(unused_variables)] #[doc(hidden)] @@ -1008,7 +973,7 @@ pub enum Exception { pub use self::Exception as exception; extern "C" { - fn PreResetTrampoline() -> !; + fn Reset() -> !; fn NonMaskableInt();