Skip to content

Commit

Permalink
crates/sel4/sys: Add support for aarch32
Browse files Browse the repository at this point in the history
  • Loading branch information
nspin committed Sep 13, 2023
1 parent 6345385 commit 8d2c123
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 23 deletions.
16 changes: 10 additions & 6 deletions crates/sel4/sys/build/xml/invocations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::path::Path;
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};

use sel4_config::sel4_cfg_bool;

use super::{parse_xml, Condition};

mod parse;
Expand Down Expand Up @@ -557,30 +559,32 @@ impl ParameterTypes {
this.insert_capability("seL4_SchedContext");
this.insert_capability("seL4_SchedControl");

if sel4_config::sel4_cfg_bool!(ARCH_AARCH64) {
if sel4_cfg_bool!(ARCH_AARCH64) | sel4_cfg_bool!(ARCH_AARCH32) {
this.insert_enum("seL4_ARM_VMAttributes", WORD_SIZE);
this.insert_capability("seL4_ARM_Page");
this.insert_capability("seL4_ARM_PageTable");
this.insert_capability("seL4_ARM_PageDirectory");
this.insert_capability("seL4_ARM_PageUpperDirectory");
this.insert_capability("seL4_ARM_PageGlobalDirectory");
this.insert_capability("seL4_ARM_VSpace");
if sel4_cfg_bool!(ARCH_AARCH64) {
this.insert_capability("seL4_ARM_PageUpperDirectory");
this.insert_capability("seL4_ARM_PageGlobalDirectory");
this.insert_capability("seL4_ARM_VSpace");
}
this.insert_capability("seL4_ARM_ASIDControl");
this.insert_capability("seL4_ARM_ASIDPool");
this.insert_capability("seL4_ARM_VCPU");
this.insert_capability("seL4_ARM_IOSpace");
this.insert_capability("seL4_ARM_IOPageTable");
}

if sel4_config::sel4_cfg_bool!(ARCH_RISCV64) || sel4_config::sel4_cfg_bool!(ARCH_RISCV32) {
if sel4_cfg_bool!(ARCH_RISCV64) || sel4_cfg_bool!(ARCH_RISCV32) {
this.insert_enum("seL4_RISCV_VMAttributes", WORD_SIZE);
this.insert_capability("seL4_RISCV_Page");
this.insert_capability("seL4_RISCV_PageTable");
this.insert_capability("seL4_RISCV_ASIDControl");
this.insert_capability("seL4_RISCV_ASIDPool");
}

if sel4_config::sel4_cfg_bool!(ARCH_X86_64) {
if sel4_cfg_bool!(ARCH_X86_64) {
this.insert_enum("seL4_X86_VMAttributes", WORD_SIZE);
this.insert_capability("seL4_X86_IOPort");
this.insert_capability("seL4_X86_IOPortControl");
Expand Down
82 changes: 82 additions & 0 deletions crates/sel4/sys/src/fault/arch/aarch32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use crate::bf::*;
use crate::c::*;

use sel4_config::sel4_cfg_match;

impl seL4_Fault {
pub(crate) fn arch_get_with(label: seL4_Word, length: seL4_Word, f: impl Fn(core::ffi::c_ulong) -> seL4_Word) -> Option<Self> {
Some({
#[sel4_cfg_match]
match label {
seL4_Fault_tag::seL4_Fault_UnknownSyscall => {
assert!(length == seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_Length);
seL4_Fault_UnknownSyscall_Unpacked {
R0: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R0),
R1: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R1),
R2: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R2),
R3: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R3),
R4: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R4),
R5: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R5),
R6: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R6),
R7: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_R7),
FaultIP: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_FaultIP),
SP: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_SP),
LR: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_LR),
CPSR: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_CPSR),
Syscall: f(seL4_UnknownSyscall_Msg::seL4_UnknownSyscall_Syscall),
}
.unsplay()
}
seL4_Fault_tag::seL4_Fault_UserException => {
assert!(length == seL4_UserException_Msg::seL4_UserException_Length);
seL4_Fault_UserException_Unpacked {
FaultIP: f(seL4_UserException_Msg::seL4_UserException_FaultIP),
Stack: f(seL4_UserException_Msg::seL4_UserException_SP),
CPSR: f(seL4_UserException_Msg::seL4_UserException_CPSR),
Number: f(seL4_UserException_Msg::seL4_UserException_Number),
Code: f(seL4_UserException_Msg::seL4_UserException_Code),
}
.unsplay()
}
seL4_Fault_tag::seL4_Fault_VMFault => {
assert!(length == seL4_VMFault_Msg::seL4_VMFault_Length);
seL4_Fault_VMFault_Unpacked {
IP: f(seL4_VMFault_Msg::seL4_VMFault_IP),
Addr: f(seL4_VMFault_Msg::seL4_VMFault_Addr),
PrefetchFault: f(seL4_VMFault_Msg::seL4_VMFault_PrefetchFault),
FSR: f(seL4_VMFault_Msg::seL4_VMFault_FSR),
}
.unsplay()
}
#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
seL4_Fault_tag::seL4_Fault_VGICMaintenance => {
assert!(length == seL4_VGICMaintenance_Msg::seL4_VGICMaintenance_Length);
seL4_Fault_VGICMaintenance_Unpacked {
IDX: f(seL4_VGICMaintenance_Msg::seL4_VGICMaintenance_IDX),
}
.unsplay()
}
#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
seL4_Fault_tag::seL4_Fault_VCPUFault => {
assert!(length == seL4_VCPUFault_Msg::seL4_VCPUFault_Length);
seL4_Fault_VCPUFault_Unpacked {
HSR: f(seL4_VCPUFault_Msg::seL4_VCPUFault_HSR),
}
.unsplay()
}
#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
seL4_Fault_tag::seL4_Fault_VPPIEvent => {
// TODO
// assert!(length == seL4_VPPIEvent_Msg::seL4_VPPIEvent_Length);
seL4_Fault_VPPIEvent_Unpacked {
irq: f(seL4_VPPIEvent_Msg::seL4_VPPIEvent_IRQ),
}
.unsplay()
}
_ => {
return None
}
}
})
}
}
3 changes: 3 additions & 0 deletions crates/sel4/sys/src/fault/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ sel4_cfg_if! {
if #[cfg(ARCH_AARCH64)] {
#[path = "aarch64.rs"]
mod imp;
} else if #[cfg(ARCH_AARCH32)] {
#[path = "aarch32.rs"]
mod imp;
} else if #[cfg(any(ARCH_RISCV64, ARCH_RISCV32))] {
#[path = "riscv.rs"]
mod imp;
Expand Down
175 changes: 175 additions & 0 deletions crates/sel4/sys/src/syscalls/helpers/arch/aarch32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
use core::arch::asm;
use core::ffi::c_int;

