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

.github/workflows/ci.yml

Lines changed: 19 additions & 24 deletions
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/rust-problem-matchers@v1.1.0
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/rust-problem-matchers@v1.1.0
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/rust-problem-matchers@v1.1.0
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/rust-problem-matchers@v1.1.0
81+
- run: cargo clippy --all --all-targets

api/build.rs

Lines changed: 1 addition & 1 deletion
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();

api/src/config.rs

Lines changed: 3 additions & 4 deletions
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`].

bios/boot_sector/src/main.rs

Lines changed: 8 additions & 3 deletions
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
}

bios/boot_sector/src/mbr.rs

Lines changed: 1 addition & 1 deletion
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');

bios/common/src/lib.rs

Lines changed: 4 additions & 0 deletions
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+
}

bios/common/src/racy_cell.rs

Lines changed: 5 additions & 0 deletions
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
}

bios/stage-2/src/disk.rs

Lines changed: 1 addition & 1 deletion
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;

bios/stage-2/src/fat.rs

Lines changed: 4 additions & 4 deletions
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 =

bios/stage-2/src/main.rs

Lines changed: 6 additions & 4 deletions
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(

0 commit comments

Comments
 (0)