1
0
Fork 0
forked from koniifer/ableos

ARM: checkpoint from micro-tau

This commit is contained in:
able 2023-07-17 09:36:39 -05:00
parent ede52eb1db
commit 9225d2d773
5 changed files with 62 additions and 103 deletions

View file

@ -1,7 +1,8 @@
ENTRY(_start) ENTRY(_kernel_start)
SECTIONS SECTIONS
{ {
. = 0x40080000; . = 0xffffffff80000000;
.text.boot : { *(.text.boot) } .text.boot : { *(.text.boot) }
.text : { *(.text) } .text : { *(.text) }
.data : { *(.data) } .data : { *(.data) }
@ -11,4 +12,4 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
. = . + 0x4000; . = . + 0x4000;
LD_STACK_PTR = .; LD_STACK_PTR = .;
} }

View file

@ -1,29 +1,32 @@
//! use {core::arch::asm, limine::FramebufferRequest};
// #[allow(deprecated)]
// use limine::{TerminalRequest, TerminalResponse}; pub const PAGE_SIZE: usize = 4096;
#[no_mangle] #[no_mangle]
#[allow(deprecated)]
unsafe extern "C" fn _kernel_start() -> ! { unsafe extern "C" fn _kernel_start() -> ! {
use limine::{Framebuffer, FramebufferRequest, NonNullPtr};
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0); static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
let fb1: &NonNullPtr<Framebuffer> = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
unsafe {
fb1.address.as_ptr().expect("REASON").write_volatile(0x00); for i in 0..100_usize {
let offset = i * fb1.pitch as usize + i * 4;
unsafe {
*(fb1.address.as_ptr().unwrap().offset(offset as isize) as *mut u32) = 0xFFFFFFFF;
}
} }
loop {} spin_loop();
}
pub fn spin_loop() -> ! {
loop {
unsafe { asm!("wfi") }
}
}
pub fn hardware_random_u64() -> u64 {
0
} }
pub fn log(_args: core::fmt::Arguments<'_>) -> core::fmt::Result { pub fn log(_args: core::fmt::Arguments<'_>) -> core::fmt::Result {
panic!() panic!()
} }
pub fn spin_loop() -> ! {
loop {}
}
pub fn hardware_random_u64() -> u64 {
0
}
pub const PAGE_SIZE: usize = 10;

View file

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

View file

@ -1,4 +1,4 @@
${ABLEOS_KERNEL}=boot:///{$ARCH}/kernel ${ABLEOS_KERNEL}=boot:///kernel
# TODO: Make a boot background image for ableOS # TODO: Make a boot background image for ableOS
DEFAULT_ENTRY=1 DEFAULT_ENTRY=1
@ -22,4 +22,4 @@ TERM_BACKDROP=008080
MODULE_CMDLINE="diskid=123456789" MODULE_CMDLINE="diskid=123456789"
MODULE_PATH=boot:///ecall.hb MODULE_PATH=boot:///ecall.hb
MODULE_CMDLINE="" MODULE_CMDLINE=""

View file

