Skip to content

Commit 6fd358d

Browse files
sweiglboskeralexrp
authored andcommitted
std.os.linux: add arch bits for m68k
fixup
1 parent 4b5941c commit 6fd358d

File tree

2 files changed

+306
-9
lines changed

2 files changed

+306
-9
lines changed

lib/std/os/linux.zig

+31-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const arch_bits = switch (native_arch) {
3939
.riscv64 => @import("linux/riscv64.zig"),
4040
.sparc64 => @import("linux/sparc64.zig"),
4141
.loongarch64 => @import("linux/loongarch64.zig"),
42+
.m68k => @import("linux/m68k.zig"),
4243
.mips, .mipsel => @import("linux/mips.zig"),
4344
.mips64, .mips64el => @import("linux/mips64.zig"),
4445
.powerpc, .powerpcle => @import("linux/powerpc.zig"),
@@ -279,7 +280,7 @@ pub const MAP = switch (native_arch) {
279280
UNINITIALIZED: bool = false,
280281
_: u5 = 0,
281282
},
282-
.hexagon, .s390x => packed struct(u32) {
283+
.hexagon, .m68k, .s390x => packed struct(u32) {
283284
TYPE: MAP_TYPE,
284285
FIXED: bool = false,
285286
ANONYMOUS: bool = false,
@@ -333,7 +334,7 @@ pub const O = switch (native_arch) {
333334
SYNC: bool = false,
334335
PATH: bool = false,
335336
TMPFILE: bool = false,
336-
_: u9 = 0,
337+
_23: u9 = 0,
337338
},
338339
.x86, .riscv32, .riscv64, .loongarch64 => packed struct(u32) {
339340
ACCMODE: ACCMODE = .RDONLY,
@@ -355,7 +356,7 @@ pub const O = switch (native_arch) {
355356
SYNC: bool = false,
356357
PATH: bool = false,
357358
TMPFILE: bool = false,
358-
_: u9 = 0,
359+
_23: u9 = 0,
359360
},
360361
.aarch64, .aarch64_be, .arm, .armeb, .thumb, .thumbeb => packed struct(u32) {
361362
ACCMODE: ACCMODE = .RDONLY,
@@ -377,7 +378,7 @@ pub const O = switch (native_arch) {
377378
SYNC: bool = false,
378379
PATH: bool = false,
379380
TMPFILE: bool = false,
380-
_: u9 = 0,
381+
_23: u9 = 0,
381382
},
382383
.sparc64 => packed struct(u32) {
383384
ACCMODE: ACCMODE = .RDONLY,
@@ -402,7 +403,7 @@ pub const O = switch (native_arch) {
402403
SYNC: bool = false,
403404
PATH: bool = false,
404405
TMPFILE: bool = false,
405-
_: u6 = 0,
406+
_27: u6 = 0,
406407
},
407408
.mips, .mipsel, .mips64, .mips64el => packed struct(u32) {
408409
ACCMODE: ACCMODE = .RDONLY,
@@ -426,7 +427,7 @@ pub const O = switch (native_arch) {
426427
_20: u1 = 0,
427428
PATH: bool = false,
428429
TMPFILE: bool = false,
429-
_: u9 = 0,
430+
_23: u9 = 0,
430431
},
431432
.powerpc, .powerpcle, .powerpc64, .powerpc64le => packed struct(u32) {
432433
ACCMODE: ACCMODE = .RDONLY,
@@ -448,7 +449,7 @@ pub const O = switch (native_arch) {
448449
SYNC: bool = false,
449450
PATH: bool = false,
450451
TMPFILE: bool = false,
451-
_: u9 = 0,
452+
_23: u9 = 0,
452453
},
453454
.hexagon, .s390x => packed struct(u32) {
454455
ACCMODE: ACCMODE = .RDONLY,
@@ -467,15 +468,36 @@ pub const O = switch (native_arch) {
467468
NOFOLLOW: bool = false,
468469
NOATIME: bool = false,
469470
CLOEXEC: bool = false,
470-
_17: u1 = 0,
471+
_20: u1 = 0,
471472
PATH: bool = false,
472-
_: u10 = 0,
473+
_22: u10 = 0,
473474

474475
// #define O_RSYNC 04010000
475476
// #define O_SYNC 04010000
476477
// #define O_TMPFILE 020200000
477478
// #define O_NDELAY O_NONBLOCK
478479
},
480+
.m68k => packed struct(u32) {
481+
ACCMODE: ACCMODE = .RDONLY,
482+
_2: u4 = 0,
483+
CREAT: bool = false,
484+
EXCL: bool = false,
485+
NOCTTY: bool = false,
486+
TRUNC: bool = false,
487+
APPEND: bool = false,
488+
NONBLOCK: bool = false,
489+
DSYNC: bool = false,
490+
ASYNC: bool = false,
491+
DIRECTORY: bool = false,
492+
NOFOLLOW: bool = false,
493+
DIRECT: bool = false,
494+
LARGEFILE: bool = false,
495+
NOATIME: bool = false,
496+
CLOEXEC: bool = false,
497+
_20: u1 = 0,
498+
PATH: bool = false,
499+
_22: u10 = 0,
500+
},
479501
else => @compileError("missing std.os.linux.O constants for this architecture"),
480502
};
481503

lib/std/os/linux/m68k.zig

+275
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
const builtin = @import("builtin");
2+
const std = @import("../../std.zig");
3+
const iovec = std.posix.iovec;
4+
const iovec_const = std.posix.iovec_const;
5+
const linux = std.os.linux;
6+
const SYS = linux.SYS;
7+
const uid_t = std.os.linux.uid_t;
8+
const gid_t = std.os.linux.uid_t;
9+
const pid_t = std.os.linux.pid_t;
10+
const sockaddr = linux.sockaddr;
11+
const socklen_t = linux.socklen_t;
12+
const timespec = std.os.linux.timespec;
13+
14+
pub fn syscall0(number: SYS) usize {
15+
return asm volatile ("trap #0"
16+
: [ret] "={d0}" (-> usize),
17+
: [number] "{d0}" (@intFromEnum(number)),
18+
: "memory"
19+
);
20+
}
21+
22+
pub fn syscall1(number: SYS, arg1: usize) usize {
23+
return asm volatile ("trap #0"
24+
: [ret] "={d0}" (-> usize),
25+
: [number] "{d0}" (@intFromEnum(number)),
26+
[arg1] "{d1}" (arg1),
27+
: "memory"
28+
);
29+
}
30+
31+
pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
32+
return asm volatile ("trap #0"
33+
: [ret] "={d0}" (-> usize),
34+
: [number] "{d0}" (@intFromEnum(number)),
35+
[arg1] "{d1}" (arg1),
36+
[arg2] "{d2}" (arg2),
37+
: "memory"
38+
);
39+
}
40+
41+
pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
42+
return asm volatile ("trap #0"
43+
: [ret] "={d0}" (-> usize),
44+
: [number] "{d0}" (@intFromEnum(number)),
45+
[arg1] "{d1}" (arg1),
46+
[arg2] "{d2}" (arg2),
47+
[arg3] "{d3}" (arg3),
48+
: "memory"
49+
);
50+
}
51+
52+
pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
53+
return asm volatile ("trap #0"
54+
: [ret] "={d0}" (-> usize),
55+
: [number] "{d0}" (@intFromEnum(number)),
56+
[arg1] "{d1}" (arg1),
57+
[arg2] "{d2}" (arg2),
58+
[arg3] "{d3}" (arg3),
59+
[arg4] "{d4}" (arg4),
60+
: "memory"
61+
);
62+
}
63+
64+
pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
65+
return asm volatile ("trap #0"
66+
: [ret] "={d0}" (-> usize),
67+
: [number] "{d0}" (@intFromEnum(number)),
68+
[arg1] "{d1}" (arg1),
69+
[arg2] "{d2}" (arg2),
70+
[arg3] "{d3}" (arg3),
71+
[arg4] "{d4}" (arg4),
72+
[arg5] "{d5}" (arg5),
73+
: "memory"
74+
);
75+
}
76+
77+
pub fn syscall6(
78+
number: SYS,
79+
arg1: usize,
80+
arg2: usize,
81+
arg3: usize,
82+
arg4: usize,
83+
arg5: usize,
84+
arg6: usize,
85+
) usize {
86+
return asm volatile ("trap #0"
87+
: [ret] "={d0}" (-> usize),
88+
: [number] "{d0}" (@intFromEnum(number)),
89+
[arg1] "{d1}" (arg1),
90+
[arg2] "{d2}" (arg2),
91+
[arg3] "{d3}" (arg3),
92+
[arg4] "{d4}" (arg4),
93+
[arg5] "{d5}" (arg5),
94+
[arg6] "{a0}" (arg6),
95+
: "memory"
96+
);
97+
}
98+
99+
pub fn clone() callconv(.naked) usize {
100+
// __clone(func, stack, flags, arg, ptid, tls, ctid)
101+
// +4, +8, +12, +16, +20, +24, +28
102+
//
103+
// syscall(SYS_clone, flags, stack, ptid, ctid, tls)
104+
// d0, d1, d2, d3, d4, d5
105+
asm volatile (
106+
\\ // Save callee-saved registers.
107+
\\ movem.l %%d2-%%d5, -(%%sp) // sp -= 16
108+
\\
109+
\\ // Save func and arg.
110+
\\ move.l 16+4(%%sp), %%a0
111+
\\ move.l 16+16(%%sp), %%a1
112+
\\
113+
\\ // d0 = syscall(d0, d1, d2, d3, d4, d5)
114+
\\ move.l #120, %%d0 // SYS_clone
115+
\\ move.l 16+12(%%sp), %%d1
116+
\\ move.l 16+8(%%sp), %%d2
117+
\\ move.l 16+20(%%sp), %%d3
118+
\\ move.l 16+28(%%sp), %%d4
119+
\\ move.l 16+24(%%sp), %%d5
120+
\\ and.l #-4, %%d2 // Align the child stack pointer.
121+
\\ trap #0
122+
\\
123+
\\ // Are we in the parent or child?
124+
\\ tst.l %%d0
125+
\\ beq 1f
126+
\\ // Parent:
127+
\\
128+
\\ // Restore callee-saved registers and return.
129+
\\ movem.l (%%sp)+, %%d2-%%d5 // sp += 16
130+
\\ rts
131+
\\
132+
\\ // Child:
133+
\\1:
134+
);
135+
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
136+
\\ .cfi_undefined %%pc
137+
);
138+
asm volatile (
139+
\\ suba.l %%fp, %%fp
140+
\\
141+
\\ // d0 = func(a1)
142+
\\ move.l %%a1, -(%%sp)
143+
\\ jsr (%%a0)
144+
\\
145+
\\ // syscall(d0, d1)
146+
\\ move.l %%d0, %%d1
147+
\\ move.l #1, %%d0 // SYS_exit
148+
\\ trap #0
149+
);
150+
}
151+
152+
pub const restore = restore_rt;
153+
154+
pub fn restore_rt() callconv(.naked) noreturn {
155+
asm volatile ("trap #0"
156+
:
157+
: [number] "{d0}" (@intFromEnum(SYS.rt_sigreturn)),
158+
: "memory"
159+
);
160+
}
161+
162+
pub const F = struct {
163+
pub const DUPFD = 0;
164+
pub const GETFD = 1;
165+
pub const SETFD = 2;
166+
pub const GETFL = 3;
167+
pub const SETFL = 4;
168+
169+
pub const SETOWN = 8;
170+
pub const GETOWN = 9;
171+
pub const SETSIG = 10;
172+
pub const GETSIG = 11;
173+
174+
pub const GETLK = 12;
175+
pub const SETLK = 13;
176+
pub const SETLKW = 14;
177+
178+
pub const SETOWN_EX = 15;
179+
pub const GETOWN_EX = 16;
180+
181+
pub const GETOWNER_UIDS = 17;
182+
183+
pub const RDLCK = 0;
184+
pub const WRLCK = 1;
185+
pub const UNLCK = 2;
186+
};
187+
188+
pub const blksize_t = i32;
189+
pub const nlink_t = u32;
190+
pub const time_t = i32;
191+
pub const mode_t = u32;
192+
pub const off_t = i64;
193+
pub const ino_t = u64;
194+
pub const dev_t = u64;
195+
pub const blkcnt_t = i64;
196+
197+
pub const timeval = extern struct {
198+
sec: time_t,
199+
usec: i32,
200+
};
201+
202+
pub const Flock = extern struct {
203+
type: i16,
204+
whence: i16,
205+
start: off_t,
206+
len: off_t,
207+
pid: pid_t,
208+
};
209+
210+
// TODO: not 100% sure of padding for msghdr
211+
pub const msghdr = extern struct {
212+
name: ?*sockaddr,
213+
namelen: socklen_t,
214+
iov: [*]iovec,
215+
iovlen: i32,
216+
control: ?*anyopaque,
217+
controllen: socklen_t,
218+
flags: i32,
219+
};
220+
221+
pub const msghdr_const = extern struct {
222+
name: ?*const sockaddr,
223+
namelen: socklen_t,
224+
iov: [*]const iovec_const,
225+
iovlen: i32,
226+
control: ?*const anyopaque,
227+
controllen: socklen_t,
228+
flags: i32,
229+
};
230+
231+
pub const Stat = extern struct {
232+
dev: dev_t,
233+
__pad: i16,
234+
__ino_truncated: i32,
235+
mode: mode_t,
236+
nlink: nlink_t,
237+
uid: uid_t,
238+
gid: gid_t,
239+
rdev: dev_t,
240+
__pad2: i16,
241+
size: off_t,
242+
blksize: blksize_t,
243+
blocks: blkcnt_t,
244+
atim: timespec,
245+
mtim: timespec,
246+
ctim: timespec,
247+
ino: ino_t,
248+
249+
pub fn atime(self: @This()) timespec {
250+
return self.atim;
251+
}
252+
253+
pub fn mtime(self: @This()) timespec {
254+
return self.mtim;
255+
}
256+
257+
pub fn ctime(self: @This()) timespec {
258+
return self.ctim;
259+
}
260+
};
261+
262+
pub const Elf_Symndx = u32;
263+
264+
// m68k has multiple minimum page sizes.
265+
// glibc sets MMAP2_PAGE_UNIT to -1 so it is queried at runtime.
266+
pub const MMAP2_UNIT = -1;
267+
268+
// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.
269+
pub const VDSO = void;
270+
271+
/// TODO
272+
pub const ucontext_t = void;
273+
274+
/// TODO
275+
pub const getcontext = {};

0 commit comments

Comments
 (0)