├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Cargo.toml ├── LICENSE ├── README.md ├── README.rx ├── Xargo.toml ├── build.rs ├── deps ├── LICENSE_BSD2.txt ├── LICENSE_GPLv2.txt └── README.md ├── package └── CMakeLists.txt ├── res └── bindgen_wrapper.h ├── rust-toolchain ├── src └── lib.rs └── test_configs ├── README.md ├── aarch64-sel4-fel4.json ├── armv7-sel4-fel4.json ├── fel4.toml └── x86_64-sel4-fel4.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.idea 2 | **/*.rs.bk 3 | *.swp 4 | target 5 | Cargo.lock 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libsel4-sys/deps/musllibc"] 2 | path = deps/musllibc 3 | url = https://github.com/seL4/musllibc.git 4 | [submodule "libsel4-sys/deps/seL4_kernel"] 5 | path = deps/seL4_kernel 6 | url = https://github.com/seL4/seL4.git 7 | [submodule "libsel4-sys/deps/seL4_libs"] 8 | path = deps/seL4_libs 9 | url = https://github.com/seL4/seL4_libs.git 10 | [submodule "libsel4-sys/deps/seL4_tools"] 11 | path = deps/seL4_tools 12 | url = https://github.com/seL4/seL4_tools.git 13 | [submodule "libsel4-sys/deps/util_libs"] 14 | path = deps/util_libs 15 | url = https://github.com/seL4/util_libs.git 16 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.7.2) 2 | 3 | include(deps/seL4_tools/cmake-tool/base.cmake) 4 | 5 | add_subdirectory(deps/musllibc musllibc) 6 | add_subdirectory(deps/seL4_libs seL4_libs) 7 | add_subdirectory(deps/util_libs util_libs) 8 | add_subdirectory(package) 9 | 10 | include(deps/seL4_tools/cmake-tool/configuration.cmake) 11 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libsel4-sys" 3 | version = "0.5.0" 4 | publish = false 5 | build = "build.rs" 6 | links = "sel4" 7 | 8 | [lib] 9 | name = "sel4_sys" 10 | path = "src/lib.rs" 11 | 12 | [dependencies] 13 | rlibc = "1.0" 14 | 15 | [build-dependencies] 16 | cmake = "0.1" 17 | bindgen = { version = "0.35", default-features = false } 18 | fel4-config = { git = "https://github.com/PolySync/fel4-config.git", branch = "master" } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 PolySync Technologies 4 | 5 | Permission is hereby granted, free of charge, to any 6 | person obtaining a copy of this software and associated 7 | documentation files (the "Software"), to deal in the 8 | Software without restriction, including without 9 | limitation the rights to use, copy, modify, merge, 10 | publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software 12 | is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice 16 | shall be included in all copies or substantial portions 17 | of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 20 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 21 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 22 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 23 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 26 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | DEALINGS IN THE SOFTWARE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libsel4-sys 2 | 3 | ## Overview 4 | 5 | Builds the sel4 kernel and generates Rust bindings around it, 6 | as configured by a feL4 manifest. 7 | 8 | This library provides thin Rust bindings around the [seL4 codebase](https://github.com/seL4/seL4); 9 | more idiomatic Rust wrappers for the enclosed functionality will be supplied in other crates. 10 | 11 | Intended for use in projects managed by 12 | [cargo-fel4](https://github.com/PolySync/cargo-fel4), see that repository 13 | for introductory materials. 14 | 15 | ## Getting Started 16 | 17 | ### Dependencies 18 | 19 | libsel4-sys uses git submodules to make seL4 related code available 20 | locally. Building the seL4 code requires several system dependencies 21 | to be installed. The few Rust dependencies are managed by Cargo.toml, 22 | so Cargo is necessary, as well as Xargo for cross-compilation. Rustup 23 | is the recommended Rust toolchain manager. 24 | 25 | * [rust](https://github.com/rust-lang-nursery/rustup.rs) (nightly) 26 | * [xargo](https://github.com/japaric/xargo) (for cross-compiling) 27 | * [gcc/g++ cross compilers](https://gcc.gnu.org/) (for ARM targets) 28 | * [cmake](https://cmake.org/download/) (for seL4's build) 29 | * [ninja-build](https://ninja-build.org/) (for seL4's build) 30 | * [python](https://python.org/) (for seL4's build) 31 | * [xmlint](http://xmlsoft.org/xmllint.html) (for seL4's build) 32 | 33 | ### Building 34 | 35 | This project is intended to be built in the context of the `cargo fel4` command, which manages 36 | the piping of key environment variables relevant to the downstream project. 37 | 38 | * Install [Rust Nightly](https://github.com/rust-lang-nursery/rustup.rs) 39 | ```bash 40 | # Download the rustup install script 41 | wget https://static.rust-lang.org/rustup/rustup-init.sh 42 | 43 | # Install rustup 44 | chmod +x rustup-init.sh 45 | sh rustup-init.sh 46 | 47 | rustup install nightly 48 | ``` 49 | * Install [xargo](https://github.com/japaric/xargo) 50 | ```bash 51 | # Xargo requires rust-src component 52 | rustup component add --toolchain nightly rust-src 53 | 54 | # Install Xargo 55 | cargo +nightly install xargo 56 | ``` 57 | * Install the [gnu cross compilers](https://gcc.gnu.org/) 58 | ```bash 59 | # Used by the armv7-sel4-fel4 target 60 | sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf 61 | 62 | # Used by the aarch64-sel4-fel4 target 63 | sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu 64 | ``` 65 | * Install Python, pip, and a sel4-specific pip package. 66 | ```bash 67 | # Install python and pip, if you don't have them already 68 | sudo apt-get install python-pip 69 | 70 | pip install sel4-deps 71 | ``` 72 | * Install [cmake](https://cmake.org/download/) 73 | 74 | CMake version `3.7.2` or greater is required. 75 | Binary releases are available from [cmake.org](https://cmake.org/download/). 76 | 77 | An example workflow for a recent binary installation on Ubuntu 78 | [can be found on StackExchange's askUbuntu](https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line/865294#865294). 79 | 80 | Alternately, you can use Python's `pip` tool to install the latest cmake. 81 | ```bash 82 | sudo pip install --upgrade cmake 83 | ``` 84 | * Install [ninja-build](https://ninja-build.org/) 85 | Ninja version `1.7.1` or greater is required or greater is required due to the seL4 build system. 86 | Binary releases are available from [github](https://github.com/ninja-build/ninja/releases). 87 | 88 | Ubuntu users can typically install ninja using apt-get. 89 | 90 | ```bash 91 | sudo apt-get install ninja-build 92 | ``` 93 | * [xmlint](http://xmlsoft.org/xmllint.html) 94 | 95 | The underlying seL4 build system requires `xmlint`. 96 | 97 | ```bash 98 | sudo apt-get install libxml2-utils 99 | ``` 100 | * Install [cargo-fel4](https://github.com/PolySync/cargo-fel4) using the directions from that repository. 101 | * Use `cargo-fel4` to create a new feL4 project, which will automatically include `libsel4-sys` as a dependency to build 102 | ```bash 103 | cargo fel4 new demo_project 104 | cd demo_project 105 | cargo fel4 build 106 | ``` 107 | * Manual builds are available as an alternative to using `cargo-fel4`, though are not recommended for general use. 108 | * Clone the libsel4-sys repository 109 | ```bash 110 | git clone git@github.com:PolySync/libsel4-sys.git 111 | cd libsel4-sys 112 | ``` 113 | * Pull in seL4 related dependencies to the local filesystem 114 | ```bash 115 | git submodule update --init 116 | ``` 117 | * Manual builds require that the `FEL4_MANIFEST_PATH` environment variable is set and 118 | includes a path pointing to a fel4.toml file, as specified by the `fel4-config` crate. 119 | Additionally, the `RUST_TARGET_PATH` must be supplied, pointing to the directory that 120 | contains the Rust target specification JSON files relevant for the desired build target. 121 | ```bash 122 | RUST_TARGET_PATH=$PWD/test_configs FEL4_MANIFEST_PATH=$PWD/test_configs/fel4.toml xargo rustc --target x86_64-sel4-fel4 -vv 123 | ``` 124 | 125 | ### Installation 126 | 127 | libsel4-sys may be included in your Rust project by including it in your Cargo.toml. 128 | 129 | * In the relevant `[dependencies]` section: 130 | ```toml 131 | libsel4-sys = { git = "https://github.com/PolySync/libsel4-sys.git", branch = "master" } 132 | ``` 133 | 134 | ## Usage 135 | 136 | The generated bindings should be treated as relatively ephemeral and dynamic compared 137 | to most Rust libraries. The output is context-specific to the target (e.g. "armv7-sel4-fel4") 138 | and the set of configuration flags derived from the input feL4 manifest file. 139 | 140 | See the Rust docs for a surface-level overview of the raw APIs exposed. 141 | 142 | ```bash 143 | RUST_TARGET_PATH=$PWD/test_configs FEL4_MANIFEST_PATH=$PWD/test_configs/fel4.toml xargo doc --target x86_64-sel4-fel4 -vv 144 | ``` 145 | 146 | ### Examples 147 | 148 | * Creating a seL4_CapRights_t instance 149 | ```rust 150 | extern crate libsel4_sys; 151 | use libsel4_sys::{seL4_Word, seL4_CapRights_new}; 152 | let cap_rights = unsafe { seL4_CapRights_new(0 as seL4_Word, 1 as seL4_Word, 0 as seL4_Word); }; 153 | ``` 154 | 155 | ## Tests 156 | 157 | Currently, all testing is done one level up, in the `cargo-fel4` repo, 158 | which has the capability to auto-generate the appropriate test runner 159 | code and exercise the resultant artifacts. 160 | 161 | ### Building 162 | 163 | See the [cargo-fel4 repository](https://github.com/PolySync/cargo-fel4) for its 164 | build and installation. 165 | 166 | ### Running 167 | 168 | Once `cargo-fel4` and the `libsel4-sys` dependencies are installed, you should be able to run: 169 | 170 | ```bash 171 | cargo fel4 new tests 172 | cd tests 173 | cargo fel4 test build 174 | cargo fel4 test simulate 175 | ``` 176 | 177 | # License 178 | 179 | © 2018, PolySync Technologies, Inc. 180 | 181 | * Jon Lamb [email](mailto:jlamb@polysync.io) 182 | * Zack Pierce [email](mailto:zpierce@polysync.io) 183 | * Dan Pittman [email](mailto:dpittman@polysync.io) 184 | 185 | Please see the [LICENSE](./LICENSE) file for more details 186 | 187 | -------------------------------------------------------------------------------- /README.rx: -------------------------------------------------------------------------------- 1 | # -!!- 2 | 3 | ## Overview 4 | 5 | -!!- 6 | 7 | -""- 8 | 9 | ## Getting Started 10 | 11 | ### Dependencies 12 | 13 | -??- 14 | 15 | * -??- 16 | * [-!!-](-!!-) -??- 17 | * -""- 18 | 19 | ### Building 20 | 21 | -!!- 22 | 23 | * -!!- 24 | ```-??- 25 | ``` 26 | * -""- 27 | 28 | ### Installation 29 | 30 | -!!- 31 | 32 | * -!!- 33 | ```-??- 34 | ``` 35 | * -""- 36 | 37 | ## Usage 38 | 39 | -!!- 40 | 41 | -""- 42 | 43 | ```-!!- 44 | ``` 45 | 46 | * -??- 47 | 48 | ### Examples 49 | 50 | -??- 51 | 52 | -""- 53 | 54 | * -!!- 55 | * -""- 56 | 57 | ## Tests 58 | 59 | -!!- 60 | 61 | ### Building 62 | 63 | -!!- 64 | 65 | ```-??- 66 | ``` 67 | 68 | ### Running 69 | 70 | -!!- 71 | 72 | ```-??- 73 | ``` 74 | 75 | # License 76 | 77 | © 2018, PolySync Technologies, Inc. 78 | 79 | * -!!- [-!!-](mailto:-!!-@-!!-) 80 | * -""- 81 | 82 | Please see the [LICENSE](./LICENSE) file for more details 83 | -------------------------------------------------------------------------------- /Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.x86_64-sel4-fel4.dependencies] 2 | alloc = {} 3 | [target.armv7-sel4-fel4.dependencies] 4 | alloc = {} 5 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | //! This is the build script for the `libsel4-sys` package. 2 | //! 3 | //! It builds both the kernel binary and libsel4.a C bindings. 4 | //! 5 | 6 | extern crate bindgen; 7 | extern crate cmake; 8 | extern crate fel4_config; 9 | 10 | use bindgen::Builder; 11 | use cmake::Config as CmakeConfig; 12 | use fel4_config::{Fel4Config, SupportedPlatform, SupportedTarget}; 13 | use std::env; 14 | use std::fs; 15 | use std::path::PathBuf; 16 | 17 | struct BindgenHeaderIncludeConfig { 18 | kernel_arch: String, 19 | kernel_sel4_arch: String, 20 | width: String, 21 | platform: String, 22 | } 23 | 24 | fn main() { 25 | // Resolve fel4 configuration from the manifest located via FEL4_MANIFEST_PATH 26 | // and PROFILE env-vars 27 | let (fel4_manifest_path, build_profile) = match fel4_config::infer_manifest_location_from_env() 28 | { 29 | Ok(p) => p, 30 | Err(e) => panic!( 31 | "libsel4-sys build.rs had trouble figuring out where to pull fel4 config from. {}", 32 | e 33 | ), 34 | }; 35 | println!("cargo:rerun-if-changed={}", fel4_manifest_path.display()); 36 | let fel4 = match fel4_config::get_fel4_config(&fel4_manifest_path, &build_profile) { 37 | Ok(f) => f, 38 | Err(e) => panic!( 39 | "libsel4-sys build.rs ran into trouble with the fel4 manifest found at {:?}. {}", 40 | &fel4_manifest_path, e 41 | ), 42 | }; 43 | println!( 44 | "cargo:rerun-if-changed={}", 45 | fs::canonicalize(&fel4_manifest_path) 46 | .expect("Could not canonicalize the fel4 manifest path") 47 | .display() 48 | ); 49 | 50 | // Configure the CMake build using the data resolved from the fel4 manifest 51 | let mut cmake_build_config = CmakeConfig::new("."); 52 | match fel4_config::configure_cmake_build_from_env(&mut cmake_build_config, &fel4) { 53 | Ok(_) => {}, 54 | Err(e) => { panic!("libsel4-sys build.rs ran into trouble configuring the sel4 kernel CMake build when using the fel4 manifest from {:?}. {}", &fel4_manifest_path, e) }, 55 | }; 56 | 57 | // Delete any existing CMakeCache.txt to prevent seL4/CMake from 58 | // unexpected reconfigurations 59 | let prev_cache_path = PathBuf::from(getenv_unwrap("OUT_DIR")) 60 | .join("build") 61 | .join("CMakeCache.txt"); 62 | 63 | if prev_cache_path.exists() { 64 | fs::remove_file(prev_cache_path).expect("failed to delete previous CMakeCache.txt file"); 65 | } 66 | 67 | // Perform the cmake build 68 | let cargo_output_path = cmake_build_config.build(); 69 | 70 | generate_bindings(&fel4, cargo_output_path.join("build").join("staging")); 71 | 72 | // Our links key is "sel4" 73 | // These non-cargo variables can be read by consumer 74 | // packages 75 | print_cargo_links_keys(cargo_output_path.clone()); 76 | 77 | print_cargo_rerun_if_flags(); 78 | 79 | // Copy artifacts if environment variable is set 80 | let dest_env = env::var("FEL4_ARTIFACT_PATH"); 81 | match dest_env { 82 | Ok(p) => copy_artifacts(cargo_output_path.clone(), PathBuf::from(p)), 83 | Err(_) => (), 84 | } 85 | 86 | println!( 87 | "cargo:rustc-link-search=native={}", 88 | cargo_output_path.display() 89 | ); 90 | 91 | // Native libsel4.a location 92 | println!( 93 | "cargo:rustc-link-search=native={}", 94 | cargo_output_path.join("build").join("libsel4").display() 95 | ); 96 | 97 | println!("cargo:rustc-link-lib=static=sel4"); 98 | } 99 | 100 | /// Print common links keys used by consumer packages. 101 | /// 102 | /// You can access these as environment variables: 103 | /// - `DEP_SEL4_CMAKE_CACHE_PATH` 104 | /// - `DEP_SEL4_KERNEL_PATH` 105 | /// - `DEP_SEL4_SIMULATION_SCRIPT_PATH` 106 | fn print_cargo_links_keys(cargo_output_path: PathBuf) { 107 | println!( 108 | "cargo:cmake_cache_path={}", 109 | cargo_output_path 110 | .join("build") 111 | .join("CMakeCache.txt") 112 | .display() 113 | ); 114 | 115 | println!( 116 | "cargo:kernel_path={}", 117 | cargo_output_path 118 | .join("build") 119 | .join("images") 120 | .join("kernel") 121 | .display() 122 | ); 123 | 124 | println!( 125 | "cargo:simulation_script_path={}", 126 | cargo_output_path.join("build").join("simulate").display() 127 | ); 128 | } 129 | 130 | /// Print common environment rerun-if's. 131 | fn print_cargo_rerun_if_flags() { 132 | println!("cargo:rerun-if-env-changed=OUT_DIR"); 133 | println!("cargo:rerun-if-env-changed=PROFILE"); 134 | println!("cargo:rerun-if-env-changed=FEL4_MANIFEST_PATH"); 135 | println!("cargo:rerun-if-env-changed=FEL4_ARTIFACT_PATH"); 136 | println!("cargo:rerun-if-env-changed=FEL4_ROOT_TASK_IMAGE_PATH"); 137 | println!("cargo:rerun-if-changed=package"); 138 | println!("cargo:rerun-if-changed=package/CMakeLists.txt"); 139 | } 140 | 141 | /// Copy build external build artifacts (kernel/simulation-script) into the 142 | /// artifact directory. 143 | fn copy_artifacts(artifact_path: PathBuf, output_path: PathBuf) { 144 | if !output_path.exists() { 145 | fs::create_dir_all(&output_path).unwrap(); 146 | } 147 | 148 | fs::copy( 149 | artifact_path.join("build").join("images").join("kernel"), 150 | output_path.join("kernel"), 151 | ).unwrap(); 152 | 153 | fs::copy( 154 | artifact_path.join("build").join("simulate"), 155 | output_path.join("simulate"), 156 | ).unwrap(); 157 | 158 | fs::copy( 159 | artifact_path.join("build").join("CMakeCache.txt"), 160 | output_path.join("CMakeCache.txt"), 161 | ).unwrap(); 162 | 163 | println!( 164 | "cargo:rerun-if-changed={}", 165 | output_path.join("kernel").display() 166 | ); 167 | println!( 168 | "cargo:rerun-if-changed={}", 169 | output_path.join("simulate").display() 170 | ); 171 | } 172 | 173 | /// Generate the libsel4 Rust bindings. 174 | fn generate_bindings(fel4: &Fel4Config, include_path: PathBuf) { 175 | let bindgen_include_config = get_bindgen_include_config(fel4); 176 | 177 | let target_args = if fel4.target == SupportedTarget::Armv7Sel4Fel4 { 178 | String::from("-mfloat-abi=hard") 179 | } else { 180 | String::from("") 181 | }; 182 | 183 | let bindings = Builder::default() 184 | .header("res/bindgen_wrapper.h") 185 | .whitelist_recursively(true) 186 | .no_copy("*") 187 | .use_core() 188 | // Our custom c_types 189 | .ctypes_prefix("c_types") 190 | // These are implemented by this crate 191 | .blacklist_type("strcpy") 192 | .blacklist_type("__assert_fail") 193 | .clang_arg(target_args) 194 | .clang_arg(format!("-I{}", include_path.join("include").display())) 195 | .clang_arg(format!("-I{}", include_path.join(bindgen_include_config.kernel_arch).display())) 196 | .clang_arg(format!("-I{}", include_path.join(bindgen_include_config.kernel_sel4_arch).display())) 197 | .clang_arg(format!("-I{}", include_path.join(bindgen_include_config.width).display())) 198 | .clang_arg(format!("-I{}", include_path.join(bindgen_include_config.platform).display())) 199 | .clang_arg(format!("-I{}", include_path.join("autoconf").display())) 200 | .clang_arg(format!("-I{}", include_path.join("gen_config").display())) 201 | .clang_arg(format!("-I{}", include_path.join("include").display())) 202 | .generate() 203 | .expect("failed to generate bindings"); 204 | 205 | bindings 206 | .write_to_file(PathBuf::from(getenv_unwrap("OUT_DIR")).join("bindings.rs")) 207 | .expect("failed to write bindings to file"); 208 | } 209 | 210 | /// Parses the target and platform data to produce 211 | /// bindgen compatable include 212 | /// token Strings. 213 | /// 214 | /// Returns a BindgenHeaderIncludeConfig. 215 | fn get_bindgen_include_config(fel4: &Fel4Config) -> BindgenHeaderIncludeConfig { 216 | // TODO - expand here when we add more supported platforms/targets in 217 | // fel4-config or move more of this include knowledge to fel4-config 218 | // (painful) 219 | match &fel4.target { 220 | &SupportedTarget::X8664Sel4Fel4 => BindgenHeaderIncludeConfig { 221 | kernel_arch: String::from("x86"), 222 | kernel_sel4_arch: String::from("x86_64"), 223 | width: String::from("64"), 224 | platform: fel4.platform.full_name().to_string(), 225 | }, 226 | t @ &SupportedTarget::Armv7Sel4Fel4 => { 227 | // TODO - add more mappings as platform options expand 228 | //"exynos5410" => "exynos5", 229 | //"exynos5422" => "exynos5", 230 | //"exynos5250" => "exynos5", 231 | //"imx7sabre" => "imx7", 232 | //"rpi3" => "bcm2837", 233 | 234 | // Platform names don't always match the associated sub-directory used for 235 | // header includes so a mapping is necessary 236 | let plat_include_dir = match &fel4.platform { 237 | p @ &SupportedPlatform::PC99 => panic!( 238 | "{} target is not supported in combination with {} platform", 239 | t.full_name(), 240 | p.full_name() 241 | ), 242 | p @ &SupportedPlatform::Tx1 => panic!( 243 | "{} target is not supported in combination with {} platform", 244 | t.full_name(), 245 | p.full_name() 246 | ), 247 | &SupportedPlatform::Sabre => "imx6", 248 | }; 249 | BindgenHeaderIncludeConfig { 250 | kernel_arch: String::from("arm"), 251 | kernel_sel4_arch: String::from("aarch32"), 252 | width: String::from("32"), 253 | platform: plat_include_dir.to_string(), 254 | } 255 | } 256 | &SupportedTarget::Aarch64Sel4Fel4 => BindgenHeaderIncludeConfig { 257 | kernel_arch: String::from("arm"), 258 | kernel_sel4_arch: String::from("aarch64"), 259 | width: String::from("64"), 260 | platform: fel4.platform.full_name().to_string(), 261 | }, 262 | } 263 | } 264 | 265 | /// Return an environment variable as a String. 266 | fn getenv_unwrap(v: &str) -> String { 267 | match env::var(v) { 268 | Ok(s) => s, 269 | Err(..) => fail(&format!("environment variable `{}` not defined", v)), 270 | } 271 | } 272 | 273 | /// Failure with panic. 274 | fn fail(s: &str) -> ! { 275 | panic!("\n{}\n\nlibsel4-sys build script failed", s) 276 | } 277 | -------------------------------------------------------------------------------- /deps/LICENSE_BSD2.txt: -------------------------------------------------------------------------------- 1 | Files described as being under the "BSD 2-Clause" license fall under the 2 | following license. 3 | 4 | ----------------------------------------------------------------------- 5 | 6 | Copyright (c) 2017 Data61 and other contributors. 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /deps/LICENSE_GPLv2.txt: -------------------------------------------------------------------------------- 1 | 2 | Files described as being under the "GNU General Public License version 2" 3 | or simply the "GPLv2" fall under the following license. 4 | 5 | Note that this copyright does not cover user programs that use kernel 6 | services by normal system calls --- this is merely considered normal use 7 | of the kernel, and does not fall under the heading of "derived work". 8 | 9 | Also note that while the Free Software Foundation owns the copyright to 10 | the license text below, copyright for the actual files included in this 11 | project are held by their respective owners, indicated at the top of 12 | each file. 13 | 14 | 15 | ----------------------------------------------------------------------- 16 | 17 | GNU GENERAL PUBLIC LICENSE 18 | Version 2, June 1991 19 | 20 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | Everyone is permitted to copy and distribute verbatim copies 23 | of this license document, but changing it is not allowed. 24 | 25 | Preamble 26 | 27 | The licenses for most software are designed to take away your 28 | freedom to share and change it. By contrast, the GNU General Public 29 | License is intended to guarantee your freedom to share and change free 30 | software--to make sure the software is free for all its users. This 31 | General Public License applies to most of the Free Software 32 | Foundation's software and to any other program whose authors commit to 33 | using it. (Some other Free Software Foundation software is covered by 34 | the GNU Lesser General Public License instead.) You can apply it to 35 | your programs, too. 36 | 37 | When we speak of free software, we are referring to freedom, not 38 | price. Our General Public Licenses are designed to make sure that you 39 | have the freedom to distribute copies of free software (and charge for 40 | this service if you wish), that you receive source code or can get it 41 | if you want it, that you can change the software or use pieces of it 42 | in new free programs; and that you know you can do these things. 43 | 44 | To protect your rights, we need to make restrictions that forbid 45 | anyone to deny you these rights or to ask you to surrender the rights. 46 | These restrictions translate to certain responsibilities for you if you 47 | distribute copies of the software, or if you modify it. 48 | 49 | For example, if you distribute copies of such a program, whether 50 | gratis or for a fee, you must give the recipients all the rights that 51 | you have. You must make sure that they, too, receive or can get the 52 | source code. And you must show them these terms so they know their 53 | rights. 54 | 55 | We protect your rights with two steps: (1) copyright the software, and 56 | (2) offer you this license which gives you legal permission to copy, 57 | distribute and/or modify the software. 58 | 59 | Also, for each author's protection and ours, we want to make certain 60 | that everyone understands that there is no warranty for this free 61 | software. If the software is modified by someone else and passed on, we 62 | want its recipients to know that what they have is not the original, so 63 | that any problems introduced by others will not reflect on the original 64 | authors' reputations. 65 | 66 | Finally, any free program is threatened constantly by software 67 | patents. We wish to avoid the danger that redistributors of a free 68 | program will individually obtain patent licenses, in effect making the 69 | program proprietary. To prevent this, we have made it clear that any 70 | patent must be licensed for everyone's free use or not licensed at all. 71 | 72 | The precise terms and conditions for copying, distribution and 73 | modification follow. 74 | 75 | GNU GENERAL PUBLIC LICENSE 76 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 77 | 78 | 0. This License applies to any program or other work which contains 79 | a notice placed by the copyright holder saying it may be distributed 80 | under the terms of this General Public License. The "Program", below, 81 | refers to any such program or work, and a "work based on the Program" 82 | means either the Program or any derivative work under copyright law: 83 | that is to say, a work containing the Program or a portion of it, 84 | either verbatim or with modifications and/or translated into another 85 | language. (Hereinafter, translation is included without limitation in 86 | the term "modification".) Each licensee is addressed as "you". 87 | 88 | Activities other than copying, distribution and modification are not 89 | covered by this License; they are outside its scope. The act of 90 | running the Program is not restricted, and the output from the Program 91 | is covered only if its contents constitute a work based on the 92 | Program (independent of having been made by running the Program). 93 | Whether that is true depends on what the Program does. 94 | 95 | 1. You may copy and distribute verbatim copies of the Program's 96 | source code as you receive it, in any medium, provided that you 97 | conspicuously and appropriately publish on each copy an appropriate 98 | copyright notice and disclaimer of warranty; keep intact all the 99 | notices that refer to this License and to the absence of any warranty; 100 | and give any other recipients of the Program a copy of this License 101 | along with the Program. 102 | 103 | You may charge a fee for the physical act of transferring a copy, and 104 | you may at your option offer warranty protection in exchange for a fee. 105 | 106 | 2. You may modify your copy or copies of the Program or any portion 107 | of it, thus forming a work based on the Program, and copy and 108 | distribute such modifications or work under the terms of Section 1 109 | above, provided that you also meet all of these conditions: 110 | 111 | a) You must cause the modified files to carry prominent notices 112 | stating that you changed the files and the date of any change. 113 | 114 | b) You must cause any work that you distribute or publish, that in 115 | whole or in part contains or is derived from the Program or any 116 | part thereof, to be licensed as a whole at no charge to all third 117 | parties under the terms of this License. 118 | 119 | c) If the modified program normally reads commands interactively 120 | when run, you must cause it, when started running for such 121 | interactive use in the most ordinary way, to print or display an 122 | announcement including an appropriate copyright notice and a 123 | notice that there is no warranty (or else, saying that you provide 124 | a warranty) and that users may redistribute the program under 125 | these conditions, and telling the user how to view a copy of this 126 | License. (Exception: if the Program itself is interactive but 127 | does not normally print such an announcement, your work based on 128 | the Program is not required to print an announcement.) 129 | 130 | These requirements apply to the modified work as a whole. If 131 | identifiable sections of that work are not derived from the Program, 132 | and can be reasonably considered independent and separate works in 133 | themselves, then this License, and its terms, do not apply to those 134 | sections when you distribute them as separate works. But when you 135 | distribute the same sections as part of a whole which is a work based 136 | on the Program, the distribution of the whole must be on the terms of 137 | this License, whose permissions for other licensees extend to the 138 | entire whole, and thus to each and every part regardless of who wrote it. 139 | 140 | Thus, it is not the intent of this section to claim rights or contest 141 | your rights to work written entirely by you; rather, the intent is to 142 | exercise the right to control the distribution of derivative or 143 | collective works based on the Program. 144 | 145 | In addition, mere aggregation of another work not based on the Program 146 | with the Program (or with a work based on the Program) on a volume of 147 | a storage or distribution medium does not bring the other work under 148 | the scope of this License. 149 | 150 | 3. You may copy and distribute the Program (or a work based on it, 151 | under Section 2) in object code or executable form under the terms of 152 | Sections 1 and 2 above provided that you also do one of the following: 153 | 154 | a) Accompany it with the complete corresponding machine-readable 155 | source code, which must be distributed under the terms of Sections 156 | 1 and 2 above on a medium customarily used for software interchange; or, 157 | 158 | b) Accompany it with a written offer, valid for at least three 159 | years, to give any third party, for a charge no more than your 160 | cost of physically performing source distribution, a complete 161 | machine-readable copy of the corresponding source code, to be 162 | distributed under the terms of Sections 1 and 2 above on a medium 163 | customarily used for software interchange; or, 164 | 165 | c) Accompany it with the information you received as to the offer 166 | to distribute corresponding source code. (This alternative is 167 | allowed only for noncommercial distribution and only if you 168 | received the program in object code or executable form with such 169 | an offer, in accord with Subsection b above.) 170 | 171 | The source code for a work means the preferred form of the work for 172 | making modifications to it. For an executable work, complete source 173 | code means all the source code for all modules it contains, plus any 174 | associated interface definition files, plus the scripts used to 175 | control compilation and installation of the executable. However, as a 176 | special exception, the source code distributed need not include 177 | anything that is normally distributed (in either source or binary 178 | form) with the major components (compiler, kernel, and so on) of the 179 | operating system on which the executable runs, unless that component 180 | itself accompanies the executable. 181 | 182 | If distribution of executable or object code is made by offering 183 | access to copy from a designated place, then offering equivalent 184 | access to copy the source code from the same place counts as 185 | distribution of the source code, even though third parties are not 186 | compelled to copy the source along with the object code. 187 | 188 | 4. You may not copy, modify, sublicense, or distribute the Program 189 | except as expressly provided under this License. Any attempt 190 | otherwise to copy, modify, sublicense or distribute the Program is 191 | void, and will automatically terminate your rights under this License. 192 | However, parties who have received copies, or rights, from you under 193 | this License will not have their licenses terminated so long as such 194 | parties remain in full compliance. 195 | 196 | 5. You are not required to accept this License, since you have not 197 | signed it. However, nothing else grants you permission to modify or 198 | distribute the Program or its derivative works. These actions are 199 | prohibited by law if you do not accept this License. Therefore, by 200 | modifying or distributing the Program (or any work based on the 201 | Program), you indicate your acceptance of this License to do so, and 202 | all its terms and conditions for copying, distributing or modifying 203 | the Program or works based on it. 204 | 205 | 6. Each time you redistribute the Program (or any work based on the 206 | Program), the recipient automatically receives a license from the 207 | original licensor to copy, distribute or modify the Program subject to 208 | these terms and conditions. You may not impose any further 209 | restrictions on the recipients' exercise of the rights granted herein. 210 | You are not responsible for enforcing compliance by third parties to 211 | this License. 212 | 213 | 7. If, as a consequence of a court judgment or allegation of patent 214 | infringement or for any other reason (not limited to patent issues), 215 | conditions are imposed on you (whether by court order, agreement or 216 | otherwise) that contradict the conditions of this License, they do not 217 | excuse you from the conditions of this License. If you cannot 218 | distribute so as to satisfy simultaneously your obligations under this 219 | License and any other pertinent obligations, then as a consequence you 220 | may not distribute the Program at all. For example, if a patent 221 | license would not permit royalty-free redistribution of the Program by 222 | all those who receive copies directly or indirectly through you, then 223 | the only way you could satisfy both it and this License would be to 224 | refrain entirely from distribution of the Program. 225 | 226 | If any portion of this section is held invalid or unenforceable under 227 | any particular circumstance, the balance of the section is intended to 228 | apply and the section as a whole is intended to apply in other 229 | circumstances. 230 | 231 | It is not the purpose of this section to induce you to infringe any 232 | patents or other property right claims or to contest validity of any 233 | such claims; this section has the sole purpose of protecting the 234 | integrity of the free software distribution system, which is 235 | implemented by public license practices. Many people have made 236 | generous contributions to the wide range of software distributed 237 | through that system in reliance on consistent application of that 238 | system; it is up to the author/donor to decide if he or she is willing 239 | to distribute software through any other system and a licensee cannot 240 | impose that choice. 241 | 242 | This section is intended to make thoroughly clear what is believed to 243 | be a consequence of the rest of this License. 244 | 245 | 8. If the distribution and/or use of the Program is restricted in 246 | certain countries either by patents or by copyrighted interfaces, the 247 | original copyright holder who places the Program under this License 248 | may add an explicit geographical distribution limitation excluding 249 | those countries, so that distribution is permitted only in or among 250 | countries not thus excluded. In such case, this License incorporates 251 | the limitation as if written in the body of this License. 252 | 253 | 9. The Free Software Foundation may publish revised and/or new versions 254 | of the General Public License from time to time. Such new versions will 255 | be similar in spirit to the present version, but may differ in detail to 256 | address new problems or concerns. 257 | 258 | Each version is given a distinguishing version number. If the Program 259 | specifies a version number of this License which applies to it and "any 260 | later version", you have the option of following the terms and conditions 261 | either of that version or of any later version published by the Free 262 | Software Foundation. If the Program does not specify a version number of 263 | this License, you may choose any version ever published by the Free Software 264 | Foundation. 265 | 266 | 10. If you wish to incorporate parts of the Program into other free 267 | programs whose distribution conditions are different, write to the author 268 | to ask for permission. For software which is copyrighted by the Free 269 | Software Foundation, write to the Free Software Foundation; we sometimes 270 | make exceptions for this. Our decision will be guided by the two goals 271 | of preserving the free status of all derivatives of our free software and 272 | of promoting the sharing and reuse of software generally. 273 | 274 | NO WARRANTY 275 | 276 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 277 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 278 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 279 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 280 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 281 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 282 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 283 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 284 | REPAIR OR CORRECTION. 285 | 286 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 287 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 288 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 289 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 290 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 291 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 292 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 293 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 294 | POSSIBILITY OF SUCH DAMAGES. 295 | 296 | END OF TERMS AND CONDITIONS 297 | -------------------------------------------------------------------------------- /deps/README.md: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | 3 | # License 4 | 5 | Note that the libsel4-sys project itself is licensed under MIT, 6 | and makes use of seL4 through the BSD 2-Clause license. 7 | 8 | The GPLv2 license is reproduced here for clarity, but does not 9 | affect the use of libsel4-sys as the seL4 related code is incorporated 10 | without modification via git, and built using input-piping wrappers 11 | around seL4's own unmodified build infrastructure. 12 | -------------------------------------------------------------------------------- /package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake rules for glueing together the packaging 2 | # of the seL4 kernel and C bindings 3 | 4 | cmake_minimum_required(VERSION 3.7.2) 5 | 6 | project(sel4_package NONE) 7 | 8 | set( 9 | BuildWithCommonSimulationSettings 10 | OFF 11 | CACHE BOOL 12 | "Include only simulation compatible configurations") 13 | 14 | set(rootservername sel4_package) 15 | 16 | add_library(sel4_package ALIAS sel4) 17 | 18 | # The current elfloader-tool CMakeList.txt doesn't set `-mgeneral-regs-only` for some reason 19 | # So we construct the base compile options for it here, `-ffreestanding` is required with it 20 | if(KernelArchARM AND KernelSel4ArchAarch64 AND KernelPlatformTx1) 21 | set_property(TARGET elfloader PROPERTY COMPILE_OPTIONS "-ffreestanding;-mgeneral-regs-only") 22 | endif() 23 | 24 | ApplyData61ElfLoaderSettings() 25 | 26 | if(BuildWithCommonSimulationSettings) 27 | ApplyCommonSimulationSettings() 28 | GenerateSimulateScript() 29 | endif(BuildWithCommonSimulationSettings) 30 | 31 | # Disable GC sections as it causes binaries to be stripped sometimes 32 | set(UserLinkerGCSections OFF CACHE BOOL "" FORCE) 33 | 34 | # This mimicks what DeclareRootserver() would do 35 | set( 36 | IMAGE_NAME 37 | "${CMAKE_BINARY_DIR}/images/feL4img") 38 | 39 | set( 40 | KERNEL_IMAGE_NAME 41 | "${CMAKE_BINARY_DIR}/images/kernel") 42 | 43 | if("${KernelArch}" STREQUAL "x86") 44 | if(Kernel64) 45 | add_custom_command( 46 | OUTPUT "${KERNEL_IMAGE_NAME}" 47 | COMMAND ${CROSS_COMPILE_PREFIX}objcopy -O elf32-i386 $ "${KERNEL_IMAGE_NAME}" 48 | VERBATIM 49 | DEPENDS kernel.elf 50 | COMMENT "objcopy kernel into bootable elf" 51 | ) 52 | else() 53 | add_custom_command( 54 | OUTPUT "${KERNEL_IMAGE_NAME}" 55 | COMMAND cp $ "${KERNEL_IMAGE_NAME}" 56 | VERBATIM 57 | DEPENDS kernel.elf 58 | ) 59 | endif() 60 | 61 | add_custom_target( 62 | rootserver_image 63 | ALL DEPENDS 64 | "${KERNEL_IMAGE_NAME}" 65 | kernel.elf) 66 | elseif("${KernelArch}" STREQUAL "arm") 67 | set(IMAGE_NAME "${CMAKE_BINARY_DIR}/images/kernel") 68 | if(NOT "${ElfloaderImage}" STREQUAL "elf") 69 | # If not an elf we construct an intermediate rule to do an objcopy to binary 70 | add_custom_command(OUTPUT "${IMAGE_NAME}" 71 | COMMAND ${CROSS_COMPILER_PREFIX}objcopy -O binary $ "${IMAGE_NAME}" 72 | DEPENDS $ elfloader 73 | ) 74 | else () 75 | add_custom_command(OUTPUT "${IMAGE_NAME}" 76 | COMMAND ${CMAKE_COMMAND} -E copy $ "${IMAGE_NAME}" 77 | DEPENDS $ elfloader 78 | ) 79 | endif() 80 | 81 | add_custom_target( 82 | rootserver_image 83 | ALL DEPENDS 84 | "${IMAGE_NAME}" 85 | elfloader 86 | ${rootservername}) 87 | 88 | # WARNING - this will likely change as we migrate to a Rust project 89 | # 90 | # This is brittle, and won't complain if the `FEL4_ROOT_TASK_IMAGE_PATH` variable is not set. 91 | # 92 | # This is intentional and a step in the right direction until we have a 93 | # fully formed Rust bootstrapping tool. 94 | # It lets us get away with muli-stage building, where we can first 95 | # build kernel binary and libsel4.a without having a root-task image. 96 | # Then on further invocations (assuming environment variable is set) you can 97 | # have the elfloader-tool pick up the root-task image and link everthing together. 98 | set_property(TARGET rootserver_image PROPERTY ROOTSERVER_IMAGE "$ENV{FEL4_ROOT_TASK_IMAGE_PATH}") 99 | endif() 100 | 101 | # Get the basename of FEL4_ARTIFACT_PATH 102 | get_filename_component( 103 | FEL4_ARTIFACT_BASENAME 104 | "$ENV{FEL4_ARTIFACT_PATH}" 105 | NAME) 106 | 107 | # Mock the rootserver_image properties used by the simulate script building mechanism 108 | set_property(TARGET rootserver_image PROPERTY IMAGE_NAME "${FEL4_ARTIFACT_BASENAME}/feL4img") 109 | set_property(TARGET rootserver_image PROPERTY KERNEL_IMAGE_NAME "${FEL4_ARTIFACT_BASENAME}/kernel") 110 | 111 | install( 112 | DIRECTORY 113 | $ 114 | $ 115 | DESTINATION .) 116 | 117 | install( 118 | FILES 119 | $ 120 | DESTINATION lib) 121 | -------------------------------------------------------------------------------- /res/bindgen_wrapper.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | nightly 2 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![allow(non_upper_case_globals)] 3 | #![allow(non_camel_case_types)] 4 | #![allow(non_snake_case)] 5 | 6 | extern crate rlibc; 7 | 8 | mod c_types { 9 | pub type c_uint = u32; 10 | pub type c_int = i32; 11 | 12 | pub type c_ulong = u64; 13 | pub type c_long = u32; 14 | 15 | pub type c_uchar = u8; 16 | pub type c_char = i8; 17 | pub type c_schar = i8; 18 | 19 | pub type c_ushort = u16; 20 | pub type c_short = i16; 21 | 22 | pub type c_ulonglong = u64; 23 | pub type c_longlong = i64; 24 | } 25 | 26 | #[cfg(feature = "KernelPrinting")] 27 | pub struct DebugOutHandle; 28 | 29 | #[cfg(feature = "KernelPrinting")] 30 | impl ::core::fmt::Write for DebugOutHandle { 31 | fn write_str(&mut self, s: &str) -> ::core::fmt::Result { 32 | for &b in s.as_bytes() { 33 | unsafe { self::seL4_DebugPutChar(b as i8) }; 34 | } 35 | Ok(()) 36 | } 37 | } 38 | 39 | #[no_mangle] 40 | pub unsafe extern "C" fn __assert_fail( 41 | mstr: *const c_types::c_char, 42 | file: *const c_types::c_char, 43 | line: c_types::c_int, 44 | function: *const c_types::c_char, 45 | ) { 46 | panic!("assertion failed"); 47 | } 48 | 49 | #[no_mangle] 50 | pub unsafe extern "C" fn stpcpy( 51 | dest: *mut c_types::c_schar, 52 | source: *const c_types::c_schar, 53 | ) -> *mut c_types::c_schar { 54 | for i in 0.. { 55 | *dest.offset(i) = *source.offset(i); 56 | if *dest.offset(i) == 0 { 57 | break; 58 | } 59 | } 60 | 61 | dest 62 | } 63 | 64 | #[no_mangle] 65 | pub unsafe extern "C" fn strcpy( 66 | dest: *mut c_types::c_schar, 67 | source: *const c_types::c_schar, 68 | ) -> *mut c_types::c_schar { 69 | stpcpy(dest, source); 70 | dest 71 | } 72 | 73 | #[cfg(all(target_arch = "arm", target_os = "sel4", target_env = "fel4"))] 74 | /// Number of bits in a `seL4_Word`. 75 | /// 76 | /// # Remarks 77 | /// 78 | /// Normally this is defined as the following macro: 79 | /// ``` 80 | /// #define seL4_WordBits (sizeof(seL4_Word) * 8) 81 | /// ``` 82 | /// 83 | /// For our `armv7-sel4-fel4` target see file: 84 | /// `libsel4/sel4_arch_include/aarch32/sel4/sel4_arch/constants.h` 85 | /// 86 | /// However due to bindgen not being able to expand functional 87 | /// macros, the type gets ignored. 88 | /// 89 | /// For the time being, we just provide the constant here. 90 | /// 91 | /// See following issues for more information: 92 | /// - `rust-bindgen/issues/753` 93 | /// - `feL4-dependencies/issues/18` 94 | pub const seL4_WordBits: u32 = 32; 95 | 96 | #[cfg(all(target_arch = "aarch64", target_os = "sel4", target_env = "fel4"))] 97 | /// Number of bits in a `seL4_Word`. 98 | /// 99 | /// # Remarks 100 | /// 101 | /// Normally this is defined as the following macro: 102 | /// ``` 103 | /// #define seL4_WordBits (sizeof(seL4_Word) * 8) 104 | /// ``` 105 | /// 106 | /// For our `aarch64-sel4-fel4` target see file: 107 | /// `libsel4/sel4_arch_include/aarch64/sel4/sel4_arch/constants.h` 108 | /// 109 | /// However due to bindgen not being able to expand functional 110 | /// macros, the type gets ignored. 111 | /// 112 | /// For the time being, we just provide the constant here. 113 | /// 114 | /// See following issues for more information: 115 | /// - `rust-bindgen/issues/753` 116 | /// - `feL4-dependencies/issues/18` 117 | pub const seL4_WordBits: u32 = 64; 118 | 119 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 120 | -------------------------------------------------------------------------------- /test_configs/README.md: -------------------------------------------------------------------------------- 1 | ## fel4.toml 2 | An example fel4 manifest that could be used to configure 3 | the build of libsel4-sys. See the [fel4-config repository](https://github.com/PolySync/fel4-config) 4 | for more information about the fel4 manifest format. 5 | 6 | ## feL4-targets JSON files 7 | Example Rust target specifications for feL4. 8 | Note that these are for reference only, and the primary source of truth 9 | for supported target specifications can be found in the 10 | [cargo-fel4 repository](https://github.com/PolySync/cargo-fel4). 11 | -------------------------------------------------------------------------------- /test_configs/aarch64-sel4-fel4.json: -------------------------------------------------------------------------------- 1 | { 2 | "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", 3 | "llvm-target": "aarch64-unknown-linux-gnu", 4 | "target-endian": "little", 5 | "target-pointer-width": "64", 6 | "target-c-int-width": "32", 7 | "os": "sel4", 8 | "env": "fel4", 9 | "arch": "aarch64", 10 | "linker-is-gnu": true, 11 | "executables": true, 12 | "linker": "aarch64-linux-gnu-gcc", 13 | "ar": "aarch64-linux-gnu-ar", 14 | "relocation-model": "static", 15 | "position-independent-executables": true, 16 | "has-elf-tls": true, 17 | "panic-strategy": "abort", 18 | "no-default-libraries": true, 19 | "features": "+a57,+fullfp16,-neon", 20 | "cpu": "cortex-a57", 21 | "linker-flavor": "gcc", 22 | "pre-link-args": { 23 | "gcc": ["-ffreestanding", "-nodefaultlibs", "-nostdlib"] 24 | }, 25 | "post-link-args": { 26 | "gcc": ["-lm", "-lgcc_s", "-lgcc"] 27 | }, 28 | "default-codegen-units": 1 29 | } 30 | -------------------------------------------------------------------------------- /test_configs/armv7-sel4-fel4.json: -------------------------------------------------------------------------------- 1 | { 2 | "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", 3 | "llvm-target": "armv7-unknown-linux-gnueabihf", 4 | "target-endian": "little", 5 | "target-pointer-width": "32", 6 | "target-c-int-width": "32", 7 | "os": "sel4", 8 | "env": "fel4", 9 | "arch": "arm", 10 | "linker-is-gnu": true, 11 | "executables": true, 12 | "linker": "arm-linux-gnueabihf-gcc", 13 | "ar": "arm-linux-gnueabihf-ar", 14 | "relocation-model": "static", 15 | "position-independent-executables": true, 16 | "has-elf-tls": true, 17 | "panic-strategy": "abort", 18 | "no-default-libraries": true, 19 | "features": "+v7,+vfp3,+d16,+thumb2,-neon", 20 | "linker-flavor": "gcc", 21 | "pre-link-args": { 22 | "gcc": ["-ffreestanding", "-nodefaultlibs", "-nostdlib"] 23 | }, 24 | "post-link-args": { 25 | "gcc": ["-lm", "-lgcc_s", "-lgcc"] 26 | }, 27 | "default-codegen-units": 1 28 | } 29 | -------------------------------------------------------------------------------- /test_configs/fel4.toml: -------------------------------------------------------------------------------- 1 | [fel4] 2 | artifact-path = "artifacts" 3 | target-specs-path = "target_specs" 4 | target = "x86_64-sel4-fel4" 5 | platform = "pc99" 6 | 7 | [x86_64-sel4-fel4] 8 | BuildWithCommonSimulationSettings = true 9 | KernelOptimisation = "-O2" 10 | KernelVerificationBuild = false 11 | KernelBenchmarks = "none" 12 | KernelFastpath = true 13 | LibSel4FunctionAttributes = "public" 14 | KernelNumDomains = 1 15 | HardwareDebugAPI = false 16 | KernelFWholeProgram = false 17 | KernelResetChunkBits = 8 18 | LibSel4DebugAllocBufferEntries = 0 19 | LibSel4DebugFunctionInstrumentation = "none" 20 | KernelNumPriorities = 256 21 | KernelStackBits = 12 22 | KernelTimeSlice = 5 23 | KernelTimerTickMS = 2 24 | # the following keys are specific to x86_64-sel4-fel4 targets 25 | KernelArch = "x86" 26 | KernelX86Sel4Arch = "x86_64" 27 | KernelMaxNumNodes = 1 28 | KernelRetypeFanOutLimit = 256 29 | KernelRootCNodeSizeBits = 19 30 | KernelMaxNumBootinfoUntypedCaps = 230 31 | KernelSupportPCID = false 32 | KernelCacheLnSz = 64 33 | KernelDebugDisablePrefetchers = false 34 | KernelExportPMCUser = false 35 | KernelFPU = "FXSAVE" 36 | KernelFPUMaxRestoresSinceSwitch = 64 37 | KernelFSGSBase = "msr" 38 | KernelHugePage = true 39 | KernelIOMMU = false 40 | KernelIRQController = "IOAPIC" 41 | KernelIRQReporting = true 42 | KernelLAPICMode = "XAPIC" 43 | KernelMaxNumIOAPIC = 1 44 | KernelMaxNumWorkUnitsPerPreemption= 100 45 | KernelMultiboot1Header = true 46 | KernelMultiboot2Header = true 47 | KernelMultibootGFXMode = "none" 48 | KernelSkimWindow = true 49 | KernelSyscall = "syscall" 50 | KernelVTX = false 51 | KernelX86DangerousMSR = false 52 | KernelX86IBPBOnContextSwitch = false 53 | KernelX86IBRSMode = "ibrs_none" 54 | KernelX86RSBOnContextSwitch = false 55 | KernelXSaveSize = 576 56 | LinkPageSize = 4096 57 | UserLinkerGCSections = false 58 | 59 | [x86_64-sel4-fel4.pc99] 60 | KernelX86MicroArch = "nehalem" 61 | LibPlatSupportX86ConsoleDevice = "com1" 62 | 63 | [x86_64-sel4-fel4.debug] 64 | KernelDebugBuild = true 65 | KernelPrinting = true 66 | KernelColourPrinting = true 67 | KernelUserStackTraceLength = 16 68 | 69 | [x86_64-sel4-fel4.release] 70 | KernelDebugBuild = false 71 | KernelPrinting = false 72 | 73 | [armv7-sel4-fel4] 74 | BuildWithCommonSimulationSettings = true 75 | KernelOptimisation = "-O2" 76 | KernelVerificationBuild = false 77 | KernelBenchmarks = "none" 78 | KernelFastpath = true 79 | LibSel4FunctionAttributes = "public" 80 | KernelNumDomains = 1 81 | HardwareDebugAPI = false 82 | KernelFWholeProgram = false 83 | KernelResetChunkBits = 8 84 | LibSel4DebugAllocBufferEntries = 0 85 | LibSel4DebugFunctionInstrumentation = "none" 86 | KernelNumPriorities = 256 87 | KernelStackBits = 12 88 | KernelTimeSlice = 5 89 | KernelTimerTickMS = 2 90 | # the following keys are specific to armv7-sel4-fel4 targets 91 | KernelArch = "arm" 92 | KernelArmSel4Arch = "aarch32" 93 | KernelMaxNumNodes = 1 94 | KernelRetypeFanOutLimit = 256 95 | KernelRootCNodeSizeBits = 19 96 | KernelMaxNumBootinfoUntypedCaps = 230 97 | KernelAArch32FPUEnableContextSwitch = true 98 | KernelDebugDisableBranchPrediction = false 99 | KernelFPUMaxRestoresSinceSwitch = 64 100 | KernelIPCBufferLocation = "threadID_register" 101 | KernelMaxNumWorkUnitsPerPreemption = 100 102 | LinkPageSize = 4096 103 | UserLinkerGCSections = false 104 | 105 | [armv7-sel4-fel4.debug] 106 | KernelDebugBuild = true 107 | KernelPrinting = true 108 | KernelColourPrinting = true 109 | KernelUserStackTraceLength = 16 110 | 111 | [armv7-sel4-fel4.release] 112 | KernelDebugBuild = false 113 | KernelPrinting = false 114 | 115 | [armv7-sel4-fel4.sabre] 116 | KernelARMPlatform = "sabre" 117 | ElfloaderImage = "elf" 118 | ElfloaderMode = "secure supervisor" 119 | ElfloaderErrata764369 = true 120 | KernelArmEnableA9Prefetcher = false 121 | KernelArmExportPMUUser = false 122 | KernelDebugDisableL2Cache = false 123 | 124 | [aarch64-sel4-fel4] 125 | BuildWithCommonSimulationSettings = true 126 | KernelOptimisation = "-O2" 127 | KernelVerificationBuild = false 128 | KernelBenchmarks = "none" 129 | KernelFastpath = true 130 | LibSel4FunctionAttributes = "public" 131 | KernelNumDomains = 1 132 | HardwareDebugAPI = false 133 | KernelFWholeProgram = false 134 | KernelResetChunkBits = 8 135 | LibSel4DebugAllocBufferEntries = 0 136 | LibSel4DebugFunctionInstrumentation = "none" 137 | KernelNumPriorities = 256 138 | KernelStackBits = 12 139 | KernelTimeSlice = 5 140 | KernelTimerTickMS = 2 141 | # the following keys are specific to aarch64-sel4-fel4 targets 142 | KernelArch = "arm" 143 | KernelArmSel4Arch = "aarch64" 144 | KernelMaxNumNodes = 1 145 | KernelRetypeFanOutLimit = 256 146 | KernelRootCNodeSizeBits = 19 147 | KernelMaxNumBootinfoUntypedCaps = 230 148 | KernelDebugDisableBranchPrediction = false 149 | KernelFPUMaxRestoresSinceSwitch = 64 150 | KernelIPCBufferLocation = "threadID_register" 151 | KernelMaxNumWorkUnitsPerPreemption = 100 152 | LinkPageSize = 4096 153 | UserLinkerGCSections = false 154 | 155 | [aarch64-sel4-fel4.debug] 156 | KernelDebugBuild = true 157 | KernelPrinting = true 158 | KernelColourPrinting = true 159 | KernelUserStackTraceLength = 16 160 | 161 | [aarch64-sel4-fel4.release] 162 | KernelDebugBuild = false 163 | KernelPrinting = false 164 | 165 | [aarch64-sel4-fel4.tx1] 166 | KernelARMPlatform = "tx1" 167 | ElfloaderImage = "binary" 168 | -------------------------------------------------------------------------------- /test_configs/x86_64-sel4-fel4.json: -------------------------------------------------------------------------------- 1 | { 2 | "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", 3 | "llvm-target": "x86_64-elf", 4 | "target-endian": "little", 5 | "target-pointer-width": "64", 6 | "target-c-int-width": "32", 7 | "os": "sel4", 8 | "env": "fel4", 9 | "arch": "x86_64", 10 | "linker-is-gnu": true, 11 | "executables": true, 12 | "no-compiler-rt": false, 13 | "relocation-model": "pic", 14 | "position-independent-executables": false, 15 | "dynamic_linking": false, 16 | "has-elf-tls": true, 17 | "panic-strategy": "abort", 18 | "cpu": "westmere", 19 | "no-default-libraries": true, 20 | "linker-flavor": "gcc", 21 | "pre-link-args": { 22 | "gcc": ["-m64", "-ffreestanding", "-nodefaultlibs", "-nostdlib"] 23 | }, 24 | "default-codegen-units": 1 25 | } 26 | --------------------------------------------------------------------------------