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';
37 runtime_fastrand(void)
52 runtime_cputicks(void)
54 #if defined(__386__) || defined(__x86_64__)
56 asm("rdtsc" : "=a" (low
), "=d" (high
));
57 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
58 #elif defined (__s390__) || defined (__s390x__)
60 /* stckf may not write the return variable in case of a clock error, so make
61 it read-write to prevent that the initialisation is optimised out.
62 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
63 we don't support Go for machines older than that. */
64 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
67 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
68 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
69 // TODO: need more entropy to better seed fastrand.
70 return runtime_nanotime();
75 runtime_signalstack(byte
*p
, uintptr n
)
83 st
.ss_flags
= SS_DISABLE
;
84 if(sigaltstack(&st
, nil
) < 0)
88 int32
go_open(char *, int32
, int32
)
89 __asm__ (GOSYM_PREFIX
"runtime.open");
92 go_open(char *name
, int32 mode
, int32 perm
)
94 return runtime_open(name
, mode
, perm
);
97 int32
go_read(int32
, void *, int32
)
98 __asm__ (GOSYM_PREFIX
"runtime.read");
101 go_read(int32 fd
, void *p
, int32 n
)
103 return runtime_read(fd
, p
, n
);
106 int32
go_write(uintptr
, void *, int32
)
107 __asm__ (GOSYM_PREFIX
"runtime.write");
110 go_write(uintptr fd
, void *p
, int32 n
)
112 return runtime_write(fd
, p
, n
);
115 int32
go_closefd(int32
)
116 __asm__ (GOSYM_PREFIX
"runtime.closefd");
121 return runtime_close(fd
);
125 __asm__ (GOSYM_PREFIX
"runtime.errno");
134 __asm__ (GOSYM_PREFIX
"runtime.getEnd");
140 // mmap adresses range start at 0x30000000 on AIX for 32 bits processes
141 uintptr end
= 0x30000000U
;
155 // CPU-specific initialization.
156 // Fetch CPUID info on x86.
161 #if defined(__i386__) || defined(__x86_64__)
162 unsigned int eax
, ebx
, ecx
, edx
;
164 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {
168 #if defined(HAVE_AS_X86_AES)
174 // A publication barrier: a store/store barrier.
176 void publicationBarrier(void)
177 __asm__ (GOSYM_PREFIX
"runtime.publicationBarrier");
182 __atomic_thread_fence(__ATOMIC_RELEASE
);
187 /* Currently sbrk0 is only called on GNU/Linux. */
190 __asm__ (GOSYM_PREFIX
"runtime.sbrk0");
195 return syscall(SYS_brk
, (uintptr
)(0));
198 #endif /* __linux__ */