-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e70afe4
commit 297aa6e
Showing
6 changed files
with
132 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use std::env; | ||
|
||
fn main() { | ||
let target = env::var("TARGET").unwrap(); | ||
|
||
if target.starts_with("riscv") { | ||
println!("cargo:rustc-cfg=riscv"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,103 @@ | ||
//! IMPLEMENTATION DETAILS USED BY MACROS | ||
use crate::hio::{self, HostStream}; | ||
use core::fmt::{self, Write}; | ||
|
||
#[cfg(feature = "machine-mode")] | ||
use riscv::interrupt; | ||
static mut HSTDOUT: Option<HostStream> = None; | ||
|
||
use crate::hio::{self, HostStream}; | ||
static mut HSTDERR: Option<HostStream> = None; | ||
|
||
static mut HSTDOUT: Option<HostStream> = None; | ||
#[cfg(not(feature = "u-mode"))] | ||
mod machine { | ||
use super::*; | ||
|
||
pub fn hstdout_str(s: &str) { | ||
let _result = critical_section::with(|_| unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout()?); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop) | ||
}); | ||
} | ||
|
||
pub fn hstdout_fmt(args: fmt::Arguments) { | ||
let _result = critical_section::with(|_| unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout()?); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}); | ||
} | ||
|
||
pub fn hstderr_str(s: &str) { | ||
let _result = critical_section::with(|_| unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr()?); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_str(s).map_err(drop) | ||
}); | ||
} | ||
|
||
pub fn hstderr_fmt(args: fmt::Arguments) { | ||
let _result = critical_section::with(|_| unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr()?); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}); | ||
} | ||
} | ||
#[cfg(not(feature = "u-mode"))] | ||
pub use machine::*; | ||
|
||
#[cfg(feature = "u-mode")] | ||
mod user { | ||
use super::*; | ||
pub fn hstdout_str(s: &str) { | ||
let _result = unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout().unwrap()); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop) | ||
}; | ||
} | ||
|
||
#[cfg(not(feature = "no-semihosting"))] | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature="machine-mode")] { | ||
pub fn hstdout_str(s: &str) { | ||
let _result = interrupt::free(|_| unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout()?); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop) | ||
}); | ||
} | ||
|
||
pub fn hstdout_fmt(args: fmt::Arguments) { | ||
let _result = interrupt::free(|_| unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout()?); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}); | ||
} | ||
|
||
static mut HSTDERR: Option<HostStream> = None; | ||
|
||
pub fn hstderr_str(s: &str) { | ||
let _result = interrupt::free(|_| unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr()?); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_str(s).map_err(drop) | ||
}); | ||
} | ||
|
||
pub fn hstderr_fmt(args: fmt::Arguments) { | ||
let _result = interrupt::free(|_| unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr()?); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}); | ||
} | ||
pub fn hstdout_fmt(args: fmt::Arguments) { | ||
let _result = unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout().unwrap()); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}; | ||
} | ||
else if #[cfg(feature = "user-mode")] { | ||
pub fn hstdout_str(s: &str) { | ||
let _result = unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout().unwrap()); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop) | ||
}; | ||
} | ||
|
||
pub fn hstdout_fmt(args: fmt::Arguments) { | ||
let _result = unsafe { | ||
if HSTDOUT.is_none() { | ||
HSTDOUT = Some(hio::hstdout().unwrap()); | ||
} | ||
|
||
HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}; | ||
} | ||
|
||
static mut HSTDERR: Option<HostStream> = None; | ||
|
||
pub fn hstderr_str(s: &str) { | ||
let _result = unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr().unwrap()); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_str(s).map_err(drop) | ||
}; | ||
} | ||
|
||
pub fn hstderr_fmt(args: fmt::Arguments) { | ||
let _result = unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr().unwrap()); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}; | ||
} | ||
|
||
static mut HSTDERR: Option<HostStream> = None; | ||
|
||
pub fn hstderr_str(s: &str) { | ||
let _result = unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr().unwrap()); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_str(s).map_err(drop) | ||
}; | ||
} | ||
else { | ||
compile_error!("A privilege level has not been selected. Enable either \ | ||
the machine-mode or user-mode features as appropriate \ | ||
for your use case."); | ||
|
||
pub fn hstderr_fmt(args: fmt::Arguments) { | ||
let _result = unsafe { | ||
if HSTDERR.is_none() { | ||
HSTDERR = Some(hio::hstderr().unwrap()); | ||
} | ||
|
||
HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop) | ||
}; | ||
} | ||
} | ||
#[cfg(feature = "u-mode")] | ||
pub use user::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters