Skip to content

Commit 3649e82

Browse files
authored
Merge pull request #282 from rust-osdev/ci
CI: Set up caching and update problem matcher
2 parents b4d58a8 + 6caa684 commit 3649e82

File tree

23 files changed

+82
-59
lines changed

23 files changed

+82
-59
lines changed

Diff for: .github/workflows/ci.yml

+19-24
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ jobs:
1414
timeout-minutes: 10
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
18+
- run: cargo --version --verbose
19+
- uses: Swatinem/rust-cache@v2
20+
- uses: r7kamura/[email protected]
1821
- name: "Run `cargo check`"
19-
uses: actions-rs/cargo@v1
20-
with:
21-
command: check
22+
run: cargo check --all-targets --all
2223

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

3334
steps:
34-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@v3
36+
- run: cargo --version --verbose
37+
- uses: Swatinem/rust-cache@v2
3538

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

59+
- uses: r7kamura/[email protected]
5660
- name: Run api tests
57-
uses: actions-rs/cargo@v1
58-
with:
59-
command: test
60-
args: -p bootloader_api
61-
61+
run: cargo test -p bootloader_api
6262
- name: Run integration tests
63-
uses: actions-rs/cargo@v1
64-
with:
65-
command: test
63+
run: cargo test
6664

6765
fmt:
6866
name: Check Formatting
6967
runs-on: ubuntu-latest
7068
steps:
71-
- uses: actions/checkout@v2
72-
- name: Run `cargo fmt --all -- --check`
73-
uses: actions-rs/cargo@v1
74-
with:
75-
command: fmt
76-
args: --all -- --check
69+
- uses: actions/checkout@v3
70+
- uses: r7kamura/[email protected]
71+
- run: cargo fmt --all -- --check
7772

7873
clippy:
7974
name: Clippy
8075
runs-on: ubuntu-latest
8176
steps:
82-
- uses: actions/checkout@v2
83-
- name: Run `cargo clippy`
84-
uses: actions-rs/cargo@v1
85-
with:
86-
command: clippy
77+
- uses: actions/checkout@v3
78+
- run: cargo --version --verbose
79+
- uses: Swatinem/rust-cache@v2
80+
- uses: r7kamura/[email protected]
81+
- run: cargo clippy --all --all-targets

Diff for: api/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn main() {
4343
);
4444
}
4545

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

4949
let version_major: u16 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();

Diff for: api/src/config.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,14 @@ impl BootloaderConfig {
132132
Option::Some(addr) => concat_1_8([1], addr.to_le_bytes()),
133133
},
134134
);
135-
let buf = concat_106_9(
135+
136+
concat_106_9(
136137
buf,
137138
match minimum_framebuffer_width {
138139
Option::None => [0; 9],
139140
Option::Some(addr) => concat_1_8([1], addr.to_le_bytes()),
140141
},
141-
);
142-
143-
buf
142+
)
144143
}
145144

146145
/// Tries to deserialize a config byte array that was created using [`Self::serialize`].

Diff for: bios/boot_sector/src/main.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#![no_main]
33
#![warn(unsafe_op_in_unsafe_fn)]
44

5-
use core::{arch::global_asm, slice};
5+
use core::{
6+
arch::{asm, global_asm},
7+
slice,
8+
};
69
use fail::{print_char, UnwrapOrFail};
710

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

5558
start_lba += u64::from(sectors);
5659
number_of_sectors -= u32::from(sectors);
57-
target_addr = target_addr + u32::from(sectors) * 512;
60+
target_addr += u32::from(sectors) * 512;
5861

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

76-
loop {}
79+
loop {
80+
unsafe { asm!("hlt") }
81+
}
7782
}

Diff for: bios/boot_sector/src/mbr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn get_partition(partitions_raw: &[u8], index: usize) -> PartitionTab
1111
let offset = index * ENTRY_SIZE;
1212
let buffer = partitions_raw.get(offset..).unwrap_or_fail(b'c');
1313

14-
let bootable_raw = *buffer.get(0).unwrap_or_fail(b'd');
14+
let bootable_raw = *buffer.first().unwrap_or_fail(b'd');
1515
let bootable = bootable_raw == 0x80;
1616

1717
let partition_type = *buffer.get(4).unwrap_or_fail(b'e');

