Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | // |
| 5 | // System calls and other sys.stuff for AMD64, FreeBSD |
| 6 | // /usr/src/sys/kern/syscalls.master for syscall numbers. |
| 7 | // |
| 8 | |
Russ Cox | 5588940 | 2011-12-19 15:51:13 -0500 | [diff] [blame] | 9 | #include "zasm_GOOS_GOARCH.h" |
Russ Cox | cb040d5 | 2014-09-04 23:05:18 -0400 | [diff] [blame] | 10 | #include "textflag.h" |
Russ Cox | 555da73 | 2013-09-16 14:04:32 -0400 | [diff] [blame] | 11 | |
| 12 | // FreeBSD 8, FreeBSD 9, and older versions that I have checked |
| 13 | // do not restore R10 on exit from a "restarted" system call |
| 14 | // if you use the SYSCALL instruction. This means that, for example, |
| 15 | // if a signal arrives while the wait4 system call is executing, |
| 16 | // the wait4 internally returns ERESTART, which makes the kernel |
| 17 | // back up the PC to execute the SYSCALL instruction a second time. |
| 18 | // However, since the kernel does not restore R10, the fourth |
| 19 | // argument to the system call has been lost. (FreeBSD 9 also fails |
| 20 | // to restore the fifth and sixth arguments, R8 and R9, although |
| 21 | // some earlier versions did restore those correctly.) |
| 22 | // The broken code is in fast_syscall in FreeBSD's amd64/amd64/exception.S. |
| 23 | // It restores only DI, SI, DX, AX, and RFLAGS on system call return. |
| 24 | // http://fxr.watson.org/fxr/source/amd64/amd64/exception.S?v=FREEBSD91#L399 |
| 25 | // |
| 26 | // The INT $0x80 system call path (int0x80_syscall in FreeBSD's |
| 27 | // amd64/ia32/ia32_exception.S) does not have this problem, |
| 28 | // but it expects the third argument in R10. Instead of rewriting |
| 29 | // all the assembly in this file, #define SYSCALL to a safe simulation |
| 30 | // using INT $0x80. |
Russ Cox | a70cbf1 | 2013-09-16 14:22:24 -0400 | [diff] [blame] | 31 | // |
Russ Cox | 555da73 | 2013-09-16 14:04:32 -0400 | [diff] [blame] | 32 | // INT $0x80 is a little slower than SYSCALL, but correctness wins. |
| 33 | // |
| 34 | // See golang.org/issue/6372. |
| 35 | #define SYSCALL MOVQ R10, CX; INT $0x80 |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 36 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 37 | TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 38 | MOVQ addr+0(FP), DI |
| 39 | MOVL mode+8(FP), SI |
| 40 | MOVL val+12(FP), DX |
| 41 | MOVQ ptr2+16(FP), R10 |
| 42 | MOVQ ts+24(FP), R8 |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 43 | MOVL $454, AX |
| 44 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 45 | MOVL AX, ret+32(FP) |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 46 | RET |
| 47 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 48 | TEXT runtime·thr_new(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 49 | MOVQ param+0(FP), DI |
| 50 | MOVL size+8(FP), SI |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 51 | MOVL $455, AX |
| 52 | SYSCALL |
| 53 | RET |
| 54 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 55 | TEXT runtime·thr_start(SB),NOSPLIT,$0 |
Devon H. O'Dell | b089106 | 2012-02-22 15:44:09 +1100 | [diff] [blame] | 56 | MOVQ DI, R13 // m |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 57 | |
| 58 | // set up FS to point at m->tls |
| 59 | LEAQ m_tls(R13), DI |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 60 | CALL runtime·settls(SB) // smashes DI |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 61 | |
| 62 | // set up m, g |
| 63 | get_tls(CX) |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 64 | MOVQ m_g0(R13), DI |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame] | 65 | MOVQ R13, g_m(DI) |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 66 | MOVQ DI, g(CX) |
| 67 | |
Russ Cox | e6a3e22 | 2013-03-01 11:44:43 -0500 | [diff] [blame] | 68 | CALL runtime·stackcheck(SB) |
| 69 | CALL runtime·mstart(SB) |
Russ Cox | c5f694a | 2013-03-01 08:30:11 -0500 | [diff] [blame] | 70 | |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 71 | MOVQ 0, AX // crash (not reached) |
| 72 | |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 73 | // Exit the entire program (like C exit) |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 74 | TEXT runtime·exit(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 75 | MOVL code+0(FP), DI // arg 1 exit status |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 76 | MOVL $1, AX |
| 77 | SYSCALL |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 78 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 79 | RET |
| 80 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 81 | TEXT runtime·exit1(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 82 | MOVL code+0(FP), DI // arg 1 exit status |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 83 | MOVL $431, AX |
| 84 | SYSCALL |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 85 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 86 | RET |
| 87 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 88 | TEXT runtime·open(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 89 | MOVQ name+0(FP), DI // arg 1 pathname |
| 90 | MOVL mode+8(FP), SI // arg 2 flags |
| 91 | MOVL perm+12(FP), DX // arg 3 mode |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 92 | MOVL $5, AX |
| 93 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 94 | MOVL AX, ret+16(FP) |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 95 | RET |
| 96 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 97 | TEXT runtime·close(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 98 | MOVL fd+0(FP), DI // arg 1 fd |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 99 | MOVL $6, AX |
| 100 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 101 | MOVL AX, ret+8(FP) |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 102 | RET |
| 103 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 104 | TEXT runtime·read(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 105 | MOVL fd+0(FP), DI // arg 1 fd |
| 106 | MOVQ p+8(FP), SI // arg 2 buf |
| 107 | MOVL n+16(FP), DX // arg 3 count |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 108 | MOVL $3, AX |
| 109 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 110 | MOVL AX, ret+24(FP) |
Keith Randall | a5d4024 | 2013-03-12 10:47:44 -0700 | [diff] [blame] | 111 | RET |
| 112 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 113 | TEXT runtime·write(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 114 | MOVQ fd+0(FP), DI // arg 1 fd |
| 115 | MOVQ p+8(FP), SI // arg 2 buf |
| 116 | MOVL n+16(FP), DX // arg 3 count |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 117 | MOVL $4, AX |
| 118 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 119 | MOVL AX, ret+24(FP) |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 120 | RET |
| 121 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 122 | TEXT runtime·getrlimit(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 123 | MOVL kind+0(FP), DI |
| 124 | MOVQ limit+8(FP), SI |
Russ Cox | 102274a | 2012-02-24 15:28:51 -0500 | [diff] [blame] | 125 | MOVL $194, AX |
| 126 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 127 | MOVL AX, ret+16(FP) |
Russ Cox | 102274a | 2012-02-24 15:28:51 -0500 | [diff] [blame] | 128 | RET |
| 129 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 130 | TEXT runtime·raise(SB),NOSPLIT,$16 |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame] | 131 | // thr_self(&8(SP)) |
| 132 | LEAQ 8(SP), DI // arg 1 &8(SP) |
| 133 | MOVL $432, AX |
| 134 | SYSCALL |
| 135 | // thr_kill(self, SIGPIPE) |
| 136 | MOVQ 8(SP), DI // arg 1 id |
Russ Cox | 5146a93 | 2013-03-15 01:11:03 -0400 | [diff] [blame] | 137 | MOVL sig+0(FP), SI // arg 2 |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame] | 138 | MOVL $433, AX |
| 139 | SYSCALL |
| 140 | RET |
| 141 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 142 | TEXT runtime·setitimer(SB), NOSPLIT, $-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 143 | MOVL mode+0(FP), DI |
| 144 | MOVQ new+8(FP), SI |
| 145 | MOVQ old+16(FP), DX |
Russ Cox | 8dee872 | 2011-03-23 11:31:42 -0400 | [diff] [blame] | 146 | MOVL $83, AX |
| 147 | SYSCALL |
| 148 | RET |
| 149 | |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 150 | // func now() (sec int64, nsec int32) |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 151 | TEXT time·now(SB), NOSPLIT, $32 |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 152 | MOVL $232, AX |
Mikio Hara | 36013e4 | 2014-02-26 10:19:51 +0900 | [diff] [blame] | 153 | MOVQ $0, DI // CLOCK_REALTIME |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 154 | LEAQ 8(SP), SI |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 155 | SYSCALL |
| 156 | MOVQ 8(SP), AX // sec |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 157 | MOVQ 16(SP), DX // nsec |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 158 | |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 159 | // sec is in AX, nsec in DX |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 160 | MOVQ AX, sec+0(FP) |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 161 | MOVL DX, nsec+8(FP) |
| 162 | RET |
| 163 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 164 | TEXT runtime·nanotime(SB), NOSPLIT, $32 |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 165 | MOVL $232, AX |
Mikio Hara | 36013e4 | 2014-02-26 10:19:51 +0900 | [diff] [blame] | 166 | // We can use CLOCK_MONOTONIC_FAST here when we drop |
| 167 | // support for FreeBSD 8-STABLE. |
| 168 | MOVQ $4, DI // CLOCK_MONOTONIC |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 169 | LEAQ 8(SP), SI |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 170 | SYSCALL |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 171 | MOVQ 8(SP), AX // sec |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 172 | MOVQ 16(SP), DX // nsec |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 173 | |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 174 | // sec is in AX, nsec in DX |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 175 | // return nsec in AX |
| 176 | IMULQ $1000000000, AX |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 177 | ADDQ DX, AX |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 178 | MOVQ AX, ret+0(FP) |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 179 | RET |
| 180 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 181 | TEXT runtime·sigaction(SB),NOSPLIT,$-8 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 182 | MOVL sig+0(FP), DI // arg 1 sig |
| 183 | MOVQ new+8(FP), SI // arg 2 act |
| 184 | MOVQ old+16(FP), DX // arg 3 oact |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 185 | MOVL $416, AX |
| 186 | SYSCALL |
| 187 | JCC 2(PC) |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 188 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 189 | RET |
| 190 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 191 | TEXT runtime·sigtramp(SB),NOSPLIT,$64 |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 192 | get_tls(BX) |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 193 | |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame] | 194 | // check that g exists |
| 195 | MOVQ g(BX), R10 |
| 196 | CMPQ R10, $0 |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 197 | JNE 5(PC) |
Alan Donovan | 532dee3 | 2012-09-04 14:40:49 -0400 | [diff] [blame] | 198 | MOVQ DI, 0(SP) |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 199 | MOVQ $runtime·badsignal(SB), AX |
| 200 | CALL AX |
Alan Donovan | 532dee3 | 2012-09-04 14:40:49 -0400 | [diff] [blame] | 201 | RET |
Russ Cox | b236911 | 2012-03-12 15:55:18 -0400 | [diff] [blame] | 202 | |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 203 | // save g |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 204 | MOVQ R10, 40(SP) |
| 205 | |
| 206 | // g = m->signal |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame] | 207 | MOVQ g_m(R10), BP |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 208 | MOVQ m_gsignal(BP), BP |
| 209 | MOVQ BP, g(BX) |
| 210 | |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 211 | MOVQ DI, 0(SP) |
| 212 | MOVQ SI, 8(SP) |
| 213 | MOVQ DX, 16(SP) |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 214 | MOVQ R10, 24(SP) |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 215 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 216 | CALL runtime·sighandler(SB) |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 217 | |
| 218 | // restore g |
| 219 | get_tls(BX) |
| 220 | MOVQ 40(SP), R10 |
| 221 | MOVQ R10, g(BX) |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 222 | RET |
| 223 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 224 | TEXT runtime·mmap(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 225 | MOVQ addr+0(FP), DI // arg 1 addr |
| 226 | MOVQ n+8(FP), SI // arg 2 len |
| 227 | MOVL prot+16(FP), DX // arg 3 prot |
| 228 | MOVL flags+20(FP), R10 // arg 4 flags |
| 229 | MOVL fd+24(FP), R8 // arg 5 fid |
| 230 | MOVL off+28(FP), R9 // arg 6 offset |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 231 | MOVL $477, AX |
| 232 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 233 | MOVQ AX, ret+32(FP) |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 234 | RET |
| 235 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 236 | TEXT runtime·munmap(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 237 | MOVQ addr+0(FP), DI // arg 1 addr |
| 238 | MOVQ n+8(FP), SI // arg 2 len |
Russ Cox | d4cc557 | 2010-09-07 09:57:22 -0400 | [diff] [blame] | 239 | MOVL $73, AX |
| 240 | SYSCALL |
| 241 | JCC 2(PC) |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 242 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 243 | RET |
| 244 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 245 | TEXT runtime·madvise(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 246 | MOVQ addr+0(FP), DI |
| 247 | MOVQ n+8(FP), SI |
| 248 | MOVL flags+16(FP), DX |
John Graham-Cumming | 314fd62 | 2012-11-24 15:55:19 +1100 | [diff] [blame] | 249 | MOVQ $75, AX // madvise |
| 250 | SYSCALL |
Russ Cox | 295a4d8 | 2012-12-22 15:06:28 -0500 | [diff] [blame] | 251 | // ignore failure - maybe pages are locked |
John Graham-Cumming | 314fd62 | 2012-11-24 15:55:19 +1100 | [diff] [blame] | 252 | RET |
| 253 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 254 | TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 255 | MOVQ new+8(SP), DI |
| 256 | MOVQ old+16(SP), SI |
| 257 | MOVQ $53, AX |
| 258 | SYSCALL |
| 259 | JCC 2(PC) |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 260 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | 0489a26 | 2009-11-17 08:20:58 -0800 | [diff] [blame] | 261 | RET |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 262 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 263 | TEXT runtime·usleep(SB),NOSPLIT,$16 |
Shenghou Ma | c30ba7e | 2012-01-17 03:22:34 +1100 | [diff] [blame] | 264 | MOVL $0, DX |
| 265 | MOVL usec+0(FP), AX |
| 266 | MOVL $1000000, CX |
| 267 | DIVL CX |
| 268 | MOVQ AX, 0(SP) // tv_sec |
| 269 | MOVL $1000, AX |
| 270 | MULL DX |
| 271 | MOVQ AX, 8(SP) // tv_nsec |
| 272 | |
| 273 | MOVQ SP, DI // arg 1 - rqtp |
| 274 | MOVQ $0, SI // arg 2 - rmtp |
| 275 | MOVL $240, AX // sys_nanosleep |
| 276 | SYSCALL |
David Symonds | 723f73c | 2011-09-30 16:39:10 -0700 | [diff] [blame] | 277 | RET |
| 278 | |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 279 | // set tls base to DI |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 280 | TEXT runtime·settls(SB),NOSPLIT,$8 |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 281 | ADDQ $16, DI // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m |
| 282 | MOVQ DI, 0(SP) |
| 283 | MOVQ SP, SI |
| 284 | MOVQ $129, DI // AMD64_SET_FSBASE |
| 285 | MOVQ $165, AX // sysarch |
| 286 | SYSCALL |
| 287 | JCC 2(PC) |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 288 | MOVL $0xf1, 0xf1 // crash |
Russ Cox | e473f42 | 2010-08-04 17:50:22 -0700 | [diff] [blame] | 289 | RET |
Devon H. O'Dell | 12bf000 | 2012-01-10 17:39:17 +1100 | [diff] [blame] | 290 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 291 | TEXT runtime·sysctl(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 292 | MOVQ mib+0(FP), DI // arg 1 - name |
| 293 | MOVL miblen+8(FP), SI // arg 2 - namelen |
| 294 | MOVQ out+16(FP), DX // arg 3 - oldp |
| 295 | MOVQ size+24(FP), R10 // arg 4 - oldlenp |
| 296 | MOVQ dst+32(FP), R8 // arg 5 - newp |
| 297 | MOVQ ndst+40(FP), R9 // arg 6 - newlen |
Devon H. O'Dell | 12bf000 | 2012-01-10 17:39:17 +1100 | [diff] [blame] | 298 | MOVQ $202, AX // sys___sysctl |
| 299 | SYSCALL |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 300 | JCC 4(PC) |
Russ Cox | e3c7a9d | 2013-03-14 23:42:11 -0400 | [diff] [blame] | 301 | NEGQ AX |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 302 | MOVL AX, ret+48(FP) |
Devon H. O'Dell | 12bf000 | 2012-01-10 17:39:17 +1100 | [diff] [blame] | 303 | RET |
| 304 | MOVL $0, AX |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 305 | MOVL AX, ret+48(FP) |
Devon H. O'Dell | 12bf000 | 2012-01-10 17:39:17 +1100 | [diff] [blame] | 306 | RET |
| 307 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 308 | TEXT runtime·osyield(SB),NOSPLIT,$-4 |
Devon H. O'Dell | dff5535 | 2012-02-21 07:32:20 +0900 | [diff] [blame] | 309 | MOVL $331, AX // sys_sched_yield |
Devon H. O'Dell | 8542dc0 | 2012-02-22 11:04:25 +0900 | [diff] [blame] | 310 | SYSCALL |
Devon H. O'Dell | dff5535 | 2012-02-21 07:32:20 +0900 | [diff] [blame] | 311 | RET |
Devon H. O'Dell | b089106 | 2012-02-22 15:44:09 +1100 | [diff] [blame] | 312 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 313 | TEXT runtime·sigprocmask(SB),NOSPLIT,$0 |
Devon H. O'Dell | b089106 | 2012-02-22 15:44:09 +1100 | [diff] [blame] | 314 | MOVL $3, DI // arg 1 - how (SIG_SETMASK) |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 315 | MOVQ new+0(FP), SI // arg 2 - set |
| 316 | MOVQ old+8(FP), DX // arg 3 - oset |
Devon H. O'Dell | b089106 | 2012-02-22 15:44:09 +1100 | [diff] [blame] | 317 | MOVL $340, AX // sys_sigprocmask |
| 318 | SYSCALL |
| 319 | JAE 2(PC) |
Russ Cox | 36aa7d4 | 2012-03-08 14:03:56 -0500 | [diff] [blame] | 320 | MOVL $0xf1, 0xf1 // crash |
Devon H. O'Dell | b089106 | 2012-02-22 15:44:09 +1100 | [diff] [blame] | 321 | RET |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 322 | |
| 323 | // int32 runtime·kqueue(void); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 324 | TEXT runtime·kqueue(SB),NOSPLIT,$0 |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 325 | MOVQ $0, DI |
| 326 | MOVQ $0, SI |
| 327 | MOVQ $0, DX |
| 328 | MOVL $362, AX |
| 329 | SYSCALL |
| 330 | JCC 2(PC) |
| 331 | NEGQ AX |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 332 | MOVL AX, ret+0(FP) |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 333 | RET |
| 334 | |
| 335 | // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 336 | TEXT runtime·kevent(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 337 | MOVL fd+0(FP), DI |
| 338 | MOVQ ev1+8(FP), SI |
| 339 | MOVL nev1+16(FP), DX |
| 340 | MOVQ ev2+24(FP), R10 |
| 341 | MOVL nev2+32(FP), R8 |
| 342 | MOVQ ts+40(FP), R9 |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 343 | MOVL $363, AX |
| 344 | SYSCALL |
| 345 | JCC 2(PC) |
| 346 | NEGQ AX |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 347 | MOVL AX, ret+48(FP) |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 348 | RET |
| 349 | |
| 350 | // void runtime·closeonexec(int32 fd); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 351 | TEXT runtime·closeonexec(SB),NOSPLIT,$0 |
Russ Cox | 25f6b02 | 2014-08-27 11:32:17 -0400 | [diff] [blame] | 352 | MOVL fd+0(FP), DI // fd |
Mikio Hara | c5732c8 | 2013-05-20 19:25:32 +0900 | [diff] [blame] | 353 | MOVQ $2, SI // F_SETFD |
| 354 | MOVQ $1, DX // FD_CLOEXEC |
| 355 | MOVL $92, AX // fcntl |
| 356 | SYSCALL |
| 357 | RET |