use sel4_config::sel4_cfg;

use crate::{seL4_Word, seL4_MessageInfo};
use super::sys_id_to_word;

// NOTE:
// asm!() does not allow r6 to be used for input or output operands, because it's sometimes used by LLVM.

pub fn sys_send(
sys: c_int,
dest: seL4_Word,
info_arg: seL4_MessageInfo,
mr0: seL4_Word,
mr1: seL4_Word,
mr2: seL4_Word,
mr3: seL4_Word,
) {
unsafe {
asm!("swi 0",
in("r7") sys_id_to_word(sys),
in("r0") dest,
in("r1") info_arg.into_word(),
in("r2") mr0,
in("r3") mr1,
in("r4") mr2,
in("r5") mr3,
);
}
}

#[sel4_cfg(not(KERNEL_MCS))]
pub fn sys_reply(
sys: c_int,
info_arg: seL4_MessageInfo,
mr0: seL4_Word,
mr1: seL4_Word,
mr2: seL4_Word,
mr3: seL4_Word,
) {
unsafe {
asm!("swi 0",
in("r7") sys_id_to_word(sys),
in("r1") info_arg.into_word(),
in("r2") mr0,
in("r3") mr1,
in("r4") mr2,
in("r5") mr3,
);
}
}

pub fn sys_send_null(
sys: c_int,
src: seL4_Word,
info_arg: seL4_MessageInfo,
) {
unsafe {
asm!("swi 0",
in("r7") sys_id_to_word(sys),
in("r0") src,
in("r1") info_arg.into_word(),
);
}
}

pub fn sys_recv(
sys: c_int,
src: seL4_Word,
out_mr0: &mut seL4_Word,
out_mr1: &mut seL4_Word,
out_mr2: &mut seL4_Word,
out_mr3: &mut seL4_Word,
reply: seL4_Word,
) -> (seL4_MessageInfo, seL4_Word) {
let out_info: seL4_Word;
let out_badge: seL4_Word;
unsafe {
asm!(
"mov r10, r6",
"mov r6, r9",
"swi 0",
"mov r6, r10",
in("r7") sys_id_to_word(sys),
inout("r0") src => out_badge,
out("r1") out_info,
out("r2") *out_mr0,
out("r3") *out_mr1,
out("r4") *out_mr2,
out("r5") *out_mr3,
in("r9") reply,
inout("r10") 0 => _,
);
}
(seL4_MessageInfo::from_word(out_info), out_badge)
}

