Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup code and remove unsupported dependencies #31

Merged
merged 9 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: xenial
language: rust

rust:
- nightly-2019-11-05
- nightly-2020-03-01
env:
- RUSTFLAGS="-D warnings"

Expand Down
32 changes: 24 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ log-serial = []
log-panic = ["log-serial"]

[dependencies]
cpuio = "*"
spin = "0.5"
x86_64 = "0.9"
atomic_refcell = "0.1"
r-efi = "2.1.0"

24 changes: 5 additions & 19 deletions layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ ENTRY(ram64_start)

PHDRS
{
rodata PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
text PT_LOAD ;
program PT_LOAD FILEHDR PHDRS ;
}

/* Loaders like to put stuff in low memory (< 1M), so we don't use it. */
Expand All @@ -13,31 +11,19 @@ ram_max = 2M;
/* Our stack grows down from ram_max. TODO: Add a guard for stack overflows. */
stack_size = 64K;

/* Pagetable locations loaded by Firecracker/cloud-hypervisor */
pml4t = 0x9000;
pml3t = 0xa000;

SECTIONS
{
/* Mapping in the program headers makes it easier to mmap the whole file. */
. = ram_min;
. += SIZEOF_HEADERS;

.rodata : { *(.rodata .rodata.*) } :rodata
.data : { *(.data .data.*) *(.bss .bss.*) } :data
.text : {
*(.text .text.*)
*(.ram64)
} :text
.rodata : { *(.rodata .rodata.*) } :program
.text : { *(.text .text.*) } :program
.data : { *(.data .data.*) } :program
.bss : { *(.bss .bss.*) } :program

firmware_ram_size = . - ram_min;

/* Memory for identity mapping, keep synced with ADDRESS_SPACE_GIB */
address_space_gib = 4;
. = ALIGN(4K);
pml2t = .;
. += 4K * address_space_gib;

ASSERT((. <= ram_max - stack_size), "firmware size too big for RAM region")

/* Match edk2's GccBase.lds DISCARD section */
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2019-11-05
josephlr marked this conversation as resolved.
Show resolved Hide resolved
nightly-2020-03-01
1 change: 1 addition & 0 deletions src/asm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global_asm!(include_str!("ram64.s"));
17 changes: 1 addition & 16 deletions src/asm/ram64.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.section .ram64, "ax"
.section .text, "ax"
.global ram64_start
.code64

Expand All @@ -8,22 +8,7 @@ ram64_start:
movb $'L', %al
outb %al, %dx

# Enable SSE2 for XMM registers (needed for EFI calling)
# Clear CR0.EM and Set CR0.MP
movq %cr0, %rax
andb $0b11111011, %al # Clear bit 2
orb $0b00000010, %al # Set bit 1
movq %rax, %cr0
# Set CR4.OSFXSR and CR4.OSXMMEXCPT
movq %cr4, %rax
orb $0b00000110, %ah # Set bits 9 and 10
movq %rax, %cr4

# Setup the stack (at the end of our RAM region)
movq $ram_max, %rsp

jmp rust64_start

halt_loop:
hlt
jmp halt_loop
3 changes: 1 addition & 2 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

use core::cell::RefCell;

use crate::virtio::Error as VirtioError;
use crate::virtio::VirtioTransport;
use crate::virtio::{Error as VirtioError, VirtioTransport};

const QUEUE_SIZE: usize = 16;

Expand Down
3 changes: 1 addition & 2 deletions src/bzimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::fat;
use fat::Read;
use crate::fat::{self, Read};

pub enum Error {
FileError,
Expand Down
4 changes: 2 additions & 2 deletions src/efi/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const PAGE_SIZE: u64 = 4096;

use r_efi::efi::{AllocateType, MemoryType, PhysicalAddress, Status, VirtualAddress};

const PAGE_SIZE: u64 = 4096;

// Copied from r_efi so we can do Default on it
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
10 changes: 6 additions & 4 deletions src/efi/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

use core::ffi::c_void;

use r_efi::efi::{AllocateType, Guid, MemoryType, Status};
use r_efi::protocols::device_path::Protocol as DevicePathProtocol;
use r_efi::{eficall, eficall_abi};
use r_efi::{
efi::{AllocateType, Guid, MemoryType, Status},
eficall, eficall_abi,
protocols::device_path::Protocol as DevicePathProtocol,
};

pub const PROTOCOL_GUID: Guid = Guid::from_fields(
0x964e_5b21,
Expand Down Expand Up @@ -184,7 +186,7 @@ impl<'a> BlockWrapper<'a> {
let last_block = unsafe { (*block).get_capacity() } - 1;

let size = core::mem::size_of::<BlockWrapper>();
let (_status, new_address) = super::ALLOCATOR.lock().allocate_pages(
let (_status, new_address) = super::ALLOCATOR.borrow_mut().allocate_pages(
AllocateType::AllocateAnyPages,
MemoryType::LoaderData,
((size + super::PAGE_SIZE as usize - 1) / super::PAGE_SIZE as usize) as u64,
Expand Down
16 changes: 9 additions & 7 deletions src/efi/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use r_efi::efi::{Boolean, Char16, Event, Handle, Status};
use r_efi::protocols::simple_text_input::InputKey;
use r_efi::protocols::simple_text_input::Protocol as SimpleTextInputProtocol;
use r_efi::protocols::simple_text_output::Mode as SimpleTextOutputMode;
use r_efi::protocols::simple_text_output::Protocol as SimpleTextOutputProtocol;
use r_efi::{
efi::{Boolean, Char16, Event, Handle, Status},
protocols::{
simple_text_input::{InputKey, Protocol as SimpleTextInputProtocol},
simple_text_output::{Mode as SimpleTextOutputMode, Protocol as SimpleTextOutputProtocol},
},
};

use super::{HandleType, HandleWrapper};

Expand Down Expand Up @@ -50,7 +52,7 @@ pub extern "win64" fn stdout_output_string(
message: *mut Char16,
) -> Status {
use core::fmt::Write;
let mut logger = crate::logger::LOGGER.lock();
let mut serial = crate::serial::SERIAL.borrow_mut();
let mut string_end = false;

loop {
Expand All @@ -65,7 +67,7 @@ pub extern "win64" fn stdout_output_string(
i += 1;
}
let s = unsafe { core::str::from_utf8_unchecked(&output) };
logger.write_str(s).unwrap();
serial.write_str(s).unwrap();
if string_end {
break;
}
Expand Down
15 changes: 9 additions & 6 deletions src/efi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

use core::ffi::c_void;

use r_efi::efi::{AllocateType, Char16, Guid, MemoryType, Status};
use r_efi::protocols::device_path::Protocol as DevicePathProtocol;
use r_efi::protocols::file::Protocol as FileProtocol;
use r_efi::protocols::simple_file_system::Protocol as SimpleFileSystemProtocol;
use r_efi::{
efi::{AllocateType, Char16, Guid, MemoryType, Status},
protocols::{
device_path::Protocol as DevicePathProtocol, file::Protocol as FileProtocol,
simple_file_system::Protocol as SimpleFileSystemProtocol,
},
};

#[repr(C)]
pub struct FileDevicePathProtocol {
Expand Down Expand Up @@ -81,7 +84,7 @@ pub extern "win64" fn open(
pub extern "win64" fn close(proto: *mut FileProtocol) -> Status {
let wrapper = container_of!(proto, FileWrapper, proto);
super::ALLOCATOR
.lock()
.borrow_mut()
.free_pages(&wrapper as *const _ as u64)
}

Expand Down Expand Up @@ -205,7 +208,7 @@ pub struct FileSystemWrapper<'a> {
impl<'a> FileSystemWrapper<'a> {
fn create_file(&self, root: bool) -> Option<*mut FileWrapper> {
let size = core::mem::size_of::<FileWrapper>();
let (status, new_address) = super::ALLOCATOR.lock().allocate_pages(
let (status, new_address) = super::ALLOCATOR.borrow_mut().allocate_pages(
AllocateType::AllocateAnyPages,
MemoryType::LoaderData,
((size + super::PAGE_SIZE as usize - 1) / super::PAGE_SIZE as usize) as u64,
Expand Down
Loading