Unverified Commit d5ae6c5d authored by bors[bot]'s avatar bors[bot] Committed by GitHub
Browse files

Merge #263



263: aarch64 improvements r=stlankes a=stlankes

Collections of patches to enable aarch64 support. This pull request is still  under development and doesn't support every feature of RustyHermit.
Co-authored-by: Stefan Lankes's avatarStefan Lankes <slankes@eonerc.rwth-aachen.de>
Co-authored-by: default avatarJonathan Schwender <schwenderjonathan@gmail.com>
parents a8a5a94b 4595d30d
Pipeline #533477 passed with stages
name: aarch64
on:
pull_request:
push:
branches:
- master
- staging
- trying
env:
CARGO_TERM_COLOR: always
defaults:
run:
shell: bash
jobs:
test:
name: aarch64 tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout rusty-hermit
uses: actions/checkout@v2
with:
repository: hermitcore/rusty-hermit
submodules: true
- name: Remove libhermit-rs submodule
run: git rm -r libhermit-rs
- name: Checkout libhermit-rs
uses: actions/checkout@v2
with:
path: libhermit-rs
- name: Rustup (apply rust-toolchain.toml)
working-directory: libhermit-rs
run: rustup show
- name: Build minimal kernel
working-directory: libhermit-rs
run: cargo build --no-default-features --target aarch64-unknown-hermit
- name: Build dev profile
run: cargo build --target aarch64-unknown-hermit -p hello_world
- name: Build loader
run: make arch=aarch64
working-directory: loader
env:
HERMIT_APP: ../../../../target/aarch64-unknown-hermit/debug/hello_world
- name: Install QEMU (ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install qemu-system-aarch64
- name: Install QEMU (macos)
if: ${{ matrix.os == 'macos-latest' }}
run: |
brew update
brew install qemu
- name: Install QEMU, GNU make (windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
choco install make
choco install qemu --version 2021.5.5
echo "C:\Program Files\qemu" >> $GITHUB_PATH
- name: Test kernel
run: qemu-system-aarch64 -semihosting -display none -smp 4 -m 1G -serial stdio -kernel target/aarch64-unknown-hermit-loader/debug/rusty-loader -machine raspi3
working-directory: loader
name: Test
name: x86
on:
pull_request:
......@@ -17,7 +17,7 @@ defaults:
jobs:
test:
name: Test
name: x86 tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
......
......@@ -2,6 +2,14 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aarch64"
version = "0.0.5"
source = "git+https://github.com/hermitcore/rust-aarch64#582ccd4f738501e4b90a5680e9343c48715a7d7a"
dependencies = [
"cortex-a",
]
[[package]]
name = "autocfg"
version = "1.0.1"
......@@ -26,6 +34,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cortex-a"
version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "509fc35485a2b4ddbacabe0bf2212cdfff88da93658608e5cc651afcb75b7733"
dependencies = [
"tock-registers",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
......@@ -151,6 +168,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "qemu-exit"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "220eb94f40665452ab6114bf8a8d86aa1fd41c6dbfaa4ab71b5912c8adb80389"
[[package]]
name = "quote"
version = "1.0.9"
......@@ -173,6 +196,7 @@ dependencies = [
name = "rusty-hermit"
version = "0.3.52"
dependencies = [
"aarch64",
"bitflags",
"crossbeam-utils",
"float-cmp",
......@@ -181,6 +205,7 @@ dependencies = [
"num",
"num-derive",
"num-traits",
"qemu-exit",
"scopeguard",
"x86",
]
......@@ -202,6 +227,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "tock-registers"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee8fba06c1f4d0b396ef61a54530bb6b28f0dc61c38bc8bc5a5a48161e6282e"
[[package]]
name = "unicode-xid"
version = "0.2.2"
......
......@@ -41,13 +41,14 @@ name = "measure_startup_time"
harness = false
[features]
default = ["pci", "acpi", "fsgsbase", "smp"]
default = ["pci", "acpi", "fsgsbase", "smp", "aarch64-qemu-stdout"]
vga = []
newlib = []
pci = []
acpi = []
smp = []
fsgsbase = []
aarch64-qemu-stdout = [] # Doesn't do anything on x86
[dependencies]
bitflags = "1.3"
......@@ -67,6 +68,13 @@ float-cmp = "0.9"
num-traits = { version = "0.2", default-features = false }
x86 = { version = "0.41", default-features = false }
[target.'cfg(target_arch = "aarch64")'.dependencies.aarch64]
git = "https://github.com/hermitcore/rust-aarch64"
default-features = false
[target.'cfg(target_arch = "aarch64")'.dependencies]
qemu-exit = "2.0"
# The development profile, used for `cargo build`.
[profile.dev]
opt-level = 1 # controls the `--opt-level` the compiler builds with
......
status = [
"Test (ubuntu-latest)",
"Test (macos-latest)",
"Test (windows-latest)",
"x86 tests (ubuntu-latest)",
"x86 tests (macos-latest)",
"x86 tests (windows-latest)",
"aarch64 tests (ubuntu-latest)",
"aarch64 tests (macos-latest)",
"aarch64 tests (windows-latest)",
"Format",
"Clippy",
"ci/gitlab/git.rwth-aachen.de",
......
This image diff could not be displayed because it is too large. You can view the blob instead.
img/hermitcore_logo.png

9.94 KB | W: | H:

img/hermitcore_logo.png

130 Bytes | W: | H:

img/hermitcore_logo.png
img/hermitcore_logo.png
img/hermitcore_logo.png
img/hermitcore_logo.png
  • 2-up
  • Swipe
  • Onion skin
/*
* Copyright (c) 2017, Stefan Lankes, RWTH Aachen University, Germany
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This is the kernel's entry point, which is derived from Xen's Mini-OS.
*/
#include <hermit/config.h>
#define MAIR(attr, mt) ((attr) << ((mt) * 8))
#define PAGE_SHIFT 12
#define PAGE_SIZE (1 << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
/*
* Memory types available.
*/
#define MT_DEVICE_nGnRnE 0
#define MT_DEVICE_nGnRE 1
#define MT_DEVICE_GRE 2
#define MT_NORMAL_NC 3
#define MT_NORMAL 4
/*
* TCR flags
*/
#define TCR_TxSZ(x) ((((64) - (x)) << 16) | (((64) - (x)) << 0))
#define TCR_IRGN_WBWA (((1) << 8) | ((1) << 24))
#define TCR_ORGN_WBWA (((1) << 10) | ((1) << 26))
#define TCR_SHARED (((3) << 12) | ((3) << 28))
#define TCR_TBI0 ((1) << 37)
#define TCR_TBI1 ((1) << 38)
#define TCR_ASID16 ((1) << 36)
#define TCR_TG1_16K ((1) << 30)
#define TCR_TG1_4K ((0) << 30)
#define TCR_FLAGS (TCR_IRGN_WBWA | TCR_ORGN_WBWA | TCR_SHARED)
/* Number of virtual address bits for 4KB page */
#define VA_BITS 48
#define PT_DEVICE 0x707
#define PT_PT 0x713
#define PT_MEM 0x713
#define PT_MEM_CD 0x70F
#define PT_SELF ((1) << 55)
#define ALIGN .align 4
#define END(name) \
.size name, .-name
#define ENDPROC(name) \
.type name, @function; \
END(name)
#define ENTRY(name) \
.globl name; \
ALIGN; \
name:
.section .mboot
.global _start
_start:
b start64
.align 8
.global base
base: .quad 0
.global limit
limit: .quad 0
.global cpu_freq
cpu_freq: .dword 0
.global boot_processor
boot_processor: .dword 0
.global cpu_online
cpu_online: .dword 0
.global possible_cpus
possible_cpus: .dword 0
.global current_boot_id
current_boot_id: .dword 0
.global isle
isle: .dword -1
.global possible_isles
possible_isles: .dword 1
.global uhyve
uhyve: .dword 0
.global single_kernel
single_kernel: .dword 1
.global image_size
image_size: .quad 0
.global hcip
hcip: .byte 10,0,5,2
.global hcgateway
hcgateway: .byte 10,0,5,1
.global hcmask
hcmask: .byte 255,255,255,0
.global host_logical_addr
host_logical_addr: .quad 0
.global uart_mmio
uart_mmio: .dword 0x9000000 // Initialize with QEMU's UART address
.global cmdline
cmdline: .quad 0
.global cmdsize
cmdsize: .quad 0
.global current_stack_address
current_stack_address: .quad boot_stack_bottom
.global current_percore_address
current_percore_address: .quad PERCORE
.global boot_gtod
boot_gtod: .quad 0
start64:
//mrs x0, s3_1_c15_c3_0 // Read EL1 Configuration Base Address Register
/* disable interrupts */
msr daifset, #0b111
/* store x5=dtb */
/*adrp x1, dtb
str x5, [x1, #:lo12:dtb]*/
/* reset thread id registers */
mov x0, #0
msr tpidr_el0, x0
msr tpidr_el1, x0
/*
* Disable the MMU. We may have entered the kernel with it on and
* will need to update the tables later. If this has been set up
* with anything other than a VA == PA map then this will fail,
* but in this case the code to find where we are running from
* would have also failed.
*/
dsb sy
mrs x2, sctlr_el1
bic x2, x2, #0x1
msr sctlr_el1, x2
isb
/* Calculate where we are */
//bl _calc_offset
/* Setup CPU for turnning the MMU on. */
bl _setup_cpu
/* Setup the initial page table. */
bl _setup_pgtable
/* Load TTBRx */
mov x0, xzr
msr ttbr1_el1, x0
ldr x0, =l0_pgtable
msr ttbr0_el1, x0
isb
/* Set exception table */
ldr x0, =vector_table
msr vbar_el1, x0
/* Enable hardware coherency between cores */
/*mrs x0, S3_1_c15_c2_1 // read EL1 CPU Extended Control Register
orr x0, x0, #(1 << 6) // set the SMPEN bit
msr S3_1_c15_c2_1, x0 // write EL1 CPU Extended Control Register
isb*/
/* Turning on MMU */
dsb sy
/*
* Prepare system control register (SCTRL)
*
*
* UCI [26] Enables EL0 access in AArch64 for DC CVAU, DC CIVAC,
DC CVAC and IC IVAU instructions
* EE [25] Explicit data accesses at EL1 and Stage 1 translation
table walks at EL1 & EL0 are little-endian
* EOE [24] Explicit data accesses at EL0 are little-endian
* WXN [19] Regions with write permission are not forced to XN
* nTWE [18] WFE instructions are executed as normal
* nTWI [16] WFI instructions are executed as normal
* UCT [15] Enables EL0 access in AArch64 to the CTR_EL0 register
* DZE [14] Execution of the DC ZVA instruction is allowed at EL0
* I [12] Instruction caches enabled at EL0 and EL1
* UMA [9] Disable access to the interrupt masks from EL0
* SED [8] The SETEND instruction is available
* ITD [7] The IT instruction functionality is available
* THEE [6] ThumbEE is disabled
* CP15BEN [5] CP15 barrier operations disabled
* SA0 [4] Stack Alignment check for EL0 enabled
* SA [3] Stack Alignment check enabled
* C [2] Data and unified enabled
* A [1] Alignment fault checking disabled
* M [0] MMU enable
*/
ldr x0, =0x4D5D91D
msr sctlr_el1, x0
ldr x0, =mmu_on
br x0
mmu_on:
/* Pointer to stack base */
ldr x1, =(boot_stack+KERNEL_STACK_SIZE-0x10)
mov sp, x1
/* Test core ID */
mrs x0, mpidr_el1
ldr x0, =cpu_online
ldr x0, [x0]
cmp x0, 0
b.ne application_processor_main
bl boot_processor_main
bl halt
smp:
//bl smp_main
/* halt */
halt:
wfe
b halt
.section .text
_setup_cpu:
ic iallu
tlbi vmalle1is
dsb ish
/*
* Setup memory attribute type tables
*
* Memory regioin attributes for LPAE:
*
* n = AttrIndx[2:0]
* n MAIR
* DEVICE_nGnRnE 000 00000000 (0x00)
* DEVICE_nGnRE 001 00000100 (0x04)
* DEVICE_GRE 010 00001100 (0x0c)
* NORMAL_NC 011 01000100 (0x44)
* NORMAL 100 11111111 (0xff)
*/
ldr x0, =(MAIR(0x00, MT_DEVICE_nGnRnE) | \
MAIR(0x04, MT_DEVICE_nGnRE) | \
MAIR(0x0c, MT_DEVICE_GRE) | \
MAIR(0x44, MT_NORMAL_NC) | \
MAIR(0xff, MT_NORMAL))
msr mair_el1, x0
/*
* Setup translation control register (TCR)
*/
// determine physical address size
mrs x0, id_aa64mmfr0_el1
and x0, x0, 0xF
lsl x0, x0, 32
ldr x1, =(TCR_TxSZ(VA_BITS) | TCR_TG1_4K | TCR_FLAGS )
orr x0, x0, x1
mrs x1, id_aa64mmfr0_el1
bfi x0, x1, #32, #3
msr tcr_el1, x0
/*
* Enable FP/ASIMD in Architectural Feature Access Control Register,
*/
mov x0, #3 << 20
msr cpacr_el1, x0
/*
* Reset debug controll register
*/
msr mdscr_el1, xzr
ret
_setup_pgtable:
ldr x0, =cpu_online
ldr x0, [x0]
cmp x0, 0
b.ne 4f
ldr x0, =kernel_start
ldr x1, =image_size
ldr x1, [x1]
add x0, x0, x1
/* align to a 16KByte boundary */
add x0, x0, 0x10000
mov x1, ~0xFFFF
and x0, x0, x1
mov x3, x0 // x3 := address of the first allocated page table
// create page table entries for the 1st GB
ldr x1, =l2_pgtable
add x1, x1, 8
add x0, x0, PT_PT
mov x2, xzr
1:
str x0, [x1], 8
add x0, x0, PAGE_SIZE
add x2, x2, 1
cmp x2, 511
b.lo 1b
// create identity mapping
ldr x5, =kernel_start
mov x6, x5
// Create contiguous bit
mov x7, 1
lsl x7, x7, 52
add x7, x7, PT_MEM
orr x5, x5, x7
mov x0, x3 // map until the first page table
mov x7, xzr
2:
str x5, [x3], 8
add x5, x5, PAGE_SIZE
add x6, x6, PAGE_SIZE
add x7, x7, 1
cmp x6, x0
b.lo 2b
/* Clear rest of the boot page tables */
3:
stp xzr, xzr, [x3], 16
stp xzr, xzr, [x3], 16
stp xzr, xzr, [x3], 16
stp xzr, xzr, [x3], 16
add x7, x7, 8
cmp x7, 511*PAGE_SIZE
b.lo 3b
4:
ret
//_calc_offset:
// ldr x22, =_start // x0 := vaddr(_start)
// adr x21, _start // x21 := paddr(_start)
// sub x22, x22, x21 // x22 := phys-offset (vaddr - paddr)
// ret
/*
* There are no PUSH/POP instruction in ARMv8.
* Use STR and LDR for stack accesses.
*/
.macro push, xreg
str \xreg, [sp, #-8]!
.endm
.macro pop, xreg
ldr \xreg, [sp], #8
.endm
.macro trap_entry, el
stp x29, x30, [sp, #-16]!
stp x27, x28, [sp, #-16]!
stp x25, x26, [sp, #-16]!
stp x23, x24, [sp, #-16]!
stp x21, x22, [sp, #-16]!
stp x19, x20, [sp, #-16]!
stp x17, x18, [sp, #-16]!
stp x15, x16, [sp, #-16]!
stp x13, x14, [sp, #-16]!
stp x11, x12, [sp, #-16]!
stp x9, x10, [sp, #-16]!
stp x7, x8, [sp, #-16]!
stp x5, x6, [sp, #-16]!
stp x3, x4, [sp, #-16]!
stp x1, x2, [sp, #-16]!
mrs x22, tpidr_el0
stp x22, x0, [sp, #-16]!
mrs x22, elr_el1
mrs x23, spsr_el1