Run rustfmt

This commit is contained in:
Yash Karandikar 2021-09-20 09:28:49 -05:00
parent f3f5f34fd5
commit 0bc769e702
4 changed files with 29 additions and 23 deletions

View file

@ -1,7 +1,12 @@
use alloc::alloc::{GlobalAlloc, Layout};
use x86_64::{VirtAddr, structures::paging::{FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError}};
use core::ptr::null_mut;
use linked_list_allocator::LockedHeap;
use x86_64::{
structures::paging::{
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
},
VirtAddr,
};
pub struct Dummy;
@ -21,7 +26,10 @@ static ALLOCATOR: LockedHeap = LockedHeap::empty();
pub const HEAP_START: usize = 0x_4444_4444_0000;
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
pub fn init_heap(mapper: &mut impl Mapper<Size4KiB>, frame_allocator: &mut impl FrameAllocator<Size4KiB>) -> Result<(), MapToError<Size4KiB>> {
pub fn init_heap(
mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
) -> Result<(), MapToError<Size4KiB>> {
let page_range = {
let heap_start = VirtAddr::new(HEAP_START as u64);
let heap_end = heap_start + HEAP_SIZE - 1u64;
@ -31,11 +39,11 @@ pub fn init_heap(mapper: &mut impl Mapper<Size4KiB>, frame_allocator: &mut impl
};
for page in page_range {
let frame = frame_allocator.allocate_frame().ok_or(MapToError::FrameAllocationFailed)?;
let frame = frame_allocator
.allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?;
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
unsafe {
mapper.map_to(page, frame, flags, frame_allocator)?.flush()
}
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }
}
unsafe {

View file

@ -7,15 +7,15 @@
#![feature(abi_x86_interrupt)]
#![feature(alloc_error_handler)]
mod allocator;
mod gdt;
mod interrupts;
mod memory;
mod shell;
mod vga_buffer;
mod memory;
mod allocator;
use core::panic::PanicInfo;
use bootloader::BootInfo;
use core::panic::PanicInfo;
extern crate alloc;
@ -50,9 +50,7 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) {
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { memory::init(phys_mem_offset) };
let mut frame_allocator = unsafe {
BootInfoFrameAllocator::init(&boot_info.memory_map)
};
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
print!("[ ");
change_color(Color::Green, Color::Black);
print!("OK");

View file

@ -1,5 +1,8 @@
use x86_64::{PhysAddr, VirtAddr, structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB}};
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
use x86_64::{
structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB},
PhysAddr, VirtAddr,
};
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
let level_4_table = active_level_4_table(physical_memory_offset);
@ -27,7 +30,7 @@ impl BootInfoFrameAllocator {
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
BootInfoFrameAllocator {
memory_map,
next: 0
next: 0,
}
}

View file

@ -2,8 +2,8 @@ use crate::print;
use crate::println;
use crate::vga_buffer::ScreenChar;
use crate::vga_buffer::{change_color, Color};
use alloc::{vec::Vec, string::String};
use alloc::vec;
use alloc::{string::String, vec::Vec};
pub fn evaluate(command: &str) {
if let Some(stripped) = command.strip_prefix(">>> ") {
@ -48,19 +48,16 @@ fn compute_edit_distance(a: &str, b: &str) -> usize {
for i in 1..len_b {
cur[i] = i;
}
for (i, ca) in a.chars().enumerate() {
pre = cur[0];
cur[0] = i+1;
cur[0] = i + 1;
for (j, cb) in b.chars().enumerate() {
tmp = cur[j + 1];
cur[j + 1] = core::cmp::min(
tmp + 1,
core::cmp::min(
cur[j] + 1,
pre + if ca == cb { 0 } else { 1 }
)
);
core::cmp::min(cur[j] + 1, pre + if ca == cb { 0 } else { 1 }),
);
pre = tmp;
}
}
@ -68,7 +65,7 @@ fn compute_edit_distance(a: &str, b: &str) -> usize {
cur[len_b - 1]
}
fn default(arguments:&[&str]) {
fn default(arguments: &[&str]) {
let mut distances: Vec<(&str, usize)> = Vec::new();
let curr = arguments[0];
for &command in &["help", "info", "echo", "shutdown", "clear"] {