diff --git a/.reuse/dep5 b/.reuse/dep5 index 72d1e7561..cdfadb515 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -5,6 +5,8 @@ Source: http://sel4.systems Files: tool/microkit/Cargo.lock + example/rust/Cargo.lock + example/rust/support/*.json flake.lock CHANGES.md VERSION diff --git a/docs/manual.md b/docs/manual.md index 16793058e..b28186ad6 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -396,6 +396,16 @@ The report can be useful when debugging potential system problems. This report does not have a fixed format and may change between versions. It is not intended to be machine readable. +# Language Support + +There are native APIs for C/C++ and Rust. + +[libmicrokit](#libmicrokit) exports a C API and so can be used in any language +that supports C FFI. + +For Rust, native bindings exist but are not included in the SDK itself. They are +available at [rust-sel4](https://github.com/seL4/rust-sel4). + # libmicrokit {#libmicrokit} All program images should link against `libmicrokit.a`. diff --git a/example/rust/.cargo/config.toml b/example/rust/.cargo/config.toml new file mode 100644 index 000000000..08d1f8c13 --- /dev/null +++ b/example/rust/.cargo/config.toml @@ -0,0 +1,11 @@ +# +# Copyright 2023, Colias Group, LLC +# +# SPDX-License-Identifier: BSD-2-Clause +# + +[unstable] +unstable-options = true + +[env] +RUST_TARGET_PATH = { value = "support/targets", relative = true } diff --git a/example/rust/Cargo.lock b/example/rust/Cargo.lock new file mode 100644 index 000000000..f26c63c85 --- /dev/null +++ b/example/rust/Cargo.lock @@ -0,0 +1,802 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bindgen" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dlmalloc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5e0d321d61de16390ed273b647ce51605b575916d3c25e6ddf27a1e140035" +dependencies = [ + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "glob" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" + +[[package]] +name = "hello" +version = "0.1.0" +dependencies = [ + "sel4-microkit", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "libloading" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "pest" +version = "2.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "prettyplease" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "ryu" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sel4" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "cfg-if", + "sel4-config", + "sel4-sys", +] + +[[package]] +name = "sel4-bitfield-ops" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "rustversion", +] + +[[package]] +name = "sel4-bitfield-parser" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "pest", + "pest_derive", + "regex", +] + +[[package]] +name = "sel4-build-env" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-config" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "prettyplease", + "sel4-config-data", + "sel4-config-generic", + "sel4-config-macros", + "syn", +] + +[[package]] +name = "sel4-config-data" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "lazy_static", + "sel4-build-env", + "sel4-config-generic-types", + "serde_json", +] + +[[package]] +name = "sel4-config-generic" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "fallible-iterator", + "proc-macro2", + "quote", + "sel4-config-generic-types", + "syn", +] + +[[package]] +name = "sel4-config-generic-types" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "serde", +] + +[[package]] +name = "sel4-config-macros" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "sel4-config-data", + "sel4-config-generic", +] + +[[package]] +name = "sel4-ctors-dtors" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-dlmalloc" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "dlmalloc", + "lock_api", +] + +[[package]] +name = "sel4-elf-header" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-immediate-sync-once-cell" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-immutable-cell" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-initialize-tls" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "sel4-microkit" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "cfg-if", + "sel4", + "sel4-ctors-dtors", + "sel4-dlmalloc", + "sel4-immediate-sync-once-cell", + "sel4-microkit-base", + "sel4-microkit-macros", + "sel4-panicking", + "sel4-panicking-env", + "sel4-runtime-common", + "sel4-sync", +] + +[[package]] +name = "sel4-microkit-base" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "sel4", + "sel4-immutable-cell", +] + +[[package]] +name = "sel4-microkit-macros" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sel4-panicking" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "cfg-if", + "rustversion", + "sel4-immediate-sync-once-cell", + "sel4-panicking-env", + "unwinding", +] + +[[package]] +name = "sel4-panicking-env" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-runtime-common" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "cfg-if", + "sel4", + "sel4-elf-header", + "sel4-initialize-tls", + "sel4-panicking-env", + "sel4-stack", + "unwinding", +] + +[[package]] +name = "sel4-stack" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" + +[[package]] +name = "sel4-sync" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "lock_api", + "sel4", + "sel4-immediate-sync-once-cell", + "sel4-sync-trivial", +] + +[[package]] +name = "sel4-sync-trivial" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "lock_api", +] + +[[package]] +name = "sel4-sys" +version = "0.1.0" +source = "git+https://github.com/seL4/rust-sel4#5b9ebfd0a3a9805f28cc9222cd558e8d56a3919d" +dependencies = [ + "bindgen", + "glob", + "log", + "prettyplease", + "proc-macro2", + "quote", + "sel4-bitfield-ops", + "sel4-bitfield-parser", + "sel4-build-env", + "sel4-config", + "sel4-config-data", + "syn", + "xmltree", +] + +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "unicode-ident" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" + +[[package]] +name = "unwinding" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f06a05848f650946acef3bf525fe96612226b61f74ae23ffa4e98bfbb8ab3c" +dependencies = [ + "gimli", +] + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "xml-rs" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" + +[[package]] +name = "xmltree" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b619f8c85654798007fb10afa5125590b43b088c225a25fc2fec100a9fad0fc6" +dependencies = [ + "xml-rs", +] diff --git a/example/rust/Cargo.toml b/example/rust/Cargo.toml new file mode 100644 index 000000000..ffb760ac5 --- /dev/null +++ b/example/rust/Cargo.toml @@ -0,0 +1,18 @@ +# +# Copyright 2025, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# +# +[package] +name = "hello" +version = "0.1.0" +edition = "2021" +license = "BSD-2-Clause" + +[[bin]] +name = "hello" +path = "hello.rs" + +[dependencies] +sel4-microkit = { git = "https://github.com/seL4/rust-sel4" } diff --git a/example/rust/Makefile b/example/rust/Makefile new file mode 100644 index 000000000..8bbf47290 --- /dev/null +++ b/example/rust/Makefile @@ -0,0 +1,82 @@ +# +# Copyright 2023, Colias Group, LLC +# Copyright 2025, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# + +ifeq ($(strip $(BUILD_DIR)),) +$(error BUILD_DIR must be specified) +endif + +ifeq ($(strip $(MICROKIT_SDK)),) +$(error MICROKIT_SDK must be specified) +endif + +ifeq ($(strip $(MICROKIT_BOARD)),) +$(error MICROKIT_BOARD must be specified) +endif + +ifeq ($(strip $(MICROKIT_CONFIG)),) +$(error MICROKIT_CONFIG must be specified) +endif + +IMAGE_FILE = $(BUILD_DIR)/loader.img +REPORT_FILE = $(BUILD_DIR)/report.txt +SYSTEM_FILE := rust.system + +all: $(IMAGE_FILE) + +.PHONY: clean +clean: + rm -rf $(BUILD_DIR) + +$(BUILD_DIR): + mkdir -p $@ + +BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) +SEL4_INCLUDE_DIRS := $(BOARD_DIR)/include +ARCH := ${shell grep 'CONFIG_SEL4_ARCH ' $(BOARD_DIR)/include/kernel/gen_config.h | cut -d' ' -f4} + +ifeq ($(ARCH),aarch64) + RUST_TARGET := aarch64-sel4-microkit-minimal +else ifeq ($(ARCH),riscv64) + RUST_TARGET := riscv64gc-sel4-microkit-minimal +else +$(error Unsupported ARCH) +endif + +crate = $(BUILD_DIR)/$(1).elf + +define build_crate + +$(crate): $(crate).intermediate + +.INTERMDIATE: $(crate).intermediate +$(crate).intermediate: + SEL4_INCLUDE_DIRS=$(abspath $(SEL4_INCLUDE_DIRS)) \ + cargo build \ + -Z build-std=core,alloc,compiler_builtins \ + -Z build-std-features=compiler-builtins-mem \ + --target-dir $(BUILD_DIR)/target \ + --out-dir $(BUILD_DIR) \ + --target $(RUST_TARGET) \ + --release \ + -p $(1) + +endef + +CRATE_NAMES := hello + +CRATES := $(foreach CRATE_NAME,$(CRATE_NAMES),$(call crate,$(CRATE_NAME))) + +$(eval $(foreach CRATE_NAME,$(CRATE_NAMES),$(call build_crate,$(CRATE_NAME)))) + +$(IMAGE_FILE): $(SYSTEM_FILE) $(CRATES) + $(MICROKIT_SDK)/bin/microkit \ + $< \ + --search-path $(BUILD_DIR) \ + --board $(MICROKIT_BOARD) \ + --config $(MICROKIT_CONFIG) \ + -r $(BUILD_DIR)/report.txt \ + -o $@ diff --git a/example/rust/README.md b/example/rust/README.md new file mode 100644 index 000000000..48fcef4a1 --- /dev/null +++ b/example/rust/README.md @@ -0,0 +1,29 @@ + +# Example - Rust + +This example is the same as the 'hello' example expect that the +protection domain is written in Rust instead of C. This makes +use of the [rust-sel4](https://github.com/seL4/rust-sel4) Microkit +support. + +You can find more complicated example systems written in Rust +at the following links: + +* https://github.com/seL4/rust-microkit-demo +* https://github.com/seL4/rust-microkit-http-server-demo + +All supported platforms are supported in this example. + +## Building + +```sh +mkdir build +make BUILD_DIR=build MICROKIT_BOARD= MICROKIT_CONFIG= MICROKIT_SDK=/path/to/sdk +``` + +## Running + +See instructions for your board in the manual. diff --git a/example/rust/hello.rs b/example/rust/hello.rs new file mode 100644 index 000000000..830d70da3 --- /dev/null +++ b/example/rust/hello.rs @@ -0,0 +1,17 @@ +// +// Copyright 2025, UNSW +// +// SPDX-License-Identifier: BSD-2-Clause +// + +#![no_std] +#![no_main] + +use sel4_microkit::{NullHandler, protection_domain, debug_println}; + +#[protection_domain()] +fn init() -> NullHandler { + debug_println!("hello, world from Rust!"); + + NullHandler::new() +} diff --git a/example/rust/rust-toolchain.toml b/example/rust/rust-toolchain.toml new file mode 100644 index 000000000..84a9735bf --- /dev/null +++ b/example/rust/rust-toolchain.toml @@ -0,0 +1,9 @@ +# +# Copyright 2023, Colias Group, LLC +# +# SPDX-License-Identifier: BSD-2-Clause +# + +[toolchain] +channel = "nightly-2024-05-01" +components = [ "rustfmt", "rust-src", "rustc-dev", "llvm-tools-preview" ] diff --git a/example/rust/rust.system b/example/rust/rust.system new file mode 100644 index 000000000..146da4bab --- /dev/null +++ b/example/rust/rust.system @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/example/rust/support/targets/aarch64-sel4-microkit-minimal.json b/example/rust/support/targets/aarch64-sel4-microkit-minimal.json new file mode 100644 index 000000000..16ce9ef87 --- /dev/null +++ b/example/rust/support/targets/aarch64-sel4-microkit-minimal.json @@ -0,0 +1,37 @@ +{ + "arch": "aarch64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", + "disable-redzone": true, + "eh-frame-header": false, + "env": "sel4", + "exe-suffix": ".elf", + "features": "+v8a,+strict-align,+neon,+fp-armv8", + "link-script": "__sel4_ipc_buffer_obj = (_end + 4096 - 1) & ~(4096 - 1);", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-target": "aarch64-unknown-none", + "max-atomic-width": 128, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "pre-link-args": { + "gnu-lld": [ + "-z", + "max-page-size=4096" + ] + }, + "relocation-model": "static", + "stack-probes": { + "kind": "inline" + }, + "supported-sanitizers": [ + "kcfi", + "kernel-address" + ], + "target-pointer-width": "64" +} diff --git a/example/rust/support/targets/riscv64gc-sel4-microkit-minimal.json b/example/rust/support/targets/riscv64gc-sel4-microkit-minimal.json new file mode 100644 index 000000000..0e0e9ddeb --- /dev/null +++ b/example/rust/support/targets/riscv64gc-sel4-microkit-minimal.json @@ -0,0 +1,29 @@ +{ + "arch": "riscv64", + "code-model": "medium", + "cpu": "generic-rv64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", + "emit-debug-gdb-scripts": false, + "exe-suffix": ".elf", + "features": "+m,+a,+f,+d,+c", + "link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-abiname": "lp64d", + "llvm-target": "riscv64", + "max-atomic-width": 64, + "metadata": { + "description": null, + "host_tools": null, + "std": null, + "tier": null + }, + "panic-strategy": "abort", + "relocation-model": "static", + "supported-sanitizers": [ + "shadow-call-stack", + "kernel-address" + ], + "target-pointer-width": "64" +}