Skip to content

Merge latest changes from master into next and migrate code #338

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 76 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
62b7895
Fix CI tests on Windows (#297)
phil-opp Aug 18, 2021
a5a3a34
Run `cargo doc` in our CI job
phil-opp Aug 1, 2021
acfa59c
Use `#[cfg(doc)]` instead of docs.rs-specific cfg flag
phil-opp Aug 1, 2021
17ca2b0
Add doc_cfg for annotations on nightly
josephlr Aug 14, 2021
5354b02
CI: add cargo doc run using stable features
josephlr Aug 14, 2021
a9cbf14
Merge pull request #287 from rust-osdev/fix-cargo-doc-warnings
josephlr Aug 18, 2021
f6dbd97
docs(idt): remove a panic info
toku-sa-n Aug 29, 2021
278e1fe
feat(mapper): expose `MapperFlush(All)?::new`
toku-sa-n Aug 15, 2021
4ced281
Merge pull request #296 from toku-sa-n/flush_new
josephlr Aug 29, 2021
0290fa1
fix gdt load docs to cover deprecation
Aug 29, 2021
da4f8c4
Merge pull request #301 from ncatelli/documentation/fix-load-segment-…
josephlr Aug 29, 2021
62f99df
fix(gdt): typo
toku-sa-n Aug 30, 2021
09dc430
docs: Fix links by importing Segment trait
josephlr Sep 1, 2021
cf5efe5
Merge pull request #300 from toku-sa-n/fix_doc
josephlr Sep 1, 2021
27ab505
Merge pull request #302 from toku-sa-n/fix_typo
josephlr Sep 1, 2021
cd4d3c2
Add `clean_up` and `clean_up_with_filter` (#264)
Freax13 Sep 5, 2021
78c4a5d
Bump bit_field to 0.10.1
mkroening Sep 6, 2021
c83f36c
Add missing flags to PageFaultErrorCode
npmccallum Sep 4, 2021
611d7d9
Merge pull request #306 from mkroening/bit_field-upgrade
josephlr Sep 12, 2021
137f555
Add the ExceptionVector type
npmccallum Sep 4, 2021
79ce148
Merge pull request #303 from npmccallum/errors
josephlr Sep 13, 2021
8be29ff
Update changelog
phil-opp Sep 4, 2021
633abc3
Bump version to 0.14.5
phil-opp Sep 4, 2021
0edc4aa
Update changelog for #264, #303, #306
phil-opp Sep 5, 2021
05b5f4f
Merge pull request #304 from rust-osdev/patch-release
josephlr Sep 13, 2021
a280bbe
Move segment types into a new `registers::segmentation` module
phil-opp Sep 17, 2021
022598a
Merge pull request #309 from rust-osdev/fix-307
josephlr Sep 20, 2021
2f79eec
Update Changelog to include #309
josephlr Sep 20, 2021
7fd711b
Update version to 0.14.6
josephlr Sep 20, 2021
31172ac
Merge pull request #310 from rust-osdev/patch-release
phil-opp Sep 21, 2021
0ad7789
fix: enable manipulation of `InterruptStackFrame`
haraldh Oct 14, 2021
6461745
Merge pull request #312 from haraldh/isr_frame
josephlr Oct 15, 2021
a1fd7c3
Add the VMM Communication Exception (#VC) to the InterruptDescriptorT…
haraldh Oct 15, 2021
bf3c5ca
add derives to number and range types
Freax13 Oct 25, 2021
f156013
add derives to enum types
Freax13 Oct 25, 2021
31b3d1c
fix docs for `page_table_index`
Freax13 Oct 27, 2021
e89bbb1
Merge pull request #318 from Freax13/fix-docs
josephlr Oct 30, 2021
0e80711
Adjust vector number range in docs
phil-opp Nov 6, 2021
2c9d4ca
Merge pull request #313 from haraldh/vmm_communication_exception
phil-opp Nov 6, 2021
e8aee52
Remove redundant alignment check (#314)
mpajkowski Nov 6, 2021
640d425
remove some `PartialOrd`, `Ord` derives
Nov 7, 2021
f9b134e
add set_general_handler macro
Freax13 Jul 26, 2021
8695b39
add `GeneralHandlerFunc` for `set_general_handler`
Nov 7, 2021
d41756a
use `u8` instead of `usize`
Nov 7, 2021
43233b6
fix tests
Nov 7, 2021
6ba1dd6
put `set_general_handler` behind feature gate
Nov 7, 2021
be14601
support `vmm_communication_exception`
Nov 7, 2021
e633293
fix clippy warning in test
Nov 7, 2021
9b0065d
don't run `default_handlers` test on windows
Nov 7, 2021
e447d88
skip `set_general_handler` in doctests on windows
Nov 7, 2021
f4c2e26
Merge pull request #285 from Freax13/default-irq-handler
phil-opp Nov 7, 2021
129fa95
Merge pull request #315 from Freax13/add-derives
phil-opp Nov 8, 2021
498fa5c
fix(idt): fix panic messages for `index` and #VC (#321)
haraldh Nov 14, 2021
36a9243
remove `const_assert!` in favor of std's `assert!`
Freax13 Dec 2, 2021
55d5fad
Merge pull request #326 from Freax13/const-panic
Freax13 Dec 5, 2021
a9a8344
enable `unsafe_block_in_unsafe_fn` lint
Freax13 Dec 13, 2021
2a719f8
remove `allow(unused_unsafe)`
Freax13 Dec 13, 2021
af206af
fix: build error on the latest nightly
toku-sa-n Dec 16, 2021
3efa410
refactor: import inside the `x86_64` module
toku-sa-n Dec 17, 2021
ae44fab
Move bootloader integration test to separate CI job
phil-opp Dec 18, 2021
449f6b9
Merge PR #330
phil-opp Dec 18, 2021
575de31
Merge pull request #329 from toku-sa-n/fix_asm
phil-opp Dec 18, 2021
c693806
Update changelog
phil-opp Dec 18, 2021
e94d694
Merge pull request #328 from Freax13/unsafe_block_in_unsafe_fn
Freax13 Dec 18, 2021
680d098
Bump version to 0.14.7
phil-opp Dec 18, 2021
bb82677
Merge pull request #331 from rust-osdev/release
phil-opp Dec 18, 2021
4b525bb
add `Cr2::read_raw`
Freax13 Jan 16, 2022
38537d1
improve doc comment
Freax13 Jan 17, 2022
5014113
Merge pull request #334 from Freax13/cr2-read-raw
Freax13 Jan 17, 2022
d2ad56a
registers: MXCSR
jarkkojs Jan 21, 2022
e730686
Merge pull request #336 from jarkkojs/master
Freax13 Jan 28, 2022
c449106
Merge branch 'master' into next
phil-opp Feb 3, 2022
ea00bfd
Unsafe blocks are now required in `unsafe fn`s too (since #328)
phil-opp Feb 3, 2022
5efea6a
Page table are now indexed with `u8` instead of `usize`
phil-opp Feb 3, 2022
d9eb7f6
Update test for new `InterruptStackFrame` format
phil-opp Feb 3, 2022
b820a2e
The `level_4_table` function only returns an immutable reference sinc…
phil-opp Feb 3, 2022
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
67 changes: 50 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,29 @@ jobs:
rustc -Vv
cargo -Vv

- name: Cache binaries
id: cache-bin
uses: actions/cache@v1
with:
path: binaries
key: ${{ runner.OS }}-binaries
- name: Add binaries/bin to PATH
run: echo "$GITHUB_WORKSPACE/binaries/bin" >> $GITHUB_PATH
shell: bash

- name: "Run cargo build"
uses: actions-rs/cargo@v1
with:
command: build

- name: "Run cargo doc"
uses: actions-rs/cargo@v1
with:
command: doc

- name: "Run cargo doc for stable"
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-default-features --features external_asm,instructions
if: runner.os != 'Windows'

- name: "Run cargo doc without default features"
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-default-features

- name: "Run cargo build for stable without instructions"
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -113,6 +121,35 @@ jobs:
cargo build --target i686-unknown-linux-gnu --no-default-features --features nightly
cargo build --target thumbv7em-none-eabihf --no-default-features --features nightly

bootloader-test:
name: "Bootloader Integration Test"

strategy:
fail-fast: false
matrix:
platform: [
ubuntu-latest,
macos-latest,
windows-latest
]

runs-on: ${{ matrix.platform }}
timeout-minutes: 15

steps:
- name: "Checkout Repository"
uses: actions/checkout@v1

- name: Cache binaries
id: cache-bin
uses: actions/cache@v1
with:
path: binaries
key: ${{ runner.OS }}-binaries
- name: Add binaries/bin to PATH
run: echo "$GITHUB_WORKSPACE/binaries/bin" >> $GITHUB_PATH
shell: bash

- name: "Install Rustup Components"
run: rustup component add rust-src llvm-tools-preview
- name: "Install cargo-xbuild"
Expand All @@ -133,14 +170,10 @@ jobs:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: Install Scoop (Windows)
run: |
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
echo "$HOME\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
if: runner.os == 'Windows'
shell: pwsh
- name: Install QEMU (Windows)
run: scoop install qemu
run: |
choco install qemu --version 2021.5.5
echo "$Env:Programfiles\qemu" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
if: runner.os == 'Windows'
shell: pwsh

Expand Down
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ license = "MIT/Apache-2.0"
name = "x86_64"
readme = "README.md"
repository = "https://github.com/rust-osdev/x86_64"
version = "0.14.4"
version = "0.14.7"
edition = "2018"

[dependencies]
bit_field = "0.9.0"
bit_field = "0.10.1"
bitflags = "1.3.2"
volatile = "0.4.4"

Expand All @@ -37,13 +37,11 @@ cc = { version = "1.0.37", optional = true }
default = [ "nightly", "instructions" ]
instructions = []
external_asm = [ "cc" ]
nightly = [ "inline_asm", "const_fn", "abi_x86_interrupt" ]
nightly = [ "inline_asm", "const_fn", "abi_x86_interrupt", "doc_cfg" ]
inline_asm = []
abi_x86_interrupt = []
const_fn = []

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
doc_cfg = []

[package.metadata.release]
no-dev-version = true
Expand Down
33 changes: 33 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Unreleased

# 0.14.7 – 2021-12-18

- fix: build error on the latest nightly ([#329](https://github.com/rust-osdev/x86_64/pull/329))
- add `set_general_handler` macro ([#285](https://github.com/rust-osdev/x86_64/pull/285))
- Derive common traits for number, range and enum types ([#315](https://github.com/rust-osdev/x86_64/pull/315))
- Add the VMM Communication Exception (`#VC`) to the `InterruptDescriptorTable` ([#313](https://github.com/rust-osdev/x86_64/pull/313))
- fix: enable manipulation of `InterruptStackFrame` ([#312](https://github.com/rust-osdev/x86_64/pull/312))
- fix docs for `page_table_index` ([#318](https://github.com/rust-osdev/x86_64/pull/318))
- Remove redundant alignment check ([#314](https://github.com/rust-osdev/x86_64/pull/314))
- fix(idt): fix panic messages for `index` and `#VC` ([#321](https://github.com/rust-osdev/x86_64/pull/321))
- remove `const_assert!` in favor of std's `assert!` ([#326](https://github.com/rust-osdev/x86_64/pull/326))
- Move bootloader integration test to separate CI job ([#330](https://github.com/rust-osdev/x86_64/pull/330))

# 0.14.6 – 2021-09-20

- New `registers::segmentation` module ([#309](https://github.com/rust-osdev/x86_64/pull/309)), containing:
- `instructions::segmentation::{Segment, Segment64, CS, DS, ES, FS, GS, SS}`
- `structures::gdt::SegmentSelector`
- Old locations still re-export all the types, so this is not a breaking change.
- Fixes build so that `cargo doc --no-default-features` succeeds.

# 0.14.5 – 2021-09-04

- Add `ExceptionVector` enum and additional flags to `PageFaultErrorCode` ([#303](https://github.com/rust-osdev/x86_64/pull/303))
- Add `clean_up` and `clean_up_with_filter` methods to deallocate unused page tables ([#264](https://github.com/rust-osdev/x86_64/pull/264))
- Rename some XCr0 and CR4 flags (#[275](https://github.com/rust-osdev/x86_64/pull/275))
- Expose `MapperFlush::new` and `MapperFlushAll::new` constructor functions ([#296](https://github.com/rust-osdev/x86_64/pull/296))
- Use `#[cfg(doc)]` instead of docs.rs-specific cfg flag (#[287](https://github.com/rust-osdev/x86_64/pull/287))
- Some documentation updates:
- Update segment register references in `GDT::load*` method to non-deprecated methods ([#301](https://github.com/rust-osdev/x86_64/pull/301))
- Remove a panic note ([#300](https://github.com/rust-osdev/x86_64/pull/300))
- Update `bit_field` dependency ([#306](https://github.com/rust-osdev/x86_64/pull/306))

# 0.14.4 – 2021-07-19

- Add `instructions::tables::sgdt` ([#279](https://github.com/rust-osdev/x86_64/pull/279))
Expand Down
15 changes: 11 additions & 4 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use core::fmt;
use core::ops::{Add, AddAssign, Sub, SubAssign};

use crate::structures::paging::page_table::PageTableLevel;
use crate::structures::paging::{PageOffset, PageTableIndex};
use bit_field::BitField;

Expand All @@ -16,7 +17,7 @@ use bit_field::BitField;
/// On `x86_64`, only the 48 lower bits of a virtual address can be used. The top 16 bits need
/// to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterium
/// are called “canonical”. This type guarantees that it always represents a canonical address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct VirtAddr(u64);

Expand All @@ -29,7 +30,7 @@ pub struct VirtAddr(u64);
///
/// On `x86_64`, only the 52 lower bits of a physical address can be used. The top 12 bits need
/// to be zero. This type guarantees that it always represents a valid physical address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct PhysAddr(u64);

Expand Down Expand Up @@ -198,6 +199,12 @@ impl VirtAddr {
pub const fn p4_index(self) -> PageTableIndex {
PageTableIndex::new_truncate((self.0 >> 12 >> 9 >> 9 >> 9) as u16)
}

/// Returns the 9-bit level page table index.
#[inline]
pub const fn page_table_index(self, level: PageTableLevel) -> PageTableIndex {
PageTableIndex::new_truncate((self.0 >> 12 >> ((level as u8 - 1) * 9)) as u16)
}
}

impl fmt::Debug for VirtAddr {
Expand Down Expand Up @@ -537,7 +544,7 @@ impl Sub<PhysAddr> for PhysAddr {
/// feature, the panic message will be "index out of bounds".
#[inline]
pub const fn align_down(addr: u64, align: u64) -> u64 {
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
assert!(align.is_power_of_two(), "`align` must be a power of two");
addr & !(align - 1)
}

Expand All @@ -549,7 +556,7 @@ pub const fn align_down(addr: u64, align: u64) -> u64 {
/// feature, the panic message will be "index out of bounds".
#[inline]
pub const fn align_up(addr: u64, align: u64) -> u64 {
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
assert!(align.is_power_of_two(), "`align` must be a power of two");
let align_mask = align - 1;
if addr & align_mask == 0 {
addr // already aligned
Expand Down
16 changes: 16 additions & 0 deletions src/asm/asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,19 @@ _x86_64_asm_xsetbv:
movl %esi, %eax # Second param is the low 32-bits
xsetbv # Third param (high 32-bits) is already in %edx
retq

.global _x86_64_asm_write_mxcsr
.p2align 4
_x86_64_asm_write_mxcsr:
pushq %rdi
ldmxcsr (%rsp)
popq %rdi
retq

.global _x86_64_asm_read_mxcsr
.p2align 4
_x86_64_asm_read_mxcsr:
pushq $0
stmxcsr (%rsp)
popq %rax
retq
12 changes: 12 additions & 0 deletions src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,16 @@ extern "sysv64" {
link_name = "_x86_64_asm_xsetbv"
)]
pub(crate) fn x86_64_asm_xsetbv(xcr: u32, low: u32, high: u32);

#[cfg_attr(
any(target_env = "gnu", target_env = "musl"),
link_name = "_x86_64_asm_read_mxcsr"
)]
pub(crate) fn x86_64_asm_read_mxcsr() -> u32;

#[cfg_attr(
any(target_env = "gnu", target_env = "musl"),
link_name = "_x86_64_asm_write_mxcsr"
)]
pub(crate) fn x86_64_asm_write_mxcsr(val: u32);
}
12 changes: 10 additions & 2 deletions src/instructions/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Enabling and disabling interrupts

#[cfg(feature = "inline_asm")]
use core::arch::asm;

/// Returns whether interrupts are enabled.
#[inline]
pub fn are_enabled() -> bool {
Expand Down Expand Up @@ -156,7 +159,12 @@ pub fn int3() {
/// It can also cause memory/register corruption depending on the interrupt
/// implementation (if it expects values/pointers to be passed in registers).
#[cfg(feature = "inline_asm")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(feature = "nightly", feature = "inline_asm")))
)]
pub unsafe fn software_interrupt<const NUM: u8>() {
asm!("int {num}", num = const NUM, options(nomem, nostack));
unsafe {
asm!("int {num}", num = const NUM, options(nomem, nostack));
}
}
8 changes: 7 additions & 1 deletion src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub mod segmentation;
pub mod tables;
pub mod tlb;

#[cfg(feature = "inline_asm")]
use core::arch::asm;

/// Halts the CPU until the next interrupt arrives.
#[inline]
pub fn hlt() {
Expand Down Expand Up @@ -54,7 +57,10 @@ pub fn bochs_breakpoint() {
/// Gets the current instruction pointer. Note that this is only approximate as it requires a few
/// instructions to execute.
#[cfg(feature = "inline_asm")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(feature = "nightly", feature = "inline_asm")))
)]
#[inline(always)]
pub fn read_rip() -> crate::VirtAddr {
let rip: u64;
Expand Down
Loading