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

Migrate the ARM entry point to global_asm!. #383

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:

- name: Install dependencies
run: |
sudo apt-get install binutils-arm-none-eabi
cargo install elf2tab

- name: Build LEDs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# relocation.
- name: Build and Test
run: |
sudo apt-get install binutils-arm-none-eabi ninja-build
sudo apt-get install ninja-build
cd "${GITHUB_WORKSPACE}"
echo "[target.'cfg(all())']" >> .cargo/config
echo 'rustflags = ["-D", "warnings"]' >> .cargo/config
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/mac-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ jobs:
- name: Clone repository
uses: actions/checkout@v2

- name: Install arm-none-eabi-gcc
uses: fiam/arm-none-eabi-gcc@v1
with:
release: '10-2020-q4'

- name: Build and Test
run: |
cd "${GITHUB_WORKSPACE}"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/size-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
# master.
- name: Compute sizes
run: |
sudo apt-get install binutils-arm-none-eabi
UPSTREAM_REMOTE_NAME="${UPSTREAM_REMOTE_NAME:-origin}"
GITHUB_BASE_REF="${GITHUB_BASE_REF:-master}"
cd "${GITHUB_WORKSPACE}"
Expand Down
35 changes: 15 additions & 20 deletions runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod extern_asm;

// auto_layout() identifies the correct linker scripts to use based on the
// LIBTOCK_PLATFORM environment variable, and copies the linker scripts into
// OUT_DIR. The cargo invocation must pass -C link-arg=-Tlayout.ld to rustc
// (using the rustflags cargo config).
#[cfg(not(feature = "no_auto_layout"))]
fn auto_layout(out_dir: &str) {
fn auto_layout() {
use std::fs::copy;
use std::path::PathBuf;

Expand All @@ -18,6 +16,16 @@ fn auto_layout(out_dir: &str) {

// Read configuration from environment variables.

// Note: cargo fails if run in a path that is not valid Unicode, so this
// script doesn't need to handle non-Unicode paths. Also, OUT_DIR cannot be
// in a location with a newline in it, or we have no way to pass
// rustc-link-search to cargo.
let out_dir = &std::env::var("OUT_DIR").expect("Unable to read OUT_DIR");
assert!(
!out_dir.contains('\n'),
"Build path contains a newline, which is unsupported"
);

// Read the platform environment variable as a String (our platform names
// should all be valid UTF-8).
let platform = std::env::var(PLATFORM_CFG_VAR).expect("Please specify LIBTOCK_PLATFORM");
Expand All @@ -35,25 +43,12 @@ fn auto_layout(out_dir: &str) {
println!("cargo:rerun-if-changed={}", LAYOUT_GENERIC_FILENAME);
copy(LAYOUT_GENERIC_FILENAME, out_layout_generic)
.expect("Unable to copy layout_generic.ld into OUT_DIR");

// Tell rustc where to search for the layout file.
println!("cargo:rustc-link-search={}", out_dir);
}

fn main() {
// Note: cargo fails if run in a path that is not valid Unicode, so this
// script doesn't need to handle non-Unicode paths. Also, OUT_DIR cannot be
// in a location with a newline in it, or we have no way to pass
// rustc-link-search to cargo.
let out_dir = &std::env::var("OUT_DIR").expect("Unable to read OUT_DIR");
assert!(
!out_dir.contains('\n'),
"Build path contains a newline, which is unsupported"
);

#[cfg(not(feature = "no_auto_layout"))]
auto_layout(out_dir);

extern_asm::build_and_link(out_dir);

// This link search path is used by both auto_layout() and
// extern_asm::build_and_link().
println!("cargo:rustc-link-search={}", out_dir);
auto_layout();
}
130 changes: 0 additions & 130 deletions runtime/extern_asm.rs

This file was deleted.

28 changes: 14 additions & 14 deletions runtime/asm/asm_arm.S → runtime/src/startup/asm_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ start:
mov r4, pc /* r4 = address of .start + 4 (Thumb bit unset) */
mov r5, r0 /* Save rt_header; we use r0 for syscalls */
ldr r0, [r5, #0] /* r0 = rt_header.start */
add r0, #3 /* r0 = rt_header.start + 4 - 1 (for Thumb bit) */
adds r0, #3 /* r0 = rt_header.start + 4 - 1 (for Thumb bit) */
cmp r0, r4
beq .Lset_brk /* Skip error handling if pc correct */
/* If the beq on the previous line did not jump, then the binary is not at
* the correct location. Report the error via LowLevelDebug then exit. */
mov r0, #8 /* LowLevelDebug driver number */
mov r1, #1 /* Command: print alert code */
mov r2, #2 /* Alert code 2 (incorrect location */
svc 2 /* Execute `command` */
mov r0, #0 /* Operation: exit-terminate */
svc 6 /* Execute `exit` */
movs r0, #8 /* LowLevelDebug driver number */
movs r1, #1 /* Command: print alert code */
movs r2, #2 /* Alert code 2 (incorrect location */
svc 2 /* Execute `command` */
movs r0, #0 /* Operation: exit-terminate */
svc 6 /* Execute `exit` */

.Lset_brk:
/* memop(): set brk to rt_header's initial break value */
mov r0, #0 /* operation: set break */
movs r0, #0 /* operation: set break */
ldr r1, [r5, #4] /* rt_header`s initial process break */
svc 5 /* call `memop` */

Expand All @@ -66,21 +66,21 @@ start:
.Ldata_loop_body:
ldr r3, [r1] /* r3 = *src */
str r3, [r2] /* *(dest) = r3 */
sub r0, #4 /* remaining -= 4 */
add r1, #4 /* src += 4 */
add r2, #4 /* dest += 4 */
subs r0, #4 /* remaining -= 4 */
adds r1, #4 /* src += 4 */
adds r2, #4 /* dest += 4 */
cmp r0, #0
bne .Ldata_loop_body /* Iterate again if remaining != 0 */

.Lzero_bss:
ldr r0, [r5, #24] /* remaining = rt_header.bss_size */
cbz r0, .Lcall_rust_start /* Jump to call_rust_start if remaining == 0 */
ldr r1, [r5, #28] /* dest = rt_header.bss_start */
mov r2, #0 /* r2 = 0 */
movs r2, #0 /* r2 = 0 */
.Lbss_loop_body:
strb r2, [r1] /* *(dest) = r2 = 0 */
sub r0, #1 /* remaining -= 1 */
add r1, #1 /* dest += 1 */
subs r0, #1 /* remaining -= 1 */
adds r1, #1 /* dest += 1 */
cmp r0, #0
bne .Lbss_loop_body /* Iterate again if remaining != 0 */

Expand Down
3 changes: 2 additions & 1 deletion runtime/src/startup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

// Include the correct `start` symbol (the program entry point) for the
// architecture.
// TODO: Migrate ARM to global_asm! and delete extern_asm.rs.
#[cfg(target_arch = "arm")]
core::arch::global_asm!(include_str!("asm_arm.s"));
#[cfg(target_arch = "riscv32")]
core::arch::global_asm!(include_str!("asm_riscv32.s"));

Expand Down