187187//! required, but some bootloaders do not set VTOR before jumping to application code, leading to
188188//! your main function executing but interrupt handlers not being used.
189189//!
190+ //! ## `set-msplim`
191+ //!
192+ //! If this feature is enabled, the main stack pointer limit register (MSPLIM) is initialized in
193+ //! the reset handler to the `_stack_end` value from the linker script. This feature is only
194+ //! available on ARMv8-M Mainline and helps enforce stack limits by defining the lowest valid
195+ //! stack address.
196+ //!
190197//! ## `zero-init-ram`
191198//!
192199//! If this feature is enabled, RAM is initialized with zeros during startup from the `_ram_start`
266273//!
267274//! - `__INTERRUPTS`. This is the device specific interrupt portion of the vector table; its exact
268275//! size depends on the target device but if the `"device"` feature has not been enabled it will
269- //! have a size of 32 vectors (on ARMv6-M), 240 vectors (on ARMv7-M) or 496 vectors (on ARMv8-M).
276+ //! have a size of 32 vectors (on ARMv6-M), 240 vectors (on ARMv7-M, ARMv8-M Baseline) or 480
277+ //! vectors (on ARMv8-M Mainline).
270278//! This array is located after `__EXCEPTIONS` in the `.vector_table` section.
271279//!
272280//! - `__pre_init`. This is a function to be run before RAM is initialized. It defaults to an empty
@@ -544,6 +552,13 @@ cfg_global_asm! {
544552 ldr r1, =__vector_table
545553 str r1, [r0]" ,
546554
555+ // If enabled, set the Main Stack Pointer Limit (MSPLIM) to the end of the stack.
556+ // This feature is only available on ARMv8-M Mainline, where it helps enforce stack limits
557+ // by defining the lowest valid stack address.
558+ #[ cfg( all( armv8m_main, feature = "set-msplim" ) ) ]
559+ "ldr r0, =_stack_end
560+ msr MSPLIM, r0" ,
561+
547562 // Run user pre-init code which must be executed immediately after startup, before the
548563 // potentially time-consuming memory initialisation takes place.
549564 // Example use cases include disabling default watchdogs or enabling RAM.
@@ -1245,7 +1260,7 @@ pub static __EXCEPTIONS: [Vector; 14] = [
12451260
12461261// If we are not targeting a specific device we bind all the potential device specific interrupts
12471262// to the default handler
1248- #[ cfg( all( any( not( feature = "device" ) , test) , not( armv6m) , not( armv8m ) ) ) ]
1263+ #[ cfg( all( any( not( feature = "device" ) , test) , not( armv6m) , not( armv8m_main ) ) ) ]
12491264#[ doc( hidden) ]
12501265#[ cfg_attr( cortex_m, link_section = ".vector_table.interrupts" ) ]
12511266#[ no_mangle]
@@ -1257,18 +1272,18 @@ pub static __INTERRUPTS: [unsafe extern "C" fn(); 240] = [{
12571272 DefaultHandler
12581273} ; 240 ] ;
12591274
1260- // ARMv8-M can have up to 496 device specific interrupts
1261- #[ cfg( all( not( feature = "device" ) , armv8m ) ) ]
1275+ // ARMv8-M Mainline can have up to 480 device specific interrupts
1276+ #[ cfg( all( not( feature = "device" ) , armv8m_main ) ) ]
12621277#[ doc( hidden) ]
12631278#[ cfg_attr( cortex_m, link_section = ".vector_table.interrupts" ) ]
12641279#[ no_mangle]
1265- pub static __INTERRUPTS: [ unsafe extern "C" fn ( ) ; 496 ] = [ {
1280+ pub static __INTERRUPTS: [ unsafe extern "C" fn ( ) ; 480 ] = [ {
12661281 extern "C" {
12671282 fn DefaultHandler ( ) ;
12681283 }
12691284
12701285 DefaultHandler
1271- } ; 496 ] ;
1286+ } ; 480 ] ;
12721287
12731288// ARMv6-M can only have a maximum of 32 device specific interrupts
12741289#[ cfg( all( not( feature = "device" ) , armv6m) ) ]
0 commit comments