authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-29 10:33:43-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-29 10:33:43-08:00
loge701ac1a51e6f1d39b698b9b258c349b902dd848
tree5260c0b1787f3aac72858164f7e50c81e40fb025
parent89ee4b86210dd3292f39e8ab405834a11865833c
parentf10bff9ffb452eaf22af8dd85412653ac8bd1081
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7237 from koachan/sparc64-longdouble_fork

Add "long double" mapping and implement fork() on Linux/sparc64

3 files changed, 29 insertions(+), 1 deletions(-)

lib/std/os/linux.zig+3-1
......@@ -112,7 +112,9 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:
112112}
113113
114114pub fn fork() usize {
115 if (@hasField(SYS, "fork")) {
115 if (comptime builtin.arch.isSPARC()) {
116 return syscall_fork();
117 } else if (@hasField(SYS, "fork")) {
116118 return syscall0(.fork);
117119 } else {
118120 return syscall2(.clone, SIGCHLD, 0);
lib/std/os/linux/sparc64.zig+23
......@@ -21,6 +21,29 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
2121 );
2222}
2323
24pub fn syscall_fork() usize {
25 // Linux/sparc64 fork() returns two values in %o0 and %o1:
26 // - On the parent's side, %o0 is the child's PID and %o1 is 0.
27 // - On the child's side, %o0 is the parent's PID and %o1 is 1.
28 // We need to clear the child's %o0 so that the return values
29 // conform to the libc convention.
30 return asm volatile (
31 \\ t 0x6d
32 \\ bcc,pt %%xcc, 1f
33 \\ nop
34 \\ ba 2f
35 \\ neg %%o0
36 \\ 1:
37 \\ # Clear the child's %%o0
38 \\ dec %%o1
39 \\ and %%o1, %%o0, %%o0
40 \\ 2:
41 : [ret] "={o0}" (-> usize)
42 : [number] "{g1}" (@enumToInt(SYS.fork))
43 : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
44 );
45}
46
2447pub fn syscall0(number: SYS) usize {
2548 return asm volatile (
2649 \\ t 0x6d
src/stage1/codegen.cpp+3
......@@ -8640,6 +8640,9 @@ static void define_builtin_types(CodeGen *g) {
86408640 case ZigLLVM_ppc64le:
86418641 add_fp_entry(g, "c_longdouble", 128, LLVMFP128Type(), &g->builtin_types.entry_c_longdouble);
86428642 break;
8643 case ZigLLVM_sparcv9:
8644 add_fp_entry(g, "c_longdouble", 128, LLVMFP128Type(), &g->builtin_types.entry_c_longdouble);
8645 break;
86438646 case ZigLLVM_avr:
86448647 // It's either a float or a double, depending on a toolchain switch
86458648 add_fp_entry(g, "c_longdouble", 64, LLVMDoubleType(), &g->builtin_types.entry_c_longdouble);