Skip to content

CI: Set up caching and update problem matcher #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -14,11 +14,12 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: cargo --version --verbose
- uses: Swatinem/rust-cache@v2
- uses: r7kamura/[email protected]
- name: "Run `cargo check`"
uses: actions-rs/cargo@v1
with:
command: check
run: cargo check --all-targets --all

test:
name: Test
@@ -31,7 +32,9 @@ jobs:
timeout-minutes: 30

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: cargo --version --verbose
- uses: Swatinem/rust-cache@v2

# install QEMU
- name: Install QEMU (Linux)
@@ -53,34 +56,26 @@ jobs:
- name: "Print QEMU Version"
run: qemu-system-x86_64 --version

- uses: r7kamura/[email protected]
- name: Run api tests
uses: actions-rs/cargo@v1
with:
command: test
args: -p bootloader_api

run: cargo test -p bootloader_api
- name: Run integration tests
uses: actions-rs/cargo@v1
with:
command: test
run: cargo test

fmt:
name: Check Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run `cargo fmt --all -- --check`
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- uses: actions/checkout@v3
- uses: r7kamura/[email protected]
- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run `cargo clippy`
uses: actions-rs/cargo@v1
with:
command: clippy
- uses: actions/checkout@v3
- run: cargo --version --verbose
- uses: Swatinem/rust-cache@v2
- uses: r7kamura/[email protected]
- run: cargo clippy --all --all-targets
2 changes: 1 addition & 1 deletion api/build.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ fn main() {
);
}

fs::write(&dest_path, code).unwrap();
fs::write(dest_path, code).unwrap();
println!("cargo:rerun-if-changed=build.rs");

let version_major: u16 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();
7 changes: 3 additions & 4 deletions api/src/config.rs
Original file line number Diff line number Diff line change
@@ -132,15 +132,14 @@ impl BootloaderConfig {
Option::Some(addr) => concat_1_8([1], addr.to_le_bytes()),
},
);
let buf = concat_106_9(

concat_106_9(
buf,
match minimum_framebuffer_width {
Option::None => [0; 9],
Option::Some(addr) => concat_1_8([1], addr.to_le_bytes()),
},
);

buf
)
}

/// Tries to deserialize a config byte array that was created using [`Self::serialize`].
11 changes: 8 additions & 3 deletions bios/boot_sector/src/main.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@
#![no_main]
#![warn(unsafe_op_in_unsafe_fn)]

use core::{arch::global_asm, slice};
use core::{
arch::{asm, global_asm},
slice,
};
use fail::{print_char, UnwrapOrFail};

