Browse Source

[extremely gross] port from x86 to the x86_64 crate

master
3moon 8 years ago
parent
commit
633d571522
7 changed files with 26 additions and 212 deletions
  1. +9
    -196
      Cargo.lock
  2. +1
    -1
      Cargo.toml
  3. +1
    -1
      src/arch/x86_64/device/vga_console.rs
  4. +2
    -2
      src/arch/x86_64/memory/paging/mapper.rs
  5. +7
    -6
      src/arch/x86_64/memory/paging/mod.rs
  6. +3
    -3
      src/arch/x86_64/mod.rs
  7. +3
    -3
      src/lib.rs

+ 9
- 196
Cargo.lock View File

@ -10,17 +10,17 @@ dependencies = [
"rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.4.5 (git+https://github.com/messense/spin-rs?rev=020f1b3)",
"volatile 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"x86 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"x86_64 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.4.0"
name = "bit_field"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.7.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -29,25 +29,6 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "csv"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "linked_list_allocator"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -69,158 +50,15 @@ dependencies = [
]
[[package]]
name = "num"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"num-complex 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-bigint"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-complex"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-rational"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "once"
version = "0.1.0"
[[package]]
name = "phf"
version = "0.7.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_codegen"
version = "0.7.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_generator"
version = "0.7.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_shared"
version = "0.7.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "raw-cpuid"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rlibc"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "siphasher"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "spin"
version = "0.4.5"
source = "git+https://github.com/messense/spin-rs?rev=020f1b3#020f1b3f160a1facf54355278af14cbf6a1613fd"
@ -236,47 +74,22 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x86"
version = "0.8.1"
name = "x86_64"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"csv 0.14.7 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum bit_field 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff91a64014e1bc53bf643920f2c9ab5f0980d92a0948295f3ee550e9266849ad"
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
"checksum csv 0.14.7 (registry+https://github.com/rust-lang/crates.io-index)" = "266c1815d7ca63a5bd86284043faf91e8c95e943e55ce05dc0ae08e952de18bc"
"checksum libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)" = "e7eb6b826bfc1fdea7935d46556250d1799b7fe2d9f7951071f4291710665e3e"
"checksum linked_list_allocator 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1d9b8a68289fdacb7242a519f3cf181a3394ebed3bd092ee07ffa2e5c2088afd"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum multiboot2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dcea5906310f2607ea39a42b8af0745dc487d7583db9d981142a63b538647f69"
"checksum num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "98b15ba84e910ea7a1973bccd3df7b31ae282bf9d8bd2897779950c9b8303d40"
"checksum num-bigint 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6d838b16e56da1b6c383d065ff1ec3c7d7797f65a3e8f6ba7092fd87820bac"
"checksum num-complex 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "148eb324ca772230853418731ffdf13531738b50f89b30692a01fcdcb0a64677"
"checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37"
"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e"
"checksum num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "c2dc5ea04020a8f18318ae485c751f8cfa1c0e69dcf465c29ddaaa64a313cc44"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc"
"checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f"
"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03"
"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum raw-cpuid 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13b844e4049605ff38fed943f5c7b2c691fad68d9d5bf074d2720554c4e48246"
"checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c97b18e9e53de541f11e497357d6c5eaeb39f0cb9c8734e274abe4935f6991fa"
"checksum serde_json 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5aaee47e038bf9552d30380d3973fff2593ee0a76d81ad4c581f267cdcadf36"
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
"checksum spin 0.4.5 (git+https://github.com/messense/spin-rs?rev=020f1b3)" = "<none>"
"checksum spin 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7e4deb3c2455c73779e6d3eebceae9599fc70957e54c69fe88f93aa48e62f432"
"checksum volatile 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6633c5250f16598f92b48272265ce9f8179447f702f0ba0cb640c5be6537b0c0"
"checksum x86 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ada1976e1004a0b5999beb7403541af96637e8f439b97d86c8c9abef2e0e7d19"
"checksum x86_64 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73464a8ba159d4fdbfdbea0911c9d06887a4dbbb0f0521742c545f3e11bc8ea4"

+ 1
- 1
Cargo.toml View File

@ -9,7 +9,7 @@ crate-type = ["staticlib"]
[dependencies]
rlibc = "1.0"
volatile = "0.2"
x86 = "0.8"
x86_64 = "0.1.2"
multiboot2 = "0.3.2"
bitflags = "0.9"
linked_list_allocator = "0.4.2"


+ 1
- 1
src/arch/x86_64/device/vga_console.rs View File

@ -4,7 +4,7 @@ use core::fmt;
use core::ptr::Unique;
use spin::Mutex;
use volatile::Volatile;
use x86::shared::io;
use x86::instructions::port as io;
pub static WRITER: Mutex<Writer> = Mutex::new(Writer {
column_pos: 0, row_pos: 0,


+ 2
- 2
src/arch/x86_64/memory/paging/mapper.rs View File

@ -130,9 +130,9 @@ impl Mapper {
let frame = p1[page.p1_index()].pointed_frame().unwrap();
p1[page.p1_index()].set_unused();
use x86::shared::tlb;
use ::x86::instructions::tlb;
unsafe {
tlb::flush(page.start_address());
tlb::flush(::x86::VirtualAddress(page.start_address()));
}
// TODO free p(1,2,3) table if empty


+ 7
- 6
src/arch/x86_64/memory/paging/mod.rs View File

@ -47,13 +47,14 @@ impl ActivePageTable {
/// Executes a closure, with a different page table recursively mapped
pub fn with<F>(&mut self, table: &mut InactivePageTable, scratch_page: &mut TemporaryPage, f: F)
where F: FnOnce(&mut Mapper) {
use x86::shared::{tlb, control_regs};
where F: FnOnce(&mut Mapper) {
use x86::instructions::tlb;
use x86::registers::control_regs;
{
// Backup the original P4 pointer
let backup = Frame::containing_address(
unsafe {control_regs::cr3()}
unsafe {control_regs::cr3().0 as usize}
);
// Map a scratch page to the current p4 table
@ -79,14 +80,14 @@ impl ActivePageTable {
/// Note: We don't need to flush the TLB here, as the CPU automatically flushes
/// the TLB when the P4 table is switched.
pub fn switch(&mut self, new_table: InactivePageTable) -> InactivePageTable {
use x86::shared::{control_regs};
use x86::registers::control_regs;
let old_table = InactivePageTable {
p4_frame: Frame::containing_address(unsafe {control_regs::cr3()}),
p4_frame: Frame::containing_address(unsafe {control_regs::cr3().0 as usize}),
};
unsafe {
control_regs::cr3_write(new_table.p4_frame.start_address());
control_regs::cr3_write(::x86::PhysicalAddress(new_table.p4_frame.start_address() as u64));
}
old_table


+ 3
- 3
src/arch/x86_64/mod.rs View File

@ -6,7 +6,7 @@ pub mod interrupts;
/// Turn on no-execute page protection.
pub fn enable_nxe_bit() {
use x86::shared::msr;
use x86::registers::msr;
const NXE_BIT: u64 = 1<<11;
unsafe {
@ -17,8 +17,8 @@ pub fn enable_nxe_bit() {
/// Turn on page write-protect enforcement.
pub fn enable_wrprot_bit() {
use x86::shared::control_regs::{cr0, cr0_write, CR0_WRITE_PROTECT};
use x86::registers::control_regs::{cr0, cr0_write, Cr0};
unsafe {
cr0_write(cr0() | CR0_WRITE_PROTECT);
cr0_write(cr0() | Cr0::WRITE_PROTECT);
}
}

+ 3
- 3
src/lib.rs View File

@ -19,9 +19,9 @@ extern crate spin;
extern crate volatile;
#[macro_use]
extern crate bitflags;
extern crate x86;
extern crate multiboot2;
extern crate linked_list_allocator;
extern crate x86_64 as x86;
// sparkle-* libs
@ -77,12 +77,12 @@ pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32
println!("!!! PANIC in {} on line {} !!!", file, line);
println!(" {}", fmt);
unsafe{loop{x86::shared::halt();}};
unsafe{loop{x86::instructions::halt();}};
}
/// Stack unwinding. Don't care, just halt.
#[allow(non_snake_case)]
#[no_mangle]
pub extern "C" fn _Unwind_Resume() -> ! {
unsafe{loop{x86::shared::halt();}};
unsafe{loop{x86::instructions::halt();}};
}

Loading…
Cancel
Save