Skip to content

Commit e3ea13a

Browse files
authored
add tamago/amd64 support (#11)
* remove unused constant * WiP tamago/amd64 support * WiP tamago/amd64 support * WiP tamago/amd64 support * tidying * ensure entry point consistency with other archs * tidying * move processor initialization outside tamago-go * update github action * tidying * add GetG to tamago/amd64 * unify GOOS=tamago amd64/arm/riscv64 runtime support
1 parent 900cc84 commit e3ea13a

21 files changed

+586
-466
lines changed

.github/workflows/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
- name: Compile Go with all.bash
1616
run: |
1717
cd src ; ./all.bash
18+
- name: Run Go distribution tests under tamago/amd64
19+
run: |
20+
GO_BUILDER_NAME=tamago GOOS=tamago GOARCH=amd64 ./bin/go tool dist test
1821
- name: Run Go distribution tests under tamago/arm
1922
run: |
2023
GO_BUILDER_NAME=tamago GOOS=tamago GOARCH=arm ./bin/go tool dist test

src/cmd/dist/build.go

+1
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ var cgoEnabled = map[string]bool{
17731773
"plan9/amd64": false,
17741774
"plan9/arm": false,
17751775
"solaris/amd64": true,
1776+
"tamago/amd64": false,
17761777
"tamago/arm": false,
17771778
"tamago/riscv64": false,
17781779
"windows/386": true,

src/internal/platform/zosarch.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/malloc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const (
305305
//
306306
// On other platforms, the user address space is contiguous
307307
// and starts at 0, so no offset is necessary.
308-
arenaBaseOffset = 0xffff800000000000*goarch.IsAmd64 + 0x0a00000000000000*goos.IsAix
308+
arenaBaseOffset = 0xffff800000000000*goarch.IsAmd64*(1-goos.IsTamago) + 0x0a00000000000000*goos.IsAix
309309
// A typed version of this constant that will make it into DWARF (for viewcore).
310310
arenaBaseOffsetUintptr = uintptr(arenaBaseOffset)
311311

src/runtime/mpagealloc_64bit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build amd64 || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || (riscv64 && !tamago) || s390x
5+
//go:build (amd64 && !tamago) || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || (riscv64 && !tamago) || s390x
66

77
package runtime
88

src/runtime/os_tamago.go

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Copyright 2019 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.
4+
5+
//go:build tamago
6+
7+
package runtime
8+
9+
import (
10+
"internal/runtime/atomic"
11+
"unsafe"
12+
)
13+
14+
// see testing.testBinary
15+
var testBinary string
16+
17+
// Bloc allows to override the heap memory start address
18+
var Bloc uintptr
19+
20+
// the following functions must be provided externally
21+
func hwinit()
22+
func printk(byte)
23+
func getRandomData([]byte)
24+
func initRNG()
25+
26+
// the following functions must be provided externally
27+
// (but are already stubbed somewhere else in the runtime)
28+
//func nanotime1() int64
29+
30+
// GetRandomData generates len(r) random bytes from the random source provided
31+
// externally by the linked application.
32+
func GetRandomData(r []byte) {
33+
getRandomData(r)
34+
}
35+
36+
// CallOnG0 calls a function (func(off int)) on g0 stack.
37+
//
38+
// The function arguments must be passed through the following registers
39+
// (rather than on the frame pointer):
40+
//
41+
// * R0: fn argument (vector table offset)
42+
// * R1: fn pointer
43+
// * R2: size of stack area reserved for caller registers
44+
// * R3: caller program counter
45+
func CallOnG0()
46+
47+
// WakeG modifies a goroutine cached timer for time.Sleep (g.timer) to fire as
48+
// soon as possible.
49+
//
50+
// The function arguments must be passed through the following registers
51+
// (rather than on the frame pointer):
52+
//
53+
// * R0: G pointer
54+
func WakeG()
55+
56+
// stubs for unused/unimplemented functionality
57+
type mOS struct{}
58+
type sigset struct{}
59+
type gsignalStack struct{}
60+
61+
func goenvs() {}
62+
func sigsave(p *sigset) {}
63+
func msigrestore(sigmask sigset) {}
64+
func clearSignalHandlers() {}
65+
func sigblock(exiting bool) {}
66+
func minit() {}
67+
func unminit() {}
68+
func mdestroy(mp *m) {}
69+
func setProcessCPUProfiler(hz int32) {}
70+
func setThreadCPUProfiler(hz int32) {}
71+
func initsig(preinit bool) {}
72+
func osyield() {}
73+
func osyield_no_g() {}
74+
75+
// May run with m.p==nil, so write barriers are not allowed.
76+
//
77+
//go:nowritebarrier
78+
func newosproc(mp *m) {
79+
throw("newosproc: not implemented")
80+
}
81+
82+
// Called to initialize a new m (including the bootstrap m).
83+
// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
84+
func mpreinit(mp *m) {
85+
mp.gsignal = malg(32 * 1024)
86+
mp.gsignal.m = mp
87+
}
88+
89+
func osinit() {
90+
ncpu = 1
91+
physPageSize = 4096
92+
93+
if Bloc != 0 {
94+
bloc = Bloc
95+
blocMax = bloc
96+
} else {
97+
initBloc()
98+
}
99+
}
100+
101+
func readRandom(r []byte) int {
102+
initRNG()
103+
getRandomData(r)
104+
return len(r)
105+
}
106+
107+
func signame(sig uint32) string {
108+
return ""
109+
}
110+
111+
//go:linkname os_sigpipe os.sigpipe
112+
func os_sigpipe() {
113+
throw("too many writes on closed pipe")
114+
}
115+
116+
//go:nosplit
117+
func crash() {
118+
*(*int32)(nil) = 0
119+
}
120+
121+
//go:linkname syscall
122+
func syscall(number, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
123+
switch number {
124+
// SYS_WRITE
125+
case 1:
126+
r1 := write(a1, unsafe.Pointer(a2), int32(a3))
127+
return uintptr(r1), 0, 0
128+
default:
129+
throw("unexpected syscall")
130+
}
131+
132+
return
133+
}
134+
135+
//go:nosplit
136+
func write1(fd uintptr, buf unsafe.Pointer, count int32) int32 {
137+
if fd != 1 && fd != 2 {
138+
throw("unexpected fd, only stdout/stderr are supported")
139+
}
140+
141+
c := uintptr(count)
142+
143+
for i := uintptr(0); i < c; i++ {
144+
p := (*byte)(unsafe.Pointer(uintptr(buf) + i))
145+
printk(*p)
146+
}
147+
148+
return int32(c)
149+
}
150+
151+
//go:linkname syscall_now syscall.now
152+
func syscall_now() (sec int64, nsec int32) {
153+
sec, nsec, _ = time_now()
154+
return
155+
}
156+
157+
//go:nosplit
158+
func walltime() (sec int64, nsec int32) {
159+
nano := nanotime()
160+
sec = nano / 1000000000
161+
nsec = int32(nano % 1000000000)
162+
return
163+
}
164+
165+
//go:nosplit
166+
func usleep(us uint32) {
167+
wake := nanotime() + int64(us)*1000
168+
for nanotime() < wake {
169+
}
170+
}
171+
172+
//go:nosplit
173+
func usleep_no_g(usec uint32) {
174+
usleep(usec)
175+
}
176+
177+
// Exit can be provided externally by the linked application to provide an
178+
// implementation for runtime.exit.
179+
var Exit func(int32)
180+
181+
func exit(code int32) {
182+
if Exit != nil {
183+
Exit(code)
184+
}
185+
186+
print("exit with code ", code, " halting\n")
187+
188+
for {
189+
// hang forever
190+
}
191+
}
192+
193+
func exitThread(wait *atomic.Uint32) {
194+
// We should never reach exitThread
195+
throw("exitThread: not implemented")
196+
}
197+
198+
const preemptMSupported = false
199+
200+
func preemptM(mp *m) {
201+
// No threads, so nothing to do.
202+
}
203+
204+
// Stubs so tests can link correctly. These should never be called.
205+
func open(name *byte, mode, perm int32) int32 { panic("not implemented") }
206+
func closefd(fd int32) int32 { panic("not implemented") }
207+
func read(fd int32, p unsafe.Pointer, n int32) int32 { panic("not implemented") }

src/runtime/os_tamago_amd64.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019 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.
4+
5+
//go:build tamago && amd64
6+
7+
package runtime
8+
9+
// the following variables must be provided externally
10+
var ramStart uint64
11+
var ramSize uint64
12+
var ramStackOffset uint64
13+
14+
// defined in asm_amd64.s
15+
func cputicks() int64
16+
17+
// GetG returns the pointer to the current G and its P.
18+
func GetG() (gp uint64, pp uint64)
19+
20+
// MemRegion returns the start and end addresses of the physical RAM assigned
21+
// to the Go runtime.
22+
func MemRegion() (start uint64, end uint64) {
23+
return ramStart, ramStart + ramSize
24+
}
25+
26+
// TextRegion returns the start and end addresses of the physical RAM
27+
// containing the Go runtime executable instructions.
28+
func TextRegion() (start uint64, end uint64) {
29+
return uint64(firstmoduledata.text), uint64(firstmoduledata.etext)
30+
}

0 commit comments

Comments
 (0)