Skip to content

Commit

Permalink
Merge #306
Browse files Browse the repository at this point in the history
306: Upgrade to recent nightly channel r=mkroening a=mkroening

Reopens #292.

Replaces #302.

See hermit-os/hermit-rs#169.

Co-authored-by: Martin Kröning <mkroening@posteo.net>
  • Loading branch information
bors[bot] and mkroening committed Dec 5, 2021
2 parents 73994fd + e13eaaa commit a3044a6
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 72 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
@@ -1,4 +1,5 @@
[unstable]
# Keep in sync with CI!
build-std = ["core", "alloc"]
build-std-features = ["compiler-builtins-mem"]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/x86.yml
Expand Up @@ -39,7 +39,7 @@ jobs:
run: rustup show
- name: Build minimal kernel
working-directory: libhermit-rs
run: cargo build --no-default-features
run: cargo build --no-default-features -Z build-std=core,alloc
- name: Build dev profile
run: cargo build
- name: Unittests on host (ubuntu)
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2021-09-29"
channel = "nightly-2021-12-04"
components = [
"rust-src",
"llvm-tools-preview",
Expand Down
8 changes: 6 additions & 2 deletions src/arch/mod.rs
Expand Up @@ -44,7 +44,11 @@ pub use crate::arch::x86_64::*;

#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::apic::{set_oneshot_timer, wakeup_core};
#[cfg(all(target_arch = "x86_64", target_os = "hermit", feature = "smp"))]
#[cfg(all(
target_arch = "x86_64",
any(target_os = "none", target_os = "hermit"),
feature = "smp"
))]
pub use crate::arch::x86_64::kernel::application_processor_init;
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::gdt::set_current_kernel_stack;
Expand All @@ -60,7 +64,7 @@ pub use crate::arch::x86_64::kernel::scheduler;
pub use crate::arch::x86_64::kernel::switch;
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::systemtime::get_boot_time;
#[cfg(all(target_arch = "x86_64", target_os = "hermit"))]
#[cfg(all(target_arch = "x86_64", any(target_os = "none", target_os = "hermit")))]
pub use crate::arch::x86_64::kernel::{boot_application_processors, boot_processor_init};
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::{
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/apic.rs
Expand Up @@ -2,7 +2,7 @@ use crate::arch;
#[cfg(feature = "acpi")]
use crate::arch::x86_64::kernel::acpi;
use crate::arch::x86_64::kernel::irq::IrqStatistics;
#[cfg(all(target_os = "hermit", feature = "smp"))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), feature = "smp"))]
use crate::arch::x86_64::kernel::smp_boot_code::SMP_BOOT_CODE;
use crate::arch::x86_64::kernel::IRQ_COUNTERS;
use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
Expand Down Expand Up @@ -568,7 +568,7 @@ extern "C" {
/// This algorithm is derived from Intel MultiProcessor Specification 1.4, B.4, but testing has shown
/// that a second STARTUP IPI and setting the BIOS Reset Vector are no longer necessary.
/// This is partly confirmed by https://wiki.osdev.org/Symmetric_Multiprocessing
#[cfg(all(target_os = "hermit", feature = "smp"))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), feature = "smp"))]
pub fn boot_application_processors() {
// We shouldn't have any problems fitting the boot code into a single page, but let's better be sure.
assert!(
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/irq.rs
Expand Up @@ -90,7 +90,7 @@ pub fn disable() {
/// were not activated before calling this function.
#[inline]
pub fn nested_disable() -> bool {
cfg!(target_os = "hermit") && {
cfg!(any(target_os = "none", target_os = "hermit")) && {
let ret = rflags::read().contains(RFlags::FLAGS_IF);
disable();
ret
Expand Down
25 changes: 14 additions & 11 deletions src/arch/x86_64/kernel/mod.rs
Expand Up @@ -119,14 +119,14 @@ impl BootInfo {
}

/// Kernel header to announce machine features
#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
static mut BOOT_INFO: *mut BootInfo = ptr::null_mut();

#[cfg(all(target_os = "hermit", not(feature = "newlib")))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), not(feature = "newlib")))]
#[link_section = ".data"]
static mut BOOT_INFO: *mut BootInfo = ptr::null_mut();

#[cfg(all(target_os = "hermit", feature = "newlib"))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), feature = "newlib"))]
#[link_section = ".mboot"]
static mut BOOT_INFO: *mut BootInfo = ptr::null_mut();

Expand Down Expand Up @@ -298,7 +298,10 @@ pub fn message_output_init() {
}
}

#[cfg(all(not(target_os = "hermit"), not(target_os = "windows")))]
#[cfg(all(
not(any(target_os = "none", target_os = "hermit")),
not(target_os = "windows")
))]
pub fn output_message_byte(byte: u8) {
extern "C" {
fn write(fd: i32, buf: *const u8, count: usize) -> isize;
Expand All @@ -320,7 +323,7 @@ pub fn output_message_byte(byte: u8) {
}
}

#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
#[test]
fn test_output() {
output_message_byte('t' as u8);
Expand All @@ -330,7 +333,7 @@ fn test_output() {
output_message_byte('\n' as u8);
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub fn output_message_byte(byte: u8) {
if environment::is_single_kernel() {
// Output messages to the serial port and VGA screen in unikernel mode.
Expand All @@ -348,15 +351,15 @@ pub fn output_message_byte(byte: u8) {
}
}

//#[cfg(target_os = "hermit")]
//#[cfg(any(target_os = "none", target_os = "hermit"))]
pub fn output_message_buf(buf: &[u8]) {
for byte in buf {
output_message_byte(*byte);
}
}

/// Real Boot Processor initialization as soon as we have put the first Welcome message on the screen.
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub fn boot_processor_init() {
processor::detect_features();
processor::configure();
Expand Down Expand Up @@ -403,15 +406,15 @@ pub fn boot_processor_init() {

/// Boots all available Application Processors on bare-metal or QEMU.
/// Called after the Boot Processor has been fully initialized along with its scheduler.
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub fn boot_application_processors() {
#[cfg(feature = "smp")]
apic::boot_application_processors();
apic::print_information();
}

/// Application Processor initialization
#[cfg(all(target_os = "hermit", feature = "smp"))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), feature = "smp"))]
pub fn application_processor_init() {
percore::init();
processor::configure();
Expand Down Expand Up @@ -466,7 +469,7 @@ pub fn print_statistics() {
}
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[inline(never)]
#[no_mangle]
unsafe fn pre_init(boot_info: &'static mut BootInfo) -> ! {
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/percore.rs
Expand Up @@ -137,13 +137,13 @@ impl<T: Is32BitVariable> PerCoreVariableMethods<T> for PerCoreVariable<T> {
}
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[inline]
pub fn core_id() -> CoreId {
unsafe { PERCORE.core_id.get() }
}

#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
pub fn core_id() -> CoreId {
0
}
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86_64/kernel/processor.rs
Expand Up @@ -337,14 +337,14 @@ impl CpuFrequency {
pic::eoi(pit::PIT_INTERRUPT_NUMBER);
}

#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
fn measure_frequency(&mut self) -> Result<(), ()> {
// return just Ok because the real implementation must run in ring 0
self.source = CpuFrequencySources::Measurement;
Ok(())
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
fn measure_frequency(&mut self) -> Result<(), ()> {
// The PIC is not initialized for uhyve, so we cannot measure anything.
if environment::is_uhyve() {
Expand Down Expand Up @@ -865,7 +865,7 @@ pub fn print_information() {
infofooter!();
}

/*#[cfg(not(target_os = "hermit"))]
/*#[cfg(not(any(target_os = "none", target_os = "hermit")))]
#[test]
fn print_cpu_information() {
::logging::init();
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/scheduler.rs
Expand Up @@ -305,12 +305,12 @@ impl Clone for TaskTLS {
}
}

#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize, _user_stack: u64) -> ! {
unimplemented!()
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[naked]
extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize, _user_stack: u64) -> ! {
// `f` is in the `rdi` register
Expand Down
2 changes: 1 addition & 1 deletion src/console.rs
Expand Up @@ -31,7 +31,7 @@ impl Console {

pub static CONSOLE: SpinlockIrqSave<Console> = SpinlockIrqSave::new(Console(()));

#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
#[test]
fn test_console() {
println!("HelloWorld");
Expand Down
40 changes: 24 additions & 16 deletions src/lib.rs
Expand Up @@ -11,6 +11,8 @@
#![feature(abi_x86_interrupt)]
#![feature(allocator_api)]
#![feature(asm)]
#![feature(asm_const)]
#![feature(asm_sym)]
#![feature(const_btree_new)]
#![feature(const_fn_trait_bound)]
#![feature(const_mut_refs)]
Expand All @@ -30,13 +32,19 @@
#![feature(llvm_asm)]
#![feature(global_asm)]
#![no_std]
#![cfg_attr(target_os = "hermit", feature(custom_test_frameworks))]
#![cfg_attr(target_os = "hermit", cfg_attr(test, test_runner(crate::test_runner)))]
#![cfg_attr(
target_os = "hermit",
any(target_os = "none", target_os = "hermit"),
feature(custom_test_frameworks)
)]
#![cfg_attr(
any(target_os = "none", target_os = "hermit"),
cfg_attr(test, test_runner(crate::test_runner))
)]
#![cfg_attr(
any(target_os = "none", target_os = "hermit"),
cfg_attr(test, reexport_test_harness_main = "test_main")
)]
#![cfg_attr(target_os = "hermit", cfg_attr(test, no_main))]
#![cfg_attr(any(target_os = "none", target_os = "hermit"), cfg_attr(test, no_main))]

// EXTERNAL CRATES
#[macro_use]
Expand All @@ -47,7 +55,7 @@ extern crate bitflags;
extern crate log;
#[macro_use]
extern crate num_derive;
#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
#[macro_use]
extern crate std;
#[cfg(target_arch = "aarch64")]
Expand Down Expand Up @@ -88,7 +96,7 @@ mod errno;
mod ffi;
mod kernel_message_buffer;
mod mm;
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
mod runtime_glue;
mod scheduler;
mod synch;
Expand All @@ -102,7 +110,7 @@ pub fn _print(args: ::core::fmt::Arguments<'_>) {
}

#[cfg(test)]
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[no_mangle]
extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! {
println!("Executing hermit unittests. Any arguments are dropped");
Expand All @@ -120,14 +128,14 @@ pub fn test_runner(tests: &[&dyn Fn()]) {
sys_exit(0);
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[test_case]
fn trivial_test() {
println!("Test test test");
panic!("Test called");
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();

Expand All @@ -137,7 +145,7 @@ static ALLOCATOR: LockedHeap = LockedHeap::empty();
/// Returning a null pointer indicates that either memory is exhausted or
/// `size` and `align` do not meet this allocator's size or alignment constraints.
///
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub extern "C" fn __sys_malloc(size: usize, align: usize) -> *mut u8 {
let layout_res = Layout::from_size_align(size, align);
if layout_res.is_err() || size == 0 {
Expand Down Expand Up @@ -179,7 +187,7 @@ pub extern "C" fn __sys_malloc(size: usize, align: usize) -> *mut u8 {
/// # Errors
/// Returns null if the new layout does not meet the size and alignment constraints of the
/// allocator, or if reallocation otherwise fails.
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub extern "C" fn __sys_realloc(
ptr: *mut u8,
size: usize,
Expand Down Expand Up @@ -224,7 +232,7 @@ pub extern "C" fn __sys_realloc(
///
/// # Errors
/// May panic if debug assertions are enabled and invalid parameters `size` or `align` where passed.
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
pub extern "C" fn __sys_free(ptr: *mut u8, size: usize, align: usize) {
unsafe {
let layout_res = Layout::from_size_align(size, align);
Expand All @@ -247,7 +255,7 @@ pub extern "C" fn __sys_free(ptr: *mut u8, size: usize, align: usize) {
}
}

#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
extern "C" {
static mut __bss_start: usize;
}
Expand All @@ -259,7 +267,7 @@ fn has_ipdevice() -> bool {
}

/// Entry point of a kernel thread, which initialize the libos
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
extern "C" fn initd(_arg: usize) {
extern "C" {
#[cfg(not(test))]
Expand Down Expand Up @@ -319,7 +327,7 @@ fn synch_all_cores() {
}

/// Entry Point of HermitCore for the Boot Processor
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
fn boot_processor_main() -> ! {
// Initialize the kernel and hardware.
arch::message_output_init();
Expand Down Expand Up @@ -372,7 +380,7 @@ fn boot_processor_main() -> ! {
}

/// Entry Point of HermitCore for an Application Processor
#[cfg(all(target_os = "hermit", feature = "smp"))]
#[cfg(all(any(target_os = "none", target_os = "hermit"), feature = "smp"))]
fn application_processor_main() -> ! {
arch::application_processor_init();
scheduler::add_current_core();
Expand Down
4 changes: 2 additions & 2 deletions src/mm/allocator.rs
Expand Up @@ -31,9 +31,9 @@ pub struct Heap {
index: usize,
bottom: usize,
size: usize,
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "none", target_os = "hermit"))]
holes: HoleList,
#[cfg(not(target_os = "hermit"))]
#[cfg(not(any(target_os = "none", target_os = "hermit")))]
pub holes: HoleList,
}

Expand Down

0 comments on commit a3044a6

Please sign in to comment.