使得DragonOS kernel 能为riscv64编译通过(尚未能启动) (#457)

* 使得DragonOS kernel 能为riscv64编译通过(尚未能启动)

* 修正了系统调用号声明不正确的问题,同时添加了编译配置文档
This commit is contained in:
LoGin
2023-11-25 12:07:39 +08:00
committed by GitHub
parent a1fd1cf1cb
commit 4fda81ce81
112 changed files with 2587 additions and 615 deletions

View File

@ -2,6 +2,7 @@ use crate::utils::cargo_handler::{CargoHandler, TargetArch};
use self::x86_64::X86_64BindgenArch;
pub mod riscv64;
pub mod x86_64;
pub(super) trait BindgenArch {
@ -13,6 +14,7 @@ pub(super) fn current_bindgenarch() -> &'static dyn BindgenArch {
let arch = CargoHandler::target_arch();
match arch {
TargetArch::X86_64 => &X86_64BindgenArch,
TargetArch::Riscv64 => &riscv64::RiscV64BindgenArch,
_ => panic!("Unsupported arch: {:?}", arch),
}
}

View File

@ -0,0 +1,10 @@
use super::BindgenArch;
pub struct RiscV64BindgenArch;
impl BindgenArch for RiscV64BindgenArch {
fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder {
builder
.clang_arg("-I./src/arch/riscv64/include")
.clang_arg("--target=riscv64-none-none-elf")
}
}

View File

@ -6,6 +6,7 @@ use crate::utils::cargo_handler::{CargoHandler, TargetArch};
use self::x86_64::X86_64CFilesArch;
pub mod riscv64;
pub mod x86_64;
pub(super) trait CFilesArch {
@ -25,6 +26,7 @@ pub(super) fn current_cfiles_arch() -> &'static dyn CFilesArch {
let arch = CargoHandler::target_arch();
match arch {
TargetArch::X86_64 => &X86_64CFilesArch,
TargetArch::Riscv64 => &riscv64::RiscV64CFilesArch,
_ => panic!("Unsupported arch: {:?}", arch),
}
}

View File

@ -0,0 +1,41 @@
use std::path::PathBuf;
use crate::{constant::ARCH_DIR_RISCV64, utils::FileUtils};
use super::CFilesArch;
pub(super) struct RiscV64CFilesArch;
impl CFilesArch for RiscV64CFilesArch {
fn setup_defines(&self, c: &mut cc::Build) {
c.define("__riscv64__", None);
c.define("__riscv", None);
}
fn setup_global_include_dir(&self, c: &mut cc::Build) {
c.include("src/arch/riscv64/include");
}
fn setup_files(&self, _c: &mut cc::Build, files: &mut Vec<std::path::PathBuf>) {
files.push(PathBuf::from("src/arch/riscv64/boot/head.S"));
files.append(&mut FileUtils::list_all_files(
&arch_path("asm"),
Some("c"),
true,
));
}
fn setup_global_flags(&self, c: &mut cc::Build) {
// 在这里设置编译器不然的话vscode的rust-analyzer会报错
c.compiler("riscv64-unknown-elf-gcc");
// // c.flag("-march=rv64imafdc");
// c.no_default_flags(true);
c.flag("-mcmodel=medany");
c.flag("-mabi=lp64");
c.flag("-march=rv64imac");
}
}
fn arch_path(relative_path: &str) -> PathBuf {
PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path))
}

View File

@ -50,6 +50,7 @@ impl CFilesArch for X86_64CFilesArch {
fn setup_global_flags(&self, c: &mut Build) {
c.asm_flag("-m64");
c.flag("-mcmodel=large").flag("-m64");
}
}

View File

@ -23,14 +23,12 @@ impl CFilesBuilder {
}
fn setup_global_flags(c: &mut Build) {
c.flag("-mcmodel=large")
.flag("-fno-builtin")
c.flag("-fno-builtin")
.flag("-nostdlib")
.flag("-fno-stack-protector")
.flag("-fno-pie")
.flag("-Wno-expansion-to-defined")
.flag("-Wno-unused-parameter")
.flag("-m64")
.flag("-O1");
// set Arch-specific flags

View File

@ -1 +1,2 @@
pub const ARCH_DIR_X86_64: &str = "src/arch/x86_64";
pub const ARCH_DIR_RISCV64: &str = "src/arch/riscv64";