| author | |
| committer | |
| log | 516040582da20208d2026996c0ca9cf4c1fc20be |
| tree | 8ad0c419222004e01bf984c552239abf2d8b4706 |
| parent | 6d2c427635dfcdbe5867c5af5194cbe175b85003 |
| signature |
11 files changed, 290 insertions(+), 291 deletions(-)
lib/std/os/linux/aarch64.zig+21-21| ... | @@ -116,36 +116,36 @@ pub fn clone() callconv(.naked) u64 { | ... | @@ -116,36 +116,36 @@ pub fn clone() callconv(.naked) u64 { |
| 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 117 | // x8, x0, x1, x2, x3, x4 | 117 | // x8, x0, x1, x2, x3, x4 |
| 118 | asm volatile ( | 118 | asm volatile ( |
| 119 | \\ // align stack and save func,arg | 119 | \\ // align stack and save func,arg |
| 120 | \\ and x1,x1,#-16 | 120 | \\ and x1,x1,#-16 |
| 121 | \\ stp x0,x3,[x1,#-16]! | 121 | \\ stp x0,x3,[x1,#-16]! |
| 122 | \\ | 122 | \\ |
| 123 | \\ // syscall | 123 | \\ // syscall |
| 124 | \\ uxtw x0,w2 | 124 | \\ uxtw x0,w2 |
| 125 | \\ mov x2,x4 | 125 | \\ mov x2,x4 |
| 126 | \\ mov x3,x5 | 126 | \\ mov x3,x5 |
| 127 | \\ mov x4,x6 | 127 | \\ mov x4,x6 |
| 128 | \\ mov x8,#220 // SYS_clone | 128 | \\ mov x8,#220 // SYS_clone |
| 129 | \\ svc #0 | 129 | \\ svc #0 |
| 130 | \\ | 130 | \\ |
| 131 | \\ cbz x0,1f | 131 | \\ cbz x0,1f |
| 132 | \\ // parent | 132 | \\ // parent |
| 133 | \\ ret | 133 | \\ ret |
| 134 | \\ | 134 | \\ |
| 135 | \\ // child | 135 | \\ // child |
| 136 | \\1: | 136 | \\1: |
| 137 | ); | 137 | ); |
| 138 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 138 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 139 | \\ .cfi_undefined lr | 139 | \\ .cfi_undefined lr |
| 140 | ); | 140 | ); |
| 141 | asm volatile ( | 141 | asm volatile ( |
| 142 | \\ mov fp, 0 | 142 | \\ mov fp, 0 |
| 143 | \\ mov lr, 0 | 143 | \\ mov lr, 0 |
| 144 | \\ | 144 | \\ |
| 145 | \\ ldp x1,x0,[sp],#16 | 145 | \\ ldp x1,x0,[sp],#16 |
| 146 | \\ blr x1 | 146 | \\ blr x1 |
| 147 | \\ mov x8,#93 // SYS_exit | 147 | \\ mov x8,#93 // SYS_exit |
| 148 | \\ svc #0 | 148 | \\ svc #0 |
| 149 | ); | 149 | ); |
| 150 | } | 150 | } |
| 151 | 151 |
lib/std/os/linux/arc.zig+23-23| ... | @@ -116,37 +116,37 @@ pub fn clone() callconv(.naked) u32 { | ... | @@ -116,37 +116,37 @@ pub fn clone() callconv(.naked) u32 { |
| 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 117 | // r8 r0, r1, r2, r3, r4 | 117 | // r8 r0, r1, r2, r3, r4 |
| 118 | asm volatile ( | 118 | asm volatile ( |
| 119 | \\ // Align stack pointer | 119 | \\ // Align stack pointer |
| 120 | \\ and r1, r1, -16 | 120 | \\ and r1, r1, -16 |
| 121 | \\ mov r10, r0 | 121 | \\ mov r10, r0 |
| 122 | \\ mov r11, r3 | 122 | \\ mov r11, r3 |
| 123 | \\ // Setup the arguments | 123 | \\ // Setup the arguments |
| 124 | \\ mov r0, r2 | 124 | \\ mov r0, r2 |
| 125 | \\ mov r2, r4 | 125 | \\ mov r2, r4 |
| 126 | \\ mov r3, r5 | 126 | \\ mov r3, r5 |
| 127 | \\ mov r4, r6 | 127 | \\ mov r4, r6 |
| 128 | \\ mov r8, 220 // SYS_clone | 128 | \\ mov r8, 220 // SYS_clone |
| 129 | \\ trap_s 0 | 129 | \\ trap_s 0 |
| 130 | \\ cmp r0, 0 | 130 | \\ cmp r0, 0 |
| 131 | \\ beq 1f | 131 | \\ beq 1f |
| 132 | \\ j [blink] | 132 | \\ j [blink] |
| 133 | \\ // Child | 133 | \\ // Child |
| 134 | \\ 1: | 134 | \\1: |
| 135 | ); | 135 | ); |
| 136 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 136 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 137 | \\ .cfi_undefined blink | 137 | \\ .cfi_undefined blink |
| 138 | ); | 138 | ); |
| 139 | 139 | ||
| 140 | asm volatile ( | 140 | asm volatile ( |
| 141 | \\ mov fp, 0 | 141 | \\ mov fp, 0 |
| 142 | \\ mov blink, 0 | 142 | \\ mov blink, 0 |
| 143 | \\ | 143 | \\ |
| 144 | \\ mov r0, r11 | 144 | \\ mov r0, r11 |
| 145 | \\ jl [r10] | 145 | \\ jl [r10] |
| 146 | \\ | 146 | \\ |
| 147 | \\ // Exit | 147 | \\ // Exit |
| 148 | \\ mov r8, 93 // SYS_exit | 148 | \\ mov r8, 93 // SYS_exit |
| 149 | \\ trap_s 0 | 149 | \\ trap_s 0 |
| 150 | ); | 150 | ); |
| 151 | } | 151 | } |
| 152 | 152 |
lib/std/os/linux/arm.zig+25-23| ... | @@ -116,32 +116,34 @@ pub fn clone() callconv(.naked) u32 { | ... | @@ -116,32 +116,34 @@ pub fn clone() callconv(.naked) u32 { |
| 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 117 | // r7 r0, r1, r2, r3, r4 | 117 | // r7 r0, r1, r2, r3, r4 |
| 118 | asm volatile ( | 118 | asm volatile ( |
| 119 | \\ stmfd sp!,{r4,r5,r6,r7} | 119 | \\ stmfd sp!,{r4,r5,r6,r7} |
| 120 | \\ mov r7,#120 // SYS_clone | 120 | \\ mov r7,#120 // SYS_clone |
| 121 | \\ mov r6,r3 | 121 | \\ mov r6,r3 |
| 122 | \\ mov r5,r0 | 122 | \\ mov r5,r0 |
| 123 | \\ mov r0,r2 | 123 | \\ mov r0,r2 |
| 124 | \\ and r1,r1,#-16 | 124 | \\ and r1,r1,#-16 |
| 125 | \\ ldr r2,[sp,#16] | 125 | \\ ldr r2,[sp,#16] |
| 126 | \\ ldr r3,[sp,#20] | 126 | \\ ldr r3,[sp,#20] |
| 127 | \\ ldr r4,[sp,#24] | 127 | \\ ldr r4,[sp,#24] |
| 128 | \\ svc 0 | 128 | \\ svc 0 |
| 129 | \\ tst r0,r0 | 129 | \\ tst r0,r0 |
| 130 | \\ beq 1f | 130 | \\ beq 1f |
| 131 | \\ ldmfd sp!,{r4,r5,r6,r7} | 131 | \\ ldmfd sp!,{r4,r5,r6,r7} |
| 132 | \\ bx lr | 132 | \\ bx lr |
| 133 | \\ | 133 | \\ |
| 134 | \\ // https://github.com/llvm/llvm-project/issues/115891 | 134 | \\ // https://github.com/llvm/llvm-project/issues/115891 |
| 135 | \\1: mov r7, #0 | 135 | \\1: |
| 136 | \\ mov r11, #0 | 136 | \\ mov r7, #0 |
| 137 | \\ mov lr, #0 | 137 | \\ mov r11, #0 |
| 138 | \\ mov lr, #0 | ||
| 138 | \\ | 139 | \\ |
| 139 | \\ mov r0,r6 | 140 | \\ mov r0,r6 |
| 140 | \\ bl 3f | 141 | \\ bl 3f |
| 141 | \\ mov r7,#1 // SYS_exit | 142 | \\ mov r7,#1 // SYS_exit |
| 142 | \\ svc 0 | 143 | \\ svc 0 |
| 143 | \\ | 144 | \\ |
| 144 | \\3: bx r5 | 145 | \\3: |
| 146 | \\ bx r5 | ||
| 145 | ); | 147 | ); |
| 146 | } | 148 | } |
| 147 | 149 |
lib/std/os/linux/powerpc.zig+7-7| ... | @@ -16,7 +16,7 @@ pub fn syscall0( | ... | @@ -16,7 +16,7 @@ pub fn syscall0( |
| 16 | \\ sc | 16 | \\ sc |
| 17 | \\ bns+ 1f | 17 | \\ bns+ 1f |
| 18 | \\ neg 3, 3 | 18 | \\ neg 3, 3 |
| 19 | \\ 1: | 19 | \\1: |
| 20 | : [ret] "={r3}" (-> u32), | 20 | : [ret] "={r3}" (-> u32), |
| 21 | [r0_out] "={r0}" (r0_out), | 21 | [r0_out] "={r0}" (r0_out), |
| 22 | : [number] "{r0}" (@backingInt(number)), | 22 | : [number] "{r0}" (@backingInt(number)), |
| ... | @@ -33,7 +33,7 @@ pub fn syscall1( | ... | @@ -33,7 +33,7 @@ pub fn syscall1( |
| 33 | \\ sc | 33 | \\ sc |
| 34 | \\ bns+ 1f | 34 | \\ bns+ 1f |
| 35 | \\ neg 3, 3 | 35 | \\ neg 3, 3 |
| 36 | \\ 1: | 36 | \\1: |
| 37 | : [ret] "={r3}" (-> u32), | 37 | : [ret] "={r3}" (-> u32), |
| 38 | [r0_out] "={r0}" (r0_out), | 38 | [r0_out] "={r0}" (r0_out), |
| 39 | : [number] "{r0}" (@backingInt(number)), | 39 | : [number] "{r0}" (@backingInt(number)), |
| ... | @@ -53,7 +53,7 @@ pub fn syscall2( | ... | @@ -53,7 +53,7 @@ pub fn syscall2( |
| 53 | \\ sc | 53 | \\ sc |
| 54 | \\ bns+ 1f | 54 | \\ bns+ 1f |
| 55 | \\ neg 3, 3 | 55 | \\ neg 3, 3 |
| 56 | \\ 1: | 56 | \\1: |
| 57 | : [ret] "={r3}" (-> u32), | 57 | : [ret] "={r3}" (-> u32), |
| 58 | [r0_out] "={r0}" (r0_out), | 58 | [r0_out] "={r0}" (r0_out), |
| 59 | [r4_out] "={r4}" (r4_out), | 59 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -77,7 +77,7 @@ pub fn syscall3( | ... | @@ -77,7 +77,7 @@ pub fn syscall3( |
| 77 | \\ sc | 77 | \\ sc |
| 78 | \\ bns+ 1f | 78 | \\ bns+ 1f |
| 79 | \\ neg 3, 3 | 79 | \\ neg 3, 3 |
| 80 | \\ 1: | 80 | \\1: |
| 81 | : [ret] "={r3}" (-> u32), | 81 | : [ret] "={r3}" (-> u32), |
| 82 | [r0_out] "={r0}" (r0_out), | 82 | [r0_out] "={r0}" (r0_out), |
| 83 | [r4_out] "={r4}" (r4_out), | 83 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -105,7 +105,7 @@ pub fn syscall4( | ... | @@ -105,7 +105,7 @@ pub fn syscall4( |
| 105 | \\ sc | 105 | \\ sc |
| 106 | \\ bns+ 1f | 106 | \\ bns+ 1f |
| 107 | \\ neg 3, 3 | 107 | \\ neg 3, 3 |
| 108 | \\ 1: | 108 | \\1: |
| 109 | : [ret] "={r3}" (-> u32), | 109 | : [ret] "={r3}" (-> u32), |
| 110 | [r0_out] "={r0}" (r0_out), | 110 | [r0_out] "={r0}" (r0_out), |
| 111 | [r4_out] "={r4}" (r4_out), | 111 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -137,7 +137,7 @@ pub fn syscall5( | ... | @@ -137,7 +137,7 @@ pub fn syscall5( |
| 137 | \\ sc | 137 | \\ sc |
| 138 | \\ bns+ 1f | 138 | \\ bns+ 1f |
| 139 | \\ neg 3, 3 | 139 | \\ neg 3, 3 |
| 140 | \\ 1: | 140 | \\1: |
| 141 | : [ret] "={r3}" (-> u32), | 141 | : [ret] "={r3}" (-> u32), |
| 142 | [r0_out] "={r0}" (r0_out), | 142 | [r0_out] "={r0}" (r0_out), |
| 143 | [r4_out] "={r4}" (r4_out), | 143 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -173,7 +173,7 @@ pub fn syscall6( | ... | @@ -173,7 +173,7 @@ pub fn syscall6( |
| 173 | \\ sc | 173 | \\ sc |
| 174 | \\ bns+ 1f | 174 | \\ bns+ 1f |
| 175 | \\ neg 3, 3 | 175 | \\ neg 3, 3 |
| 176 | \\ 1: | 176 | \\1: |
| 177 | : [ret] "={r3}" (-> u32), | 177 | : [ret] "={r3}" (-> u32), |
| 178 | [r0_out] "={r0}" (r0_out), | 178 | [r0_out] "={r0}" (r0_out), |
| 179 | [r4_out] "={r4}" (r4_out), | 179 | [r4_out] "={r4}" (r4_out), |
lib/std/os/linux/powerpc64.zig+40-40| ... | @@ -16,7 +16,7 @@ pub fn syscall0( | ... | @@ -16,7 +16,7 @@ pub fn syscall0( |
| 16 | \\ sc | 16 | \\ sc |
| 17 | \\ bns+ 1f | 17 | \\ bns+ 1f |
| 18 | \\ neg 3, 3 | 18 | \\ neg 3, 3 |
| 19 | \\ 1: | 19 | \\1: |
| 20 | : [ret] "={r3}" (-> u64), | 20 | : [ret] "={r3}" (-> u64), |
| 21 | [r0_out] "={r0}" (r0_out), | 21 | [r0_out] "={r0}" (r0_out), |
| 22 | : [number] "{r0}" (@backingInt(number)), | 22 | : [number] "{r0}" (@backingInt(number)), |
| ... | @@ -33,7 +33,7 @@ pub fn syscall1( | ... | @@ -33,7 +33,7 @@ pub fn syscall1( |
| 33 | \\ sc | 33 | \\ sc |
| 34 | \\ bns+ 1f | 34 | \\ bns+ 1f |
| 35 | \\ neg 3, 3 | 35 | \\ neg 3, 3 |
| 36 | \\ 1: | 36 | \\1: |
| 37 | : [ret] "={r3}" (-> u64), | 37 | : [ret] "={r3}" (-> u64), |
| 38 | [r0_out] "={r0}" (r0_out), | 38 | [r0_out] "={r0}" (r0_out), |
| 39 | : [number] "{r0}" (@backingInt(number)), | 39 | : [number] "{r0}" (@backingInt(number)), |
| ... | @@ -53,7 +53,7 @@ pub fn syscall2( | ... | @@ -53,7 +53,7 @@ pub fn syscall2( |
| 53 | \\ sc | 53 | \\ sc |
| 54 | \\ bns+ 1f | 54 | \\ bns+ 1f |
| 55 | \\ neg 3, 3 | 55 | \\ neg 3, 3 |
| 56 | \\ 1: | 56 | \\1: |
| 57 | : [ret] "={r3}" (-> u64), | 57 | : [ret] "={r3}" (-> u64), |
| 58 | [r0_out] "={r0}" (r0_out), | 58 | [r0_out] "={r0}" (r0_out), |
| 59 | [r4_out] "={r4}" (r4_out), | 59 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -77,7 +77,7 @@ pub fn syscall3( | ... | @@ -77,7 +77,7 @@ pub fn syscall3( |
| 77 | \\ sc | 77 | \\ sc |
| 78 | \\ bns+ 1f | 78 | \\ bns+ 1f |
| 79 | \\ neg 3, 3 | 79 | \\ neg 3, 3 |
| 80 | \\ 1: | 80 | \\1: |
| 81 | : [ret] "={r3}" (-> u64), | 81 | : [ret] "={r3}" (-> u64), |
| 82 | [r0_out] "={r0}" (r0_out), | 82 | [r0_out] "={r0}" (r0_out), |
| 83 | [r4_out] "={r4}" (r4_out), | 83 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -105,7 +105,7 @@ pub fn syscall4( | ... | @@ -105,7 +105,7 @@ pub fn syscall4( |
| 105 | \\ sc | 105 | \\ sc |
| 106 | \\ bns+ 1f | 106 | \\ bns+ 1f |
| 107 | \\ neg 3, 3 | 107 | \\ neg 3, 3 |
| 108 | \\ 1: | 108 | \\1: |
| 109 | : [ret] "={r3}" (-> u64), | 109 | : [ret] "={r3}" (-> u64), |
| 110 | [r0_out] "={r0}" (r0_out), | 110 | [r0_out] "={r0}" (r0_out), |
| 111 | [r4_out] "={r4}" (r4_out), | 111 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -137,7 +137,7 @@ pub fn syscall5( | ... | @@ -137,7 +137,7 @@ pub fn syscall5( |
| 137 | \\ sc | 137 | \\ sc |
| 138 | \\ bns+ 1f | 138 | \\ bns+ 1f |
| 139 | \\ neg 3, 3 | 139 | \\ neg 3, 3 |
| 140 | \\ 1: | 140 | \\1: |
| 141 | : [ret] "={r3}" (-> u64), | 141 | : [ret] "={r3}" (-> u64), |
| 142 | [r0_out] "={r0}" (r0_out), | 142 | [r0_out] "={r0}" (r0_out), |
| 143 | [r4_out] "={r4}" (r4_out), | 143 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -173,7 +173,7 @@ pub fn syscall6( | ... | @@ -173,7 +173,7 @@ pub fn syscall6( |
| 173 | \\ sc | 173 | \\ sc |
| 174 | \\ bns+ 1f | 174 | \\ bns+ 1f |
| 175 | \\ neg 3, 3 | 175 | \\ neg 3, 3 |
| 176 | \\ 1: | 176 | \\1: |
| 177 | : [ret] "={r3}" (-> u64), | 177 | : [ret] "={r3}" (-> u64), |
| 178 | [r0_out] "={r0}" (r0_out), | 178 | [r0_out] "={r0}" (r0_out), |
| 179 | [r4_out] "={r4}" (r4_out), | 179 | [r4_out] "={r4}" (r4_out), |
| ... | @@ -198,51 +198,51 @@ pub fn clone() callconv(.naked) u64 { | ... | @@ -198,51 +198,51 @@ pub fn clone() callconv(.naked) u64 { |
| 198 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 198 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 199 | // 0 3, 4, 5, 6, 7 | 199 | // 0 3, 4, 5, 6, 7 |
| 200 | asm volatile ( | 200 | asm volatile ( |
| 201 | \\ # create initial stack frame for new thread | 201 | \\ # create initial stack frame for new thread |
| 202 | \\ clrrdi 4, 4, 4 | 202 | \\ clrrdi 4, 4, 4 |
| 203 | \\ li 0, 0 | 203 | \\ li 0, 0 |
| 204 | \\ stdu 0,-32(4) | 204 | \\ stdu 0,-32(4) |
| 205 | \\ | 205 | \\ |
| 206 | \\ # save fn and arg to child stack | 206 | \\ # save fn and arg to child stack |
| 207 | \\ std 3, 8(4) | 207 | \\ std 3, 8(4) |
| 208 | \\ std 6, 16(4) | 208 | \\ std 6, 16(4) |
| 209 | \\ | 209 | \\ |
| 210 | \\ # shuffle args into correct registers and call SYS_clone | 210 | \\ # shuffle args into correct registers and call SYS_clone |
| 211 | \\ mr 3, 5 | 211 | \\ mr 3, 5 |
| 212 | \\ #mr 4, 4 | 212 | \\ #mr 4, 4 |
| 213 | \\ mr 5, 7 | 213 | \\ mr 5, 7 |
| 214 | \\ mr 6, 8 | 214 | \\ mr 6, 8 |
| 215 | \\ mr 7, 9 | 215 | \\ mr 7, 9 |
| 216 | \\ li 0, 120 # SYS_clone = 120 | 216 | \\ li 0, 120 # SYS_clone = 120 |
| 217 | \\ sc | 217 | \\ sc |
| 218 | \\ | 218 | \\ |
| 219 | \\ # if error, negate return (errno) | 219 | \\ # if error, negate return (errno) |
| 220 | \\ bns+ 1f | 220 | \\ bns+ 1f |
| 221 | \\ neg 3, 3 | 221 | \\ neg 3, 3 |
| 222 | \\ | 222 | \\ |
| 223 | \\1: | 223 | \\1: |
| 224 | \\ # if we're the parent, return | 224 | \\ # if we're the parent, return |
| 225 | \\ cmpwi cr7, 3, 0 | 225 | \\ cmpwi cr7, 3, 0 |
| 226 | \\ bnelr cr7 | 226 | \\ bnelr cr7 |
| 227 | \\ | 227 | \\ |
| 228 | \\ # we're the child | 228 | \\ # we're the child |
| 229 | ); | 229 | ); |
| 230 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 230 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 231 | \\ .cfi_undefined lr | 231 | \\ .cfi_undefined lr |
| 232 | ); | 232 | ); |
| 233 | asm volatile ( | 233 | asm volatile ( |
| 234 | \\ li 31, 0 | 234 | \\ li 31, 0 |
| 235 | \\ mtlr 31 | 235 | \\ mtlr 31 |
| 236 | \\ | 236 | \\ |
| 237 | \\ # call fn(arg) | 237 | \\ # call fn(arg) |
| 238 | \\ ld 3, 16(1) | 238 | \\ ld 3, 16(1) |
| 239 | \\ ld 12, 8(1) | 239 | \\ ld 12, 8(1) |
| 240 | \\ mtctr 12 | 240 | \\ mtctr 12 |
| 241 | \\ bctrl | 241 | \\ bctrl |
| 242 | \\ | 242 | \\ |
| 243 | \\ # call SYS_exit. exit code is already in r3 from fn return value | 243 | \\ # call SYS_exit. exit code is already in r3 from fn return value |
| 244 | \\ li 0, 1 # SYS_exit = 1 | 244 | \\ li 0, 1 # SYS_exit = 1 |
| 245 | \\ sc | 245 | \\ sc |
| 246 | ); | 246 | ); |
| 247 | } | 247 | } |
| 248 | 248 |
lib/std/os/linux/riscv32.zig+25-25| ... | @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u32 { | ... | @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u32 { |
| 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 117 | // a7 a0, a1, a2, a3, a4 | 117 | // a7 a0, a1, a2, a3, a4 |
| 118 | asm volatile ( | 118 | asm volatile ( |
| 119 | \\ andi a1, a1, -16 | 119 | \\ andi a1, a1, -16 |
| 120 | \\ # Save func and arg to stack | 120 | \\ # Save func and arg to stack |
| 121 | \\ addi a1, a1, -16 | 121 | \\ addi a1, a1, -16 |
| 122 | \\ sw a0, 0(a1) | 122 | \\ sw a0, 0(a1) |
| 123 | \\ sw a3, 4(a1) | 123 | \\ sw a3, 4(a1) |
| 124 | \\ | 124 | \\ |
| 125 | \\ # Call SYS_clone | 125 | \\ # Call SYS_clone |
| 126 | \\ mv a0, a2 | 126 | \\ mv a0, a2 |
| 127 | \\ mv a2, a4 | 127 | \\ mv a2, a4 |
| 128 | \\ mv a3, a5 | 128 | \\ mv a3, a5 |
| 129 | \\ mv a4, a6 | 129 | \\ mv a4, a6 |
| 130 | \\ li a7, 220 # SYS_clone | 130 | \\ li a7, 220 # SYS_clone |
| 131 | \\ ecall | 131 | \\ ecall |
| 132 | \\ | 132 | \\ |
| 133 | \\ beqz a0, 1f | 133 | \\ beqz a0, 1f |
| 134 | \\ # Parent | 134 | \\ # Parent |
| 135 | \\ ret | 135 | \\ ret |
| 136 | \\ | 136 | \\ |
| 137 | \\ # Child | 137 | \\ # Child |
| 138 | \\1: | 138 | \\1: |
| 139 | ); | 139 | ); |
| 140 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 140 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 141 | \\ .cfi_undefined ra | 141 | \\ .cfi_undefined ra |
| 142 | ); | 142 | ); |
| 143 | asm volatile ( | 143 | asm volatile ( |
| 144 | \\ mv fp, zero | 144 | \\ mv fp, zero |
| 145 | \\ mv ra, zero | 145 | \\ mv ra, zero |
| 146 | \\ | 146 | \\ |
| 147 | \\ lw a1, 0(sp) | 147 | \\ lw a1, 0(sp) |
| 148 | \\ lw a0, 4(sp) | 148 | \\ lw a0, 4(sp) |
| 149 | \\ jalr a1 | 149 | \\ jalr a1 |
| 150 | \\ | 150 | \\ |
| 151 | \\ # Exit | 151 | \\ # Exit |
| 152 | \\ li a7, 93 # SYS_exit | 152 | \\ li a7, 93 # SYS_exit |
| 153 | \\ ecall | 153 | \\ ecall |
| 154 | ); | 154 | ); |
| 155 | } | 155 | } |
| 156 | 156 |
lib/std/os/linux/riscv64.zig+25-25| ... | @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u64 { | ... | @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u64 { |
| 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 116 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 117 | // a7 a0, a1, a2, a3, a4 | 117 | // a7 a0, a1, a2, a3, a4 |
| 118 | asm volatile ( | 118 | asm volatile ( |
| 119 | \\ andi a1, a1, -16 | 119 | \\ andi a1, a1, -16 |
| 120 | \\ # Save func and arg to stack | 120 | \\ # Save func and arg to stack |
| 121 | \\ addi a1, a1, -16 | 121 | \\ addi a1, a1, -16 |
| 122 | \\ sd a0, 0(a1) | 122 | \\ sd a0, 0(a1) |
| 123 | \\ sd a3, 8(a1) | 123 | \\ sd a3, 8(a1) |
| 124 | \\ | 124 | \\ |
| 125 | \\ # Call SYS_clone | 125 | \\ # Call SYS_clone |
| 126 | \\ mv a0, a2 | 126 | \\ mv a0, a2 |
| 127 | \\ mv a2, a4 | 127 | \\ mv a2, a4 |
| 128 | \\ mv a3, a5 | 128 | \\ mv a3, a5 |
| 129 | \\ mv a4, a6 | 129 | \\ mv a4, a6 |
| 130 | \\ li a7, 220 # SYS_clone | 130 | \\ li a7, 220 # SYS_clone |
| 131 | \\ ecall | 131 | \\ ecall |
| 132 | \\ | 132 | \\ |
| 133 | \\ beqz a0, 1f | 133 | \\ beqz a0, 1f |
| 134 | \\ # Parent | 134 | \\ # Parent |
| 135 | \\ ret | 135 | \\ ret |
| 136 | \\ | 136 | \\ |
| 137 | \\ # Child | 137 | \\ # Child |
| 138 | \\1: | 138 | \\1: |
| 139 | ); | 139 | ); |
| 140 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 140 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 141 | \\ .cfi_undefined ra | 141 | \\ .cfi_undefined ra |
| 142 | ); | 142 | ); |
| 143 | asm volatile ( | 143 | asm volatile ( |
| 144 | \\ mv fp, zero | 144 | \\ mv fp, zero |
| 145 | \\ mv ra, zero | 145 | \\ mv ra, zero |
| 146 | \\ | 146 | \\ |
| 147 | \\ ld a1, 0(sp) | 147 | \\ ld a1, 0(sp) |
| 148 | \\ ld a0, 8(sp) | 148 | \\ ld a0, 8(sp) |
| 149 | \\ jalr a1 | 149 | \\ jalr a1 |
| 150 | \\ | 150 | \\ |
| 151 | \\ # Exit | 151 | \\ # Exit |
| 152 | \\ li a7, 93 # SYS_exit | 152 | \\ li a7, 93 # SYS_exit |
| 153 | \\ ecall | 153 | \\ ecall |
| 154 | ); | 154 | ); |
| 155 | } | 155 | } |
| 156 | 156 |
lib/std/os/linux/s390x.zig+49-50| ... | @@ -111,72 +111,71 @@ pub fn syscall6( | ... | @@ -111,72 +111,71 @@ pub fn syscall6( |
| 111 | 111 | ||
| 112 | pub fn clone() callconv(.naked) u64 { | 112 | pub fn clone() callconv(.naked) u64 { |
| 113 | asm volatile ( | 113 | asm volatile ( |
| 114 | \\# int clone( | 114 | \\ # int clone( |
| 115 | \\# fn, a = r2 | 115 | \\ # fn, a = r2 |
| 116 | \\# stack, b = r3 | 116 | \\ # stack, b = r3 |
| 117 | \\# flags, c = r4 | 117 | \\ # flags, c = r4 |
| 118 | \\# arg, d = r5 | 118 | \\ # arg, d = r5 |
| 119 | \\# ptid, e = r6 | 119 | \\ # ptid, e = r6 |
| 120 | \\# tls, f = *(r15+160) | 120 | \\ # tls, f = *(r15+160) |
| 121 | \\# ctid) g = *(r15+168) | 121 | \\ # ctid) g = *(r15+168) |
| 122 | \\# | 122 | \\ # |
| 123 | \\# pseudo C code: | 123 | \\ # pseudo C code: |
| 124 | \\# tid = syscall(SYS_clone,b,c,e,g,f); | 124 | \\ # tid = syscall(SYS_clone,b,c,e,g,f); |
| 125 | \\# if (!tid) syscall(SYS_exit, a(d)); | 125 | \\ # if (!tid) syscall(SYS_exit, a(d)); |
| 126 | \\# return tid; | 126 | \\ # return tid; |
| 127 | \\ | 127 | \\ |
| 128 | \\# preserve call-saved register used as syscall arg | 128 | \\ # preserve call-saved register used as syscall arg |
| 129 | \\stg %%r6, 48(%%r15) | 129 | \\ stg %%r6, 48(%%r15) |
| 130 | \\ | 130 | \\ |
| 131 | \\# create initial stack frame for new thread | 131 | \\ # create initial stack frame for new thread |
| 132 | \\nill %%r3, 0xfff8 | 132 | \\ nill %%r3, 0xfff8 |
| 133 | \\aghi %%r3, -160 | 133 | \\ aghi %%r3, -160 |
| 134 | \\lghi %%r0, 0 | 134 | \\ lghi %%r0, 0 |
| 135 | \\stg %%r0, 0(%%r3) | 135 | \\ stg %%r0, 0(%%r3) |
| 136 | \\ | 136 | \\ |
| 137 | \\# save fn and arg to child stack | 137 | \\ # save fn and arg to child stack |
| 138 | \\stg %%r2, 8(%%r3) | 138 | \\ stg %%r2, 8(%%r3) |
| 139 | \\stg %%r5, 16(%%r3) | 139 | \\ stg %%r5, 16(%%r3) |
| 140 | \\ | 140 | \\ |
| 141 | \\# shuffle args into correct registers and call SYS_clone | 141 | \\ # shuffle args into correct registers and call SYS_clone |
| 142 | \\lgr %%r2, %%r3 | 142 | \\ lgr %%r2, %%r3 |
| 143 | \\lgr %%r3, %%r4 | 143 | \\ lgr %%r3, %%r4 |
| 144 | \\lgr %%r4, %%r6 | 144 | \\ lgr %%r4, %%r6 |
| 145 | \\lg %%r5, 168(%%r15) | 145 | \\ lg %%r5, 168(%%r15) |
| 146 | \\lg %%r6, 160(%%r15) | 146 | \\ lg %%r6, 160(%%r15) |
| 147 | \\svc 120 | 147 | \\ svc 120 |
| 148 | \\ | 148 | \\ |
| 149 | \\# restore call-saved register | 149 | \\ # restore call-saved register |
| 150 | \\lg %%r6, 48(%%r15) | 150 | \\ lg %%r6, 48(%%r15) |
| 151 | \\ | 151 | \\ |
| 152 | \\# if error or if we're the parent, return | 152 | \\ # if error or if we're the parent, return |
| 153 | \\ltgr %%r2, %%r2 | 153 | \\ ltgr %%r2, %%r2 |
| 154 | \\bnzr %%r14 | 154 | \\ bnzr %%r14 |
| 155 | \\ | 155 | \\ |
| 156 | \\# we're the child | 156 | \\ # we're the child |
| 157 | ); | 157 | ); |
| 158 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 158 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 159 | \\.cfi_undefined %%r14 | 159 | \\ .cfi_undefined %%r14 |
| 160 | ); | 160 | ); |
| 161 | asm volatile ( | 161 | asm volatile ( |
| 162 | \\lghi %%r11, 0 | 162 | \\ lghi %%r11, 0 |
| 163 | \\lghi %%r14, 0 | 163 | \\ lghi %%r14, 0 |
| 164 | \\ | 164 | \\ |
| 165 | \\# call fn(arg) | 165 | \\ # call fn(arg) |
| 166 | \\lg %%r1, 8(%%r15) | 166 | \\ lg %%r1, 8(%%r15) |
| 167 | \\lg %%r2, 16(%%r15) | 167 | \\ lg %%r2, 16(%%r15) |
| 168 | \\basr %%r14, %%r1 | 168 | \\ basr %%r14, %%r1 |
| 169 | \\ | ||
| 170 | \\# call SYS_exit. exit code is already in r2 from fn return value | ||
| 171 | \\svc 1 | ||
| 172 | \\ | 169 | \\ |
| 170 | \\ # call SYS_exit. exit code is already in r2 from fn return value | ||
| 171 | \\ svc 1 | ||
| 173 | ); | 172 | ); |
| 174 | } | 173 | } |
| 175 | 174 | ||
| 176 | pub fn restore() callconv(.naked) noreturn { | 175 | pub fn restore() callconv(.naked) noreturn { |
| 177 | asm volatile ( | 176 | asm volatile ( |
| 178 | \\lghi %%r1, %[number] | 177 | \\ lghi %%r1, %[number] |
| 179 | \\svc 0 | 178 | \\ svc 0 |
| 180 | : | 179 | : |
| 181 | : [number] "K" (@backingInt(SYS.sigreturn)), | 180 | : [number] "K" (@backingInt(SYS.sigreturn)), |
| 182 | ); | 181 | ); |
| ... | @@ -184,8 +183,8 @@ pub fn restore() callconv(.naked) noreturn { | ... | @@ -184,8 +183,8 @@ pub fn restore() callconv(.naked) noreturn { |
| 184 | 183 | ||
| 185 | pub fn restore_rt() callconv(.naked) noreturn { | 184 | pub fn restore_rt() callconv(.naked) noreturn { |
| 186 | asm volatile ( | 185 | asm volatile ( |
| 187 | \\lghi %%r1, %[number] | 186 | \\ lghi %%r1, %[number] |
| 188 | \\svc 0 | 187 | \\ svc 0 |
| 189 | : | 188 | : |
| 190 | : [number] "K" (@backingInt(SYS.rt_sigreturn)), | 189 | : [number] "K" (@backingInt(SYS.rt_sigreturn)), |
| 191 | ); | 190 | ); |
lib/std/os/linux/x32.zig+21-22| ... | @@ -125,35 +125,34 @@ pub fn syscall_lseek( | ... | @@ -125,35 +125,34 @@ pub fn syscall_lseek( |
| 125 | 125 | ||
| 126 | pub fn clone() callconv(.naked) u32 { | 126 | pub fn clone() callconv(.naked) u32 { |
| 127 | asm volatile ( | 127 | asm volatile ( |
| 128 | \\ movl $0x40000038,%%eax // SYS_clone | 128 | \\ movl $0x40000038,%%eax // SYS_clone |
| 129 | \\ mov %%rdi,%%r11 | 129 | \\ mov %%rdi,%%r11 |
| 130 | \\ mov %%rdx,%%rdi | 130 | \\ mov %%rdx,%%rdi |
| 131 | \\ mov %%r8,%%rdx | 131 | \\ mov %%r8,%%rdx |
| 132 | \\ mov %%r9,%%r8 | 132 | \\ mov %%r9,%%r8 |
| 133 | \\ mov 8(%%rsp),%%r10d | 133 | \\ mov 8(%%rsp),%%r10d |
| 134 | \\ mov %%r11,%%r9 | 134 | \\ mov %%r11,%%r9 |
| 135 | \\ and $-16,%%rsi | 135 | \\ and $-16,%%rsi |
| 136 | \\ sub $8,%%rsi | 136 | \\ sub $8,%%rsi |
| 137 | \\ mov %%rcx,(%%rsi) | 137 | \\ mov %%rcx,(%%rsi) |
| 138 | \\ syscall | 138 | \\ syscall |
| 139 | \\ test %%eax,%%eax | 139 | \\ test %%eax,%%eax |
| 140 | \\ jz 1f | 140 | \\ jz 1f |
| 141 | \\ ret | 141 | \\ ret |
| 142 | \\ | 142 | \\ |
| 143 | \\1: | 143 | \\1: |
| 144 | ); | 144 | ); |
| 145 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 145 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 146 | \\ .cfi_undefined %%rip | 146 | \\ .cfi_undefined %%rip |
| 147 | ); | 147 | ); |
| 148 | asm volatile ( | 148 | asm volatile ( |
| 149 | \\ xor %%ebp,%%ebp | 149 | \\ xor %%ebp,%%ebp |
| 150 | \\ | ||
| 151 | \\ pop %%rdi | ||
| 152 | \\ call *%%r9 | ||
| 153 | \\ mov %%eax,%%edi | ||
| 154 | \\ movl $0x4000003c,%%eax // SYS_exit | ||
| 155 | \\ syscall | ||
| 156 | \\ | 150 | \\ |
| 151 | \\ pop %%rdi | ||
| 152 | \\ call *%%r9 | ||
| 153 | \\ mov %%eax,%%edi | ||
| 154 | \\ movl $0x4000003c,%%eax // SYS_exit | ||
| 155 | \\ syscall | ||
| 157 | ); | 156 | ); |
| 158 | } | 157 | } |
| 159 | 158 |
lib/std/os/linux/x86.zig+33-33| ... | @@ -142,46 +142,46 @@ pub fn clone() callconv(.naked) u32 { | ... | @@ -142,46 +142,46 @@ pub fn clone() callconv(.naked) u32 { |
| 142 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | 142 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 143 | // eax, ebx, ecx, edx, esi, edi | 143 | // eax, ebx, ecx, edx, esi, edi |
| 144 | asm volatile ( | 144 | asm volatile ( |
| 145 | \\ pushl %%ebp | 145 | \\ pushl %%ebp |
| 146 | \\ movl %%esp,%%ebp | 146 | \\ movl %%esp,%%ebp |
| 147 | \\ pushl %%ebx | 147 | \\ pushl %%ebx |
| 148 | \\ pushl %%esi | 148 | \\ pushl %%esi |
| 149 | \\ pushl %%edi | 149 | \\ pushl %%edi |
| 150 | \\ // Setup the arguments | 150 | \\ // Setup the arguments |
| 151 | \\ movl 16(%%ebp),%%ebx | 151 | \\ movl 16(%%ebp),%%ebx |
| 152 | \\ movl 12(%%ebp),%%ecx | 152 | \\ movl 12(%%ebp),%%ecx |
| 153 | \\ andl $-16,%%ecx | 153 | \\ andl $-16,%%ecx |
| 154 | \\ subl $20,%%ecx | 154 | \\ subl $20,%%ecx |
| 155 | \\ movl 20(%%ebp),%%eax | 155 | \\ movl 20(%%ebp),%%eax |
| 156 | \\ movl %%eax,4(%%ecx) | 156 | \\ movl %%eax,4(%%ecx) |
| 157 | \\ movl 8(%%ebp),%%eax | 157 | \\ movl 8(%%ebp),%%eax |
| 158 | \\ movl %%eax,0(%%ecx) | 158 | \\ movl %%eax,0(%%ecx) |
| 159 | \\ movl 24(%%ebp),%%edx | 159 | \\ movl 24(%%ebp),%%edx |
| 160 | \\ movl 28(%%ebp),%%esi | 160 | \\ movl 28(%%ebp),%%esi |
| 161 | \\ movl 32(%%ebp),%%edi | 161 | \\ movl 32(%%ebp),%%edi |
| 162 | \\ movl $120,%%eax // SYS_clone | 162 | \\ movl $120,%%eax // SYS_clone |
| 163 | \\ int $128 | 163 | \\ int $128 |
| 164 | \\ testl %%eax,%%eax | 164 | \\ testl %%eax,%%eax |
| 165 | \\ jz 1f | 165 | \\ jz 1f |
| 166 | \\ popl %%edi | 166 | \\ popl %%edi |
| 167 | \\ popl %%esi | 167 | \\ popl %%esi |
| 168 | \\ popl %%ebx | 168 | \\ popl %%ebx |
| 169 | \\ popl %%ebp | 169 | \\ popl %%ebp |
| 170 | \\ retl | 170 | \\ retl |
| 171 | \\ | 171 | \\ |
| 172 | \\1: | 172 | \\1: |
| 173 | ); | 173 | ); |
| 174 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 174 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 175 | \\ .cfi_undefined %%eip | 175 | \\ .cfi_undefined %%eip |
| 176 | ); | 176 | ); |
| 177 | asm volatile ( | 177 | asm volatile ( |
| 178 | \\ xorl %%ebp,%%ebp | 178 | \\ xorl %%ebp,%%ebp |
| 179 | \\ | 179 | \\ |
| 180 | \\ popl %%eax | 180 | \\ popl %%eax |
| 181 | \\ calll *%%eax | 181 | \\ calll *%%eax |
| 182 | \\ movl %%eax,%%ebx | 182 | \\ movl %%eax,%%ebx |
| 183 | \\ movl $1,%%eax // SYS_exit | 183 | \\ movl $1,%%eax // SYS_exit |
| 184 | \\ int $128 | 184 | \\ int $128 |
| 185 | ); | 185 | ); |
| 186 | } | 186 | } |
| 187 | 187 |
lib/std/os/linux/x86_64.zig+21-22| ... | @@ -111,35 +111,34 @@ pub fn syscall6( | ... | @@ -111,35 +111,34 @@ pub fn syscall6( |
| 111 | 111 | ||
| 112 | pub fn clone() callconv(.naked) u64 { | 112 | pub fn clone() callconv(.naked) u64 { |
| 113 | asm volatile ( | 113 | asm volatile ( |
| 114 | \\ movl $56,%%eax // SYS_clone | 114 | \\ movl $56,%%eax // SYS_clone |
| 115 | \\ movq %%rdi,%%r11 | 115 | \\ movq %%rdi,%%r11 |
| 116 | \\ movq %%rdx,%%rdi | 116 | \\ movq %%rdx,%%rdi |
| 117 | \\ movq %%r8,%%rdx | 117 | \\ movq %%r8,%%rdx |
| 118 | \\ movq %%r9,%%r8 | 118 | \\ movq %%r9,%%r8 |
| 119 | \\ movq 8(%%rsp),%%r10 | 119 | \\ movq 8(%%rsp),%%r10 |
| 120 | \\ movq %%r11,%%r9 | 120 | \\ movq %%r11,%%r9 |
| 121 | \\ andq $-16,%%rsi | 121 | \\ andq $-16,%%rsi |
| 122 | \\ subq $8,%%rsi | 122 | \\ subq $8,%%rsi |
| 123 | \\ movq %%rcx,(%%rsi) | 123 | \\ movq %%rcx,(%%rsi) |
| 124 | \\ syscall | 124 | \\ syscall |
| 125 | \\ testq %%rax,%%rax | 125 | \\ testq %%rax,%%rax |
| 126 | \\ jz 1f | 126 | \\ jz 1f |
| 127 | \\ retq | 127 | \\ retq |
| 128 | \\ | 128 | \\ |
| 129 | \\1: | 129 | \\1: |
| 130 | ); | 130 | ); |
| 131 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( | 131 | if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( |
| 132 | \\ .cfi_undefined %%rip | 132 | \\ .cfi_undefined %%rip |
| 133 | ); | 133 | ); |
| 134 | asm volatile ( | 134 | asm volatile ( |
| 135 | \\ xorl %%ebp,%%ebp | 135 | \\ xorl %%ebp,%%ebp |
| 136 | \\ | ||
| 137 | \\ popq %%rdi | ||
| 138 | \\ callq *%%r9 | ||
| 139 | \\ movl %%eax,%%edi | ||
| 140 | \\ movl $60,%%eax // SYS_exit | ||
| 141 | \\ syscall | ||
| 142 | \\ | 136 | \\ |
| 137 | \\ popq %%rdi | ||
| 138 | \\ callq *%%r9 | ||
| 139 | \\ movl %%eax,%%edi | ||
| 140 | \\ movl $60,%%eax // SYS_exit | ||
| 141 | \\ syscall | ||
| 143 | ); | 142 | ); |
| 144 | } | 143 | } |
| 145 | 144 |