Compare commits

..

1 Commits

Author SHA1 Message Date
Ayke van Laethem e0bdf2b070 WIP x509 on macOS 2025-08-04 14:27:20 +02:00
47 changed files with 521 additions and 1086 deletions
+8 -10
View File
@@ -92,20 +92,16 @@ commands:
- /go/pkg/mod
jobs:
test-oldest:
# This tests our lowest supported versions of Go and LLVM, to make sure at
# least the smoke tests still pass.
test-llvm15-go122:
docker:
- image: golang:1.22-bullseye
steps:
- test-linux:
llvm: "15"
resource_class: large
test-newest:
# This tests the latest supported LLVM version when linking against system
# libraries.
test-llvm20-go124:
docker:
- image: golang:1.25-bullseye
- image: golang:1.24-bullseye
steps:
- test-linux:
llvm: "20"
@@ -114,6 +110,8 @@ jobs:
workflows:
test-all:
jobs:
- test-oldest
# disable this test, since CircleCI seems unable to download due to rate-limits on Dockerhub.
# - test-newest
# This tests our lowest supported versions of Go and LLVM, to make sure at
# least the smoke tests still pass.
- test-llvm15-go122
# This tests LLVM 20 support when linking against system libraries.
- test-llvm20-go124
+2 -2
View File
@@ -39,7 +39,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Restore LLVM source cache
uses: actions/cache/restore@v4
@@ -134,7 +134,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Build TinyGo (LLVM ${{ matrix.version }})
run: go install -tags=llvm${{ matrix.version }}
+4 -4
View File
@@ -18,7 +18,7 @@ jobs:
# statically linked binary.
runs-on: ubuntu-latest
container:
image: golang:1.25-alpine
image: golang:1.24-alpine
outputs:
version: ${{ steps.version.outputs.version }}
steps:
@@ -137,7 +137,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Install wasmtime
uses: bytecodealliance/actions/wasmtime/setup@v1
@@ -181,7 +181,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Install Node.js
uses: actions/setup-node@v4
@@ -298,7 +298,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Restore LLVM source cache
uses: actions/cache/restore@v4
+10 -19
View File
@@ -13,17 +13,9 @@ concurrency:
jobs:
build-windows:
runs-on: ${{ matrix.image }}
runs-on: windows-2022
outputs:
version: ${{ steps.version.outputs.version }}
strategy:
matrix:
goarch: [ amd64, arm64 ]
include:
- goarch: amd64
image: windows-2022
- goarch: arm64
image: windows-11-arm
steps:
- name: Configure pagefile
uses: al-cheb/configure-pagefile-action@v1.4
@@ -49,7 +41,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Restore cached LLVM source
uses: actions/cache/restore@v4
@@ -80,7 +72,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
key: llvm-build-19-windows-${{ matrix.goarch }}-v1
key: llvm-build-19-windows-v1
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -102,7 +94,7 @@ jobs:
- name: Cache Go cache
uses: actions/cache@v4
with:
key: go-cache-windows-${{ matrix.goarch }}-v1-${{ hashFiles('go.mod') }}
key: go-cache-windows-v1-${{ hashFiles('go.mod') }}
path: |
C:/Users/runneradmin/AppData/Local/go-build
C:/Users/runneradmin/go/pkg/mod
@@ -113,7 +105,6 @@ jobs:
run: make -j3 gen-device
- name: Test TinyGo
shell: bash
if: matrix.goarch == 'amd64' # skip on ARM64 to speed up build
run: make test GOTESTFLAGS="-only-current-os"
- name: Build TinyGo release tarball
shell: bash
@@ -121,7 +112,7 @@ jobs:
- name: Make release artifact
shell: bash
working-directory: build/release
run: 7z -tzip a tinygo${{ steps.version.outputs.version }}.windows-${{ matrix.goarch }}.zip tinygo
run: 7z -tzip a tinygo${{ steps.version.outputs.version }}.windows-amd64.zip tinygo
- name: Publish release artifact
# Note: this release artifact is double-zipped, see:
# https://github.com/actions/upload-artifact/issues/39
@@ -131,8 +122,8 @@ jobs:
# We're doing the former here, to keep artifact uploads fast.
uses: actions/upload-artifact@v4
with:
name: windows-${{ matrix.goarch }}-double-zipped-${{ steps.version.outputs.version }}
path: build/release/tinygo${{ steps.version.outputs.version }}.windows-${{ matrix.goarch }}.zip
name: windows-amd64-double-zipped-${{ steps.version.outputs.version }}
path: build/release/tinygo${{ steps.version.outputs.version }}.windows-amd64.zip
smoke-test-windows:
runs-on: windows-2022
@@ -156,7 +147,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Download TinyGo build
uses: actions/download-artifact@v4
@@ -186,7 +177,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Download TinyGo build
uses: actions/download-artifact@v4
@@ -222,7 +213,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
go-version: '1.24'
cache: true
- name: Download TinyGo build
uses: actions/download-artifact@v4
-52
View File
@@ -1,55 +1,3 @@
0.39.0
---
* **general**
- all: add Go 1.25 support
- net: update to latest tinygo net package
- docs: clarify build verification step for macOS users
- Add flag to skip Renesas SVD builds
* **build**
- Makefile: install missing dlmalloc files
- flash: add -o flag support to save built binary (Fixes #4937) (#4942)
- fix: update version of clang to 17 to accommodate latest Go 1.25 docker base image
* **ci**
- chore: update all CI builds to test Go 1.25 release
- fix: disable test-newest since CircleCI seems unable to download due to rate-limits on Dockerhub
- ci: rename some jobs to avoid churn on every Go/LLVM version bump
- ci: make the goroutines test less racy
- tests: de-flake goroutines test
* **compiler**
- compiler: implement internal/abi.Escape
* **main**
- main: show the compiler error (if any) for `tinygo test -c`
- chore: correct GOOS=js name in error messages for WASM
* **machine**
- machine: add international keys
- machine: remove some unnecessary "// peripherals:" comments
- machine: add I2C pin comments
- machine: standardize I2C errors with "i2c:" prefix
- machine: make I2C usable in the simulator
- fix: add SPI and I2C to teensy 4.1 (#4943)
- `rp2`: use the correct channel mask for rp2350 ADC; hold lock during read (#4938)
- `rp2`: disable digital input for analog inputs
* **runtime**
- runtime: ensure time.Sleep(d) sleeps at least d
- runtime: stub out weak pointer support
- runtime: implement dummy AddCleanup
- runtime: enable multi-core scheduler for rp2350
- `internal/task`: use -stack-size flag when starting a new thread
- `internal/task`: add SA_RESTART flag to GC interrupts
- `internal/task`: a few small correctness fixes
- `internal/gclayout`: make gclayout values constants
- darwin: add threading support and use it by default
* **standard library**
- `sync`: implement sync.Swap
- `reflect`: implement Method.IsExported
* **testing**
- testing: stub out testing.B.Loop
* **targets**
- `stm32`: add support for the STM32L031G6U6
- add metro-rp2350 board definition (#4989)
- `rp2040/rp2350`: set the default stack size to 8k for rp2040/rp2350 based boards where this was not already the case
0.38.0
---
* **general**
+3 -3
View File
@@ -1,8 +1,8 @@
# tinygo-llvm stage obtains the llvm source for TinyGo
FROM golang:1.25 AS tinygo-llvm
FROM golang:1.24 AS tinygo-llvm
RUN apt-get update && \
apt-get install -y apt-utils make cmake clang-17 ninja-build && \
apt-get install -y apt-utils make cmake clang-15 ninja-build && \
rm -rf \
/var/lib/apt/lists/* \
/var/log/* \
@@ -33,7 +33,7 @@ RUN cd /tinygo/ && \
# tinygo-compiler copies the compiler build over to a base Go container (without
# all the build tools etc).
FROM golang:1.25 AS tinygo-compiler
FROM golang:1.24 AS tinygo-compiler
# Copy tinygo build.
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
+9 -15
View File
@@ -460,15 +460,11 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS)
TEST_IOFS := false
endif
TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic'
# Test known-working standard library packages.
# TODO: parallelize, and only show failing tests (no implied -v flag).
.PHONY: tinygo-test
tinygo-test:
@# TestExtraMethods: used by many crypto packages and uses reflect.Type.Method which is not implemented.
@# TestParseAndBytesRoundTrip/P256/Generic: relies on t.Skip() which is not implemented
$(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
$(TINYGO) test $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
@# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also
@# requires a large stack-size. Hence, io/fs is only run conditionally.
@# For more details, see the comments on issue #3143.
@@ -476,7 +472,7 @@ ifeq ($(TEST_IOFS),true)
$(TINYGO) test -stack-size=6MB io/fs
endif
tinygo-test-fast:
$(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST)
$(TINYGO) test $(TEST_PACKAGES_HOST)
tinygo-bench:
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
tinygo-bench-fast:
@@ -484,18 +480,18 @@ tinygo-bench-fast:
# Same thing, except for wasi rather than the current platform.
tinygo-test-wasm:
$(TINYGO) test -target wasm $(TEST_SKIP_FLAG) $(TEST_PACKAGES_WASM)
$(TINYGO) test -target wasm $(TEST_PACKAGES_WASM)
tinygo-test-wasi:
$(TINYGO) test -target wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasip1:
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasip1-fast:
$(TINYGO) test -target=wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
$(TINYGO) test -target=wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-test-wasip2-slow:
$(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_SLOW)
$(TINYGO) test -target=wasip2 $(TEST_PACKAGES_SLOW)
tinygo-test-wasip2-fast:
$(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
$(TINYGO) test -target=wasip2 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-test-wasip2-sum-slow:
TINYGO=$(TINYGO) \
@@ -521,7 +517,7 @@ tinygo-bench-wasip2-fast:
# Run tests on riscv-qemu since that one provides a large amount of memory.
tinygo-test-baremetal:
$(TINYGO) test -target riscv-qemu $(TEST_SKIP_FLAG) $(TEST_PACKAGES_BAREMETAL)
$(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL)
# Test external packages in a large corpus.
test-corpus:
@@ -785,8 +781,6 @@ endif
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pico-plus2 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=metro-rp2350 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=waveshare-rp2040-tiny examples/echo
@$(MD5SUM) test.hex
# test pwm
+1 -1
View File
@@ -26,7 +26,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
// Version range supported by TinyGo.
const minorMin = 19
const minorMax = 25
const minorMax = 24
// Check that we support this Go toolchain version.
gorootMajor, gorootMinor, err := goenv.GetGorootVersion()
+3 -3
View File
@@ -42,9 +42,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test.
tests := []sizeTest{
// microcontrollers
{"hifive1b", "examples/echo", 4580, 280, 0, 2264},
{"microbit", "examples/serial", 2928, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7387, 1489, 116, 6912},
{"hifive1b", "examples/echo", 4556, 280, 0, 2264},
{"microbit", "examples/serial", 2920, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7379, 1489, 116, 6912},
// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the
-23
View File
@@ -121,29 +121,6 @@ func (b *builder) createKeepAliveImpl() {
b.CreateRetVoid()
}
// createAbiEscapeImpl implements the generic internal/abi.Escape function. It
// currently only supports pointer types.
func (b *builder) createAbiEscapeImpl() {
b.createFunctionStart(true)
// The first parameter is assumed to be a pointer. This is checked at the
// call site of createAbiEscapeImpl.
pointerValue := b.getValue(b.fn.Params[0], getPos(b.fn))
// Create an equivalent of the following C code, which is basically just a
// nop but ensures the pointerValue is kept alive:
//
// __asm__ __volatile__("" : : "r"(pointerValue))
//
// It should be portable to basically everything as the "r" register type
// exists basically everywhere.
asmType := llvm.FunctionType(b.dataPtrType, []llvm.Type{b.dataPtrType}, false)
asmFn := llvm.InlineAsm(asmType, "", "=r,0", true, false, 0, false)
result := b.createCall(asmType, asmFn, []llvm.Value{pointerValue}, "")
b.CreateRet(result)
}
var mathToLLVMMapping = map[string]string{
"math.Ceil": "llvm.ceil.f64",
"math.Exp": "llvm.exp.f64",
-17
View File
@@ -253,23 +253,6 @@ func (c *compilerContext) maybeCreateSyntheticFunction(fn *ssa.Function, llvmFn
// The exception is the package initializer, which does appear in the
// *ssa.Package members and so shouldn't be created here.
if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" {
if origin := fn.Origin(); origin != nil && origin.RelString(nil) == "internal/abi.Escape" {
// This is a special implementation or internal/abi.Escape, which
// can only really be implemented in the compiler.
// For simplicity we'll only implement pointer parameters for now.
if _, ok := fn.Params[0].Type().Underlying().(*types.Pointer); ok {
irbuilder := c.ctx.NewBuilder()
defer irbuilder.Dispose()
b := newBuilder(c, irbuilder, fn)
b.createAbiEscapeImpl()
llvmFn.SetLinkage(llvm.LinkOnceODRLinkage)
llvmFn.SetUnnamedAddr(true)
}
// If the parameter is not of a pointer type, it will be left
// unimplemented. This will result in a linker error if the function
// is really called, making it clear it needs to be implemented.
return
}
if len(fn.Blocks) == 0 {
c.addError(fn.Pos(), "missing function body")
return
+1 -1
View File
@@ -10,7 +10,7 @@ import (
// Version of TinyGo.
// Update this value before release of new version of software.
const version = "0.39.0"
const version = "0.39.0-dev"
// Return TinyGo version, either in the form 0.30.0 or as a development version
// (like 0.30.0-dev-abcd012).
+27 -30
View File
@@ -229,36 +229,33 @@ func needsSyscallPackage(buildTags []string) bool {
// means use the TinyGo version.
func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
paths := map[string]bool{
"": true,
"crypto/": true,
"crypto/rand/": false,
"crypto/tls/": false,
"crypto/x509/": true,
"crypto/x509/internal/": true,
"crypto/x509/internal/macos/": false,
"device/": false,
"examples/": false,
"internal/": true,
"internal/abi/": false,
"internal/binary/": false,
"internal/bytealg/": false,
"internal/cm/": false,
"internal/futex/": false,
"internal/fuzz/": false,
"internal/reflectlite/": false,
"internal/gclayout": false,
"internal/task/": false,
"internal/wasi/": false,
"machine/": false,
"net/": true,
"net/http/": false,
"os/": true,
"reflect/": false,
"runtime/": false,
"sync/": true,
"testing/": true,
"tinygo/": false,
"unique/": false,
"": true,
"crypto/": true,
"crypto/rand/": false,
"crypto/tls/": false,
"device/": false,
"examples/": false,
"internal/": true,
"internal/abi/": false,
"internal/binary/": false,
"internal/bytealg/": false,
"internal/cm/": false,
"internal/futex/": false,
"internal/fuzz/": false,
"internal/reflectlite/": false,
"internal/gclayout": false,
"internal/task/": false,
"internal/wasi/": false,
"machine/": false,
"net/": true,
"net/http/": false,
"os/": true,
"reflect/": false,
"runtime/": false,
"sync/": true,
"testing/": true,
"tinygo/": false,
"unique/": false,
}
if goMinor >= 19 {
+5 -32
View File
@@ -291,8 +291,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
})
if testConfig.CompileOnly {
// Return the compiler error, if there is one.
return true, err
return true, nil
}
importPath := strings.TrimSuffix(result.ImportPath, ".test")
@@ -340,17 +339,8 @@ func dirsToModuleRootAbs(maindir, modroot string) []string {
return dirs
}
// validateOutputFormat checks if the output file extension matches the expected format
func validateOutputFormat(outpath, expectedExt string) error {
actualExt := filepath.Ext(outpath)
if actualExt != expectedExt {
return fmt.Errorf("output format %s does not match target format %s", actualExt, expectedExt)
}
return nil
}
// Flash builds and flashes the built binary to the given serial port.
func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
func Flash(pkgName, port string, options *compileopts.Options) error {
config, err := builder.NewConfig(options)
if err != nil {
return err
@@ -399,24 +389,13 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
if !options.Work {
defer os.RemoveAll(tmpdir)
}
// Validate output format before building
if outpath != "" {
if err := validateOutputFormat(outpath, fileExt); err != nil {
return err
}
}
// Build the binary.
result, err := builder.Build(pkgName, fileExt, tmpdir, config)
if err != nil {
return err
}
// Save output file if specified (after build, before flashing)
if outpath != "" {
if err := copyFile(result.Binary, outpath); err != nil {
return fmt.Errorf("failed to save output file: %v", err)
}
}
// do we need port reset to put MCU into bootloader mode?
if config.Target.PortReset == "true" && flashMethod != "openocd" {
port, err := getDefaultPort(port, config.Target.SerialPort)
@@ -1318,11 +1297,6 @@ extension at all.`
(https://tinygo.org/docs/reference/microcontrollers/).
Examples: "arduino-nano", "d1mini", "xiao".
-o={filename}:
Save the built binary to the specified output file. The file
format must match the target's expected format (e.g., .hex,
.uf2). Both flashing and saving will be performed.
-monitor:
Start the serial monitor (see below) immediately after
flashing. However, some microcontrollers need a split second
@@ -1653,7 +1627,7 @@ func main() {
flag.BoolVar(&flagTest, "test", false, "supply -test flag to go list")
}
var outpath string
if command == "help" || command == "build" || command == "test" || command == "flash" {
if command == "help" || command == "build" || command == "test" {
flag.StringVar(&outpath, "o", "", "output filename")
}
@@ -1804,7 +1778,7 @@ func main() {
case "flash", "gdb", "lldb":
pkgName := filepath.ToSlash(flag.Arg(0))
if command == "flash" {
err := Flash(pkgName, *port, outpath, options)
err := Flash(pkgName, *port, options)
printBuildOutput(err, *flagJSON)
} else {
if !options.Debug {
@@ -1890,7 +1864,6 @@ func main() {
wd = ""
}
diagnostics.CreateDiagnostics(err).WriteTo(os.Stderr, wd)
os.Exit(1)
}
if !passed {
select {
-189
View File
@@ -1,189 +0,0 @@
package macos
import (
"errors"
"time"
)
// Exported symbols copied from Big Go, but stripped of functionality.
// Allows building of crypto/x509 on macOS.
const (
ErrSecCertificateExpired = -67818
ErrSecHostNameMismatch = -67602
ErrSecNotTrusted = -67843
)
var ErrNoTrustSettings = errors.New("no trust settings found")
var SecPolicyAppleSSL = StringToCFString("1.2.840.113635.100.1.3") // defined by POLICYMACRO
var SecPolicyOid = StringToCFString("SecPolicyOid")
var SecTrustSettingsPolicy = StringToCFString("kSecTrustSettingsPolicy")
var SecTrustSettingsPolicyString = StringToCFString("kSecTrustSettingsPolicyString")
var SecTrustSettingsResultKey = StringToCFString("kSecTrustSettingsResult")
func CFArrayAppendValue(array CFRef, val CFRef) {}
func CFArrayGetCount(array CFRef) int {
return 0
}
func CFDataGetBytePtr(data CFRef) uintptr {
return 0
}
func CFDataGetLength(data CFRef) int {
return 0
}
func CFDataToSlice(data CFRef) []byte {
return nil
}
func CFEqual(a, b CFRef) bool {
return false
}
func CFErrorGetCode(errRef CFRef) int {
return 0
}
func CFNumberGetValue(num CFRef) (int32, error) {
return 0, errors.New("not implemented")
}
func CFRelease(ref CFRef) {}
func CFStringToString(ref CFRef) string {
return ""
}
func ReleaseCFArray(array CFRef) {}
func SecCertificateCopyData(cert CFRef) ([]byte, error) {
return nil, errors.New("not implemented")
}
func SecTrustCopyCertificateChain(trustObj CFRef) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecTrustEvaluateWithError(trustObj CFRef) (int, error) {
return 0, errors.New("not implemented")
}
func SecTrustGetCertificateCount(trustObj CFRef) int {
return 0
}
func SecTrustGetResult(trustObj CFRef, result CFRef) (CFRef, CFRef, error) {
return 0, 0, errors.New("not implemented")
}
func SecTrustSetVerifyDate(trustObj CFRef, dateRef CFRef) error {
return errors.New("not implemented")
}
type CFRef uintptr
func BytesToCFData(b []byte) CFRef {
return 0
}
func CFArrayCreateMutable() CFRef {
return 0
}
func CFArrayGetValueAtIndex(array CFRef, index int) CFRef {
return 0
}
func CFDateCreate(seconds float64) CFRef {
return 0
}
func CFDictionaryGetValueIfPresent(dict CFRef, key CFString) (value CFRef, ok bool) {
return 0, false
}
func CFErrorCopyDescription(errRef CFRef) CFRef {
return 0
}
func CFStringCreateExternalRepresentation(strRef CFRef) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecCertificateCreateWithData(b []byte) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecPolicyCreateSSL(name string) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecTrustCreateWithCertificates(certs CFRef, policies CFRef) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecTrustEvaluate(trustObj CFRef) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecTrustGetCertificateAtIndex(trustObj CFRef, i int) (CFRef, error) {
return 0, errors.New("not implemented")
}
func SecTrustSettingsCopyCertificates(domain SecTrustSettingsDomain) (certArray CFRef, err error) {
return 0, errors.New("not implemented")
}
func SecTrustSettingsCopyTrustSettings(cert CFRef, domain SecTrustSettingsDomain) (trustSettings CFRef, err error) {
return 0, errors.New("not implemented")
}
func TimeToCFDateRef(t time.Time) CFRef {
return 0
}
type CFString CFRef
func StringToCFString(s string) CFString {
return 0
}
type OSStatus struct {
// Has unexported fields.
}
func (s OSStatus) Error() string
type SecTrustResultType int32
const (
SecTrustResultInvalid SecTrustResultType = iota
SecTrustResultProceed
SecTrustResultConfirm // deprecated
SecTrustResultDeny
SecTrustResultUnspecified
SecTrustResultRecoverableTrustFailure
SecTrustResultFatalTrustFailure
SecTrustResultOtherError
)
type SecTrustSettingsDomain int32
const (
SecTrustSettingsDomainUser SecTrustSettingsDomain = iota
SecTrustSettingsDomainAdmin
SecTrustSettingsDomainSystem
)
type SecTrustSettingsResult int32
const (
SecTrustSettingsResultInvalid SecTrustSettingsResult = iota
SecTrustSettingsResultTrustRoot
SecTrustSettingsResultTrustAsRoot
SecTrustSettingsResultDeny
SecTrustSettingsResultUnspecified
)
-7
View File
@@ -8,10 +8,3 @@ import "unsafe"
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
return p
}
func Escape[T any](x T) T {
// This function is either implemented in the compiler, or left undefined
// for some variation of T. The body of this function should not be compiled
// as-is.
panic("internal/abi.Escape: unreachable (implemented in the compiler)")
}
+2 -7
View File
@@ -58,7 +58,6 @@ void tinygo_task_init(void *mainTask, pthread_t *thread, int *numCPU, void *cont
// Using pthread_kill, we can still send the signal to a specific thread.
struct sigaction act = { 0 };
act.sa_handler = tinygo_task_gc_pause;
act.sa_flags = SA_RESTART;
sigaction(taskPauseSignal, &act, NULL);
// Obtain the number of CPUs available on program start (for NumCPU).
@@ -101,7 +100,7 @@ static void* start_wrapper(void *arg) {
};
// Start a new goroutine in an OS thread.
int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, uintptr_t *stackTop, uintptr_t stackSize, void *context) {
int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, uintptr_t *stackTop, void *context) {
// Sanity check. Should get optimized away.
if (sizeof(pthread_t) != sizeof(void*)) {
__builtin_trap();
@@ -118,11 +117,7 @@ int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, u
#else
sem_init(&state.startlock, 0, 0);
#endif
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_setstacksize(&attrs, stackSize);
int result = pthread_create(thread, &attrs, &start_wrapper, &state);
pthread_attr_destroy(&attrs);
int result = pthread_create(thread, NULL, &start_wrapper, &state);
// Wait until the thread has been created and read all state_pass variables.
#if __APPLE__
+2 -2
View File
@@ -109,7 +109,7 @@ func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
// and the stop-the-world GC won't see threads that haven't started yet or
// are not fully started yet.
activeTaskLock.Lock()
errCode := tinygo_task_start(fn, args, t, &t.state.thread, &t.state.stackTop, stackSize)
errCode := tinygo_task_start(fn, args, t, &t.state.thread, &t.state.stackTop)
if errCode != 0 {
runtimePanic("could not start thread")
}
@@ -266,7 +266,7 @@ func tinygo_task_init(t *Task, thread *threadID, numCPU *int32)
// Here same as for tinygo_task_init.
//
//go:linkname tinygo_task_start tinygo_task_start
func tinygo_task_start(fn uintptr, args unsafe.Pointer, t *Task, thread *threadID, stackTop *uintptr, stackSize uintptr) int32
func tinygo_task_start(fn uintptr, args unsafe.Pointer, t *Task, thread *threadID, stackTop *uintptr) int32
// Pause the thread by sending it a signal.
//
-183
View File
@@ -1,183 +0,0 @@
//go:build metro_rp2350
package machine
// GPIO pins
const (
GP0 Pin = GPIO0
GP1 Pin = GPIO1
GP2 Pin = GPIO2
GP3 Pin = GPIO3
GP4 Pin = GPIO4
GP5 Pin = GPIO5
GP6 Pin = GPIO6
GP7 Pin = GPIO7
GP8 Pin = GPIO8
GP9 Pin = GPIO9
GP10 Pin = GPIO10
GP11 Pin = GPIO11
GP12 Pin = GPIO12
GP13 Pin = GPIO13
GP14 Pin = GPIO14
GP15 Pin = GPIO15
GP16 Pin = GPIO16
GP17 Pin = GPIO17
GP18 Pin = GPIO18
GP19 Pin = GPIO19
GP20 Pin = GPIO20
GP21 Pin = GPIO21
GP22 Pin = GPIO22
GP23 Pin = GPIO23
GP24 Pin = GPIO24
GP25 Pin = GPIO25
GP26 Pin = GPIO26
GP27 Pin = GPIO27
GP28 Pin = GPIO28
GP29 Pin = GPIO29
GP30 Pin = GPIO30
GP31 Pin = GPIO31
GP32 Pin = GPIO32
GP33 Pin = GPIO33
GP34 Pin = GPIO34
GP35 Pin = GPIO35
GP36 Pin = GPIO36
GP37 Pin = GPIO37
GP38 Pin = GPIO38
GP39 Pin = GPIO39
GP40 Pin = GPIO40
GP41 Pin = GPIO41
GP42 Pin = GPIO42
GP43 Pin = GPIO43
GP44 Pin = GPIO44
GP45 Pin = GPIO45
GP46 Pin = GPIO46
// Boot button
BUTTON Pin = GPIO24
// Onboard LED
LED Pin = GPIO23
// Onboard NeoPixel
NEOPIXEL Pin = GPIO25
WS2812 Pin = GPIO25
// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
)
// Arduino-header digital pins
const (
RX Pin = GPIO1
TX Pin = GPIO0
D2 Pin = GPIO2
D3 Pin = GPIO3
D4 Pin = GPIO4
D5 Pin = GPIO5
D6 Pin = GPIO6
D7 Pin = GPIO7
D8 Pin = GPIO8
D9 Pin = GPIO9
D10 Pin = GPIO10
D11 Pin = GPIO11
D22 Pin = GPIO22
D23 Pin = GPIO23
)
// Arduino-header analog pins
const (
A0 Pin = GPIO41
A1 Pin = GPIO42
A2 Pin = GPIO43
A3 Pin = GPIO44
A4 Pin = GPIO45
A5 Pin = GPIO46
)
// I2C Default pins on Raspberry Pico.
const (
I2C0_SDA_PIN = GP20
I2C0_SCL_PIN = GP21
I2C1_SDA_PIN = GP2
I2C1_SCL_PIN = GP3
)
// SPI default pins
const (
// Default Serial Clock Bus 0 for SPI communications
SPI0_SCK_PIN = GPIO18
// Default Serial Out Bus 0 for SPI communications
SPI0_SDO_PIN = GPIO19 // Tx
// Default Serial In Bus 0 for SPI communications
SPI0_SDI_PIN = GPIO16 // Rx
// Default Serial Clock Bus 1 for SPI communications
SPI1_SCK_PIN = GPIO30
// Default Serial Out Bus 1 for SPI communications
SPI1_SDO_PIN = GPIO31 // Tx
// Default Serial In Bus 1 for SPI communications
SPI1_SDI_PIN = GPIO28 // Rx
// SPI header pins
MOSI Pin = SPI1_SDO_PIN
MISO Pin = SPI1_SDI_PIN
SCK Pin = SPI1_SCK_PIN
)
// SD card reader pins
const (
SD_SCK = GPIO34
SD_MOSI = GPIO35
SD_MISO = GPIO36
SDIO_DATA1 = GPIO37
SDIO_DATA2 = GPIO38
SD_CS = GPIO39
SD_CARD_DETECT = GPIO40
)
// HSTX pins
const (
CKN Pin = GPIO15
CKP Pin = GPIO14
D0N Pin = GPIO19
D0P Pin = GPIO18
D1N Pin = GPIO17
D1P Pin = GPIO16
D2N Pin = GPIO13
D2P Pin = GPIO12
D26 Pin = GPIO26
D27 Pin = GPIO27
SCL Pin = GPIO21
SDA Pin = GPIO20
)
// USB host header pins
const (
USB_HOST_DATA_PLUS Pin = GPIO32
USB_HOST_DATA_MINUS Pin = GPIO33
USB_HOST_5V_POWER Pin = GPIO29
)
// UART pins
const (
UART0_TX_PIN = GPIO0
UART0_RX_PIN = GPIO1
UART1_TX_PIN = GPIO8
UART1_RX_PIN = GPIO9
UART_TX_PIN = UART0_TX_PIN
UART_RX_PIN = UART0_RX_PIN
)
var DefaultUART = UART0
// USB identifiers
const (
usb_STRING_PRODUCT = "Metro RP2350"
usb_STRING_MANUFACTURER = "Adafruit"
)
var (
usb_VID uint16 = 0x239A
usb_PID uint16 = 0x814E
)
+1 -1
Submodule src/net updated: 983d88dd7a...77be3968d1
-5
View File
@@ -127,11 +127,6 @@ type Method struct {
Index int // index for Type.Method
}
// IsExported reports whether the method is exported.
func (m Method) IsExported() bool {
return m.PkgPath == ""
}
// The following Type type has been copied almost entirely from
// https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212.
// Some methods have been commented out as they haven't yet been implemented.
-27
View File
@@ -106,33 +106,6 @@ func UnlockOSThread() {
// point of the call.
func KeepAlive(x interface{})
// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up.
//
// We base this on the following loophole in the official runtime.AddCleanup
// documentation:
//
// > The cleanup(arg) call is not always guaranteed to run; in particular it is
// > not guaranteed to run before program exit.
//
// So it's technically correct (the best kind of correct) to not run any
// cleanups. But of course, this can lead to resource leaks so cleanups may need
// to be implemented eventually.
func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup {
return Cleanup{}
}
type Cleanup struct{}
func (c Cleanup) Stop() {}
//go:linkname registerWeakPointer weak.runtime_registerWeakPointer
func registerWeakPointer(ptr unsafe.Pointer) unsafe.Pointer {
// TODO: unimplemented.
// I hope not implementing this won't break anything, like packages that
// expect weak pointers to be GC'd before they actually are.
return ptr
}
var godebugUpdate func(string, string)
//go:linkname godebug_setUpdate internal/godebug.setUpdate
-367
View File
@@ -1,367 +0,0 @@
//go:build rp2040 || rp2350
package runtime
import (
"device/arm"
"device/rp"
"internal/task"
"machine"
"machine/usb/cdc"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
)
const numCPU = 2
// machineTicks is provided by package machine.
func machineTicks() uint64
// machineLightSleep is provided by package machine.
func machineLightSleep(uint64)
// ticks returns the number of ticks (microseconds) elapsed since power up.
func ticks() timeUnit {
t := machineTicks()
return timeUnit(t)
}
func ticksToNanoseconds(ticks timeUnit) int64 {
return int64(ticks) * 1000
}
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns / 1000)
}
func sleepTicks(d timeUnit) {
if hasScheduler {
// With scheduler, sleepTicks may return early if an interrupt or
// event fires - so scheduler can schedule any go routines now
// eligible to run
machineLightSleep(uint64(d))
return
}
// Busy loop
sleepUntil := ticks() + d
for ticks() < sleepUntil {
}
}
// Currently sleeping core, or 0xff.
// Must only be accessed with the scheduler lock held.
var sleepingCore uint8 = 0xff
// Return whether another core is sleeping.
// May only be called with the scheduler lock held.
func hasSleepingCore() bool {
return sleepingCore != 0xff
}
// Almost identical to sleepTicks, except that it will unlock/lock the scheduler
// while sleeping and is interruptible by interruptSleepTicksMulticore.
// This may only be called with the scheduler lock held.
func sleepTicksMulticore(d timeUnit) {
sleepingCore = uint8(currentCPU())
// Note: interruptSleepTicksMulticore will be able to interrupt this, since
// it executes the "sev" instruction which would make sleepTicks return
// immediately without sleeping. Even if it happens while configuring the
// sleep operation.
schedulerLock.Unlock()
sleepTicks(d)
schedulerLock.Lock()
sleepingCore = 0xff
}
// Interrupt an ongoing call to sleepTicksMulticore on another core.
func interruptSleepTicksMulticore(wakeup timeUnit) {
arm.Asm("sev")
}
// Number of cores that are currently in schedulerUnlockAndWait.
// It is possible for both cores to be sleeping, if the program is waiting for
// an interrupt (or is deadlocked).
var waitingCore uint8
// Put the scheduler to sleep, since there are no tasks to run.
// This will unlock the scheduler lock, and must be called with the scheduler
// lock held.
func schedulerUnlockAndWait() {
waitingCore++
schedulerLock.Unlock()
arm.Asm("wfe")
schedulerLock.Lock()
waitingCore--
}
// Wake another core, if one is sleeping. Must be called with the scheduler lock
// held.
func schedulerWake() {
if waitingCore != 0 {
arm.Asm("sev")
}
}
// Return the current core number: 0 or 1.
func currentCPU() uint32 {
return rp.SIO.CPUID.Get()
}
// Start the secondary cores for this chip.
// On the RP2040/RP2350, there is only one other core to start.
func startSecondaryCores() {
// Start the second core of the RP2040/RP2350.
// See sections 2.8.2 and 5.3 in the datasheets for RP2040 and RP2350 respectively.
seq := 0
for {
cmd := core1StartSequence[seq]
if cmd == 0 {
multicore_fifo_drain()
arm.Asm("sev")
}
multicore_fifo_push_blocking(cmd)
response := multicore_fifo_pop_blocking()
if cmd != response {
seq = 0
continue
}
seq = seq + 1
if seq >= len(core1StartSequence) {
break
}
}
// Enable the FIFO interrupt for the GC stop the world phase.
// We can only do this after we don't need the FIFO anymore for starting the
// second core.
intr := interrupt.New(sioIrqFifoProc0, func(intr interrupt.Interrupt) {
switch rp.SIO.FIFO_RD.Get() {
case 1:
gcInterruptHandler(0)
}
})
intr.Enable()
intr.SetPriority(0xff)
}
var core1StartSequence = [...]uint32{
0, 0, 1,
uint32(uintptr(unsafe.Pointer(&__isr_vector))),
uint32(uintptr(unsafe.Pointer(&stack1TopSymbol))),
uint32(exportedFuncPtr(runCore1)),
}
//go:extern __isr_vector
var __isr_vector [0]uint32
//go:extern _stack1_top
var stack1TopSymbol [0]uint32
// The function that is started on the second core.
//
//export tinygo_runCore1
func runCore1() {
// Clear sticky bit that seems to have been set while starting this core.
rp.SIO.FIFO_ST.Set(rp.SIO_FIFO_ST_ROE)
// Enable the FIFO interrupt, mainly used for the stop-the-world phase of
// the GC.
// Use the lowest possible priority (highest priority value), so that other
// interrupts can still happen while the GC is running.
intr := interrupt.New(sioIrqFifoProc1, func(intr interrupt.Interrupt) {
switch rp.SIO.FIFO_RD.Get() {
case 1:
gcInterruptHandler(1)
}
})
intr.Enable()
intr.SetPriority(0xff)
// Now start running the scheduler on this core.
schedulerLock.Lock()
scheduler(false)
schedulerLock.Unlock()
// The main function returned.
exit(0)
}
// The below multicore_fifo_* functions have been translated from the Raspberry
// Pi Pico SDK.
func multicore_fifo_rvalid() bool {
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_VLD != 0
}
func multicore_fifo_wready() bool {
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_RDY != 0
}
func multicore_fifo_drain() {
for multicore_fifo_rvalid() {
rp.SIO.FIFO_RD.Get()
}
}
func multicore_fifo_push_blocking(data uint32) {
for !multicore_fifo_wready() {
}
rp.SIO.FIFO_WR.Set(data)
arm.Asm("sev")
}
func multicore_fifo_pop_blocking() uint32 {
for !multicore_fifo_rvalid() {
arm.Asm("wfe")
}
return rp.SIO.FIFO_RD.Get()
}
// Value used to communicate between the GC core and the other (paused) cores.
var gcSignalWait volatile.Register8
// The GC interrupted this core for the stop-the-world phase.
// This function handles that, and only returns after the stop-the-world phase
// ended.
func gcInterruptHandler(hartID uint32) {
// Let the GC know we're ready.
gcScanState.Add(1)
arm.Asm("sev")
// Wait until we get a signal to start scanning.
for gcSignalWait.Get() == 0 {
arm.Asm("wfe")
}
gcSignalWait.Set(0)
// Scan the stack(s) of this core.
scanCurrentStack()
if !task.OnSystemStack() {
// Mark system stack.
markRoots(task.SystemStack(), coreStackTop(hartID))
}
// Signal we've finished scanning.
gcScanState.Store(1)
arm.Asm("sev")
// Wait until we get a signal that the stop-the-world phase has ended.
for gcSignalWait.Get() == 0 {
arm.Asm("wfe")
}
gcSignalWait.Set(0)
// Signal we received the signal and are going to exit the interrupt.
gcScanState.Add(1)
arm.Asm("sev")
}
// Pause the given core by sending it an interrupt.
func gcPauseCore(core uint32) {
rp.SIO.FIFO_WR.Set(1)
}
// Signal the given core that it can resume one step.
// This is called twice after gcPauseCore: the first time to scan the stack of
// the core, and the second time to end the stop-the-world phase.
func gcSignalCore(core uint32) {
gcSignalWait.Set(1)
arm.Asm("sev")
}
// Returns the stack top (highest address) of the system stack of the given
// core.
func coreStackTop(core uint32) uintptr {
switch core {
case 0:
return uintptr(unsafe.Pointer(&stackTopSymbol))
case 1:
return uintptr(unsafe.Pointer(&stack1TopSymbol))
default:
runtimePanic("unexpected core")
return 0
}
}
// These spinlocks are needed by the runtime.
var (
printLock = spinLock{id: 0}
schedulerLock = spinLock{id: 1}
atomicsLock = spinLock{id: 2}
futexLock = spinLock{id: 3}
)
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
type spinLock struct {
id uint8
}
// Return the spinlock register: rp.SIO.SPINLOCKx
func (l *spinLock) spinlock() *volatile.Register32 {
return (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&rp.SIO.SPINLOCK0), l.id*4))
}
func (l *spinLock) Lock() {
// Wait for the lock to be available.
spinlock := l.spinlock()
for spinlock.Get() == 0 {
// TODO: use wfe and send an event when unlocking so the CPU can go to
// sleep while waiting for the lock.
// Unfortunately when doing that, time.Sleep() seems to hang somewhere.
// This needs some debugging to figure out.
}
}
func (l *spinLock) Unlock() {
l.spinlock().Set(0)
}
// Wait until a signal is received, indicating that it can resume from the
// spinloop.
func spinLoopWait() {
arm.Asm("wfe")
}
func waitForEvents() {
arm.Asm("wfe")
}
func putchar(c byte) {
machine.Serial.WriteByte(c)
}
func getchar() byte {
for machine.Serial.Buffered() == 0 {
Gosched()
}
v, _ := machine.Serial.ReadByte()
return v
}
func buffered() int {
return machine.Serial.Buffered()
}
// machineInit is provided by package machine.
func machineInit()
func init() {
machineInit()
cdc.EnableUSBCDC()
machine.USBDev.Configure(machine.UARTConfig{})
machine.InitSerial()
}
//export Reset_Handler
func main() {
preinit()
run()
exit(0)
}
+358 -3
View File
@@ -3,10 +3,365 @@
package runtime
import (
"device/arm"
"device/rp"
"internal/task"
"machine"
"machine/usb/cdc"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
)
const (
sioIrqFifoProc0 = rp.IRQ_SIO_IRQ_PROC0
sioIrqFifoProc1 = rp.IRQ_SIO_IRQ_PROC1
const numCPU = 2
// machineTicks is provided by package machine.
func machineTicks() uint64
// machineLightSleep is provided by package machine.
func machineLightSleep(uint64)
// ticks returns the number of ticks (microseconds) elapsed since power up.
func ticks() timeUnit {
t := machineTicks()
return timeUnit(t)
}
func ticksToNanoseconds(ticks timeUnit) int64 {
return int64(ticks) * 1000
}
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns / 1000)
}
func sleepTicks(d timeUnit) {
if hasScheduler {
// With scheduler, sleepTicks may return early if an interrupt or
// event fires - so scheduler can schedule any go routines now
// eligible to run
machineLightSleep(uint64(d))
return
}
// Busy loop
sleepUntil := ticks() + d
for ticks() < sleepUntil {
}
}
// Currently sleeping core, or 0xff.
// Must only be accessed with the scheduler lock held.
var sleepingCore uint8 = 0xff
// Return whether another core is sleeping.
// May only be called with the scheduler lock held.
func hasSleepingCore() bool {
return sleepingCore != 0xff
}
// Almost identical to sleepTicks, except that it will unlock/lock the scheduler
// while sleeping and is interruptible by interruptSleepTicksMulticore.
// This may only be called with the scheduler lock held.
func sleepTicksMulticore(d timeUnit) {
sleepingCore = uint8(currentCPU())
// Note: interruptSleepTicksMulticore will be able to interrupt this, since
// it executes the "sev" instruction which would make sleepTicks return
// immediately without sleeping. Even if it happens while configuring the
// sleep operation.
schedulerLock.Unlock()
sleepTicks(d)
schedulerLock.Lock()
sleepingCore = 0xff
}
// Interrupt an ongoing call to sleepTicksMulticore on another core.
func interruptSleepTicksMulticore(wakeup timeUnit) {
arm.Asm("sev")
}
// Number of cores that are currently in schedulerUnlockAndWait.
// It is possible for both cores to be sleeping, if the program is waiting for
// an interrupt (or is deadlocked).
var waitingCore uint8
// Put the scheduler to sleep, since there are no tasks to run.
// This will unlock the scheduler lock, and must be called with the scheduler
// lock held.
func schedulerUnlockAndWait() {
waitingCore++
schedulerLock.Unlock()
arm.Asm("wfe")
schedulerLock.Lock()
waitingCore--
}
// Wake another core, if one is sleeping. Must be called with the scheduler lock
// held.
func schedulerWake() {
if waitingCore != 0 {
arm.Asm("sev")
}
}
// Return the current core number: 0 or 1.
func currentCPU() uint32 {
return rp.SIO.CPUID.Get()
}
// Start the secondary cores for this chip.
// On the RP2040, there is only one other core to start.
func startSecondaryCores() {
// Start the second core of the RP2040.
// See section 2.8.2 in the datasheet.
seq := 0
for {
cmd := core1StartSequence[seq]
if cmd == 0 {
multicore_fifo_drain()
arm.Asm("sev")
}
multicore_fifo_push_blocking(cmd)
response := multicore_fifo_pop_blocking()
if cmd != response {
seq = 0
continue
}
seq = seq + 1
if seq >= len(core1StartSequence) {
break
}
}
// Enable the FIFO interrupt for the GC stop the world phase.
// We can only do this after we don't need the FIFO anymore for starting the
// second core.
intr := interrupt.New(rp.IRQ_SIO_IRQ_PROC0, func(intr interrupt.Interrupt) {
switch rp.SIO.FIFO_RD.Get() {
case 1:
gcInterruptHandler(0)
}
})
intr.Enable()
intr.SetPriority(0xff)
}
var core1StartSequence = [...]uint32{
0, 0, 1,
uint32(uintptr(unsafe.Pointer(&__isr_vector))),
uint32(uintptr(unsafe.Pointer(&stack1TopSymbol))),
uint32(exportedFuncPtr(runCore1)),
}
//go:extern __isr_vector
var __isr_vector [0]uint32
//go:extern _stack1_top
var stack1TopSymbol [0]uint32
// The function that is started on the second core.
//
//export tinygo_runCore1
func runCore1() {
// Clear sticky bit that seems to have been set while starting this core.
rp.SIO.FIFO_ST.Set(rp.SIO_FIFO_ST_ROE)
// Enable the FIFO interrupt, mainly used for the stop-the-world phase of
// the GC.
// Use the lowest possible priority (highest priority value), so that other
// interrupts can still happen while the GC is running.
intr := interrupt.New(rp.IRQ_SIO_IRQ_PROC1, func(intr interrupt.Interrupt) {
switch rp.SIO.FIFO_RD.Get() {
case 1:
gcInterruptHandler(1)
}
})
intr.Enable()
intr.SetPriority(0xff)
// Now start running the scheduler on this core.
schedulerLock.Lock()
scheduler(false)
schedulerLock.Unlock()
// The main function returned.
exit(0)
}
// The below multicore_fifo_* functions have been translated from the Raspberry
// Pi Pico SDK.
func multicore_fifo_rvalid() bool {
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_VLD != 0
}
func multicore_fifo_wready() bool {
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_RDY != 0
}
func multicore_fifo_drain() {
for multicore_fifo_rvalid() {
rp.SIO.FIFO_RD.Get()
}
}
func multicore_fifo_push_blocking(data uint32) {
for !multicore_fifo_wready() {
}
rp.SIO.FIFO_WR.Set(data)
arm.Asm("sev")
}
func multicore_fifo_pop_blocking() uint32 {
for !multicore_fifo_rvalid() {
arm.Asm("wfe")
}
return rp.SIO.FIFO_RD.Get()
}
// Value used to communicate between the GC core and the other (paused) cores.
var gcSignalWait volatile.Register8
// The GC interrupted this core for the stop-the-world phase.
// This function handles that, and only returns after the stop-the-world phase
// ended.
func gcInterruptHandler(hartID uint32) {
// Let the GC know we're ready.
gcScanState.Add(1)
arm.Asm("sev")
// Wait until we get a signal to start scanning.
for gcSignalWait.Get() == 0 {
arm.Asm("wfe")
}
gcSignalWait.Set(0)
// Scan the stack(s) of this core.
scanCurrentStack()
if !task.OnSystemStack() {
// Mark system stack.
markRoots(task.SystemStack(), coreStackTop(hartID))
}
// Signal we've finished scanning.
gcScanState.Store(1)
arm.Asm("sev")
// Wait until we get a signal that the stop-the-world phase has ended.
for gcSignalWait.Get() == 0 {
arm.Asm("wfe")
}
gcSignalWait.Set(0)
// Signal we received the signal and are going to exit the interrupt.
gcScanState.Add(1)
arm.Asm("sev")
}
// Pause the given core by sending it an interrupt.
func gcPauseCore(core uint32) {
rp.SIO.FIFO_WR.Set(1)
}
// Signal the given core that it can resume one step.
// This is called twice after gcPauseCore: the first time to scan the stack of
// the core, and the second time to end the stop-the-world phase.
func gcSignalCore(core uint32) {
gcSignalWait.Set(1)
arm.Asm("sev")
}
// Returns the stack top (highest address) of the system stack of the given
// core.
func coreStackTop(core uint32) uintptr {
switch core {
case 0:
return uintptr(unsafe.Pointer(&stackTopSymbol))
case 1:
return uintptr(unsafe.Pointer(&stack1TopSymbol))
default:
runtimePanic("unexpected core")
return 0
}
}
// These spinlocks are needed by the runtime.
var (
printLock = spinLock{id: 0}
schedulerLock = spinLock{id: 1}
atomicsLock = spinLock{id: 2}
futexLock = spinLock{id: 3}
)
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
type spinLock struct {
id uint8
}
// Return the spinlock register: rp.SIO.SPINLOCKx
func (l *spinLock) spinlock() *volatile.Register32 {
return (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&rp.SIO.SPINLOCK0), l.id*4))
}
func (l *spinLock) Lock() {
// Wait for the lock to be available.
spinlock := l.spinlock()
for spinlock.Get() == 0 {
// TODO: use wfe and send an event when unlocking so the CPU can go to
// sleep while waiting for the lock.
// Unfortunately when doing that, time.Sleep() seems to hang somewhere.
// This needs some debugging to figure out.
}
}
func (l *spinLock) Unlock() {
l.spinlock().Set(0)
}
// Wait until a signal is received, indicating that it can resume from the
// spinloop.
func spinLoopWait() {
arm.Asm("wfe")
}
func waitForEvents() {
arm.Asm("wfe")
}
func putchar(c byte) {
machine.Serial.WriteByte(c)
}
func getchar() byte {
for machine.Serial.Buffered() == 0 {
Gosched()
}
v, _ := machine.Serial.ReadByte()
return v
}
func buffered() int {
return machine.Serial.Buffered()
}
// machineInit is provided by package machine.
func machineInit()
func init() {
machineInit()
cdc.EnableUSBCDC()
machine.USBDev.Configure(machine.UARTConfig{})
machine.InitSerial()
}
//export Reset_Handler
func main() {
preinit()
run()
exit(0)
}
+79 -9
View File
@@ -3,14 +3,84 @@
package runtime
import (
"device/rp"
"device/arm"
"machine"
"machine/usb/cdc"
)
const (
// On RP2040 each core has a different IRQ number: SIO_IRQ_PROC0 and SIO_IRQ_PROC1.
// On RP2350 both cores share the same irq number (SIO_IRQ_PROC) just with a
// different SIO interrupt output routed to that IRQ input on each core.
// https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#group_pico_multicore_1ga1413ebfa65114c6f408f4675897ac5ee
sioIrqFifoProc0 = rp.IRQ_SIO_IRQ_FIFO
sioIrqFifoProc1 = rp.IRQ_SIO_IRQ_FIFO
)
// machineTicks is provided by package machine.
func machineTicks() uint64
// machineLightSleep is provided by package machine.
func machineLightSleep(uint64)
// ticks returns the number of ticks (microseconds) elapsed since power up.
func ticks() timeUnit {
t := machineTicks()
return timeUnit(t)
}
func ticksToNanoseconds(ticks timeUnit) int64 {
return int64(ticks) * 1000
}
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns / 1000)
}
func sleepTicks(d timeUnit) {
if d <= 0 {
return
}
if hasScheduler {
// With scheduler, sleepTicks may return early if an interrupt or
// event fires - so scheduler can schedule any go routines now
// eligible to run
machineLightSleep(uint64(d))
return
}
// Busy loop
sleepUntil := ticks() + d
for ticks() < sleepUntil {
}
}
func waitForEvents() {
arm.Asm("wfe")
}
func putchar(c byte) {
machine.Serial.WriteByte(c)
}
func getchar() byte {
for machine.Serial.Buffered() == 0 {
Gosched()
}
v, _ := machine.Serial.ReadByte()
return v
}
func buffered() int {
return machine.Serial.Buffered()
}
// machineInit is provided by package machine.
func machineInit()
func init() {
machineInit()
cdc.EnableUSBCDC()
machine.USBDev.Configure(machine.UARTConfig{})
machine.InitSerial()
}
//export Reset_Handler
func main() {
preinit()
run()
exit(0)
}
+1 -1
View File
@@ -77,6 +77,7 @@ func addSleepTask(t *task.Task, duration timeUnit) {
panic("runtime: addSleepTask: expected next task to be nil")
}
}
t.Data = uint64(duration)
now := ticks()
if sleepQueue == nil {
scheduleLog(" -> sleep new queue")
@@ -84,7 +85,6 @@ func addSleepTask(t *task.Task, duration timeUnit) {
// set new base time
sleepQueueBaseTime = now
}
t.Data = uint64(duration + (now - sleepQueueBaseTime))
// Add to sleep queue.
q := &sleepQueue
-6
View File
@@ -46,9 +46,3 @@ func timerCallback(tn *timerNode, delta int64) {
addTimer(tn)
}
}
//go:linkname time_runtimeIsBubbled time.runtimeIsBubbled
func time_runtimeIsBubbled() bool {
// We don't currently support bubbles.
return false
}
-12
View File
@@ -70,15 +70,3 @@ func (m *Map) Range(f func(key, value interface{}) bool) {
}
}
}
// Swap replaces the value for the given key, and returns the old value if any.
func (m *Map) Swap(key, value any) (previous any, loaded bool) {
m.lock.Lock()
defer m.lock.Unlock()
if m.m == nil {
m.m = make(map[interface{}]interface{})
}
previous, loaded = m.m[key]
m.m[key] = value
return
}
-19
View File
@@ -17,22 +17,3 @@ func TestMapLoadAndDelete(t *testing.T) {
t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok)
}
}
func TestMapSwap(t *testing.T) {
var sm sync.Map
sm.Store("present", "value")
if v, ok := sm.Swap("present", "value2"); !ok || v != "value" {
t.Errorf("Swap returned %v, %v, want value, true", v, ok)
}
if v, ok := sm.Load("present"); !ok || v != "value2" {
t.Errorf("Load after Swap returned %v, %v, want value2, true", v, ok)
}
if v, ok := sm.Swap("new", "foo"); ok || v != nil {
t.Errorf("Swap returned %v, %v, want nil, false", v, ok)
}
if v, ok := sm.Load("present"); !ok || v != "value2" {
t.Errorf("Load after Swap returned %v, %v, want foo, true", v, ok)
}
}
-4
View File
@@ -500,10 +500,6 @@ func (b *B) RunParallel(body func(*PB)) {
return
}
func (b *B) Loop() bool {
panic("unimplemented: testing.B.Loop")
}
// Benchmark benchmarks a single function. It is useful for creating
// custom benchmarks that do not use the "go test" command.
//
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["badger2040_w", "cyw43439"],
"ldflags": [
"--defsym=__flash_size=1020K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["badger2040"],
"ldflags": [
"--defsym=__flash_size=1020K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:1023"],
"default-stack-size": 8192,
"build-tags": ["challenger_rp2040"],
"ldflags": [
"--defsym=__flash_size=8M"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["239a:80f1"],
"default-stack-size": 8192,
"build-tags": ["feather_rp2040"],
"ldflags": [
"--defsym=__flash_size=8192K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["gopher_badge"],
"ldflags": [
"--defsym=__flash_size=8M"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"build-tags": ["macropad_rp2040"],
"default-stack-size": 8192,
"serial-port": ["239a:8107"],
"ldflags": [
"--defsym=__flash_size=8M"
-11
View File
@@ -1,11 +0,0 @@
{
"inherits": [
"rp2350b"
],
"build-tags": ["metro_rp2350"],
"serial-port": ["239a:814e"],
"default-stack-size": 8192,
"ldflags": [
"--defsym=__flash_size=16M"
]
}
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2341:005e"],
"default-stack-size": 8192,
"build-tags": ["nano_rp2040", "ninafw", "ninafw_machine_init"],
"ldflags": [
"--defsym=__flash_size=16M"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["239a:80f7"],
"default-stack-size": 8192,
"build-tags": ["qtpy_rp2040"],
"ldflags": [
"--defsym=__flash_size=8192K"
+1 -3
View File
@@ -1,7 +1,6 @@
{
"inherits": ["cortex-m33"],
"build-tags": ["rp2350", "rp"],
"scheduler": "cores",
"flash-1200-bps-reset": "true",
"flash-method": "msd",
"serial": "usb",
@@ -14,8 +13,7 @@
"targets/rp2350_embedded_block.s"
],
"ldflags": [
"--defsym=__flash_size=2M",
"--defsym=__num_stacks=2"
"--defsym=__flash_size=2M"
],
"linkerscript": "targets/rp2350.ld",
"openocd-interface": "picoprobe",
+1 -2
View File
@@ -6,6 +6,5 @@
"ldflags": [
"--defsym=__flash_size=4M"
],
"serial-port": ["2e8a:000f"],
"default-stack-size": 8192
"serial-port": ["2e8a:000f"]
}
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["239a:8109"],
"default-stack-size": 8192,
"build-tags": ["trinkey_qt2040"],
"ldflags": [
"--defsym=__flash_size=8192K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["tufty2040"],
"ldflags": [
"--defsym=__flash_size=1020K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["waveshare_rp2040_tiny"],
"ldflags": [
"--defsym=__flash_size=1020K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:0003"],
"default-stack-size": 8192,
"build-tags": ["waveshare_rp2040_zero"],
"ldflags": [
"--defsym=__flash_size=1020K"
-1
View File
@@ -3,7 +3,6 @@
"rp2040"
],
"serial-port": ["2e8a:000a"],
"default-stack-size": 8192,
"build-tags": ["xiao_rp2040"],
"ldflags": [
"--defsym=__flash_size=1020K"
+3 -3
View File
@@ -14,9 +14,9 @@ func init() {
func main() {
println("main 1")
go sub()
time.Sleep(100 * time.Millisecond)
time.Sleep(1 * time.Millisecond)
println("main 2")
time.Sleep(200 * time.Millisecond)
time.Sleep(2 * time.Millisecond)
println("main 3")
// Await a blocking call.
@@ -103,7 +103,7 @@ func acquire(m *sync.Mutex, wg *sync.WaitGroup) {
func sub() {
println("sub 1")
time.Sleep(200 * time.Millisecond)
time.Sleep(2 * time.Millisecond)
println("sub 2")
}