Skip to content

Commit fd98df8

Browse files
committed
Auto merge of #135085 - knickish:m68k_unknown_none, r=workingjubilee
add m68k-unknown-none-elf target r? `@workingjubilee` The existing `m68k-unknown-linux-gnu` target builds `std` by default, requires atomics, and has a base cpu with an fpu. A smaller/more embedded target is desirable both to have a baseline target for the ISA, as well to make debugging easier for working on the llvm backend. Currently this target is using the `M68010` as the minimum CPU due, but as missing features are merged into the `M68k` llvm backend I am hoping to lower this further. I have been able to build very small crates using a toolchain built against this target (together with a later version of `object`) using the configuration described in the target platform-support documentation, although getting anything of substantial complexity to build quickly hits errors in the llvm backend
2 parents 56f9e6f + f985a37 commit fd98df8

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed

Diff for: compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ supported_targets! {
16561656
("loongarch64-unknown-linux-gnu", loongarch64_unknown_linux_gnu),
16571657
("loongarch64-unknown-linux-musl", loongarch64_unknown_linux_musl),
16581658
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
1659+
("m68k-unknown-none-elf", m68k_unknown_none_elf),
16591660
("csky-unknown-linux-gnuabiv2", csky_unknown_linux_gnuabiv2),
16601661
("csky-unknown-linux-gnuabiv2hf", csky_unknown_linux_gnuabiv2hf),
16611662
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{CodeModel, PanicStrategy, RelocModel, Target, TargetOptions};
3+
4+
pub(crate) fn target() -> Target {
5+
let options = TargetOptions {
6+
cpu: "M68010".into(),
7+
max_atomic_width: None,
8+
endian: Endian::Big,
9+
// LLD currently does not have support for M68k
10+
linker: Some("m68k-linux-gnu-ld".into()),
11+
panic_strategy: PanicStrategy::Abort,
12+
code_model: Some(CodeModel::Medium),
13+
has_rpath: false,
14+
// should be soft-float
15+
llvm_floatabi: None,
16+
relocation_model: RelocModel::Static,
17+
..Default::default()
18+
};
19+
20+
Target {
21+
llvm_target: "m68k".into(),
22+
metadata: crate::spec::TargetMetadata {
23+
description: Some("Motorola 680x0".into()),
24+
tier: Some(3),
25+
host_tools: Some(false),
26+
std: Some(false),
27+
},
28+
pointer_width: 32,
29+
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".into(),
30+
arch: "m68k".into(),
31+
options,
32+
}
33+
}

Diff for: src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
- [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md)
6161
- [loongarch\*-unknown-none\*](platform-support/loongarch-none.md)
6262
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
63+
- [m68k-unknown-none-elf](platform-support/m68k-unknown-none-elf.md)
6364
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
6465
- [mipsel-sony-psx](platform-support/mipsel-sony-psx.md)
6566
- [mips\*-mti-none-elf](platform-support/mips-mti-none-elf.md)

Diff for: src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ target | std | host | notes
317317
[`i686-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | [^x86_32-floats-return-ABI]
318318
[`loongarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | LoongArch64 OpenHarmony
319319
[`m68k-unknown-linux-gnu`](platform-support/m68k-unknown-linux-gnu.md) | ? | | Motorola 680x0 Linux
320+
[`m68k-unknown-none-elf`](platform-support/m68k-unknown-none-elf.md) | | | Motorola 680x0
320321
`mips-unknown-linux-gnu` | ✓ | ✓ | MIPS Linux (kernel 4.4, glibc 2.23)
321322
`mips-unknown-linux-musl` | ✓ | | MIPS Linux with musl 1.2.3
322323
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# m68k-unknown-none-elf
2+
3+
**Tier: 3**
4+
5+
Bare metal Motorola 680x0
6+
7+
## Designated Developers
8+
9+
* [@knickish](https://github.com/knickish)
10+
11+
## Requirements
12+
13+
This target requires an m68k build environment for cross-compilation which
14+
is available on Debian, Debian-based systems, openSUSE, and other distributions.
15+
16+
On Debian-based systems, it should be sufficient to install a g++ cross-compiler for the m68k
17+
architecture which will automatically pull in additional dependencies such as
18+
the glibc cross development package:
19+
20+
```sh
21+
apt install g++-m68k-linux-gnu
22+
```
23+
24+
Binaries can be run using QEMU user emulation. On Debian-based systems, it should be
25+
sufficient to install the package `qemu-user-static` to be able to run simple static
26+
binaries:
27+
28+
```text
29+
# apt install qemu-user-static
30+
```
31+
32+
To run more complex programs, it will be necessary to set up a Debian/m68k chroot with
33+
the help of the command `debootstrap`:
34+
35+
```text
36+
# apt install debootstrap debian-ports-archive-keyring
37+
# debootstrap --keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg --arch=m68k unstable debian-68k http://ftp.ports.debian.org/debian-ports
38+
```
39+
40+
This chroot can then seamlessly entered using the normal `chroot` command thanks to
41+
QEMU user emulation:
42+
43+
```text
44+
# chroot /path/to/debian-68k
45+
```
46+
47+
To get started with native builds, which are currently untested, a native Debian/m68k
48+
system can be installed either on real hardware such as 68k-based Commodore Amiga or
49+
Atari systems or emulated environments such as QEMU version 4.2 or newer or ARAnyM.
50+
51+
ISO images for installation are provided by the Debian Ports team and can be obtained
52+
from the Debian CD image server available at:
53+
54+
[https://cdimage.debian.org/cdimage/ports/current](https://cdimage.debian.org/cdimage/ports/current/)
55+
56+
Documentation for Debian/m68k is available on the Debian Wiki at:
57+
58+
[https://wiki.debian.org/M68k](https://wiki.debian.org/M68k)
59+
60+
Support is available either through the `debian-68k` mailing list:
61+
62+
[https://lists.debian.org/debian-68k/](https://lists.debian.org/debian-68k/)
63+
64+
or the `#debian-68k` IRC channel on OFTC network.
65+
66+
## Building
67+
68+
At least llvm version `19.1.5` is required to build `core` and `alloc` for this target, and currently the gnu linker is required, as `lld` has no support for the `m68k` architecture
69+
70+
## Cross-compilation
71+
72+
This target can be cross-compiled from a standard Debian or Debian-based, openSUSE or any
73+
other distribution which has a basic m68k cross-toolchain available.
74+
75+
## Testing
76+
77+
Currently there is no support to run the rustc test suite for this target.
78+
79+
## Building Rust programs
80+
81+
Recommended `.cargo/config.toml`:
82+
```toml
83+
[unstable]
84+
build-std = ["panic_abort", "core", "alloc"]
85+
86+
[target.m68k-unknown-none-elf]
87+
# as we're building for ELF, the m68k-linux linker should be adequate
88+
linker = "m68k-linux-gnu-ld"
89+
90+
# the mold linker also supports m68k, remove the above line and uncomment the
91+
# following ones to use that instead
92+
# linker = "clang"
93+
# rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold/binary"]
94+
```
95+
96+
Rust programs can be built for this target using:
97+
98+
```sh
99+
cargo build --target m68k-unknown-none-elf
100+
```
101+
102+
Very simple programs can be run using the `qemu-m68k-static` program:
103+
104+
```sh
105+
qemu-m68k-static your-code
106+
```
107+
108+
For more complex applications, a chroot or native m68k system is required for testing.

Diff for: src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static TARGETS: &[&str] = &[
114114
"loongarch64-unknown-none",
115115
"loongarch64-unknown-none-softfloat",
116116
"m68k-unknown-linux-gnu",
117+
"m68k-unknown-none-elf",
117118
"csky-unknown-linux-gnuabiv2",
118119
"csky-unknown-linux-gnuabiv2hf",
119120
"mips-unknown-linux-gnu",

Diff for: tests/assembly/targets/targets-elf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@
261261
//@ revisions: m68k_unknown_linux_gnu
262262
//@ [m68k_unknown_linux_gnu] compile-flags: --target m68k-unknown-linux-gnu
263263
//@ [m68k_unknown_linux_gnu] needs-llvm-components: m68k
264+
//@ revisions: m68k_unknown_none_elf
265+
//@ [m68k_unknown_none_elf] compile-flags: --target m68k-unknown-none-elf
266+
//@ [m68k_unknown_none_elf] needs-llvm-components: m68k
264267
//@ revisions: mips64_openwrt_linux_musl
265268
//@ [mips64_openwrt_linux_musl] compile-flags: --target mips64-openwrt-linux-musl
266269
//@ [mips64_openwrt_linux_musl] needs-llvm-components: mips

0 commit comments

Comments
 (0)