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
{
32 extern struct gotraceback_ret
gotraceback(void)
33 __asm__ (GOSYM_PREFIX
"runtime.gotraceback");
35 // runtime_gotraceback is the C interface to runtime.gotraceback.
37 runtime_gotraceback(bool *crash
)
39 struct gotraceback_ret r
;
48 runtime_atoi(const byte
*p
, intgo len
)
53 while(len
> 0 && '0' <= *p
&& *p
<= '9') {
54 n
= n
*10 + *p
++ - '0';
61 runtime_fastrand(void)
76 runtime_cputicks(void)
78 #if defined(__386__) || defined(__x86_64__)
80 asm("rdtsc" : "=a" (low
), "=d" (high
));
81 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
82 #elif defined (__s390__) || defined (__s390x__)
84 /* stckf may not write the return variable in case of a clock error, so make
85 it read-write to prevent that the initialisation is optimised out.
86 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
87 we don't support Go for machines older than that. */
88 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
91 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
92 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
93 // TODO: need more entropy to better seed fastrand.
94 return runtime_nanotime();
99 runtime_signalstack(byte
*p
, uintptr n
)
107 st
.ss_flags
= SS_DISABLE
;
108 if(sigaltstack(&st
, nil
) < 0)
112 struct debugVars runtime_debug
;
115 runtime_setdebug(struct debugVars
* d
) {
119 void memclrBytes(Slice
)
120 __asm__ (GOSYM_PREFIX
"runtime.memclrBytes");
125 runtime_memclr(s
.__values
, s
.__count
);
128 int32
go_open(char *, int32
, int32
)
129 __asm__ (GOSYM_PREFIX
"runtime.open");
132 go_open(char *name
, int32 mode
, int32 perm
)
134 return runtime_open(name
, mode
, perm
);
137 int32
go_read(int32
, void *, int32
)
138 __asm__ (GOSYM_PREFIX
"runtime.read");
141 go_read(int32 fd
, void *p
, int32 n
)
143 return runtime_read(fd
, p
, n
);
146 int32
go_write(uintptr
, void *, int32
)
147 __asm__ (GOSYM_PREFIX
"runtime.write");
150 go_write(uintptr fd
, void *p
, int32 n
)
152 return runtime_write(fd
, p
, n
);
155 int32
go_closefd(int32
)
156 __asm__ (GOSYM_PREFIX
"runtime.closefd");
161 return runtime_close(fd
);
165 __asm__ (GOSYM_PREFIX
"runtime.errno");
173 // CPU-specific initialization.
174 // Fetch CPUID info on x86.
179 #if defined(__i386__) || defined(__x86_64__)
180 unsigned int eax
, ebx
, ecx
, edx
;
182 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {
186 #if defined(HAVE_AS_X86_AES)