Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [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 | // |
| 6 | // System calls and other sys.stuff for 386, Linux |
| 7 | // |
| 8 | |
Russ Cox | 5588940 | 2011-12-19 15:51:13 -0500 | [diff] [blame] | 9 | #include "zasm_GOOS_GOARCH.h" |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 10 | #include "../../cmd/ld/textflag.h" |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 11 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 12 | TEXT runtime·exit(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 13 | MOVL $252, AX // syscall number |
| 14 | MOVL 4(SP), BX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 15 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 16 | INT $3 // not reached |
| 17 | RET |
| 18 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 19 | TEXT runtime·exit1(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 20 | MOVL $1, AX // exit - exit the current os thread |
| 21 | MOVL 4(SP), BX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 22 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 23 | INT $3 // not reached |
| 24 | RET |
| 25 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 26 | TEXT runtime·open(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 27 | MOVL $5, AX // syscall - open |
| 28 | MOVL 4(SP), BX |
| 29 | MOVL 8(SP), CX |
| 30 | MOVL 12(SP), DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 31 | CALL *runtime·_vdso(SB) |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 32 | RET |
| 33 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 34 | TEXT runtime·close(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 35 | MOVL $6, AX // syscall - close |
| 36 | MOVL 4(SP), BX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 37 | CALL *runtime·_vdso(SB) |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 38 | RET |
| 39 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 40 | TEXT runtime·write(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 41 | MOVL $4, AX // syscall - write |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 42 | MOVL 4(SP), BX |
| 43 | MOVL 8(SP), CX |
| 44 | MOVL 12(SP), DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 45 | CALL *runtime·_vdso(SB) |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 46 | RET |
| 47 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 48 | TEXT runtime·read(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 49 | MOVL $3, AX // syscall - read |
| 50 | MOVL 4(SP), BX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 51 | MOVL 8(SP), CX |
| 52 | MOVL 12(SP), DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 53 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 54 | RET |
| 55 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 56 | TEXT runtime·getrlimit(SB),NOSPLIT,$0 |
Russ Cox | 102274a | 2012-02-24 15:28:51 -0500 | [diff] [blame] | 57 | MOVL $191, AX // syscall - ugetrlimit |
| 58 | MOVL 4(SP), BX |
| 59 | MOVL 8(SP), CX |
| 60 | CALL *runtime·_vdso(SB) |
| 61 | RET |
| 62 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 63 | TEXT runtime·usleep(SB),NOSPLIT,$8 |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 64 | MOVL $0, DX |
| 65 | MOVL usec+0(FP), AX |
| 66 | MOVL $1000000, CX |
| 67 | DIVL CX |
Hector Chu | 8591614 | 2011-10-03 19:08:59 +0100 | [diff] [blame] | 68 | MOVL AX, 0(SP) |
| 69 | MOVL DX, 4(SP) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 70 | |
| 71 | // select(0, 0, 0, 0, &tv) |
Hector Chu | 8591614 | 2011-10-03 19:08:59 +0100 | [diff] [blame] | 72 | MOVL $142, AX |
| 73 | MOVL $0, BX |
| 74 | MOVL $0, CX |
| 75 | MOVL $0, DX |
| 76 | MOVL $0, SI |
| 77 | LEAL 0(SP), DI |
| 78 | CALL *runtime·_vdso(SB) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 79 | RET |
| 80 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 81 | TEXT runtime·raise(SB),NOSPLIT,$12 |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame] | 82 | MOVL $224, AX // syscall - gettid |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 83 | CALL *runtime·_vdso(SB) |
Russ Cox | 5146a93 | 2013-03-15 01:11:03 -0400 | [diff] [blame] | 84 | MOVL AX, BX // arg 1 tid |
| 85 | MOVL sig+0(FP), CX // arg 2 signal |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame] | 86 | MOVL $238, AX // syscall - tkill |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 87 | CALL *runtime·_vdso(SB) |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame] | 88 | RET |
Russ Cox | 8dee872 | 2011-03-23 11:31:42 -0400 | [diff] [blame] | 89 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 90 | TEXT runtime·setitimer(SB),NOSPLIT,$0-24 |
Russ Cox | 8dee872 | 2011-03-23 11:31:42 -0400 | [diff] [blame] | 91 | MOVL $104, AX // syscall - setitimer |
| 92 | MOVL 4(SP), BX |
| 93 | MOVL 8(SP), CX |
| 94 | MOVL 12(SP), DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 95 | CALL *runtime·_vdso(SB) |
Russ Cox | 8dee872 | 2011-03-23 11:31:42 -0400 | [diff] [blame] | 96 | RET |
| 97 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 98 | TEXT runtime·mincore(SB),NOSPLIT,$0-24 |
Jonathan Mark | ddde52a | 2011-06-07 21:50:10 -0700 | [diff] [blame] | 99 | MOVL $218, AX // syscall - mincore |
| 100 | MOVL 4(SP), BX |
| 101 | MOVL 8(SP), CX |
| 102 | MOVL 12(SP), DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 103 | CALL *runtime·_vdso(SB) |
Jonathan Mark | ddde52a | 2011-06-07 21:50:10 -0700 | [diff] [blame] | 104 | RET |
| 105 | |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 106 | // func now() (sec int64, nsec int32) |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 107 | TEXT time·now(SB), NOSPLIT, $32 |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 108 | MOVL $265, AX // syscall - clock_gettime |
Jay Weisskopf | 86c976f | 2014-02-24 10:57:46 -0500 | [diff] [blame] | 109 | MOVL $0, BX // CLOCK_REALTIME |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 110 | LEAL 8(SP), CX |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 111 | MOVL $0, DX |
| 112 | CALL *runtime·_vdso(SB) |
| 113 | MOVL 8(SP), AX // sec |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 114 | MOVL 12(SP), BX // nsec |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 115 | |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 116 | // sec is in AX, nsec in BX |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 117 | MOVL AX, sec+0(FP) |
| 118 | MOVL $0, sec+4(FP) |
Russ Cox | efe3d35 | 2011-11-30 11:59:44 -0500 | [diff] [blame] | 119 | MOVL BX, nsec+8(FP) |
| 120 | RET |
| 121 | |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 122 | // int64 nanotime(void) so really |
| 123 | // void nanotime(int64 *nsec) |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 124 | TEXT runtime·nanotime(SB), NOSPLIT, $32 |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 125 | MOVL $265, AX // syscall - clock_gettime |
Jay Weisskopf | 86c976f | 2014-02-24 10:57:46 -0500 | [diff] [blame] | 126 | MOVL $1, BX // CLOCK_MONOTONIC |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 127 | LEAL 8(SP), CX |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 128 | MOVL $0, DX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 129 | CALL *runtime·_vdso(SB) |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 130 | MOVL 8(SP), AX // sec |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 131 | MOVL 12(SP), BX // nsec |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 132 | |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 133 | // sec is in AX, nsec in BX |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 134 | // convert to DX:AX nsec |
| 135 | MOVL $1000000000, CX |
| 136 | MULL CX |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 137 | ADDL BX, AX |
| 138 | ADCL $0, DX |
Shenghou Ma | 7777bac | 2012-12-18 22:57:25 +0800 | [diff] [blame] | 139 | |
Russ Cox | f437331 | 2011-11-03 17:35:28 -0400 | [diff] [blame] | 140 | MOVL ret+0(FP), DI |
| 141 | MOVL AX, 0(DI) |
| 142 | MOVL DX, 4(DI) |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 143 | RET |
| 144 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 145 | TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0 |
Russ Cox | 240b1d5 | 2012-02-23 14:43:58 -0500 | [diff] [blame] | 146 | MOVL $175, AX // syscall entry |
| 147 | MOVL 4(SP), BX |
| 148 | MOVL 8(SP), CX |
| 149 | MOVL 12(SP), DX |
| 150 | MOVL 16(SP), SI |
| 151 | CALL *runtime·_vdso(SB) |
| 152 | CMPL AX, $0xfffff001 |
| 153 | JLS 2(PC) |
| 154 | INT $3 |
| 155 | RET |
| 156 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 157 | TEXT runtime·rt_sigaction(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 158 | MOVL $174, AX // syscall - rt_sigaction |
| 159 | MOVL 4(SP), BX |
| 160 | MOVL 8(SP), CX |
| 161 | MOVL 12(SP), DX |
| 162 | MOVL 16(SP), SI |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 163 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 164 | RET |
| 165 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 166 | TEXT runtime·sigtramp(SB),NOSPLIT,$44 |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 167 | get_tls(CX) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 168 | |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame^] | 169 | // check that g exists |
| 170 | MOVL g(CX), DI |
| 171 | CMPL DI, $0 |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 172 | JNE 6(PC) |
Alan Donovan | 532dee3 | 2012-09-04 14:40:49 -0400 | [diff] [blame] | 173 | MOVL sig+0(FP), BX |
| 174 | MOVL BX, 0(SP) |
Shenghou Ma | 2f1ead7 | 2013-07-12 04:39:39 +0800 | [diff] [blame] | 175 | MOVL $runtime·badsignal(SB), AX |
| 176 | CALL AX |
Alan Donovan | 532dee3 | 2012-09-04 14:40:49 -0400 | [diff] [blame] | 177 | RET |
Russ Cox | b236911 | 2012-03-12 15:55:18 -0400 | [diff] [blame] | 178 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 179 | // save g |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 180 | MOVL DI, 20(SP) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 181 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 182 | // g = m->gsignal |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame^] | 183 | MOVL g_m(DI), BX |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 184 | MOVL m_gsignal(BX), BX |
| 185 | MOVL BX, g(CX) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 186 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 187 | // copy arguments for call to sighandler |
| 188 | MOVL sig+0(FP), BX |
| 189 | MOVL BX, 0(SP) |
| 190 | MOVL info+4(FP), BX |
| 191 | MOVL BX, 4(SP) |
| 192 | MOVL context+8(FP), BX |
| 193 | MOVL BX, 8(SP) |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 194 | MOVL DI, 12(SP) |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 195 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 196 | CALL runtime·sighandler(SB) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 197 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 198 | // restore g |
| 199 | get_tls(CX) |
| 200 | MOVL 20(SP), BX |
| 201 | MOVL BX, g(CX) |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 202 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 203 | RET |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 204 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 205 | TEXT runtime·sigreturn(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 206 | MOVL $173, AX // rt_sigreturn |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 207 | // Sigreturn expects same SP as signal handler, |
| 208 | // so cannot CALL *runtime._vsdo(SB) here. |
| 209 | INT $0x80 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 210 | INT $3 // not reached |
| 211 | RET |
| 212 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 213 | TEXT runtime·mmap(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 214 | MOVL $192, AX // mmap2 |
| 215 | MOVL 4(SP), BX |
| 216 | MOVL 8(SP), CX |
| 217 | MOVL 12(SP), DX |
| 218 | MOVL 16(SP), SI |
| 219 | MOVL 20(SP), DI |
| 220 | MOVL 24(SP), BP |
| 221 | SHRL $12, BP |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 222 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 223 | CMPL AX, $0xfffff001 |
Adam Langley | 3f7a324 | 2009-11-13 10:08:51 -0800 | [diff] [blame] | 224 | JLS 3(PC) |
| 225 | NOTL AX |
| 226 | INCL AX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 227 | RET |
| 228 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 229 | TEXT runtime·munmap(SB),NOSPLIT,$0 |
Russ Cox | d4cc557 | 2010-09-07 09:57:22 -0400 | [diff] [blame] | 230 | MOVL $91, AX // munmap |
| 231 | MOVL 4(SP), BX |
| 232 | MOVL 8(SP), CX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 233 | CALL *runtime·_vdso(SB) |
Russ Cox | d4cc557 | 2010-09-07 09:57:22 -0400 | [diff] [blame] | 234 | CMPL AX, $0xfffff001 |
| 235 | JLS 2(PC) |
| 236 | INT $3 |
| 237 | RET |
| 238 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 239 | TEXT runtime·madvise(SB),NOSPLIT,$0 |
Sébastien Paolacci | e6f5a90 | 2011-12-12 16:33:13 -0500 | [diff] [blame] | 240 | MOVL $219, AX // madvise |
| 241 | MOVL 4(SP), BX |
| 242 | MOVL 8(SP), CX |
| 243 | MOVL 12(SP), DX |
| 244 | CALL *runtime·_vdso(SB) |
Russ Cox | 295a4d8 | 2012-12-22 15:06:28 -0500 | [diff] [blame] | 245 | // ignore failure - maybe pages are locked |
Sébastien Paolacci | e6f5a90 | 2011-12-12 16:33:13 -0500 | [diff] [blame] | 246 | RET |
| 247 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 248 | // int32 futex(int32 *uaddr, int32 op, int32 val, |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 249 | // struct timespec *timeout, int32 *uaddr2, int32 val2); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 250 | TEXT runtime·futex(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 251 | MOVL $240, AX // futex |
| 252 | MOVL 4(SP), BX |
| 253 | MOVL 8(SP), CX |
| 254 | MOVL 12(SP), DX |
| 255 | MOVL 16(SP), SI |
| 256 | MOVL 20(SP), DI |
| 257 | MOVL 24(SP), BP |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 258 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 259 | RET |
| 260 | |
Jingcheng Zhang | 70e967b | 2012-12-19 00:30:29 +0800 | [diff] [blame] | 261 | // int32 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void)); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 262 | TEXT runtime·clone(SB),NOSPLIT,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 263 | MOVL $120, AX // clone |
| 264 | MOVL flags+4(SP), BX |
| 265 | MOVL stack+8(SP), CX |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 266 | MOVL $0, DX // parent tid ptr |
| 267 | MOVL $0, DI // child tid ptr |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 268 | |
Jingcheng Zhang | 70e967b | 2012-12-19 00:30:29 +0800 | [diff] [blame] | 269 | // Copy mp, gp, fn off parent stack for use by child. |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 270 | SUBL $16, CX |
| 271 | MOVL mm+12(SP), SI |
| 272 | MOVL SI, 0(CX) |
| 273 | MOVL gg+16(SP), SI |
| 274 | MOVL SI, 4(CX) |
| 275 | MOVL fn+20(SP), SI |
| 276 | MOVL SI, 8(CX) |
| 277 | MOVL $1234, 12(CX) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 278 | |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 279 | // cannot use CALL *runtime·_vdso(SB) here, because |
Russ Cox | d324f21 | 2011-09-30 09:40:01 -0400 | [diff] [blame] | 280 | // the stack changes during the system call (after |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 281 | // CALL *runtime·_vdso(SB), the child is still using |
| 282 | // the parent's stack when executing its RET instruction). |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 283 | INT $0x80 |
| 284 | |
| 285 | // In parent, return. |
| 286 | CMPL AX, $0 |
| 287 | JEQ 2(PC) |
| 288 | RET |
| 289 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 290 | // Paranoia: check that SP is as we expect. |
| 291 | MOVL 12(SP), BP |
| 292 | CMPL BP, $1234 |
| 293 | JEQ 2(PC) |
| 294 | INT $3 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 295 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 296 | // Initialize AX to Linux tid |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 297 | MOVL $224, AX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 298 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 299 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 300 | // In child on new stack. Reload registers (paranoia). |
| 301 | MOVL 0(SP), BX // m |
| 302 | MOVL 4(SP), DX // g |
Russ Cox | 2d6ae38 | 2010-07-17 16:54:03 -0700 | [diff] [blame] | 303 | MOVL 8(SP), SI // fn |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 304 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 305 | MOVL AX, m_procid(BX) // save tid as m->procid |
| 306 | |
| 307 | // set up ldt 7+id to point at m->tls. |
Russ Cox | 2d6ae38 | 2010-07-17 16:54:03 -0700 | [diff] [blame] | 308 | // newosproc left the id in tls[0]. |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 309 | LEAL m_tls(BX), BP |
| 310 | MOVL 0(BP), DI |
| 311 | ADDL $7, DI // m0 is LDT#7. count up. |
| 312 | // setldt(tls#, &tls, sizeof tls) |
| 313 | PUSHAL // save registers |
| 314 | PUSHL $32 // sizeof tls |
| 315 | PUSHL BP // &tls |
| 316 | PUSHL DI // tls # |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 317 | CALL runtime·setldt(SB) |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 318 | POPL AX |
| 319 | POPL AX |
| 320 | POPL AX |
| 321 | POPAL |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 322 | |
| 323 | // Now segment is established. Initialize m, g. |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 324 | get_tls(AX) |
| 325 | MOVL DX, g(AX) |
Russ Cox | 89f185f | 2014-06-26 11:54:39 -0400 | [diff] [blame^] | 326 | MOVL BX, g_m(DX) |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 327 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 328 | CALL runtime·stackcheck(SB) // smashes AX, CX |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 329 | MOVL 0(DX), DX // paranoia; check they are not nil |
| 330 | MOVL 0(BX), BX |
| 331 | |
| 332 | // more paranoia; check that stack splitting code works |
| 333 | PUSHAL |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 334 | CALL runtime·emptyfunc(SB) |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 335 | POPAL |
| 336 | |
Russ Cox | 2d6ae38 | 2010-07-17 16:54:03 -0700 | [diff] [blame] | 337 | CALL SI // fn() |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 338 | CALL runtime·exit1(SB) |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 339 | MOVL $0x1234, 0x1005 |
| 340 | RET |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 341 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 342 | TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 343 | MOVL $186, AX // sigaltstack |
| 344 | MOVL new+4(SP), BX |
| 345 | MOVL old+8(SP), CX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 346 | CALL *runtime·_vdso(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 347 | CMPL AX, $0xfffff001 |
| 348 | JLS 2(PC) |
| 349 | INT $3 |
| 350 | RET |
| 351 | |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 352 | // <asm-i386/ldt.h> |
| 353 | // struct user_desc { |
Russ Cox | bbcb91a | 2009-09-21 15:46:50 -0700 | [diff] [blame] | 354 | // unsigned int entry_number; |
| 355 | // unsigned long base_addr; |
| 356 | // unsigned int limit; |
| 357 | // unsigned int seg_32bit:1; |
| 358 | // unsigned int contents:2; |
| 359 | // unsigned int read_exec_only:1; |
| 360 | // unsigned int limit_in_pages:1; |
| 361 | // unsigned int seg_not_present:1; |
| 362 | // unsigned int useable:1; |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 363 | // }; |
| 364 | #define SEG_32BIT 0x01 |
| 365 | // contents are the 2 bits 0x02 and 0x04. |
| 366 | #define CONTENTS_DATA 0x00 |
| 367 | #define CONTENTS_STACK 0x02 |
| 368 | #define CONTENTS_CODE 0x04 |
| 369 | #define READ_EXEC_ONLY 0x08 |
| 370 | #define LIMIT_IN_PAGES 0x10 |
| 371 | #define SEG_NOT_PRESENT 0x20 |
| 372 | #define USEABLE 0x40 |
| 373 | |
| 374 | // setldt(int entry, int address, int limit) |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 375 | TEXT runtime·setldt(SB),NOSPLIT,$32 |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 376 | MOVL entry+0(FP), BX // entry |
| 377 | MOVL address+4(FP), CX // base address |
| 378 | |
| 379 | /* |
| 380 | * When linking against the system libraries, |
| 381 | * we use its pthread_create and let it set up %gs |
| 382 | * for us. When we do that, the private storage |
| 383 | * we get is not at 0(GS), 4(GS), but -8(GS), -4(GS). |
| 384 | * To insulate the rest of the tool chain from this |
Russ Cox | 90093f0 | 2014-04-15 13:45:39 -0400 | [diff] [blame] | 385 | * ugliness, 8l rewrites 0(TLS) into -8(GS) for us. |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 386 | * To accommodate that rewrite, we translate |
| 387 | * the address here and bump the limit to 0xffffffff (no limit) |
| 388 | * so that -8(GS) maps to 0(address). |
Russ Cox | 2d6ae38 | 2010-07-17 16:54:03 -0700 | [diff] [blame] | 389 | * Also, the final 0(GS) (current 8(CX)) has to point |
| 390 | * to itself, to mimic ELF. |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 391 | */ |
| 392 | ADDL $0x8, CX // address |
Russ Cox | 2d6ae38 | 2010-07-17 16:54:03 -0700 | [diff] [blame] | 393 | MOVL CX, 0(CX) |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 394 | |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 395 | // set up user_desc |
| 396 | LEAL 16(SP), AX // struct user_desc |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 397 | MOVL BX, 0(AX) |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 398 | MOVL CX, 4(AX) |
| 399 | MOVL $0xfffff, 8(AX) |
| 400 | MOVL $(SEG_32BIT|LIMIT_IN_PAGES|USEABLE|CONTENTS_DATA), 12(AX) // flag bits |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 401 | |
| 402 | // call modify_ldt |
Russ Cox | bbcb91a | 2009-09-21 15:46:50 -0700 | [diff] [blame] | 403 | MOVL $1, BX // func = 1 (write) |
| 404 | MOVL AX, CX // user_desc |
| 405 | MOVL $16, DX // sizeof(user_desc) |
| 406 | MOVL $123, AX // syscall - modify_ldt |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 407 | CALL *runtime·_vdso(SB) |
Russ Cox | bbcb91a | 2009-09-21 15:46:50 -0700 | [diff] [blame] | 408 | |
| 409 | // breakpoint on error |
| 410 | CMPL AX, $0xfffff001 |
| 411 | JLS 2(PC) |
| 412 | INT $3 |
Russ Cox | 1b14bdb | 2009-09-22 16:28:32 -0700 | [diff] [blame] | 413 | |
| 414 | // compute segment selector - (entry*8+7) |
| 415 | MOVL entry+0(FP), AX |
| 416 | SHLL $3, AX |
| 417 | ADDL $7, AX |
| 418 | MOVW AX, GS |
| 419 | |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 420 | RET |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 421 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 422 | TEXT runtime·osyield(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 423 | MOVL $158, AX |
Yuval Pavel Zholkover | c20a338 | 2011-08-29 10:36:06 -0400 | [diff] [blame] | 424 | CALL *runtime·_vdso(SB) |
Dmitriy Vyukov | 4e5086b | 2011-07-29 12:44:06 -0400 | [diff] [blame] | 425 | RET |
Shenghou Ma | 4f308ed | 2012-08-10 10:05:26 +0800 | [diff] [blame] | 426 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 427 | TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0 |
Shenghou Ma | 4f308ed | 2012-08-10 10:05:26 +0800 | [diff] [blame] | 428 | MOVL $242, AX // syscall - sched_getaffinity |
| 429 | MOVL 4(SP), BX |
| 430 | MOVL 8(SP), CX |
| 431 | MOVL 12(SP), DX |
| 432 | CALL *runtime·_vdso(SB) |
| 433 | RET |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 434 | |
| 435 | // int32 runtime·epollcreate(int32 size); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 436 | TEXT runtime·epollcreate(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 437 | MOVL $254, AX |
| 438 | MOVL 4(SP), BX |
| 439 | CALL *runtime·_vdso(SB) |
| 440 | RET |
| 441 | |
| 442 | // int32 runtime·epollcreate1(int32 flags); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 443 | TEXT runtime·epollcreate1(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 444 | MOVL $329, AX |
| 445 | MOVL 4(SP), BX |
| 446 | CALL *runtime·_vdso(SB) |
| 447 | RET |
| 448 | |
| 449 | // int32 runtime·epollctl(int32 epfd, int32 op, int32 fd, EpollEvent *ev); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 450 | TEXT runtime·epollctl(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 451 | MOVL $255, AX |
| 452 | MOVL 4(SP), BX |
| 453 | MOVL 8(SP), CX |
| 454 | MOVL 12(SP), DX |
| 455 | MOVL 16(SP), SI |
| 456 | CALL *runtime·_vdso(SB) |
| 457 | RET |
| 458 | |
| 459 | // int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 460 | TEXT runtime·epollwait(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 461 | MOVL $256, AX |
| 462 | MOVL 4(SP), BX |
| 463 | MOVL 8(SP), CX |
| 464 | MOVL 12(SP), DX |
| 465 | MOVL 16(SP), SI |
| 466 | CALL *runtime·_vdso(SB) |
| 467 | RET |
| 468 | |
| 469 | // void runtime·closeonexec(int32 fd); |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 470 | TEXT runtime·closeonexec(SB),NOSPLIT,$0 |
Dmitriy Vyukov | 49e0300 | 2013-03-14 19:06:35 +0400 | [diff] [blame] | 471 | MOVL $55, AX // fcntl |
| 472 | MOVL 4(SP), BX // fd |
| 473 | MOVL $2, CX // F_SETFD |
| 474 | MOVL $1, DX // FD_CLOEXEC |
| 475 | CALL *runtime·_vdso(SB) |
| 476 | RET |