Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit 88ebaf1

Browse files
author
Jorge Aparicio
authored
Merge pull request #1 from japaric/used
make the reset handler private
2 parents 4ac91ae + 4457c0e commit 88ebaf1

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = ["Jorge Aparicio <[email protected]>"]
55

66
[dependencies]
7-
r0 = "0.2.0"
7+
r0 = "0.2.1"
88

99
[dependencies.cortex-m]
1010
optional = true

link.x

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ SECTIONS
77
/* Vector table */
88
_VECTOR_TABLE = .;
99
LONG(ORIGIN(RAM) + LENGTH(RAM));
10-
LONG(__reset + 1);
1110

11+
KEEP(*(.rodata.reset_handler));
1212
KEEP(*(.rodata._EXCEPTIONS));
1313
__exceptions = .;
1414

1515
KEEP(*(.rodata._INTERRUPTS));
1616
__interrupts = .;
1717

18-
/* Entry point: the reset handler */
19-
__reset = .;
20-
KEEP(*(.text.start));
21-
2218
*(.text.*);
2319
*(.rodata.*);
20+
_init_array_start = ALIGN(4);
21+
KEEP(*(.init_array));
22+
_init_array_end = ALIGN(4);
2423
} > FLASH
2524

2625
.bss : ALIGN(4)

src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(compiler_builtins_lib)]
3232
#![feature(lang_items)]
3333
#![feature(linkage)]
34+
#![feature(used)]
3435
#![no_std]
3536

3637
#[cfg(feature = "panic-over-itm")]
@@ -44,13 +45,10 @@ extern crate r0;
4445

4546
mod lang_items;
4647

47-
// TODO make private and use `#[used]`
4848
/// The reset handler
4949
///
5050
/// This is the entry point of all programs
51-
#[doc(hidden)]
52-
#[export_name = "start"]
53-
pub unsafe extern "C" fn reset_handler() -> ! {
51+
unsafe extern "C" fn reset_handler() -> ! {
5452
extern "C" {
5553
static mut _ebss: u32;
5654
static mut _sbss: u32;
@@ -59,10 +57,14 @@ pub unsafe extern "C" fn reset_handler() -> ! {
5957
static mut _sdata: u32;
6058

6159
static _sidata: u32;
60+
61+
static _init_array_start: extern "C" fn();
62+
static _init_array_end: extern "C" fn();
6263
}
6364

6465
::r0::zero_bss(&mut _sbss, &mut _ebss);
6566
::r0::init_data(&mut _sdata, &mut _edata, &_sidata);
67+
::r0::run_init_array(&_init_array_start, &_init_array_end);
6668

6769
// NOTE `rustc` forces this signature on us. See `src/lang_items.rs`
6870
extern "C" {
@@ -79,3 +81,8 @@ pub unsafe extern "C" fn reset_handler() -> ! {
7981
asm!("wfi" :::: "volatile");
8082
}
8183
}
84+
85+
#[allow(dead_code)]
86+
#[used]
87+
#[link_section = ".rodata.reset_handler"]
88+
static RESET_HANDLER: unsafe extern "C" fn() -> ! = reset_handler;

0 commit comments

Comments
 (0)