File tree Expand file tree Collapse file tree 7 files changed +35
-20
lines changed Expand file tree Collapse file tree 7 files changed +35
-20
lines changed Original file line number Diff line number Diff line change 5555 run : RUSTFLAGS="-C link-arg=-Tmemory.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features device
5656 - name : Build (include memory.x)
5757 run : RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features memory
58+ - name : Build (include memory.x, use trap region)
59+ run : RUSTFLAGS="-C link-arg=-Tdevice.x -C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features memory,trap-region
5860 - name : Build (include device.x and memory.x)
5961 run : RUSTFLAGS="-C link-arg=-Tlink.x" cargo build --package tests-build --target ${{ matrix.target }} --example ${{ matrix.example }} --features device,memory
6062
Original file line number Diff line number Diff line change @@ -42,3 +42,4 @@ no-interrupts = []
4242no-exceptions = []
4343device = []
4444memory = []
45+ trap-region = []
Original file line number Diff line number Diff line change @@ -143,8 +143,10 @@ SECTIONS
143143 /* point of the program. */
144144 KEEP(*(.init));
145145 . = ALIGN(4);
146+ {% if not contains(cfg.feature, "trap-region") %}
146147 *(.trap);
147148 *(.trap.rust);
149+ {% endif %}
148150 *(.text.abort);
149151 *(.text .text.*);
150152
@@ -167,6 +169,15 @@ SECTIONS
167169 __erodata = .;
168170 } > REGION_RODATA
169171
172+ {% if contains(cfg.feature, "trap-region") %}
173+ .trap : ALIGN(4)
174+ {
175+ . = ALIGN(4);
176+ *(.trap);
177+ *(.trap.rust);
178+ } > REGION_TRAP
179+ {% endif %}
180+
170181 .data : ALIGN({{ cfg.arch_width }})
171182 {
172183 . = ALIGN({{ cfg.arch_width }});
Original file line number Diff line number Diff line change 532532//! because when booting from elf, U-boot passes `argc` and `argv`. This feature also implies `single-hart`.
533533//! The only way to get boot-hart is through fdt, so other harts initialization is up to you.
534534//!
535+ //! ## `trap-region`
536+ //!
537+ //! Adds a dedicated trap memory region, `REGION_TRAP`, for placing `.trap` sections into. Enabling
538+ //! this feature and adding `REGION_ALIAS("REGION_TRAP", RAM);` to `memory.x` would for example place
539+ //! it in `RAM`.
540+ //!
541+ //! `REGION_TEXT` is usually placed in flash memory with a cache in front. Having a separate trap
542+ //! memory region makes it possible to always store interrupt and exceptions handlers in RAM,
543+ //! effectively bypassing cache contention and variable trap latency at the cost of increased RAM
544+ //! usage.
545+ //!
535546//! [attr-entry]: attr.entry.html
536547//! [attr-exception]: attr.exception.html
537548//! [attr-external-interrupt]: attr.external_interrupt.html
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ panic-halt = "1.0"
88riscv = { path = " ../riscv" }
99riscv-rt = { path = " ../riscv-rt" }
1010
11+ [build-dependencies ]
12+ minilink = " 0.2"
13+
1114[features ]
1215pre-init = [" riscv-rt/pre-init" ]
1316single-hart = [" riscv-rt/single-hart" ]
@@ -16,3 +19,4 @@ device = ["riscv-rt/device"]
1619memory = [" riscv-rt/memory" ]
1720no-exceptions = [" riscv-rt/no-exceptions" ]
1821no-interrupts = [" riscv-rt/no-interrupts" ]
22+ trap-region = [" riscv-rt/trap-region" ]
Original file line number Diff line number Diff line change 1- use std:: { env, fs:: File , io:: Write , path:: PathBuf } ;
2-
31fn main ( ) {
4- // Put device.x somewhere the linker can find it
5- let out = & PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
6- File :: create ( out. join ( "device.x" ) )
7- . unwrap ( )
8- . write_all ( include_bytes ! ( "device.x" ) )
9- . unwrap ( ) ;
10- println ! ( "cargo:rustc-link-search={}" , out. display( ) ) ;
11- println ! ( "cargo:rerun-if-changed=device.x" ) ;
12-
13- // Put memory.x somewhere the linker can find it
14- File :: create ( out. join ( "memory.x" ) )
15- . unwrap ( )
16- . write_all ( include_bytes ! ( "memory.x" ) )
17- . unwrap ( ) ;
18- println ! ( "cargo:rustc-link-search={}" , out. display( ) ) ;
19- println ! ( "cargo:rerun-if-changed=memory.x" ) ;
20-
21- println ! ( "cargo:rerun-if-changed=build.rs" ) ;
2+ minilink:: register_template ( "device.x" , "device.x" ) ;
3+ minilink:: register_template ( "memory.x" , "memory.x" ) ;
224}
Original file line number Diff line number Diff line change @@ -10,3 +10,7 @@ REGION_ALIAS("REGION_DATA", RAM);
1010REGION_ALIAS (" REGION_BSS" , RAM);
1111REGION_ALIAS (" REGION_HEAP" , RAM);
1212REGION_ALIAS (" REGION_STACK" , RAM);
13+
14+ {% if contains (cfg.feature , " trap-region" ) %}
15+ REGION_ALIAS (" REGION_TRAP" , RAM);
16+ {% endif %}
You can’t perform that action at this time.
0 commit comments