1
0
Fork 0
forked from AbleOS/ableos

Merge pull request 'ARM: Add serial console logging' (#9) from microtau/ableos:master into master

Reviewed-on: https://git.ablecorp.us/AbleOS/ableos/pulls/9
This commit is contained in:
able 2023-07-20 11:03:57 +00:00
commit 239ee43064
6 changed files with 43 additions and 1169 deletions

1154
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,23 @@
use {core::fmt::Write, spin::Mutex};
const SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole {
uart: 0x09000000 as *mut u8,
});
struct SerialConsole {
uart: *mut u8,
}
impl core::fmt::Write for SerialConsole {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
for c in s.chars() {
unsafe { *self.uart = c as u8 }
}
Ok(())
}
}
pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result {
SERIAL_CONSOLE.lock().write_fmt(args)
}

View file

@ -1,9 +1,15 @@
use {core::arch::asm, limine::FramebufferRequest}; use {core::arch::asm, limine::FramebufferRequest};
pub mod logging;
pub use logging::log;
pub const PAGE_SIZE: usize = 4096; pub const PAGE_SIZE: usize = 4096;
#[no_mangle] #[no_mangle]
unsafe extern "C" fn _kernel_start() -> ! { unsafe extern "C" fn _kernel_start() -> ! {
crate::logger::init().expect("failed to set logger");
log::info!("Initialising AKern {}", crate::VERSION);
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0); static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
@ -26,7 +32,3 @@ pub fn spin_loop() -> ! {
pub fn hardware_random_u64() -> u64 { pub fn hardware_random_u64() -> u64 {
0 0
} }
pub fn log(_args: core::fmt::Arguments<'_>) -> core::fmt::Result {
panic!()
}

View file

@ -19,9 +19,7 @@ pub fn init() {
pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result {
x86_64::instructions::interrupts::without_interrupts(|| { x86_64::instructions::interrupts::without_interrupts(|| {
// TERMINAL_LOGGER.lock().write_fmt(args)?; // TERMINAL_LOGGER.lock().write_fmt(args)?;
let mut sc = SERIAL_CONSOLE.lock(); SERIAL_CONSOLE.lock().write_fmt(args)
sc.write_fmt(args)?;
Ok(())
}) })
} }

View file

@ -4,14 +4,9 @@ version = "0.2.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
cpio_reader = "0.1" # remove me
derive_more = "0.99" derive_more = "0.99"
env_logger = "0.10"
error-stack = "0.2" error-stack = "0.2"
fatfs = "0.3" fatfs = "0.3"
log = "0.4" # remove me
rpm = "0.11" # remove me
zstd = "0.12" # remove me
[dependencies.reqwest] [dependencies.reqwest]
version = "0.11" version = "0.11"

View file

@ -71,25 +71,11 @@ fn main() -> Result<(), Error> {
} }
fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> { fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> {
let path = Path::new("target/disk.img");
match std::fs::metadata(path) {
Err(e) if e.kind() == io::ErrorKind::NotFound => (),
Err(e) => bail!(e),
Ok(_) => {
return FileSystem::new(
File::options().read(true).write(true).open(path)?,
FsOptions::new(),
)
.into_report()
}
}
let mut img = File::options() let mut img = File::options()
.read(true) .read(true)
.write(true) .write(true)
.create(true) .create(true)
.open(path)?; .open(Path::new("target/disk.img"))?;
img.set_len(1024 * 1024 * 64)?; img.set_len(1024 * 1024 * 64)?;