global_asm!(include_str!("boot.s"));
@@ -54,7 +57,7 @@ pub extern "C" fn first_stage(disk_number: u16) {

start_lba += u64::from(sectors);
number_of_sectors -= u32::from(sectors);
target_addr = target_addr + u32::from(sectors) * 512;
target_addr += u32::from(sectors) * 512;

if number_of_sectors == 0 {
break;
@@ -73,5 +76,7 @@ pub extern "C" fn first_stage(disk_number: u16) {
print_char(b'R');
}

loop {}
loop {
unsafe { asm!("hlt") }
}
}
2 changes: 1 addition & 1 deletion bios/boot_sector/src/mbr.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ pub(crate) fn get_partition(partitions_raw: &[u8], index: usize) -> PartitionTab
let offset = index * ENTRY_SIZE;
let buffer = partitions_raw.get(offset..).unwrap_or_fail(b'c');

let bootable_raw = *buffer.get(0).unwrap_or_fail(b'd');
let bootable_raw = *buffer.first().unwrap_or_fail(b'd');
let bootable = bootable_raw == 0x80;

let partition_type = *buffer.get(4).unwrap_or_fail(b'e');
4 changes: 4 additions & 0 deletions bios/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -62,3 +62,7 @@ pub struct E820MemoryRegion {
pub region_type: u32,
pub acpi_extended_attributes: u32,
}

pub fn hlt() {
unsafe { core::arch::asm!("hlt") };
}
5 changes: 5 additions & 0 deletions bios/common/src/racy_cell.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,11 @@ impl<T> RacyCell<T> {
Self(UnsafeCell::new(v))
}

/// Gets a mutable pointer to the wrapped value.
///
/// ## Safety
/// Ensure that the access is unique (no active references, mutable or not).
#[allow(clippy::mut_from_ref)]
pub unsafe fn get_mut(&self) -> &mut T {
unsafe { &mut *self.0.get() }
}
2 changes: 1 addition & 1 deletion bios/stage-2/src/disk.rs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ impl Read for DiskAccess {

start_lba += u64::from(sectors);
number_of_sectors -= u64::from(sectors);
target_addr = target_addr + u32::from(sectors) * 512;
target_addr += u32::from(sectors) * 512;

if number_of_sectors == 0 {
break;
8 changes: 4 additions & 4 deletions bios/stage-2/src/fat.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ struct Bpb {
fat_size_16: u16,
total_sectors_32: u32,
fat_size_32: u32,
root_cluster: u32,
_root_cluster: u32,
}

impl Bpb {
@@ -71,7 +71,7 @@ impl Bpb {
fat_size_16,
total_sectors_32,
fat_size_32,
root_cluster,
_root_cluster: root_cluster,
}
}

@@ -209,7 +209,7 @@ impl<D: Read + Seek> FileSystem<D> {
) -> impl Iterator<Item = Result<RawDirectoryEntry, ()>> + 'a {
match self.bpb.fat_type() {
FatType::Fat32 => {
self.bpb.root_cluster;
// self.bpb.root_cluster;
unimplemented!();
}
FatType::Fat12 | FatType::Fat16 => {
@@ -391,7 +391,7 @@ impl<'a> RawDirectoryEntry<'a> {
} else {
fn slice_to_string(slice: &[u8]) -> Result<&str, ()> {
const SKIP_SPACE: u8 = 0x20;
let mut iter = slice.into_iter().copied();
let mut iter = slice.iter().copied();
match iter.position(|c| c != SKIP_SPACE) {
Some(start_idx) => {
let end_idx =
10 changes: 6 additions & 4 deletions bios/stage-2/src/main.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use crate::{
copy_to_protected_mode, enter_protected_mode_and_jump_to_stage_3, enter_unreal_mode,
},
};
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, Region};
use bootloader_x86_64_bios_common::{hlt, BiosFramebufferInfo, BiosInfo, Region};
use byteorder::{ByteOrder, LittleEndian};
use core::{fmt::Write as _, slice};
use disk::AlignedArrayBuffer;
@@ -50,12 +50,12 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {

let mut entries = [PartitionTableEntry::empty(); MAX_ENTRIES];
let raw = unsafe { slice::from_raw_parts(partition_table_start, ENTRY_SIZE * MAX_ENTRIES) };
for idx in 0..MAX_ENTRIES {
for (idx, entry) in entries.iter_mut().enumerate() {
let offset = idx * ENTRY_SIZE;
let partition_type = PartitionType::from_mbr_tag_byte(raw[offset + 4]);
let lba = LittleEndian::read_u32(&raw[offset + 8..]);
let len = LittleEndian::read_u32(&raw[offset + 12..]);
entries[idx] = PartitionTableEntry::new(partition_type, lba, len);
*entry = PartitionTableEntry::new(partition_type, lba, len);
}
entries
};
@@ -146,7 +146,9 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {

enter_protected_mode_and_jump_to_stage_3(STAGE_3_DST, &mut info);

loop {}
loop {
hlt();
}
}

fn load_file(
2 changes: 1 addition & 1 deletion bios/stage-2/src/memory_map.rs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ pub unsafe fn query_memory_map() -> Result<&'static mut [E820MemoryRegion], ()>
if buf_written_len != 0 {
let buf = &buf[..buf_written_len];

let (&base_raw, rest) = split_array_ref(&buf);
let (&base_raw, rest) = split_array_ref(buf);
let (&len_raw, rest) = split_array_ref(rest);
let (&kind_raw, rest) = split_array_ref(rest);
let acpi_extended_raw: [u8; 4] = rest.try_into().unwrap_or_default();
6 changes: 4 additions & 2 deletions bios/stage-3/src/main.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#![deny(unsafe_op_in_unsafe_fn)]

use crate::screen::Writer;
use bootloader_x86_64_bios_common::BiosInfo;
use bootloader_x86_64_bios_common::{hlt, BiosInfo};
use core::{arch::asm, fmt::Write as _};

mod gdt;
@@ -24,7 +24,9 @@ pub extern "C" fn _start(info: &mut BiosInfo) {
gdt::LONG_MODE_GDT.load();
enter_long_mode_and_jump_to_stage_4(info);

loop {}
loop {
hlt();
}
}

#[no_mangle]
2 changes: 1 addition & 1 deletion bios/stage-4/src/main.rs
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ fn detect_rsdp() -> Option<PhysAddr> {
}
}

#[cfg(all(not(test), target_os = "none"))]
#[cfg(target_os = "none")]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
unsafe {
9 changes: 9 additions & 0 deletions common/src/legacy_memory_region.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,10 @@ pub trait LegacyMemoryRegion: Copy + core::fmt::Debug {
fn start(&self) -> PhysAddr;
/// Returns the size of the region in bytes.
fn len(&self) -> u64;
/// Returns whether this region is empty.
fn is_empty(&self) -> bool {
self.len() == 0
}
/// Returns the type of the region, e.g. whether it is usable or reserved.
fn kind(&self) -> MemoryRegionKind;

@@ -81,6 +85,11 @@ where
self.original.len()
}

/// Returns whether this memory map is empty.
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the largest detected physical memory address.
///
/// Useful for creating a mapping for all physical memory.
3 changes: 2 additions & 1 deletion common/src/logger.rs
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ fn get_char_raster(c: char) -> RasterizedChar {
font_constants::CHAR_RASTER_HEIGHT,
)
}
get(c).unwrap_or(get(BACKUP_CHAR).expect("Should get raster of backup char."))
get(c).unwrap_or_else(|| get(BACKUP_CHAR).expect("Should get raster of backup char."))
}

impl LockedLogger {
@@ -62,6 +62,7 @@ impl LockedLogger {

/// Force-unlocks the logger to prevent a deadlock.
///
/// ## Safety
/// This method is not memory safe and should be only used when absolutely necessary.
pub unsafe fn force_unlock(&self) {
unsafe { self.0.force_unlock() };
2 changes: 1 addition & 1 deletion src/fat.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ pub fn create_fat_filesystem(
.write(true)
.create(true)
.truncate(true)
.open(&out_fat_path)
.open(out_fat_path)
.unwrap();
let fat_size_padded_and_rounded = ((needed_size + 1024 * 64 - 1) / MB + 1) * MB;
fat_file.set_len(fat_size_padded_and_rounded).unwrap();
6 changes: 3 additions & 3 deletions src/gpt.rs
Original file line number Diff line number Diff line change
@@ -12,11 +12,11 @@ pub fn create_gpt_disk(fat_image: &Path, out_gpt_path: &Path) -> anyhow::Result<
.truncate(true)
.read(true)
.write(true)
.open(&out_gpt_path)
.open(out_gpt_path)
.with_context(|| format!("failed to create GPT file at `{}`", out_gpt_path.display()))?;

// set file size
let partition_size: u64 = fs::metadata(&fat_image)
let partition_size: u64 = fs::metadata(fat_image)
.context("failed to read metadata of fat image")?
.len();
let disk_size = partition_size + 1024 * 64; // for GPT headers
@@ -61,7 +61,7 @@ pub fn create_gpt_disk(fat_image: &Path, out_gpt_path: &Path) -> anyhow::Result<
disk.seek(io::SeekFrom::Start(start_offset))
.context("failed to seek to start offset")?;
io::copy(
&mut File::open(&fat_image).context("failed to open FAT image")?,
&mut File::open(fat_image).context("failed to open FAT image")?,
&mut disk,
)
.context("failed to copy FAT image to GPT disk")?;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ impl UefiBoot {
files.insert(KERNEL_FILE_NAME, self.kernel.as_path());

let out_file = NamedTempFile::new().context("failed to create temp file")?;
fat::create_fat_filesystem(files, &out_file.path())
fat::create_fat_filesystem(files, out_file.path())
.context("failed to create UEFI FAT filesystem")?;

Ok(out_file)
2 changes: 1 addition & 1 deletion src/mbr.rs
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ pub fn create_mbr_disk(
.truncate(true)
.read(true)
.write(true)
.open(&out_mbr_path)
.open(out_mbr_path)
.with_context(|| {
format!(
"failed to create MBR disk image at `{}`",
2 changes: 1 addition & 1 deletion tests/lto.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use bootloader_test_runner::run_test_kernel;
#[test]
fn basic_boot() {
// build test kernel manually to force-enable link-time optimization
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or("cargo".into()));
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()));
cmd.arg("build");
cmd.arg("-p").arg("test_kernel_lto");
cmd.arg("--target").arg("x86_64-unknown-none");
6 changes: 3 additions & 3 deletions uefi/src/main.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
)
.unwrap();

let kernel = load_kernel(image, &mut st);
let kernel = load_kernel(image, &st);

let framebuffer = init_logger(&st, kernel.config);

@@ -143,7 +143,7 @@ fn load_kernel_file(image: Handle, st: &SystemTable<Boot>) -> Option<&'static mu

fn load_kernel_file_from_disk(image: Handle, st: &SystemTable<Boot>) -> Option<&'static mut [u8]> {
let file_system_raw = {
let ref this = st.boot_services();
let this = st.boot_services();
let loaded_image = this
.open_protocol::<LoadedImage>(
OpenProtocolParams {
@@ -428,7 +428,7 @@ fn init_logger(st: &SystemTable<Boot>, config: BootloaderConfig) -> Option<RawFr
})
}

#[cfg(all(not(test), target_os = "uefi"))]
#[cfg(target_os = "uefi")]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::arch::asm;
2 changes: 1 addition & 1 deletion uefi/src/memory_descriptor.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ pub struct UefiMemoryDescriptor(pub MemoryDescriptor);

const PAGE_SIZE: u64 = 4096;

impl<'a> LegacyMemoryRegion for UefiMemoryDescriptor {
impl LegacyMemoryRegion for UefiMemoryDescriptor {
fn start(&self) -> PhysAddr {
PhysAddr::new(self.0.phys_start)
}
3 changes: 2 additions & 1 deletion x86_64-stage-4.json
Original file line number Diff line number Diff line change
@@ -17,5 +17,6 @@
},
"static-position-independent-executables": true,
"target-pointer-width": "64",
"relocation-model": "static"
"relocation-model": "static",
"os": "none"
}