uefi subarch, x86 still broke

This commit is contained in:
Able 2022-02-07 02:58:54 -06:00
parent 04374aa905
commit 118c2edfc1
5 changed files with 183 additions and 173 deletions

View file

@ -9,11 +9,11 @@ panic = "abort"
[package.metadata.bootimage]
run-args = [
"-cpu",
# "-cpu",
# "kvm64-v1",
# Support for rdrand
# "Broadwell",
"EPYC-v1",
# "EPYC-v1",
"-serial",
@ -51,8 +51,6 @@ pretty-hex = "0.2.1"
unicode-width = "0.1.7"
picorand = "*"
# watson = "0.4"
uefi = { version="*",default-features = false, features = ["exts"] }
uefi-services = "0.11.0"
[dependencies.rdrand]
version = "0.8.1"
@ -118,3 +116,9 @@ pic8259 = "0.10.1"
uart_16550 = "0.2.0"
volatile = "0.2.6"
x86_64 = "*"
[target.'cfg(target_os = "uefi")'.dependencies]
uefi = { version="*",default-features = false, features = ["exts"] }
uefi-services = "0.11.0"

View file

@ -17,10 +17,12 @@ static ALLOCATOR: Dummy = Dummy;
*/
use linked_list_allocator::LockedHeap;
// #[global_allocator]
#[cfg(not(target_os = "uefi"))]
#[global_allocator]
pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
// #[alloc_error_handler]
#[cfg(not(target_os = "uefi"))]
#[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
panic!("allocation error: {:?}", layout)
}

View file

@ -7,3 +7,168 @@ pub fn shutdown() {
pub fn sloop() -> ! {
loop {}
}
use crate::kmain::kernel_main;
use uefi::{
prelude::*,
proto::{
console::gop::{GraphicsOutput, PixelFormat},
media::{
file::{File, FileAttribute, FileMode},
fs::SimpleFileSystem,
},
},
CStr16,
};
use uefi::{proto::console::gop::FrameBuffer, ResultExt};
use crate::{file::FileLocations, logger, vterm::Vterm, GraphicsReturn, ScreenBuffer};
#[entry]
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
system_table
.stdout()
.reset(false)
.expect_success("Failed to reset output buffer");
uefi_services::init(&mut system_table).unwrap_success();
// Print out UEFI revision number
{
let rev = system_table.uefi_revision();
let (major, minor) = (rev.major(), rev.minor());
info!("UEFI {}.{}", major, minor);
}
info!("Running graphics output protocol test");
let stdout = system_table.stdout();
stdout.set_cursor_position(0, 10).unwrap_success();
info!("{:?}", stdout.cursor_position());
// loop {}
/*
if let Ok(gop) = system_table
.boot_services()
.locate_protocol::<GraphicsOutput>()
{
let gop = gop.expect("Warnings encountered while opening GOP");
// Maybe save this
let gop = unsafe { &mut *gop.get() };
let mode = gop
.modes()
.map(|mode| mode.expect("Warnings encountered while querying mode"))
.find(|mode| {
let info = mode.info();
info.resolution() == (1440, 900)
})
.unwrap();
gop.set_mode(&mode)
.expect_success("Failed to set graphics mode");
//crate::check_screenshot(bt, "gop_test");
draw_fb(gop);
} else {
// No tests can be run.
warn!("UEFI Graphics Output Protocol is not supported");
}
*/
// exit boot services
kernel_main();
Status::SUCCESS
}
pub fn draw_fb(gop: &mut GraphicsOutput) {
let mi = gop.current_mode_info();
let stride = mi.stride();
let (width, height) = mi.resolution();
let mut fb = gop.frame_buffer();
type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]);
unsafe fn write_pixel_rgb(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, rgb);
}
unsafe fn write_pixel_bgr(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]);
}
let write_pixel: PixelWriter = match mi.pixel_format() {
PixelFormat::Rgb => write_pixel_rgb,
PixelFormat::Bgr => write_pixel_bgr,
_ => {
info!("This pixel format is not supported by the drawing demo");
return;
}
};
let mut fill_rectangle = |(x1, y1), (x2, y2), color| {
assert!((x1 < width) && (x2 < width), "Bad X coordinate");
assert!((y1 < height) && (y2 < height), "Bad Y coordinate");
for row in y1..y2 {
for column in x1..x2 {
unsafe {
let pixel_index = (row * stride) + column;
let pixel_base = 4 * pixel_index;
write_pixel(&mut fb, pixel_base, color);
}
}
}
};
fill_rectangle((50, 30), (150, 600), [123, 123, 123]);
fill_rectangle((400, 120), (750, 450), [16, 0, 255]);
fill_rectangle((80, 50), (200, 120), [0, 255, 0]);
}
pub trait GopBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn;
}
impl GopBuffer for ScreenBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn {
GraphicsReturn::GenericError
}
}
/*
pub fn file_system() -> Result<SimpleFileSystem, Status> {
if let Ok(gop) = system_table
.boot_services()
.locate_protocol::<SimpleFileSystem>()
{
let gop = gop.expect("Warnings encountered while opening GOP");
// Maybe save this
let gop = unsafe { &mut *gop.get() };
let mut root = gop.open_volume().unwrap().expect("Failed to open volume");
let attr = FileAttribute::all();
let xyz = root.open("test", FileMode::CreateReadWrite, attr).unwrap();
let abcd = xyz.expect("Failed to open file").into_type();
let abcdef = abcd.unwrap().expect("Failed to open file");
let mut buffer = [0u8; 10];
match abcdef {
uefi::proto::media::file::FileType::Regular(mut file) => {
info!("{:?}", file.read(&mut buffer))
}
uefi::proto::media::file::FileType::Dir(_) => todo!(),
}
} else {
// No tests can be run.
warn!("UEFI Simple File System is not supported");
}
}
*/

View file

@ -2,6 +2,7 @@
use x86_64::instructions::random::RdRand;
use crate::{logger, vterm::Vterm};
use {
crate::{
arch::{init, sloop},
@ -28,7 +29,6 @@ use {
lazy_static::lazy_static,
log::*,
};
lazy_static! {
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
@ -37,8 +37,9 @@ lazy_static! {
/// The main entry point of the kernel
#[no_mangle]
pub fn kernel_main() -> ! {
log::set_max_level(BOOT_CONF.log_level());
// log::set_max_level(BOOT_CONF.log_level());
init::init();
info!("AbleOS {} {}", KERNEL_VERSION, RELEASE_TYPE);
let result = logger::init();
match result {
Ok(_) => {}
@ -88,167 +89,3 @@ pub fn generate_process_pass() -> u128 {
let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
ret
}
// #![no_main]
// #![no_std]
use uefi::{
prelude::*,
proto::{
console::gop::{GraphicsOutput, PixelFormat},
media::{
file::{File, FileAttribute, FileMode},
fs::SimpleFileSystem,
},
},
CStr16,
};
use uefi::{proto::console::gop::FrameBuffer, ResultExt};
use crate::{file::FileLocations, logger, vterm::Vterm, GraphicsReturn, ScreenBuffer};
#[entry]
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
system_table
.stdout()
.reset(false)
.expect_success("Failed to reset output buffer");
uefi_services::init(&mut system_table).unwrap_success();
// Print out UEFI revision number
{
let rev = system_table.uefi_revision();
let (major, minor) = (rev.major(), rev.minor());
info!("UEFI {}.{}", major, minor);
}
info!("Running graphics output protocol test");
let stdout = system_table.stdout();
stdout.set_cursor_position(0, 10).unwrap_success();
info!("{:?}", stdout.cursor_position());
// loop {}
/*
if let Ok(gop) = system_table
.boot_services()
.locate_protocol::<GraphicsOutput>()
{
let gop = gop.expect("Warnings encountered while opening GOP");
// Maybe save this
let gop = unsafe { &mut *gop.get() };
let mode = gop
.modes()
.map(|mode| mode.expect("Warnings encountered while querying mode"))
.find(|mode| {
let info = mode.info();
info.resolution() == (1440, 900)
})
.unwrap();
gop.set_mode(&mode)
.expect_success("Failed to set graphics mode");
//crate::check_screenshot(bt, "gop_test");
draw_fb(gop);
} else {
// No tests can be run.
warn!("UEFI Graphics Output Protocol is not supported");
}
*/
// exit boot services
kernel_main();
Status::SUCCESS
}
pub fn draw_fb(gop: &mut GraphicsOutput) {
let mi = gop.current_mode_info();
let stride = mi.stride();
let (width, height) = mi.resolution();
let mut fb = gop.frame_buffer();
type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]);
unsafe fn write_pixel_rgb(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, rgb);
}
unsafe fn write_pixel_bgr(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]);
}
let write_pixel: PixelWriter = match mi.pixel_format() {
PixelFormat::Rgb => write_pixel_rgb,
PixelFormat::Bgr => write_pixel_bgr,
_ => {
info!("This pixel format is not supported by the drawing demo");
return;
}
};
let mut fill_rectangle = |(x1, y1), (x2, y2), color| {
assert!((x1 < width) && (x2 < width), "Bad X coordinate");
assert!((y1 < height) && (y2 < height), "Bad Y coordinate");
for row in y1..y2 {
for column in x1..x2 {
unsafe {
let pixel_index = (row * stride) + column;
let pixel_base = 4 * pixel_index;
write_pixel(&mut fb, pixel_base, color);
}
}
}
};
fill_rectangle((50, 30), (150, 600), [123, 123, 123]);
fill_rectangle((400, 120), (750, 450), [16, 0, 255]);
fill_rectangle((80, 50), (200, 120), [0, 255, 0]);
}
pub trait GopBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn;
}
impl GopBuffer for ScreenBuffer {
fn copy_to_buffer(&self) -> GraphicsReturn {
GraphicsReturn::GenericError
}
}
/*
pub fn file_system() -> Result<SimpleFileSystem, Status> {
if let Ok(gop) = system_table
.boot_services()
.locate_protocol::<SimpleFileSystem>()
{
let gop = gop.expect("Warnings encountered while opening GOP");
// Maybe save this
let gop = unsafe { &mut *gop.get() };
let mut root = gop.open_volume().unwrap().expect("Failed to open volume");
let attr = FileAttribute::all();
let xyz = root.open("test", FileMode::CreateReadWrite, attr).unwrap();
let abcd = xyz.expect("Failed to open file").into_type();
let abcdef = abcd.unwrap().expect("Failed to open file");
let mut buffer = [0u8; 10];
match abcdef {
uefi::proto::media::file::FileType::Regular(mut file) => {
info!("{:?}", file.read(&mut buffer))
}
uefi::proto::media::file::FileType::Dir(_) => todo!(),
}
} else {
// No tests can be run.
warn!("UEFI Simple File System is not supported");
}
}
*/

View file

@ -9,7 +9,9 @@ use {crate::arch::sloop, core::panic::PanicInfo};
///
/// # Safety
/// This function is unsafe because it does not guarantee that the panic is handled.
// #[panic_handler]
#[cfg(not(target_os = "uefi"))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
error!("{}", info);
// help me use facepalm::start_facepalm;