Skip to content

Commit

Permalink
[Boot2Snow] Change Allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
ANEP-ET committed Jun 12, 2018
1 parent 5b3a70a commit 05aad58
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ clean:
@rm -r build #target

run: $(img)
@qemu-system-x86_64 -m 1024 -serial mon:stdio -net none -vga std -bios ovmf.fd $(img)
@qemu-system-x86_64 -m 4096 -serial mon:stdio -net none -vga std -bios ovmf.fd $(img)

run-debug: $(img)
@qemu-system-x86_64 -s -S -m 1024 -serial mon:stdio -net none -vga std -bios ovmf.fd $(img)
Expand Down
2 changes: 1 addition & 1 deletion boot2snow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uefi = {git = "https://github.com/SnowFlakeOS/uefi"}
rlibc = "1.0"
bitflags = "1"
x86_64 = "0.1.2"
slab_allocator = { git = "https://github.com/redox-os/slab_allocator.git", rev = "0a53a0b" }
uefi_alloc = { git = "https://github.com/SnowFlakeOS/uefi_alloc" }
orbclient = { git = "https://github.com/redox-os/orbclient.git", branch = "no_std" }

[lib]
Expand Down
14 changes: 0 additions & 14 deletions boot2snow/src/boot2snow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ pub extern fn init() -> Result<(), ()> {
{
let (mut display, vid_addr) = {
let output = Output::one().unwrap();

let mut mode: u32 = 0;

for i in 0..output.0.mode.max_mode {
let info = output.0.query_mode(i).unwrap();

if info.pixel_format != PixelFormat::RGBX
&& info.pixel_format != PixelFormat::BGRX { continue; }
if info.horizontal_resolution > 1920 && info.vertical_resolution > 1080 { continue; }
if info.horizontal_resolution == 1920 && info.vertical_resolution == 1080 { mode = i; break; }
mode = i;
};

let _ = output.0.set_mode(mode);
let vid_addr = output.0.mode.frame_buffer_base;

(Display::new(output), vid_addr)
Expand Down
42 changes: 24 additions & 18 deletions boot2snow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use uefi::{SimpleInputInterface,
Handle,
SystemTable,
Status};
use uefi::boot_services::protocols::{GraphicsOutput, ModeInformation, PixelFormat};

#[macro_use]
extern crate bitflags;
Expand All @@ -34,7 +35,7 @@ extern crate bitflags;
extern crate alloc;
extern crate uefi;
extern crate x86_64;
extern crate slab_allocator;
extern crate uefi_alloc;
extern crate orbclient;

#[macro_use]
Expand All @@ -61,8 +62,6 @@ mod kernel_proto;
#[path="../../share/color.rs"]
mod color;

use slab_allocator::LockedHeap;

// Globals used for panic handling and loging
static mut S_CONIN: *mut SimpleInputInterface = 1 as *mut _;
static mut S_CONOUT: *const SimpleTextOutputInterface = 1 as *const _;
Expand All @@ -72,11 +71,8 @@ static mut S_IMAGE_HANDLE: Handle = 0 as *mut _;

pub type EntryPoint = extern "C" fn(usize, *const kernel_proto::Info) -> !;

pub const HEAP_OFFSET: usize = 0o_000_000_070_000_0000;
pub const HEAP_SIZE: usize = 50 * 1024 * 1024;

#[global_allocator]
static mut ALLOCATOR: LockedHeap = LockedHeap::empty();
static ALLOCATOR: uefi_alloc::Allocator = uefi_alloc::Allocator;

pub fn get_conin() -> &'static mut SimpleInputInterface {
unsafe { &mut *S_CONIN }
Expand All @@ -98,28 +94,33 @@ pub fn get_runtime_services() -> &'static RuntimeServices {
unsafe { &*S_RUNTIME_SERVICES }
}

fn set_text_mode(output: &SimpleTextOutputInterface) -> Result<(), ()> {
fn set_graphics_mode(output: &GraphicsOutput) -> Result<(), ()> {
let mut max_i = None;
let mut max_w = 0;
let mut max_h = 0;

for i in 0..output.mode.max_mode as usize {
let mut w = 0;
let mut h = 0;
if output.query_mode(i, &mut w, &mut h).into_result().is_ok() {
if w >= max_w && h >= max_h {
max_i = Some(i);
let mut mode_ptr: *mut ModeInformation = ::core::ptr::null_mut();
let mut mode_size = 0;
if (output.query_mode)(output, i as u32, &mut mode_size, &mut (mode_ptr as *const ModeInformation)).into_result().is_ok() {
let mode = unsafe { &mut *mode_ptr };

let w = mode.horizontal_resolution;
let h = mode.vertical_resolution;
let pixel_format = mode.pixel_format;
if w >= max_w && h >= max_h && pixel_format == PixelFormat::BGRX {
max_i = Some(i as u32);
max_w = w;
max_h = h;
}
}
}

if let Some(i) = max_i {
let _ = output.set_mode(i);
output.set_mode(i);
}

Ok(())
Ok(())
}

#[no_mangle]
Expand All @@ -135,14 +136,19 @@ pub extern "win64" fn _start(image_handle: Handle, system_table: &SystemTable) -
S_BOOT_SERVICES = system_table.boot_services;
S_RUNTIME_SERVICES = system_table.runtime_services;

::ALLOCATOR.init(::HEAP_OFFSET, ::HEAP_SIZE);
uefi_alloc::init(get_boot_services());
}

let gop = GraphicsOutput::new(get_boot_services()).unwrap();

{
if let Err(err) = set_text_mode(system_table.con_out).into_result() {
println!("Sorry, set_text_mode() Failed :( {:?}", err);
if let Err(err) = set_graphics_mode(gop).into_result() {
println!("Sorry, set_graphics_mode() Failed :( {:?}", err);
loop {};
}

let _ = conout.set_attribute(0x0F);

if let Err(err) = boot2snow::init().into_result() {
println!("Sorry, boot2snow::init() Failed :( {:?}", err);
loop {};
Expand Down
3 changes: 2 additions & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ spin = "0.4.5"
x86_64 = "0.1.2"
bitflags = "1"
once = "0.3.3"
slab_allocator = { git = "https://github.com/redox-os/slab_allocator.git", rev = "0a53a0b" }
slab_allocator = { git = "https://github.com/redox-os/slab_allocator.git", rev = "0a53a0b" }
orbclient = { git = "https://github.com/redox-os/orbclient.git", branch = "no_std" }
1 change: 1 addition & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern crate alloc;
extern crate x86_64;
extern crate spin;
extern crate slab_allocator;
extern crate orbclient;

#[macro_use]
mod macros;
Expand Down

0 comments on commit 05aad58

Please sign in to comment.