github.com/hlts2/go@v0.0.0-20170904000733-812b34efaed8/src/runtime/sys_netbsd_amd64.s (about) 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, NetBSD 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 // int32 lwp_create(void *context, uintptr flags, void *lwpid) 14 TEXT runtime·lwp_create(SB),NOSPLIT,$0 15 MOVQ ctxt+0(FP), DI 16 MOVQ flags+8(FP), SI 17 MOVQ lwpid+16(FP), DX 18 MOVL $309, AX // sys__lwp_create 19 SYSCALL 20 JCC 2(PC) 21 NEGQ AX 22 MOVL AX, ret+24(FP) 23 RET 24 25 TEXT runtime·lwp_tramp(SB),NOSPLIT,$0 26 27 // Set FS to point at m->tls. 28 LEAQ m_tls(R8), DI 29 CALL runtime·settls(SB) 30 31 // Set up new stack. 32 get_tls(CX) 33 MOVQ R8, g_m(R9) 34 MOVQ R9, g(CX) 35 CALL runtime·stackcheck(SB) 36 37 // Call fn 38 CALL R12 39 40 // It shouldn't return. If it does, exit. 41 MOVL $310, AX // sys__lwp_exit 42 SYSCALL 43 JMP -3(PC) // keep exiting 44 45 TEXT runtime·osyield(SB),NOSPLIT,$0 46 MOVL $350, AX // sys_sched_yield 47 SYSCALL 48 RET 49 50 TEXT runtime·lwp_park(SB),NOSPLIT,$0 51 MOVQ abstime+0(FP), DI // arg 1 - abstime 52 MOVL unpark+8(FP), SI // arg 2 - unpark 53 MOVQ hint+16(FP), DX // arg 3 - hint 54 MOVQ unparkhint+24(FP), R10 // arg 4 - unparkhint 55 MOVL $434, AX // sys__lwp_park 56 SYSCALL 57 MOVL AX, ret+32(FP) 58 RET 59 60 TEXT runtime·lwp_unpark(SB),NOSPLIT,$0 61 MOVL lwp+0(FP), DI // arg 1 - lwp 62 MOVQ hint+8(FP), SI // arg 2 - hint 63 MOVL $321, AX // sys__lwp_unpark 64 SYSCALL 65 MOVL AX, ret+16(FP) 66 RET 67 68 TEXT runtime·lwp_self(SB),NOSPLIT,$0 69 MOVL $311, AX // sys__lwp_self 70 SYSCALL 71 MOVL AX, ret+0(FP) 72 RET 73 74 // Exit the entire program (like C exit) 75 TEXT runtime·exit(SB),NOSPLIT,$-8 76 MOVL code+0(FP), DI // arg 1 - exit status 77 MOVL $1, AX // sys_exit 78 SYSCALL 79 MOVL $0xf1, 0xf1 // crash 80 RET 81 82 TEXT runtime·exit1(SB),NOSPLIT,$-8 83 MOVL $310, AX // sys__lwp_exit 84 SYSCALL 85 MOVL $0xf1, 0xf1 // crash 86 RET 87 88 TEXT runtime·open(SB),NOSPLIT,$-8 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 92 MOVL $5, AX 93 SYSCALL 94 JCC 2(PC) 95 MOVL $-1, AX 96 MOVL AX, ret+16(FP) 97 RET 98 99 TEXT runtime·closefd(SB),NOSPLIT,$-8 100 MOVL fd+0(FP), DI // arg 1 fd 101 MOVL $6, AX 102 SYSCALL 103 JCC 2(PC) 104 MOVL $-1, AX 105 MOVL AX, ret+8(FP) 106 RET 107 108 TEXT runtime·read(SB),NOSPLIT,$-8 109 MOVL fd+0(FP), DI // arg 1 fd 110 MOVQ p+8(FP), SI // arg 2 buf 111 MOVL n+16(FP), DX // arg 3 count 112 MOVL $3, AX 113 SYSCALL 114 JCC 2(PC) 115 MOVL $-1, AX 116 MOVL AX, ret+24(FP) 117 RET 118 119 TEXT runtime·write(SB),NOSPLIT,$-8 120 MOVQ fd+0(FP), DI // arg 1 - fd 121 MOVQ p+8(FP), SI // arg 2 - buf 122 MOVL n+16(FP), DX // arg 3 - nbyte 123 MOVL $4, AX // sys_write 124 SYSCALL 125 JCC 2(PC) 126 MOVL $-1, AX 127 MOVL AX, ret+24(FP) 128 RET 129 130 TEXT runtime·usleep(SB),NOSPLIT,$16 131 MOVL $0, DX 132 MOVL usec+0(FP), AX 133 MOVL $1000000, CX 134 DIVL CX 135 MOVQ AX, 0(SP) // tv_sec 136 MOVL $1000, AX 137 MULL DX 138 MOVQ AX, 8(SP) // tv_nsec 139 140 MOVQ SP, DI // arg 1 - rqtp 141 MOVQ $0, SI // arg 2 - rmtp 142 MOVL $430, AX // sys_nanosleep 143 SYSCALL 144 RET 145 146 TEXT runtime·raise(SB),NOSPLIT,$16 147 MOVL $311, AX // sys__lwp_self 148 SYSCALL 149 MOVQ AX, DI // arg 1 - target 150 MOVL sig+0(FP), SI // arg 2 - signo 151 MOVL $318, AX // sys__lwp_kill 152 SYSCALL 153 RET 154 155 TEXT runtime·raiseproc(SB),NOSPLIT,$16 156 MOVL $20, AX // sys_getpid 157 SYSCALL 158 MOVQ AX, DI // arg 1 - pid 159 MOVL sig+0(FP), SI // arg 2 - signo 160 MOVL $37, AX // sys_kill 161 SYSCALL 162 RET 163 164 TEXT runtime·setitimer(SB),NOSPLIT,$-8 165 MOVL mode+0(FP), DI // arg 1 - which 166 MOVQ new+8(FP), SI // arg 2 - itv 167 MOVQ old+16(FP), DX // arg 3 - oitv 168 MOVL $425, AX // sys_setitimer 169 SYSCALL 170 RET 171 172 // func walltime() (sec int64, nsec int32) 173 TEXT runtime·walltime(SB), NOSPLIT, $32 174 MOVQ $0, DI // arg 1 - clock_id 175 LEAQ 8(SP), SI // arg 2 - tp 176 MOVL $427, AX // sys_clock_gettime 177 SYSCALL 178 MOVQ 8(SP), AX // sec 179 MOVL 16(SP), DX // nsec 180 181 // sec is in AX, nsec in DX 182 MOVQ AX, sec+0(FP) 183 MOVL DX, nsec+8(FP) 184 RET 185 186 TEXT runtime·nanotime(SB),NOSPLIT,$32 187 MOVQ $0, DI // arg 1 - clock_id 188 LEAQ 8(SP), SI // arg 2 - tp 189 MOVL $427, AX // sys_clock_gettime 190 SYSCALL 191 MOVQ 8(SP), AX // sec 192 MOVL 16(SP), DX // nsec 193 194 // sec is in AX, nsec in DX 195 // return nsec in AX 196 IMULQ $1000000000, AX 197 ADDQ DX, AX 198 MOVQ AX, ret+0(FP) 199 RET 200 201 TEXT runtime·getcontext(SB),NOSPLIT,$-8 202 MOVQ ctxt+0(FP), DI // arg 1 - context 203 MOVL $307, AX // sys_getcontext 204 SYSCALL 205 JCC 2(PC) 206 MOVL $0xf1, 0xf1 // crash 207 RET 208 209 TEXT runtime·sigprocmask(SB),NOSPLIT,$0 210 MOVL how+0(FP), DI // arg 1 - how 211 MOVQ new+8(FP), SI // arg 2 - set 212 MOVQ old+16(FP), DX // arg 3 - oset 213 MOVL $293, AX // sys_sigprocmask 214 SYSCALL 215 JCC 2(PC) 216 MOVL $0xf1, 0xf1 // crash 217 RET 218 219 TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$-8 220 MOVQ R15, DI // Load address of ucontext 221 MOVQ $308, AX // sys_setcontext 222 SYSCALL 223 MOVQ $-1, DI // Something failed... 224 MOVL $1, AX // sys_exit 225 SYSCALL 226 227 TEXT runtime·sigaction(SB),NOSPLIT,$-8 228 MOVL sig+0(FP), DI // arg 1 - signum 229 MOVQ new+8(FP), SI // arg 2 - nsa 230 MOVQ old+16(FP), DX // arg 3 - osa 231 // arg 4 - tramp 232 LEAQ runtime·sigreturn_tramp(SB), R10 233 MOVQ $2, R8 // arg 5 - vers 234 MOVL $340, AX // sys___sigaction_sigtramp 235 SYSCALL 236 JCC 2(PC) 237 MOVL $0xf1, 0xf1 // crash 238 RET 239 240 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 241 MOVQ fn+0(FP), AX 242 MOVL sig+8(FP), DI 243 MOVQ info+16(FP), SI 244 MOVQ ctx+24(FP), DX 245 PUSHQ BP 246 MOVQ SP, BP 247 ANDQ $~15, SP // alignment for x86_64 ABI 248 CALL AX 249 MOVQ BP, SP 250 POPQ BP 251 RET 252 253 TEXT runtime·sigtramp(SB),NOSPLIT,$72 254 // Save callee-saved C registers, since the caller may be a C signal handler. 255 MOVQ BX, bx-8(SP) 256 MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set 257 MOVQ R12, r12-24(SP) 258 MOVQ R13, r13-32(SP) 259 MOVQ R14, r14-40(SP) 260 MOVQ R15, r15-48(SP) 261 // We don't save mxcsr or the x87 control word because sigtrampgo doesn't 262 // modify them. 263 264 MOVQ DX, ctx-56(SP) 265 MOVQ SI, info-64(SP) 266 MOVQ DI, signum-72(SP) 267 CALL runtime·sigtrampgo(SB) 268 269 MOVQ r15-48(SP), R15 270 MOVQ r14-40(SP), R14 271 MOVQ r13-32(SP), R13 272 MOVQ r12-24(SP), R12 273 MOVQ bp-16(SP), BP 274 MOVQ bx-8(SP), BX 275 RET 276 277 TEXT runtime·mmap(SB),NOSPLIT,$0 278 MOVQ addr+0(FP), DI // arg 1 - addr 279 MOVQ n+8(FP), SI // arg 2 - len 280 MOVL prot+16(FP), DX // arg 3 - prot 281 MOVL flags+20(FP), R10 // arg 4 - flags 282 MOVL fd+24(FP), R8 // arg 5 - fd 283 MOVL off+28(FP), R9 284 SUBQ $16, SP 285 MOVQ R9, 8(SP) // arg 7 - offset (passed on stack) 286 MOVQ $0, R9 // arg 6 - pad 287 MOVL $197, AX // sys_mmap 288 SYSCALL 289 ADDQ $16, SP 290 MOVQ AX, ret+32(FP) 291 RET 292 293 TEXT runtime·munmap(SB),NOSPLIT,$0 294 MOVQ addr+0(FP), DI // arg 1 - addr 295 MOVQ n+8(FP), SI // arg 2 - len 296 MOVL $73, AX // sys_munmap 297 SYSCALL 298 JCC 2(PC) 299 MOVL $0xf1, 0xf1 // crash 300 RET 301 302 303 TEXT runtime·madvise(SB),NOSPLIT,$0 304 MOVQ addr+0(FP), DI // arg 1 - addr 305 MOVQ n+8(FP), SI // arg 2 - len 306 MOVL flags+16(FP), DX // arg 3 - behav 307 MOVQ $75, AX // sys_madvise 308 SYSCALL 309 // ignore failure - maybe pages are locked 310 RET 311 312 TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 313 MOVQ new+0(FP), DI // arg 1 - nss 314 MOVQ old+8(FP), SI // arg 2 - oss 315 MOVQ $281, AX // sys___sigaltstack14 316 SYSCALL 317 JCC 2(PC) 318 MOVL $0xf1, 0xf1 // crash 319 RET 320 321 // set tls base to DI 322 TEXT runtime·settls(SB),NOSPLIT,$8 323 // adjust for ELF: wants to use -8(FS) for g 324 ADDQ $8, DI // arg 1 - ptr 325 MOVQ $317, AX // sys__lwp_setprivate 326 SYSCALL 327 JCC 2(PC) 328 MOVL $0xf1, 0xf1 // crash 329 RET 330 331 TEXT runtime·sysctl(SB),NOSPLIT,$0 332 MOVQ mib+0(FP), DI // arg 1 - name 333 MOVL miblen+8(FP), SI // arg 2 - namelen 334 MOVQ out+16(FP), DX // arg 3 - oldp 335 MOVQ size+24(FP), R10 // arg 4 - oldlenp 336 MOVQ dst+32(FP), R8 // arg 5 - newp 337 MOVQ ndst+40(FP), R9 // arg 6 - newlen 338 MOVQ $202, AX // sys___sysctl 339 SYSCALL 340 JCC 4(PC) 341 NEGQ AX 342 MOVL AX, ret+48(FP) 343 RET 344 MOVL $0, AX 345 MOVL AX, ret+48(FP) 346 RET 347 348 // int32 runtime·kqueue(void) 349 TEXT runtime·kqueue(SB),NOSPLIT,$0 350 MOVQ $0, DI 351 MOVL $344, AX 352 SYSCALL 353 JCC 2(PC) 354 NEGQ AX 355 MOVL AX, ret+0(FP) 356 RET 357 358 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout) 359 TEXT runtime·kevent(SB),NOSPLIT,$0 360 MOVL kq+0(FP), DI 361 MOVQ ch+8(FP), SI 362 MOVL nch+16(FP), DX 363 MOVQ ev+24(FP), R10 364 MOVL nev+32(FP), R8 365 MOVQ ts+40(FP), R9 366 MOVL $435, AX 367 SYSCALL 368 JCC 2(PC) 369 NEGQ AX 370 MOVL AX, ret+48(FP) 371 RET 372 373 // void runtime·closeonexec(int32 fd) 374 TEXT runtime·closeonexec(SB),NOSPLIT,$0 375 MOVL fd+0(FP), DI // fd 376 MOVQ $2, SI // F_SETFD 377 MOVQ $1, DX // FD_CLOEXEC 378 MOVL $92, AX // fcntl 379 SYSCALL 380 RET