mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Map page 0 instead of page 0x1000 because of bootloader 0.8.0
Bootloader 0.8.0 maps the page at 0x1000 itself.
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user