Skip to content

Commit f1b85e7

Browse files
committed
Add m68k architecture support
1 parent 9892a86 commit f1b85e7

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

gen/include/support.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,24 @@ typedef __INT8_TYPE__ int8_t;
1010
typedef __INT16_TYPE__ int16_t;
1111
typedef __INT32_TYPE__ int32_t;
1212
typedef __INT64_TYPE__ int64_t;
13+
#ifdef __m68k__
14+
// Hack: until the fix for [1] is released, lie to clang that `size_t` has
15+
// alignment 4 on m68k. This doesn't affect the correctness of bindings, since
16+
// the only structs that (transitively) contain a size_t are
17+
// `net::{msghdr, cmsghdr, mmsghdr}` and their definitions are the same
18+
// regardless of the alignment of `size_t`.
19+
//
20+
// [1]: https://github.com/rust-lang/rust-bindgen/issues/3312
21+
typedef struct __attribute__((aligned(4))) {
22+
__SIZE_TYPE__ s;
23+
} size_t;
24+
typedef struct __attribute__((aligned(4))) {
25+
__PTRDIFF_TYPE__ s;
26+
} ssize_t;
27+
#else
1328
typedef __SIZE_TYPE__ size_t;
1429
typedef __PTRDIFF_TYPE__ ssize_t;
30+
#endif
1531
typedef __PTRDIFF_TYPE__ ptrdiff_t;
1632
typedef __INTPTR_TYPE__ intptr_t;
1733
typedef __UINTPTR_TYPE__ uintptr_t;

gen/ioctl/generate.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,10 @@ cat loongarch-ioctls.txt >> "$out"
105105
# qemu-csky -L /usr/csky-linux-gnuabiv2 ./main.exe >> "$out"
106106
cat csky-ioctls.txt >> "$out"
107107

108+
install_headers m68k
109+
m68k-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
110+
m68k-linux-gnu-gcc main.c list.o -o main.exe $cflags
111+
qemu-m68k -L /usr/m68k-linux-gnu ./main.exe >> "$out"
112+
108113
# Add any extra custom definitions at the end.
109114
echo "#include \"ioctl-addendum.h\"" >> "$out"

gen/ioctl/list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct sockaddr {
100100
#include <linux/joystick.h>
101101
#include <linux/kd.h>
102102
#include <linux/kcov.h>
103-
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__)// various errors
103+
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__) && !defined(__m68k__) // various errors
104104
#include <linux/kvm.h>
105105
#endif
106106
#include <linux/lirc.h>

gen/ioctl/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int main(void) {
4949
printf("#ifdef __loongarch__\n");
5050
#elif defined(__csky__)
5151
printf("#ifdef __csky__\n");
52+
#elif defined(__m68k__)
53+
printf("#ifdef __m68k__\n");
5254
#else
5355
#error "unimplemented architecture"
5456
#endif

gen/modules/general.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct user_desc {
229229
// that its fourth argument be the size of the kernel's internal `sigset_t`
230230
// type. So we define our own.
231231

232-
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__)
232+
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__) || defined(__m68k__)
233233
#define _NSIG 64
234234
#endif
235235

gen/src/main.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ fn main() {
174174
writeln!(cargo_toml, "std = []").unwrap();
175175
writeln!(cargo_toml, "no_std = []").unwrap();
176176
writeln!(cargo_toml, "elf = []").unwrap();
177-
writeln!(
178-
cargo_toml,
179-
"rustc-dep-of-std = [\"core\", \"no_std\"]"
180-
)
181-
.unwrap();
177+
writeln!(cargo_toml, "rustc-dep-of-std = [\"core\", \"no_std\"]").unwrap();
182178

183179
eprintln!("All bindings generated!");
184180
}
@@ -291,15 +287,16 @@ fn rust_arches(linux_arch: &str) -> &[&str] {
291287
"csky" => &["csky"],
292288
"hexagon" => &["hexagon"],
293289
"loongarch" => &["loongarch64"],
290+
"m68k" => &["m68k"],
294291
"mips" => &["mips", "mips64", "mips32r6", "mips64r6"],
295292
"powerpc" => &["powerpc", "powerpc64"],
296293
"riscv" => &["riscv32", "riscv64"],
297294
"s390" => &["s390x"],
298295
"sparc" => &["sparc", "sparc64"],
299296
"x86" => &["x86", "x86_64", "x32"],
300-
"alpha" | "cris" | "h8300" | "m68k" | "microblaze" | "mn10300" | "score" | "blackfin"
301-
| "frv" | "ia64" | "m32r" | "m68knommu" | "parisc" | "sh" | "um" | "xtensa"
302-
| "unicore32" | "c6x" | "nios2" | "openrisc" | "arc" | "nds32" | "metag" | "tile" => &[],
297+
"alpha" | "cris" | "h8300" | "microblaze" | "mn10300" | "score" | "blackfin" | "frv"
298+
| "ia64" | "m32r" | "m68knommu" | "parisc" | "sh" | "um" | "xtensa" | "unicore32"
299+
| "c6x" | "nios2" | "openrisc" | "arc" | "nds32" | "metag" | "tile" => &[],
303300
_ => panic!("unrecognized arch: {}", linux_arch),
304301
}
305302
}
@@ -362,6 +359,13 @@ fn run_bindgen(
362359
builder = builder.blocklist_item("^HUGETLB_FLAG_ENCODE_.*");
363360
builder = builder.blocklist_item("^RESOLVE_.*");
364361
}
362+
if rust_arch == "m68k" {
363+
// Don't emit the `size_t` workaround types for m68k. This should be
364+
// removed when there's a bindgen release with a fix for [1].
365+
//
366+
// [1]: https://github.com/rust-lang/rust-bindgen/issues/3312
367+
builder = builder.blocklist_type("^s?size_t$");
368+
}
365369

366370
let bindings = builder
367371
.use_core()

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod ctypes {
2727
pub type c_char = c_uchar;
2828
#[cfg(any(
2929
target_arch = "loongarch64",
30+
target_arch = "m68k",
3031
target_arch = "mips",
3132
target_arch = "mips64",
3233
target_arch = "mips32r6",

0 commit comments

Comments
 (0)