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_cputicks(void)
39 #if defined(__386__) || defined(__x86_64__)
41 asm("rdtsc" : "=a" (low
), "=d" (high
));
42 return (int64
)(((uint64
)high
<< 32) | (uint64
)low
);
43 #elif defined (__s390__) || defined (__s390x__)
45 /* stckf may not write the return variable in case of a clock error, so make
46 it read-write to prevent that the initialisation is optimised out.
47 Note: Targets below z9-109 will crash when executing store clock fast, i.e.
48 we don't support Go for machines older than that. */
49 asm volatile(".insn s,0xb27c0000,%0" /* stckf */ : "+Q" (clock
) : : "cc" );
52 // Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
53 // runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
54 // TODO: need more entropy to better seed fastrand.
55 return runtime_nanotime();
60 runtime_signalstack(byte
*p
, uintptr n
)
68 st
.ss_flags
= SS_DISABLE
;
69 if(sigaltstack(&st
, nil
) < 0)
73 int32
go_open(char *, int32
, int32
)
74 __asm__ (GOSYM_PREFIX
"runtime.open");
77 go_open(char *name
, int32 mode
, int32 perm
)
79 return runtime_open(name
, mode
, perm
);
82 int32
go_read(int32
, void *, int32
)
83 __asm__ (GOSYM_PREFIX
"runtime.read");
86 go_read(int32 fd
, void *p
, int32 n
)
88 return runtime_read(fd
, p
, n
);
91 int32
go_write(uintptr
, void *, int32
)
92 __asm__ (GOSYM_PREFIX
"runtime.write");
95 go_write(uintptr fd
, void *p
, int32 n
)
97 return runtime_write(fd
, p
, n
);
100 int32
go_closefd(int32
)
101 __asm__ (GOSYM_PREFIX
"runtime.closefd");
106 return runtime_close(fd
);
110 __asm__ (GOSYM_PREFIX
"runtime.errno");
119 __asm__ (GOSYM_PREFIX
"runtime.getEnd");
125 // mmap adresses range start at 0x30000000 on AIX for 32 bits processes
126 uintptr end
= 0x30000000U
;
140 // CPU-specific initialization.
141 // Fetch CPUID info on x86.
146 #if defined(__i386__) || defined(__x86_64__)
147 unsigned int eax
, ebx
, ecx
, edx
;
149 if (__get_cpuid(1, &eax
, &ebx
, &ecx
, &edx
)) {
153 #if defined(HAVE_AS_X86_AES)
159 // A publication barrier: a store/store barrier.
161 void publicationBarrier(void)
162 __asm__ (GOSYM_PREFIX
"runtime.publicationBarrier");
167 __atomic_thread_fence(__ATOMIC_RELEASE
);
172 /* Currently sbrk0 is only called on GNU/Linux. */
175 __asm__ (GOSYM_PREFIX
"runtime.sbrk0");
180 return syscall(SYS_brk
, (uintptr
)(0));
183 #endif /* __linux__ */