From 820bc0cab355893453aa3d29189f6890a6da0f30 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sat, 14 Sep 2019 17:41:01 +0200 Subject: [PATCH] Map page 0 instead of page 0x1000 because of bootloader 0.8.0 Bootloader 0.8.0 maps the page at 0x1000 itself. --- .../second-edition/posts/09-paging-implementation/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blog/content/second-edition/posts/09-paging-implementation/index.md b/blog/content/second-edition/posts/09-paging-implementation/index.md index 3b803d3d..b3234e05 100644 --- a/blog/content/second-edition/posts/09-paging-implementation/index.md +++ b/blog/content/second-edition/posts/09-paging-implementation/index.md @@ -782,8 +782,8 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { let mut mapper = unsafe { memory::init(boot_info.physical_memory_offset) }; let mut frame_allocator = memory::EmptyFrameAllocator; - // map a previously unmapped page - let page = Page::containing_address(VirtAddr::new(0x1000)); + // map an unused page + let page = Page::containing_address(VirtAddr::new(0)); memory::create_example_mapping(page, &mut mapper, &mut frame_allocator); // write the string `New!` to the screen through the new mapping @@ -794,7 +794,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { } ``` -We first create the mapping for the page at `0x1000` by calling our `create_example_mapping` function with a mutable reference to the `mapper` and the `frame_allocator` instances. This maps the page `0x1000` to the VGA text buffer frame, so we should see any write to it on the screen. +We first create the mapping for the page at address `0` by calling our `create_example_mapping` function with a mutable reference to the `mapper` and the `frame_allocator` instances. This maps the page to the VGA text buffer frame, so we should see any write to it on the screen. Then we convert the page to a raw pointer and write a value to offset `400`. We don't write to the start of the page because the top line of the VGA buffer is directly shifted off the screen by the next `println`. We write the value `0x_f021_f077_f065_f04e`, which represents the string _"New!"_ on white background. As we learned [in the _“VGA Text Mode”_ post], writes to the VGA buffer should be volatile, so we use the [`write_volatile`] method.