File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 607
607
//!
608
608
//! It is expected that the custom code does not clobber any registers.
609
609
//!
610
+ //! ### Example
611
+ //!
612
+ //! ```rust,no_run
613
+ //! core::arch::global_asm!(
614
+ //! r#"
615
+ //! .section .trap.start, "ax"
616
+ //! .extern _pre_default_start_trap_ret
617
+ //! .global _pre_default_start_trap
618
+ //!
619
+ //! // with the pre-default-start-trap feature enabled this code is executed before
620
+ //! // the code in _default_start_trap
621
+ //! _pre_default_start_trap:
622
+ //! // move SP to some save place if it's pointing below the RAM
623
+ //! // otherwise we won't be able to do anything reasonable
624
+ //! // (since we don't have a useable stack otherwise)
625
+ //! //
626
+ //! // most probably we will just print something and halt in this case
627
+ //! // we actually can't do anything else
628
+ //! csrw mscratch, t0
629
+ //! la t0, _dram_origin
630
+ //! bge sp, t0, 1f
631
+ //!
632
+ //! // set SP to the start of the stack
633
+ //! la sp, _stack_start
634
+ //!
635
+ //! 1:
636
+ //! // remember to not clobber any registers, restore t0 from mscratch
637
+ //! csrr t0, mscratch
638
+ //!
639
+ //! // jump back to continue with _default_start_trap
640
+ //! j _pre_default_start_trap_ret
641
+ //! "#
642
+ //! );
643
+ //! ```
610
644
//! [attr-entry]: attr.entry.html
611
645
//! [attr-exception]: attr.exception.html
612
646
//! [attr-external-interrupt]: attr.external_interrupt.html
You can’t perform that action at this time.
0 commit comments