diff --git a/src/librustc_target/spec/aarch64_unknown_redox.rs b/src/librustc_target/spec/aarch64_unknown_redox.rs new file mode 100644 index 0000000000000000000000000000000000000000..e85f90d8825fbe8796f500e9c249038ed8f919fb --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_redox.rs @@ -0,0 +1,30 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::redox_base::opts(); + base.max_atomic_width = Some(128); + + Ok(Target { + llvm_target: "aarch64-unknown-redox".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + target_os: "redox".to_string(), + target_env: "".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 46fefd78f45197632d36f219b0d07466e35cd605..a8520b241b0d425318aed8976d9990e10a7427f5 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -416,6 +416,7 @@ fn $module() { ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc), + ("aarch64-unknown-redox", aarch64_unknown_redox), ("x86_64-unknown-redox", x86_64_unknown_redox), ("i386-apple-ios", i386_apple_ios), diff --git a/src/librustc_target/spec/redox_base.rs b/src/librustc_target/spec/redox_base.rs index dc51aeb58391ffa6e9905c0e69ccdeb607602609..38ed750ed8b9c0c30c56f867729f1fbb70eab5ec 100644 --- a/src/librustc_target/spec/redox_base.rs +++ b/src/librustc_target/spec/redox_base.rs @@ -23,7 +23,7 @@ pub fn opts() -> TargetOptions { relocation_model: "static".to_string(), disable_redzone: true, eliminate_frame_pointer: false, - target_family: None, + target_family: Some("redox".to_string()), linker_is_gnu: true, has_elf_tls: true, .. Default::default() diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 71e82f0a9b02e3fe6b1652253e99f9d8f32083c2..d048af024cf6003cacac52ba8be95bd458c1d18c 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -182,6 +182,11 @@ pub enum Prefix<'a> { /// Prefix `C:` for the given disk drive. #[stable(feature = "rust1", since = "1.0.0")] Disk(#[stable(feature = "rust1", since = "1.0.0")] u8), + + /// Scheme `file:` used on Redox + #[cfg(target_os = "redox")] + #[stable(feature = "rust1", since = "1.0.0")] + Scheme(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr), } impl<'a> Prefix<'a> { @@ -212,6 +217,7 @@ fn os_str_len(s: &OsStr) -> usize { }, DeviceNS(x) => 4 + os_str_len(x), Disk(_) => 2, + Scheme(x) => 1 + os_str_len(x), } } @@ -313,11 +319,6 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr { &*(s as *const [u8] as *const OsStr) } -// Detect scheme on Redox -fn has_redox_scheme(s: &[u8]) -> bool { - cfg!(target_os = "redox") && s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':') -} - //////////////////////////////////////////////////////////////////////////////// // Cross-platform, iterator-independent parsing //////////////////////////////////////////////////////////////////////////////// @@ -1900,12 +1901,7 @@ pub fn to_path_buf(&self) -> PathBuf { #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] pub fn is_absolute(&self) -> bool { - if cfg!(target_os = "redox") { - // FIXME: Allow Redox prefixes - self.has_root() || has_redox_scheme(self.as_u8_slice()) - } else { - self.has_root() && (cfg!(unix) || self.prefix().is_some()) - } + self.has_root() && (cfg!(unix) || self.prefix().is_some()) } /// Returns `true` if the `Path` is relative, i.e., not absolute. @@ -2310,8 +2306,7 @@ pub fn components(&self) -> Components<'_> { Components { path: self.as_u8_slice(), prefix, - has_physical_root: has_physical_root(self.as_u8_slice(), prefix) || - has_redox_scheme(self.as_u8_slice()), + has_physical_root: has_physical_root(self.as_u8_slice(), prefix), front: State::Prefix, back: State::Body, } diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index 0e8ed8e303d43a046d8ca236dce365a44c0111cf..77cdd4355b6d4da5975265111585cb0ff3c949d7 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -92,6 +92,29 @@ pub fn cvt_libc<T: IsMinusOne>(t: T) -> crate::io::Result<T> { } } +#[doc(hidden)] +pub trait IsMinusOne { + fn is_minus_one(&self) -> bool; +} + +macro_rules! impl_is_minus_one { + ($($t:ident)*) => ($(impl IsMinusOne for $t { + fn is_minus_one(&self) -> bool { + *self == -1 + } + })*) +} + +impl_is_minus_one! { i8 i16 i32 i64 isize } + +pub fn cvt_libc<T: IsMinusOne>(t: T) -> io::Result<T> { + if t.is_minus_one() { + Err(io::Error::last_os_error()) + } else { + Ok(t) + } +} + /// On Redox, use an illegal instruction to abort pub unsafe fn abort_internal() -> ! { core::intrinsics::abort(); diff --git a/src/libstd/sys/redox/path.rs b/src/libstd/sys/redox/path.rs index b62d6c9878211ae95b7dee1a2a9b705bfa0beb3d..c1da12416e311f30f80507cf1ca75f14fef7e3ca 100644 --- a/src/libstd/sys/redox/path.rs +++ b/src/libstd/sys/redox/path.rs @@ -13,10 +13,8 @@ pub fn is_verbatim_sep(b: u8) -> bool { pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> { if let Some(path_str) = path.to_str() { - if let Some(_i) = path_str.find(':') { - // FIXME: Redox specific prefix - // Some(Prefix::Verbatim(OsStr::new(&path_str[..i]))) - None + if let Some(i) = path_str.find(':') { + Some(Prefix::Scheme(OsStr::new(&path_str[..i]))) } else { None } diff --git a/src/libstd/sys/redox/syscall/arch/aarch64.rs b/src/libstd/sys/redox/syscall/arch/aarch64.rs new file mode 100644 index 0000000000000000000000000000000000000000..662f428d04cff535d246e83a858f2c04fd0c25aa --- /dev/null +++ b/src/libstd/sys/redox/syscall/arch/aarch64.rs @@ -0,0 +1,77 @@ +use super::error::{Error, Result}; + +pub unsafe fn syscall0(mut a: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a) + : "x0", "x8" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b) + : "x0", "x8" + : "volatile"); + + Error::demux(a) +} + +// Clobbers all registers - special for clone +pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b) + : "memory", + "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", + "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", + "x16", "x17","x18", "x19", "x20", "x21", "x22", "x23", + "x24", "x25", "x26", "x27", "x28", "x29", "x30" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b), "{x1}"(c) + : "x0", "x1", "x8" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d) + : "x0", "x1", "x2", "x8" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e) + : "x0", "x1", "x2", "x3", "x8" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result<usize> { + asm!("svc 0" + : "={x0}"(a) + : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e), "{x4}"(f) + : "x0", "x1", "x2", "x3", "x4", "x8" + : "volatile"); + + Error::demux(a) +} diff --git a/src/libstd/sys/redox/syscall/mod.rs b/src/libstd/sys/redox/syscall/mod.rs index b16f5dbd918e8a918da65695076257cfb143e651..6607531876cfcb56b43ca3d251002176a46cb29f 100644 --- a/src/libstd/sys/redox/syscall/mod.rs +++ b/src/libstd/sys/redox/syscall/mod.rs @@ -9,6 +9,10 @@ #[path="arch/arm.rs"] mod arch; +#[cfg(target_arch = "aarch64")] +#[path="arch/aarch64.rs"] +mod arch; + #[cfg(target_arch = "x86")] #[path="arch/x86.rs"] mod arch; diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 61cc78ad807af23c395d008ced9a3f6c8611ebaf..3a9ed7ccd942ca28c23f748620fceff5d17e66ab 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -48,6 +48,7 @@ "aarch64-unknown-cloudabi", "aarch64-unknown-linux-gnu", "aarch64-unknown-linux-musl", + "aarch64-unknown-redox", "arm-linux-androideabi", "arm-unknown-linux-gnueabi", "arm-unknown-linux-gnueabihf",