github.com/c9s/go@v0.0.0-20180120015821-984e81f64e0c/src/runtime/sys_plan9_amd64.s (about) 1 // Copyright 2010 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 #include "go_asm.h" 6 #include "go_tls.h" 7 #include "textflag.h" 8 9 // setldt(int entry, int address, int limit) 10 TEXT runtime·setldt(SB),NOSPLIT,$0 11 RET 12 13 TEXT runtime·open(SB),NOSPLIT,$0 14 MOVQ $14, BP 15 SYSCALL 16 MOVL AX, ret+16(FP) 17 RET 18 19 TEXT runtime·pread(SB),NOSPLIT,$0 20 MOVQ $50, BP 21 SYSCALL 22 MOVL AX, ret+32(FP) 23 RET 24 25 TEXT runtime·pwrite(SB),NOSPLIT,$0 26 MOVQ $51, BP 27 SYSCALL 28 MOVL AX, ret+32(FP) 29 RET 30 31 // int32 _seek(int64*, int32, int64, int32) 32 TEXT _seek<>(SB),NOSPLIT,$0 33 MOVQ $39, BP 34 SYSCALL 35 RET 36 37 // int64 seek(int32, int64, int32) 38 // Convenience wrapper around _seek, the actual system call. 39 TEXT runtime·seek(SB),NOSPLIT,$32 40 LEAQ ret+24(FP), AX 41 MOVL fd+0(FP), BX 42 MOVQ offset+8(FP), CX 43 MOVL whence+16(FP), DX 44 MOVQ AX, 0(SP) 45 MOVL BX, 8(SP) 46 MOVQ CX, 16(SP) 47 MOVL DX, 24(SP) 48 CALL _seek<>(SB) 49 CMPL AX, $0 50 JGE 2(PC) 51 MOVQ $-1, ret+24(FP) 52 RET 53 54 TEXT runtime·closefd(SB),NOSPLIT,$0 55 MOVQ $4, BP 56 SYSCALL 57 MOVL AX, ret+8(FP) 58 RET 59 60 TEXT runtime·exits(SB),NOSPLIT,$0 61 MOVQ $8, BP 62 SYSCALL 63 RET 64 65 TEXT runtime·brk_(SB),NOSPLIT,$0 66 MOVQ $24, BP 67 SYSCALL 68 MOVL AX, ret+8(FP) 69 RET 70 71 TEXT runtime·sleep(SB),NOSPLIT,$0 72 MOVQ $17, BP 73 SYSCALL 74 MOVL AX, ret+8(FP) 75 RET 76 77 TEXT runtime·plan9_semacquire(SB),NOSPLIT,$0 78 MOVQ $37, BP 79 SYSCALL 80 MOVL AX, ret+16(FP) 81 RET 82 83 TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0 84 MOVQ $52, BP 85 SYSCALL 86 MOVL AX, ret+16(FP) 87 RET 88 89 TEXT runtime·nsec(SB),NOSPLIT,$0 90 MOVQ $53, BP 91 SYSCALL 92 MOVQ AX, ret+8(FP) 93 RET 94 95 // func walltime() (sec int64, nsec int32) 96 TEXT runtime·walltime(SB),NOSPLIT,$8-12 97 CALL runtime·nanotime(SB) 98 MOVQ 0(SP), AX 99 100 // generated code for 101 // func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 } 102 // adapted to reduce duplication 103 MOVQ AX, CX 104 MOVQ $1360296554856532783, AX 105 MULQ CX 106 ADDQ CX, DX 107 RCRQ $1, DX 108 SHRQ $29, DX 109 MOVQ DX, sec+0(FP) 110 IMULQ $1000000000, DX 111 SUBQ DX, CX 112 MOVL CX, nsec+8(FP) 113 RET 114 115 TEXT runtime·notify(SB),NOSPLIT,$0 116 MOVQ $28, BP 117 SYSCALL 118 MOVL AX, ret+8(FP) 119 RET 120 121 TEXT runtime·noted(SB),NOSPLIT,$0 122 MOVQ $29, BP 123 SYSCALL 124 MOVL AX, ret+8(FP) 125 RET 126 127 TEXT runtime·plan9_semrelease(SB),NOSPLIT,$0 128 MOVQ $38, BP 129 SYSCALL 130 MOVL AX, ret+16(FP) 131 RET 132 133 TEXT runtime·rfork(SB),NOSPLIT,$0 134 MOVQ $19, BP 135 SYSCALL 136 MOVL AX, ret+8(FP) 137 RET 138 139 TEXT runtime·tstart_plan9(SB),NOSPLIT,$8 140 MOVQ newm+0(FP), CX 141 MOVQ m_g0(CX), DX 142 143 // Layout new m scheduler stack on os stack. 144 MOVQ SP, AX 145 MOVQ AX, (g_stack+stack_hi)(DX) 146 SUBQ $(64*1024), AX // stack size 147 MOVQ AX, (g_stack+stack_lo)(DX) 148 MOVQ AX, g_stackguard0(DX) 149 MOVQ AX, g_stackguard1(DX) 150 151 // Initialize procid from TOS struct. 152 MOVQ _tos(SB), AX 153 MOVL 64(AX), AX 154 MOVQ AX, m_procid(CX) // save pid as m->procid 155 156 // Finally, initialize g. 157 get_tls(BX) 158 MOVQ DX, g(BX) 159 160 CALL runtime·stackcheck(SB) // smashes AX, CX 161 CALL runtime·mstart(SB) 162 163 // Exit the thread. 164 MOVQ $0, 0(SP) 165 CALL runtime·exits(SB) 166 JMP 0(PC) 167 168 // This is needed by asm_amd64.s 169 TEXT runtime·settls(SB),NOSPLIT,$0 170 RET 171 172 // void sigtramp(void *ureg, int8 *note) 173 TEXT runtime·sigtramp(SB),NOSPLIT,$0 174 get_tls(AX) 175 176 // check that g exists 177 MOVQ g(AX), BX 178 CMPQ BX, $0 179 JNE 3(PC) 180 CALL runtime·badsignal2(SB) // will exit 181 RET 182 183 // save args 184 MOVQ ureg+0(FP), CX 185 MOVQ note+8(FP), DX 186 187 // change stack 188 MOVQ g_m(BX), BX 189 MOVQ m_gsignal(BX), R10 190 MOVQ (g_stack+stack_hi)(R10), BP 191 MOVQ BP, SP 192 193 // make room for args and g 194 SUBQ $128, SP 195 196 // save g 197 MOVQ g(AX), BP 198 MOVQ BP, 32(SP) 199 200 // g = m->gsignal 201 MOVQ R10, g(AX) 202 203 // load args and call sighandler 204 MOVQ CX, 0(SP) 205 MOVQ DX, 8(SP) 206 MOVQ BP, 16(SP) 207 208 CALL runtime·sighandler(SB) 209 MOVL 24(SP), AX 210 211 // restore g 212 get_tls(BX) 213 MOVQ 32(SP), R10 214 MOVQ R10, g(BX) 215 216 // call noted(AX) 217 MOVQ AX, 0(SP) 218 CALL runtime·noted(SB) 219 RET 220 221 TEXT runtime·setfpmasks(SB),NOSPLIT,$8 222 STMXCSR 0(SP) 223 MOVL 0(SP), AX 224 ANDL $~0x3F, AX 225 ORL $(0x3F<<7), AX 226 MOVL AX, 0(SP) 227 LDMXCSR 0(SP) 228 RET 229 230 #define ERRMAX 128 /* from os_plan9.h */ 231 232 // void errstr(int8 *buf, int32 len) 233 TEXT errstr<>(SB),NOSPLIT,$0 234 MOVQ $41, BP 235 SYSCALL 236 RET 237 238 // func errstr() string 239 // Only used by package syscall. 240 // Grab error string due to a syscall made 241 // in entersyscall mode, without going 242 // through the allocator (issue 4994). 243 // See ../syscall/asm_plan9_amd64.s:/·Syscall/ 244 TEXT runtime·errstr(SB),NOSPLIT,$16-16 245 get_tls(AX) 246 MOVQ g(AX), BX 247 MOVQ g_m(BX), BX 248 MOVQ (m_mOS+mOS_errstr)(BX), CX 249 MOVQ CX, 0(SP) 250 MOVQ $ERRMAX, 8(SP) 251 CALL errstr<>(SB) 252 CALL runtime·findnull(SB) 253 MOVQ 8(SP), AX 254 MOVQ AX, ret_len+8(FP) 255 MOVQ 0(SP), AX 256 MOVQ AX, ret_base+0(FP) 257 RET