1
0
Fork 0
zynq-rs/src/main.rs

132 lines
2.8 KiB
Rust
Raw Normal View History

2019-05-05 20:56:23 +08:00
#![no_std]
#![no_main]
#![feature(asm)]
2019-05-31 02:30:19 +08:00
#![feature(global_asm)]
2019-05-05 20:56:23 +08:00
#![feature(naked_functions)]
#![feature(compiler_builtins_lib)]
2019-06-17 09:32:10 +08:00
#![feature(never_type)]
2019-05-05 20:56:23 +08:00
use core::mem::uninitialized;
2019-05-07 22:45:31 +08:00
2019-05-05 20:56:23 +08:00
use r0::zero_bss;
use compiler_builtins as _;
2019-05-05 20:56:23 +08:00
2019-05-07 05:56:53 +08:00
mod regs;
2019-05-05 20:56:23 +08:00
mod cortex_a9;
mod slcr;
mod uart;
2019-06-20 06:30:18 +08:00
mod stdio;
2019-05-08 01:28:33 +08:00
mod eth;
2019-05-05 20:56:23 +08:00
use crate::regs::{RegisterR, RegisterW};
2019-06-17 09:32:10 +08:00
use crate::cortex_a9::{asm, regs::*, mmu};
2019-05-24 01:05:06 +08:00
2019-05-05 20:56:23 +08:00
extern "C" {
static mut __bss_start: u32;
static mut __bss_end: u32;
2019-05-27 07:44:24 +08:00
static mut __stack_start: u32;
2019-05-05 20:56:23 +08:00
}
#[link_section = ".text.boot"]
#[no_mangle]
#[naked]
pub unsafe extern "C" fn _boot_cores() -> ! {
const CORE_MASK: u32 = 0x3;
match MPIDR.read() & CORE_MASK {
2019-05-05 20:56:23 +08:00
0 => {
SP.write(&mut __stack_start as *mut _ as u32);
2019-05-20 07:21:22 +08:00
boot_core0();
2019-05-05 20:56:23 +08:00
}
_ => loop {
// if not core0, infinitely wait for events
asm::wfe();
},
}
}
2019-05-30 08:41:44 +08:00
#[naked]
#[inline(never)]
2019-05-20 07:21:22 +08:00
unsafe fn boot_core0() -> ! {
2019-05-24 01:05:06 +08:00
l1_cache_init();
2019-05-20 07:21:22 +08:00
zero_bss(&mut __bss_start, &mut __bss_end);
2019-05-30 08:41:44 +08:00
2019-06-18 08:22:07 +08:00
let mmu_table = mmu::L1Table::get()
.setup_flat_layout();
mmu::with_mmu(mmu_table, || {
2019-06-17 09:32:10 +08:00
main();
panic!("return from main");
});
2019-05-20 07:21:22 +08:00
}
2019-05-24 01:05:06 +08:00
fn l1_cache_init() {
// Invalidate TLBs
tlbiall();
// Invalidate I-Cache
iciallu();
// Invalidate Branch Predictor Array
bpiall();
// Invalidate D-Cache
dccisw();
}
2019-05-05 20:56:23 +08:00
fn main() {
2019-06-20 06:30:18 +08:00
println!("Main.");
2019-06-05 05:49:06 +08:00
2019-06-09 07:02:10 +08:00
let mut eth = eth::Eth::default([0x0, 0x17, 0xde, 0xea, 0xbe, 0xef]);
2019-06-20 06:30:18 +08:00
println!("Eth on");
2019-06-19 06:21:17 +08:00
match eth::phy::Phy::find(&mut eth) {
Some((addr, phy)) => {
2019-06-20 06:30:18 +08:00
println!("Found {} PHY at addr {}", phy.name(), addr);
2019-06-19 06:21:17 +08:00
}
None => {
use eth::phy::PhyAccess;
for addr in 1..32 {
match eth::phy::id::identify_phy(&mut eth, addr) {
Some(identifier) => {
2019-06-20 06:30:18 +08:00
println!("phy {}: {:?}", addr, identifier);
2019-06-19 06:21:17 +08:00
}
None => {}
}
}
}
2019-05-21 07:30:54 +08:00
}
2019-05-08 01:28:33 +08:00
let mut rx_buffers = [[0u8; 1536]; eth::rx::DESCS];
let mut rx_buffer_ptrs: [&mut [u8]; eth::rx::DESCS] = unsafe {
uninitialized()
};
for (i, (ptr, buf)) in rx_buffer_ptrs.iter_mut().zip(rx_buffers.iter_mut()).enumerate() {
*ptr = buf;
}
let mut eth = eth.start_rx(rx_buffer_ptrs);
2019-06-10 08:44:29 +08:00
loop {
match eth.recv_next() {
None => {}
Some(pkt) => {
2019-06-20 06:30:18 +08:00
println!("eth: received {} bytes", pkt.len());
2019-06-10 08:44:29 +08:00
}
}
}
2019-06-05 05:49:06 +08:00
panic!("End");
2019-05-05 20:56:23 +08:00
}
2019-05-28 06:28:35 +08:00
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
2019-06-20 06:30:18 +08:00
println!("\nPanic: {}", info);
2019-05-28 06:28:35 +08:00
slcr::RegisterBlock::unlocked(|slcr| slcr.soft_reset());
2019-05-31 06:19:20 +08:00
loop {}
2019-05-28 06:28:35 +08:00
}
2019-05-31 02:30:19 +08:00
#[no_mangle]
pub unsafe extern "C" fn PrefetchAbort() {
panic!("PrefetchAbort");
}
#[no_mangle]
pub unsafe extern "C" fn DataAbort() {
panic!("DataAbort");
}