github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/runtime/sys_linux_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 // 6 // System calls and other sys.stuff for 386, Linux 7 // 8 9 #include "go_asm.h" 10 #include "go_tls.h" 11 #include "textflag.h" 12 13 // Most linux systems use glibc's dynamic linker, which puts the 14 // __kernel_vsyscall vdso helper at 0x10(GS) for easy access from position 15 // independent code and setldt in runtime does the same in the statically 16 // linked case. However, systems that use alternative libc such as Android's 17 // bionic and musl, do not save the helper anywhere, and so the only way to 18 // invoke a syscall from position independent code is boring old int $0x80 19 // (which is also what syscall wrappers in bionic/musl use). 20 // 21 // The benchmarks also showed that using int $0x80 is as fast as calling 22 // *%gs:0x10 except on AMD Opteron. See https://golang.org/cl/19833 23 // for the benchmark program and raw data. 24 //#define INVOKE_SYSCALL CALL 0x10(GS) // non-portable 25 #define INVOKE_SYSCALL INT $0x80 26 27 #define SYS_exit 1 28 #define SYS_read 3 29 #define SYS_write 4 30 #define SYS_open 5 31 #define SYS_close 6 32 #define SYS_getpid 20 33 #define SYS_access 33 34 #define SYS_kill 37 35 #define SYS_brk 45 36 #define SYS_munmap 91 37 #define SYS_socketcall 102 38 #define SYS_setittimer 104 39 #define SYS_clone 120 40 #define SYS_sched_yield 158 41 #define SYS_nanosleep 162 42 #define SYS_rt_sigreturn 173 43 #define SYS_rt_sigaction 174 44 #define SYS_rt_sigprocmask 175 45 #define SYS_sigaltstack 186 46 #define SYS_mmap2 192 47 #define SYS_mincore 218 48 #define SYS_madvise 219 49 #define SYS_gettid 224 50 #define SYS_futex 240 51 #define SYS_sched_getaffinity 242 52 #define SYS_set_thread_area 243 53 #define SYS_exit_group 252 54 #define SYS_timer_create 259 55 #define SYS_timer_settime 260 56 #define SYS_timer_delete 263 57 #define SYS_clock_gettime 265 58 #define SYS_tgkill 270 59 #define SYS_pipe2 331 60 61 TEXT runtime·exit(SB),NOSPLIT,$0 62 MOVL $SYS_exit_group, AX 63 MOVL code+0(FP), BX 64 INVOKE_SYSCALL 65 INT $3 // not reached 66 RET 67 68 TEXT exit1<>(SB),NOSPLIT,$0 69 MOVL $SYS_exit, AX 70 MOVL code+0(FP), BX 71 INVOKE_SYSCALL 72 INT $3 // not reached 73 RET 74 75 // func exitThread(wait *atomic.Uint32) 76 TEXT runtime·exitThread(SB),NOSPLIT,$0-4 77 MOVL wait+0(FP), AX 78 // We're done using the stack. 79 MOVL $0, (AX) 80 MOVL $1, AX // exit (just this thread) 81 MOVL $0, BX // exit code 82 INT $0x80 // no stack; must not use CALL 83 // We may not even have a stack any more. 84 INT $3 85 JMP 0(PC) 86 87 TEXT runtime·open(SB),NOSPLIT,$0 88 MOVL $SYS_open, AX 89 MOVL name+0(FP), BX 90 MOVL mode+4(FP), CX 91 MOVL perm+8(FP), DX 92 INVOKE_SYSCALL 93 CMPL AX, $0xfffff001 94 JLS 2(PC) 95 MOVL $-1, AX 96 MOVL AX, ret+12(FP) 97 RET 98 99 TEXT runtime·closefd(SB),NOSPLIT,$0 100 MOVL $SYS_close, AX 101 MOVL fd+0(FP), BX 102 INVOKE_SYSCALL 103 CMPL AX, $0xfffff001 104 JLS 2(PC) 105 MOVL $-1, AX 106 MOVL AX, ret+4(FP) 107 RET 108 109 TEXT runtime·write1(SB),NOSPLIT,$0 110 MOVL $SYS_write, AX 111 MOVL fd+0(FP), BX 112 MOVL p+4(FP), CX 113 MOVL n+8(FP), DX 114 INVOKE_SYSCALL 115 MOVL AX, ret+12(FP) 116 RET 117 118 TEXT runtime·read(SB),NOSPLIT,$0 119 MOVL $SYS_read, AX 120 MOVL fd+0(FP), BX 121 MOVL p+4(FP), CX 122 MOVL n+8(FP), DX 123 INVOKE_SYSCALL 124 MOVL AX, ret+12(FP) 125 RET 126 127 // func pipe2(flags int32) (r, w int32, errno int32) 128 TEXT runtime·pipe2(SB),NOSPLIT,$0-16 129 MOVL $SYS_pipe2, AX 130 LEAL r+4(FP), BX 131 MOVL flags+0(FP), CX 132 INVOKE_SYSCALL 133 MOVL AX, errno+12(FP) 134 RET 135 136 TEXT runtime·usleep(SB),NOSPLIT,$8 137 MOVL $0, DX 138 MOVL usec+0(FP), AX 139 MOVL $1000000, CX 140 DIVL CX 141 MOVL AX, 0(SP) 142 MOVL $1000, AX // usec to nsec 143 MULL DX 144 MOVL AX, 4(SP) 145 146 // nanosleep(&ts, 0) 147 MOVL $SYS_nanosleep, AX 148 LEAL 0(SP), BX 149 MOVL $0, CX 150 INVOKE_SYSCALL 151 RET 152 153 TEXT runtime·gettid(SB),NOSPLIT,$0-4 154 MOVL $SYS_gettid, AX 155 INVOKE_SYSCALL 156 MOVL AX, ret+0(FP) 157 RET 158 159 TEXT runtime·raise(SB),NOSPLIT,$12 160 MOVL $SYS_getpid, AX 161 INVOKE_SYSCALL 162 MOVL AX, BX // arg 1 pid 163 MOVL $SYS_gettid, AX 164 INVOKE_SYSCALL 165 MOVL AX, CX // arg 2 tid 166 MOVL sig+0(FP), DX // arg 3 signal 167 MOVL $SYS_tgkill, AX 168 INVOKE_SYSCALL 169 RET 170 171 TEXT runtime·raiseproc(SB),NOSPLIT,$12 172 MOVL $SYS_getpid, AX 173 INVOKE_SYSCALL 174 MOVL AX, BX // arg 1 pid 175 MOVL sig+0(FP), CX // arg 2 signal 176 MOVL $SYS_kill, AX 177 INVOKE_SYSCALL 178 RET 179 180 TEXT ·getpid(SB),NOSPLIT,$0-4 181 MOVL $SYS_getpid, AX 182 INVOKE_SYSCALL 183 MOVL AX, ret+0(FP) 184 RET 185 186 TEXT ·tgkill(SB),NOSPLIT,$0 187 MOVL $SYS_tgkill, AX 188 MOVL tgid+0(FP), BX 189 MOVL tid+4(FP), CX 190 MOVL sig+8(FP), DX 191 INVOKE_SYSCALL 192 RET 193 194 TEXT runtime·setitimer(SB),NOSPLIT,$0-12 195 MOVL $SYS_setittimer, AX 196 MOVL mode+0(FP), BX 197 MOVL new+4(FP), CX 198 MOVL old+8(FP), DX 199 INVOKE_SYSCALL 200 RET 201 202 TEXT runtime·timer_create(SB),NOSPLIT,$0-16 203 MOVL $SYS_timer_create, AX 204 MOVL clockid+0(FP), BX 205 MOVL sevp+4(FP), CX 206 MOVL timerid+8(FP), DX 207 INVOKE_SYSCALL 208 MOVL AX, ret+12(FP) 209 RET 210 211 TEXT runtime·timer_settime(SB),NOSPLIT,$0-20 212 MOVL $SYS_timer_settime, AX 213 MOVL timerid+0(FP), BX 214 MOVL flags+4(FP), CX 215 MOVL new+8(FP), DX 216 MOVL old+12(FP), SI 217 INVOKE_SYSCALL 218 MOVL AX, ret+16(FP) 219 RET 220 221 TEXT runtime·timer_delete(SB),NOSPLIT,$0-8 222 MOVL $SYS_timer_delete, AX 223 MOVL timerid+0(FP), BX 224 INVOKE_SYSCALL 225 MOVL AX, ret+4(FP) 226 RET 227 228 TEXT runtime·mincore(SB),NOSPLIT,$0-16 229 MOVL $SYS_mincore, AX 230 MOVL addr+0(FP), BX 231 MOVL n+4(FP), CX 232 MOVL dst+8(FP), DX 233 INVOKE_SYSCALL 234 MOVL AX, ret+12(FP) 235 RET 236 237 // func walltime() (sec int64, nsec int32) 238 TEXT runtime·walltime(SB), NOSPLIT, $8-12 239 // We don't know how much stack space the VDSO code will need, 240 // so switch to g0. 241 242 MOVL SP, BP // Save old SP; BP unchanged by C code. 243 244 get_tls(CX) 245 MOVL g(CX), AX 246 MOVL g_m(AX), SI // SI unchanged by C code. 247 248 // Set vdsoPC and vdsoSP for SIGPROF traceback. 249 // Save the old values on stack and restore them on exit, 250 // so this function is reentrant. 251 MOVL m_vdsoPC(SI), CX 252 MOVL m_vdsoSP(SI), DX 253 MOVL CX, 0(SP) 254 MOVL DX, 4(SP) 255 256 LEAL sec+0(FP), DX 257 MOVL -4(DX), CX 258 MOVL CX, m_vdsoPC(SI) 259 MOVL DX, m_vdsoSP(SI) 260 261 CMPL AX, m_curg(SI) // Only switch if on curg. 262 JNE noswitch 263 264 MOVL m_g0(SI), DX 265 MOVL (g_sched+gobuf_sp)(DX), SP // Set SP to g0 stack 266 267 noswitch: 268 SUBL $16, SP // Space for results 269 ANDL $~15, SP // Align for C code 270 271 // Stack layout, depending on call path: 272 // x(SP) vDSO INVOKE_SYSCALL 273 // 12 ts.tv_nsec ts.tv_nsec 274 // 8 ts.tv_sec ts.tv_sec 275 // 4 &ts - 276 // 0 CLOCK_<id> - 277 278 MOVL runtime·vdsoClockgettimeSym(SB), AX 279 CMPL AX, $0 280 JEQ fallback 281 282 LEAL 8(SP), BX // &ts (struct timespec) 283 MOVL BX, 4(SP) 284 MOVL $0, 0(SP) // CLOCK_REALTIME 285 CALL AX 286 JMP finish 287 288 fallback: 289 MOVL $SYS_clock_gettime, AX 290 MOVL $0, BX // CLOCK_REALTIME 291 LEAL 8(SP), CX 292 INVOKE_SYSCALL 293 294 finish: 295 MOVL 8(SP), AX // sec 296 MOVL 12(SP), BX // nsec 297 298 MOVL BP, SP // Restore real SP 299 // Restore vdsoPC, vdsoSP 300 // We don't worry about being signaled between the two stores. 301 // If we are not in a signal handler, we'll restore vdsoSP to 0, 302 // and no one will care about vdsoPC. If we are in a signal handler, 303 // we cannot receive another signal. 304 MOVL 4(SP), CX 305 MOVL CX, m_vdsoSP(SI) 306 MOVL 0(SP), CX 307 MOVL CX, m_vdsoPC(SI) 308 309 // sec is in AX, nsec in BX 310 MOVL AX, sec_lo+0(FP) 311 MOVL $0, sec_hi+4(FP) 312 MOVL BX, nsec+8(FP) 313 RET 314 315 // int64 nanotime(void) so really 316 // void nanotime(int64 *nsec) 317 TEXT runtime·nanotime1(SB), NOSPLIT, $8-8 318 // Switch to g0 stack. See comment above in runtime·walltime. 319 320 MOVL SP, BP // Save old SP; BP unchanged by C code. 321 322 get_tls(CX) 323 MOVL g(CX), AX 324 MOVL g_m(AX), SI // SI unchanged by C code. 325 326 // Set vdsoPC and vdsoSP for SIGPROF traceback. 327 // Save the old values on stack and restore them on exit, 328 // so this function is reentrant. 329 MOVL m_vdsoPC(SI), CX 330 MOVL m_vdsoSP(SI), DX 331 MOVL CX, 0(SP) 332 MOVL DX, 4(SP) 333 334 LEAL ret+0(FP), DX 335 MOVL -4(DX), CX 336 MOVL CX, m_vdsoPC(SI) 337 MOVL DX, m_vdsoSP(SI) 338 339 CMPL AX, m_curg(SI) // Only switch if on curg. 340 JNE noswitch 341 342 MOVL m_g0(SI), DX 343 MOVL (g_sched+gobuf_sp)(DX), SP // Set SP to g0 stack 344 345 noswitch: 346 SUBL $16, SP // Space for results 347 ANDL $~15, SP // Align for C code 348 349 MOVL runtime·vdsoClockgettimeSym(SB), AX 350 CMPL AX, $0 351 JEQ fallback 352 353 LEAL 8(SP), BX // &ts (struct timespec) 354 MOVL BX, 4(SP) 355 MOVL $1, 0(SP) // CLOCK_MONOTONIC 356 CALL AX 357 JMP finish 358 359 fallback: 360 MOVL $SYS_clock_gettime, AX 361 MOVL $1, BX // CLOCK_MONOTONIC 362 LEAL 8(SP), CX 363 INVOKE_SYSCALL 364 365 finish: 366 MOVL 8(SP), AX // sec 367 MOVL 12(SP), BX // nsec 368 369 MOVL BP, SP // Restore real SP 370 // Restore vdsoPC, vdsoSP 371 // We don't worry about being signaled between the two stores. 372 // If we are not in a signal handler, we'll restore vdsoSP to 0, 373 // and no one will care about vdsoPC. If we are in a signal handler, 374 // we cannot receive another signal. 375 MOVL 4(SP), CX 376 MOVL CX, m_vdsoSP(SI) 377 MOVL 0(SP), CX 378 MOVL CX, m_vdsoPC(SI) 379 380 // sec is in AX, nsec in BX 381 // convert to DX:AX nsec 382 MOVL $1000000000, CX 383 MULL CX 384 ADDL BX, AX 385 ADCL $0, DX 386 387 MOVL AX, ret_lo+0(FP) 388 MOVL DX, ret_hi+4(FP) 389 RET 390 391 TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0 392 MOVL $SYS_rt_sigprocmask, AX 393 MOVL how+0(FP), BX 394 MOVL new+4(FP), CX 395 MOVL old+8(FP), DX 396 MOVL size+12(FP), SI 397 INVOKE_SYSCALL 398 CMPL AX, $0xfffff001 399 JLS 2(PC) 400 INT $3 401 RET 402 403 TEXT runtime·rt_sigaction(SB),NOSPLIT,$0 404 MOVL $SYS_rt_sigaction, AX 405 MOVL sig+0(FP), BX 406 MOVL new+4(FP), CX 407 MOVL old+8(FP), DX 408 MOVL size+12(FP), SI 409 INVOKE_SYSCALL 410 MOVL AX, ret+16(FP) 411 RET 412 413 TEXT runtime·sigfwd(SB),NOSPLIT,$12-16 414 MOVL fn+0(FP), AX 415 MOVL sig+4(FP), BX 416 MOVL info+8(FP), CX 417 MOVL ctx+12(FP), DX 418 MOVL SP, SI 419 SUBL $32, SP 420 ANDL $-15, SP // align stack: handler might be a C function 421 MOVL BX, 0(SP) 422 MOVL CX, 4(SP) 423 MOVL DX, 8(SP) 424 MOVL SI, 12(SP) // save SI: handler might be a Go function 425 CALL AX 426 MOVL 12(SP), AX 427 MOVL AX, SP 428 RET 429 430 // Called using C ABI. 431 TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$28 432 // Save callee-saved C registers, since the caller may be a C signal handler. 433 MOVL BX, bx-4(SP) 434 MOVL BP, bp-8(SP) 435 MOVL SI, si-12(SP) 436 MOVL DI, di-16(SP) 437 // We don't save mxcsr or the x87 control word because sigtrampgo doesn't 438 // modify them. 439 440 MOVL (28+4)(SP), BX 441 MOVL BX, 0(SP) 442 MOVL (28+8)(SP), BX 443 MOVL BX, 4(SP) 444 MOVL (28+12)(SP), BX 445 MOVL BX, 8(SP) 446 CALL runtime·sigtrampgo(SB) 447 448 MOVL di-16(SP), DI 449 MOVL si-12(SP), SI 450 MOVL bp-8(SP), BP 451 MOVL bx-4(SP), BX 452 RET 453 454 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 455 JMP runtime·sigtramp(SB) 456 457 TEXT runtime·sigreturn(SB),NOSPLIT,$0 458 MOVL $SYS_rt_sigreturn, AX 459 // Sigreturn expects same SP as signal handler, 460 // so cannot CALL 0x10(GS) here. 461 INT $0x80 462 INT $3 // not reached 463 RET 464 465 TEXT runtime·mmap(SB),NOSPLIT,$0 466 MOVL $SYS_mmap2, AX 467 MOVL addr+0(FP), BX 468 MOVL n+4(FP), CX 469 MOVL prot+8(FP), DX 470 MOVL flags+12(FP), SI 471 MOVL fd+16(FP), DI 472 MOVL off+20(FP), BP 473 SHRL $12, BP 474 INVOKE_SYSCALL 475 CMPL AX, $0xfffff001 476 JLS ok 477 NOTL AX 478 INCL AX 479 MOVL $0, p+24(FP) 480 MOVL AX, err+28(FP) 481 RET 482 ok: 483 MOVL AX, p+24(FP) 484 MOVL $0, err+28(FP) 485 RET 486 487 TEXT runtime·munmap(SB),NOSPLIT,$0 488 MOVL $SYS_munmap, AX 489 MOVL addr+0(FP), BX 490 MOVL n+4(FP), CX 491 INVOKE_SYSCALL 492 CMPL AX, $0xfffff001 493 JLS 2(PC) 494 INT $3 495 RET 496 497 TEXT runtime·madvise(SB),NOSPLIT,$0 498 MOVL $SYS_madvise, AX 499 MOVL addr+0(FP), BX 500 MOVL n+4(FP), CX 501 MOVL flags+8(FP), DX 502 INVOKE_SYSCALL 503 MOVL AX, ret+12(FP) 504 RET 505 506 // int32 futex(int32 *uaddr, int32 op, int32 val, 507 // struct timespec *timeout, int32 *uaddr2, int32 val2); 508 TEXT runtime·futex(SB),NOSPLIT,$0 509 MOVL $SYS_futex, AX 510 MOVL addr+0(FP), BX 511 MOVL op+4(FP), CX 512 MOVL val+8(FP), DX 513 MOVL ts+12(FP), SI 514 MOVL addr2+16(FP), DI 515 MOVL val3+20(FP), BP 516 INVOKE_SYSCALL 517 MOVL AX, ret+24(FP) 518 RET 519 520 // int32 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void)); 521 TEXT runtime·clone(SB),NOSPLIT,$0 522 MOVL $SYS_clone, AX 523 MOVL flags+0(FP), BX 524 MOVL stk+4(FP), CX 525 MOVL $0, DX // parent tid ptr 526 MOVL $0, DI // child tid ptr 527 528 // Copy mp, gp, fn off parent stack for use by child. 529 SUBL $16, CX 530 MOVL mp+8(FP), SI 531 MOVL SI, 0(CX) 532 MOVL gp+12(FP), SI 533 MOVL SI, 4(CX) 534 MOVL fn+16(FP), SI 535 MOVL SI, 8(CX) 536 MOVL $1234, 12(CX) 537 538 // cannot use CALL 0x10(GS) here, because the stack changes during the 539 // system call (after CALL 0x10(GS), the child is still using the 540 // parent's stack when executing its RET instruction). 541 INT $0x80 542 543 // In parent, return. 544 CMPL AX, $0 545 JEQ 3(PC) 546 MOVL AX, ret+20(FP) 547 RET 548 549 // Paranoia: check that SP is as we expect. 550 NOP SP // tell vet SP changed - stop checking offsets 551 MOVL 12(SP), BP 552 CMPL BP, $1234 553 JEQ 2(PC) 554 INT $3 555 556 // Initialize AX to Linux tid 557 MOVL $SYS_gettid, AX 558 INVOKE_SYSCALL 559 560 MOVL 0(SP), BX // m 561 MOVL 4(SP), DX // g 562 MOVL 8(SP), SI // fn 563 564 CMPL BX, $0 565 JEQ nog 566 CMPL DX, $0 567 JEQ nog 568 569 MOVL AX, m_procid(BX) // save tid as m->procid 570 571 // set up ldt 7+id to point at m->tls. 572 LEAL m_tls(BX), BP 573 MOVL m_id(BX), DI 574 ADDL $7, DI // m0 is LDT#7. count up. 575 // setldt(tls#, &tls, sizeof tls) 576 PUSHAL // save registers 577 PUSHL $32 // sizeof tls 578 PUSHL BP // &tls 579 PUSHL DI // tls # 580 CALL runtime·setldt(SB) 581 POPL AX 582 POPL AX 583 POPL AX 584 POPAL 585 586 // Now segment is established. Initialize m, g. 587 get_tls(AX) 588 MOVL DX, g(AX) 589 MOVL BX, g_m(DX) 590 591 CALL runtime·stackcheck(SB) // smashes AX, CX 592 MOVL 0(DX), DX // paranoia; check they are not nil 593 MOVL 0(BX), BX 594 595 // more paranoia; check that stack splitting code works 596 PUSHAL 597 CALL runtime·emptyfunc(SB) 598 POPAL 599 600 nog: 601 CALL SI // fn() 602 CALL exit1<>(SB) 603 MOVL $0x1234, 0x1005 604 605 TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 606 MOVL $SYS_sigaltstack, AX 607 MOVL new+0(FP), BX 608 MOVL old+4(FP), CX 609 INVOKE_SYSCALL 610 CMPL AX, $0xfffff001 611 JLS 2(PC) 612 INT $3 613 RET 614 615 // <asm-i386/ldt.h> 616 // struct user_desc { 617 // unsigned int entry_number; 618 // unsigned long base_addr; 619 // unsigned int limit; 620 // unsigned int seg_32bit:1; 621 // unsigned int contents:2; 622 // unsigned int read_exec_only:1; 623 // unsigned int limit_in_pages:1; 624 // unsigned int seg_not_present:1; 625 // unsigned int useable:1; 626 // }; 627 #define SEG_32BIT 0x01 628 // contents are the 2 bits 0x02 and 0x04. 629 #define CONTENTS_DATA 0x00 630 #define CONTENTS_STACK 0x02 631 #define CONTENTS_CODE 0x04 632 #define READ_EXEC_ONLY 0x08 633 #define LIMIT_IN_PAGES 0x10 634 #define SEG_NOT_PRESENT 0x20 635 #define USEABLE 0x40 636 637 // `-1` means the kernel will pick a TLS entry on the first setldt call, 638 // which happens during runtime init, and that we'll store back the saved 639 // entry and reuse that on subsequent calls when creating new threads. 640 DATA runtime·tls_entry_number+0(SB)/4, $-1 641 GLOBL runtime·tls_entry_number(SB), NOPTR, $4 642 643 // setldt(int entry, int address, int limit) 644 // We use set_thread_area, which mucks with the GDT, instead of modify_ldt, 645 // which would modify the LDT, but is disabled on some kernels. 646 // The name, setldt, is a misnomer, although we leave this name as it is for 647 // the compatibility with other platforms. 648 TEXT runtime·setldt(SB),NOSPLIT,$32 649 MOVL base+4(FP), DX 650 651 #ifdef GOOS_android 652 // Android stores the TLS offset in runtime·tls_g. 653 SUBL runtime·tls_g(SB), DX 654 MOVL DX, 0(DX) 655 #else 656 /* 657 * When linking against the system libraries, 658 * we use its pthread_create and let it set up %gs 659 * for us. When we do that, the private storage 660 * we get is not at 0(GS), but -4(GS). 661 * To insulate the rest of the tool chain from this 662 * ugliness, 8l rewrites 0(TLS) into -4(GS) for us. 663 * To accommodate that rewrite, we translate 664 * the address here and bump the limit to 0xffffffff (no limit) 665 * so that -4(GS) maps to 0(address). 666 * Also, the final 0(GS) (current 4(DX)) has to point 667 * to itself, to mimic ELF. 668 */ 669 ADDL $0x4, DX // address 670 MOVL DX, 0(DX) 671 #endif 672 673 // get entry number 674 MOVL runtime·tls_entry_number(SB), CX 675 676 // set up user_desc 677 LEAL 16(SP), AX // struct user_desc 678 MOVL CX, 0(AX) // unsigned int entry_number 679 MOVL DX, 4(AX) // unsigned long base_addr 680 MOVL $0xfffff, 8(AX) // unsigned int limit 681 MOVL $(SEG_32BIT|LIMIT_IN_PAGES|USEABLE|CONTENTS_DATA), 12(AX) // flag bits 682 683 // call set_thread_area 684 MOVL AX, BX // user_desc 685 MOVL $SYS_set_thread_area, AX 686 // We can't call this via 0x10(GS) because this is called from setldt0 to set that up. 687 INT $0x80 688 689 // breakpoint on error 690 CMPL AX, $0xfffff001 691 JLS 2(PC) 692 INT $3 693 694 // read allocated entry number back out of user_desc 695 LEAL 16(SP), AX // get our user_desc back 696 MOVL 0(AX), AX 697 698 // store entry number if the kernel allocated it 699 CMPL CX, $-1 700 JNE 2(PC) 701 MOVL AX, runtime·tls_entry_number(SB) 702 703 // compute segment selector - (entry*8+3) 704 SHLL $3, AX 705 ADDL $3, AX 706 MOVW AX, GS 707 708 RET 709 710 TEXT runtime·osyield(SB),NOSPLIT,$0 711 MOVL $SYS_sched_yield, AX 712 INVOKE_SYSCALL 713 RET 714 715 TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0 716 MOVL $SYS_sched_getaffinity, AX 717 MOVL pid+0(FP), BX 718 MOVL len+4(FP), CX 719 MOVL buf+8(FP), DX 720 INVOKE_SYSCALL 721 MOVL AX, ret+12(FP) 722 RET 723 724 // int access(const char *name, int mode) 725 TEXT runtime·access(SB),NOSPLIT,$0 726 MOVL $SYS_access, AX 727 MOVL name+0(FP), BX 728 MOVL mode+4(FP), CX 729 INVOKE_SYSCALL 730 MOVL AX, ret+8(FP) 731 RET 732 733 // int connect(int fd, const struct sockaddr *addr, socklen_t addrlen) 734 TEXT runtime·connect(SB),NOSPLIT,$0-16 735 // connect is implemented as socketcall(NR_socket, 3, *(rest of args)) 736 // stack already should have fd, addr, addrlen. 737 MOVL $SYS_socketcall, AX 738 MOVL $3, BX // connect 739 LEAL fd+0(FP), CX 740 INVOKE_SYSCALL 741 MOVL AX, ret+12(FP) 742 RET 743 744 // int socket(int domain, int type, int protocol) 745 TEXT runtime·socket(SB),NOSPLIT,$0-16 746 // socket is implemented as socketcall(NR_socket, 1, *(rest of args)) 747 // stack already should have domain, type, protocol. 748 MOVL $SYS_socketcall, AX 749 MOVL $1, BX // socket 750 LEAL domain+0(FP), CX 751 INVOKE_SYSCALL 752 MOVL AX, ret+12(FP) 753 RET 754 755 // func sbrk0() uintptr 756 TEXT runtime·sbrk0(SB),NOSPLIT,$0-4 757 // Implemented as brk(NULL). 758 MOVL $SYS_brk, AX 759 MOVL $0, BX // NULL 760 INVOKE_SYSCALL 761 MOVL AX, ret+0(FP) 762 RET