Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Rust toolchain to 2021-03-25. #280

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/platform/src/command_return_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn failure_u64() {
assert_eq!(command_return.get_failure_2_u32(), None);
assert_eq!(
command_return.get_failure_u64(),
Some((ErrorCode::Busy, 0x00001003_00001002))
Some((ErrorCode::Busy, 0x0000_1003_0000_1002))
);
assert_eq!(command_return.get_success_u32(), None);
assert_eq!(command_return.get_success_2_u32(), None);
Expand Down Expand Up @@ -240,7 +240,10 @@ fn success_u64() {
assert_eq!(command_return.get_failure_u64(), None);
assert_eq!(command_return.get_success_u32(), None);
assert_eq!(command_return.get_success_2_u32(), None);
assert_eq!(command_return.get_success_u64(), Some(0x00001002_00001001));
assert_eq!(
command_return.get_success_u64(),
Some(0x0000_1002_0000_1001)
);
assert_eq!(command_return.get_success_3_u32(), None);
assert_eq!(command_return.get_success_u32_u64(), None);
assert_eq!(command_return.return_variant(), return_variant::SUCCESS_U64);
Expand Down Expand Up @@ -299,7 +302,7 @@ fn success_u32_u64() {
assert_eq!(command_return.get_success_3_u32(), None);
assert_eq!(
command_return.get_success_u32_u64(),
Some((1001, 0x00001003_00001002))
Some((1001, 0x0000_1003_0000_1002))
);
assert_eq!(
command_return.return_variant(),
Expand Down
1 change: 1 addition & 0 deletions core/platform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![warn(unsafe_op_in_unsafe_fn)]

mod async_traits;
mod command_return;
Expand Down
1 change: 1 addition & 0 deletions core/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#![feature(asm)]
#![no_std]
#![warn(unsafe_op_in_unsafe_fn)]

mod startup;

Expand Down
18 changes: 10 additions & 8 deletions core/runtime/src/syscalls_impl_riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ impl RawSyscalls for crate::TockSyscalls {
mut r3: usize,
class: u8,
) -> (u32, usize, usize, usize) {
asm!("ecall",
inlateout("a0") r0,
inlateout("a1") r1,
inlateout("a2") r2,
inlateout("a3") r3,
in("a4") class,
options(preserves_flags, nostack),
);
unsafe {
asm!("ecall",
inlateout("a0") r0,
inlateout("a1") r1,
inlateout("a2") r2,
inlateout("a3") r3,
in("a4") class,
options(preserves_flags, nostack),
);
}
(r0, r1 as usize, r2, r3)
}

Expand Down
24 changes: 7 additions & 17 deletions core/src/entry_point/start_item_arm.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
use core::hint;

/// Tock programs' entry point. Called by the kernel at program start. Sets up
/// the stack then calls rust_start() for the remainder of setup.
#[doc(hidden)]
#[no_mangle]
#[naked]
#[link_section = ".start"]
pub unsafe extern "C" fn _start(
app_start: usize,
mem_start: usize,
_memory_len: usize,
app_heap_break: usize,
) -> ! {
llvm_asm!("
pub unsafe extern "C" fn _start() -> ! {
asm!(
"
// Because ROPI-RWPI support in LLVM/rustc is incomplete, Rust
// applications must be statically linked. An offset between the
// location the program is linked at and its actual location in flash
Expand Down Expand Up @@ -102,12 +96,8 @@ pub unsafe extern "C" fn _start(
mov r2, r8

// Call rust_start
bl rust_start"
: // No output operands
: "{r0}"(app_start), "{r1}"(mem_start), "{r3}"(app_heap_break) // Input operands
: "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r12",
"cc", "memory" // Clobbers
: "volatile" // Options
);
hint::unreachable_unchecked()
bl rust_start",
// No clobbers because we don't return.
options(noreturn),
)
}
26 changes: 10 additions & 16 deletions core/src/entry_point/start_item_riscv32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::hint;

/// Tock programs' entry point. Called by the kernel at program start. Sets up
/// the stack then calls rust_start() for the remainder of setup.
#[doc(hidden)]
Expand All @@ -14,12 +12,12 @@ use core::hint;
// Due to Rust issue: https://github.com/rust-lang/rust/issues/42779 we can't have
// args to the function
pub unsafe extern "C" fn _start() -> ! {
llvm_asm!(
// Compute the stack top.
//
// struct hdr* myhdr = (struct hdr*) app_start;
// uint32_t stacktop = (((uint32_t) mem_start + myhdr->stack_size + 7) & 0xfffffff8);
"lw t0, 36(a0) // t0 = myhdr->stack_size
asm!(
// Compute the stack top.
//
// struct hdr* myhdr = (struct hdr*) app_start;
// uint32_t stacktop = (((uint32_t) mem_start + myhdr->stack_size + 7) & 0xfffffff8);
"lw t0, 36(a0) // t0 = myhdr->stack_size
addi t0, t0, 7 // t0 = myhdr->stack_size + 7
add t0, t0, a1 // t0 = mem_start + myhdr->stack_size + 7
li t1, 7 // t1 = 7
Expand Down Expand Up @@ -89,14 +87,10 @@ pub unsafe extern "C" fn _start() -> ! {
mv s0, sp // Set the frame pointer to sp.
mv a1, s1 // second arg is stacktop
mv a2, t1 // third arg is app_heap_break that we told the kernel
jal rust_start"
: // No output operands
:
: "memory", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17",
"x5", "x6", "x7", "x28", "x29", "x30", "x31", "x1" // Clobbers
: "volatile" // Options
);
hint::unreachable_unchecked();
jal rust_start",
// No clobbers needed for a noreturn asm! block.
options(noreturn),
)
}

/// Ensure an abort symbol exists.
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(lang_items, llvm_asm, naked_functions)]
#![feature(asm, lang_items, llvm_asm, naked_functions)]
#![cfg_attr(any(target_arch = "arm", target_arch = "riscv32"), no_std)]
#![cfg_attr(feature = "alloc", feature(alloc_error_handler))]

Expand Down
35 changes: 11 additions & 24 deletions layout_generic.ld
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ SECTIONS {
/* Section for just the app crt0 header.
* This must be first so that the app can find it.
*/
.crt0_header :
/* Runtime setup logic. The crt0_header symbol is used by the entry point
* assembly. We have to include start here rather than .text because
* otherwise elf2tab fails to recognize that the process binary's flash
* region should start at the beginning of .start.
*/
.start :
{
_beginning = .; /* Start of the app in flash. */
crt0_header = .;
/**
* Populate the header expected by `crt0`:
*
Expand Down Expand Up @@ -68,14 +74,15 @@ SECTIONS {
* between the header and subsequent .data section. It's unclear why,
* but LLD is aligning sections to a multiple of 32 bytes. */
. = ALIGN(32);

*(.start)
} > FLASH =0xFF

/* Text section, Code! */
.text :
{
. = ALIGN(4);
_text = .;
KEEP (*(.start))
*(.text*)
*(.rodata*)
KEEP (*(.syscalls))
Expand Down Expand Up @@ -140,30 +147,10 @@ SECTIONS {
{
} > FLASH

/* ARM Exception support
*
* This contains compiler-generated support for unwinding the stack,
* consisting of key-value pairs of function addresses and information on
* how to unwind stack frames.
* https://wiki.linaro.org/KenWerner/Sandbox/libunwind?action=AttachFile&do=get&target=libunwind-LDS.pdf
*
* .ARM.exidx is sorted, so has to go in its own output section.
*
* __NOTE__: It's at the end because we currently don't actually serialize
* it to the binary in elf2tbf. If it was before the RAM sections, it would
* through off our calculations of the header.
*/
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
/* (C++) Index entries for section unwinding */
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
PROVIDE_HIDDEN (__exidx_end = .);

/* Sections we do not need. */
/DISCARD/ :
{
*(.eh_frame)
*(.ARM.exidx .eh_frame)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
# See https://rust-lang.github.io/rustup-components-history/ for a list of
# recently nightlies and what components are available for them.
channel = "nightly-2020-08-20"
channel = "nightly-2021-03-25"
components = ["clippy", "miri", "rustfmt"]
targets = ["thumbv7em-none-eabi",
"riscv32imac-unknown-none-elf",
Expand Down
14 changes: 9 additions & 5 deletions src/ble_composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct BlePayload {
}

impl BlePayload {
pub fn add(&mut self, kind: u8, content: &[u8]) -> Result<(), ()> {
pub fn add(&mut self, kind: u8, content: &[u8]) -> Result<(), Overflow> {
self.check_can_write_num_bytes(content.len() + 2)?;

self.bytes[self.occupied] = (content.len() + 1) as u8;
Expand All @@ -26,7 +26,7 @@ impl BlePayload {
Ok(())
}

pub fn add_flag(&mut self, flag: u8) -> Result<(), ()> {
pub fn add_flag(&mut self, flag: u8) -> Result<(), Overflow> {
self.check_can_write_num_bytes(3)?;

self.bytes[self.occupied] = 2;
Expand All @@ -36,7 +36,7 @@ impl BlePayload {
Ok(())
}

pub fn add_service_payload(&mut self, uuid: [u8; 2], content: &[u8]) -> Result<(), ()> {
pub fn add_service_payload(&mut self, uuid: [u8; 2], content: &[u8]) -> Result<(), Overflow> {
self.check_can_write_num_bytes(4 + content.len())?;
self.bytes[self.occupied] = (content.len() + 3) as u8;
self.bytes[self.occupied + 1] = gap_types::SERVICE_DATA;
Expand All @@ -49,11 +49,11 @@ impl BlePayload {
Ok(())
}

fn check_can_write_num_bytes(&self, number: usize) -> Result<(), ()> {
fn check_can_write_num_bytes(&self, number: usize) -> Result<(), Overflow> {
if self.occupied + number <= self.bytes.len() {
Ok(())
} else {
Err(())
Err(Overflow)
}
}
}
Expand All @@ -72,6 +72,10 @@ impl AsRef<[u8]> for BlePayload {
}
}

// Error type returned when the buffer is too full to perform an operation.
#[derive(Debug)]
pub struct Overflow;

#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub unsafe fn dump_address(address: *const usize) {
write_as_hex(&mut buffer[12..22], *address);
for index in 0..4 {
let byte = *(address as *const u8).offset(index);
let byte_is_printable_char = byte >= 0x20 && byte < 0x80;
let byte_is_printable_char = (0x20..0x80).contains(&byte);
if byte_is_printable_char {
buffer[23 + index as usize] = byte;
}
Expand Down
6 changes: 3 additions & 3 deletions src/sensors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ macro_rules! single_value_sensor {
}
}

impl Into<i32> for $type_name {
fn into(self) -> i32 {
self.value
impl From<$type_name> for i32 {
fn from(sensor: $type_name) -> i32 {
sensor.value
}
}

Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fn process_output(stdout: ChildStdout) -> Result<(), Box<dyn std::error::Error>>
}

fn test_succeeded(input: String, failed_tests: &mut Vec<String>) -> Option<bool> {
let success = input.find("[ OK ]").is_some();
let failure = input.find("[ FAILURE ]").is_some();
let success = input.contains("[ OK ]");
let failure = input.contains("[ FAILURE ]");
let input = input.replace("[ OK ]", "");
let input = input.replace("[ FAILURE ]", "");
let input = input.trim();
Expand Down
20 changes: 12 additions & 8 deletions tools/print_sizes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,29 @@ fn main() {
.expect("No examples found");
let section_width = 7;

// TODO: We do not currently print out .rodata's size. Currently, the linker
// script embeds .rodata in .text, so we don't see it as a separate section
// here. We should modify the linker script to put .rodata in its own
// section. Until that is done, .rodata's size will be counted as part of
// .text, so we'll just print .text's size for now.
println!(
"{0:1$} {2:3$} {4:>7$} {5:>7$} {6:>7$}",
"Example", name_width, "Architecture", arch_width, ".bss", ".data", ".text", section_width
"{0:1$} {2:3$} {4:>8$} {5:>8$} {6:>8$} {7:>8$}",
"Example",
name_width,
"Architecture",
arch_width,
".bss",
".data",
".text",
".rodata",
section_width
);
for data in example_data {
println!(
"{0:1$} {2:3$} {4:7$} {5:7$} {6:7$}",
"{0:1$} {2:3$} {4:8$} {5:8$} {6:8$} {7:8$}",
data.name,
name_width,
data.arch,
arch_width,
data.sizes.bss,
data.sizes.data,
data.sizes.text,
data.sizes.rodata,
section_width
);
}
Expand Down