github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_linux_mips64x.s (about) 1 // Copyright 2015 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 // +build linux 6 // +build mips64 mips64le 7 8 // 9 // System calls and other sys.stuff for mips64, Linux 10 // 11 12 #include "go_asm.h" 13 #include "go_tls.h" 14 #include "textflag.h" 15 16 #define SYS_exit 5058 17 #define SYS_read 5000 18 #define SYS_write 5001 19 #define SYS_open 5002 20 #define SYS_close 5003 21 #define SYS_getpid 5038 22 #define SYS_kill 5060 23 #define SYS_fcntl 5080 24 #define SYS_gettimeofday 5094 25 #define SYS_mmap 5009 26 #define SYS_munmap 5011 27 #define SYS_setitimer 5036 28 #define SYS_clone 5055 29 #define SYS_newselect 5022 30 #define SYS_sched_yield 5023 31 #define SYS_rt_sigreturn 5211 32 #define SYS_rt_sigaction 5013 33 #define SYS_rt_sigprocmask 5014 34 #define SYS_sigaltstack 5129 35 #define SYS_getrlimit 5095 36 #define SYS_madvise 5027 37 #define SYS_mincore 5026 38 #define SYS_gettid 5178 39 #define SYS_tkill 5192 40 #define SYS_futex 5194 41 #define SYS_sched_getaffinity 5196 42 #define SYS_exit_group 5205 43 #define SYS_epoll_create 5207 44 #define SYS_epoll_ctl 5208 45 #define SYS_epoll_wait 5209 46 #define SYS_clock_gettime 5222 47 #define SYS_epoll_create1 5285 48 49 TEXT runtime·exit(SB),NOSPLIT,$-8-4 50 MOVW code+0(FP), R4 51 MOVV $SYS_exit_group, R2 52 SYSCALL 53 RET 54 55 TEXT runtime·exit1(SB),NOSPLIT,$-8-4 56 MOVW code+0(FP), R4 57 MOVV $SYS_exit, R2 58 SYSCALL 59 RET 60 61 TEXT runtime·open(SB),NOSPLIT,$-8-20 62 MOVV name+0(FP), R4 63 MOVW mode+8(FP), R5 64 MOVW perm+12(FP), R6 65 MOVV $SYS_open, R2 66 SYSCALL 67 BEQ R7, 2(PC) 68 MOVW $-1, R2 69 MOVW R2, ret+16(FP) 70 RET 71 72 TEXT runtime·closefd(SB),NOSPLIT,$-8-12 73 MOVW fd+0(FP), R4 74 MOVV $SYS_close, R2 75 SYSCALL 76 BEQ R7, 2(PC) 77 MOVW $-1, R2 78 MOVW R2, ret+8(FP) 79 RET 80 81 TEXT runtime·write(SB),NOSPLIT,$-8-28 82 MOVV fd+0(FP), R4 83 MOVV p+8(FP), R5 84 MOVW n+16(FP), R6 85 MOVV $SYS_write, R2 86 SYSCALL 87 BEQ R7, 2(PC) 88 MOVW $-1, R2 89 MOVW R2, ret+24(FP) 90 RET 91 92 TEXT runtime·read(SB),NOSPLIT,$-8-28 93 MOVW fd+0(FP), R4 94 MOVV p+8(FP), R5 95 MOVW n+16(FP), R6 96 MOVV $SYS_read, R2 97 SYSCALL 98 BEQ R7, 2(PC) 99 MOVW $-1, R2 100 MOVW R2, ret+24(FP) 101 RET 102 103 TEXT runtime·getrlimit(SB),NOSPLIT,$-8-20 104 MOVW kind+0(FP), R4 // _RLIMIT_AS = 6 on linux/mips 105 MOVV limit+8(FP), R5 106 MOVV $SYS_getrlimit, R2 107 SYSCALL 108 MOVW R2, ret+16(FP) 109 RET 110 111 TEXT runtime·usleep(SB),NOSPLIT,$16-4 112 MOVWU usec+0(FP), R3 113 MOVV R3, R5 114 MOVW $1000000, R4 115 DIVVU R4, R3 116 MOVV LO, R3 117 MOVV R3, 8(R29) 118 MULVU R3, R4 119 MOVV LO, R4 120 SUBVU R4, R5 121 MOVV R5, 16(R29) 122 123 // select(0, 0, 0, 0, &tv) 124 MOVW $0, R4 125 MOVW $0, R5 126 MOVW $0, R6 127 MOVW $0, R7 128 ADDV $8, R29, R8 129 MOVV $SYS_newselect, R2 130 SYSCALL 131 RET 132 133 TEXT runtime·gettid(SB),NOSPLIT,$0-4 134 MOVV $SYS_gettid, R2 135 SYSCALL 136 MOVW R2, ret+0(FP) 137 RET 138 139 TEXT runtime·raise(SB),NOSPLIT,$-8 140 MOVV $SYS_gettid, R2 141 SYSCALL 142 MOVW R2, R4 // arg 1 tid 143 MOVW sig+0(FP), R5 // arg 2 144 MOVV $SYS_tkill, R2 145 SYSCALL 146 RET 147 148 TEXT runtime·raiseproc(SB),NOSPLIT,$-8 149 MOVV $SYS_getpid, R2 150 SYSCALL 151 MOVW R2, R4 // arg 1 pid 152 MOVW sig+0(FP), R5 // arg 2 153 MOVV $SYS_kill, R2 154 SYSCALL 155 RET 156 157 TEXT runtime·setitimer(SB),NOSPLIT,$-8-24 158 MOVW mode+0(FP), R4 159 MOVV new+8(FP), R5 160 MOVV old+16(FP), R6 161 MOVV $SYS_setitimer, R2 162 SYSCALL 163 RET 164 165 TEXT runtime·mincore(SB),NOSPLIT,$-8-28 166 MOVV addr+0(FP), R4 167 MOVV n+8(FP), R5 168 MOVV dst+16(FP), R6 169 MOVV $SYS_mincore, R2 170 SYSCALL 171 SUBVU R2, R0, R2 // caller expects negative errno 172 MOVW R2, ret+24(FP) 173 RET 174 175 // func now() (sec int64, nsec int32) 176 TEXT time·now(SB),NOSPLIT,$16 177 MOVV $0(R29), R4 178 MOVV $0, R5 179 MOVV $SYS_gettimeofday, R2 180 SYSCALL 181 MOVV 0(R29), R3 // sec 182 MOVV 8(R29), R5 // usec 183 MOVV $1000, R4 184 MULVU R4, R5 185 MOVV LO, R5 186 MOVV R3, sec+0(FP) 187 MOVW R5, nsec+8(FP) 188 RET 189 190 TEXT runtime·nanotime(SB),NOSPLIT,$16 191 MOVW $1, R4 // CLOCK_MONOTONIC 192 MOVV $0(R29), R5 193 MOVV $SYS_clock_gettime, R2 194 SYSCALL 195 MOVV 0(R29), R3 // sec 196 MOVV 8(R29), R5 // nsec 197 // sec is in R3, nsec in R5 198 // return nsec in R3 199 MOVV $1000000000, R4 200 MULVU R4, R3 201 MOVV LO, R3 202 ADDVU R5, R3 203 MOVV R3, ret+0(FP) 204 RET 205 206 TEXT runtime·rtsigprocmask(SB),NOSPLIT,$-8-28 207 MOVW sig+0(FP), R4 208 MOVV new+8(FP), R5 209 MOVV old+16(FP), R6 210 MOVW size+24(FP), R7 211 MOVV $SYS_rt_sigprocmask, R2 212 SYSCALL 213 BEQ R7, 2(PC) 214 MOVV R0, 0xf1(R0) // crash 215 RET 216 217 TEXT runtime·rt_sigaction(SB),NOSPLIT,$-8-36 218 MOVV sig+0(FP), R4 219 MOVV new+8(FP), R5 220 MOVV old+16(FP), R6 221 MOVV size+24(FP), R7 222 MOVV $SYS_rt_sigaction, R2 223 SYSCALL 224 MOVW R2, ret+32(FP) 225 RET 226 227 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 228 MOVW sig+8(FP), R4 229 MOVV info+16(FP), R5 230 MOVV ctx+24(FP), R6 231 MOVV fn+0(FP), R1 232 JAL (R1) 233 RET 234 235 TEXT runtime·sigtramp(SB),NOSPLIT,$64 236 // initialize essential registers (just in case) 237 JAL runtime·reginit(SB) 238 239 // this might be called in external code context, 240 // where g is not set. 241 MOVB runtime·iscgo(SB), R1 242 BEQ R1, 2(PC) 243 JAL runtime·load_g(SB) 244 245 MOVW R4, 8(R29) 246 MOVV R5, 16(R29) 247 MOVV R6, 24(R29) 248 MOVV $runtime·sigtrampgo(SB), R1 249 JAL (R1) 250 RET 251 252 TEXT runtime·mmap(SB),NOSPLIT,$-8 253 MOVV addr+0(FP), R4 254 MOVV n+8(FP), R5 255 MOVW prot+16(FP), R6 256 MOVW flags+20(FP), R7 257 MOVW fd+24(FP), R8 258 MOVW off+28(FP), R9 259 260 MOVV $SYS_mmap, R2 261 SYSCALL 262 MOVV R2, ret+32(FP) 263 RET 264 265 TEXT runtime·munmap(SB),NOSPLIT,$-8 266 MOVV addr+0(FP), R4 267 MOVV n+8(FP), R5 268 MOVV $SYS_munmap, R2 269 SYSCALL 270 BEQ R7, 2(PC) 271 MOVV R0, 0xf3(R0) // crash 272 RET 273 274 TEXT runtime·madvise(SB),NOSPLIT,$-8 275 MOVV addr+0(FP), R4 276 MOVV n+8(FP), R5 277 MOVW flags+16(FP), R6 278 MOVV $SYS_madvise, R2 279 SYSCALL 280 // ignore failure - maybe pages are locked 281 RET 282 283 // int64 futex(int32 *uaddr, int32 op, int32 val, 284 // struct timespec *timeout, int32 *uaddr2, int32 val2); 285 TEXT runtime·futex(SB),NOSPLIT,$-8 286 MOVV addr+0(FP), R4 287 MOVW op+8(FP), R5 288 MOVW val+12(FP), R6 289 MOVV ts+16(FP), R7 290 MOVV addr2+24(FP), R8 291 MOVW val3+32(FP), R9 292 MOVV $SYS_futex, R2 293 SYSCALL 294 MOVW R2, ret+40(FP) 295 RET 296 297 // int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void)); 298 TEXT runtime·clone(SB),NOSPLIT,$-8 299 MOVW flags+0(FP), R4 300 MOVV stk+8(FP), R5 301 302 // Copy mp, gp, fn off parent stack for use by child. 303 // Careful: Linux system call clobbers ???. 304 MOVV mm+16(FP), R16 305 MOVV gg+24(FP), R17 306 MOVV fn+32(FP), R18 307 308 MOVV R16, -8(R5) 309 MOVV R17, -16(R5) 310 MOVV R18, -24(R5) 311 MOVV $1234, R16 312 MOVV R16, -32(R5) 313 314 MOVV $SYS_clone, R2 315 SYSCALL 316 317 // In parent, return. 318 BEQ R2, 3(PC) 319 MOVW R2, ret+40(FP) 320 RET 321 322 // In child, on new stack. 323 // initialize essential registers 324 JAL runtime·reginit(SB) 325 MOVV -32(R29), R16 326 MOVV $1234, R1 327 BEQ R16, R1, 2(PC) 328 MOVV R0, 0(R0) 329 330 // Initialize m->procid to Linux tid 331 MOVV $SYS_gettid, R2 332 SYSCALL 333 334 MOVV -24(R29), R18 // fn 335 MOVV -16(R29), R17 // g 336 MOVV -8(R29), R16 // m 337 338 BEQ R16, nog 339 BEQ R17, nog 340 341 MOVV R2, m_procid(R16) 342 343 // TODO: setup TLS. 344 345 // In child, set up new stack 346 MOVV R16, g_m(R17) 347 MOVV R17, g 348 //CALL runtime·stackcheck(SB) 349 350 nog: 351 // Call fn 352 JAL (R18) 353 354 // It shouldn't return. If it does, exit that thread. 355 MOVW $111, R4 356 MOVV $SYS_exit, R2 357 SYSCALL 358 JMP -3(PC) // keep exiting 359 360 TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 361 MOVV new+0(FP), R4 362 MOVV old+8(FP), R5 363 MOVV $SYS_sigaltstack, R2 364 SYSCALL 365 BEQ R7, 2(PC) 366 MOVV R0, 0xf1(R0) // crash 367 RET 368 369 TEXT runtime·osyield(SB),NOSPLIT,$-8 370 MOVV $SYS_sched_yield, R2 371 SYSCALL 372 RET 373 374 TEXT runtime·sched_getaffinity(SB),NOSPLIT,$-8 375 MOVV pid+0(FP), R4 376 MOVV len+8(FP), R5 377 MOVV buf+16(FP), R6 378 MOVV $SYS_sched_getaffinity, R2 379 SYSCALL 380 MOVW R2, ret+24(FP) 381 RET 382 383 // int32 runtime·epollcreate(int32 size); 384 TEXT runtime·epollcreate(SB),NOSPLIT,$-8 385 MOVW size+0(FP), R4 386 MOVV $SYS_epoll_create, R2 387 SYSCALL 388 MOVW R2, ret+8(FP) 389 RET 390 391 // int32 runtime·epollcreate1(int32 flags); 392 TEXT runtime·epollcreate1(SB),NOSPLIT,$-8 393 MOVW flags+0(FP), R4 394 MOVV $SYS_epoll_create1, R2 395 SYSCALL 396 MOVW R2, ret+8(FP) 397 RET 398 399 // func epollctl(epfd, op, fd int32, ev *epollEvent) int 400 TEXT runtime·epollctl(SB),NOSPLIT,$-8 401 MOVW epfd+0(FP), R4 402 MOVW op+4(FP), R5 403 MOVW fd+8(FP), R6 404 MOVV ev+16(FP), R7 405 MOVV $SYS_epoll_ctl, R2 406 SYSCALL 407 MOVW R2, ret+24(FP) 408 RET 409 410 // int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout); 411 TEXT runtime·epollwait(SB),NOSPLIT,$-8 412 MOVW epfd+0(FP), R4 413 MOVV ev+8(FP), R5 414 MOVW nev+16(FP), R6 415 MOVW timeout+20(FP), R7 416 MOVV $SYS_epoll_wait, R2 417 SYSCALL 418 MOVW R2, ret+24(FP) 419 RET 420 421 // void runtime·closeonexec(int32 fd); 422 TEXT runtime·closeonexec(SB),NOSPLIT,$-8 423 MOVW fd+0(FP), R4 // fd 424 MOVV $2, R5 // F_SETFD 425 MOVV $1, R6 // FD_CLOEXEC 426 MOVV $SYS_fcntl, R2 427 SYSCALL 428 RET