| author | |
| committer | |
| log | e701ac1a51e6f1d39b698b9b258c349b902dd848 |
| tree | 5260c0b1787f3aac72858164f7e50c81e40fb025 |
| parent | 89ee4b86210dd3292f39e8ab405834a11865833c |
| parent | f10bff9ffb452eaf22af8dd85412653ac8bd1081 |
| signature |
Add "long double" mapping and implement fork() on Linux/sparc643 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: [*: | ... | @@ -112,7 +112,9 @@ pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*: |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | pub fn fork() usize { | 114 | pub fn fork() usize { |
| 115 | if (@hasField(SYS, "fork")) { | 115 | if (comptime builtin.arch.isSPARC()) { |
| 116 | return syscall_fork(); | ||
| 117 | } else if (@hasField(SYS, "fork")) { | ||
| 116 | return syscall0(.fork); | 118 | return syscall0(.fork); |
| 117 | } else { | 119 | } else { |
| 118 | return syscall2(.clone, SIGCHLD, 0); | 120 | return syscall2(.clone, SIGCHLD, 0); |
lib/std/os/linux/sparc64.zig+23| ... | @@ -21,6 +21,29 @@ pub fn syscall_pipe(fd: *[2]i32) usize { | ... | @@ -21,6 +21,29 @@ pub fn syscall_pipe(fd: *[2]i32) usize { |
| 21 | ); | 21 | ); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | pub 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 | |||
| 24 | pub fn syscall0(number: SYS) usize { | 47 | pub fn syscall0(number: SYS) usize { |
| 25 | return asm volatile ( | 48 | return asm volatile ( |
| 26 | \\ t 0x6d | 49 | \\ t 0x6d |
src/stage1/codegen.cpp+3| ... | @@ -8640,6 +8640,9 @@ static void define_builtin_types(CodeGen *g) { | ... | @@ -8640,6 +8640,9 @@ static void define_builtin_types(CodeGen *g) { |
| 8640 | case ZigLLVM_ppc64le: | 8640 | case ZigLLVM_ppc64le: |
| 8641 | add_fp_entry(g, "c_longdouble", 128, LLVMFP128Type(), &g->builtin_types.entry_c_longdouble); | 8641 | add_fp_entry(g, "c_longdouble", 128, LLVMFP128Type(), &g->builtin_types.entry_c_longdouble); |
| 8642 | break; | 8642 | break; |
| 8643 | case ZigLLVM_sparcv9: | ||
| 8644 | add_fp_entry(g, "c_longdouble", 128, LLVMFP128Type(), &g->builtin_types.entry_c_longdouble); | ||
| 8645 | break; | ||
| 8643 | case ZigLLVM_avr: | 8646 | case ZigLLVM_avr: |
| 8644 | // It's either a float or a double, depending on a toolchain switch | 8647 | // It's either a float or a double, depending on a toolchain switch |
| 8645 | add_fp_entry(g, "c_longdouble", 64, LLVMDoubleType(), &g->builtin_types.entry_c_longdouble); | 8648 | add_fp_entry(g, "c_longdouble", 64, LLVMDoubleType(), &g->builtin_types.entry_c_longdouble); |