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 runtime_atoi(const byte
*p
, intgo len
)
25 while(len
> 0 && '0' <= *p
&& *p
<= '9') {
26 n
= n
*10 + *p
++ - '0';
33 runtime_fastrand(void)
48 runtime_cputicks(void)
50 #if defined(__386__) || defined(__x86_64__)
52 asm("rdtsc" : "=a" (low
), "=d" (high
));
53 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
54 #elif defined (__s390__) || defined (__s390x__)
56 /* stckf may not write the return variable in case of a clock error, so make
57 it read-write to prevent that the initialisation is optimised out.
58 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
59 we don't support Go for machines older than that. */
60 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
63 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
64 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
65 // TODO: need more entropy to better seed fastrand.
66 return runtime_nanotime();
71 runtime_signalstack(byte
*p
, uintptr n
)
79 st
.ss_flags
= SS_DISABLE
;
80 if(sigaltstack(&st
, nil
) < 0)
84 struct debugVars runtime_debug
;
87 runtime_setdebug(struct debugVars
* d
) {
91 int32
go_open(char *, int32
, int32
)
92 __asm__ (GOSYM_PREFIX
"runtime.open");
95 go_open(char *name
, int32 mode
, int32 perm
)
97 return runtime_open(name
, mode
, perm
);
100 int32
go_read(int32
, void *, int32
)
101 __asm__ (GOSYM_PREFIX
"runtime.read");
104 go_read(int32 fd
, void *p
, int32 n
)
106 return runtime_read(fd
, p
, n
);
109 int32
go_write(uintptr
, void *, int32
)
110 __asm__ (GOSYM_PREFIX
"runtime.write");
113 go_write(uintptr fd
, void *p
, int32 n
)
115 return runtime_write(fd
, p
, n
);
118 int32
go_closefd(int32
)
119 __asm__ (GOSYM_PREFIX
"runtime.closefd");
124 return runtime_close(fd
);
128 __asm__ (GOSYM_PREFIX
"runtime.errno");
137 __asm__ (GOSYM_PREFIX
"runtime.getEnd");
143 // mmap adresses range start at 0x30000000 on AIX for 32 bits processes
144 uintptr end
= 0x30000000U
;
158 // CPU-specific initialization.
159 // Fetch CPUID info on x86.
164 #if defined(__i386__) || defined(__x86_64__)
165 unsigned int eax
, ebx
, ecx
, edx
;
167 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {
171 #if defined(HAVE_AS_X86_AES)
177 // A publication barrier: a store/store barrier.
179 void publicationBarrier(void)
180 __asm__ (GOSYM_PREFIX
"runtime.publicationBarrier");
185 __atomic_thread_fence(__ATOMIC_RELEASE
);