github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/src/runtime/sys_dragonfly_386.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 386, 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 runtime·sys_umtx_sleep(SB),NOSPLIT,$-4 14 MOVL $469, AX // umtx_sleep 15 INT $0x80 16 JAE 2(PC) 17 NEGL AX 18 MOVL AX, ret+12(FP) 19 RET 20 21 TEXT runtime·sys_umtx_wakeup(SB),NOSPLIT,$-4 22 MOVL $470, AX // umtx_wakeup 23 INT $0x80 24 JAE 2(PC) 25 NEGL AX 26 MOVL AX, ret+8(FP) 27 RET 28 29 TEXT runtime·lwp_create(SB),NOSPLIT,$-4 30 MOVL $495, AX // lwp_create 31 INT $0x80 32 MOVL AX, ret+4(FP) 33 RET 34 35 TEXT runtime·lwp_start(SB),NOSPLIT,$0 36 37 // Set GS to point at m->tls. 38 MOVL mm+0(FP), BX 39 MOVL m_g0(BX), DX 40 LEAL m_tls(BX), BP 41 PUSHAL 42 PUSHL BP 43 CALL runtime·settls(SB) 44 POPL AX 45 POPAL 46 47 // Now segment is established. Initialize m, g. 48 get_tls(CX) 49 MOVL BX, g_m(DX) 50 MOVL DX, g(CX) 51 52 CALL runtime·stackcheck(SB) // smashes AX, CX 53 MOVL 0(DX), DX // paranoia; check they are not nil 54 MOVL 0(BX), BX 55 56 // More paranoia; check that stack splitting code works. 57 PUSHAL 58 CALL runtime·emptyfunc(SB) 59 POPAL 60 61 CALL runtime·mstart(SB) 62 63 CALL runtime·exit1(SB) 64 MOVL $0x1234, 0x1005 65 RET 66 67 // Exit the entire program (like C exit) 68 TEXT runtime·exit(SB),NOSPLIT,$-4 69 MOVL $1, AX 70 INT $0x80 71 MOVL $0xf1, 0xf1 // crash 72 RET 73 74 TEXT runtime·exit1(SB),NOSPLIT,$16 75 MOVL $0, 0(SP) // syscall gap 76 MOVL $0x10000, 4(SP) // arg 1 - how (EXTEXIT_LWP) 77 MOVL $0, 8(SP) // arg 2 - status 78 MOVL $0, 12(SP) // arg 3 - addr 79 MOVL $494, AX 80 INT $0x80 81 JAE 2(PC) 82 MOVL $0xf1, 0xf1 // crash 83 RET 84 85 TEXT runtime·open(SB),NOSPLIT,$-4 86 MOVL $5, AX 87 INT $0x80 88 MOVL AX, ret+12(FP) 89 RET 90 91 TEXT runtime·close(SB),NOSPLIT,$-4 92 MOVL $6, AX 93 INT $0x80 94 MOVL AX, ret+4(FP) 95 RET 96 97 TEXT runtime·read(SB),NOSPLIT,$-4 98 MOVL $3, AX 99 INT $0x80 100 MOVL AX, ret+12(FP) 101 RET 102 103 TEXT runtime·write(SB),NOSPLIT,$-4 104 MOVL $4, AX 105 INT $0x80 106 MOVL AX, ret+12(FP) 107 RET 108 109 TEXT runtime·getrlimit(SB),NOSPLIT,$-4 110 MOVL $194, AX 111 INT $0x80 112 MOVL AX, ret+8(FP) 113 RET 114 115 TEXT runtime·raise(SB),NOSPLIT,$16 116 MOVL $496, AX // lwp_gettid 117 INT $0x80 118 MOVL $0, 0(SP) 119 MOVL $-1, 4(SP) // arg 1 - pid 120 MOVL AX, 8(SP) // arg 2 - tid 121 MOVL sig+0(FP), AX 122 MOVL AX, 8(SP) // arg 3 - signum 123 MOVL $497, AX // lwp_kill 124 INT $0x80 125 RET 126 127 TEXT runtime·mmap(SB),NOSPLIT,$36 128 LEAL addr+0(FP), SI 129 LEAL 4(SP), DI 130 CLD 131 MOVSL // arg 1 - addr 132 MOVSL // arg 2 - len 133 MOVSL // arg 3 - prot 134 MOVSL // arg 4 - flags 135 MOVSL // arg 5 - fd 136 MOVL $0, AX 137 STOSL // arg 6 - pad 138 MOVSL // arg 7 - offset 139 MOVL $0, AX // top 32 bits of file offset 140 STOSL 141 MOVL $197, AX // sys_mmap 142 INT $0x80 143 MOVL AX, ret+24(FP) 144 RET 145 146 TEXT runtime·munmap(SB),NOSPLIT,$-4 147 MOVL $73, AX 148 INT $0x80 149 JAE 2(PC) 150 MOVL $0xf1, 0xf1 // crash 151 RET 152 153 TEXT runtime·madvise(SB),NOSPLIT,$-4 154 MOVL $75, AX // madvise 155 INT $0x80 156 // ignore failure - maybe pages are locked 157 RET 158 159 TEXT runtime·setitimer(SB), NOSPLIT, $-4 160 MOVL $83, AX 161 INT $0x80 162 RET 163 164 // func now() (sec int64, nsec int32) 165 TEXT time·now(SB), NOSPLIT, $32 166 MOVL $232, AX 167 LEAL 12(SP), BX 168 MOVL $0, 4(SP) // CLOCK_REALTIME 169 MOVL BX, 8(SP) 170 INT $0x80 171 MOVL 12(SP), AX // sec 172 MOVL 16(SP), BX // nsec 173 174 // sec is in AX, nsec in BX 175 MOVL AX, sec+0(FP) 176 MOVL $0, sec+4(FP) 177 MOVL BX, nsec+8(FP) 178 RET 179 180 // int64 nanotime(void) so really 181 // void nanotime(int64 *nsec) 182 TEXT runtime·nanotime(SB), NOSPLIT, $32 183 MOVL $232, AX 184 LEAL 12(SP), BX 185 MOVL $4, 4(SP) // CLOCK_MONOTONIC 186 MOVL BX, 8(SP) 187 INT $0x80 188 MOVL 12(SP), AX // sec 189 MOVL 16(SP), BX // nsec 190 191 // sec is in AX, nsec in BX 192 // convert to DX:AX nsec 193 MOVL $1000000000, CX 194 MULL CX 195 ADDL BX, AX 196 ADCL $0, DX 197 198 MOVL AX, ret_lo+0(FP) 199 MOVL DX, ret_hi+4(FP) 200 RET 201 202 203 TEXT runtime·sigaction(SB),NOSPLIT,$-4 204 MOVL $342, AX 205 INT $0x80 206 JAE 2(PC) 207 MOVL $0xf1, 0xf1 // crash 208 RET 209 210 TEXT runtime·sigtramp(SB),NOSPLIT,$44 211 get_tls(CX) 212 213 // check that g exists 214 MOVL g(CX), DI 215 CMPL DI, $0 216 JNE 6(PC) 217 MOVL signo+0(FP), BX 218 MOVL BX, 0(SP) 219 MOVL $runtime·badsignal(SB), AX 220 CALL AX 221 JMP ret 222 223 // save g 224 MOVL DI, 20(SP) 225 226 // g = m->gsignal 227 MOVL g_m(DI), BX 228 MOVL m_gsignal(BX), BX 229 MOVL BX, g(CX) 230 231 // copy arguments for call to sighandler 232 MOVL signo+0(FP), BX 233 MOVL BX, 0(SP) 234 MOVL info+4(FP), BX 235 MOVL BX, 4(SP) 236 MOVL context+8(FP), BX 237 MOVL BX, 8(SP) 238 MOVL DI, 12(SP) 239 240 CALL runtime·sighandler(SB) 241 242 // restore g 243 get_tls(CX) 244 MOVL 20(SP), BX 245 MOVL BX, g(CX) 246 247 ret: 248 // call sigreturn 249 MOVL context+8(FP), AX 250 MOVL $0, 0(SP) // syscall gap 251 MOVL AX, 4(SP) 252 MOVL $344, AX // sigreturn(ucontext) 253 INT $0x80 254 MOVL $0xf1, 0xf1 // crash 255 RET 256 257 TEXT runtime·sigaltstack(SB),NOSPLIT,$0 258 MOVL $53, AX 259 INT $0x80 260 JAE 2(PC) 261 MOVL $0xf1, 0xf1 // crash 262 RET 263 264 TEXT runtime·usleep(SB),NOSPLIT,$20 265 MOVL $0, DX 266 MOVL usec+0(FP), AX 267 MOVL $1000000, CX 268 DIVL CX 269 MOVL AX, 12(SP) // tv_sec 270 MOVL $1000, AX 271 MULL DX 272 MOVL AX, 16(SP) // tv_nsec 273 274 MOVL $0, 0(SP) 275 LEAL 12(SP), AX 276 MOVL AX, 4(SP) // arg 1 - rqtp 277 MOVL $0, 8(SP) // arg 2 - rmtp 278 MOVL $240, AX // sys_nanosleep 279 INT $0x80 280 RET 281 282 TEXT runtime·setldt(SB),NOSPLIT,$4 283 // Under DragonFly we set the GS base instead of messing with the LDT. 284 MOVL tls0+4(FP), AX 285 MOVL AX, 0(SP) 286 CALL runtime·settls(SB) 287 RET 288 289 TEXT runtime·settls(SB),NOSPLIT,$24 290 // adjust for ELF: wants to use -8(GS) and -4(GS) for g and m 291 MOVL tlsbase+0(FP), CX 292 ADDL $8, CX 293 294 // Set up a struct tls_info - a size of -1 maps the whole address 295 // space and is required for direct-tls access of variable data 296 // via negative offsets. 297 LEAL 16(SP), BX 298 MOVL CX, 16(SP) // base 299 MOVL $-1, 20(SP) // size 300 301 // set_tls_area returns the descriptor that needs to be loaded into GS. 302 MOVL $0, 0(SP) // syscall gap 303 MOVL $0, 4(SP) // arg 1 - which 304 MOVL BX, 8(SP) // arg 2 - tls_info 305 MOVL $8, 12(SP) // arg 3 - infosize 306 MOVL $472, AX // set_tls_area 307 INT $0x80 308 JCC 2(PC) 309 MOVL $0xf1, 0xf1 // crash 310 MOVW AX, GS 311 RET 312 313 TEXT runtime·sysctl(SB),NOSPLIT,$28 314 LEAL mib+0(FP), SI 315 LEAL 4(SP), DI 316 CLD 317 MOVSL // arg 1 - name 318 MOVSL // arg 2 - namelen 319 MOVSL // arg 3 - oldp 320 MOVSL // arg 4 - oldlenp 321 MOVSL // arg 5 - newp 322 MOVSL // arg 6 - newlen 323 MOVL $202, AX // sys___sysctl 324 INT $0x80 325 JCC 4(PC) 326 NEGL AX 327 MOVL AX, ret+24(FP) 328 RET 329 MOVL $0, AX 330 MOVL AX, ret+24(FP) 331 RET 332 333 TEXT runtime·osyield(SB),NOSPLIT,$-4 334 MOVL $331, AX // sys_sched_yield 335 INT $0x80 336 RET 337 338 TEXT runtime·sigprocmask(SB),NOSPLIT,$16 339 MOVL $0, 0(SP) // syscall gap 340 MOVL $3, 4(SP) // arg 1 - how (SIG_SETMASK) 341 MOVL new+0(FP), AX 342 MOVL AX, 8(SP) // arg 2 - set 343 MOVL old+4(FP), AX 344 MOVL AX, 12(SP) // arg 3 - oset 345 MOVL $340, AX // sys_sigprocmask 346 INT $0x80 347 JAE 2(PC) 348 MOVL $0xf1, 0xf1 // crash 349 RET 350 351 // int32 runtime·kqueue(void); 352 TEXT runtime·kqueue(SB),NOSPLIT,$0 353 MOVL $362, AX 354 INT $0x80 355 JAE 2(PC) 356 NEGL AX 357 MOVL AX, ret+0(FP) 358 RET 359 360 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); 361 TEXT runtime·kevent(SB),NOSPLIT,$0 362 MOVL $363, AX 363 INT $0x80 364 JAE 2(PC) 365 NEGL AX 366 MOVL AX, ret+24(FP) 367 RET 368 369 // int32 runtime·closeonexec(int32 fd); 370 TEXT runtime·closeonexec(SB),NOSPLIT,$32 371 MOVL $92, AX // fcntl 372 // 0(SP) is where the caller PC would be; kernel skips it 373 MOVL fd+0(FP), BX 374 MOVL BX, 4(SP) // fd 375 MOVL $2, 8(SP) // F_SETFD 376 MOVL $1, 12(SP) // FD_CLOEXEC 377 INT $0x80 378 JAE 2(PC) 379 NEGL AX 380 RET 381 382 GLOBL runtime·tlsoffset(SB),NOPTR,$4