mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Formatting: Run rustfmt
This commit is contained in:
@@ -85,6 +85,6 @@ extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &str, line: u32) -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn _Unwind_Resume() -> ! {
|
pub extern "C" fn _Unwind_Resume() -> ! {
|
||||||
loop{}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,16 +20,19 @@ pub const PAGE_SIZE: usize = 4096;
|
|||||||
pub fn init(boot_info: &BootInformation) {
|
pub fn init(boot_info: &BootInformation) {
|
||||||
assert_has_not_been_called!("memory::init must be called only once");
|
assert_has_not_been_called!("memory::init must be called only once");
|
||||||
|
|
||||||
let memory_map_tag = boot_info.memory_map_tag().expect(
|
let memory_map_tag = boot_info.memory_map_tag().expect("Memory map tag required");
|
||||||
"Memory map tag required");
|
let elf_sections_tag = boot_info.elf_sections_tag().expect("Elf sections tag required");
|
||||||
let elf_sections_tag = boot_info.elf_sections_tag().expect(
|
|
||||||
"Elf sections tag required");
|
|
||||||
|
|
||||||
let kernel_start = elf_sections_tag.sections()
|
let kernel_start = elf_sections_tag.sections()
|
||||||
.filter(|s| s.is_allocated()).map(|s| s.addr).min().unwrap();
|
.filter(|s| s.is_allocated())
|
||||||
|
.map(|s| s.addr)
|
||||||
|
.min()
|
||||||
|
.unwrap();
|
||||||
let kernel_end = elf_sections_tag.sections()
|
let kernel_end = elf_sections_tag.sections()
|
||||||
.filter(|s| s.is_allocated()).map(|s| s.addr + s.size).max()
|
.filter(|s| s.is_allocated())
|
||||||
.unwrap();
|
.map(|s| s.addr + s.size)
|
||||||
|
.max()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
println!("kernel start: {:#x}, kernel end: {:#x}",
|
println!("kernel start: {:#x}, kernel end: {:#x}",
|
||||||
kernel_start,
|
kernel_start,
|
||||||
@@ -38,19 +41,19 @@ pub fn init(boot_info: &BootInformation) {
|
|||||||
boot_info.start_address(),
|
boot_info.start_address(),
|
||||||
boot_info.end_address());
|
boot_info.end_address());
|
||||||
|
|
||||||
let mut frame_allocator = AreaFrameAllocator::new(
|
let mut frame_allocator = AreaFrameAllocator::new(kernel_start as usize,
|
||||||
kernel_start as usize, kernel_end as usize,
|
kernel_end as usize,
|
||||||
boot_info.start_address(), boot_info.end_address(),
|
boot_info.start_address(),
|
||||||
memory_map_tag.memory_areas());
|
boot_info.end_address(),
|
||||||
|
memory_map_tag.memory_areas());
|
||||||
|
|
||||||
let mut active_table = paging::remap_the_kernel(&mut frame_allocator,
|
let mut active_table = paging::remap_the_kernel(&mut frame_allocator, boot_info);
|
||||||
boot_info);
|
|
||||||
|
|
||||||
use self::paging::Page;
|
use self::paging::Page;
|
||||||
use hole_list_allocator::{HEAP_START, HEAP_SIZE};
|
use hole_list_allocator::{HEAP_START, HEAP_SIZE};
|
||||||
|
|
||||||
let heap_start_page = Page::containing_address(HEAP_START);
|
let heap_start_page = Page::containing_address(HEAP_START);
|
||||||
let heap_end_page = Page::containing_address(HEAP_START + HEAP_SIZE-1);
|
let heap_end_page = Page::containing_address(HEAP_START + HEAP_SIZE - 1);
|
||||||
|
|
||||||
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
||||||
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
active_table.map(page, paging::WRITABLE, &mut frame_allocator);
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ impl InactivePageTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation) -> ActivePageTable
|
||||||
-> ActivePageTable
|
|
||||||
where A: FrameAllocator
|
where A: FrameAllocator
|
||||||
{
|
{
|
||||||
let mut temporary_page = TemporaryPage::new(Page { number: 0xcafebabe }, allocator);
|
let mut temporary_page = TemporaryPage::new(Page { number: 0xcafebabe }, allocator);
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ pub struct Table<L: TableLevel> {
|
|||||||
level: PhantomData<L>,
|
level: PhantomData<L>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> Table<L> where L: TableLevel
|
impl<L> Table<L>
|
||||||
|
where L: TableLevel
|
||||||
{
|
{
|
||||||
pub fn zero(&mut self) {
|
pub fn zero(&mut self) {
|
||||||
for entry in self.entries.iter_mut() {
|
for entry in self.entries.iter_mut() {
|
||||||
@@ -29,7 +30,8 @@ impl<L> Table<L> where L: TableLevel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> Table<L> where L: HierarchicalLevel
|
impl<L> Table<L>
|
||||||
|
where L: HierarchicalLevel
|
||||||
{
|
{
|
||||||
fn next_table_address(&self, index: usize) -> Option<usize> {
|
fn next_table_address(&self, index: usize) -> Option<usize> {
|
||||||
let entry_flags = self[index].flags();
|
let entry_flags = self[index].flags();
|
||||||
@@ -68,7 +70,8 @@ impl<L> Table<L> where L: HierarchicalLevel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> Index<usize> for Table<L> where L: TableLevel
|
impl<L> Index<usize> for Table<L>
|
||||||
|
where L: TableLevel
|
||||||
{
|
{
|
||||||
type Output = Entry;
|
type Output = Entry;
|
||||||
|
|
||||||
@@ -77,7 +80,8 @@ impl<L> Index<usize> for Table<L> where L: TableLevel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> IndexMut<usize> for Table<L> where L: TableLevel
|
impl<L> IndexMut<usize> for Table<L>
|
||||||
|
where L: TableLevel
|
||||||
{
|
{
|
||||||
fn index_mut(&mut self, index: usize) -> &mut Entry {
|
fn index_mut(&mut self, index: usize) -> &mut Entry {
|
||||||
&mut self.entries[index]
|
&mut self.entries[index]
|
||||||
|
|||||||
Reference in New Issue
Block a user