Skip to content

Commit

Permalink
SSE and AVX support (#77)
Browse files Browse the repository at this point in the history
* The bootloader now implements SSE and AVX support and enables AVX if found.

* Rewrote SSE code in rust using inline ASM and made SSE and AVX features.

* Deleted SSE assembly and formatted code.

* Aded a use statement to fix a compile error.

* Removed AVX support.

* Tested SSE support and formatted code.

* Formatted code and ensured that the bootloader *actually* built.

* Got SSE t ofinally work (haven't committed in a while because of lack of time)

* Aded bit_field dependency. Formatted code.

* Moved SSE into its own module. Made deps for SSE entirely optional. Removed botloader dep from test kernel.

* Added function call to enable SSE if SSE feature is enabled
  • Loading branch information
ethindp authored and phil-opp committed Sep 21, 2019
1 parent c6f5783 commit 537fc71
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 2 deletions.
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.

0 comments on commit 537fc71

Please sign in to comment.