Skip to content

Commit

Permalink
9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Sep 3, 2023
1 parent 94eeaa3 commit 9795ff6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions modules/axruntime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ net = ["axdriver", "axnet"]
display = ["axdriver", "axdisplay"]

[dependencies]
volatile = "0.2.4"
axhal = { path = "../axhal" }
axlog = { path = "../axlog" }
axconfig = { path = "../axconfig" }
Expand Down
14 changes: 14 additions & 0 deletions modules/axruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

#![cfg_attr(not(test), no_std)]
#![feature(doc_auto_cfg)]
#![feature(core_intrinsics)]

#[macro_use]
extern crate axlog;

#[cfg(all(target_os = "none", not(test)))]
mod lang_items;
mod trap;
mod rtc;

#[cfg(feature = "smp")]
mod mp;
Expand Down Expand Up @@ -189,6 +191,18 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! {
core::hint::spin_loop();
}

unsafe{
info!("before");
/*
let mut myrtc = rtc::Pl031rtc::new();
let x = myrtc.time();
*/
rtc::init();
let x = rtc::PL031_RTC.time();
info!("{}",x);
info!("after");
}

unsafe { main() };

#[cfg(feature = "multitask")]
Expand Down
44 changes: 44 additions & 0 deletions modules/axruntime/src/rtc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use core::intrinsics::{volatile_load, volatile_store};

static RTC_DR: u32 = 0x000;
static RTC_MR: u32 = 0x004;
static RTC_LR: u32 = 0x008;
static RTC_CR: u32 = 0x00c;
static RTC_IMSC: u32 = 0x010;
static RTC_RIS: u32 = 0x014;
static RTC_MIS: u32 = 0x018;
static RTC_ICR: u32 = 0x01c;

pub static mut PL031_RTC: Pl031rtc = Pl031rtc {
address: 0,
};

pub unsafe fn init() {
PL031_RTC.init();
}

pub struct Pl031rtc {
pub address: usize,
}

pub const PHYS_OFFSET: usize = 0xffff_0000_0000_0000;

impl Pl031rtc {
unsafe fn init(&mut self) {
self.address = PHYS_OFFSET + 0x09010000;
}

unsafe fn read(&self, reg: u32) -> u32 {
let val = volatile_load((self.address + reg as usize) as *const u32);
val
}

unsafe fn write(&mut self, reg: u32, value: u32) {
volatile_store((self.address + reg as usize) as *mut u32, value);
}

pub fn time(&mut self) -> u64 {
let seconds = unsafe { self.read(RTC_DR) } as u64;
seconds
}
}
1 change: 1 addition & 0 deletions platforms/aarch64-qemu-virt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mmio-regions = [
["0x0a00_0000", "0x4000"], # VirtIO
["0x1000_0000", "0x2eff_0000"], # PCI memory ranges (ranges 1: 32-bit MMIO space)
["0x40_1000_0000", "0x1000_0000"], # PCI config space
["0x0901_0000", "0x100"],
]
# VirtIO MMIO regions with format (`base_paddr`, `size`).
virtio-mmio-regions = [
Expand Down

0 comments on commit 9795ff6

Please sign in to comment.