pub fn sys_send_recv(
sys: c_int,
dest: seL4_Word,
info_arg: seL4_MessageInfo,
in_out_mr0: &mut seL4_Word,
in_out_mr1: &mut seL4_Word,
in_out_mr2: &mut seL4_Word,
in_out_mr3: &mut seL4_Word,
reply: seL4_Word,
) -> (seL4_MessageInfo, seL4_Word) {
let out_info: seL4_Word;
let out_badge: seL4_Word;
unsafe {
asm!(
"mov r10, r6",
"mov r6, r9",
"swi 0",
"mov r6, r10",
in("r7") sys_id_to_word(sys),
inout("r0") dest => out_badge,
inout("r1") info_arg.into_word() => out_info,
inout("r2") *in_out_mr0,
inout("r3") *in_out_mr1,
inout("r4") *in_out_mr2,
inout("r5") *in_out_mr3,
in("r9") reply,
inout("r10") 0 => _,
);
}
(seL4_MessageInfo::from_word(out_info), out_badge)
}

#[sel4_cfg(KERNEL_MCS)]
pub fn sys_nb_send_recv(
sys: c_int,
dest: seL4_Word,
src: seL4_Word,
info_arg: seL4_MessageInfo,
in_out_mr0: &mut seL4_Word,
in_out_mr1: &mut seL4_Word,
in_out_mr2: &mut seL4_Word,
in_out_mr3: &mut seL4_Word,
reply: seL4_Word,
) -> (seL4_MessageInfo, seL4_Word) {
let out_info: seL4_Word;
let out_badge: seL4_Word;
unsafe {
asm!(
"mov r10, r6",
"mov r6, r9",
"swi 0",
"mov r6, r10",
in("r7") sys_id_to_word(sys),
inout("r0") src => out_badge,
inout("r1") info_arg.into_word() => out_info,
inout("r2") *in_out_mr0,
inout("r3") *in_out_mr1,
inout("r4") *in_out_mr2,
inout("r5") *in_out_mr3,
in("r9") reply,
in("r8") dest,
inout("r10") 0 => _,
);
}
(seL4_MessageInfo::from_word(out_info), out_badge)
}

pub fn sys_null(
sys: c_int,
) {
unsafe {
asm!("swi 0",
in("r7") sys_id_to_word(sys),
);
}
}
3 changes: 3 additions & 0 deletions crates/sel4/sys/src/syscalls/helpers/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ sel4_cfg_if! {
if #[cfg(ARCH_AARCH64)] {
#[path = "aarch64.rs"]
mod imp;
} else if #[cfg(ARCH_AARCH32)] {
#[path = "aarch32.rs"]
mod imp;
} else if #[cfg(any(ARCH_RISCV64, ARCH_RISCV32))] {
#[path = "riscv.rs"]
mod imp;
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4/sys/src/wrappers/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ sel4_cfg_if! {

sel4_cfg_if! {
if #[cfg(ENABLE_BENCHMARKS)] {

// TODO
}
}

Expand Down
9 changes: 8 additions & 1 deletion hacking/nix/rust-utils/build-sysroot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ in
, extraManifest ? {}
, extraConfig ? {}
, rustTargetInfo ? defaultRustTargetInfo
, compilerBuiltinsWeakIntrinsics ? false
}:

let
Expand Down Expand Up @@ -62,6 +63,12 @@ let
extraConfig
]);

features = lib.concatStringsSep "," ([
"compiler-builtins-mem"
] ++ lib.optionals compilerBuiltinsWeakIntrinsics [
"compiler-builtins-weak-intrinsics"
]);

in
runCommand "sysroot" {
depsBuildBuild = [ buildPackages.stdenv.cc ];
Expand All @@ -77,7 +84,7 @@ runCommand "sysroot" {
${lib.optionalString release "--release"} \
--target ${rustTargetInfo.name} \
-Z build-std=core,alloc,compiler_builtins \
-Z build-std-features=compiler-builtins-mem \
-Z build-std-features=${features} \
--manifest-path ${workspace}/Cargo.toml \
--target-dir $(pwd)/target
Expand Down
3 changes: 2 additions & 1 deletion hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ superCallPackage ../rust-utils {} self //

# TODO name more configurations
sel4test = makeOverridable' mkSeL4Test {
rust = hostPlatform.is64bit || hostPlatform.isRiscV;
rust = hostPlatform.isAarch || hostPlatform.isRiscV || hostPlatform.isx86_64;
# mcs = true;
};

### helpers
Expand Down
Loading

0 comments on commit 8d2c123

Please sign in to comment.