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.
9 #if defined(__i386__) || defined(__x86_64__)
20 maxround
= sizeof(uintptr
),
23 extern volatile intgo runtime_MemProfileRate
24 __asm__ (GOSYM_PREFIX
"runtime.MemProfileRate");
26 struct gotraceback_ret
{
31 extern struct gotraceback_ret
gotraceback(void)
32 __asm__ (GOSYM_PREFIX
"runtime.gotraceback");
34 // runtime_gotraceback is the C interface to runtime.gotraceback.
36 runtime_gotraceback(bool *crash
)
38 struct gotraceback_ret r
;
47 runtime_atoi(const byte
*p
, intgo len
)
52 while(len
> 0 && '0' <= *p
&& *p
<= '9') {
53 n
= n
*10 + *p
++ - '0';
60 runtime_fastrand1(void)
75 runtime_cputicks(void)
77 #if defined(__386__) || defined(__x86_64__)
79 asm("rdtsc" : "=a" (low
), "=d" (high
));
80 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
81 #elif defined (__s390__) || defined (__s390x__)
83 /* stckf may not write the return variable in case of a clock error, so make
84 it read-write to prevent that the initialisation is optimised out.
85 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
86 we don't support Go for machines older than that. */
87 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
90 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand1().
91 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
92 // TODO: need more entropy to better seed fastrand1.
93 return runtime_nanotime();
97 // Called to initialize a new m (including the bootstrap m).
98 // Called on the parent thread (main thread in case of bootstrap), can allocate memory.
100 runtime_mpreinit(M
*mp
)
102 int32 stacksize
= 32 * 1024; // OS X wants >=8K, Linux >=2K
105 if(stacksize
< SIGSTKSZ
)
106 stacksize
= SIGSTKSZ
;
109 mp
->gsignal
= runtime_malg(stacksize
, (byte
**)&mp
->gsignalstack
, &mp
->gsignalstacksize
);
113 // Called to initialize a new m (including the bootstrap m).
114 // Called on the new thread, can not allocate memory.
121 // Initialize signal handling.
123 runtime_signalstack(m
->gsignalstack
, m
->gsignalstacksize
);
124 if (sigemptyset(&sigs
) != 0)
125 runtime_throw("sigemptyset");
126 pthread_sigmask(SIG_SETMASK
, &sigs
, nil
);
129 // Called from dropm to undo the effect of an minit.
131 runtime_unminit(void)
133 runtime_signalstack(nil
, 0);
138 runtime_signalstack(byte
*p
, int32 n
)
146 st
.ss_flags
= SS_DISABLE
;
147 if(sigaltstack(&st
, nil
) < 0)
151 struct debugVars runtime_debug
;
154 runtime_setdebug(struct debugVars
* d
) {
158 void memclrBytes(Slice
)
159 __asm__ (GOSYM_PREFIX
"runtime.memclrBytes");
164 runtime_memclr(s
.__values
, s
.__count
);
167 int32
go_open(char *, int32
, int32
)
168 __asm__ (GOSYM_PREFIX
"runtime.open");
171 go_open(char *name
, int32 mode
, int32 perm
)
173 return runtime_open(name
, mode
, perm
);
176 int32
go_read(int32
, void *, int32
)
177 __asm__ (GOSYM_PREFIX
"runtime.read");
180 go_read(int32 fd
, void *p
, int32 n
)
182 return runtime_read(fd
, p
, n
);
185 int32
go_write(uintptr
, void *, int32
)
186 __asm__ (GOSYM_PREFIX
"runtime.write");
189 go_write(uintptr fd
, void *p
, int32 n
)
191 return runtime_write(fd
, p
, n
);
194 int32
go_closefd(int32
)
195 __asm__ (GOSYM_PREFIX
"runtime.closefd");
200 return runtime_close(fd
);
204 __asm__ (GOSYM_PREFIX
"runtime.errno");
212 // CPU-specific initialization.
213 // Fetch CPUID info on x86.
218 #if defined(__i386__) || defined(__x86_64__)
219 unsigned int eax
, ebx
, ecx
, edx
;
221 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {