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