Skip to content

Commit db1fb85

Browse files
committed
Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiser
Add initial support for m68k This patch series adds initial support for m68k making use of the new M68k backend introduced with LLVM-13. Additional changes will be needed to be able to actually use the backend for this target.
2 parents e71925a + 5d22b1a commit db1fb85

File tree

18 files changed

+196
-2
lines changed

18 files changed

+196
-2
lines changed

compiler/rustc_llvm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn main() {
7676
"aarch64",
7777
"amdgpu",
7878
"avr",
79+
"m68k",
7980
"mips",
8081
"powerpc",
8182
"systemz",

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ void LLVMRustAddLastExtensionPasses(
201201
#define SUBTARGET_AVR
202202
#endif
203203

204+
#ifdef LLVM_COMPONENT_M68k
205+
#define SUBTARGET_M68K SUBTARGET(M68k)
206+
#else
207+
#define SUBTARGET_M68K
208+
#endif
209+
204210
#ifdef LLVM_COMPONENT_MIPS
205211
#define SUBTARGET_MIPS SUBTARGET(Mips)
206212
#else
@@ -248,6 +254,7 @@ void LLVMRustAddLastExtensionPasses(
248254
SUBTARGET_ARM \
249255
SUBTARGET_AARCH64 \
250256
SUBTARGET_AVR \
257+
SUBTARGET_M68K \
251258
SUBTARGET_MIPS \
252259
SUBTARGET_PPC \
253260
SUBTARGET_SYSTEMZ \

compiler/rustc_llvm/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ pub fn initialize_available_targets() {
9090
LLVMInitializeAVRAsmPrinter,
9191
LLVMInitializeAVRAsmParser
9292
);
93+
init_target!(
94+
llvm_component = "m68k",
95+
LLVMInitializeM68kTargetInfo,
96+
LLVMInitializeM68kTarget,
97+
LLVMInitializeM68kTargetMC,
98+
LLVMInitializeM68kAsmPrinter,
99+
LLVMInitializeM68kAsmParser
100+
);
93101
init_target!(
94102
llvm_component = "mips",
95103
LLVMInitializeMipsTargetInfo,
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::abi::call::{ArgAbi, FnAbi};
2+
3+
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
4+
if ret.layout.is_aggregate() {
5+
ret.make_indirect();
6+
} else {
7+
ret.extend_integer_width_to(32);
8+
}
9+
}
10+
11+
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
12+
if arg.layout.is_aggregate() {
13+
arg.make_indirect_byval();
14+
} else {
15+
arg.extend_integer_width_to(32);
16+
}
17+
}
18+
19+
pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
20+
if !fn_abi.ret.is_ignore() {
21+
classify_ret(&mut fn_abi.ret);
22+
}
23+
24+
for arg in &mut fn_abi.args {
25+
if arg.is_ignore() {
26+
continue;
27+
}
28+
classify_arg(arg);
29+
}
30+
}

compiler/rustc_target/src/abi/call/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod arm;
99
mod avr;
1010
mod bpf;
1111
mod hexagon;
12+
mod m68k;
1213
mod mips;
1314
mod mips64;
1415
mod msp430;
@@ -656,6 +657,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
656657
"amdgpu" => amdgpu::compute_abi_info(cx, self),
657658
"arm" => arm::compute_abi_info(cx, self),
658659
"avr" => avr::compute_abi_info(self),
660+
"m68k" => m68k::compute_abi_info(self),
659661
"mips" => mips::compute_abi_info(cx, self),
660662
"mips64" => mips64::compute_abi_info(cx, self),
661663
"powerpc" => powerpc::compute_abi_info(self),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let mut base = super::linux_base::opts();
6+
base.max_atomic_width = Some(32);
7+
8+
Target {
9+
llvm_target: "m68k-unknown-linux-gnu".to_string(),
10+
pointer_width: 32,
11+
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(),
12+
arch: "m68k".to_string(),
13+
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base },
14+
}
15+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ supported_targets! {
742742
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
743743
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
744744
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
745+
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
745746
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
746747
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),
747748
("mips64el-unknown-linux-gnuabi64", mips64el_unknown_linux_gnuabi64),

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ changelog-seen = 2
103103
# the same format as above, but since these targets are experimental, they are
104104
# not built by default and the experimental Rust compilation targets that depend
105105
# on them will not work unless the user opts in to building them.
106-
#experimental-targets = "AVR"
106+
#experimental-targets = "AVR;M68k"
107107

108108
# Cap the number of parallel linker invocations when compiling LLVM.
109109
# This can be useful when building LLVM with debug info, which significantly

