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__)
24 runtime_atoi(const byte
*p
, intgo len
)
29 while(len
> 0 && '0' <= *p
&& *p
<= '9') {
30 n
= n
*10 + *p
++ - '0';
36 #if defined(__i386__) || defined(__x86_64__) || defined (__s390__) || defined (__s390x__)
38 // When cputicks is just asm instructions, skip the split stack
39 // prologue for speed.
41 int64
runtime_cputicks(void) __attribute__((no_split_stack
));
45 // Whether the processor supports SSE2.
46 #if defined (__i386__)
49 // Force appropriate CPU level so that we can call the lfence/mfence
52 #pragma GCC push_options
53 #pragma GCC target("sse2")
55 #elif defined(__x86_64__)
59 #if defined(__i386__) || defined(__x86_64__)
60 // Whether to use lfence, as opposed to mfence.
61 // Set based on cpuid.
62 static _Bool lfenceBeforeRdtsc
;
63 #endif // defined(__i386__) || defined(__x86_64__)
66 runtime_cputicks(void)
68 #if defined(__i386__) || defined(__x86_64__)
70 if (lfenceBeforeRdtsc
) {
71 __builtin_ia32_lfence();
73 __builtin_ia32_mfence();
76 return __builtin_ia32_rdtsc();
77 #elif defined (__s390__) || defined (__s390x__)
79 /* stckf may not write the return variable in case of a clock error, so make
80 it read-write to prevent that the initialisation is optimised out.
81 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
82 we don't support Go for machines older than that. */
83 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
86 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
87 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
88 // TODO: need more entropy to better seed fastrand.
89 return runtime_nanotime();
94 #pragma GCC pop_options
98 runtime_signalstack(byte
*p
, uintptr n
)
106 st
.ss_flags
= SS_DISABLE
;
107 if(sigaltstack(&st
, nil
) < 0)
111 int32
go_open(char *, int32
, int32
)
112 __asm__ (GOSYM_PREFIX
"runtime.open");
115 go_open(char *name
, int32 mode
, int32 perm
)
117 return runtime_open(name
, mode
, perm
);
120 int32
go_read(int32
, void *, int32
)
121 __asm__ (GOSYM_PREFIX
"runtime.read");
124 go_read(int32 fd
, void *p
, int32 n
)
126 return runtime_read(fd
, p
, n
);
129 int32
go_write(uintptr
, void *, int32
)
130 __asm__ (GOSYM_PREFIX
"runtime.write");
133 go_write(uintptr fd
, void *p
, int32 n
)
135 return runtime_write(fd
, p
, n
);
138 int32
go_closefd(int32
)
139 __asm__ (GOSYM_PREFIX
"runtime.closefd");
144 return runtime_close(fd
);
148 __asm__ (GOSYM_PREFIX
"runtime.errno");
157 __asm__ (GOSYM_PREFIX
"runtime.getEnd");
163 // mmap adresses range start at 0x30000000 on AIX for 32 bits processes
164 uintptr end
= 0x30000000U
;
178 // CPU-specific initialization.
179 // Fetch CPUID info on x86.
184 #if defined(__i386__) || defined(__x86_64__)
185 unsigned int eax
, ebx
, ecx
, edx
;
187 if (__get_cpuid(0, &eax
, &ebx
, &ecx
, &edx
)) {
189 && ebx
== 0x756E6547 // "Genu"
190 && edx
== 0x49656E69 // "ineI"
191 && ecx
== 0x6C65746E) { // "ntel"
192 lfenceBeforeRdtsc
= true;
195 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {
197 #if defined(__i386__)
198 if ((edx
& bit_SSE2
) != 0) {
204 #if defined(HAVE_AS_X86_AES)
210 // A publication barrier: a store/store barrier.
212 void publicationBarrier(void)
213 __asm__ (GOSYM_PREFIX
"runtime.publicationBarrier");
218 __atomic_thread_fence(__ATOMIC_RELEASE
);
223 /* Currently sbrk0 is only called on GNU/Linux. */
226 __asm__ (GOSYM_PREFIX
"runtime.sbrk0");
231 return syscall(SYS_brk
, (uintptr
)(0));
234 #endif /* __linux__ */