Skip to content

Commit bcc7d27

Browse files
committed
std: add arch bits for m68k-linux
1 parent 525466b commit bcc7d27

File tree

2 files changed

+300
-1
lines changed

2 files changed

+300
-1
lines changed

lib/std/os/linux.zig

+2-1
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,

lib/std/os/linux/m68k.zig

+298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
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+
asm volatile (
101+
\\ // int clone(
102+
\\ // fn,
103+
\\ // stack, (d2)
104+
\\ // flags, (d1)
105+
\\ // arg,
106+
\\ // ptid, (d3)
107+
\\ // tls, (d4)
108+
\\ // ctid (d5)
109+
\\ //)
110+
\\
111+
\\ // save child stack and func into scratch registers
112+
\\ movel 8(%%sp), a0
113+
\\ movel 4(%%sp), a1
114+
\\
115+
\\ // push arg to child stack
116+
\\ movel 16(%%sp), -(%%a0)
117+
\\
118+
\\ // save callee saved register to parent and child stacks,
119+
\\ // then load arg
120+
\\
121+
\\ // flag (not callee saved)
122+
\\ movel 12(%%sp), %%d1
123+
\\
124+
\\ // ptid
125+
\\ movel %%d3, -(%%sp)
126+
\\ movel %%d3, -(%%a0)
127+
\\ movel 20+4(%%sp), %%d3
128+
\\
129+
\\ // tls
130+
\\ movel %%d4, -(%%sp)
131+
\\ movel %%d4, -(%%a0)
132+
\\ movel 24+8(%%sp), %%d4
133+
\\
134+
\\ // child_tidptr
135+
\\ movel %%d5, -(%%sp)
136+
\\ movel %%d5, -(%%a0)
137+
\\ movel 28+12(%%sp), %%d5
138+
\\
139+
\\ // stack
140+
\\ movel %%d2, -(%%sp)
141+
\\ movel %%d2, -(%%a0)
142+
\\ exg %%a0, %%d2
143+
\\
144+
\\ movl #120, %%d0
145+
\\ trap #0
146+
\\
147+
\\ movel (%%sp)+, %%d2
148+
\\ movel (%%sp)+, %%d5
149+
\\ movel (%%sp)+, %%d4
150+
\\ movel (%%sp)+, %%d3
151+
\\
152+
\\ tstl %%d0
153+
\\
154+
\\ jeq 1f
155+
\\
156+
\\ // parent: returns pid of child or -1 on error
157+
\\ rts
158+
\\1:
159+
);
160+
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
161+
\\ .cfi_undefined %%pc
162+
);
163+
asm volatile (
164+
\\ subl %%fp, %%fp // zero fp
165+
\\ jsr (%%a0) // call func
166+
\\
167+
\\ // exit with return value
168+
\\ movel %%d0, %%d1
169+
\\ movel #1, %%d0
170+
\\ trap #0
171+
);
172+
}
173+
174+
pub const restore = restore_rt;
175+
176+
pub fn restore_rt() callconv(.naked) noreturn {
177+
asm volatile ("trap #0"
178+
:
179+
: [number] "{d0}" (@intFromEnum(SYS.rt_sigreturn)),
180+
: "memory"
181+
);
182+
}
183+
184+
pub const F = struct {
185+
pub const DUPFD = 0;
186+
pub const GETFD = 1;
187+
pub const SETFD = 2;
188+
pub const GETFL = 3;
189+
pub const SETFL = 4;
190+
191+
pub const SETOWN = 8;
192+
pub const GETOWN = 9;
193+
pub const SETSIG = 10;
194+
pub const GETSIG = 11;
195+
196+
pub const GETLK = 12;
197+
pub const SETLK = 13;
198+
pub const SETLKW = 14;
199+
200+
pub const SETOWN_EX = 15;
201+
pub const GETOWN_EX = 16;
202+
203+
pub const GETOWNER_UIDS = 17;
204+
205+
pub const RDLCK = 0;
206+
pub const WRLCK = 1;
207+
pub const UNLCK = 2;
208+
};
209+
210+
pub const blksize_t = i32;
211+
pub const nlink_t = u32;
212+
pub const time_t = i32;
213+
pub const mode_t = u32;
214+
pub const off_t = i32;
215+
pub const ino_t = u32;
216+
pub const dev_t = u32;
217+
pub const blkcnt_t = i32;
218+
219+
pub const timeval = extern struct {
220+
sec: time_t,
221+
usec: i32,
222+
};
223+
224+
pub const Flock = extern struct {
225+
type: i16,
226+
whence: i16,
227+
start: off_t,
228+
len: off_t,
229+
pid: pid_t,
230+
};
231+
232+
// TODO: not 100% sure of padding for msghdr
233+
pub const msghdr = extern struct {
234+
name: ?*sockaddr,
235+
namelen: socklen_t,
236+
iov: [*]iovec,
237+
iovlen: i32,
238+
control: ?*anyopaque,
239+
controllen: socklen_t,
240+
flags: i32,
241+
};
242+
243+
pub const msghdr_const = extern struct {
244+
name: ?*const sockaddr,
245+
namelen: socklen_t,
246+
iov: [*]const iovec_const,
247+
iovlen: i32,
248+
control: ?*const anyopaque,
249+
controllen: socklen_t,
250+
flags: i32,
251+
};
252+
253+
pub const Stat = extern struct {
254+
dev: dev_t,
255+
__pad: u16,
256+
ino: ino_t,
257+
mode: mode_t,
258+
nlink: nlink_t,
259+
uid: uid_t,
260+
gid: gid_t,
261+
rdev: dev_t,
262+
__pad2: u16,
263+
size: off_t,
264+
blksize: blksize_t,
265+
blocks: blkcnt_t,
266+
atim: timespec,
267+
mtim: timespec,
268+
ctim: timespec,
269+
__unused: [2]i32,
270+
271+
// Old interface
272+
pub fn atime(self: @This()) timespec {
273+
return self.atim;
274+
}
275+
276+
pub fn mtime(self: @This()) timespec {
277+
return self.mtim;
278+
}
279+
280+
pub fn ctime(self: @This()) timespec {
281+
return self.ctim;
282+
}
283+
};
284+
285+
pub const Elf_Symndx = u32;
286+
287+
// m68k has multiple minimum page sizes.
288+
// glibc sets MMAP2_PAGE_UNIT to -1 so it is queried at runtime.
289+
pub const MMAP2_UNIT = -1;
290+
291+
// glibc 112a0ae18b831bf31f44d81b82666980312511d6
292+
pub const VDSO = null;
293+
294+
/// TODO
295+
pub const ucontext_t = void;
296+
297+
/// TODO
298+
pub const getcontext = {};

0 commit comments

Comments
 (0)