From 860821c1504f6d4cd39d45ab40e055daf6f6c276 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 26 Jul 2022 16:01:54 -0600 Subject: [PATCH] Support compilation on more architectures --- Cargo.lock | 4 ++-- acpid/Cargo.toml | 2 +- acpid/src/acpi.rs | 6 ++++++ ahcid/src/ahci/hba.rs | 4 ++-- nvmed/src/main.rs | 10 ++++++++++ nvmed/src/nvme/mod.rs | 16 ++++++++++++++-- nvmed/src/nvme/queues.rs | 2 +- ps2d/src/vm.rs | 10 +++++++++- vesad/src/display.rs | 30 ++++++++++++++++++++--------- vesad/src/main.rs | 6 ++---- vesad/src/primitive.rs | 38 ------------------------------------- vesad/src/screen/graphic.rs | 15 +++++++++++---- 12 files changed, 79 insertions(+), 64 deletions(-) delete mode 100644 vesad/src/primitive.rs diff --git a/Cargo.lock b/Cargo.lock index 986e168dba..0f5f5d06ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1107,9 +1107,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] diff --git a/acpid/Cargo.toml b/acpid/Cargo.toml index ecd8ad11b4..06fc3c698f 100644 --- a/acpid/Cargo.toml +++ b/acpid/Cargo.toml @@ -13,5 +13,5 @@ num-traits = "0.2" parking_lot = "0.11.1" plain = "0.2.3" redox-log = "0.1.1" -redox_syscall = "0.2.12" +redox_syscall = "0.2.16" thiserror = "1" diff --git a/acpid/src/acpi.rs b/acpid/src/acpi.rs index 697d5d445f..1fc4260578 100644 --- a/acpid/src/acpi.rs +++ b/acpid/src/acpi.rs @@ -14,6 +14,12 @@ use super::aml::AmlValue; pub mod dmar; use self::dmar::Dmar; +#[cfg(target_arch = "aarch64")] +pub const PAGE_SIZE: usize = 4096; + +#[cfg(target_arch = "x86")] +pub const PAGE_SIZE: usize = 4096; + #[cfg(target_arch = "x86_64")] pub const PAGE_SIZE: usize = 4096; diff --git a/ahcid/src/ahci/hba.rs b/ahcid/src/ahci/hba.rs index be469e948a..b798878772 100644 --- a/ahcid/src/ahci/hba.rs +++ b/ahcid/src/ahci/hba.rs @@ -112,9 +112,9 @@ impl HbaPort { } self.clb[0].write(clb.physical() as u32); - self.clb[1].write((clb.physical() >> 32) as u32); + self.clb[1].write(((clb.physical() as u64) >> 32) as u32); self.fb[0].write(fb.physical() as u32); - self.fb[1].write((fb.physical() >> 32) as u32); + self.fb[1].write(((fb.physical() as u64) >> 32) as u32); let is = self.is.read(); self.is.write(is); self.ie.write(0 /*TODO: Enable interrupts: 0b10111*/); diff --git a/nvmed/src/main.rs b/nvmed/src/main.rs index 6393be65e1..34e1e35141 100644 --- a/nvmed/src/main.rs +++ b/nvmed/src/main.rs @@ -51,6 +51,7 @@ pub struct AllocatedBars(pub [Mutex>; 6]); /// Get the most optimal yet functional interrupt mechanism: either (in the order of preference): /// MSI-X, MSI, and INTx# pin. Returns both runtime interrupt structures (MSI/MSI-X capability /// structures), and the handles to the interrupts. +#[cfg(target_arch = "x86_64")] fn get_int_method( pcid_handle: &mut PcidServerHandle, function: &PciFunction, @@ -214,6 +215,15 @@ fn get_int_method( } } +#[cfg(not(target_arch = "x86_64"))] +fn get_int_method( + pcid_handle: &mut PcidServerHandle, + function: &PciFunction, + allocated_bars: &AllocatedBars, +) -> Result<(InterruptMethod, InterruptSources)> { + todo!("handling of interrupts on non-x86_64") +} + fn setup_logging() -> Option<&'static RedoxLogger> { let mut logger = RedoxLogger::new() .with_output( diff --git a/nvmed/src/nvme/mod.rs b/nvmed/src/nvme/mod.rs index 9934f8a357..723c65593b 100644 --- a/nvmed/src/nvme/mod.rs +++ b/nvmed/src/nvme/mod.rs @@ -22,6 +22,18 @@ pub use self::queues::{NvmeCmd, NvmeCmdQueue, NvmeComp, NvmeCompQueue}; use pcid_interface::msi::{MsiCapability, MsixCapability, MsixTableEntry}; use pcid_interface::PcidServerHandle; +#[cfg(target_arch = "aarch64")] +#[inline(always)] +pub(crate) unsafe fn pause() { std::arch::x86::__yield(); } + +#[cfg(target_arch = "x86")] +#[inline(always)] +pub(crate) unsafe fn pause() { std::arch::x86::_mm_pause(); } + +#[cfg(target_arch = "x86_64")] +#[inline(always)] +pub(crate) unsafe fn pause() { std::arch::x86_64::_mm_pause(); } + /// Used in conjunction with `InterruptMethod`, primarily by the CQ reactor. #[derive(Debug)] pub enum InterruptSources { @@ -264,7 +276,7 @@ impl Nvme { let csts = self.regs.get_mut().unwrap().csts.read(); log::trace!("CSTS: {:X}", csts); if csts & 1 == 1 { - std::arch::x86_64::_mm_pause(); + pause(); } else { break; } @@ -318,7 +330,7 @@ impl Nvme { let csts = self.regs.get_mut().unwrap().csts.read(); log::debug!("CSTS: {:X}", csts); if csts & 1 == 0 { - std::arch::x86_64::_mm_pause(); + pause(); } else { break; } diff --git a/nvmed/src/nvme/queues.rs b/nvmed/src/nvme/queues.rs index 19783095a6..dfd0e6871f 100644 --- a/nvmed/src/nvme/queues.rs +++ b/nvmed/src/nvme/queues.rs @@ -82,7 +82,7 @@ impl NvmeCompQueue { if let Some(some) = self.complete() { return some; } else { - unsafe { std::arch::x86_64::_mm_pause() } + unsafe { super::pause(); } } } } diff --git a/ps2d/src/vm.rs b/ps2d/src/vm.rs index 97a014e7d5..c04185b480 100644 --- a/ps2d/src/vm.rs +++ b/ps2d/src/vm.rs @@ -26,6 +26,7 @@ pub const LEFT_BUTTON: u32 = 0x20; pub const RIGHT_BUTTON: u32 = 0x10; pub const MIDDLE_BUTTON: u32 = 0x08; +#[cfg(target_arch = "x86_64")] global_asm!(" .globl cmd_inner cmd_inner: @@ -54,7 +55,7 @@ cmd_inner: PORT = const PORT, ); -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[cfg(target_arch = "x86_64")] pub unsafe fn cmd(cmd: u32, arg: u32) -> (u32, u32, u32, u32, u32, u32) { extern "sysv64" { fn cmd_inner(array_ptr: *mut u32, cmd: u32, arg: u32); @@ -68,6 +69,13 @@ pub unsafe fn cmd(cmd: u32, arg: u32) -> (u32, u32, u32, u32, u32, u32) { (a, b, c, d, e, f) } +//TODO: is it possible to enable this on non-x86_64? +#[cfg(not(target_arch = "x86_64"))] +pub unsafe fn cmd(_cmd: u32, _arg: u32) -> (u32, u32, u32, u32, u32, u32) { + (0, 0, 0, 0, 0, 0) +} + +#[cfg(target_arch = "x86_64")] pub fn enable(relative: bool) -> bool { eprintln!("ps2d: Enable vmmouse"); diff --git a/vesad/src/display.rs b/vesad/src/display.rs index 8048b04c3f..c07e6bcf90 100644 --- a/vesad/src/display.rs +++ b/vesad/src/display.rs @@ -2,11 +2,9 @@ extern crate rusttype; use std::alloc::{Allocator, Global, Layout}; -use std::{cmp, slice}; +use std::{cmp, ptr, slice}; use std::ptr::NonNull; -use crate::primitive::{fast_set32, fast_copy}; - #[cfg(feature="rusttype")] use self::rusttype::{Font, FontCollection, Scale, point}; @@ -96,9 +94,17 @@ impl Display { for _y in 0..cmp::min(height, self.height) { unsafe { - fast_copy(new_ptr as *mut u8, old_ptr as *const u8, cmp::min(width, self.width) * 4); + ptr::copy( + old_ptr as *const u8, + new_ptr as *mut u8, + cmp::min(width, self.width) * 4 + ); if width > self.width { - fast_set32(new_ptr.offset(self.width as isize), 0, width - self.width); + ptr::write_bytes( + new_ptr.offset(self.width as isize), + 0, + width - self.width + ); } old_ptr = old_ptr.offset(self.width as isize); new_ptr = new_ptr.offset(width as isize); @@ -108,7 +114,7 @@ impl Display { if height > self.height { for _y in self.height..height { unsafe { - fast_set32(new_ptr, 0, width); + ptr::write_bytes(new_ptr, 0, width); new_ptr = new_ptr.offset(width as isize); } } @@ -145,8 +151,10 @@ impl Display { let mut rows = end_y - start_y; while rows > 0 { - unsafe { - fast_set32(offscreen_ptr as *mut u32, color, len); + for i in 0..len { + unsafe { + *(offscreen_ptr as *mut u32).add(i) = color; + } } offscreen_ptr += stride; rows -= 1; @@ -279,7 +287,11 @@ impl Display { let mut rows = end_y - start_y; while rows > 0 { unsafe { - fast_copy(onscreen_ptr as *mut u8, offscreen_ptr as *const u8, len); + ptr::copy( + offscreen_ptr as *const u8, + onscreen_ptr as *mut u8, + len + ); } offscreen_ptr += stride; onscreen_ptr += stride; diff --git a/vesad/src/main.rs b/vesad/src/main.rs index 4df6644003..ed1bdc0965 100644 --- a/vesad/src/main.rs +++ b/vesad/src/main.rs @@ -3,17 +3,15 @@ extern crate orbclient; extern crate syscall; -use std::{env, process}; +use std::{env, process, ptr}; use std::fs::File; use std::io::{Read, Write}; use std::os::unix::io::{RawFd, FromRawFd}; use syscall::{physmap, physunmap, Packet, SchemeMut, EVENT_READ, PHYSMAP_WRITE, PHYSMAP_WRITE_COMBINE}; -use crate::primitive::fast_set64; use crate::scheme::{DisplayScheme, HandleKind}; pub mod display; -pub mod primitive; pub mod scheme; pub mod screen; @@ -74,7 +72,7 @@ fn main() { //TODO: Remap on resize let largest_size = 8 * 1024 * 1024; let onscreen = unsafe { physmap(physbaseptr, largest_size * 4, PHYSMAP_WRITE | PHYSMAP_WRITE_COMBINE).expect("vesad: failed to map VBE LFB") }; - unsafe { fast_set64(onscreen as *mut u64, 0, size/2) }; + unsafe { ptr::write_bytes(onscreen as *mut u32, 0, size); } let mut scheme = DisplayScheme::new(width, height, onscreen, &spec); diff --git a/vesad/src/primitive.rs b/vesad/src/primitive.rs deleted file mode 100644 index 3879c4f99b..0000000000 --- a/vesad/src/primitive.rs +++ /dev/null @@ -1,38 +0,0 @@ -use core::arch::asm; - -#[cfg(target_arch = "x86_64")] -#[inline(always)] -pub unsafe fn fast_copy(dst: *mut u8, src: *const u8, len: usize) { - // direction flag must always be cleared, as per the System V ABI - asm!("rep movsb", - inout("rdi") dst as usize => _, inout("rsi") src as usize => _, inout("rcx") len => _, - options(nostack, preserves_flags), - ); -} - -#[cfg(target_arch = "x86_64")] -#[inline(always)] -pub unsafe fn fast_copy64(dst: *mut u64, src: *const u64, len: usize) { - asm!("rep movsq", - inout("rdi") dst as usize => _, inout("rsi") src as usize => _, inout("rcx") len => _, - options(nostack, preserves_flags), - ); -} - -#[cfg(target_arch = "x86_64")] -#[inline(always)] -pub unsafe fn fast_set32(dst: *mut u32, src: u32, len: usize) { - asm!("rep stosd", - inout("rdi") dst as usize => _, in("eax") src, inout("rcx") len => _, - options(nostack, preserves_flags), - ); -} - -#[cfg(target_arch = "x86_64")] -#[inline(always)] -pub unsafe fn fast_set64(dst: *mut u64, src: u64, len: usize) { - asm!("rep stosq", - inout("rdi") dst as usize => _, in("rax") src, inout("rcx") len => _, - options(nostack, preserves_flags), - ); -} diff --git a/vesad/src/screen/graphic.rs b/vesad/src/screen/graphic.rs index 1f5ac5ea3f..1dd5df6533 100644 --- a/vesad/src/screen/graphic.rs +++ b/vesad/src/screen/graphic.rs @@ -1,12 +1,11 @@ use std::collections::VecDeque; -use std::{cmp, mem, slice}; +use std::{cmp, mem, ptr, slice}; use orbclient::{Event, ResizeEvent}; use syscall::error::*; use syscall::flag::{SEEK_SET, SEEK_CUR, SEEK_END}; use crate::display::Display; -use crate::primitive::fast_copy; use crate::screen::Screen; pub struct GraphicScreen { @@ -81,9 +80,17 @@ impl Screen for GraphicScreen { if size > 0 { unsafe { - fast_copy(self.display.offscreen.as_mut_ptr().offset(self.seek as isize) as *mut u8, buf.as_ptr(), size * 4); + ptr::copy( + buf.as_ptr(), + self.display.offscreen.as_mut_ptr().offset(self.seek as isize) as *mut u8, + size * 4 + ); if sync { - fast_copy(self.display.onscreen.as_mut_ptr().offset(self.seek as isize) as *mut u8, buf.as_ptr(), size * 4); + ptr::copy( + buf.as_ptr(), + self.display.onscreen.as_mut_ptr().offset(self.seek as isize) as *mut u8, + size * 4 + ); } } }