github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_freebsd_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_op(SB),NOSPLIT,$-4 14 MOVL $454, AX 15 INT $0x80 16 MOVL AX, ret+20(FP) 17 RET 18 19 TEXT runtime·thr_new(SB),NOSPLIT,$-4 20 MOVL $455, AX 21 INT $0x80 22 RET 23 24 TEXT runtime·thr_start(SB),NOSPLIT,$0 25 MOVL mm+0(FP), AX 26 MOVL m_g0(AX), BX 27 LEAL m_tls(AX), BP 28 MOVL m_id(AX), DI 29 ADDL $7, DI 30 PUSHAL 31 PUSHL $32 32 PUSHL BP 33 PUSHL DI 34 CALL runtime·setldt(SB) 35 POPL AX 36 POPL AX 37 POPL AX 38 POPAL 39 get_tls(CX) 40 MOVL BX, g(CX) 41 42 MOVL AX, g_m(BX) 43 CALL runtime·stackcheck(SB) // smashes AX 44 CALL runtime·mstart(SB) 45 46 MOVL 0, AX // crash (not reached) 47 48 // Exit the entire program (like C exit) 49 TEXT runtime·exit(SB),NOSPLIT,$-4 50 MOVL $1, AX 51 INT $0x80 52 MOVL $0xf1, 0xf1 // crash 53 RET 54 55 TEXT runtime·exit1(SB),NOSPLIT,$-4 56 MOVL $431, AX 57 INT $0x80 58 JAE 2(PC) 59 MOVL $0xf1, 0xf1 // crash 60 RET 61 62 TEXT runtime·open(SB),NOSPLIT,$-4 63 MOVL $5, AX 64 INT $0x80 65 JAE 2(PC) 66 MOVL $-1, AX 67 MOVL AX, ret+12(FP) 68 RET 69 70 TEXT runtime·closefd(SB),NOSPLIT,$-4 71 MOVL $6, AX 72 INT $0x80 73 JAE 2(PC) 74 MOVL $-1, AX 75 MOVL AX, ret+4(FP) 76 RET 77 78 TEXT runtime·read(SB),NOSPLIT,$-4 79 MOVL $3, AX 80 INT $0x80 81 JAE 2(PC) 82 MOVL $-1, AX 83 MOVL AX, ret+12(FP) 84 RET 85 86 TEXT runtime·write(SB),NOSPLIT,$-4 87 MOVL $4, AX 88 INT $0x80 89 JAE 2(PC) 90 MOVL $-1, AX 91 MOVL AX, ret+12(FP) 92 RET 93 94 TEXT runtime·getrlimit(SB),NOSPLIT,$-4 95 MOVL $194, AX 96 INT $0x80 97 MOVL AX, ret+8(FP) 98 RET 99 100 TEXT runtime·raise(SB),NOSPLIT,$16 101 // thr_self(&8(SP)) 102 LEAL 8(SP), AX 103 MOVL AX, 4(SP) 104 MOVL $432, AX 105 INT $0x80 106 // thr_kill(self, SIGPIPE) 107 MOVL 8(SP), AX 108 MOVL AX, 4(SP) 109 MOVL sig+0(FP), AX 110 MOVL AX, 8(SP) 111 MOVL $433, AX 112 INT $0x80 113 RET 114 115 TEXT runtime·raiseproc(SB),NOSPLIT,$16 116 // getpid 117 MOVL $20, AX 118 INT $0x80 119 // kill(self, sig) 120 MOVL AX, 4(SP) 121 MOVL sig+0(FP), AX 122 MOVL AX, 8(SP) 123 MOVL $37, AX 124 INT $0x80 125 RET 126 127 TEXT runtime·mmap(SB),NOSPLIT,$32 128 LEAL addr+0(FP), SI 129 LEAL 4(SP), DI 130 CLD 131 MOVSL 132 MOVSL 133 MOVSL 134 MOVSL 135 MOVSL 136 MOVSL 137 MOVL $0, AX // top 32 bits of file offset 138 STOSL 139 MOVL $477, AX 140 INT $0x80 141 MOVL AX, ret+24(FP) 142 RET 143 144 TEXT runtime·munmap(SB),NOSPLIT,$-4 145 MOVL $73, AX 146 INT $0x80 147 JAE 2(PC) 148 MOVL $0xf1, 0xf1 // crash 149 RET 150 151 TEXT runtime·madvise(SB),NOSPLIT,$-4 152 MOVL $75, AX // madvise 153 INT $0x80 154 // ignore failure - maybe pages are locked 155 RET 156 157 TEXT runtime·setitimer(SB), NOSPLIT, $-4 158 MOVL $83, AX 159 INT $0x80 160 RET 161 162 // func now() (sec int64, nsec int32) 163 TEXT time·now(SB), NOSPLIT, $32 164 MOVL $232, AX 165 LEAL 12(SP), BX 166 MOVL $0, 4(SP) // CLOCK_REALTIME 167 MOVL BX, 8(SP) 168 INT $0x80 169 MOVL 12(SP), AX // sec 170 MOVL 16(SP), BX // nsec 171 172 // sec is in AX, nsec in BX 173 MOVL AX, sec+0(FP) 174 MOVL $0, sec+4(FP) 175 MOVL BX, nsec+8(FP) 176 RET 177 178 // int64 nanotime(void) so really 179 // void nanotime(int64 *nsec) 180 TEXT runtime·nanotime(SB), NOSPLIT, $32 181 MOVL $232, AX 182 LEAL 12(SP), BX 183 // We can use CLOCK_MONOTONIC_FAST here when we drop 184 // support for FreeBSD 8-STABLE. 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 $416, AX 205 INT $0x80 206 JAE 2(PC) 207 MOVL $0xf1, 0xf1 // crash 208 RET 209 210 TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 211 MOVL sig+4(FP), AX 212 MOVL AX, 0(SP) 213 MOVL info+8(FP), AX 214 MOVL AX, 4(SP) 215 MOVL ctx+12(FP), AX 216 MOVL AX, 8(SP) 217 MOVL fn+0(FP), AX 218 CALL AX 219 RET 220 221 TEXT runtime·sigtramp(SB),NOSPLIT,$12 222 MOVL signo+0(FP), BX 223 MOVL BX, 0(SP) 224 MOVL info+4(FP), BX 225 MOVL BX, 4(SP) 226 MOVL context+8(FP), BX 227 MOVL BX, 8(SP) 228 CALL runtime·sigtrampgo(SB) 229 230 // call sigreturn 231 MOVL context+8(FP), AX 232 MOVL $0, 0(SP) // syscall gap 233 MOVL AX, 4(SP) 234 MOVL $417, AX // sigreturn(ucontext) 235 INT $0x80 236 MOVL $0xf1, 0xf1 // crash 237 RET 238 239 TEXT runtime·sigaltstack(SB),NOSPLIT,$0 240 MOVL $53, AX 241 INT $0x80 242 JAE 2(PC) 243 MOVL $0xf1, 0xf1 // crash 244 RET 245 246 TEXT runtime·usleep(SB),NOSPLIT,$20 247 MOVL $0, DX 248 MOVL usec+0(FP), AX 249 MOVL $1000000, CX 250 DIVL CX 251 MOVL AX, 12(SP) // tv_sec 252 MOVL $1000, AX 253 MULL DX 254 MOVL AX, 16(SP) // tv_nsec 255 256 MOVL $0, 0(SP) 257 LEAL 12(SP), AX 258 MOVL AX, 4(SP) // arg 1 - rqtp 259 MOVL $0, 8(SP) // arg 2 - rmtp 260 MOVL $240, AX // sys_nanosleep 261 INT $0x80 262 RET 263 264 /* 265 descriptor entry format for system call 266 is the native machine format, ugly as it is: 267 268 2-byte limit 269 3-byte base 270 1-byte: 0x80=present, 0x60=dpl<<5, 0x1F=type 271 1-byte: 0x80=limit is *4k, 0x40=32-bit operand size, 272 0x0F=4 more bits of limit 273 1 byte: 8 more bits of base 274 275 int i386_get_ldt(int, union ldt_entry *, int); 276 int i386_set_ldt(int, const union ldt_entry *, int); 277 278 */ 279 280 // setldt(int entry, int address, int limit) 281 TEXT runtime·setldt(SB),NOSPLIT,$32 282 MOVL address+4(FP), BX // aka base 283 // see comment in sys_linux_386.s; freebsd is similar 284 ADDL $0x4, BX 285 286 // set up data_desc 287 LEAL 16(SP), AX // struct data_desc 288 MOVL $0, 0(AX) 289 MOVL $0, 4(AX) 290 291 MOVW BX, 2(AX) 292 SHRL $16, BX 293 MOVB BX, 4(AX) 294 SHRL $8, BX 295 MOVB BX, 7(AX) 296 297 MOVW $0xffff, 0(AX) 298 MOVB $0xCF, 6(AX) // 32-bit operand, 4k limit unit, 4 more bits of limit 299 300 MOVB $0xF2, 5(AX) // r/w data descriptor, dpl=3, present 301 302 // call i386_set_ldt(entry, desc, 1) 303 MOVL $0xffffffff, 0(SP) // auto-allocate entry and return in AX 304 MOVL AX, 4(SP) 305 MOVL $1, 8(SP) 306 CALL runtime·i386_set_ldt(SB) 307 308 // compute segment selector - (entry*8+7) 309 SHLL $3, AX 310 ADDL $7, AX 311 MOVW AX, GS 312 RET 313 314 TEXT runtime·i386_set_ldt(SB),NOSPLIT,$16 315 LEAL args+0(FP), AX // 0(FP) == 4(SP) before SP got moved 316 MOVL $0, 0(SP) // syscall gap 317 MOVL $1, 4(SP) 318 MOVL AX, 8(SP) 319 MOVL $165, AX 320 INT $0x80 321 JAE 2(PC) 322 INT $3 323 RET 324 325 TEXT runtime·sysctl(SB),NOSPLIT,$28 326 LEAL mib+0(FP), SI 327 LEAL 4(SP), DI 328 CLD 329 MOVSL // arg 1 - name 330 MOVSL // arg 2 - namelen 331 MOVSL // arg 3 - oldp 332 MOVSL // arg 4 - oldlenp 333 MOVSL // arg 5 - newp 334 MOVSL // arg 6 - newlen 335 MOVL $202, AX // sys___sysctl 336 INT $0x80 337 JAE 4(PC) 338 NEGL AX 339 MOVL AX, ret+24(FP) 340 RET 341 MOVL $0, AX 342 MOVL AX, ret+24(FP) 343 RET 344 345 TEXT runtime·osyield(SB),NOSPLIT,$-4 346 MOVL $331, AX // sys_sched_yield 347 INT $0x80 348 RET 349 350 TEXT runtime·sigprocmask(SB),NOSPLIT,$16 351 MOVL $0, 0(SP) // syscall gap 352 MOVL how+0(FP), AX // arg 1 - how 353 MOVL AX, 4(SP) 354 MOVL new+4(FP), AX 355 MOVL AX, 8(SP) // arg 2 - set 356 MOVL old+8(FP), AX 357 MOVL AX, 12(SP) // arg 3 - oset 358 MOVL $340, AX // sys_sigprocmask 359 INT $0x80 360 JAE 2(PC) 361 MOVL $0xf1, 0xf1 // crash 362 RET 363 364 // int32 runtime·kqueue(void); 365 TEXT runtime·kqueue(SB),NOSPLIT,$0 366 MOVL $362, AX 367 INT $0x80 368 JAE 2(PC) 369 NEGL AX 370 MOVL AX, ret+0(FP) 371 RET 372 373 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout); 374 TEXT runtime·kevent(SB),NOSPLIT,$0 375 MOVL $363, AX 376 INT $0x80 377 JAE 2(PC) 378 NEGL AX 379 MOVL AX, ret+24(FP) 380 RET 381 382 // int32 runtime·closeonexec(int32 fd); 383 TEXT runtime·closeonexec(SB),NOSPLIT,$32 384 MOVL $92, AX // fcntl 385 // 0(SP) is where the caller PC would be; kernel skips it 386 MOVL fd+0(FP), BX 387 MOVL BX, 4(SP) // fd 388 MOVL $2, 8(SP) // F_SETFD 389 MOVL $1, 12(SP) // FD_CLOEXEC 390 INT $0x80 391 JAE 2(PC) 392 NEGL AX 393 RET 394 395 GLOBL runtime·tlsoffset(SB),NOPTR,$4