diff --git a/crates/sel4/sys/build/xml/invocations/mod.rs b/crates/sel4/sys/build/xml/invocations/mod.rs index 0cdcb1739..b56e171a6 100644 --- a/crates/sel4/sys/build/xml/invocations/mod.rs +++ b/crates/sel4/sys/build/xml/invocations/mod.rs @@ -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; @@ -557,14 +559,16 @@ 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"); @@ -572,7 +576,7 @@ impl ParameterTypes { 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"); @@ -580,7 +584,7 @@ impl ParameterTypes { 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"); diff --git a/crates/sel4/sys/src/fault/arch/aarch32.rs b/crates/sel4/sys/src/fault/arch/aarch32.rs new file mode 100644 index 000000000..aa8ae6eca --- /dev/null +++ b/crates/sel4/sys/src/fault/arch/aarch32.rs @@ -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 { + 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 + } + } + }) + } +} diff --git a/crates/sel4/sys/src/fault/arch/mod.rs b/crates/sel4/sys/src/fault/arch/mod.rs index d9190a94d..c19cd68b9 100644 --- a/crates/sel4/sys/src/fault/arch/mod.rs +++ b/crates/sel4/sys/src/fault/arch/mod.rs @@ -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; diff --git a/crates/sel4/sys/src/syscalls/helpers/arch/aarch32.rs b/crates/sel4/sys/src/syscalls/helpers/arch/aarch32.rs new file mode 100644 index 000000000..a421b5945 --- /dev/null +++ b/crates/sel4/sys/src/syscalls/helpers/arch/aarch32.rs @@ -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), + ); + } +} diff --git a/crates/sel4/sys/src/syscalls/helpers/arch/mod.rs b/crates/sel4/sys/src/syscalls/helpers/arch/mod.rs index 452433624..43624fabf 100644 --- a/crates/sel4/sys/src/syscalls/helpers/arch/mod.rs +++ b/crates/sel4/sys/src/syscalls/helpers/arch/mod.rs @@ -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; diff --git a/crates/sel4/sys/src/wrappers/syscalls.rs b/crates/sel4/sys/src/wrappers/syscalls.rs index aa59c1c41..4ae58914e 100644 --- a/crates/sel4/sys/src/wrappers/syscalls.rs +++ b/crates/sel4/sys/src/wrappers/syscalls.rs @@ -410,7 +410,7 @@ sel4_cfg_if! { sel4_cfg_if! { if #[cfg(ENABLE_BENCHMARKS)] { - + // TODO } } diff --git a/hacking/nix/rust-utils/build-sysroot.nix b/hacking/nix/rust-utils/build-sysroot.nix index 167cadb73..706045cd5 100644 --- a/hacking/nix/rust-utils/build-sysroot.nix +++ b/hacking/nix/rust-utils/build-sysroot.nix @@ -18,6 +18,7 @@ in , extraManifest ? {} , extraConfig ? {} , rustTargetInfo ? defaultRustTargetInfo +, compilerBuiltinsWeakIntrinsics ? false }: let @@ -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 ]; @@ -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 diff --git a/hacking/nix/scope/default.nix b/hacking/nix/scope/default.nix index 8242bd17f..57cd01d01 100644 --- a/hacking/nix/scope/default.nix +++ b/hacking/nix/scope/default.nix @@ -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 diff --git a/hacking/nix/scope/sel4test/default.nix b/hacking/nix/scope/sel4test/default.nix index 111efb2c0..3e583aaa5 100644 --- a/hacking/nix/scope/sel4test/default.nix +++ b/hacking/nix/scope/sel4test/default.nix @@ -28,6 +28,7 @@ , mcs ? false , smp ? false , virtualization ? false +, filter ? ".*" }: with lib; @@ -50,6 +51,7 @@ let "-DSMP=${bool smp}" "-DSIMULATION=TRUE" "-DLibSel4UseRust=${bool rust}" + "-DLibSel4TestPrinterRegex='${filter}'" ] ++ lib.optionals rust [ "-DHACK_CARGO_MANIFEST_PATH=${workspace}/Cargo.toml" "-DHACK_CARGO_CONFIG=${cargoConfig}" @@ -59,7 +61,6 @@ let "-DPLATFORM=pc99" ] ++ lib.optionals hostPlatform.isRiscV [ "-DPLATFORM=spike" - "-DHACK_COMPILER_BUILTINS_SYMBOLS=${compilerBuiltinsSymbols}" ] ++ lib.optionals hostPlatform.isAarch [ "-DPLATFORM=qemu-arm-virt" "-DARM_HYP=${bool virtualization}" @@ -119,13 +120,9 @@ let release = false; inherit rustTargetInfo; extraManifest = profiles; + compilerBuiltinsWeakIntrinsics = true; }; - compilerBuiltinsSymbols = runCommandCC "weaken.txt" {} '' - $NM ${sysroot}/lib/rustlib/${rustTargetInfo.name}/lib/libcompiler_builtins-*.rlib \ - | sed -rn 's,^.* T (__.*)$,\1,p' > $out - ''; - tests = thisStdenv.mkDerivation { name = "sel4test"; @@ -179,13 +176,15 @@ let sed -i 's,tput reset,true,' \ tools/seL4/cmake-tool/simulate_scripts/simulate.py - '' + lib.optionalString hostPlatform.isRiscV64 '' + # HACK with this aarch32 toolchain, sizeof(SUCCESS) != sizeof(test_result_t) + sed -i 's|test_eq(res, SUCCESS);|test_eq((int)res, SUCCESS);|' \ + projects/sel4test/apps/sel4test-tests/src/tests/ipc.c + '' + lib.optionalString hostPlatform.isx86 '' # HACK - sed -i 's|test_bad_instruction, true|test_bad_instruction, false|' \ - projects/sel4test/apps/sel4test-tests/src/tests/faults.c - - sed -i 's|printf("Bootstrapping kernel\\n");|printf("Bootstrapping kernel %lx\\n", v_entry);|' \ - kernel/src/arch/riscv/kernel/boot.c + sed -i \ + -e 's|test_scheduler_accuracy,|test_scheduler_accuracy, false \&\&|' \ + -e 's|test_ordering_periodic_threads,|test_ordering_periodic_threads, false \&\&|' \ + projects/sel4test/apps/sel4test-tests/src/tests/scheduler.c ''; configurePhase = '' diff --git a/hacking/nix/scope/sources.nix b/hacking/nix/scope/sources.nix index 385fee204..28be21ac6 100644 --- a/hacking/nix/scope/sources.nix +++ b/hacking/nix/scope/sources.nix @@ -54,7 +54,7 @@ in rec { rust-sel4test = fetchGit { url = "https://github.com/coliasgroup/seL4.git"; - rev = "4c9ab2779783c008346e0139df6d9cfc53c047fd"; # rust-sel4test + rev = "07266a57e1073e4dfb4a4f9dddc31b197abdb2a0"; # rust-sel4test local = localRoot + "/seL4"; # useLocal = true; }; diff --git a/hacking/nix/top-level/default.nix b/hacking/nix/top-level/default.nix index 6ad50783e..00098a20f 100644 --- a/hacking/nix/top-level/default.nix +++ b/hacking/nix/top-level/default.nix @@ -20,7 +20,7 @@ in { sel4testInstances = (map (x: x.this.sel4test) [ pkgs.host.aarch64.none - pkgs.host.aarch32.linux # TODO figure out why none doesn't pass + pkgs.host.aarch32.none pkgs.host.riscv64.none pkgs.host.riscv32.none # TODO figure out why none doesn't build