From 1d52d415402c5325bf469e21c50a622ae7c291bd Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Fri, 1 Nov 2024 13:49:43 -0700 Subject: [PATCH] cookie-cutter: add bin for asm analysis --- Cargo.lock | 143 +++++++++++++++++++++++++++++++++- cookie-cutter/Cargo.toml | 15 ++++ cookie-cutter/src/bin/test.rs | 40 ++++++++++ 3 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 cookie-cutter/src/bin/test.rs diff --git a/Cargo.lock b/Cargo.lock index 34ed76f..34ce891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + [[package]] name = "byteorder" version = "1.5.0" @@ -37,8 +52,43 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "cookie-cutter" version = "0.1.0" dependencies = [ + "cortex-m", + "cortex-m-rt", "fill-array", "macros", + "panic-halt", +] + +[[package]] +name = "cortex-m" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" +dependencies = [ + "bare-metal", + "bitfield", + "embedded-hal 0.2.7", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1" +dependencies = [ + "cortex-m-rt-macros", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -101,6 +151,16 @@ dependencies = [ "heapless", ] +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + [[package]] name = "embedded-hal" version = "1.0.0" @@ -113,7 +173,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884" dependencies = [ - "embedded-hal", + "embedded-hal 1.0.0", ] [[package]] @@ -139,7 +199,7 @@ checksum = "185bcf633493c77322af55faf35f91b8fd72644a54f4c9951d9a66baf1b8eebc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.52", ] [[package]] @@ -198,7 +258,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn", + "syn 2.0.52", ] [[package]] @@ -207,6 +267,21 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + [[package]] name = "packit" version = "0.1.0" @@ -215,6 +290,12 @@ dependencies = [ "crc", ] +[[package]] +name = "panic-halt" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a513e167849a384b7f9b746e517604398518590a9142f4846a32e3c2a4de7b11" + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -274,12 +355,47 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.52" @@ -296,3 +412,24 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc" +dependencies = [ + "vcell", +] diff --git a/cookie-cutter/Cargo.toml b/cookie-cutter/Cargo.toml index 40e7d56..9ec0212 100644 --- a/cookie-cutter/Cargo.toml +++ b/cookie-cutter/Cargo.toml @@ -6,3 +6,18 @@ edition = "2021" [dependencies] macros = { path = "../macros", version = "0.1.0" } fill-array = "0.2.1" + +# for binary +panic-halt = { version = "1.0.0", optional = true } +cortex-m = { version = "0.7.7", optional = true } +cortex-m-rt = { version = "0.7.3", optional = true } + +[features] +binary = ["dep:panic-halt", "dep:cortex-m", "cortex-m-rt"] +cortex-m-rt = ["dep:cortex-m-rt"] + +[[bin]] +name = "test" +bench = false +test = false +required-features = ["binary"] diff --git a/cookie-cutter/src/bin/test.rs b/cookie-cutter/src/bin/test.rs new file mode 100644 index 0000000..a4f3cab --- /dev/null +++ b/cookie-cutter/src/bin/test.rs @@ -0,0 +1,40 @@ +#![no_std] +#![no_main] + +use core::ptr::{null, null_mut, read_volatile, write_volatile}; + +use panic_halt as _; + +use cookie_cutter::{encoding::vanilla, SerializeIter}; +use cortex_m_rt::entry; + +#[derive(vanilla::SerializeIter)] +struct Foo { + a: u32, + b: u16, +} + +#[inline(never)] +fn deserialize(buf: &[u8; N]) -> Foo { + unsafe { Foo::deserialize_iter(buf).unwrap_unchecked() } +} + +#[inline(never)] +fn serialize(foo: Foo, buf: &mut [u8; N]) { + unsafe { foo.serialize_iter(buf).unwrap_unchecked() } +} + +#[entry] +fn main() -> ! { + let buf = unsafe { read_volatile(null() as *const [u8; 20]) }; + + let foo = deserialize(&buf); + + let mut buf = [0; 20]; + + serialize(foo, &mut buf); + + unsafe { write_volatile(null_mut(), buf) }; + + loop {} +}