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

Add ARM v6 syscalls and Raspberry Pi Pico / Nano Rp2040 Connect #381

Merged
merged 10 commits into from
Feb 23, 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
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ flash-nrf52840:
LIBTOCK_PLATFORM=nrf52840 cargo run --example $(EXAMPLE) $(features) \
--target=thumbv7em-none-eabi $(release) -- --deploy=tockloader

.PHONY: raspberrypi_pico
raspberrypi_pico:
LIBTOCK_PLATFORM=raspberrypi_pico cargo run --example $(EXAMPLE) $(features) \
--target=thumbv6m-none-eabi $(release)
mkdir -p target/tbf/raspberrypi_pico
cp target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/raspberrypi_pico

.PHONY: nano_rp2040_connect
nano_rp2040_connect:
LIBTOCK_PLATFORM=nano_rp2040_connect cargo run --example $(EXAMPLE) $(features) \
--target=thumbv6m-none-eabi $(release)
mkdir -p target/tbf/nano_rp2040_connect
cp target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tab \
target/thumbv6m-none-eabi/release/examples/$(EXAMPLE).tbf \
target/tbf/nano_rp2040_connect

.PHONY: stm32f3discovery
stm32f3discovery:
LIBTOCK_PLATFORM=stm32f3discovery cargo run --example $(EXAMPLE) \
Expand Down
9 changes: 9 additions & 0 deletions runtime/layouts/nano_rp2040_connect.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Layout for the Raspberry Pi Pico board, used by the examples in this repository. */

MEMORY {
FLASH (X) : ORIGIN = 0x10020000, LENGTH = 256K
RAM (W) : ORIGIN = 0x20004000, LENGTH = 248K
}

TBF_HEADER_SIZE = 0x48;
INCLUDE libtock_layout.ld
9 changes: 9 additions & 0 deletions runtime/layouts/raspberrypi_pico.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Layout for the Raspberry Pi Pico board, used by the examples in this repository. */

MEMORY {
FLASH (X) : ORIGIN = 0x10020000, LENGTH = 256K
RAM (W) : ORIGIN = 0x20004000, LENGTH = 248K
}

TBF_HEADER_SIZE = 0x48;
INCLUDE libtock_layout.ld
14 changes: 10 additions & 4 deletions runtime/src/startup/asm_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
*
* We currently only use the value in r0. It is copied into r5 early on because
* r0 is needed to invoke system calls.
*
* To be compatible with ARMv6 Thumb-1, we the cmp and beq instructions
* instead of cbz in two places. This increases the code size with 4 bytes,
* but allows us to use it on Cortex-M0+ processors.
*/
.section .start, "ax"
.global start
Expand All @@ -37,8 +41,8 @@ start:
mov r5, r0 /* Save rt_header; we use r0 for syscalls */
ldr r0, [r5, #0] /* r0 = rt_header.start */
adds r0, #3 /* r0 = rt_header.start + 4 - 1 (for Thumb bit) */
cmp r0, r4
beq .Lset_brk /* Skip error handling if pc correct */
cmp r0, r4 /* Skip error handling if pc correct */
beq .Lset_brk
/* 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. */
movs r0, #8 /* LowLevelDebug driver number */
Expand All @@ -60,7 +64,8 @@ start:

/* Copy .data into place */
ldr r0, [r5, #12] /* remaining = rt_header.data_size */
cbz r0, .Lzero_bss /* Jump to zero_bss if remaining == 0 */
cmp r0, #0 /* Jump to zero_bss if remaining == 0 */
beq .Lzero_bss
ldr r1, [r5, #16] /* src = rt_header.data_flash_start */
ldr r2, [r5, #20] /* dest = rt_header.data_ram_start */
.Ldata_loop_body:
Expand All @@ -74,7 +79,8 @@ start:

.Lzero_bss:
ldr r0, [r5, #24] /* remaining = rt_header.bss_size */
cbz r0, .Lcall_rust_start /* Jump to call_rust_start if remaining == 0 */
cmp r0, #0 /* Jump to call_rust_start if remaining == 0 */
beq .Lcall_rust_start
ldr r1, [r5, #28] /* dest = rt_header.bss_start */
movs r2, #0 /* r2 = 0 */
.Lbss_loop_body:
Expand Down
17 changes: 8 additions & 9 deletions runtime/src/syscalls_impl_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,40 @@ unsafe impl RawSyscalls for crate::TockSyscalls {
unsafe fn yield1([Register(r0)]: [Register; 1]) {
// Safety: This matches the invariants required by the documentation on
// RawSyscalls::yield1
// the use of `clobber_abi` allows us this to run on both Thumb-1 and Thumb-2
unsafe {
asm!("svc 0",
inlateout("r0") r0 => _, // a1
lateout("r1") _, // a2
lateout("r2") _, // a3
lateout("r3") _, // a4
// r4-r8 are callee-saved.
// r9 is platform-specific. We don't use it in libtock_runtime,
// so it is either unused or used as a callee-saved register.
// r10 and r11 are callee-saved.
lateout("r12") _, // ip

// r13 is the stack pointer and must be restored by the callee.
lateout("r14") _, // lr
// r15 is the program counter.

clobber_abi("C"), // a2, a3, a4, ip (r12), lr (r14)
);
}
}

unsafe fn yield2([Register(r0), Register(r1)]: [Register; 2]) {
// Safety: This matches the invariants required by the documentation on
// RawSyscalls::yield2
// the use of `clobber_abi` allows us this to run on both Thumb-1 and Thumb-2
unsafe {
asm!("svc 0",
inlateout("r0") r0 => _, // a1
inlateout("r1") r1 => _, // a2
lateout("r2") _, // a3
lateout("r3") _, // a4
// r4-r8 are callee-saved.
// r9 is platform-specific. We don't use it in libtock_runtime,
// so it is either unused or used as a callee-saved register.
// r10 and r11 are callee-saved.
lateout("r12") _, // ip

// r13 is the stack pointer and must be restored by the callee.
lateout("r14") _, // lr
// r15 is the program counter.

clobber_abi("C"), // a3, a4, ip (r12), lr (r14)
);
}
}
Expand Down