Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure-Rust boot sequence #74

Merged
merged 86 commits into from
Jan 31, 2017
Merged
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
fa7a2a6
[bootstrap] start implementing 32-bit bootstrap crate
hawkw Oct 19, 2016
ed6a9e8
[build] add target for 32-bit module
hawkw Oct 19, 2016
55c2cbc
[build] rename bootstrap crate
hawkw Oct 20, 2016
4b8d438
[build] Rust boot code actually gets linked in now
hawkw Oct 23, 2016
4c985a2
[build] fix make clean task
hawkw Oct 24, 2016
a34f9bb
Merge branch 'master' of github.com:hawkw/sos-kernel into new-rust-boot
hawkw Oct 27, 2016
b74ffa4
[boot] implement page-table mapping in pure Rust
hawkw Jan 23, 2017
27a05ce
[boot] change boot module to make a binary (start on #69)
hawkw Jan 23, 2017
5b052f1
[bootstrap] start implementing 32-bit bootstrap crate
hawkw Oct 19, 2016
12e5f6f
[build] add target for 32-bit module
hawkw Oct 19, 2016
db86de3
[build] rename bootstrap crate
hawkw Oct 20, 2016
7f5e21d
[build] Rust boot code actually gets linked in now
hawkw Oct 23, 2016
29089e2
[build] fix make clean task
hawkw Oct 24, 2016
3cdc945
[boot] implement page-table mapping in pure Rust
hawkw Jan 23, 2017
8c9a603
[boot] change boot module to make a binary (start on #69)
hawkw Jan 23, 2017
e57ba65
Merge branch 'new-rust-boot' of github.com:hawkw/sos-kernel into new-…
hawkw Jan 23, 2017
2da3050
[kernel, x86_64] almost finish rust boot process
hawkw Jan 24, 2017
43989f8
[boot] remove unused data segment descriptor from boot gdt
hawkw Jan 25, 2017
cee4d55
[boot] re-add functions for page table setup
hawkw Jan 25, 2017
c72d7ec
more work on trying to fix boot
hawkw Jan 25, 2017
2da7183
[boot] slightly prettier code for setting long mode?
hawkw Jan 26, 2017
5f1f82c
[boot] make some boot code prettier
hawkw Jan 26, 2017
5b66c91
[boot] fix objcopy mangling the boot executable
hawkw Jan 26, 2017
ce09656
[build] add Make task for getting the last exception
hawkw Jan 26, 2017
d7e2c49
[boot] long mode jump PROBLEM CHANGED
hawkw Jan 26, 2017
b2b639f
[boot] problem changed again
hawkw Jan 26, 2017
fb3ed50
[boot] remove data segment from GDT
hawkw Jan 26, 2017
193aaff
[boot] make GDT pointer much rustier
hawkw Jan 26, 2017
421d0e0
[boot] add support for making a debug and release boot object
hawkw Jan 28, 2017
705c9d5
[boot] fix boot loop entering 64-bit code!
hawkw Jan 28, 2017
219e702
[boot] make GDT loading more idiomatic
hawkw Jan 29, 2017
fad5219
[boot] add a cute macro for setting control register flags
hawkw Jan 29, 2017
aecfd1f
[boot] clean up boot module a little
hawkw Jan 29, 2017
2953f73
[boot] make boot writing to VGA buffer prettier
hawkw Jan 29, 2017
01ba0a7
[boot] add test for multiboot support back in
hawkw Jan 29, 2017
ae70797
[boot] make page table mapping even more idiomatic
hawkw Jan 29, 2017
d776c65
[chore] add .gdb_history to .gitignore
hawkw Jan 29, 2017
c45a7c0
[chore] have travis build the whole kernel, hopefully fixing build
hawkw Jan 29, 2017
2d2a7af
[bootstrap] start implementing 32-bit bootstrap crate
hawkw Oct 19, 2016
c1030b3
[build] add target for 32-bit module
hawkw Oct 19, 2016
62af7fe
[build] rename bootstrap crate
hawkw Oct 20, 2016
acebe89
[build] Rust boot code actually gets linked in now
hawkw Oct 23, 2016
5f221e9
[build] fix make clean task
hawkw Oct 24, 2016
490a879
[boot] implement page-table mapping in pure Rust
hawkw Jan 23, 2017
549ff46
[boot] change boot module to make a binary (start on #69)
hawkw Jan 23, 2017
06fd63e
[bootstrap] start implementing 32-bit bootstrap crate
hawkw Oct 19, 2016
b093f5d
[build] add target for 32-bit module
hawkw Oct 19, 2016
2bc4888
[build] rename bootstrap crate
hawkw Oct 20, 2016
3ea6558
[build] Rust boot code actually gets linked in now
hawkw Oct 23, 2016
0611bc3
[boot] implement page-table mapping in pure Rust
hawkw Jan 23, 2017
a97289e
[boot] change boot module to make a binary (start on #69)
hawkw Jan 23, 2017
6c4d0fe
[boot] remove unused data segment descriptor from boot gdt
hawkw Jan 25, 2017
9bef8eb
[boot] re-add functions for page table setup
hawkw Jan 25, 2017
e248f8a
more work on trying to fix boot
hawkw Jan 25, 2017
4f9cc5c
[boot] slightly prettier code for setting long mode?
hawkw Jan 26, 2017
84a575b
[boot] make some boot code prettier
hawkw Jan 26, 2017
e013c87
[boot] fix objcopy mangling the boot executable
hawkw Jan 26, 2017
7f9917a
[build] add Make task for getting the last exception
hawkw Jan 26, 2017
23afed2
[boot] long mode jump PROBLEM CHANGED
hawkw Jan 26, 2017
3ac63b3
[boot] problem changed again
hawkw Jan 26, 2017
3c34e60
[boot] remove data segment from GDT
hawkw Jan 26, 2017
158acbc
[boot] make GDT pointer much rustier
hawkw Jan 26, 2017
e8e1ba3
[boot] add support for making a debug and release boot object
hawkw Jan 28, 2017
7bf34c8
[boot] fix boot loop entering 64-bit code!
hawkw Jan 28, 2017
7eb5e20
[boot] make GDT loading more idiomatic
hawkw Jan 29, 2017
f14364a
[boot] add a cute macro for setting control register flags
hawkw Jan 29, 2017
da17d8f
[boot] clean up boot module a little
hawkw Jan 29, 2017
5ea9130
[boot] make boot writing to VGA buffer prettier
hawkw Jan 29, 2017
d8f1104
[boot] add test for multiboot support back in
hawkw Jan 29, 2017
5cd395f
[boot] make page table mapping even more idiomatic
hawkw Jan 29, 2017
c3c0256
[chore] add .gdb_history to .gitignore
hawkw Jan 29, 2017
bdafa32
[chore] have travis build the whole kernel, hopefully fixing build
hawkw Jan 29, 2017
cacbc26
Merge branch 'new-rust-boot' of github.com:hawkw/sos-kernel into new-…
hawkw Jan 29, 2017
d1a4a26
[boot] remove boot/main.rs
hawkw Jan 29, 2017
68614c5
[x86_64] add the rest of bss to the bss section
hawkw Jan 29, 2017
e1041ee
[x86_64] start trying to fix page fault in heap
hawkw Jan 29, 2017
2ae3312
[build] attempt to fix travis not having a cross toolchain
hawkw Jan 31, 2017
0e6150a
[travis] attempt to fix bash syntax on travis script
hawkw Jan 31, 2017
1e74bb6
[travis] another attempt to fix travis bash syntax
hawkw Jan 31, 2017
e463c73
[travis] fix even more bad bash syntax
hawkw Jan 31, 2017
e197ff4
[cpu][x86_all] link to boot GDT in cpu module
hawkw Jan 31, 2017
462416c
[cpu, boot][x86_all] fix linking to GDT in CPU crate
hawkw Jan 31, 2017
93eff6d
[cpu][x86_64] remove dead code in IDT gate module
hawkw Jan 31, 2017
447b037
[travis] make ~/bin/ if it doesn't exist on CI
hawkw Jan 31, 2017
1b68031
[travis] also link x86_64 strip on ubuntu
hawkw Jan 31, 2017
efde010
[x86_64][boot] clean up some leftover stuff from asm boot
hawkw Jan 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[boot] implement page-table mapping in pure Rust
moves code from 05d24c8 into this branch
  • Loading branch information
hawkw committed Jan 29, 2017
commit 0611bc36b76b40423d3431c800b12950c4e03965
45 changes: 23 additions & 22 deletions boot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// SOS: the Stupid Operating System
// by Eliza Weisman (hi@hawkweisman.me)
//
// Copyright (c) 2016 Eliza Weisman
// Copyright (c) 2016-2017 Eliza Weisman
// Released under the terms of the MIT license. See `LICENSE` in the root
// directory of this repository for more information.
//
@@ -11,6 +11,7 @@
#![crate_type = "staticlib"]
#![feature(asm)]
#![feature(lang_items)]
#![feature(naked_functions)]
#![no_std]

const TABLE_LENGTH: usize = 512;
@@ -25,37 +26,37 @@ extern fn panic_fmt(fmt: Arguments, file: &'static str, line: u32) -> ! {
}

extern {
static mut pml4_table: Table;
static mut pdp_table: Table;
static mut pd_table: Table;
static mut page_table: Table;
static mut pml4_table: Table;
static mut pdp_table: Table;
static mut pd_table: Table;
static mut page_table: Table;
//
// static low_end: u8;
// static kernel_size: u8; // &kernel_size == kernel size in pages
// static low_end: u8;
// static kernel_size: u8; // &kernel_size == kernel size in pages
}

#[no_mangle]
#[naked]
pub unsafe extern fn create_page_tables() {
const HUGE_PAGE_SIZE: u64 = 2 * 1024 * 1024; // 2 MiB

//-- map the PML4 and PDP tables -----------------------------------------
// recursive map last PML4 entry
pml4_table[511] = (&pml4_table as *const Table as u64) | 3;
// map first PML4 entry to PDP table
pml4_table[0] = (&pdp_table as *const Table as u64) | 3;
// map first PDPT entry to PD table
pdp_table[0] = (&pd_table as *const Table as u64) | 3;

// map the PD table
// TODO: implement this in Rust
asm!("
// map each PD table entry to its own 2mB page
mov ecx, 0
.pd_table_map: // maps the PD table ----------------------------------------
mov eax, 0x200000 // 2 mB
mul ecx // times the start address of the page
or eax, 0b10000011 // check if present + writable + huge
mov [pd_table + ecx * 8], eax // map nth entry from pd -> own page
// increment counter and check if done
inc ecx
cmp ecx, 512
jne .pd_table_map
" :::: "volatile", "intel");
//-- map the PD table ----------------------------------------------------
for (number, entry) in pd_table.iter_mut().enumerate() {
// set each PD entry equal to the start address of the page (the page
// number times the page's size)
let addr = number as u64 * HUGE_PAGE_SIZE;
// with the appropriate flags (present + writable + huge)
// TODO: do we want to do this using bitflags, or is that too
// heavyweight for the boot module?
// - eliza, 1/23/2017
*entry = addr | 0b10000011;
}
}