Diff for: bios/common/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ pub struct E820MemoryRegion {
6262
pub region_type: u32,
6363
pub acpi_extended_attributes: u32,
6464
}
65+
66+
pub fn hlt() {
67+
unsafe { core::arch::asm!("hlt") };
68+
}

Diff for: bios/common/src/racy_cell.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ impl<T> RacyCell<T> {
77
Self(UnsafeCell::new(v))
88
}
99

10+
/// Gets a mutable pointer to the wrapped value.
11+
///
12+
/// ## Safety
13+
/// Ensure that the access is unique (no active references, mutable or not).
14+
#[allow(clippy::mut_from_ref)]
1015
pub unsafe fn get_mut(&self) -> &mut T {
1116
unsafe { &mut *self.0.get() }
1217
}

Diff for: bios/stage-2/src/disk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Read for DiskAccess {
4747

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

5252
if number_of_sectors == 0 {
5353
break;

Diff for: bios/stage-2/src/fat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Bpb {
2828
fat_size_16: u16,
2929
total_sectors_32: u32,
3030
fat_size_32: u32,
31-
root_cluster: u32,
31+
_root_cluster: u32,
3232
}
3333

3434
impl Bpb {
@@ -71,7 +71,7 @@ impl Bpb {
7171
fat_size_16,
7272
total_sectors_32,
7373
fat_size_32,
74-
root_cluster,
74+
_root_cluster: root_cluster,
7575
}
7676
}
7777

@@ -209,7 +209,7 @@ impl<D: Read + Seek> FileSystem<D> {
209209
) -> impl Iterator<Item = Result<RawDirectoryEntry, ()>> + 'a {
210210
match self.bpb.fat_type() {
211211
FatType::Fat32 => {
212-
self.bpb.root_cluster;
212+
// self.bpb.root_cluster;
213213
unimplemented!();
214214
}
215215
FatType::Fat12 | FatType::Fat16 => {
@@ -391,7 +391,7 @@ impl<'a> RawDirectoryEntry<'a> {
391391
} else {
392392
fn slice_to_string(slice: &[u8]) -> Result<&str, ()> {
393393
const SKIP_SPACE: u8 = 0x20;
394-
let mut iter = slice.into_iter().copied();
394+
let mut iter = slice.iter().copied();
395395
match iter.position(|c| c != SKIP_SPACE) {
396396
Some(start_idx) => {
397397
let end_idx =

Diff for: bios/stage-2/src/main.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
copy_to_protected_mode, enter_protected_mode_and_jump_to_stage_3, enter_unreal_mode,
88
},
99
};
10-
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, Region};
10+
use bootloader_x86_64_bios_common::{hlt, BiosFramebufferInfo, BiosInfo, Region};
1111
use byteorder::{ByteOrder, LittleEndian};
1212
use core::{fmt::Write as _, slice};
1313
use disk::AlignedArrayBuffer;
@@ -50,12 +50,12 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
5050

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

147147
enter_protected_mode_and_jump_to_stage_3(STAGE_3_DST, &mut info);
148148

149-
loop {}
149+
loop {
150+
hlt();
151+
}
150152
}
151153

152154
fn load_file(

Diff for: bios/stage-2/src/memory_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub unsafe fn query_memory_map() -> Result<&'static mut [E820MemoryRegion], ()>
4747
if buf_written_len != 0 {
4848
let buf = &buf[..buf_written_len];
4949

50-
let (&base_raw, rest) = split_array_ref(&buf);
50+
let (&base_raw, rest) = split_array_ref(buf);
5151
let (&len_raw, rest) = split_array_ref(rest);
5252
let (&kind_raw, rest) = split_array_ref(rest);
5353
let acpi_extended_raw: [u8; 4] = rest.try_into().unwrap_or_default();

Diff for: bios/stage-3/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![deny(unsafe_op_in_unsafe_fn)]
44

55
use crate::screen::Writer;
6-
use bootloader_x86_64_bios_common::BiosInfo;
6+
use bootloader_x86_64_bios_common::{hlt, BiosInfo};
77
use core::{arch::asm, fmt::Write as _};
88

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

27-
loop {}
27+
loop {
28+
hlt();
29+
}
2830
}
2931

3032
#[no_mangle]

Diff for: bios/stage-4/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn detect_rsdp() -> Option<PhysAddr> {
227227
}
228228
}
229229

230-
#[cfg(all(not(test), target_os = "none"))]
230+
#[cfg(target_os = "none")]
231231
#[panic_handler]
232232
fn panic(info: &core::panic::PanicInfo) -> ! {
233233
unsafe {

Diff for: common/src/legacy_memory_region.rs

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub trait LegacyMemoryRegion: Copy + core::fmt::Debug {
1111
fn start(&self) -> PhysAddr;
1212
/// Returns the size of the region in bytes.
1313
fn len(&self) -> u64;
14+
/// Returns whether this region is empty.
15+
fn is_empty(&self) -> bool {
16+
self.len() == 0
17+
}
1418
/// Returns the type of the region, e.g. whether it is usable or reserved.
1519
fn kind(&self) -> MemoryRegionKind;
1620

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

88+
/// Returns whether this memory map is empty.
89+
pub fn is_empty(&self) -> bool {
90+
self.len() == 0
91+
}
92+
8493
/// Returns the largest detected physical memory address.
8594
///
8695
/// Useful for creating a mapping for all physical memory.

Diff for: common/src/logger.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn get_char_raster(c: char) -> RasterizedChar {
5151
font_constants::CHAR_RASTER_HEIGHT,
5252
)
5353
}
54-
get(c).unwrap_or(get(BACKUP_CHAR).expect("Should get raster of backup char."))
54+
get(c).unwrap_or_else(|| get(BACKUP_CHAR).expect("Should get raster of backup char."))
5555
}
5656

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

6363
/// Force-unlocks the logger to prevent a deadlock.
6464
///
65+
/// ## Safety
6566
/// This method is not memory safe and should be only used when absolutely necessary.
6667
pub unsafe fn force_unlock(&self) {
6768
unsafe { self.0.force_unlock() };

Diff for: src/fat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn create_fat_filesystem(
2424
.write(true)
2525
.create(true)
2626
.truncate(true)
27-
.open(&out_fat_path)
27+
.open(out_fat_path)
2828
.unwrap();
2929
let fat_size_padded_and_rounded = ((needed_size + 1024 * 64 - 1) / MB + 1) * MB;
3030
fat_file.set_len(fat_size_padded_and_rounded).unwrap();

Diff for: src/gpt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ pub fn create_gpt_disk(fat_image: &Path, out_gpt_path: &Path) -> anyhow::Result<
1212
.truncate(true)
1313
.read(true)
1414
.write(true)
15-
.open(&out_gpt_path)
15+
.open(out_gpt_path)
1616
.with_context(|| format!("failed to create GPT file at `{}`", out_gpt_path.display()))?;
1717

1818
// set file size
19-
let partition_size: u64 = fs::metadata(&fat_image)
19+
let partition_size: u64 = fs::metadata(fat_image)
2020
.context("failed to read metadata of fat image")?
2121
.len();
2222
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<
6161
disk.seek(io::SeekFrom::Start(start_offset))
6262
.context("failed to seek to start offset")?;
6363
io::copy(
64-
&mut File::open(&fat_image).context("failed to open FAT image")?,
64+
&mut File::open(fat_image).context("failed to open FAT image")?,
6565
&mut disk,
6666
)
6767
.context("failed to copy FAT image to GPT disk")?;

Diff for: src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl UefiBoot {
127127
files.insert(KERNEL_FILE_NAME, self.kernel.as_path());
128128

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

133133
Ok(out_file)

Diff for: src/mbr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn create_mbr_disk(
6868
.truncate(true)
6969
.read(true)
7070
.write(true)
71-
.open(&out_mbr_path)
71+
.open(out_mbr_path)
7272
.with_context(|| {
7373
format!(
7474
"failed to create MBR disk image at `{}`",

Diff for: tests/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bootloader_test_runner::run_test_kernel;
55
#[test]
66
fn basic_boot() {
77
// build test kernel manually to force-enable link-time optimization
8-
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or("cargo".into()));
8+
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()));
99
cmd.arg("build");
1010
cmd.arg("-p").arg("test_kernel_lto");
1111
cmd.arg("--target").arg("x86_64-unknown-none");

0 commit comments

Comments
 (0)