Use target_arch instead of features

This commit is contained in:
Yuke Peng 2023-03-29 00:42:49 -07:00 committed by Tate, Hongliang Tian
parent e0c0fc7937
commit fbcfbe19d1
13 changed files with 33 additions and 28 deletions

10
.vscode/settings.json vendored
View File

@ -1,4 +1,10 @@
{
"rust-analyzer.cargo.target" : "x86_64-unknown-none",
"rust-analyzer.check.extraArgs" : ["--target","x86_64-custom.json","-Zbuild-std=core,alloc,compiler_builtins","-Zbuild-std-features=compiler-builtins-mem"]
"rust-analyzer.check.allTargets": false,
"rust-analyzer.cargo.target": "x86_64-custom.json",
"rust-analyzer.check.extraArgs": [
"--target",
"x86_64-custom.json",
"-Zbuild-std=core,alloc,compiler_builtins",
"-Zbuild-std-features=compiler-builtins-mem"
]
}

View File

@ -18,11 +18,10 @@ log = "0.4"
lazy_static = { version = "1.0", features = ["spin_no_std"] }
trapframe = { git = "https://github.com/sdww0/trapframe-rs", rev = "94fc010" }
limine = { version = "0.1.10", features = ["into-uuid"], optional = true }
x86_64 = { version = "0.14.2", optional = true }
x86 = { version = "0.52.0", optional = true }
acpi = { version = "4.1.1", optional = true }
[target.x86_64-custom.dependencies]
limine = { version = "0.1.10", features = ["into-uuid"] }
x86_64 = "0.14.2"
x86 = "0.52.0"
acpi = "4.1.1"
[features]
default = ["x86_64"]
x86_64 = ["dep:x86_64", "dep:x86", "dep:limine", "dep:acpi"]

View File

@ -1,20 +1,20 @@
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
pub mod x86;
/// Call before all the resources have been initialized
pub(crate) fn before_all_init() {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
x86::before_all_init();
}
/// Call after all the resources have been initialized
pub(crate) fn after_all_init() {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
x86::after_all_init();
}
#[inline]
pub(crate) fn interrupts_ack() {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
x86::interrupts_ack();
}

View File

@ -1,7 +1,7 @@
//! CPU.
cfg_if::cfg_if! {
if #[cfg(feature="x86_64")]{
if #[cfg(target_arch = "x86_64")]{
pub use crate::arch::x86::cpu::CpuContext;
pub use crate::arch::x86::cpu::FpRegs;
pub use crate::arch::x86::cpu::TrapInformation;

View File

@ -33,7 +33,7 @@ pub use self::error::Error;
pub use self::prelude::Result;
use alloc::vec::Vec;
use core::{mem, panic::PanicInfo};
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
pub use limine::{LimineFramebufferRequest, LimineModuleRequest};
use trap::{IrqCallbackHandle, IrqLine};
use trapframe::TrapFrame;

View File

@ -4,7 +4,7 @@ use core::sync::atomic::{
Ordering::{Acquire, Relaxed, Release},
};
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
use crate::arch::x86::cpu;
use crate::prelude::*;
use crate::sync::AtomicBits;

View File

@ -1,6 +1,6 @@
//! Timer.
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
use crate::arch::x86::timer::{add_timeout_list, TimerCallback, TICK};
use crate::{config::TIMER_FREQ, prelude::*};
use core::time::Duration;

View File

@ -1,9 +1,7 @@
//! User space.
use trapframe::UserContext;
cfg_if::cfg_if! {
if #[cfg(feature="x86_64")]{
if #[cfg(target_arch = "x86_64")]{
use crate::arch::x86::cpu::CpuContext;
}
}

View File

@ -57,7 +57,7 @@ pub fn alloc_with_paddr(paddr: Paddr) -> Option<VmFrame> {
/// Check if the physical address in range is valid
fn is_paddr_valid(range: Range<usize>) -> bool {
// special area in x86
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
if range.start >= 0xFE00_0000 && range.end <= 0xFFFF_FFFF {
return true;
}

View File

@ -82,7 +82,7 @@ pub static FRAMEBUFFER_REGIONS: Once<Vec<MemoryRegions>> = Once::new();
pub(crate) fn init() {
heap_allocator::init();
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
let memory_regions = crate::arch::x86::mm::get_memory_regions();
let mut framebuffer_regions = Vec::new();

View File

@ -219,7 +219,7 @@ fn next_table_or_create<'a>(
/// translate a virtual address to physical address which cannot use offset to get physical address
pub fn vaddr_to_paddr(virtual_address: Vaddr) -> Option<Paddr> {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
let (page_directory_base, _) = x86_64::registers::control::Cr3::read();
let page_directory_base = page_directory_base.start_address().as_u64() as usize;
@ -239,7 +239,7 @@ pub fn vaddr_to_paddr(virtual_address: Vaddr) -> Option<Paddr> {
}
pub(crate) fn init() {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
let (page_directory_base, _) = x86_64::registers::control::Cr3::read();
let page_directory_base = page_directory_base.start_address().as_u64() as usize;

View File

@ -37,7 +37,7 @@ impl VmSpace {
}
/// Activate the page table, load root physical address to cr3
pub unsafe fn activate(&self) {
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
crate::arch::x86::mm::activate_page_table(
self.memory_set.lock().pt.root_pa,
x86_64::registers::control::Cr3Flags::PAGE_LEVEL_CACHE_DISABLE,
@ -91,7 +91,7 @@ impl VmSpace {
/// clear all mappings
pub fn clear(&self) {
self.memory_set.lock().clear();
#[cfg(feature = "x86_64")]
#[cfg(target_arch = "x86_64")]
x86_64::instructions::tlb::flush_all();
}

View File

@ -1,6 +1,8 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"code-model": "kernel",
"cpu": "x86-64",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
@ -16,5 +18,5 @@
},
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float"
}
"features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float"
}