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 Aarch64 test #16

Merged
merged 4 commits into from
May 21, 2021
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
3 changes: 3 additions & 0 deletions .github/workflows/aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ jobs:
if: ${{ matrix.os == 'macOS-latest' }}
- name: Build loader (unix)
run: make arch=aarch64
- name: Test loader
run: qemu-system-aarch64 -display none -smp 4 -m 1G -serial stdio -kernel target/aarch64-unknown-hermit-loader/debug/rusty-loader -machine raspi3 -semihosting
timeout-minutes: 1
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
arch ?= x86_64
target ?= $(arch)-unknown-hermit
release ?= 0
app ?= "$(PWD)/data/hello_world"

opt :=
rdir := debug
Expand All @@ -14,6 +13,7 @@ endif
# Todo - make this feature toggleable
ifeq ($(arch), aarch64)
opt += --features "aarch64-qemu-stdout"
export HERMIT_APP ?= $(PWD)/data/hello_world_aarch64
endif

CONVERT :=
Expand Down Expand Up @@ -42,5 +42,6 @@ docs:

loader:
@echo Build loader
HERMIT_APP=$(app) cargo build $(opt) -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --target $(target)-loader.json
echo "hermit app: $(HERMIT_APP)"
cargo build $(opt) -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --target $(target)-loader.json
$(CONVERT)
3 changes: 3 additions & 0 deletions data/hello_world_aarch64
Git LFS file not shown
8 changes: 0 additions & 8 deletions src/arch/aarch64/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ extern "C" {
fn loader_main();
}

const BOOT_STACK_SIZE: usize = 4096;
const BOOT_CORE_ID: u64 = 0; // ID of CPU for booting on SMP systems - this might be board specific in the future

#[link_section = ".data"]
static STACK: [u8; BOOT_STACK_SIZE] = [0; BOOT_STACK_SIZE];

/*
* Memory types available.
*/
Expand Down Expand Up @@ -57,10 +53,6 @@ global_asm!(include_str!("entry.s"));
#[inline(never)]
#[no_mangle]
pub unsafe fn _start_rust() -> ! {
// Pointer to stack base
llvm_asm!("mov sp, $0"
:: "r"(&STACK[BOOT_STACK_SIZE - 0x10] as *const u8 as usize)
:: "volatile");
pre_init()
}

Expand Down
20 changes: 19 additions & 1 deletion src/arch/aarch64/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

.equ _core_id_mask, 0b11 //Assume 4 core raspi3


// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm

.section .text._start

_start:
Expand All @@ -13,7 +26,12 @@ _start:
b.ne 1f

// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.


// This loads the physical address of the Stack end. For details see
// https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/master/16_virtual_mem_part4_higher_half_kernel/src/bsp/raspberrypi/link.ld
ADR_REL x4, __boot_core_stack_end_exclusive
mov sp, x4

// Jump to Rust code.
b _start_rust

Expand Down
67 changes: 50 additions & 17 deletions src/arch/aarch64/link.ld
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
/* Parts of this linker script are directly taken from Andre Richters Project:
* https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/master/16_virtual_mem_part4_higher_half_kernel/src/bsp/raspberrypi/link.ld
*/

OUTPUT_FORMAT("elf64-littleaarch64")
OUTPUT_ARCH("aarch64")
ENTRY(_start)

/* start address of the RAM, below belongs to the flash */
phys = 0x00080000;

PHDRS
{
segment_rx PT_LOAD FLAGS(5); /* 5 == RX */
segment_rw PT_LOAD FLAGS(6); /* 6 == RW */
}

SECTIONS
{
. = phys;
kernel_start = .;
.text ALIGN(4096) : AT(ADDR(.text)) {
*(.text)
*(.text.*)
}
.rodata ALIGN(4096) : AT(ADDR(.rodata)) {
*(.rodata)
*(.rodata.*)
}
.data ALIGN(4096) : AT(ADDR(.data)) {
*(.data)
*(.data.*)
}
.bss ALIGN(4096) : AT(ADDR(.bss)) {
__rx_start = .;
.text ALIGN(4096) : AT(phys) {
KEEP(*(.text._start))
*(.text._start_arguments) /* Constants (or statics in Rust speak) read by _start(). */
*(.text._start_rust) /* The Rust entry point */
*(.text*) /* Everything else */
} :segment_rx
.rodata : ALIGN(8) { *(.rodata*) } :segment_rx
.got : ALIGN(8) { *(.got) } :segment_rx /* Global offset table Todo - do we use this?*/
. = ALIGN(64K); /* Align to page boundary */
__rx_end_exclusive = .;

__rw_start = .;
.data : { *(.data*) } :segment_rw

.bss : ALIGN(8) {
bss_start = .;
*(.bss)
*(.bss.*)
}
bss_end = .;
*(.bss*);
. = ALIGN(8);
. += 8;
bss_end = .;
} :NONE

. = ALIGN(64K); /* Align to page boundary */
__rw_end_exclusive = .;

/***********************************************************************************************
* Guard Page between boot core stack and data
***********************************************************************************************/
__boot_core_stack_guard_page_start = .;
. += 64K;
__boot_core_stack_guard_page_end_exclusive = .;

/***********************************************************************************************
* Boot Core Stack
***********************************************************************************************/
__boot_core_stack_start = .; /* ^ */
/* | stack */
. += 512K; /* | growth */
/* | direction */
__boot_core_stack_end_exclusive = .; /* | */
kernel_end = .;
}