Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample of how to generate the function #1531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/lpc55xpresso/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abi = { path = "../../sys/abi"}
kern = { path = "../../sys/kern" }
lpc55-rot-startup = {path = "../../lib/lpc55-rot-startup"}
unwrap-lite = {path = "../../lib/unwrap-lite"}
lpc55_romapi = { path = "../../lib/lpc55-romapi" }
lpc55-hashcrypt = { path = "../../lib/lpc55-hashcrypt" }

# this lets you use `cargo fix`!
[[bin]]
Expand Down
6 changes: 6 additions & 0 deletions app/lpc55xpresso/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ fn main() -> ! {

let (cycles_per_ms, _div) = get_clock_speed(&peripherals);

set_hashcrypt_rom();

startup(&core_peripherals, &peripherals);

set_hashcrypt_default();

unsafe { kern::startup::start_kernel(cycles_per_ms * 1_000) }
}

lpc55_hashcrypt::dynamic_hashcrypt!();
17 changes: 17 additions & 0 deletions lib/lpc55-hashcrypt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "lpc55-hashcrypt"
version = "0.1.0"
edition = "2021"

[dependencies]
cfg-if = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
zerocopy = { workspace = true }
syn = { workspace = true }

[build-dependencies]
build-util = { path = "../../build/util" }

[lib]
proc-macro = true
42 changes: 42 additions & 0 deletions lib/lpc55-hashcrypt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

/// proc macro to generate iocon function for LPC55
extern crate proc_macro;
use proc_macro::TokenStream;
extern crate proc_macro2;
use quote::quote;

#[proc_macro]
pub fn dynamic_hashcrypt(_item: TokenStream) -> TokenStream {
let code = quote! {
static mut USE_ROM: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: improve readability w/ use core::sync::atomic::AtomicBool;


pub fn set_hashcrypt_default() {
unsafe {
USE_ROM.store(false, core::sync::atomic::Ordering::Relaxed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: improve readability w/ use core::sync::atomic::Ordering

}
}

pub fn set_hashcrypt_rom() {
unsafe {
USE_ROM.store(true, core::sync::atomic::Ordering::Relaxed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}
}

#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn HASHCRYPT() {
if USE_ROM.load(core::sync::atomic::Ordering::Relaxed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

lpc55_romapi::skboot_hashcrypt_handler();
} else {
kern::arch::DefaultHandler();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace

};

code.into()
}
1 change: 1 addition & 0 deletions lib/lpc55-rot-startup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lpc55_romapi = { path = "../lpc55-romapi" }
stage0-handoff = { path = "../stage0-handoff"}
unwrap-lite = { path = "../unwrap-lite" }
drv-lpc55-flash.path = "../../drv/lpc55-flash"
lpc55-hashcrypt = { path = "../lpc55-hashcrypt" }

[build-dependencies]
build-util = { path = "../../build/util" }
Expand Down