Skip to content

Commit

Permalink
align GOOS=tamago support to go1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
abarisani committed Feb 27, 2020
1 parent 5e437af commit 2a2234a
Show file tree
Hide file tree
Showing 30 changed files with 617 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,10 @@ var cgoEnabled = map[string]bool{
"plan9/amd64": false,
"plan9/arm": false,
"solaris/amd64": true,
"tamago/arm": true,
"windows/386": true,
"windows/amd64": true,
"windows/arm": false,
"tamago/arm": true,
}

// List of platforms which are supported but not complete yet. These get
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/dist/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ func xsamefile(f1, f2 string) bool {
}

func xgetgoarm() string {
if goos == "tamago" {
// tamago guarantees VFPv3 and is always cross-compiled.
return "7"
}
if goos == "darwin" || goos == "android" {
// Assume all darwin/arm and android devices have VFPv3.
// These ports are also mostly cross-compiled, so it makes little
Expand Down
14 changes: 14 additions & 0 deletions src/internal/poll/fcntl_tamago.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build tamago

package poll

import "syscall"

// fcntl not supported on tamago
func fcntl(fd int, cmd int, arg int) (int, error) {
return 0, syscall.ENOSYS
}
2 changes: 1 addition & 1 deletion src/os/stat_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build js,wasm tamago
// +build js,wasm

package os

Expand Down
54 changes: 54 additions & 0 deletions src/os/stat_tamago.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build tamago

package os

import (
"syscall"
"time"
)

func fillFileStatFromSys(fs *fileStat, name string) {
fs.name = basename(name)
fs.size = fs.sys.Size
fs.modTime = timespecToTime(fs.sys.Mtime, fs.sys.MtimeNsec)
fs.mode = FileMode(fs.sys.Mode & 0777)
switch fs.sys.Mode & syscall.S_IFMT {
case syscall.S_IFBLK:
fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR:
fs.mode |= ModeDir
case syscall.S_IFIFO:
fs.mode |= ModeNamedPipe
case syscall.S_IFLNK:
fs.mode |= ModeSymlink
case syscall.S_IFREG:
// nothing to do
case syscall.S_IFSOCK:
fs.mode |= ModeSocket
}
if fs.sys.Mode&syscall.S_ISGID != 0 {
fs.mode |= ModeSetgid
}
if fs.sys.Mode&syscall.S_ISUID != 0 {
fs.mode |= ModeSetuid
}
if fs.sys.Mode&syscall.S_ISVTX != 0 {
fs.mode |= ModeSticky
}
}

func timespecToTime(sec, nsec int64) time.Time {
return time.Unix(sec, nsec)
}

// For testing.
func atime(fi FileInfo) time.Time {
st := fi.Sys().(*syscall.Stat_t)
return timespecToTime(st.Atime, st.AtimeNsec)
}
3 changes: 0 additions & 3 deletions src/runtime/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ func alginit() {
initAlgAES()
return
}
if GOOS == "tamago" {
initRNG()
}
getRandomData((*[len(hashkey) * sys.PtrSize]byte)(unsafe.Pointer(&hashkey))[:])
hashkey[0] |= 1 // make sure these numbers are odd
hashkey[1] |= 1
Expand Down
1 change: 1 addition & 0 deletions src/runtime/internal/sys/zgoos_aix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_android.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_dragonfly.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_freebsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/runtime/internal/sys/zgoos_hurd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/runtime/internal/sys/zgoos_illumos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_js.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_netbsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_openbsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_plan9.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/runtime/internal/sys/zgoos_tamago.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/internal/sys/zgoos_zos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 3 additions & 21 deletions src/runtime/lock_tamago.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,9 @@ func checkTimeouts() {
}
}

var returnedEventHandler *g

func init() {
// At the toplevel we need an extra goroutine that handles asynchronous events.
initg := getg()
go func() {
returnedEventHandler = getg()
goready(initg, 1)

gopark(nil, nil, waitReasonZero, traceEvNone, 1)
returnedEventHandler = nil
}()
gopark(nil, nil, waitReasonZero, traceEvNone, 1)
}

// beforeIdle gets called by the scheduler if no goroutine is awake.
// We resume the event handler (if available) which will pause the execution.
func beforeIdle() bool {
if returnedEventHandler != nil {
goready(returnedEventHandler, 1)
return true
}
// If we are not already handling an event, then we pause for an async event.
// If an event handler returned, we resume it and it will pause the execution.
func beforeIdle(delay int64) bool {
return false
}
2 changes: 1 addition & 1 deletion src/runtime/mem_tamago.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
// so try to extend the address space.
p = sbrk(n)
}
if p == nil {
if p == nil && v == nil {
p = memAlloc(n)
memCheck()
}
Expand Down
15 changes: 11 additions & 4 deletions src/runtime/os_tamago_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func initRNG()

// the following functions must be provided externally
// (but are already stubbed somewhere else in the runtime)
//func initRNG()
//func nanotime() int64
//func nanotime1() int64

// the following functions are defined in sys_tamago_arm.s
func set_vbar(addr unsafe.Pointer)
Expand Down Expand Up @@ -356,7 +355,7 @@ func syscall(number, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
}

//go:nosplit
func write(fd uintptr, buf unsafe.Pointer, count int32) int32 {
func write1(fd uintptr, buf unsafe.Pointer, count int32) int32 {
if fd != 1 && fd != 2 {
throw("unexpected fd, only stdout/stderr are supported")
}
Expand All @@ -378,7 +377,7 @@ func syscall_now() (sec int64, nsec int32) {
}

//go:nosplit
func walltime() (sec int64, nsec int32) {
func walltime1() (sec int64, nsec int32) {
// TODO: probably better implement this in sys_tamago_arm.s for better
// performance
nano := nanotime()
Expand Down Expand Up @@ -409,3 +408,11 @@ func exitThread(wait *uint32) {
// We should never reach exitThread
throw("exitThread: not implemented")
}

const preemptMSupported = false

func preemptM(mp *m) {
// Not currently supported.
//
// TODO: Use a note like we use signals on POSIX OSes
}
3 changes: 3 additions & 0 deletions src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ func mcommoninit(mp *m) {
var fastrandseed uintptr

func fastrandinit() {
if GOOS == "tamago" {
initRNG()
}
s := (*[unsafe.Sizeof(fastrandseed)]byte)(unsafe.Pointer(&fastrandseed))[:]
getRandomData(s)
}
Expand Down
Loading

0 comments on commit 2a2234a

Please sign in to comment.