diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/riscv32/Cargo.toml | 4 | ||||
| -rw-r--r-- | tests/riscv32/link.x | 214 |
2 files changed, 216 insertions, 2 deletions
diff --git a/tests/riscv32/Cargo.toml b/tests/riscv32/Cargo.toml index 38fb2deec..94eda3c09 100644 --- a/tests/riscv32/Cargo.toml +++ b/tests/riscv32/Cargo.toml | |||
| @@ -11,8 +11,8 @@ embassy-executor = { version = "0.5.0", path = "../../embassy-executor", feature | |||
| 11 | embassy-time = { version = "0.3.0", path = "../../embassy-time" } | 11 | embassy-time = { version = "0.3.0", path = "../../embassy-time" } |
| 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 13 | 13 | ||
| 14 | riscv-rt = "0.11" | 14 | riscv-rt = "0.12.2" |
| 15 | riscv = { version = "0.10", features = ["critical-section-single-hart"] } | 15 | riscv = { version = "0.11.1", features = ["critical-section-single-hart"] } |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | [profile.dev] | 18 | [profile.dev] |
diff --git a/tests/riscv32/link.x b/tests/riscv32/link.x new file mode 100644 index 000000000..4076b0c68 --- /dev/null +++ b/tests/riscv32/link.x | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | /* # EMBASSY notes | ||
| 2 | This file is a workaround for https://github.com/rust-embedded/riscv/issues/196 | ||
| 3 | Remove when fixed upstream. | ||
| 4 | */ | ||
| 5 | /* # Developer notes | ||
| 6 | |||
| 7 | - Symbols that start with a double underscore (__) are considered "private" | ||
| 8 | |||
| 9 | - Symbols that start with a single underscore (_) are considered "semi-public"; they can be | ||
| 10 | overridden in a user linker script, but should not be referred from user code (e.g. `extern "C" { | ||
| 11 | static mut _heap_size }`). | ||
| 12 | |||
| 13 | - `EXTERN` forces the linker to keep a symbol in the final binary. We use this to make sure a | ||
| 14 | symbol if not dropped if it appears in or near the front of the linker arguments and "it's not | ||
| 15 | needed" by any of the preceding objects (linker arguments) | ||
| 16 | |||
| 17 | - `PROVIDE` is used to provide default values that can be overridden by a user linker script | ||
| 18 | |||
| 19 | - In this linker script, you may find symbols that look like `${...}` (e.g., `4`). | ||
| 20 | These are wildcards used by the `build.rs` script to adapt to different target particularities. | ||
| 21 | Check `build.rs` for more details about these symbols. | ||
| 22 | |||
| 23 | - On alignment: it's important for correctness that the VMA boundaries of both .bss and .data *and* | ||
| 24 | the LMA of .data are all `4`-byte aligned. These alignments are assumed by the RAM | ||
| 25 | initialization routine. There's also a second benefit: `4`-byte aligned boundaries | ||
| 26 | means that you won't see "Address (..) is out of bounds" in the disassembly produced by `objdump`. | ||
| 27 | */ | ||
| 28 | |||
| 29 | PROVIDE(_stext = ORIGIN(REGION_TEXT)); | ||
| 30 | PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK)); | ||
| 31 | PROVIDE(_max_hart_id = 0); | ||
| 32 | PROVIDE(_hart_stack_size = 2K); | ||
| 33 | PROVIDE(_heap_size = 0); | ||
| 34 | |||
| 35 | PROVIDE(InstructionMisaligned = ExceptionHandler); | ||
| 36 | PROVIDE(InstructionFault = ExceptionHandler); | ||
| 37 | PROVIDE(IllegalInstruction = ExceptionHandler); | ||
| 38 | PROVIDE(Breakpoint = ExceptionHandler); | ||
| 39 | PROVIDE(LoadMisaligned = ExceptionHandler); | ||
| 40 | PROVIDE(LoadFault = ExceptionHandler); | ||
| 41 | PROVIDE(StoreMisaligned = ExceptionHandler); | ||
| 42 | PROVIDE(StoreFault = ExceptionHandler);; | ||
| 43 | PROVIDE(UserEnvCall = ExceptionHandler); | ||
| 44 | PROVIDE(SupervisorEnvCall = ExceptionHandler); | ||
| 45 | PROVIDE(MachineEnvCall = ExceptionHandler); | ||
| 46 | PROVIDE(InstructionPageFault = ExceptionHandler); | ||
| 47 | PROVIDE(LoadPageFault = ExceptionHandler); | ||
| 48 | PROVIDE(StorePageFault = ExceptionHandler); | ||
| 49 | |||
| 50 | PROVIDE(SupervisorSoft = DefaultHandler); | ||
| 51 | PROVIDE(MachineSoft = DefaultHandler); | ||
| 52 | PROVIDE(SupervisorTimer = DefaultHandler); | ||
| 53 | PROVIDE(MachineTimer = DefaultHandler); | ||
| 54 | PROVIDE(SupervisorExternal = DefaultHandler); | ||
| 55 | PROVIDE(MachineExternal = DefaultHandler); | ||
| 56 | |||
| 57 | PROVIDE(DefaultHandler = DefaultInterruptHandler); | ||
| 58 | PROVIDE(ExceptionHandler = DefaultExceptionHandler); | ||
| 59 | |||
| 60 | /* # Pre-initialization function */ | ||
| 61 | /* If the user overrides this using the `#[pre_init]` attribute or by creating a `__pre_init` function, | ||
| 62 | then the function this points to will be called before the RAM is initialized. */ | ||
| 63 | PROVIDE(__pre_init = default_pre_init); | ||
| 64 | |||
| 65 | /* A PAC/HAL defined routine that should initialize custom interrupt controller if needed. */ | ||
| 66 | PROVIDE(_setup_interrupts = default_setup_interrupts); | ||
| 67 | |||
| 68 | /* # Multi-processing hook function | ||
| 69 | fn _mp_hook() -> bool; | ||
| 70 | |||
| 71 | This function is called from all the harts and must return true only for one hart, | ||
| 72 | which will perform memory initialization. For other harts it must return false | ||
| 73 | and implement wake-up in platform-dependent way (e.g. after waiting for a user interrupt). | ||
| 74 | */ | ||
| 75 | PROVIDE(_mp_hook = default_mp_hook); | ||
| 76 | |||
| 77 | /* # Start trap function override | ||
| 78 | By default uses the riscv crates default trap handler | ||
| 79 | but by providing the `_start_trap` symbol external crates can override. | ||
| 80 | */ | ||
| 81 | PROVIDE(_start_trap = default_start_trap); | ||
| 82 | |||
| 83 | SECTIONS | ||
| 84 | { | ||
| 85 | .text.dummy (NOLOAD) : | ||
| 86 | { | ||
| 87 | /* This section is intended to make _stext address work */ | ||
| 88 | . = ABSOLUTE(_stext); | ||
| 89 | } > REGION_TEXT | ||
| 90 | |||
| 91 | .text _stext : | ||
| 92 | { | ||
| 93 | /* Put reset handler first in .text section so it ends up as the entry */ | ||
| 94 | /* point of the program. */ | ||
| 95 | KEEP(*(.init)); | ||
| 96 | KEEP(*(.init.rust)); | ||
| 97 | . = ALIGN(4); | ||
| 98 | *(.trap); | ||
| 99 | *(.trap.rust); | ||
| 100 | *(.text.abort); | ||
| 101 | *(.text .text.*); | ||
| 102 | } > REGION_TEXT | ||
| 103 | |||
| 104 | .eh_frame : { KEEP(*(.eh_frame)) } > REGION_TEXT | ||
| 105 | .eh_frame_hdr : { *(.eh_frame_hdr) } > REGION_TEXT | ||
| 106 | |||
| 107 | .rodata : ALIGN(4) | ||
| 108 | { | ||
| 109 | *(.srodata .srodata.*); | ||
| 110 | *(.rodata .rodata.*); | ||
| 111 | |||
| 112 | /* 4-byte align the end (VMA) of this section. | ||
| 113 | This is required by LLD to ensure the LMA of the following .data | ||
| 114 | section will have the correct alignment. */ | ||
| 115 | . = ALIGN(4); | ||
| 116 | } > REGION_RODATA | ||
| 117 | |||
| 118 | .data : ALIGN(4) | ||
| 119 | { | ||
| 120 | _sidata = LOADADDR(.data); | ||
| 121 | _sdata = .; | ||
| 122 | /* Must be called __global_pointer$ for linker relaxations to work. */ | ||
| 123 | PROVIDE(__global_pointer$ = . + 0x800); | ||
| 124 | *(.sdata .sdata.* .sdata2 .sdata2.*); | ||
| 125 | *(.data .data.*); | ||
| 126 | . = ALIGN(4); | ||
| 127 | _edata = .; | ||
| 128 | } > REGION_DATA AT > REGION_RODATA | ||
| 129 | |||
| 130 | .bss (NOLOAD) : ALIGN(4) | ||
| 131 | { | ||
| 132 | _sbss = .; | ||
| 133 | *(.sbss .sbss.* .bss .bss.*); | ||
| 134 | . = ALIGN(4); | ||
| 135 | _ebss = .; | ||
| 136 | } > REGION_BSS | ||
| 137 | |||
| 138 | /* fictitious region that represents the memory available for the heap */ | ||
| 139 | .heap (NOLOAD) : | ||
| 140 | { | ||
| 141 | _sheap = .; | ||
| 142 | . += _heap_size; | ||
| 143 | . = ALIGN(4); | ||
| 144 | _eheap = .; | ||
| 145 | } > REGION_HEAP | ||
| 146 | |||
| 147 | /* fictitious region that represents the memory available for the stack */ | ||
| 148 | .stack (NOLOAD) : | ||
| 149 | { | ||
| 150 | _estack = .; | ||
| 151 | . = ABSOLUTE(_stack_start); | ||
| 152 | _sstack = .; | ||
| 153 | } > REGION_STACK | ||
| 154 | |||
| 155 | /* fake output .got section */ | ||
| 156 | /* Dynamic relocations are unsupported. This section is only used to detect | ||
| 157 | relocatable code in the input files and raise an error if relocatable code | ||
| 158 | is found */ | ||
| 159 | .got (INFO) : | ||
| 160 | { | ||
| 161 | KEEP(*(.got .got.*)); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | /* Do not exceed this mark in the error messages above | */ | ||
| 166 | ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " | ||
| 167 | ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); | ||
| 168 | |||
| 169 | ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, " | ||
| 170 | ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned"); | ||
| 171 | |||
| 172 | ASSERT(ORIGIN(REGION_DATA) % 4 == 0, " | ||
| 173 | ERROR(riscv-rt): the start of the REGION_DATA must be 4-byte aligned"); | ||
| 174 | |||
| 175 | ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, " | ||
| 176 | ERROR(riscv-rt): the start of the REGION_HEAP must be 4-byte aligned"); | ||
| 177 | |||
| 178 | ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " | ||
| 179 | ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); | ||
| 180 | |||
| 181 | ASSERT(ORIGIN(REGION_STACK) % 4 == 0, " | ||
| 182 | ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned"); | ||
| 183 | |||
| 184 | ASSERT(_stext % 4 == 0, " | ||
| 185 | ERROR(riscv-rt): `_stext` must be 4-byte aligned"); | ||
| 186 | |||
| 187 | ASSERT(_sdata % 4 == 0 && _edata % 4 == 0, " | ||
| 188 | BUG(riscv-rt): .data is not 4-byte aligned"); | ||
| 189 | |||
| 190 | ASSERT(_sidata % 4 == 0, " | ||
| 191 | BUG(riscv-rt): the LMA of .data is not 4-byte aligned"); | ||
| 192 | |||
| 193 | ASSERT(_sbss % 4 == 0 && _ebss % 4 == 0, " | ||
| 194 | BUG(riscv-rt): .bss is not 4-byte aligned"); | ||
| 195 | |||
| 196 | ASSERT(_sheap % 4 == 0, " | ||
| 197 | BUG(riscv-rt): start of .heap is not 4-byte aligned"); | ||
| 198 | |||
| 199 | ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), " | ||
| 200 | ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region. | ||
| 201 | Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'"); | ||
| 202 | |||
| 203 | ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, " | ||
| 204 | ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts. | ||
| 205 | Consider changing `_max_hart_id` or `_hart_stack_size`."); | ||
| 206 | |||
| 207 | ASSERT(SIZEOF(.got) == 0, " | ||
| 208 | .got section detected in the input files. Dynamic relocations are not | ||
| 209 | supported. If you are linking to C code compiled using the `gcc` crate | ||
| 210 | then modify your build script to compile the C code _without_ the | ||
| 211 | -fPIC flag. See the documentation of the `gcc::Config.fpic` method for | ||
| 212 | details."); | ||
| 213 | |||
| 214 | /* Do not exceed this mark in the error messages above | */ | ||
