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
{
. = 0x40080000;
. = 0xffffffff80000000;
.text.boot : { *(.text.boot) }
.text : { *(.text) }
.data : { *(.data) }

View file

@ -1,29 +1,32 @@
//!
// #[allow(deprecated)]
// use limine::{TerminalRequest, TerminalResponse};
use {core::arch::asm, limine::FramebufferRequest};
pub const PAGE_SIZE: usize = 4096;
#[no_mangle]
#[allow(deprecated)]
unsafe extern "C" fn _kernel_start() -> ! {
use limine::{Framebuffer, FramebufferRequest, NonNullPtr};
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
let fb1: &NonNullPtr<Framebuffer> = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
unsafe {
fb1.address.as_ptr().expect("REASON").write_volatile(0x00);
let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
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 {
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"
[dependencies]
cpio_reader = "0.1"
cpio_reader = "0.1" # remove me
derive_more = "0.99"
env_logger = "0.10"
error-stack = "0.2"
fatfs = "0.3"
log = "0.4"
rpm = "0.11"
zstd = "0.12"
rpm = "0.11" # remove me
zstd = "0.12" # remove me
[dependencies.reqwest]
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
DEFAULT_ENTRY=1

View file

@ -1,6 +1,6 @@
use {
derive_more::{Deref, DerefMut, Display},
error_stack::{bail, ensure, report, Context, IntoReport, Result, ResultExt},
derive_more::Display,
error_stack::{bail, report, Context, IntoReport, Result, ResultExt},
fatfs::{FileSystem, FormatVolumeOptions, FsOptions, ReadWriteSeek},
std::{
fmt::Display,
@ -31,12 +31,12 @@ fn main() -> Result<(), Error> {
for arg in args {
if arg == "-r" || arg == "--release" {
release = true;
}
if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
} else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
target = Target::Riscv64Virt;
}
if arg == "aarch" || arg == "arm64" {
} else if arg == "aarch" || arg == "arm64" {
target = Target::Aarch64;
} else {
return Err(report!(Error::InvalidSubCom));
}
}
@ -48,12 +48,12 @@ fn main() -> Result<(), Error> {
for arg in args {
if arg == "-r" || arg == "--release" {
release = true;
}
if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
} else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" {
target = Target::Riscv64Virt;
}
if arg == "arm64" || arg == "aarch64" {
} else if arg == "aarch" || arg == "arm64" {
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 {
return Ok(());
if target != Target::Aarch64 {
todo!()
}
(|| -> std::io::Result<_> {
@ -216,8 +216,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
#[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 {
#[rustfmt::skip]
com.args([
"-bios",
"AAVMF_CODE.fd",
"-M",
"virt",
"-device",
"ramfb",
"-m", //
"128M",
//
"-drive",
"file=target/disk.img,format=raw",
// "-serial", "stdio",
"-M", "virt",
"-cpu", "cortex-a72",
"-device", "ramfb",
"-device", "qemu-xhci",
"-device", "usb-kbd",
"-m", "2G",
"-bios", "target/AARCH64_OVMF.fd",
"-drive", "file=target/disk.img,format=raw",
]);
}
@ -264,14 +260,15 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
}
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()
.create(true)
.write(true)
.read(true)
.open("target/OVMF_CODE.fd")
.open("target/AARCH64_OVMF.fd")
.into_report()
.change_context(OvmfFetchError::Io)?,
Ok(_) => return Ok(()),
@ -279,64 +276,22 @@ fn fetch_ovmf() -> Result<(), OvmfFetchError> {
};
log::info!("No OVMF found, downloading…");
let rpm = rpm::RPMPackage::parse(
&mut std::convert::identity::<reqwest::Result<_>>((|| {
reqwest::blocking::get(OVMF_RPM_URL)?.bytes()
})())
let bytes = std::convert::identity((|| reqwest::blocking::get(OVMF_AARCH64_URL)?.bytes())())
.into_report()
.change_context(OvmfFetchError::Fetch)?
.as_ref(),
)
.map_err(RpmError)
.into_report()
.change_context(OvmfFetchError::RpmParse)?;
.change_context(OvmfFetchError::Fetch)?;
ensure!(
rpm.metadata
.get_payload_compressor()
.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)?;
file.write_all(&bytes)
.into_report()
.change_context(OvmfFetchError::Io)?;
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)]
enum OvmfFetchError {
#[display(fmt = "Failed to fetch OVMF package")]
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")]
Io,
}