@ -1,6 +1,6 @@
use { use {
derive_more::{Deref, DerefMut, Display}, derive_more::Display,
error_stack::{bail, ensure, report, Context, IntoReport, Result, ResultExt}, error_stack::{bail, report, Context, IntoReport, Result, ResultExt},
fatfs::{FileSystem, FormatVolumeOptions, FsOptions, ReadWriteSeek}, fatfs::{FileSystem, FormatVolumeOptions, FsOptions, ReadWriteSeek},
std::{ std::{
fmt::Display, fmt::Display,
@ -31,12 +31,12 @@ fn main() -> Result<(), Error> {
for arg in args { for arg in args {
if arg == "-r" || arg == "--release" { if arg == "-r" || arg == "--release" {
release = true; release = true;
} } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
target = Target::Riscv64Virt; target = Target::Riscv64Virt;
} } else if arg == "aarch" || arg == "arm64" {
if arg == "aarch" || arg == "arm64" {
target = Target::Aarch64; target = Target::Aarch64;
} else {
return Err(report!(Error::InvalidSubCom));
} }
} }
@ -48,12 +48,12 @@ fn main() -> Result<(), Error> {
for arg in args { for arg in args {
if arg == "-r" || arg == "--release" { if arg == "-r" || arg == "--release" {
release = true; release = true;
} } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
target = Target::Riscv64Virt; target = Target::Riscv64Virt;
} } else if arg == "aarch" || arg == "arm64" {
if arg == "arm64" || arg == "aarch64" {
target = Target::Aarch64; target = Target::Aarch64;
} else {
return Err(report!(Error::InvalidSubCom));
} }
} }
@ -168,8 +168,8 @@ fn build(release: bool, target: Target) -> Result<(), Error> {
_ => (), _ => (),
} }
if target != Target::X86_64 { if target != Target::Aarch64 {
return Ok(()); todo!()
} }
(|| -> std::io::Result<_> { (|| -> std::io::Result<_> {
@ -216,8 +216,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
// com.args(["-enable-kvm", "-cpu", "host"]);
//com.args(["-enable-kvm", "-cpu", "host"]);
} }
} }
@ -237,19 +236,16 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
} }
if target == Target::Aarch64 { if target == Target::Aarch64 {
#[rustfmt::skip]
com.args([ com.args([
"-bios", "-M", "virt",
"AAVMF_CODE.fd", "-cpu", "cortex-a72",
"-M", "-device", "ramfb",
"virt", "-device", "qemu-xhci",
"-device", "-device", "usb-kbd",
"ramfb", "-m", "2G",
"-m", // "-bios", "target/AARCH64_OVMF.fd",
"128M", "-drive", "file=target/disk.img,format=raw",
//
"-drive",
"file=target/disk.img,format=raw",
// "-serial", "stdio",
]); ]);
} }
@ -264,14 +260,15 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
} }
fn fetch_ovmf() -> Result<(), OvmfFetchError> { fn fetch_ovmf() -> Result<(), OvmfFetchError> {
const OVMF_RPM_URL: &str = "https://kojipkgs.fedoraproject.org/packages/edk2/20230524/3.fc38/noarch/edk2-ovmf-20230524-3.fc38.noarch.rpm"; const OVMF_AARCH64_URL: &str =
"https://retrage.github.io/edk2-nightly/bin/RELEASEAARCH64_QEMU_EFI.fd";
let mut file = match std::fs::metadata("target/OVMF_CODE.fd") { let mut file = match std::fs::metadata("target/AARCH64_OVMF.fd") {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => std::fs::OpenOptions::new() Err(e) if e.kind() == std::io::ErrorKind::NotFound => std::fs::OpenOptions::new()
.create(true) .create(true)
.write(true) .write(true)
.read(true) .read(true)
.open("target/OVMF_CODE.fd") .open("target/AARCH64_OVMF.fd")
.into_report() .into_report()
.change_context(OvmfFetchError::Io)?, .change_context(OvmfFetchError::Io)?,
Ok(_) => return Ok(()), Ok(_) => return Ok(()),
@ -279,64 +276,22 @@ fn fetch_ovmf() -> Result<(), OvmfFetchError> {
}; };
log::info!("No OVMF found, downloading…"); log::info!("No OVMF found, downloading…");
let rpm = rpm::RPMPackage::parse(
&mut std::convert::identity::<reqwest::Result<_>>((|| { let bytes = std::convert::identity((|| reqwest::blocking::get(OVMF_AARCH64_URL)?.bytes())())
reqwest::blocking::get(OVMF_RPM_URL)?.bytes()
})())
.into_report() .into_report()
.change_context(OvmfFetchError::Fetch)? .change_context(OvmfFetchError::Fetch)?;
.as_ref(),
)
.map_err(RpmError)
.into_report()
.change_context(OvmfFetchError::RpmParse)?;
ensure!( file.write_all(&bytes)
rpm.metadata .into_report()
.get_payload_compressor() .change_context(OvmfFetchError::Io)?;
.map_err(RpmError)
.into_report()
.change_context(OvmfFetchError::RpmParse)?
== rpm::CompressionType::Zstd,
OvmfFetchError::UnsupportedCompression,
);
file.write_all(
cpio_reader::iter_files(
&zstd::decode_all(std::io::Cursor::new(rpm.content))
.into_report()
.change_context(OvmfFetchError::Zstd)?,
)
.find(|file| file.name() == "./usr/share/edk2/ovmf/OVMF_CODE.fd")
.ok_or_else(|| report!(OvmfFetchError::NoFileFound))?
.file(),
)
.into_report()
.change_context(OvmfFetchError::Io)?;
Ok(()) Ok(())
} }
#[derive(Debug, Display, Deref, DerefMut)]
struct RpmError(rpm::RPMError);
impl Context for RpmError {}
// Ehhh?? I am pretty sure they just forgot :ferrisClueless:
unsafe impl Sync for RpmError {}
unsafe impl Send for RpmError {}
#[derive(Debug, Display)] #[derive(Debug, Display)]
enum OvmfFetchError { enum OvmfFetchError {
#[display(fmt = "Failed to fetch OVMF package")] #[display(fmt = "Failed to fetch OVMF package")]
Fetch, Fetch,
#[display(fmt = "RPM parse error")]
RpmParse,
#[display(fmt = "Unsupported compression (ZSTD is the only supported one)")]
UnsupportedCompression,
#[display(fmt = "Decompression error")]
Zstd,
#[display(fmt = "Requested file not found in package")]
NoFileFound,
#[display(fmt = "IO Error")] #[display(fmt = "IO Error")]
Io, Io,
} }