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

Add a Cargo Feature for Enabling SSE #77

Merged
merged 11 commits into from
Sep 21, 2019
Merged
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ xmas-elf = { version = "0.6.2", optional = true }
x86_64 = { version = "0.7.2", optional = true }
usize_conversions = { version = "0.2.0", optional = true }
fixedvec = { version = "0.2.4", optional = true }
bit_field = { version = "0.10.0", optional = true }

[dependencies.font8x8]
version = "0.2.4"
Expand All @@ -34,6 +35,7 @@ binary = ["xmas-elf", "x86_64", "usize_conversions", "fixedvec", "llvm-tools", "
vga_320x200 = ["font8x8"]
recursive_page_table = []
map_physical_memory = []
sse = ["bit_field"]

[profile.dev]
panic = "abort"
Expand Down
5 changes: 5 additions & 0 deletions example-kernel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example-kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub extern "C" fn _start() -> ! {
// named `_start` by default

let vga_buffer = 0xb8000 as *mut u8;

// print `HELLO` to the screen (see
// https://os.phil-opp.com/minimal-rust-kernel/#printing-to-screen)
for (i, &byte) in HELLO.iter().enumerate() {
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ mod frame_allocator;
mod level4_entries;
mod page_table;
mod printer;
#[cfg(feature = "sse")]
mod sse;

pub struct IdentityMappedAddr(PhysAddr);

Expand Down Expand Up @@ -142,6 +144,10 @@ fn load_elf(
// Extract required information from the ELF file.
let mut preallocated_space = alloc_stack!([ProgramHeader64; 32]);
let mut segments = FixedVec::new(&mut preallocated_space);
#[cfg(feature = "sse")]
{
sse::enable_sse();
}
let entry_point;
{
let kernel_start_ptr = usize_from(kernel_start.as_u64()) as *const u8;
Expand Down
24 changes: 24 additions & 0 deletions src/sse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Enables Streaming SIMD Extensions (SSE) support for loaded kernels.
#[cfg(feature = "sse")]
pub fn enable_sse() {
use bit_field::BitField;
use x86_64::registers::control::Cr0;
let mut flags = Cr0::read_raw();
flags.set_bit(2, false);
flags.set_bit(1, true);
flags.set_bit(9, true);
flags.set_bit(10, true);
unsafe {
Cr0::write_raw(flags);
}
// For now, we must use inline ASM here
let mut cr4: u64;
unsafe {
asm!("mov %cr4, $0" : "=r" (cr4));
}
cr4.set_bit(9, true);
cr4.set_bit(10, true);
unsafe {
asm!("mov $0, %cr4" :: "r" (cr4) : "memory");
}
}
1 change: 0 additions & 1 deletion src/stage_2.s
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ enter_protected_mode_again:
mov eax, cr0
or al, 1 # set protected mode bit
mov cr0, eax

push 0x8
lea eax, [stage_3]
push eax
Expand Down
5 changes: 5 additions & 0 deletions test-kernel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.