Skip to content
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

Add initial support for m68k #88321

Merged
merged 12 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn main() {
"aarch64",
"amdgpu",
"avr",
"m68k",
"mips",
"powerpc",
"systemz",
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ void LLVMRustAddLastExtensionPasses(
#define SUBTARGET_AVR
#endif

#ifdef LLVM_COMPONENT_M68k
#define SUBTARGET_M68K SUBTARGET(M68k)
#else
#define SUBTARGET_M68K
#endif

#ifdef LLVM_COMPONENT_MIPS
#define SUBTARGET_MIPS SUBTARGET(Mips)
#else
Expand Down Expand Up @@ -248,6 +254,7 @@ void LLVMRustAddLastExtensionPasses(
SUBTARGET_ARM \
SUBTARGET_AARCH64 \
SUBTARGET_AVR \
SUBTARGET_M68K \
SUBTARGET_MIPS \
SUBTARGET_PPC \
SUBTARGET_SYSTEMZ \
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ pub fn initialize_available_targets() {
LLVMInitializeAVRAsmPrinter,
LLVMInitializeAVRAsmParser
);
init_target!(
llvm_component = "m68k",
LLVMInitializeM68kTargetInfo,
LLVMInitializeM68kTarget,
LLVMInitializeM68kTargetMC,
LLVMInitializeM68kAsmPrinter,
LLVMInitializeM68kAsmParser
);
init_target!(
llvm_component = "mips",
LLVMInitializeMipsTargetInfo,
Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_target/src/abi/call/m68k.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::abi::call::{ArgAbi, FnAbi};

fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if ret.layout.is_aggregate() {
ret.make_indirect();
} else {
ret.extend_integer_width_to(32);
}
}

fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
if arg.layout.is_aggregate() {
arg.make_indirect_byval();
} else {
arg.extend_integer_width_to(32);
}
}

pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
if !fn_abi.ret.is_ignore() {
classify_ret(&mut fn_abi.ret);
}

for arg in &mut fn_abi.args {
if arg.is_ignore() {
continue;
}
classify_arg(arg);
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod arm;
mod avr;
mod bpf;
mod hexagon;
mod m68k;
mod mips;
mod mips64;
mod msp430;
Expand Down Expand Up @@ -634,6 +635,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
"amdgpu" => amdgpu::compute_abi_info(cx, self),
"arm" => arm::compute_abi_info(cx, self),
"avr" => avr::compute_abi_info(self),
"m68k" => m68k::compute_abi_info(self),
"mips" => mips::compute_abi_info(cx, self),
"mips64" => mips64::compute_abi_info(cx, self),
"powerpc" => powerpc::compute_abi_info(self),
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::abi::Endian;
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_base::opts();
base.max_atomic_width = Some(32);

Target {
llvm_target: "m68k-unknown-linux-gnu".to_string(),
pointer_width: 32,
data_layout: "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16".to_string(),
arch: "m68k".to_string(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base },
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ supported_targets! {
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),
("mips64el-unknown-linux-gnuabi64", mips64el_unknown_linux_gnuabi64),
Expand Down
2 changes: 1 addition & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ changelog-seen = 2
# the same format as above, but since these targets are experimental, they are
# not built by default and the experimental Rust compilation targets that depend
# on them will not work unless the user opts in to building them.
#experimental-targets = "AVR"
#experimental-targets = "AVR;M68k"

# Cap the number of parallel linker invocations when compiling LLVM.
# This can be useful when building LLVM with debug info, which significantly
Expand Down
1 change: 1 addition & 0 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ pub mod consts {
/// - x86_64
/// - arm
/// - aarch64
/// - m68k
/// - mips
/// - mips64
/// - powerpc
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
#[cfg(any(
target_arch = "x86",
target_arch = "le32",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "sparc",
target_arch = "arm",
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def default_build_triple(verbose):
'i486': 'i686',
'i686': 'i686',
'i786': 'i686',
'm68k': 'm68k',
'powerpc': 'powerpc',
'powerpc64': 'powerpc64',
'powerpc64le': 'powerpc64le',
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Step for Llvm {

let llvm_exp_targets = match builder.config.llvm_experimental_targets {
Some(ref s) => s,
None => "AVR",
None => "AVR;M68k",
glaubitz marked this conversation as resolved.
Show resolved Hide resolved
};

let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };
Expand Down
26 changes: 26 additions & 0 deletions src/ci/docker/host-x86_64/disabled/dist-m68k-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
make \
file \
curl \
ca-certificates \
python2.7 \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is python2.7 really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. I wrote this Docker file over a year ago when the CI was still using an older version of Ubuntu.

I will verify that the issue and send in a follow-up PR to drop python2.7 if necessary.

Thanks for spotting this.

git \
cmake \
sudo \
gdb \
xz-utils \
g++-m68k-linux-gnu \
libssl-dev \
pkg-config


COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

ENV HOSTS=m68k-unknown-linux-gnu

ENV RUST_CONFIGURE_ARGS --host=$HOSTS --enable-extended
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ target | std | host | notes
`i686-uwp-windows-gnu` | ? | |
`i686-uwp-windows-msvc` | ? | |
`i686-wrs-vxworks` | ? | |
`m68k-unknown-linux-gnu` | ? | | Motorola 680x0 Linux
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
`mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc
Expand Down
97 changes: 97 additions & 0 deletions src/doc/rustc/src/platform-support/m68k-unknown-linux-gnu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# m68k-unknown-linux-gnu

**Tier: 3**

Motorola 680x0 Linux

## Designated Developers

* [@glaubitz](https://github.com/glaubitz)
* [@ricky26](https://github.com/ricky26)

## Requirements

This target requires a Linux/m68k build environment for cross-compilation which
is available on Debian and Debian-based systems, openSUSE and other distributions.

On Debian, it should be sufficient to install a g++ cross-compiler for the m68k
architecture which will automatically pull in additional dependencies such as
the glibc cross development package:

```text
# apt install g++-m68k-linux-gnu
```

Binaries can be run using QEMU user emulation. On Debian-based systems, it should be
sufficient to install the package `qemu-user-static` to be able to run simple static
binaries:

```text
# apt install qemu-user-static
```

To run more complex programs, it will be necessary to set up a Debian/m68k chroot with
the help of the command `debootstrap`:

```text
# apt install debootstrap debian-ports-archive-keyring
# debootstrap --keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg --arch=m68k unstable debian-68k http://ftp.ports.debian.org/debian-ports
```

This chroot can then seamlessly entered using the normal `chroot` command thanks to
QEMU user emulation:

```text
# chroot /path/to/debian-68k
```

To get started with native builds, which are currently untested, a native Debian/m68k
system can be installed either on real hardware such as 68k-based Commodore Amiga or
Atari systems or emulated environments such as QEMU version 4.2 or newer or ARAnyM.

ISO images for installation are provided by the Debian Ports team and can be obtained
from the Debian CD image server available at:

[https://cdimage.debian.org/cdimage/ports/current](https://cdimage.debian.org/cdimage/ports/current/)

Documentation for Debian/m68k is available on the Debian Wiki at:

[https://wiki.debian.org/M68k](https://wiki.debian.org/M68k)

Support is available either through the `debian-68k` mailing list:

[https://lists.debian.org/debian-68k/](https://lists.debian.org/debian-68k/)

or the `#debian-68k` IRC channel on OFTC network.

## Building

The codegen for this target should be built by default. However, core and std
are currently missing but are being worked on and should become available in
the near future.

## Cross-compilation

This target can be cross-compiled from a standard Debian or Debian-based, openSUSE or any
other distribution which has a basic m68k cross-toolchain available.

## Testing

Currently there is no support to run the rustc test suite for this target.

## Building Rust programs

Rust programs can be built for that target:

```text
rustc --target m68k-unknown-linux-gnu your-code.rs
```

Very simple progams can be run using the `qemu-m68k-static` program:

```text
$ qemu-m68k-static your-code
```

For more complex applications, a chroot or native (emulated) Debian/m68k system are required
for testing.
1 change: 1 addition & 0 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ impl<'a> fmt::Display for Display<'a> {
"aarch64" => "AArch64",
"arm" => "ARM",
"asmjs" => "JavaScript",
"m68k" => "M68k",
"mips" => "MIPS",
"mips64" => "MIPS-64",
"msp430" => "MSP430",
Expand Down
1 change: 1 addition & 0 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static TARGETS: &[&str] = &[
"i686-unknown-freebsd",
"i686-unknown-linux-gnu",
"i686-unknown-linux-musl",
"m68k-unknown-linux-gnu",
"mips-unknown-linux-gnu",
"mips-unknown-linux-musl",
"mips64-unknown-linux-gnuabi64",
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const ARCH_TABLE: &[(&str, &str)] = &[
("i386", "x86"),
("i586", "x86"),
("i686", "x86"),
("m68k", "m68k"),
("mips", "mips"),
("mips64", "mips64"),
("mips64el", "mips64"),
Expand Down