Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 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, Darwin |
| 6 | // See http://fxr.watson.org/fxr/source/bsd/kern/syscalls.c?v=xnu-1228 |
| 7 | // or /usr/include/sys/syscall.h (on a Mac) for system call numbers. |
| 8 | |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 9 | #include "386/asm.h" |
| 10 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 11 | TEXT runtime·notok(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 12 | MOVL $0xf1, 0xf1 |
| 13 | RET |
| 14 | |
| 15 | // Exit the entire program (like C exit) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 16 | TEXT runtime·exit(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 17 | MOVL $1, AX |
| 18 | INT $0x80 |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 19 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 20 | RET |
| 21 | |
| 22 | // Exit this OS thread (like pthread_exit, which eventually |
| 23 | // calls __bsdthread_terminate). |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 24 | TEXT runtime·exit1(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 25 | MOVL $361, AX |
| 26 | INT $0x80 |
| 27 | JAE 2(PC) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 28 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 29 | RET |
| 30 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 31 | TEXT runtime·write(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 32 | MOVL $4, AX |
| 33 | INT $0x80 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 34 | RET |
| 35 | |
Russ Cox | 8698bb6 | 2011-04-25 16:58:00 -0400 | [diff] [blame^] | 36 | TEXT runtime·raisesigpipe(SB),7,$8 |
| 37 | get_tls(CX) |
| 38 | MOVL m(CX), DX |
| 39 | MOVL m_procid(DX), DX |
| 40 | MOVL DX, 0(SP) // thread_port |
| 41 | MOVL $13, 4(SP) // signal: SIGPIPE |
| 42 | MOVL $328, AX // __pthread_kill |
| 43 | INT $0x80 |
| 44 | RET |
| 45 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 46 | TEXT runtime·mmap(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 47 | MOVL $197, AX |
| 48 | INT $0x80 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 49 | RET |
| 50 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 51 | TEXT runtime·munmap(SB),7,$0 |
Russ Cox | d4cc557 | 2010-09-07 09:57:22 -0400 | [diff] [blame] | 52 | MOVL $73, AX |
| 53 | INT $0x80 |
| 54 | JAE 2(PC) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 55 | CALL runtime·notok(SB) |
Russ Cox | d4cc557 | 2010-09-07 09:57:22 -0400 | [diff] [blame] | 56 | RET |
| 57 | |
Russ Cox | 8dee872 | 2011-03-23 11:31:42 -0400 | [diff] [blame] | 58 | TEXT runtime·setitimer(SB),7,$0 |
| 59 | MOVL $83, AX |
| 60 | INT $0x80 |
| 61 | RET |
| 62 | |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 63 | // void gettime(int64 *sec, int32 *usec) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 64 | TEXT runtime·gettime(SB), 7, $32 |
Russ Cox | e4f0681 | 2010-02-08 14:32:22 -0800 | [diff] [blame] | 65 | LEAL 12(SP), AX // must be non-nil, unused |
| 66 | MOVL AX, 4(SP) |
| 67 | MOVL $0, 8(SP) // time zone pointer |
| 68 | MOVL $116, AX |
| 69 | INT $0x80 |
| 70 | |
| 71 | MOVL sec+0(FP), DI |
| 72 | MOVL AX, (DI) |
| 73 | MOVL $0, 4(DI) // zero extend 32 -> 64 |
| 74 | |
| 75 | MOVL usec+4(FP), DI |
| 76 | MOVL DX, (DI) |
| 77 | RET |
| 78 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 79 | TEXT runtime·sigaction(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 80 | MOVL $46, AX |
| 81 | INT $0x80 |
| 82 | JAE 2(PC) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 83 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 84 | RET |
| 85 | |
| 86 | // Sigtramp's job is to call the actual signal handler. |
| 87 | // It is called with the following arguments on the stack: |
| 88 | // 0(FP) "return address" - ignored |
| 89 | // 4(FP) actual handler |
| 90 | // 8(FP) siginfo style - ignored |
| 91 | // 12(FP) signal number |
| 92 | // 16(FP) siginfo |
| 93 | // 20(FP) context |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 94 | TEXT runtime·sigtramp(SB),7,$40 |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 95 | get_tls(CX) |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 96 | |
| 97 | // save g |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 98 | MOVL g(CX), DI |
| 99 | MOVL DI, 20(SP) |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 100 | |
| 101 | // g = m->gsignal |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 102 | MOVL m(CX), BP |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 103 | MOVL m_gsignal(BP), BP |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 104 | MOVL BP, g(CX) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 105 | |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 106 | // copy arguments to sighandler |
| 107 | MOVL sig+8(FP), BX |
| 108 | MOVL BX, 0(SP) |
| 109 | MOVL info+12(FP), BX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 110 | MOVL BX, 4(SP) |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 111 | MOVL context+16(FP), BX |
| 112 | MOVL BX, 8(SP) |
| 113 | MOVL DI, 12(SP) |
| 114 | |
| 115 | MOVL handler+0(FP), BX |
| 116 | CALL BX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 117 | |
Russ Cox | 53a529a | 2010-06-12 10:48:04 -0700 | [diff] [blame] | 118 | // restore g |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 119 | get_tls(CX) |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 120 | MOVL 20(SP), DI |
| 121 | MOVL DI, g(CX) |
Russ Cox | 597b2a9 | 2009-11-16 17:51:47 -0800 | [diff] [blame] | 122 | |
Russ Cox | 690291a | 2011-02-23 14:47:42 -0500 | [diff] [blame] | 123 | // call sigreturn |
Russ Cox | 597b2a9 | 2009-11-16 17:51:47 -0800 | [diff] [blame] | 124 | MOVL context+16(FP), CX |
| 125 | MOVL style+4(FP), BX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 126 | MOVL $0, 0(SP) // "caller PC" - ignored |
| 127 | MOVL CX, 4(SP) |
| 128 | MOVL BX, 8(SP) |
| 129 | MOVL $184, AX // sigreturn(ucontext, infostyle) |
| 130 | INT $0x80 |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 131 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 132 | RET |
| 133 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 134 | TEXT runtime·sigaltstack(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 135 | MOVL $53, AX |
| 136 | INT $0x80 |
| 137 | JAE 2(PC) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 138 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 139 | RET |
| 140 | |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 141 | // void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void)) |
| 142 | // System call args are: func arg stack pthread flags. |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 143 | TEXT runtime·bsdthread_create(SB),7,$32 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 144 | MOVL $360, AX |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 145 | // 0(SP) is where the caller PC would be; kernel skips it |
| 146 | MOVL func+12(FP), BX |
| 147 | MOVL BX, 4(SP) // func |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 148 | MOVL mm+4(FP), BX |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 149 | MOVL BX, 8(SP) // arg |
| 150 | MOVL stk+0(FP), BX |
| 151 | MOVL BX, 12(SP) // stack |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 152 | MOVL gg+8(FP), BX |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 153 | MOVL BX, 16(SP) // pthread |
| 154 | MOVL $0x1000000, 20(SP) // flags = PTHREAD_START_CUSTOM |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 155 | INT $0x80 |
Russ Cox | 718da33 | 2010-04-28 19:36:42 -0700 | [diff] [blame] | 156 | JAE 3(PC) |
Russ Cox | 4608feb | 2011-01-28 15:03:26 -0500 | [diff] [blame] | 157 | NEGL AX |
Russ Cox | 718da33 | 2010-04-28 19:36:42 -0700 | [diff] [blame] | 158 | RET |
| 159 | MOVL $0, AX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 160 | RET |
| 161 | |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 162 | // The thread that bsdthread_create creates starts executing here, |
| 163 | // because we registered this function using bsdthread_register |
| 164 | // at startup. |
| 165 | // AX = "pthread" (= g) |
| 166 | // BX = mach thread port |
| 167 | // CX = "func" (= fn) |
| 168 | // DX = "arg" (= m) |
| 169 | // DI = stack top |
| 170 | // SI = flags (= 0x1000000) |
| 171 | // SP = stack - C_32_STK_ALIGN |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 172 | TEXT runtime·bsdthread_start(SB),7,$0 |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 173 | // set up ldt 7+id to point at m->tls. |
| 174 | // m->tls is at m+40. newosproc left |
| 175 | // the m->id in tls[0]. |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 176 | LEAL m_tls(DX), BP |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 177 | MOVL 0(BP), DI |
| 178 | ADDL $7, DI // m0 is LDT#7. count up. |
| 179 | // setldt(tls#, &tls, sizeof tls) |
| 180 | PUSHAL // save registers |
| 181 | PUSHL $32 // sizeof tls |
| 182 | PUSHL BP // &tls |
| 183 | PUSHL DI // tls # |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 184 | CALL runtime·setldt(SB) |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 185 | POPL AX |
| 186 | POPL AX |
| 187 | POPL AX |
| 188 | POPAL |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 189 | |
| 190 | // Now segment is established. Initialize m, g. |
Hector Chu | 6bfe5f5 | 2010-01-06 17:58:55 -0800 | [diff] [blame] | 191 | get_tls(BP) |
| 192 | MOVL AX, g(BP) |
| 193 | MOVL DX, m(BP) |
Russ Cox | 8522a47 | 2009-06-17 15:15:55 -0700 | [diff] [blame] | 194 | MOVL BX, m_procid(DX) // m->procid = thread port (for debuggers) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 195 | CALL runtime·stackcheck(SB) // smashes AX |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 196 | CALL CX // fn() |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 197 | CALL runtime·exit1(SB) |
Russ Cox | 6b07021 | 2009-04-02 16:48:06 -0700 | [diff] [blame] | 198 | RET |
| 199 | |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 200 | // void bsdthread_register(void) |
| 201 | // registers callbacks for threadstart (see bsdthread_create above |
| 202 | // and wqthread and pthsize (not used). returns 0 on success. |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 203 | TEXT runtime·bsdthread_register(SB),7,$40 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 204 | MOVL $366, AX |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 205 | // 0(SP) is where kernel expects caller PC; ignored |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 206 | MOVL $runtime·bsdthread_start(SB), 4(SP) // threadstart |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 207 | MOVL $0, 8(SP) // wqthread, not used by us |
| 208 | MOVL $0, 12(SP) // pthsize, not used by us |
Russ Cox | 2f0cae4 | 2010-04-08 13:24:37 -0700 | [diff] [blame] | 209 | MOVL $0, 16(SP) // dummy_value [sic] |
| 210 | MOVL $0, 20(SP) // targetconc_ptr |
| 211 | MOVL $0, 24(SP) // dispatchqueue_offset |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 212 | INT $0x80 |
| 213 | JAE 2(PC) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 214 | CALL runtime·notok(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 215 | RET |
| 216 | |
| 217 | // Invoke Mach system call. |
| 218 | // Assumes system call number in AX, |
| 219 | // caller PC on stack, caller's caller PC next, |
| 220 | // and then the system call arguments. |
| 221 | // |
| 222 | // Can be used for BSD too, but we don't, |
| 223 | // because if you use this interface the BSD |
| 224 | // system call numbers need an extra field |
| 225 | // in the high 16 bits that seems to be the |
| 226 | // argument count in bytes but is not always. |
| 227 | // INT $0x80 works fine for those. |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 228 | TEXT runtime·sysenter(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 229 | POPL DX |
| 230 | MOVL SP, CX |
| 231 | BYTE $0x0F; BYTE $0x34; // SYSENTER |
| 232 | // returns to DX with SP set to CX |
| 233 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 234 | TEXT runtime·mach_msg_trap(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 235 | MOVL $-31, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 236 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 237 | RET |
| 238 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 239 | TEXT runtime·mach_reply_port(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 240 | MOVL $-26, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 241 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 242 | RET |
| 243 | |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 244 | TEXT runtime·mach_task_self(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 245 | MOVL $-28, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 246 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 247 | RET |
| 248 | |
| 249 | // Mach provides trap versions of the semaphore ops, |
| 250 | // instead of requiring the use of RPC. |
| 251 | |
| 252 | // uint32 mach_semaphore_wait(uint32) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 253 | TEXT runtime·mach_semaphore_wait(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 254 | MOVL $-36, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 255 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 256 | RET |
| 257 | |
| 258 | // uint32 mach_semaphore_timedwait(uint32, uint32, uint32) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 259 | TEXT runtime·mach_semaphore_timedwait(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 260 | MOVL $-38, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 261 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 262 | RET |
| 263 | |
| 264 | // uint32 mach_semaphore_signal(uint32) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 265 | TEXT runtime·mach_semaphore_signal(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 266 | MOVL $-33, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 267 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 268 | RET |
| 269 | |
| 270 | // uint32 mach_semaphore_signal_all(uint32) |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 271 | TEXT runtime·mach_semaphore_signal_all(SB),7,$0 |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 272 | MOVL $-34, AX |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 273 | CALL runtime·sysenter(SB) |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 274 | RET |
| 275 | |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 276 | // setldt(int entry, int address, int limit) |
Russ Cox | 2f0cae4 | 2010-04-08 13:24:37 -0700 | [diff] [blame] | 277 | // entry and limit are ignored. |
Russ Cox | 68b4255 | 2010-11-04 14:00:19 -0400 | [diff] [blame] | 278 | TEXT runtime·setldt(SB),7,$32 |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 279 | MOVL address+4(FP), BX // aka base |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 280 | |
| 281 | /* |
| 282 | * When linking against the system libraries, |
| 283 | * we use its pthread_create and let it set up %gs |
| 284 | * for us. When we do that, the private storage |
| 285 | * we get is not at 0(GS) but at 0x468(GS). |
| 286 | * To insulate the rest of the tool chain from this ugliness, |
| 287 | * 8l rewrites 0(GS) into 0x468(GS) for us. |
| 288 | * To accommodate that rewrite, we translate the |
| 289 | * address and limit here so that 0x468(GS) maps to 0(address). |
| 290 | * |
| 291 | * See ../../../../libcgo/darwin_386.c for the derivation |
| 292 | * of the constant. |
| 293 | */ |
| 294 | SUBL $0x468, BX |
Russ Cox | 133a158 | 2009-10-03 10:37:12 -0700 | [diff] [blame] | 295 | |
Russ Cox | 2f0cae4 | 2010-04-08 13:24:37 -0700 | [diff] [blame] | 296 | /* |
| 297 | * Must set up as USER_CTHREAD segment because |
| 298 | * Darwin forces that value into %gs for signal handlers, |
| 299 | * and if we don't set one up, we'll get a recursive |
| 300 | * fault trying to get into the signal handler. |
| 301 | * Since we have to set one up anyway, it might as |
| 302 | * well be the value we want. So don't bother with |
| 303 | * i386_set_ldt. |
| 304 | */ |
| 305 | MOVL BX, 4(SP) |
| 306 | MOVL $3, AX // thread_fast_set_cthread_self - machdep call #3 |
| 307 | INT $0x82 // sic: 0x82, not 0x80, for machdep call |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 308 | |
Russ Cox | 2f0cae4 | 2010-04-08 13:24:37 -0700 | [diff] [blame] | 309 | XORL AX, AX |
| 310 | MOVW GS, AX |
Russ Cox | 4702c0e | 2009-03-31 15:45:12 -0700 | [diff] [blame] | 311 | RET |