Skip to content

Commit fb8c5e5

Browse files
committed
Merge branch 'master' into next
Signed-off-by: Joe Richey <[email protected]>
2 parents 2313b30 + cd9d748 commit fb8c5e5

File tree

15 files changed

+688
-242
lines changed

15 files changed

+688
-242
lines changed

Changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- `Port<T> = PortGeneric<T, ReadWriteAccess>`
77
- `PortReadOnly<T> = PortGeneric<T, ReadOnlyAccess>`
88
- `PortWriteOnly<T> = PortGeneric<T, WriteOnlyAccess>`
9-
- The following methods no longer require the `nightly` feature to be `const fn`s` ([#255](https://github.com/rust-osdev/x86_64/pull/255)):
9+
- The following methods no longer require the `nightly` feature to be `const fn`s ([#255](https://github.com/rust-osdev/x86_64/pull/255)):
1010
- `PageTable::new`
1111
- `GlobalDescriptorTable::from_raw_slice`
1212
- `MappedFrame::{start_address, size}`

src/addr.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -531,21 +531,25 @@ impl Sub<PhysAddr> for PhysAddr {
531531

532532
/// Align address downwards.
533533
///
534-
/// Returns the greatest x with alignment `align` so that x <= addr. The alignment must be
535-
/// a power of 2.
534+
/// Returns the greatest `x` with alignment `align` so that `x <= addr`.
535+
///
536+
/// Panics if the alignment is not a power of two. Without the `const_fn`
537+
/// feature, the panic message will be "index out of bounds".
536538
#[inline]
537-
pub fn align_down(addr: u64, align: u64) -> u64 {
538-
assert!(align.is_power_of_two(), "`align` must be a power of two");
539+
pub const fn align_down(addr: u64, align: u64) -> u64 {
540+
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
539541
addr & !(align - 1)
540542
}
541543

542544
/// Align address upwards.
543545
///
544-
/// Returns the smallest x with alignment `align` so that x >= addr. The alignment must be
545-
/// a power of 2.
546+
/// Returns the smallest `x` with alignment `align` so that `x >= addr`.
547+
///
548+
/// Panics if the alignment is not a power of two. Without the `const_fn`
549+
/// feature, the panic message will be "index out of bounds".
546550
#[inline]
547-
pub fn align_up(addr: u64, align: u64) -> u64 {
548-
assert!(align.is_power_of_two(), "`align` must be a power of two");
551+
pub const fn align_up(addr: u64, align: u64) -> u64 {
552+
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
549553
let align_mask = align - 1;
550554
if addr & align_mask == 0 {
551555
addr // already aligned

src/asm/asm.s

+36
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ _x86_64_asm_lidt:
123123
lidt (%rdi)
124124
retq
125125

126+
.global _x86_64_asm_sgdt
127+
.p2align 4
128+
_x86_64_asm_sgdt:
129+
sgdt (%rdi)
130+
retq
131+
126132
.global _x86_64_asm_sidt
127133
.p2align 4
128134
_x86_64_asm_sidt:
@@ -173,6 +179,36 @@ _x86_64_asm_load_gs:
173179
mov %di, %gs
174180
retq
175181

182+
.global _x86_64_asm_get_ss
183+
.p2align 4
184+
_x86_64_asm_get_ss:
185+
mov %ss, %ax
186+
retq
187+
188+
.global _x86_64_asm_get_ds
189+
.p2align 4
190+
_x86_64_asm_get_ds:
191+
mov %ds, %ax
192+
retq
193+
194+
.global _x86_64_asm_get_es
195+
.p2align 4
196+
_x86_64_asm_get_es:
197+
mov %es, %ax
198+
retq
199+
200+
.global _x86_64_asm_get_fs
201+
.p2align 4
202+
_x86_64_asm_get_fs:
203+
mov %fs, %ax
204+
retq
205+
206+
.global _x86_64_asm_get_gs
207+
.p2align 4
208+
_x86_64_asm_get_gs:
209+
mov %gs, %ax
210+
retq
211+
176212
.global _x86_64_asm_swapgs
177213
.p2align 4
178214
_x86_64_asm_swapgs:

src/asm/mod.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[link(name = "x86_64_asm", kind = "static")]
2-
extern "C" {
2+
extern "sysv64" {
33
#[cfg_attr(
44
any(target_env = "gnu", target_env = "musl"),
55
link_name = "_x86_64_asm_interrupt_enable"
@@ -114,6 +114,36 @@ extern "C" {
114114
)]
115115
pub(crate) fn x86_64_asm_load_gs(sel: u16);
116116

117+
#[cfg_attr(
118+
any(target_env = "gnu", target_env = "musl"),
119+
link_name = "_x86_64_asm_get_ss"
120+
)]
121+
pub(crate) fn x86_64_asm_get_ss() -> u16;
122+
123+
#[cfg_attr(
124+
any(target_env = "gnu", target_env = "musl"),
125+
link_name = "_x86_64_asm_get_ds"
126+
)]
127+
pub(crate) fn x86_64_asm_get_ds() -> u16;
128+
129+
#[cfg_attr(
130+
any(target_env = "gnu", target_env = "musl"),
131+
link_name = "_x86_64_asm_get_es"
132+
)]
133+
pub(crate) fn x86_64_asm_get_es() -> u16;
134+
135+
#[cfg_attr(
136+
any(target_env = "gnu", target_env = "musl"),
137+
link_name = "_x86_64_asm_get_fs"
138+
)]
139+
pub(crate) fn x86_64_asm_get_fs() -> u16;
140+
141+
#[cfg_attr(
142+
any(target_env = "gnu", target_env = "musl"),
143+
link_name = "_x86_64_asm_get_gs"
144+
)]
145+
pub(crate) fn x86_64_asm_get_gs() -> u16;
146+
117147
#[cfg_attr(
118148
any(target_env = "gnu", target_env = "musl"),
119149
link_name = "_x86_64_asm_swapgs"
@@ -138,6 +168,12 @@ extern "C" {
138168
)]
139169
pub(crate) fn x86_64_asm_lidt(idt: *const crate::instructions::tables::DescriptorTablePointer);
140170

171+
#[cfg_attr(
172+
any(target_env = "gnu", target_env = "musl"),
173+
link_name = "_x86_64_asm_sgdt"
174+
)]
175+
pub(crate) fn x86_64_asm_sgdt(gdt: *mut crate::instructions::tables::DescriptorTablePointer);
176+
141177
#[cfg_attr(
142178
any(target_env = "gnu", target_env = "musl"),
143179
link_name = "_x86_64_asm_sidt"

0 commit comments

Comments
 (0)