Skip to content

Commit

Permalink
build: Move x86_64 specific code to arch mod
Browse files Browse the repository at this point in the history
This commit introduces `arch` mod for architecture specific code, and
moves x86_64 related code under arch/x86_64. This change is to support
multiple architecture.

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Oct 31, 2022
1 parent 9ad5079 commit 1299c58
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2022 Akira Moroo

#[cfg(target_arch = "x86_64")]
pub mod x86_64;
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2022 Akira Moroo

#[cfg(not(test))]
pub mod asm;
pub mod gdt;
pub mod paging;
pub mod sse;
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions src/arch/x86_64/sse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use x86_64::registers::control::{Cr0, Cr0Flags, Cr4, Cr4Flags};

// Enable SSE2 for XMM registers (needed for EFI calling)
pub fn enable_sse() {
let mut cr0 = Cr0::read();
cr0.remove(Cr0Flags::EMULATE_COPROCESSOR);
cr0.insert(Cr0Flags::MONITOR_COPROCESSOR);
unsafe { Cr0::write(cr0) };
let mut cr4 = Cr4::read();
cr4.insert(Cr4Flags::OSFXSR);
cr4.insert(Cr4Flags::OSXMMEXCPT_ENABLE);
unsafe { Cr4::write(cr4) };
}
30 changes: 6 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,26 @@

use core::panic::PanicInfo;

use x86_64::{
instructions::hlt,
registers::control::{Cr0, Cr0Flags, Cr4, Cr4Flags},
};
use x86_64::instructions::hlt;

#[macro_use]
mod serial;

#[macro_use]
mod common;

#[cfg(not(test))]
mod asm;
mod arch;
mod block;
mod boot;
mod bzimage;
mod coreboot;
mod delay;
mod efi;
mod fat;
mod gdt;
#[cfg(all(test, feature = "integration_tests"))]
mod integration;
mod loader;
mod mem;
mod paging;
mod part;
mod pci;
mod pe;
Expand All @@ -70,18 +64,6 @@ fn panic(_: &PanicInfo) -> ! {
loop {}
}

// Enable SSE2 for XMM registers (needed for EFI calling)
fn enable_sse() {
let mut cr0 = Cr0::read();
cr0.remove(Cr0Flags::EMULATE_COPROCESSOR);
cr0.insert(Cr0Flags::MONITOR_COPROCESSOR);
unsafe { Cr0::write(cr0) };
let mut cr4 = Cr4::read();
cr4.insert(Cr4Flags::OSFXSR);
cr4.insert(Cr4Flags::OSXMMEXCPT_ENABLE);
unsafe { Cr4::write(cr4) };
}

const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4;
const VIRTIO_PCI_BLOCK_DEVICE_ID: u16 = 0x1042;

Expand Down Expand Up @@ -150,8 +132,8 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice, info: &dyn boot::Info
pub extern "C" fn rust64_start(rdi: &pvh::StartInfo) -> ! {
serial::PORT.borrow_mut().init();

enable_sse();
paging::setup();
arch::x86_64::sse::enable_sse();
arch::x86_64::paging::setup();

main(rdi)
}
Expand All @@ -161,8 +143,8 @@ pub extern "C" fn rust64_start(rdi: &pvh::StartInfo) -> ! {
pub extern "C" fn rust64_start() -> ! {
serial::PORT.borrow_mut().init();

enable_sse();
paging::setup();
arch::x86_64::sse::enable_sse();
arch::x86_64::paging::setup();

let info = coreboot::StartInfo::default();

Expand Down

0 comments on commit 1299c58

Please sign in to comment.