Skip to content

Instantly share code, notes, and snippets.

@almindor

almindor/main.rs Secret

Created September 18, 2021 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almindor/203add5e980570c650ae33a42a72c374 to your computer and use it in GitHub Desktop.
Save almindor/203add5e980570c650ae33a42a72c374 to your computer and use it in GitHub Desktop.
all sections yay
#![no_std]
#![no_main]
use core::panic::PanicInfo;
use module_rt::entry;
const MAX: usize = 8;
static mut X: [u32; MAX] = [
1, 2, 3, 4,
5, 6, 7, 8,
];
const EMPTY_ADDR: usize = 0x2001_0000;
const OTHER_ADDR: usize = 0x8000_1000;
const HW: &'static str = "Hello World";
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
// TODO: hit a trap to machine mode
loop {}
}
unsafe fn funky(i: usize) -> usize {
i + (X[i] as usize)
}
#[entry]
fn main() -> ! {
unsafe {
for i in 0..MAX {
let ptr = &mut X[i] as *mut u32;
let src_addr = EMPTY_ADDR + funky(i);
let val = core::ptr::read_volatile(src_addr as *const u32);
core::ptr::write_volatile(ptr, val);
}
let src_addr = OTHER_ADDR;
let val = core::ptr::read_volatile(src_addr as *const u32);
let mut total = 0;
for i in 0..MAX {
total += X[i] + val;
}
if HW.as_bytes()[total as usize] > 0 {
panic!("{}", "WOOT");
}
if total > 100 {
panic!("{}", "100");
}
}
loop {
continue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment