github.com/sbinet/go@v0.0.0-20160827155028-54d7de7dd62b/src/runtime/sys_openbsd_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, OpenBSD 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 #define CLOCK_MONOTONIC $3 14 15 // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void)); 16 TEXT runtime·tfork(SB),NOSPLIT,$32 17 18 // Copy mp, gp and fn off parent stack for use by child. 19 MOVQ mm+16(FP), R8 20 MOVQ gg+24(FP), R9 21 MOVQ fn+32(FP), R12 22 23 MOVQ param+0(FP), DI 24 MOVQ psize+8(FP), SI 25 MOVL $8, AX // sys___tfork 26 SYSCALL 27 28 // Return if tfork syscall failed. 29 JCC 4(PC) 30 NEGQ AX 31 MOVL AX, ret+40(FP) 32 RET 33 34 // In parent, return. 35 CMPL AX, $0 36 JEQ 3(PC) 37 MOVL AX, ret+40(FP) 38 RET 39 40 // Set FS to point at m->tls. 41 LEAQ m_tls(R8), DI 42 CALL runtime·settls(SB) 43 44 // In child, set up new stack. 45 get_tls(CX) 46 MOVQ R8, g_m(R9) 47 MOVQ R9, g(CX) 48 CALL runtime·stackcheck(SB) 49 50 // Call fn 51 CALL R12 52 53 // It shouldn't return. If it does, exit 54 MOVQ $0, DI // arg 1 - notdead 55 MOVL $302, AX // sys___threxit 56 SYSCALL 57 JMP -3(PC) // keep exiting 58 59 TEXT runtime·osyield(SB),NOSPLIT,$0 60 MOVL $298, AX // sys_sched_yield 61 SYSCALL 62 RET 63 64 TEXT runtime·thrsleep(SB),NOSPLIT,$0 65 MOVQ ident+0(FP), DI // arg 1 - ident 66 MOVL clock_id+8(FP), SI // arg 2 - clock_id 67 MOVQ tsp+16(FP), DX // arg 3 - tp 68 MOVQ lock+24(FP), R10 // arg 4 - lock 69 MOVQ abort+32(FP), R8 // arg 5 - abort 70 MOVL $94, AX // sys___thrsleep 71 SYSCALL 72 MOVL AX, ret+40(FP) 73 RET 74 75 TEXT runtime·thrwakeup(SB),NOSPLIT,$0 76 MOVQ ident+0(FP), DI // arg 1 - ident 77 MOVL n+8(FP), SI // arg 2 - n 78 MOVL $301, AX // sys___thrwakeup 79 SYSCALL 80 MOVL AX, ret+16(FP) 81 RET 82 83 // Exit the entire program (like C exit) 84 TEXT runtime·exit(SB),NOSPLIT,$-8 85 MOVL code+0(FP), DI // arg 1 - exit status 86 MOVL $1, AX // sys_exit 87 SYSCALL 88 MOVL $0xf1, 0xf1 // crash 89 RET 90 91 TEXT runtime·exit1(SB),NOSPLIT,$-8 92 MOVQ $0, DI // arg 1 - notdead 93 MOVL $302, AX // sys___threxit 94 SYSCALL 95 MOVL $0xf1, 0xf1 // crash 96 RET 97 98 TEXT runtime·open(SB),NOSPLIT,$-8 99 MOVQ name+0(FP), DI // arg 1 pathname 100 MOVL mode+8(FP), SI // arg 2 flags 101 MOVL perm+12(FP), DX // arg 3 mode 102 MOVL $5, AX 103 SYSCALL 104 JCC 2(PC) 105 MOVL $-1, AX 106 MOVL AX, ret+16(FP) 107 RET 108 109 TEXT runtime·closefd(SB),NOSPLIT,$-8 110 MOVL fd+0(FP), DI // arg 1 fd 111 MOVL $6, AX 112 SYSCALL 113 JCC 2(PC) 114 MOVL $-1, AX 115 MOVL AX, ret+8(FP) 116 RET 117 118 TEXT runtime·read(SB),NOSPLIT,$-8 119 MOVL fd+0(FP), DI // arg 1 fd 120 MOVQ p+8(FP), SI // arg 2 buf 121 MOVL n+16(FP), DX // arg 3 count 122 MOVL $3, AX 123 SYSCALL 124 JCC 2(PC) 125 MOVL $-1, AX 126 MOVL AX, ret+24(FP) 127 RET 128 129 TEXT runtime·write(SB),NOSPLIT,$-8 130 MOVQ fd+0(FP), DI // arg 1 - fd 131 MOVQ p+8(FP), SI // arg 2 - buf 132 MOVL n+16(FP), DX // arg 3 - nbyte 133 MOVL $4, AX // sys_write 134 SYSCALL 135 JCC 2(PC) 136 MOVL $-1, AX 137 MOVL AX, ret+24(FP) 138 RET 139 140 TEXT runtime·usleep(SB),NOSPLIT,$16 141 MOVL $0, DX 142 MOVL usec+0(FP), AX 143 MOVL $1000000, CX 144 DIVL CX 145 MOVQ AX, 0(SP) // tv_sec 146 MOVL $1000, AX 147 MULL DX 148 MOVQ AX, 8(SP) // tv_nsec 149 150 MOVQ SP, DI // arg 1 - rqtp 151 MOVQ $0, SI // arg 2 - rmtp 152 MOVL $91, AX // sys_nanosleep 153 SYSCALL 154 RET 155 156 TEXT runtime·raise(SB),NOSPLIT,$16 157 MOVL $299, AX // sys_getthrid 158 SYSCALL 159 MOVQ AX, DI // arg 1 - pid 160 MOVL sig+0(FP), SI // arg 2 - signum 161 MOVL $37, AX // sys_kill 162 SYSCALL 163 RET 164 165 TEXT runtime·raiseproc(SB),NOSPLIT,$16 166 MOVL $20, AX // sys_getpid 167 SYSCALL 168 MOVQ AX, DI // arg 1 - pid 169 MOVL sig+0(FP), SI // arg 2 - signum 170 MOVL $37, AX // sys_kill 171 SYSCALL 172 RET 173 174 TEXT runtime·setitimer(SB),NOSPLIT,$-8 175 MOVL mode+0(FP), DI // arg 1 - which 176 MOVQ new+8(FP), SI // arg 2 - itv 177 MOVQ old+16(FP), DX // arg 3 - oitv 178 MOVL $69, AX // sys_setitimer 179 SYSCALL 180 RET 181 182 // func now() (sec int64, nsec int32) 183 TEXT time·now(SB), NOSPLIT, $32 184 MOVQ $0, DI // arg 1 - clock_id 185 LEAQ 8(SP), SI // arg 2 - tp 186 MOVL $87, AX // sys_clock_gettime 187 SYSCALL 188 MOVQ 8(SP), AX // sec 189 MOVQ 16(SP), DX // nsec 190 191 // sec is in AX, nsec in DX 192 MOVQ AX, sec+0(FP) 193 MOVL DX, nsec+8(FP) 194 RET 195 196 TEXT runtime·nanotime(SB),NOSPLIT,$24 197 MOVQ CLOCK_MONOTONIC, DI // arg 1 - clock_id 198 LEAQ 8(SP), SI // arg 2 - tp 199 MOVL $87, AX // sys_clock_gettime 200 SYSCALL 201 MOVQ 8(SP), AX // sec 202 MOVQ 16(SP), DX // nsec 203 204 // sec is in AX, nsec in DX 205 // return nsec in AX 206 IMULQ $1000000000, AX 207 ADDQ DX, AX 208 MOVQ AX, ret+0(FP) 209 RET 210 211 TEXT runtime·sigaction(SB),NOSPLIT,$-8 212 MOVL sig+0(FP), DI // arg 1 - signum 213 MOVQ new+8(FP), SI // arg 2 - nsa 214 MOVQ old+16(FP), DX // arg 3 - osa 215 MOVL $46, AX 216 SYSCALL 217 JCC 2(PC) 218 MOVL $0xf1, 0xf1 // crash 219 RET 220 221 TEXT runtime·sigprocmask(SB),NOSPLIT,$0 222 MOVL mode+0(FP), DI // arg 1 - how 223 MOVL new+4(FP), SI // arg 2 - set 224 MOVL $48, AX // sys_sigprocmask 225 SYSCALL 226 JCC 2(PC) 227 MOVL $0xf1, 0xf1 // crash 228 MOVL AX, ret+8(FP) 229 RET 230 231 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 232 MOVL sig+8(FP), DI 233 MOVQ info+16(FP), SI 234 MOVQ ctx+24(FP), DX 235 MOVQ fn+0(FP), AX 236 CALL AX 237 RET 238 239 TEXT runtime·sigtramp(SB),NOSPLIT,$24 240 MOVQ DI, 0(SP) 241 MOVQ SI, 8(SP) 242 MOVQ DX, 16(SP) 243 CALL runtime·sigtrampgo(SB) 244 RET 245 246 TEXT runtime·mmap(SB),NOSPLIT,$0 247 MOVQ addr+0(FP), DI // arg 1 - addr 248 MOVQ n+8(FP), SI // arg 2 - len 249 MOVL prot+16(FP), DX // arg 3 - prot 250 MOVL flags+20(FP), R10 // arg 4 - flags 251 MOVL fd+24(FP), R8 // arg 5 - fd 252 MOVL off+28(FP), R9 253 SUBQ $16, SP 254 MOVQ R9, 8(SP) // arg 7 - offset (passed on stack) 255 MOVQ $0, R9 // arg 6 - pad 256 MOVL $197, AX 257 SYSCALL 258 ADDQ $16, SP 259 MOVQ AX, ret+32(FP) 260 RET 261 262 TEXT runtime·munmap(SB),NOSPLIT,$0 263 MOVQ addr+0(FP), DI // arg 1 - addr 264 MOVQ n+8(FP), SI // arg 2 - len 265 MOVL $73, AX // sys_munmap 266 SYSCALL 267 JCC 2(PC) 268 MOVL $0xf1, 0xf1 // crash 269 RET 270 271 TEXT runtime·madvise(SB),NOSPLIT,$0 272 MOVQ addr+0(FP), DI // arg 1 - addr 273 MOVQ n+8(FP), SI // arg 2 - len 274 MOVL flags+16(FP), DX // arg 3 - behav 275 MOVQ $75, AX // sys_madvise 276 SYSCALL 277 // ignore failure - maybe pages are locked 278 RET 279 280 TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 281 MOVQ new+8(SP), DI // arg 1 - nss 282 MOVQ old+16(SP), SI // arg 2 - oss 283 MOVQ $288, AX // sys_sigaltstack 284 SYSCALL 285 JCC 2(PC) 286 MOVL $0xf1, 0xf1 // crash 287 RET 288 289 // set tls base to DI 290 TEXT runtime·settls(SB),NOSPLIT,$0 291 // adjust for ELF: wants to use -8(FS) for g 292 ADDQ $8, DI 293 MOVQ $329, AX // sys___settcb 294 SYSCALL 295 JCC 2(PC) 296 MOVL $0xf1, 0xf1 // crash 297 RET 298 299 TEXT runtime·sysctl(SB),NOSPLIT,$0 300 MOVQ mib+0(FP), DI // arg 1 - name 301 MOVL miblen+8(FP), SI // arg 2 - namelen 302 MOVQ out+16(FP), DX // arg 3 - oldp 303 MOVQ size+24(FP), R10 // arg 4 - oldlenp 304 MOVQ dst+32(FP), R8 // arg 5 - newp 305 MOVQ ndst+40(FP), R9 // arg 6 - newlen 306 MOVQ $202, AX // sys___sysctl 307 SYSCALL 308 JCC 4(PC) 309 NEGQ AX 310 MOVL AX, ret+48(FP) 311 RET 312 MOVL $0, AX 313 MOVL AX, ret+48(FP) 314 RET 315 316 // int32 runtime·kqueue(void); 317 TEXT runtime·kqueue(SB),NOSPLIT,$0 318 MOVQ $0, DI 319 MOVQ $0, SI 320 MOVQ $0, DX 321 MOVL $269, AX 322 SYSCALL 323 JCC 2(PC) 324 NEGQ AX 325 MOVL AX, ret+0(FP) 326 RET 327 328 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); 329 TEXT runtime·kevent(SB),NOSPLIT,$0 330 MOVL kq+0(FP), DI 331 MOVQ ch+8(FP), SI 332 MOVL nch+16(FP), DX 333 MOVQ ev+24(FP), R10 334 MOVL nev+32(FP), R8 335 MOVQ ts+40(FP), R9 336 MOVL $72, AX 337 SYSCALL 338 JCC 2(PC) 339 NEGQ AX 340 MOVL AX, ret+48(FP) 341 RET 342 343 // void runtime·closeonexec(int32 fd); 344 TEXT runtime·closeonexec(SB),NOSPLIT,$0 345 MOVL fd+0(FP), DI // fd 346 MOVQ $2, SI // F_SETFD 347 MOVQ $1, DX // FD_CLOEXEC 348 MOVL $92, AX // fcntl 349 SYSCALL 350 RET