library/std/src/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ pub mod consts {
879879
/// - x86_64
880880
/// - arm
881881
/// - aarch64
882+
/// - m68k
882883
/// - mips
883884
/// - mips64
884885
/// - powerpc

library/std/src/os/linux/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
2727
#[cfg(any(
2828
target_arch = "x86",
2929
target_arch = "le32",
30+
target_arch = "m68k",
3031
target_arch = "powerpc",
3132
target_arch = "sparc",
3233
target_arch = "arm",

src/bootstrap/bootstrap.py

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def default_build_triple(verbose):
277277
'i486': 'i686',
278278
'i686': 'i686',
279279
'i786': 'i686',
280+
'm68k': 'm68k',
280281
'powerpc': 'powerpc',
281282
'powerpc64': 'powerpc64',
282283
'powerpc64le': 'powerpc64le',

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Step for Llvm {
165165

166166
let llvm_exp_targets = match builder.config.llvm_experimental_targets {
167167
Some(ref s) => s,
168-
None => "AVR",
168+
None => "AVR;M68k",
169169
};
170170

171171
let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:20.04
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
g++ \
5+
make \
6+
file \
7+
curl \
8+
ca-certificates \
9+
python2.7 \
10+
git \
11+
cmake \
12+
sudo \
13+
gdb \
14+
xz-utils \
15+
g++-m68k-linux-gnu \
16+
libssl-dev \
17+
pkg-config
18+
19+
20+
COPY scripts/sccache.sh /scripts/
21+
RUN sh /scripts/sccache.sh
22+
23+
ENV HOSTS=m68k-unknown-linux-gnu
24+
25+
ENV RUST_CONFIGURE_ARGS --host=$HOSTS --enable-extended
26+
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ target | std | host | notes
238238
`i686-uwp-windows-gnu` | ? | |
239239
`i686-uwp-windows-msvc` | ? | |
240240
`i686-wrs-vxworks` | ? | |
241+
`m68k-unknown-linux-gnu` | ? | | Motorola 680x0 Linux
241242
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
242243
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
243244
`mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# m68k-unknown-linux-gnu
2+
3+
**Tier: 3**
4+
5+
Motorola 680x0 Linux
6+
7+
## Designated Developers
8+
9+
* [@glaubitz](https://github.com/glaubitz)
10+
* [@ricky26](https://github.com/ricky26)
11+
12+
## Requirements
13+
14+
This target requires a Linux/m68k build environment for cross-compilation which
15+
is available on Debian and Debian-based systems, openSUSE and other distributions.
16+
17+
On Debian, it should be sufficient to install a g++ cross-compiler for the m68k
18+
architecture which will automatically pull in additional dependencies such as
19+
the glibc cross development package:
20+
21+
```text
22+
# apt install g++-m68k-linux-gnu
23+
```
24+
25+
Binaries can be run using QEMU user emulation. On Debian-based systems, it should be
26+
sufficient to install the package `qemu-user-static` to be able to run simple static
27+
binaries:
28+
29+
```text
30+
# apt install qemu-user-static
31+
```
32+
33+
To run more complex programs, it will be necessary to set up a Debian/m68k chroot with
34+
the help of the command `debootstrap`:
35+
36+
```text
37+
# apt install debootstrap debian-ports-archive-keyring
38+
# debootstrap --keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg --arch=m68k unstable debian-68k http://ftp.ports.debian.org/debian-ports
39+
```
40+
41+
This chroot can then seamlessly entered using the normal `chroot` command thanks to
42+
QEMU user emulation:
43+
44+
```text
45+
# chroot /path/to/debian-68k
46+
```
47+
48+
To get started with native builds, which are currently untested, a native Debian/m68k
49+
system can be installed either on real hardware such as 68k-based Commodore Amiga or
50+
Atari systems or emulated environments such as QEMU version 4.2 or newer or ARAnyM.
51+
52+
ISO images for installation are provided by the Debian Ports team and can be obtained
53+
from the Debian CD image server available at:
54+
55+
[https://cdimage.debian.org/cdimage/ports/current](https://cdimage.debian.org/cdimage/ports/current/)
56+
57+
Documentation for Debian/m68k is available on the Debian Wiki at:
58+
59+
[https://wiki.debian.org/M68k](https://wiki.debian.org/M68k)
60+
61+
Support is available either through the `debian-68k` mailing list:
62+
63+
[https://lists.debian.org/debian-68k/](https://lists.debian.org/debian-68k/)
64+
65+
or the `#debian-68k` IRC channel on OFTC network.
66+
67+
## Building
68+
69+
The codegen for this target should be built by default. However, core and std
70+
are currently missing but are being worked on and should become available in
71+
the near future.
72+
73+
## Cross-compilation
74+
75+
This target can be cross-compiled from a standard Debian or Debian-based, openSUSE or any
76+
other distribution which has a basic m68k cross-toolchain available.
77+
78+
## Testing
79+
80+
Currently there is no support to run the rustc test suite for this target.
81+
82+
## Building Rust programs
83+
84+
Rust programs can be built for that target:
85+
86+
```text
87+
rustc --target m68k-unknown-linux-gnu your-code.rs
88+
```
89+
90+
Very simple progams can be run using the `qemu-m68k-static` program:
91+
92+
```text
93+
$ qemu-m68k-static your-code
94+
```
95+
96+
For more complex applications, a chroot or native (emulated) Debian/m68k system are required
97+
for testing.

src/librustdoc/clean/cfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ impl<'a> fmt::Display for Display<'a> {
491491
"aarch64" => "AArch64",
492492
"arm" => "ARM",
493493
"asmjs" => "JavaScript",
494+
"m68k" => "M68k",
494495
"mips" => "MIPS",
495496
"mips64" => "MIPS-64",
496497
"msp430" => "MSP430",

src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static TARGETS: &[&str] = &[
9999
"i686-unknown-freebsd",
100100
"i686-unknown-linux-gnu",
101101
"i686-unknown-linux-musl",
102+
"m68k-unknown-linux-gnu",
102103
"mips-unknown-linux-gnu",
103104
"mips-unknown-linux-musl",
104105
"mips64-unknown-linux-gnuabi64",

src/tools/compiletest/src/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const ARCH_TABLE: &[(&str, &str)] = &[
5454
("i386", "x86"),
5555
("i586", "x86"),
5656
("i686", "x86"),
57+
("m68k", "m68k"),
5758
("mips", "mips"),
5859
("mips64", "mips64"),
5960
("mips64el", "mips64"),

0 commit comments

Comments
 (0)