diff --git a/Makefile b/Makefile index b0b626d5..4a1f1a15 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ clean: @rm -rf build run: $(iso) - @qemu-system-x86_64 -hda $(iso) + @qemu-system-x86_64 -s -hda $(iso) iso: $(iso) diff --git a/src/arch/x86_64/boot.asm b/src/arch/x86_64/boot.asm index 41074cbb..bdfdb820 100644 --- a/src/arch/x86_64/boot.asm +++ b/src/arch/x86_64/boot.asm @@ -48,6 +48,11 @@ setup_page_tables: ; map first P3 entry to a huge page that starts at address 0 mov dword [p3_table], 0b10000011 ; present + writable + huge + ; recursive map P4 + mov eax, p4_table + or eax, 0b11 ; present + writable + mov [p4_table + 511 * 8], eax + ret enable_paging: @@ -133,7 +138,9 @@ p4_table: p3_table: resb 4096 stack_bottom: - resb 64 + ; TODO a >= 80 byte stack is enough. Theoretically we could use the memory + ; of the p3 table as a hack (it won't override the important first entry) + resb 4096 stack_top: section .rodata diff --git a/src/arch/x86_64/linker.ld b/src/arch/x86_64/linker.ld index 8334f3d3..84f6b0fb 100644 --- a/src/arch/x86_64/linker.ld +++ b/src/arch/x86_64/linker.ld @@ -27,6 +27,15 @@ SECTIONS { .text : { - *(.text) + *(.text .text.*) } + + .rodata : { + *(.rodata .rodata.*) + } + + .data.rel.ro : { + *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) + } + } diff --git a/src/lib.rs b/src/lib.rs index 5ccf4e21..d47c3533 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![feature(no_std, lang_items)] -#![feature(core_str_ext, const_fn)] +#![feature(no_std, lang_items, asm)] +#![feature(core_str_ext, const_fn, range_inclusive)] #![no_std] extern crate rlibc; @@ -26,15 +26,18 @@ use core::fmt::Write; #[macro_use] mod vga_buffer; +mod memory; + #[no_mangle] pub extern fn rust_main(multiboot_address: usize) { // ATTENTION: we have a very small stack and no guard page use vga_buffer::{Writer, Color}; - let multiboot = unsafe{multiboot2::load(multiboot_address)}; - - vga_buffer::clear_screen(); + let multiboot = unsafe{multiboot2::load(multiboot_address)}; + memory::init(multiboot); + + let mut writer = Writer::new(Color::Blue, Color::LightGreen); writer.write_byte(b'H'); let _ = writer.write_str("ello! ");