Skip to content

Commit

Permalink
Merge #385 #393 #395
Browse files Browse the repository at this point in the history
385: Rework environment module r=stlankes a=mkroening



393: Use time crate to display boot time r=stlankes a=mkroening



395: Use custom targets for kernel r=stlankes a=mkroening

Closes hermit-os/hermit-rs#197 (comment).

This puts our kernel targets into json files. This is now possible since we do not distribute the kernel via crates.io anymore.

Co-authored-by: Martin Kröning <[email protected]>
Co-authored-by: Martin Kröning <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2022
4 parents b78ae51 + 48e365e + 8ba4817 + 63841b9 commit 6e28975
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-std = ["core", "alloc"]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "x86_64-unknown-none-hermitkernel"
target = "targets/x86_64-unknown-none-hermitkernel.json"
rustflags = [
"-Zmutable-noalias=no"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: rustup show
- name: Build minimal kernel
working-directory: libhermit-rs
run: cargo build --no-default-features --target aarch64-unknown-none-hermitkernel -Z build-std=core,alloc
run: cargo build --no-default-features --target targets/aarch64-unknown-none-hermitkernel.json -Z build-std=core,alloc
- name: Build dev profile
run: cargo build --target aarch64-unknown-hermit -p hello_world
- name: Build loader
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
env:
RUSTDOCFLAGS: -D warnings
run: |
cargo doc --no-deps --document-private-items --target x86_64-unknown-none-hermitkernel
cargo doc --no-deps --document-private-items --target aarch64-unknown-none-hermitkernel
cargo doc --no-deps --document-private-items --target targets/x86_64-unknown-none-hermitkernel.json
cargo doc --no-deps --document-private-items --target targets/aarch64-unknown-none-hermitkernel.json
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ test:integration:
- python3 --version
- HERMIT_LOG_LEVEL_FILTER=Debug cargo test --test '*' --no-fail-fast -Z build-std=core,alloc
-Z build-std-features=compiler-builtins-mem --no-default-features --features=pci,acpi
--target x86_64-unknown-none-hermitkernel -- --veryverbose
--target targets/x86_64-unknown-none-hermitkernel.json -- --veryverbose
- HERMIT_LOG_LEVEL_FILTER=Debug cargo test --test '*' --no-fail-fast -Z build-std=core,alloc
-Z build-std-features=compiler-builtins-mem --no-default-features --features=pci,acpi
--target x86_64-unknown-none-hermitkernel -- --num_cores 2
--target targets/x86_64-unknown-none-hermitkernel.json -- --num_cores 2
--veryverbose
tags:
- privileged
Expand Down
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ exclude = [
".gitignore",
]

[package.metadata.docs.rs]
targets = [
"x86_64-unknown-none-hermitkernel",
"aarch64-unknown-none-hermitkernel",
]

[lib]
crate-type = ["staticlib", "lib"] # "lib" required for integration tests
name = "hermit"
Expand Down Expand Up @@ -71,13 +65,15 @@ log = { version = "0.4", default-features = false }
num = { version = "0.4", default-features = false }
num-derive = "0.3"
num-traits = { version = "0.2", default-features = false }
once_cell = { version = "1.10", default-features = false, features = ["alloc"] }
pci-ids = { version = "0.2", optional = true }
scopeguard = { version = "1.1", default-features = false }
shell-words = { version = "1.1", default-features = false }
qemu-exit = "3.0"

[target.'cfg(target_arch = "x86_64")'.dependencies]
multiboot = "0.7"
time = { version = "0.3", default-features = false }
x86 = { version = "0.47", default-features = false }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustup component add rust-src llvm-tools-preview
You can then build `libhermit-rs` with the following command

```sh
cargo build -Z build-std=core,alloc,panic_abort --target x86_64-unknown-none-hermitkernel
cargo build -Z build-std=core,alloc,panic_abort --target targets/x86_64-unknown-none-hermitkernel.json
```

The resulting library then can be found in `target/x86_64-unknown-none-hermitkernel/debug/libhermit.a`
Expand All @@ -44,7 +44,7 @@ You can change it by setting it at compile time to a string matching the name of
If the variable is not set, or the name doesn't match, then `LevelFilter::Info` is used by default.

```sh
$ HERMIT_LOG_LEVEL_FILTER=Debug cargo build -Z build-std=core,alloc,panic_abort --target x86_64-unknown-none-hermitkernel
$ HERMIT_LOG_LEVEL_FILTER=Debug cargo build -Z build-std=core,alloc,panic_abort --target targets/x86_64-unknown-none-hermitkernel.json
```

## Credits
Expand Down
14 changes: 7 additions & 7 deletions src/arch/aarch64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use crate::arch::aarch64::kernel::stubs::*;
pub use crate::arch::aarch64::kernel::systemtime::get_boot_time;
use crate::arch::aarch64::mm::{PhysAddr, VirtAddr};
use crate::config::*;
use crate::environment;
use crate::env;
use crate::kernel_message_buffer;
use crate::synch::spinlock::Spinlock;
use core::arch::{asm, global_asm};
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn message_output_init() {
COM1.port_address = core::ptr::read_volatile(&(*BOOT_INFO).uartport);
}

if environment::is_single_kernel() {
if env::is_single_kernel() {
// We can only initialize the serial port here, because VGA requires processor
// configuration first.
unsafe {
Expand All @@ -128,7 +128,7 @@ pub fn message_output_init() {
}

pub fn output_message_byte(byte: u8) {
if environment::is_single_kernel() {
if env::is_single_kernel() {
// Output messages to the serial port.
unsafe {
COM1.write_byte(byte);
Expand Down Expand Up @@ -158,12 +158,12 @@ pub fn boot_processor_init() {
::mm::init();
::mm::print_information();
environment::init();
env::init();
gdt::init();
gdt::add_current_core();
idt::install();
if !environment::is_uhyve() {
if !env::is_uhyve() {
pic::init();
}
Expand All @@ -173,7 +173,7 @@ pub fn boot_processor_init() {
processor::print_information();
systemtime::init();
if environment::is_single_kernel() && !environment::is_uhyve() {
if env::is_single_kernel() && !env::is_uhyve() {
pci::init();
pci::print_information();
acpi::init();
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn application_processor_init() {
fn finish_processor_init() {
debug!("Initialized Processor");

/*if environment::is_uhyve() {
/*if env::is_uhyve() {
// uhyve does not use apic::detect_from_acpi and therefore does not know the number of processors and
// their APIC IDs in advance.
// Therefore, we have to add each booted processor into the CPU_LOCAL_APIC_IDS vector ourselves.
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::arch::aarch64::kernel::percore::*;
use crate::arch::aarch64::kernel::processor;
use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
use crate::arch::aarch64::mm::{PhysAddr, VirtAddr};
use crate::environment;
use crate::env;
use crate::scheduler::task::{Task, TaskFrame};
use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE};
use alloc::rc::Rc;
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/systemtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::environment;
use crate::env;

extern "C" {
static mut boot_gtod: u64;
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicUsize, Ordering};
use crate::arch::aarch64::kernel::{get_boot_info_address, get_limit, get_ram_address};
use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize};
use crate::arch::aarch64::mm::{PhysAddr, VirtAddr};
use crate::environment::is_uhyve;
use crate::env::is_uhyve;
use crate::mm;
use crate::mm::freelist::{FreeList, FreeListEntry};
use crate::synch::spinlock::SpinlockIrqSave;
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::arch::x86_64::mm::{paging, virtualmem};
use crate::arch::x86_64::mm::{PhysAddr, VirtAddr};
use crate::collections::irqsave;
use crate::config::*;
use crate::environment;
use crate::env;
use crate::mm;
use crate::scheduler;
use crate::scheduler::CoreId;
Expand Down Expand Up @@ -471,7 +471,7 @@ fn default_apic() -> PhysAddr {
}

fn detect_from_uhyve() -> Result<PhysAddr, ()> {
if environment::is_uhyve() {
if env::is_uhyve() {
let default_address = PhysAddr(0xFEC0_0000);

unsafe {
Expand Down
16 changes: 8 additions & 8 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::arch::mm::{PhysAddr, VirtAddr};
use crate::arch::x86_64::kernel::irq::{get_irq_name, IrqStatistics};
use crate::arch::x86_64::kernel::percore::*;
use crate::arch::x86_64::kernel::serial::SerialPort;
use crate::environment;
use crate::env;
use crate::kernel_message_buffer;
use crate::scheduler::CoreId;

Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn message_output_init() {
COM1.port_address = core::ptr::read_volatile(&(*BOOT_INFO).uartport);
}

if environment::is_single_kernel() {
if env::is_single_kernel() {
// We can only initialize the serial port here, because VGA requires processor
// configuration first.
unsafe {
Expand Down Expand Up @@ -335,7 +335,7 @@ fn test_output() {

#[cfg(any(target_os = "none", target_os = "hermit"))]
pub fn output_message_byte(byte: u8) {
if environment::is_single_kernel() {
if env::is_single_kernel() {
// Output messages to the serial port and VGA screen in unikernel mode.
unsafe {
COM1.write_byte(byte);
Expand Down Expand Up @@ -364,14 +364,14 @@ pub fn boot_processor_init() {
processor::detect_features();
processor::configure();

if cfg!(feature = "vga") && environment::is_single_kernel() && !environment::is_uhyve() {
if cfg!(feature = "vga") && env::is_single_kernel() && !env::is_uhyve() {
#[cfg(feature = "vga")]
vga::init();
}

crate::mm::init();
crate::mm::print_information();
environment::init();
env::init();
gdt::init();
gdt::add_current_core();
idt::install();
Expand All @@ -385,14 +385,14 @@ pub fn boot_processor_init() {
irq::install();
systemtime::init();

if environment::is_single_kernel() {
if env::is_single_kernel() {
if is_uhyve_with_pci() || !is_uhyve() {
#[cfg(feature = "pci")]
pci::init();
#[cfg(feature = "pci")]
pci::print_information();
}
if !environment::is_uhyve() {
if !env::is_uhyve() {
#[cfg(feature = "acpi")]
acpi::init();
}
Expand Down Expand Up @@ -430,7 +430,7 @@ pub fn application_processor_init() {
}

fn finish_processor_init() {
if environment::is_uhyve() {
if env::is_uhyve() {
// uhyve does not use apic::detect_from_acpi and therefore does not know the number of processors and
// their APIC IDs in advance.
// Therefore, we have to add each booted processor into the CPU_LOCAL_APIC_IDS vector ourselves.
Expand Down
10 changes: 5 additions & 5 deletions src/arch/x86_64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "acpi")]
use crate::arch::x86_64::kernel::acpi;
use crate::arch::x86_64::kernel::{idt, irq, pic, pit, BOOT_INFO};
use crate::environment;
use crate::env;
use crate::x86::controlregs::*;
use crate::x86::cpuid::*;
use crate::x86::msr::*;
Expand Down Expand Up @@ -254,7 +254,7 @@ impl CpuFrequency {
}

unsafe fn detect_from_cmdline(&mut self) -> Result<(), ()> {
let mhz = environment::get_command_line_cpu_frequency().ok_or(())?;
let mhz = env::freq().ok_or(())?;
self.set_detected_cpu_frequency(mhz, CpuFrequencySources::CommandLine)
}

Expand Down Expand Up @@ -315,7 +315,7 @@ impl CpuFrequency {

fn detect_from_hypervisor(&mut self) -> Result<(), ()> {
fn detect_from_uhyve() -> Result<u16, ()> {
if environment::is_uhyve() {
if env::is_uhyve() {
unsafe {
let cpu_freq = core::ptr::read_volatile(&(*BOOT_INFO).cpu_freq);
if cpu_freq > (u16::MAX as u32) {
Expand Down Expand Up @@ -351,7 +351,7 @@ impl CpuFrequency {
#[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() {
if env::is_uhyve() {
return Err(());
}

Expand Down Expand Up @@ -609,7 +609,7 @@ impl fmt::Display for CpuFeaturePrinter {
}

pub fn run_on_hypervisor() -> bool {
if environment::is_uhyve() {
if env::is_uhyve() {
true
} else {
unsafe { RUN_ON_HYPERVISOR }
Expand Down
12 changes: 6 additions & 6 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::arch::x86_64::kernel::percore::*;
use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
use crate::arch::x86_64::mm::{PhysAddr, VirtAddr};
use crate::config::*;
use crate::environment;
use crate::env;
use crate::scheduler::task::{Task, TaskFrame};

#[repr(C, packed)]
Expand Down Expand Up @@ -238,24 +238,24 @@ impl TaskTLS {
// “ELF Handling For Thread-Local Storage” Section 3.4.6: x86-64 Specific Definitions for Run-Time Handling of TLS
// https://akkadia.org/drepper/tls.pdf

let tls_len = environment::get_tls_memsz();
let tls_len = env::get_tls_memsz();

if environment::get_tls_memsz() == 0 {
if env::get_tls_memsz() == 0 {
return None;
}

// Get TLS initialization image
let tls_init_image = {
let tls_init_data = environment::get_tls_start().as_ptr::<u8>();
let tls_init_len = environment::get_tls_filesz();
let tls_init_data = env::get_tls_start().as_ptr::<u8>();
let tls_init_len = env::get_tls_filesz();

// SAFETY: We will have to trust the environment here.
unsafe { slice::from_raw_parts(tls_init_data, tls_init_len) }
};

// Allocate TLS block
let mut block = {
let tls_align = environment::get_tls_align();
let tls_align = env::get_tls_align();

// As described in “ELF Handling For Thread-Local Storage”
let tls_offset = align_up!(tls_len, tls_align);
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86_64/kernel/serial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::environment;
use crate::env;
use crate::x86::io::*;
use core::hint::spin_loop;

Expand Down Expand Up @@ -35,7 +35,7 @@ impl SerialPort {

fn is_transmitting(&self) -> bool {
// The virtual serial port in uhyve is never blocked.
if environment::is_uhyve() {
if env::is_uhyve() {
return false;
}

Expand Down Expand Up @@ -67,7 +67,7 @@ impl SerialPort {

pub fn init(&self, baudrate: u32) {
// The virtual serial port is always initialized in uhyve.
if !environment::is_uhyve() && self.port_address != 0 {
if !env::is_uhyve() && self.port_address != 0 {
// Disable port interrupt.
self.write_to_register(UART_IER, 0);

Expand Down
Loading

0 comments on commit 6e28975

Please sign in to comment.