feat: la64 boot (#1132)

* la64能够进入到kernel_main
* ci: 添加为ubuntu编译qemu-loongarch64的脚本
* feat: la64能输出hello world
* la64 安装gcc && 配置github ci
* chore: 更新CI工作流和构建脚本中的Docker镜像版本至v1.10

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin
2025-04-20 18:51:45 +08:00
committed by GitHub
parent 167d272792
commit e80796eb82
91 changed files with 2299 additions and 118 deletions

View File

@ -0,0 +1,10 @@
use super::BindgenArch;
pub struct LoongArch64BindgenArch;
impl BindgenArch for LoongArch64BindgenArch {
fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder {
builder
.clang_arg("-I./src/arch/loongarch64/include")
.clang_arg("--target=x86_64-none-none") // 由于clang不支持loongarch64所以使用x86_64作为目标按理来说问题不大
}
}

View File

@ -0,0 +1,29 @@
use std::{collections::HashSet, path::PathBuf};
use crate::constant::ARCH_DIR_LOONGARCH64;
use super::CFilesArch;
pub(super) struct LoongArch64CFilesArch;
impl CFilesArch for LoongArch64CFilesArch {
fn setup_defines(&self, c: &mut cc::Build) {
c.define("__loongarch64__", None);
c.define("__loongarch", None);
}
fn setup_files(&self, _c: &mut cc::Build, _files: &mut HashSet<PathBuf>) {}
fn setup_global_flags(&self, c: &mut cc::Build) {
// 在这里设置编译器不然的话vscode的rust-analyzer会报错
c.compiler("loongarch64-unknown-linux-gnu-gcc");
c.flag("-mcmodel=normal");
c.flag("-march=loongarch64");
}
}
#[allow(dead_code)]
fn arch_path(relative_path: &str) -> PathBuf {
PathBuf::from(format!("{}/{}", ARCH_DIR_LOONGARCH64, relative_path))
}

View File

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

View File

@ -0,0 +1,5 @@
#[allow(dead_code)]
pub const ARCH_DIR_X86_64: &str = "src/arch/x86_64";
#[allow(dead_code)]
pub const ARCH_DIR_RISCV64: &str = "src/arch/riscv64";
pub const ARCH_DIR_LOONGARCH64: &str = "src/arch/loongarch64";

View File

@ -3,6 +3,7 @@ extern crate lazy_static;
extern crate cc;
mod cfiles;
mod constant;
mod kconfig;
mod utils;

View File

@ -68,6 +68,7 @@ pub enum TargetArch {
Riscv64,
Mips64,
Powerpc64,
LoongArch64,
S390x,
Sparc64,
Unknown,
@ -85,6 +86,7 @@ impl TargetArch {
"riscv64" => TargetArch::Riscv64,
"mips64" => TargetArch::Mips64,
"powerpc64" => TargetArch::Powerpc64,
"loongarch64" => TargetArch::LoongArch64,
"s390x" => TargetArch::S390x,
"sparc64" => TargetArch::Sparc64,
_ => TargetArch::Unknown,

View File

@ -1 +1,51 @@
use std::path::PathBuf;
pub mod cargo_handler;
#[allow(dead_code)]
pub struct FileUtils;
#[allow(dead_code)]
impl FileUtils {
/// 列出指定目录下的所有文件
///
/// ## 参数
///
/// - `path` - 指定的目录
/// - `ext_name` - 文件的扩展名如果为None则列出所有文件
/// - `recursive` - 是否递归列出所有文件
pub fn list_all_files(path: &PathBuf, ext_name: Option<&str>, recursive: bool) -> Vec<PathBuf> {
let mut queue: Vec<PathBuf> = Vec::new();
let mut result = Vec::new();
queue.push(path.clone());
while !queue.is_empty() {
let path = queue.pop().unwrap();
let d = std::fs::read_dir(path);
if d.is_err() {
continue;
}
let d = d.unwrap();
d.for_each(|ent| {
if let Ok(ent) = ent {
if let Ok(file_type) = ent.file_type() {
if file_type.is_file() {
if let Some(e) = ext_name {
if let Some(ext) = ent.path().extension() {
if ext == e {
result.push(ent.path());
}
}
}
} else if file_type.is_dir() && recursive {
queue.push(ent.path());
}
}
}
});
}
return result;
}
}