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 9 #include "go_asm.h" 10 #include "go_tls.h" 11 #include "textflag.h" 12 13 TEXT runtimesys_umtx_sleep(SB),NOSPLIT,$0 14 MOVQ addr+0(FP), DI // arg 1 - ptr 15 MOVL val+8(FP), SI // arg 2 - value 16 MOVL timeout+12(FP), DX // arg 3 - timeout 17 MOVL $469, AX // umtx_sleep 18 SYSCALL 19 JCC 2(PC) 20 NEGQ AX 21 MOVL AX, ret+16(FP) 22 RET 23 24 TEXT runtimesys_umtx_wakeup(SB),NOSPLIT,$0 25 MOVQ addr+0(FP), DI // arg 1 - ptr 26 MOVL val+8(FP), SI // arg 2 - count 27 MOVL $470, AX // umtx_wakeup 28 SYSCALL 29 JCC 2(PC) 30 NEGQ AX 31 MOVL AX, ret+16(FP) 32 RET 33 34 TEXT runtimelwp_create(SB),NOSPLIT,$0 35 MOVQ param+0(FP), DI // arg 1 - params 36 MOVL $495, AX // lwp_create 37 SYSCALL 38 MOVL AX, ret+8(FP) 39 RET 40 41 TEXT runtimelwp_start(SB),NOSPLIT,$0 42 MOVQ DI, R13 // m 43 44 // set up FS to point at m->tls 45 LEAQ m_tls(R13), DI 46 CALL runtimesettls(SB) // smashes DI 47 48 // set up m, g 49 get_tls(CX) 50 MOVQ m_g0(R13), DI 51 MOVQ R13, g_m(DI) 52 MOVQ DI, g(CX) 53 54 CALL runtimestackcheck(SB) 55 CALL runtimemstart(SB) 56 57 MOVQ 0, AX // crash (not reached) 58 59 // Exit the entire program (like C exit) 60 TEXT runtimeexit(SB),NOSPLIT,$-8 61 MOVL code+0(FP), DI // arg 1 exit status 62 MOVL $1, AX 63 SYSCALL 64 MOVL $0xf1, 0xf1 // crash 65 RET 66 67 TEXT runtimeexit1(SB),NOSPLIT,$-8 68 MOVL code+0(FP), DI // arg 1 exit status 69 MOVL $431, AX 70 SYSCALL 71 MOVL $0xf1, 0xf1 // crash 72 RET 73 74 TEXT runtimeopen(SB),NOSPLIT,$-8 75 MOVQ name+0(FP), DI // arg 1 pathname 76 MOVL mode+8(FP), SI // arg 2 flags 77 MOVL perm+12(FP), DX // arg 3 mode 78 MOVL $5, AX 79 SYSCALL 80 JCC 2(PC) 81 MOVL $-1, AX 82 MOVL AX, ret+16(FP) 83 RET 84 85 TEXT runtimeclosefd(SB),NOSPLIT,$-8 86 MOVL fd+0(FP), DI // arg 1 fd 87 MOVL $6, AX 88 SYSCALL 89 JCC 2(PC) 90 MOVL $-1, AX 91 MOVL AX, ret+8(FP) 92 RET 93 94 TEXT runtimeread(SB),NOSPLIT,$-8 95 MOVL fd+0(FP), DI // arg 1 fd 96 MOVQ p+8(FP), SI // arg 2 buf 97 MOVL n+16(FP), DX // arg 3 count 98 MOVL $3, AX 99 SYSCALL 100 JCC 2(PC) 101 MOVL $-1, AX 102 MOVL AX, ret+24(FP) 103 RET 104 105 TEXT runtimewrite(SB),NOSPLIT,$-8 106 MOVQ fd+0(FP), DI // arg 1 fd 107 MOVQ p+8(FP), SI // arg 2 buf 108 MOVL n+16(FP), DX // arg 3 count 109 MOVL $4, AX 110 SYSCALL 111 JCC 2(PC) 112 MOVL $-1, AX 113 MOVL AX, ret+24(FP) 114 RET 115 116 TEXT runtimegetrlimit(SB),NOSPLIT,$-8 117 MOVL kind+0(FP), DI 118 MOVQ limit+8(FP), SI 119 MOVL $194, AX 120 SYSCALL 121 MOVL AX, ret+16(FP) 122 RET 123 124 TEXT runtimeraise(SB),NOSPLIT,$16 125 MOVL $496, AX // lwp_gettid 126 SYSCALL 127 MOVQ $-1, DI // arg 1 - pid 128 MOVQ AX, SI // arg 2 - tid 129 MOVL sig+0(FP), DX // arg 3 - signum 130 MOVL $497, AX // lwp_kill 131 SYSCALL 132 RET 133 134 TEXT runtimeraiseproc(SB),NOSPLIT,$0 135 MOVL $20, AX // getpid 136 SYSCALL 137 MOVQ AX, DI // arg 1 - pid 138 MOVL sig+0(FP), SI // arg 2 - signum 139 MOVL $37, AX // kill 140 SYSCALL 141 RET 142 143 TEXT runtimesetitimer(SB), NOSPLIT, $-8 144 MOVL mode+0(FP), DI 145 MOVQ new+8(FP), SI 146 MOVQ old+16(FP), DX 147 MOVL $83, AX 148 SYSCALL 149 RET 150 151 // func now() (sec int64, nsec int32) 152 TEXT timenow(SB), NOSPLIT, $32 153 MOVL $232, AX 154 MOVQ $0, DI // CLOCK_REALTIME 155 LEAQ 8(SP), SI 156 SYSCALL 157 MOVQ 8(SP), AX // sec 158 MOVQ 16(SP), DX // nsec 159 160 // sec is in AX, nsec in DX 161 MOVQ AX, sec+0(FP) 162 MOVL DX, nsec+8(FP) 163 RET 164 165 TEXT runtimenanotime(SB), NOSPLIT, $32 166 MOVL $232, AX 167 MOVQ $4, DI // CLOCK_MONOTONIC 168 LEAQ 8(SP), SI 169 SYSCALL 170 MOVQ 8(SP), AX // sec 171 MOVQ 16(SP), DX // nsec 172 173 // sec is in AX, nsec in DX 174 // return nsec in AX 175 IMULQ $1000000000, AX 176 ADDQ DX, AX 177 MOVQ AX, ret+0(FP) 178 RET 179 180 TEXT runtimesigaction(SB),NOSPLIT,$-8 181 MOVL sig+0(FP), DI // arg 1 sig 182 MOVQ new+8(FP), SI // arg 2 act 183 MOVQ old+16(FP), DX // arg 3 oact 184 MOVL $342, AX 185 SYSCALL 186 JCC 2(PC) 187 MOVL $0xf1, 0xf1 // crash 188 RET 189 190 TEXT runtimesigtramp(SB),NOSPLIT,$64 191 get_tls(BX) 192 193 // check that g exists 194 MOVQ g(BX), R10 195 CMPQ R10, $0 196 JNE 5(PC) 197 MOVQ DI, 0(SP) 198 MOVQ $runtimebadsignal(SB), AX 199 CALL AX 200 RET 201 202 // save g 203 MOVQ R10, 40(SP) 204 205 // g = m->signal 206 MOVQ g_m(R10), AX 207 MOVQ m_gsignal(AX), AX 208 MOVQ AX, g(BX) 209 210 MOVQ DI, 0(SP) 211 MOVQ SI, 8(SP) 212 MOVQ DX, 16(SP) 213 MOVQ R10, 24(SP) 214 215 CALL runtimesighandler(SB) 216 217 // restore g 218 get_tls(BX) 219 MOVQ 40(SP), R10 220 MOVQ R10, g(BX) 221 RET 222 223 TEXT runtimemmap(SB),NOSPLIT,$0 224 MOVQ addr+0(FP), DI // arg 1 - addr 225 MOVQ n+8(FP), SI // arg 2 - len 226 MOVL prot+16(FP), DX // arg 3 - prot 227 MOVL flags+20(FP), R10 // arg 4 - flags 228 MOVL fd+24(FP), R8 // arg 5 - fd 229 MOVL off+28(FP), R9 230 SUBQ $16, SP 231 MOVQ R9, 8(SP) // arg 7 - offset (passed on stack) 232 MOVQ $0, R9 // arg 6 - pad 233 MOVL $197, AX 234 SYSCALL 235 ADDQ $16, SP 236 MOVQ AX, ret+32(FP) 237 RET 238 239 TEXT runtimemunmap(SB),NOSPLIT,$0 240 MOVQ addr+0(FP), DI // arg 1 addr 241 MOVQ n+8(FP), SI // arg 2 len 242 MOVL $73, AX 243 SYSCALL 244 JCC 2(PC) 245 MOVL $0xf1, 0xf1 // crash 246 RET 247 248 TEXT runtimemadvise(SB),NOSPLIT,$0 249 MOVQ addr+0(FP), DI 250 MOVQ n+8(FP), SI 251 MOVL flags+16(FP), DX 252 MOVQ $75, AX // madvise 253 SYSCALL 254 // ignore failure - maybe pages are locked 255 RET 256 257 TEXT runtimesigaltstack(SB),NOSPLIT,$-8 258 MOVQ new+8(SP), DI 259 MOVQ old+16(SP), SI 260 MOVQ $53, AX 261 SYSCALL 262 JCC 2(PC) 263 MOVL $0xf1, 0xf1 // crash 264 RET 265 266 TEXT runtimeusleep(SB),NOSPLIT,$16 267 MOVL $0, DX 268 MOVL usec+0(FP), AX 269 MOVL $1000000, CX 270 DIVL CX 271 MOVQ AX, 0(SP) // tv_sec 272 MOVL $1000, AX 273 MULL DX 274 MOVQ AX, 8(SP) // tv_nsec 275 276 MOVQ SP, DI // arg 1 - rqtp 277 MOVQ $0, SI // arg 2 - rmtp 278 MOVL $240, AX // sys_nanosleep 279 SYSCALL 280 RET 281 282 // set tls base to DI 283 TEXT runtimesettls(SB),NOSPLIT,$16 284 ADDQ $8, DI // adjust for ELF: wants to use -8(FS) for g 285 MOVQ DI, 0(SP) 286 MOVQ $16, 8(SP) 287 MOVQ $0, DI // arg 1 - which 288 MOVQ SP, SI // arg 2 - tls_info 289 MOVQ $16, DX // arg 3 - infosize 290 MOVQ $472, AX // set_tls_area 291 SYSCALL 292 JCC 2(PC) 293 MOVL $0xf1, 0xf1 // crash 294 RET 295 296 TEXT runtimesysctl(SB),NOSPLIT,$0 297 MOVQ mib+0(FP), DI // arg 1 - name 298 MOVL miblen+8(FP), SI // arg 2 - namelen 299 MOVQ out+16(FP), DX // arg 3 - oldp 300 MOVQ size+24(FP), R10 // arg 4 - oldlenp 301 MOVQ dst+32(FP), R8 // arg 5 - newp 302 MOVQ ndst+40(FP), R9 // arg 6 - newlen 303 MOVQ $202, AX // sys___sysctl 304 SYSCALL 305 JCC 4(PC) 306 NEGQ AX 307 MOVL AX, ret+48(FP) 308 RET 309 MOVL $0, AX 310 MOVL AX, ret+48(FP) 311 RET 312 313 TEXT runtimeosyield(SB),NOSPLIT,$-4 314 MOVL $331, AX // sys_sched_yield 315 SYSCALL 316 RET 317 318 TEXT runtimesigprocmask(SB),NOSPLIT,$0 319 MOVL how+0(FP), DI // arg 1 - how 320 MOVQ new+8(FP), SI // arg 2 - set 321 MOVQ old+16(FP), DX // arg 3 - oset 322 MOVL $340, AX // sys_sigprocmask 323 SYSCALL 324 JAE 2(PC) 325 MOVL $0xf1, 0xf1 // crash 326 RET 327 328 // int32 runtimekqueue(void); 329 TEXT runtimekqueue(SB),NOSPLIT,$0 330 MOVQ $0, DI 331 MOVQ $0, SI 332 MOVQ $0, DX 333 MOVL $362, AX 334 SYSCALL 335 JCC 2(PC) 336 NEGQ AX 337 MOVL AX, ret+0(FP) 338 RET 339 340 // int32 runtimekevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); 341 TEXT runtimekevent(SB),NOSPLIT,$0 342 MOVL fd+0(FP), DI 343 MOVQ ev1+8(FP), SI 344 MOVL nev1+16(FP), DX 345 MOVQ ev2+24(FP), R10 346 MOVL nev2+32(FP), R8 347 MOVQ ts+40(FP), R9 348 MOVL $363, AX 349 SYSCALL 350 JCC 2(PC) 351 NEGQ AX 352 MOVL AX, ret+48(FP) 353 RET 354 355 // void runtimecloseonexec(int32 fd); 356 TEXT runtimecloseonexec(SB),NOSPLIT,$0 357 MOVL fd+0(FP), DI // fd 358 MOVQ $2, SI // F_SETFD 359 MOVQ $1, DX // FD_CLOEXEC 360 MOVL $92, AX // fcntl 361 SYSCALL 362 RET 363