Run rustfmt
This commit is contained in:
parent
f3f5f34fd5
commit
0bc769e702
|
@ -1,7 +1,12 @@
|
||||||
use alloc::alloc::{GlobalAlloc, Layout};
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
use x86_64::{VirtAddr, structures::paging::{FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError}};
|
|
||||||
use core::ptr::null_mut;
|
use core::ptr::null_mut;
|
||||||
use linked_list_allocator::LockedHeap;
|
use linked_list_allocator::LockedHeap;
|
||||||
|
use x86_64::{
|
||||||
|
structures::paging::{
|
||||||
|
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
|
||||||
|
},
|
||||||
|
VirtAddr,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
||||||
|
@ -21,7 +26,10 @@ static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
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 page_range = {
|
||||||
let heap_start = VirtAddr::new(HEAP_START as u64);
|
let heap_start = VirtAddr::new(HEAP_START as u64);
|
||||||
let heap_end = heap_start + HEAP_SIZE - 1u64;
|
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 {
|
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;
|
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||||
unsafe {
|
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }
|
||||||
mapper.map_to(page, frame, flags, frame_allocator)?.flush()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -7,15 +7,15 @@
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
#![feature(alloc_error_handler)]
|
#![feature(alloc_error_handler)]
|
||||||
|
|
||||||
|
mod allocator;
|
||||||
mod gdt;
|
mod gdt;
|
||||||
mod interrupts;
|
mod interrupts;
|
||||||
|
mod memory;
|
||||||
mod shell;
|
mod shell;
|
||||||
mod vga_buffer;
|
mod vga_buffer;
|
||||||
mod memory;
|
|
||||||
mod allocator;
|
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
|
||||||
use bootloader::BootInfo;
|
use bootloader::BootInfo;
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
extern crate alloc;
|
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 phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||||
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
||||||
let mut frame_allocator = unsafe {
|
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||||
BootInfoFrameAllocator::init(&boot_info.memory_map)
|
|
||||||
};
|
|
||||||
print!("[ ");
|
print!("[ ");
|
||||||
change_color(Color::Green, Color::Black);
|
change_color(Color::Green, Color::Black);
|
||||||
print!("OK");
|
print!("OK");
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use x86_64::{PhysAddr, VirtAddr, structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB}};
|
|
||||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
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> {
|
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
|
||||||
let level_4_table = active_level_4_table(physical_memory_offset);
|
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 {
|
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
|
||||||
BootInfoFrameAllocator {
|
BootInfoFrameAllocator {
|
||||||
memory_map,
|
memory_map,
|
||||||
next: 0
|
next: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/shell.rs
15
src/shell.rs
|
@ -2,8 +2,8 @@ use crate::print;
|
||||||
use crate::println;
|
use crate::println;
|
||||||
use crate::vga_buffer::ScreenChar;
|
use crate::vga_buffer::ScreenChar;
|
||||||
use crate::vga_buffer::{change_color, Color};
|
use crate::vga_buffer::{change_color, Color};
|
||||||
use alloc::{vec::Vec, string::String};
|
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
|
use alloc::{string::String, vec::Vec};
|
||||||
|
|
||||||
pub fn evaluate(command: &str) {
|
pub fn evaluate(command: &str) {
|
||||||
if let Some(stripped) = command.strip_prefix(">>> ") {
|
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 {
|
for i in 1..len_b {
|
||||||
cur[i] = i;
|
cur[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, ca) in a.chars().enumerate() {
|
for (i, ca) in a.chars().enumerate() {
|
||||||
pre = cur[0];
|
pre = cur[0];
|
||||||
cur[0] = i+1;
|
cur[0] = i + 1;
|
||||||
for (j, cb) in b.chars().enumerate() {
|
for (j, cb) in b.chars().enumerate() {
|
||||||
tmp = cur[j + 1];
|
tmp = cur[j + 1];
|
||||||
cur[j + 1] = core::cmp::min(
|
cur[j + 1] = core::cmp::min(
|
||||||
tmp + 1,
|
tmp + 1,
|
||||||
core::cmp::min(
|
core::cmp::min(cur[j] + 1, pre + if ca == cb { 0 } else { 1 }),
|
||||||
cur[j] + 1,
|
);
|
||||||
pre + if ca == cb { 0 } else { 1 }
|
|
||||||
)
|
|
||||||
);
|
|
||||||
pre = tmp;
|
pre = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +65,7 @@ fn compute_edit_distance(a: &str, b: &str) -> usize {
|
||||||
cur[len_b - 1]
|
cur[len_b - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default(arguments:&[&str]) {
|
fn default(arguments: &[&str]) {
|
||||||
let mut distances: Vec<(&str, usize)> = Vec::new();
|
let mut distances: Vec<(&str, usize)> = Vec::new();
|
||||||
let curr = arguments[0];
|
let curr = arguments[0];
|
||||||
for &command in &["help", "info", "echo", "shutdown", "clear"] {
|
for &command in &["help", "info", "echo", "shutdown", "clear"] {
|
||||||
|
|
Loading…
Reference in a new issue