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 runtimesetldt(SB),NOSPLIT,$0 11 RET 12 13 TEXT runtimeopen(SB),NOSPLIT,$0 14 MOVL $14, AX 15 INT $64 16 MOVL AX, ret+12(FP) 17 RET 18 19 TEXT runtimepread(SB),NOSPLIT,$0 20 MOVL $50, AX 21 INT $64 22 MOVL AX, ret+20(FP) 23 RET 24 25 TEXT runtimepwrite(SB),NOSPLIT,$0 26 MOVL $51, AX 27 INT $64 28 MOVL AX, ret+20(FP) 29 RET 30 31 // int32 _seek(int64*, int32, int64, int32) 32 TEXT _seek<>(SB),NOSPLIT,$0 33 MOVL $39, AX 34 INT $64 35 RET 36 37 TEXT runtimeseek(SB),NOSPLIT,$24 38 LEAL ret+16(FP), AX 39 MOVL fd+0(FP), BX 40 MOVL offset_lo+4(FP), CX 41 MOVL offset_hi+8(FP), DX 42 MOVL whence+12(FP), SI 43 MOVL AX, 0(SP) 44 MOVL BX, 4(SP) 45 MOVL CX, 8(SP) 46 MOVL DX, 12(SP) 47 MOVL SI, 16(SP) 48 CALL _seek<>(SB) 49 CMPL AX, $0 50 JGE 3(PC) 51 MOVL $-1, ret_lo+16(FP) 52 MOVL $-1, ret_hi+20(FP) 53 RET 54 55 TEXT runtimeclosefd(SB),NOSPLIT,$0 56 MOVL $4, AX 57 INT $64 58 MOVL AX, ret+4(FP) 59 RET 60 61 TEXT runtimeexits(SB),NOSPLIT,$0 62 MOVL $8, AX 63 INT $64 64 RET 65 66 TEXT runtimebrk_(SB),NOSPLIT,$0 67 MOVL $24, AX 68 INT $64 69 MOVL AX, ret+4(FP) 70 RET 71 72 TEXT runtimesleep(SB),NOSPLIT,$0 73 MOVL $17, AX 74 INT $64 75 MOVL AX, ret+4(FP) 76 RET 77 78 TEXT runtimeplan9_semacquire(SB),NOSPLIT,$0 79 MOVL $37, AX 80 INT $64 81 MOVL AX, ret+8(FP) 82 RET 83 84 TEXT runtimeplan9_tsemacquire(SB),NOSPLIT,$0 85 MOVL $52, AX 86 INT $64 87 MOVL AX, ret+8(FP) 88 RET 89 90 TEXT nsec<>(SB),NOSPLIT,$0 91 MOVL $53, AX 92 INT $64 93 RET 94 95 TEXT runtimensec(SB),NOSPLIT,$8 96 LEAL ret+4(FP), AX 97 MOVL AX, 0(SP) 98 CALL nsec<>(SB) 99 CMPL AX, $0 100 JGE 3(PC) 101 MOVL $-1, ret_lo+4(FP) 102 MOVL $-1, ret_hi+8(FP) 103 RET 104 105 // func now() (sec int64, nsec int32) 106 TEXT timenow(SB),NOSPLIT,$8-12 107 CALL runtimenanotime(SB) 108 MOVL 0(SP), AX 109 MOVL 4(SP), DX 110 111 MOVL $1000000000, CX 112 DIVL CX 113 MOVL AX, sec+0(FP) 114 MOVL $0, sec+4(FP) 115 MOVL DX, nsec+8(FP) 116 RET 117 118 TEXT runtimenotify(SB),NOSPLIT,$0 119 MOVL $28, AX 120 INT $64 121 MOVL AX, ret+4(FP) 122 RET 123 124 TEXT runtimenoted(SB),NOSPLIT,$0 125 MOVL $29, AX 126 INT $64 127 MOVL AX, ret+4(FP) 128 RET 129 130 TEXT runtimeplan9_semrelease(SB),NOSPLIT,$0 131 MOVL $38, AX 132 INT $64 133 MOVL AX, ret+8(FP) 134 RET 135 136 TEXT runtimerfork(SB),NOSPLIT,$0 137 MOVL $19, AX 138 INT $64 139 MOVL AX, ret+4(FP) 140 RET 141 142 TEXT runtimetstart_plan9(SB),NOSPLIT,$0 143 MOVL newm+0(FP), CX 144 MOVL m_g0(CX), DX 145 146 // Layout new m scheduler stack on os stack. 147 MOVL SP, AX 148 MOVL AX, (g_stack+stack_hi)(DX) 149 SUBL $(64*1024), AX // stack size 150 MOVL AX, (g_stack+stack_lo)(DX) 151 MOVL AX, g_stackguard0(DX) 152 MOVL AX, g_stackguard1(DX) 153 154 // Initialize procid from TOS struct. 155 MOVL _tos(SB), AX 156 MOVL 48(AX), AX 157 MOVL AX, m_procid(CX) // save pid as m->procid 158 159 // Finally, initialize g. 160 get_tls(BX) 161 MOVL DX, g(BX) 162 163 CALL runtimestackcheck(SB) // smashes AX, CX 164 CALL runtimemstart(SB) 165 166 MOVL $0x1234, 0x1234 // not reached 167 RET 168 169 // void sigtramp(void *ureg, int8 *note) 170 TEXT runtimesigtramp(SB),NOSPLIT,$0 171 get_tls(AX) 172 173 // check that g exists 174 MOVL g(AX), BX 175 CMPL BX, $0 176 JNE 3(PC) 177 CALL runtimebadsignal2(SB) // will exit 178 RET 179 180 // save args 181 MOVL ureg+4(SP), CX 182 MOVL note+8(SP), DX 183 184 // change stack 185 MOVL g_m(BX), BX 186 MOVL m_gsignal(BX), BP 187 MOVL (g_stack+stack_hi)(BP), BP 188 MOVL BP, SP 189 190 // make room for args and g 191 SUBL $24, SP 192 193 // save g 194 MOVL g(AX), BP 195 MOVL BP, 20(SP) 196 197 // g = m->gsignal 198 MOVL m_gsignal(BX), DI 199 MOVL DI, g(AX) 200 201 // load args and call sighandler 202 MOVL CX, 0(SP) 203 MOVL DX, 4(SP) 204 MOVL BP, 8(SP) 205 206 CALL runtimesighandler(SB) 207 MOVL 12(SP), AX 208 209 // restore g 210 get_tls(BX) 211 MOVL 20(SP), BP 212 MOVL BP, g(BX) 213 214 // call noted(AX) 215 MOVL AX, 0(SP) 216 CALL runtimenoted(SB) 217 RET 218 219 // Only used by the 64-bit runtime. 220 TEXT runtimesetfpmasks(SB),NOSPLIT,$0 221 RET 222 223 #define ERRMAX 128 /* from os_plan9.h */ 224 225 // void errstr(int8 *buf, int32 len) 226 TEXT errstr<>(SB),NOSPLIT,$0 227 MOVL $41, AX 228 INT $64 229 RET 230 231 // func errstr() string 232 // Only used by package syscall. 233 // Grab error string due to a syscall made 234 // in entersyscall mode, without going 235 // through the allocator (issue 4994). 236 // See ../syscall/asm_plan9_386.s:/Syscall/ 237 TEXT runtimeerrstr(SB),NOSPLIT,$8-8 238 get_tls(AX) 239 MOVL g(AX), BX 240 MOVL g_m(BX), BX 241 MOVL m_errstr(BX), CX 242 MOVL CX, 0(SP) 243 MOVL $ERRMAX, 4(SP) 244 CALL errstr<>(SB) 245 CALL runtimefindnull(SB) 246 MOVL 4(SP), AX 247 MOVL AX, ret_len+4(FP) 248 MOVL 0(SP), AX 249 MOVL AX, ret_base+0(FP) 250 RET 251