forked from rcore-os/zCore
Merge crates zircon-loader and linux-loader into one crate
This commit is contained in:
parent
91d57d4409
commit
78322d6f31
|
@ -69,7 +69,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
use-cross: true
|
use-cross: true
|
||||||
args: --target aarch64-unknown-linux-gnu --workspace --exclude linux-syscall --exclude linux-loader --exclude zcore
|
args: --target aarch64-unknown-linux-gnu --workspace --exclude linux-syscall --exclude zcore-loader --exclude zcore
|
||||||
|
|
||||||
build-user:
|
build-user:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
|
@ -15,10 +15,11 @@ jobs:
|
||||||
cat >target/doc/index.html <<EOF
|
cat >target/doc/index.html <<EOF
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<noscript><meta http-equiv="refresh" content="0; url=kernel_hal/index.html"></noscript>
|
<meta http-equiv="refresh" content="0;URL=kernel_hal/index.html">
|
||||||
|
<title>Redirection</title>
|
||||||
</head>
|
</head>
|
||||||
<body onload="window.location = 'kernel_hal/index.html'">
|
<body onload="window.location = 'kernel_hal/index.html'">
|
||||||
<a href="kernel_hal/index.html">look here</a>
|
<p>Redirecting to <a href="kernel_hal/index.html">kernel_hal/index.html</a>...</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
"drivers",
|
||||||
|
"kernel-hal",
|
||||||
"zircon-object",
|
"zircon-object",
|
||||||
"zircon-syscall",
|
"zircon-syscall",
|
||||||
"zircon-loader",
|
|
||||||
"linux-object",
|
"linux-object",
|
||||||
"linux-syscall",
|
"linux-syscall",
|
||||||
"linux-loader",
|
"loader",
|
||||||
"kernel-hal",
|
|
||||||
"drivers",
|
|
||||||
"zCore",
|
"zCore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ cfg_if::cfg_if! {
|
||||||
mod riscv_intc;
|
mod riscv_intc;
|
||||||
mod riscv_plic;
|
mod riscv_plic;
|
||||||
|
|
||||||
|
#[doc(cfg(any(target_arch = "riscv32", target_arch = "riscv64")))]
|
||||||
pub mod riscv {
|
pub mod riscv {
|
||||||
pub use super::riscv_intc::{Intc, ScauseIntCode};
|
pub use super::riscv_intc::{Intc, ScauseIntCode};
|
||||||
pub use super::riscv_plic::Plic;
|
pub use super::riscv_plic::Plic;
|
||||||
|
@ -10,6 +11,7 @@ cfg_if::cfg_if! {
|
||||||
} else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
|
} else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
|
||||||
mod x86_apic;
|
mod x86_apic;
|
||||||
|
|
||||||
|
#[doc(cfg(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||||
pub mod x86 {
|
pub mod x86 {
|
||||||
pub use super::x86_apic::Apic;
|
pub use super::x86_apic::Apic;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![cfg_attr(not(feature = "mock"), no_std)]
|
#![cfg_attr(not(feature = "mock"), no_std)]
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
#![feature(doc_cfg)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
@ -9,10 +10,12 @@ extern crate log;
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(any(feature = "mock", doc))]
|
||||||
|
#[doc(cfg(feature = "mock"))]
|
||||||
pub mod mock;
|
pub mod mock;
|
||||||
|
|
||||||
#[cfg(feature = "virtio")]
|
#[cfg(any(feature = "virtio", doc))]
|
||||||
|
#[doc(cfg(feature = "virtio"))]
|
||||||
pub mod virtio;
|
pub mod virtio;
|
||||||
|
|
||||||
pub mod builder;
|
pub mod builder;
|
||||||
|
|
|
@ -2,5 +2,6 @@ pub mod display;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod uart;
|
pub mod uart;
|
||||||
|
|
||||||
#[cfg(feature = "graphic")]
|
#[cfg(any(feature = "graphic", doc))]
|
||||||
|
#[doc(cfg(feature = "graphic"))]
|
||||||
pub mod graphic;
|
pub mod graphic;
|
||||||
|
|
|
@ -8,7 +8,7 @@ hal_fn_def! {
|
||||||
/// Bootstrap and initialization.
|
/// Bootstrap and initialization.
|
||||||
pub mod boot {
|
pub mod boot {
|
||||||
/// The kernel command line.
|
/// The kernel command line.
|
||||||
pub fn cmdline() -> String { "".into() }
|
pub fn cmdline() -> String { String::new() }
|
||||||
|
|
||||||
/// Returns the slice of the initial RAM disk, or `None` if not exist.
|
/// Returns the slice of the initial RAM disk, or `None` if not exist.
|
||||||
pub fn init_ram_disk() -> Option<&'static mut [u8]> {
|
pub fn init_ram_disk() -> Option<&'static mut [u8]> {
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "linux-loader"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Runji Wang <wangrunji0408@163.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
description = "Linux programs loader and runner."
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
log = "0.4"
|
|
||||||
linux-syscall = { path = "../linux-syscall" }
|
|
||||||
linux-object = { path = "../linux-object" }
|
|
||||||
zircon-object = { path = "../zircon-object" }
|
|
||||||
kernel-hal = { path = "../kernel-hal", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["libos"]
|
|
||||||
libos = ["kernel-hal/libos", "zircon-object/aspace-separate"]
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
env_logger = "0.9"
|
|
||||||
async-std = { version = "1.10", features = ["attributes"] }
|
|
||||||
rcore-fs-hostfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec" }
|
|
|
@ -28,7 +28,7 @@ impl LinuxElfLoader {
|
||||||
&self,
|
&self,
|
||||||
vmar: &Arc<VmAddressRegion>,
|
vmar: &Arc<VmAddressRegion>,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
mut args: Vec<String>,
|
args: Vec<String>,
|
||||||
envs: Vec<String>,
|
envs: Vec<String>,
|
||||||
path: String,
|
path: String,
|
||||||
) -> LxResult<(VirtAddr, VirtAddr)> {
|
) -> LxResult<(VirtAddr, VirtAddr)> {
|
||||||
|
@ -45,12 +45,12 @@ impl LinuxElfLoader {
|
||||||
debug!("elf info: {:#x?}", elf.header.pt2);
|
debug!("elf info: {:#x?}", elf.header.pt2);
|
||||||
|
|
||||||
if let Ok(interp) = elf.get_interpreter() {
|
if let Ok(interp) = elf.get_interpreter() {
|
||||||
info!("interp: {:?}", interp);
|
info!("interp: {:?}, path: {:?}", interp, path);
|
||||||
let inode = self.root_inode.lookup(interp)?;
|
let inode = self.root_inode.lookup(interp)?;
|
||||||
let data = inode.read_as_vec()?;
|
let data = inode.read_as_vec()?;
|
||||||
args[0] = path.clone();
|
let mut new_args = vec![interp.into(), path.clone()];
|
||||||
args.insert(0, interp.into());
|
new_args.extend_from_slice(&args[1..]);
|
||||||
return self.load(vmar, &data, args, envs, path);
|
return self.load(vmar, &data, new_args, envs, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = elf.load_segment_size();
|
let size = elf.load_segment_size();
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
//! Linux syscall implementations
|
//! Linux syscall implementations
|
||||||
//!
|
//!
|
||||||
//! ## Example
|
//! ## Example
|
||||||
//! the syscall is called like this in the linux-loader:
|
//! The syscall is called like this in the [`zcore_loader`](../zcore_loader/index.html):
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! let num = regs.rax as u32;
|
//! let num = regs.rax as u32;
|
||||||
//! let args = [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9];
|
//! let args = [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9];
|
||||||
//! let mut syscall = Syscall {
|
//! let mut syscall = Syscall {
|
||||||
//! thread,
|
//! thread,
|
||||||
//! #[cfg(feature = "libos")]
|
|
||||||
//! syscall_entry: kernel_hal::context::syscall_entry as usize,
|
//! syscall_entry: kernel_hal::context::syscall_entry as usize,
|
||||||
//! #[cfg(not(feature = "libos"))]
|
|
||||||
//! syscall_entry: 0,
|
|
||||||
//! thread_fn,
|
//! thread_fn,
|
||||||
//! regs,
|
//! regs,
|
||||||
//! };
|
//! };
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
[package]
|
||||||
|
name = "zcore-loader"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Runji Wang <wangrunji0408@163.com>", "Yuekai Jia <equation618@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
description = "Linux and Zircon user programs loader and runner."
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4"
|
||||||
|
cfg-if = "1.0"
|
||||||
|
xmas-elf = { version = "0.7", optional = true }
|
||||||
|
kernel-hal = { path = "../kernel-hal", default-features = false }
|
||||||
|
zircon-object = { path = "../zircon-object", features = ["elf"] }
|
||||||
|
linux-object = { path = "../linux-object", optional = true }
|
||||||
|
zircon-syscall = { path = "../zircon-syscall", optional = true }
|
||||||
|
linux-syscall = { path = "../linux-syscall", optional = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["libos", "linux", "zircon"]
|
||||||
|
linux = ["linux-object", "linux-syscall"]
|
||||||
|
zircon = ["zircon-syscall", "xmas-elf"]
|
||||||
|
libos = ["kernel-hal/libos", "zircon-object/aspace-separate"]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
env_logger = "0.9"
|
||||||
|
async-std = { version = "1.10", features = ["attributes"] }
|
||||||
|
rcore-fs-hostfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec" }
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "linux-libos"
|
||||||
|
required-features = ["linux", "libos"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "zircon-libos"
|
||||||
|
required-features = ["zircon", "libos"]
|
|
@ -6,12 +6,17 @@ async fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
kernel_hal::init();
|
kernel_hal::init();
|
||||||
|
|
||||||
let args = env::args().skip(1).collect();
|
let args = std::env::args().collect::<Vec<_>>();
|
||||||
|
if args.len() < 2 {
|
||||||
|
println!("Usage: {} PROGRAM", args[0]);
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
|
let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
|
||||||
let rootfs_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../rootfs");
|
let rootfs_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../rootfs");
|
||||||
let hostfs = rcore_fs_hostfs::HostFS::new(rootfs_path);
|
let hostfs = rcore_fs_hostfs::HostFS::new(rootfs_path);
|
||||||
|
|
||||||
let proc = linux_loader::run(args, envs, hostfs);
|
let proc = zcore_loader::linux::run(args[1..].to_vec(), envs, hostfs);
|
||||||
let code = proc.wait_for_exit().await;
|
let code = proc.wait_for_exit().await;
|
||||||
std::process::exit(code as i32);
|
std::process::exit(code as i32);
|
||||||
}
|
}
|
|
@ -13,8 +13,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let zbi = std::fs::read(&args[1]).expect("failed to read zbi file");
|
let zbi = std::fs::read(&args[1]).expect("failed to read zbi file");
|
||||||
let cmdline = args.get(2).map(String::as_str).unwrap_or("");
|
let cmdline = args.get(2).map(String::as_str).unwrap_or_default();
|
||||||
|
|
||||||
let proc: Arc<dyn KernelObject> = zircon_loader::run_userboot(zbi, cmdline);
|
let proc: Arc<dyn KernelObject> = zcore_loader::zircon::run_userboot(zbi, cmdline);
|
||||||
proc.wait_signal(Signal::USER_SIGNAL_0).await;
|
proc.wait_signal(Signal::USER_SIGNAL_0).await;
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
//! Linux and Zircon user programs loader and runner.
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
#![feature(asm)]
|
||||||
|
#![feature(doc_cfg)]
|
||||||
|
#![deny(warnings, unused_must_use, missing_docs)]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(any(feature = "linux", doc))] {
|
||||||
|
#[doc(cfg(feature = "linux"))]
|
||||||
|
pub mod linux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(any(feature = "zircon", doc))] {
|
||||||
|
mod kcounter;
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "zircon"))]
|
||||||
|
pub mod zircon;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,4 @@
|
||||||
//! Linux LibOS
|
//! Run Linux process and manage trap/interrupt/syscall.
|
||||||
//! - run process and manage trap/interrupt/syscall
|
|
||||||
#![no_std]
|
|
||||||
#![feature(asm)]
|
|
||||||
#![deny(warnings, unused_must_use, missing_docs)]
|
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
alloc::{boxed::Box, string::String, sync::Arc, vec::Vec},
|
alloc::{boxed::Box, string::String, sync::Arc, vec::Vec},
|
|
@ -1,11 +1,4 @@
|
||||||
#![no_std]
|
//! Run Zircon user program (userboot) and manage trap/interrupt/syscall.
|
||||||
#![feature(asm)]
|
|
||||||
#![deny(warnings, unused_must_use)]
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate alloc;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
alloc::{boxed::Box, sync::Arc, vec::Vec},
|
alloc::{boxed::Box, sync::Arc, vec::Vec},
|
||||||
|
@ -15,8 +8,6 @@ use {
|
||||||
zircon_syscall::Syscall,
|
zircon_syscall::Syscall,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod kcounter;
|
|
||||||
|
|
||||||
// These describe userboot itself
|
// These describe userboot itself
|
||||||
const K_PROC_SELF: usize = 0;
|
const K_PROC_SELF: usize = 0;
|
||||||
const K_VMARROOT_SELF: usize = 1;
|
const K_VMARROOT_SELF: usize = 1;
|
||||||
|
@ -32,13 +23,13 @@ const K_COUNTERS: usize = 10;
|
||||||
const K_FISTINSTRUMENTATIONDATA: usize = 11;
|
const K_FISTINSTRUMENTATIONDATA: usize = 11;
|
||||||
const K_HANDLECOUNT: usize = 15;
|
const K_HANDLECOUNT: usize = 15;
|
||||||
|
|
||||||
macro_rules! boot_firmware {
|
macro_rules! boot_library {
|
||||||
($name: expr) => {{
|
($name: expr) => {{
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(target_arch = "x86_64")] {
|
if #[cfg(target_arch = "x86_64")] {
|
||||||
boot_firmware!($name, "../../prebuilt/zircon/x64")
|
boot_library!($name, "../../prebuilt/zircon/x64")
|
||||||
} else if #[cfg(target_arch = "aarch64")] {
|
} else if #[cfg(target_arch = "aarch64")] {
|
||||||
boot_firmware!($name, "../../prebuilt/zircon/arm64")
|
boot_library!($name, "../../prebuilt/zircon/arm64")
|
||||||
} else {
|
} else {
|
||||||
compile_error!("Unsupported architecture for zircon mode!")
|
compile_error!("Unsupported architecture for zircon mode!")
|
||||||
}
|
}
|
||||||
|
@ -56,9 +47,10 @@ macro_rules! boot_firmware {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run Zircon `userboot` process from the prebuilt path, and load the ZBI file as the bootfs.
|
||||||
pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc<Process> {
|
pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc<Process> {
|
||||||
let userboot = boot_firmware!("userboot");
|
let userboot = boot_library!("userboot");
|
||||||
let vdso = boot_firmware!("libzircon");
|
let vdso = boot_library!("libzircon");
|
||||||
|
|
||||||
let job = Job::root();
|
let job = Job::root();
|
||||||
let proc = Process::create(&job, "userboot").unwrap();
|
let proc = Process::create(&job, "userboot").unwrap();
|
||||||
|
@ -137,7 +129,7 @@ pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc<Process> {
|
||||||
let (user_channel, kernel_channel) = Channel::create();
|
let (user_channel, kernel_channel) = Channel::create();
|
||||||
let handle = Handle::new(user_channel, Rights::DEFAULT_CHANNEL);
|
let handle = Handle::new(user_channel, Rights::DEFAULT_CHANNEL);
|
||||||
|
|
||||||
let mut handles = vec![Handle::new(proc.clone(), Rights::empty()); K_HANDLECOUNT];
|
let mut handles = alloc::vec![Handle::new(proc.clone(), Rights::empty()); K_HANDLECOUNT];
|
||||||
handles[K_PROC_SELF] = Handle::new(proc.clone(), Rights::DEFAULT_PROCESS);
|
handles[K_PROC_SELF] = Handle::new(proc.clone(), Rights::DEFAULT_PROCESS);
|
||||||
handles[K_VMARROOT_SELF] = Handle::new(proc.vmar(), Rights::DEFAULT_VMAR | Rights::IO);
|
handles[K_VMARROOT_SELF] = Handle::new(proc.vmar(), Rights::DEFAULT_VMAR | Rights::IO);
|
||||||
handles[K_ROOTJOB] = Handle::new(job, Rights::DEFAULT_JOB);
|
handles[K_ROOTJOB] = Handle::new(job, Rights::DEFAULT_JOB);
|
||||||
|
@ -161,7 +153,7 @@ pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc<Process> {
|
||||||
let crash_log_vmo = VmObject::new_paged(1);
|
let crash_log_vmo = VmObject::new_paged(1);
|
||||||
crash_log_vmo.set_name("crashlog");
|
crash_log_vmo.set_name("crashlog");
|
||||||
handles[K_CRASHLOG] = Handle::new(crash_log_vmo, Rights::DEFAULT_VMO);
|
handles[K_CRASHLOG] = Handle::new(crash_log_vmo, Rights::DEFAULT_VMO);
|
||||||
let (counter_name_vmo, kcounters_vmo) = kcounter::create_kcounter_vmo();
|
let (counter_name_vmo, kcounters_vmo) = super::kcounter::create_kcounter_vmo();
|
||||||
handles[K_COUNTERNAMES] = Handle::new(counter_name_vmo, Rights::DEFAULT_VMO);
|
handles[K_COUNTERNAMES] = Handle::new(counter_name_vmo, Rights::DEFAULT_VMO);
|
||||||
handles[K_COUNTERS] = Handle::new(kcounters_vmo, Rights::DEFAULT_VMO);
|
handles[K_COUNTERS] = Handle::new(kcounters_vmo, Rights::DEFAULT_VMO);
|
||||||
// TODO: use correct Instrumentation data handle
|
// TODO: use correct Instrumentation data handle
|
|
@ -1,5 +1,3 @@
|
||||||
//! Linux LibOS entrance
|
|
||||||
|
|
||||||
use rcore_fs_hostfs::HostFS;
|
use rcore_fs_hostfs::HostFS;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
@ -10,7 +8,7 @@ async fn test(cmdline: &str) -> i64 {
|
||||||
let args: Vec<String> = cmdline.split(' ').map(|s| s.into()).collect();
|
let args: Vec<String> = cmdline.split(' ').map(|s| s.into()).collect();
|
||||||
let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()]; // TODO
|
let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()]; // TODO
|
||||||
let hostfs = HostFS::new("../rootfs");
|
let hostfs = HostFS::new("../rootfs");
|
||||||
let proc = linux_loader::run(args, envs, hostfs);
|
let proc = zcore_loader::linux::run(args, envs, hostfs);
|
||||||
proc.wait_for_exit().await
|
proc.wait_for_exit().await
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
async fn userboot() {
|
async fn userboot() {
|
||||||
kernel_hal::init();
|
kernel_hal::init();
|
||||||
let zbi = std::fs::read("../prebuilt/zircon/x64/bringup.zbi").expect("failed to read zbi file");
|
let zbi = std::fs::read("../prebuilt/zircon/x64/bringup.zbi").expect("failed to read zbi file");
|
||||||
let proc = zircon_loader::run_userboot(zbi, "");
|
let proc = zcore_loader::zircon::run_userboot(zbi, "");
|
||||||
proc.wait_for_exit().await;
|
proc.wait_for_exit().await;
|
||||||
}
|
}
|
|
@ -73,4 +73,4 @@ if check_failed:
|
||||||
else:
|
else:
|
||||||
print(colored('All checked case passed!', 'green'))
|
print(colored('All checked case passed!', 'green'))
|
||||||
|
|
||||||
os.system('killall linux-loader')
|
os.system('killall zcore')
|
||||||
|
|
|
@ -4,7 +4,6 @@ import re
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
TIMEOUT = 300
|
TIMEOUT = 300
|
||||||
ZIRCON_LOADER_PATH = 'zircon-loader'
|
|
||||||
ZBI_PATH = '../prebuilt/zircon/x64/core-tests.zbi'
|
ZBI_PATH = '../prebuilt/zircon/x64/core-tests.zbi'
|
||||||
CMDLINE_BASE = 'LOG=warn:userboot=test/core-standalone-test:userboot.shutdown:core-tests='
|
CMDLINE_BASE = 'LOG=warn:userboot=test/core-standalone-test:userboot.shutdown:core-tests='
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
TIMEOUT = 300
|
TIMEOUT = 300
|
||||||
ZIRCON_LOADER_PATH = 'zircon-loader'
|
|
||||||
BASE = 'zircon/'
|
BASE = 'zircon/'
|
||||||
OUTPUT_FILE = BASE + 'test-output-libos.txt'
|
OUTPUT_FILE = BASE + 'test-output-libos.txt'
|
||||||
RESULT_FILE = BASE + 'test-result-libos.txt'
|
RESULT_FILE = BASE + 'test-result-libos.txt'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "zcore"
|
name = "zcore"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["PanQL <panqinglin00@163.com>"]
|
authors = ["PanQL <panqinglin00@163.com>", "Yuekai Jia <equation618@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
default-run = "zcore"
|
default-run = "zcore"
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@ graphic = ["kernel-hal/graphic"]
|
||||||
init-ram-disk = []
|
init-ram-disk = []
|
||||||
link-user-img = ["init-ram-disk"]
|
link-user-img = ["init-ram-disk"]
|
||||||
|
|
||||||
zircon = ["zircon-loader"]
|
zircon = ["zcore-loader/zircon"]
|
||||||
linux = ["linux-loader", "linux-object", "rcore-fs", "rcore-fs-sfs"]
|
linux = ["zcore-loader/linux", "linux-object", "rcore-fs", "rcore-fs-sfs"]
|
||||||
|
|
||||||
libos = ["async-std", "chrono", "rcore-fs-hostfs", "kernel-hal/libos", "linux-loader/libos", "zircon-loader/libos"]
|
libos = ["kernel-hal/libos", "zcore-loader/libos", "async-std", "chrono", "rcore-fs-hostfs"]
|
||||||
board-qemu = []
|
board-qemu = []
|
||||||
board-d1 = ["link-user-img"]
|
board-d1 = ["link-user-img"]
|
||||||
|
|
||||||
|
@ -35,10 +35,9 @@ cfg-if = "1.0"
|
||||||
lazy_static = { version = "1.4", features = ["spin_no_std" ] }
|
lazy_static = { version = "1.4", features = ["spin_no_std" ] }
|
||||||
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "b3f9f51" }
|
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "b3f9f51" }
|
||||||
kernel-hal = { path = "../kernel-hal", default-features = false, features = ["smp"] }
|
kernel-hal = { path = "../kernel-hal", default-features = false, features = ["smp"] }
|
||||||
|
zcore-loader = { path = "../loader", default-features = false }
|
||||||
zircon-object = { path = "../zircon-object" }
|
zircon-object = { path = "../zircon-object" }
|
||||||
linux-object = { path = "../linux-object", optional = true }
|
linux-object = { path = "../linux-object", optional = true }
|
||||||
zircon-loader = { path = "../zircon-loader", default-features = false, optional = true }
|
|
||||||
linux-loader = { path = "../linux-loader", default-features = false, optional = true }
|
|
||||||
rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true }
|
rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true }
|
||||||
rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true }
|
rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#[allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn init_ram_disk() -> &'static mut [u8] {
|
fn init_ram_disk() -> &'static mut [u8] {
|
||||||
if cfg!(feature = "link-user-img") {
|
if cfg!(feature = "link-user-img") {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -49,12 +50,8 @@ cfg_if! {
|
||||||
|
|
||||||
#[cfg(feature = "libos")]
|
#[cfg(feature = "libos")]
|
||||||
pub fn zbi() -> impl AsRef<[u8]> {
|
pub fn zbi() -> impl AsRef<[u8]> {
|
||||||
let args = std::env::args().collect::<Vec<_>>();
|
let path = std::env::args().nth(1).unwrap();
|
||||||
if args.len() < 2 {
|
std::fs::read(path).expect("failed to read zbi file")
|
||||||
println!("Usage: {} ZBI_FILE [CMDLINE]", args[0]);
|
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
std::fs::read(&args[1]).expect("failed to read zbi file")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "libos"))]
|
#[cfg(not(feature = "libos"))]
|
||||||
|
|
|
@ -35,15 +35,17 @@ fn primary_main(config: kernel_hal::KernelConfig) {
|
||||||
kernel_hal::primary_init();
|
kernel_hal::primary_init();
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "linux")] {
|
if #[cfg(all(feature = "linux", feature = "zircon"))] {
|
||||||
|
panic!("Feature `linux` and `zircon` cannot be enabled at the same time!");
|
||||||
|
} else if #[cfg(feature = "linux")] {
|
||||||
let args = options.root_proc.split('?').map(Into::into).collect(); // parse "arg0?arg1?arg2"
|
let args = options.root_proc.split('?').map(Into::into).collect(); // parse "arg0?arg1?arg2"
|
||||||
let envs = alloc::vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
|
let envs = alloc::vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
|
||||||
let rootfs = fs::rootfs();
|
let rootfs = fs::rootfs();
|
||||||
let proc = linux_loader::run(args, envs, rootfs);
|
let proc = zcore_loader::linux::run(args, envs, rootfs);
|
||||||
utils::wait_for_exit(Some(proc))
|
utils::wait_for_exit(Some(proc))
|
||||||
} else if #[cfg(feature = "zircon")] {
|
} else if #[cfg(feature = "zircon")] {
|
||||||
let zbi = fs::zbi();
|
let zbi = fs::zbi();
|
||||||
let proc = zircon_loader::run_userboot(zbi, &options.cmdline);
|
let proc = zcore_loader::zircon::run_userboot(zbi, &options.cmdline);
|
||||||
utils::wait_for_exit(Some(proc))
|
utils::wait_for_exit(Some(proc))
|
||||||
} else {
|
} else {
|
||||||
panic!("One of the features `linux` or `zircon` must be specified!");
|
panic!("One of the features `linux` or `zircon` must be specified!");
|
||||||
|
|
|
@ -29,9 +29,18 @@ fn parse_cmdline(cmdline: &str) -> BTreeMap<&str, &str> {
|
||||||
pub fn boot_options() -> BootOptions {
|
pub fn boot_options() -> BootOptions {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "libos")] {
|
if #[cfg(feature = "libos")] {
|
||||||
|
let args = std::env::args().collect::<Vec<_>>();
|
||||||
|
if args.len() < 2 {
|
||||||
|
#[cfg(feature = "linux")]
|
||||||
|
println!("Usage: {} PROGRAM", args[0]);
|
||||||
|
#[cfg(feature = "zircon")]
|
||||||
|
println!("Usage: {} ZBI_FILE [CMDLINE]", args[0]);
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
let log_level = std::env::var("LOG").unwrap_or_default();
|
let log_level = std::env::var("LOG").unwrap_or_default();
|
||||||
let cmdline = if cfg!(feature = "zircon") {
|
let cmdline = if cfg!(feature = "zircon") {
|
||||||
std::env::args().nth(2).unwrap_or_default()
|
args.get(2).cloned().unwrap_or_default()
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
@ -39,7 +48,7 @@ pub fn boot_options() -> BootOptions {
|
||||||
cmdline,
|
cmdline,
|
||||||
log_level,
|
log_level,
|
||||||
#[cfg(feature = "linux")]
|
#[cfg(feature = "linux")]
|
||||||
root_proc: std::env::args().skip(1).collect::<Vec<_>>().join("?"),
|
root_proc: args[1..].join("?"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let cmdline = kernel_hal::boot::cmdline();
|
let cmdline = kernel_hal::boot::cmdline();
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "zircon-loader"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Runji Wang <wangrunji0408@163.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
description = "Zircon user program (userboot) loader"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
log = "0.4"
|
|
||||||
cfg-if = "1.0"
|
|
||||||
xmas-elf = "0.7"
|
|
||||||
zircon-object = { path = "../zircon-object", features = ["elf"] }
|
|
||||||
zircon-syscall = { path = "../zircon-syscall" }
|
|
||||||
kernel-hal = { path = "../kernel-hal", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["libos"]
|
|
||||||
libos = ["kernel-hal/libos", "zircon-object/aspace-separate", "zircon-syscall/libos"]
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
env_logger = "0.9"
|
|
||||||
async-std = { version = "1.10", features = ["attributes"] }
|
|
|
@ -9,9 +9,7 @@ description = "Zircon syscalls implementation"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# hypervisor = ["zircon-object/hypervisor"]
|
# hypervisor = ["zircon-object/hypervisor"]
|
||||||
default = []
|
|
||||||
deny-page-fault = []
|
deny-page-fault = []
|
||||||
libos = ["deny-page-fault", "kernel-hal/libos"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -129,10 +129,11 @@ impl Syscall<'_> {
|
||||||
mapping_flags.set(MMUFlags::WRITE, options.contains(VmOptions::PERM_WRITE));
|
mapping_flags.set(MMUFlags::WRITE, options.contains(VmOptions::PERM_WRITE));
|
||||||
mapping_flags.set(MMUFlags::EXECUTE, options.contains(VmOptions::PERM_EXECUTE));
|
mapping_flags.set(MMUFlags::EXECUTE, options.contains(VmOptions::PERM_EXECUTE));
|
||||||
let overwrite = options.contains(VmOptions::SPECIFIC_OVERWRITE);
|
let overwrite = options.contains(VmOptions::SPECIFIC_OVERWRITE);
|
||||||
#[cfg(feature = "deny-page-fault")]
|
let map_range = if cfg!(any(feature = "deny-page-fault", not(target_os = "none"))) {
|
||||||
let map_range = true;
|
true
|
||||||
#[cfg(not(feature = "deny-page-fault"))]
|
} else {
|
||||||
let map_range = options.contains(VmOptions::MAP_RANGE);
|
options.contains(VmOptions::MAP_RANGE)
|
||||||
|
};
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"mmuflags: {:?}, is_specific {:?}, overwrite {:?}, map_range {:?}",
|
"mmuflags: {:?}, is_specific {:?}, overwrite {:?}, map_range {:?}",
|
||||||
|
|
Loading…
Reference in New Issue