mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b9ce6c3374 | |||
| cab3834bc9 | |||
| 7f970a45c2 | |||
| ebf70ab18e | |||
| 226744a538 | |||
| dc876c6ed4 | |||
| 5a09084c73 | |||
| 6c9074772c | |||
| e49663809b | |||
| 7d6d93f7aa | |||
| 8c54e3dd88 | |||
| 47c0debe4b | |||
| 9a1cde40a8 | |||
| 20fc814635 | |||
| 64d8a04308 | |||
| b95effbdd7 | |||
| 92c130c7be | |||
| 31c4bc1151 | |||
| 42f5e55ed5 | |||
| 81da7bb4c1 | |||
| 209754493b | |||
| b0aef96340 | |||
| 056394e24b | |||
| 1545659817 | |||
| 38e3d55e64 | |||
| 66da29e89f | |||
| c180d6fe2f | |||
| cdea833b5c | |||
| c2eaa495df | |||
| 3476100dd0 | |||
| 07c7eff3c3 | |||
| a1be8cd9fe | |||
| 52b9fcd57f | |||
| ea53ace270 | |||
| a6cd072fa1 | |||
| 4372dbdd41 |
@@ -109,9 +109,9 @@ jobs:
|
||||
# "make lint" fails before go 1.21 because internal/tools/go.mod specifies packages that require go 1.21
|
||||
fmt-check: false
|
||||
resource_class: large
|
||||
test-llvm19-go123:
|
||||
test-llvm19-go124:
|
||||
docker:
|
||||
- image: golang:1.23-bullseye
|
||||
- image: golang:1.24-bullseye
|
||||
steps:
|
||||
- test-linux:
|
||||
llvm: "19"
|
||||
@@ -124,4 +124,4 @@ workflows:
|
||||
# least the smoke tests still pass.
|
||||
- test-llvm15-go119
|
||||
# This tests LLVM 19 support when linking against system libraries.
|
||||
- test-llvm19-go123
|
||||
- test-llvm19-go124
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Restore LLVM source cache
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -143,7 +143,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Build TinyGo (LLVM ${{ matrix.version }})
|
||||
run: go install -tags=llvm${{ matrix.version }}
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
# statically linked binary.
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:1.23-alpine
|
||||
image: golang:1.24-alpine
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
steps:
|
||||
@@ -146,7 +146,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Install wasmtime
|
||||
uses: bytecodealliance/actions/wasmtime/setup@v1
|
||||
@@ -165,6 +165,7 @@ jobs:
|
||||
ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo
|
||||
- run: make tinygo-test-wasip1-fast
|
||||
- run: make tinygo-test-wasip2-fast
|
||||
- run: make tinygo-test-wasm
|
||||
- run: make smoketest
|
||||
assert-test-linux:
|
||||
# Run all tests that can run on Linux, with LLVM assertions enabled to catch
|
||||
@@ -189,7 +190,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
@@ -277,7 +278,7 @@ jobs:
|
||||
run: make tinygo-test
|
||||
- run: make smoketest
|
||||
- run: make wasmtest
|
||||
- run: make tinygo-baremetal
|
||||
- run: make tinygo-test-baremetal
|
||||
build-linux-cross:
|
||||
# Build ARM Linux binaries, ready for release.
|
||||
# This intentionally uses an older Linux image, so that we compile against
|
||||
@@ -297,7 +298,7 @@ jobs:
|
||||
- goarch: arm
|
||||
toolchain: arm-linux-gnueabihf
|
||||
libc: armhf
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04 # note: use the oldest image available! (see above)
|
||||
needs: build-linux
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -315,7 +316,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Restore LLVM source cache
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -346,7 +347,7 @@ jobs:
|
||||
uses: actions/cache/restore@v4
|
||||
id: cache-llvm-build
|
||||
with:
|
||||
key: llvm-build-19-linux-${{ matrix.goarch }}-v2
|
||||
key: llvm-build-19-linux-${{ matrix.goarch }}-v3
|
||||
path: llvm-build
|
||||
- name: Build LLVM
|
||||
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
||||
|
||||
@@ -11,6 +11,7 @@ name: LLVM
|
||||
on:
|
||||
push:
|
||||
branches: [ build-llvm-image ]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Restore cached LLVM source
|
||||
uses: actions/cache/restore@v4
|
||||
@@ -156,7 +156,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Download TinyGo build
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -186,7 +186,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Download TinyGo build
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -222,7 +222,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
go-version: '1.24'
|
||||
cache: true
|
||||
- name: Download TinyGo build
|
||||
uses: actions/download-artifact@v4
|
||||
|
||||
@@ -1,3 +1,72 @@
|
||||
0.36.0
|
||||
---
|
||||
* **general**
|
||||
- add initial Go 1.24 support
|
||||
- add support for LLVM 19
|
||||
- update license for 2025
|
||||
- make small corrections for README regarding wasm
|
||||
- use GOOS and GOARCH for building wasm simulated boards
|
||||
- only infer target for wasm when GOOS and GOARCH are set correctly, not just based on file extension
|
||||
- add test-corpus-wasip2
|
||||
- use older image for cross-compiling builds
|
||||
- update Linux builds to run on ubuntu-latest since 20.04 is being retired
|
||||
- ensure build output directory is created
|
||||
- add NoSandbox flag to chrome headless that is run during WASM tests, since this is now required for Ubuntu 23+ and we are using Ubuntu 24+ when running Github Actions
|
||||
- update wasmtime used for CI to 29.0.1 to fix issue with install during CI tests
|
||||
- update to use `Get-CimInstance` as `wmic` is being deprecated on WIndows
|
||||
- remove unnecessary executable permissions
|
||||
- `goenv`: update to new v0.36.0 development version
|
||||
* **compiler**
|
||||
- `builder`: fix parsing of external ld.lld error messages
|
||||
- `cgo`: mangle identifier names
|
||||
- `interp`: correctly mark functions as modifying memory
|
||||
- add buildmode=wasi-legacy to support existing base of users who expected the older behavior for wasi modules to not return an exit code as if they were reactors
|
||||
* **standard library**
|
||||
- `crypto/tls`: add Dialer.DialContext() to fix websocket client
|
||||
- `crypto/tls`: add VersionTLS constants and VersionName(version uint16) method that turns it into a string, copied from big go
|
||||
- `internal/syscall/unix`: use our own version of this package
|
||||
- `machine`: replace hard-coded cpu frequencies on rp2xxx
|
||||
- `machine`: bump rp2350 CPUFrequency to 150 MHz
|
||||
- `machine`: compute rp2 clock dividers from crystal and target frequency
|
||||
- `machine`: remove bytes package dependency in flash code
|
||||
- `machine/usb/descriptor`: avoid bytes package
|
||||
- `net`: update to latest submodule with httptest subpackage and ResolveIPAddress implementation
|
||||
- `os`: add File.Chdir support
|
||||
- `os`: implement stub Chdir for non-OS systems
|
||||
- `os/file`: add file.Chmod
|
||||
- `reflect`: implement Value.Equal
|
||||
- `runtime`: add FIPS helper functions
|
||||
- `runtime`: manually initialize xorshift state
|
||||
- `sync`: move Mutex to internal/task
|
||||
- `syscall`: add wasip1 RandomGet
|
||||
- `testing`: add Chdir
|
||||
- `wasip2`: add stubs to get internal/syscall/unix to work
|
||||
* **fixes**
|
||||
- correctly handle calls for GetRNG() when being made from nrf devices with SoftDevice enabled
|
||||
- fix stm32f103 ADC
|
||||
- `wasm`: correctly handle id lookup for finalizeRef call
|
||||
- `wasm`: avoid total failure on wasm finalizer call
|
||||
- `wasm`: convert offset as signed int into unsigned int in syscall/js.stringVal in wasm_exec.js
|
||||
* **targets**
|
||||
- rp2350: add pll generalized solution; fix ADC handles; pwm period fix
|
||||
- rp2350: extending support to include the rp2350b
|
||||
- rp2350: cleanup: unexport internal USB and clock package variable, consts and types
|
||||
- nrf: make ADC resolution changeable
|
||||
- turn on GC for TKey1 device, since it does in fact work
|
||||
- match Pico2 stack size to Pico
|
||||
* **boards**
|
||||
- add support for Pimoroni Pico Plus2
|
||||
- add target for pico2-w board
|
||||
- add comboat_fw tag for elecrow W5 boards with Combo-AT Wifi firmware
|
||||
- add support for Elecrow Pico rp2350 W5 boards
|
||||
- add support for Elecrow Pico rp2040 W5 boards
|
||||
- add support for NRF51 HW-651
|
||||
- add support for esp32c3-supermini
|
||||
- add support for waveshare-rp2040-tiny
|
||||
* **examples**
|
||||
- add naive debouncing for pininterrupt example
|
||||
|
||||
|
||||
0.35.0
|
||||
---
|
||||
* **general**
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
# tinygo-llvm stage obtains the llvm source for TinyGo
|
||||
FROM golang:1.23 AS tinygo-llvm
|
||||
FROM golang:1.24 AS tinygo-llvm
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y apt-utils make cmake clang-15 ninja-build && \
|
||||
@@ -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.23 AS tinygo-compiler
|
||||
FROM golang:1.24 AS tinygo-compiler
|
||||
|
||||
# Copy tinygo build.
|
||||
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
|
||||
|
||||
+59
-23
@@ -309,11 +309,9 @@ TEST_PACKAGES_FAST = \
|
||||
container/heap \
|
||||
container/list \
|
||||
container/ring \
|
||||
crypto/des \
|
||||
crypto/ecdsa \
|
||||
crypto/elliptic \
|
||||
crypto/md5 \
|
||||
crypto/rc4 \
|
||||
crypto/sha1 \
|
||||
crypto/sha256 \
|
||||
crypto/sha512 \
|
||||
@@ -355,17 +353,11 @@ TEST_PACKAGES_FAST = \
|
||||
unique \
|
||||
$(nil)
|
||||
|
||||
# Assume this will go away before Go2, so only check minor version.
|
||||
ifeq ($(filter $(shell $(GO) env GOVERSION | cut -f 2 -d.), 16 17 18), )
|
||||
TEST_PACKAGES_FAST += crypto/internal/nistec/fiat
|
||||
else
|
||||
TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat
|
||||
endif
|
||||
|
||||
# archive/zip requires os.ReadAt, which is not yet supported on windows
|
||||
# bytes requires mmap
|
||||
# compress/flate appears to hang on wasi
|
||||
# crypto/aes fails on wasi, needs panic()/recover()
|
||||
# crypto/des fails on wasi, needs panic()/recover()
|
||||
# crypto/hmac fails on wasi, it exits with a "slice out of range" panic
|
||||
# debug/plan9obj requires os.ReadAt, which is not yet supported on windows
|
||||
# image requires recover(), which is not yet supported on wasi
|
||||
@@ -386,6 +378,7 @@ TEST_PACKAGES_LINUX := \
|
||||
archive/zip \
|
||||
compress/flate \
|
||||
crypto/aes \
|
||||
crypto/des \
|
||||
crypto/hmac \
|
||||
debug/dwarf \
|
||||
debug/plan9obj \
|
||||
@@ -405,14 +398,52 @@ TEST_PACKAGES_LINUX := \
|
||||
|
||||
TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX)
|
||||
|
||||
# os/user requires t.Skip() support
|
||||
TEST_PACKAGES_WINDOWS := \
|
||||
compress/flate \
|
||||
crypto/des \
|
||||
crypto/hmac \
|
||||
os/user \
|
||||
strconv \
|
||||
text/template/parse \
|
||||
$(nil)
|
||||
|
||||
|
||||
# These packages cannot be tested on wasm, mostly because these tests assume a
|
||||
# working filesystem. This could perhaps be fixed, by supporting filesystem
|
||||
# access when running inside Node.js.
|
||||
TEST_PACKAGES_WASM = $(filter-out $(TEST_PACKAGES_NONWASM), $(TEST_PACKAGES_FAST))
|
||||
TEST_PACKAGES_NONWASM = \
|
||||
compress/lzw \
|
||||
compress/zlib \
|
||||
crypto/ecdsa \
|
||||
debug/macho \
|
||||
embed/internal/embedtest \
|
||||
go/format \
|
||||
os \
|
||||
testing \
|
||||
$(nil)
|
||||
|
||||
# These packages cannot be tested on baremetal.
|
||||
#
|
||||
# Some reasons why the tests don't pass on baremetal:
|
||||
#
|
||||
# * No filesystem is available, so packages like compress/zlib can't be tested
|
||||
# (just like wasm).
|
||||
# * picolibc math functions apparently are less precise, the math package
|
||||
# fails on baremetal.
|
||||
# * Some packages fail or hang for an unknown reason, this should be
|
||||
# investigated and fixed.
|
||||
TEST_PACKAGES_BAREMETAL = $(filter-out $(TEST_PACKAGES_NONBAREMETAL), $(TEST_PACKAGES_FAST))
|
||||
TEST_PACKAGES_NONBAREMETAL = \
|
||||
$(TEST_PACKAGES_NONWASM) \
|
||||
crypto/elliptic \
|
||||
math \
|
||||
reflect \
|
||||
encoding/asn1 \
|
||||
encoding/base32 \
|
||||
go/ast \
|
||||
$(nil)
|
||||
|
||||
# Report platforms on which each standard library package is known to pass tests
|
||||
jointmp := $(shell echo /tmp/join.$$$$)
|
||||
report-stdlib-tests-pass:
|
||||
@@ -456,6 +487,8 @@ tinygo-bench-fast:
|
||||
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST)
|
||||
|
||||
# Same thing, except for wasi rather than the current platform.
|
||||
tinygo-test-wasm:
|
||||
$(TINYGO) test -target wasm $(TEST_PACKAGES_WASM)
|
||||
tinygo-test-wasi:
|
||||
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
||||
tinygo-test-wasip1:
|
||||
@@ -490,6 +523,10 @@ tinygo-bench-wasip2:
|
||||
tinygo-bench-wasip2-fast:
|
||||
$(TINYGO) test -target wasip2 -bench . $(TEST_PACKAGES_FAST)
|
||||
|
||||
# Run tests on riscv-qemu since that one provides a large amount of memory.
|
||||
tinygo-test-baremetal:
|
||||
$(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL)
|
||||
|
||||
# Test external packages in a large corpus.
|
||||
test-corpus:
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml
|
||||
@@ -497,11 +534,8 @@ test-corpus-fast:
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
|
||||
test-corpus-wasi: wasi-libc
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
|
||||
|
||||
tinygo-baremetal:
|
||||
# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
|
||||
# regression test for #2666: e.g. encoding/hex must pass on baremetal
|
||||
$(TINYGO) test -target cortex-m-qemu encoding/hex
|
||||
test-corpus-wasip2: wasi-libc
|
||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip2
|
||||
|
||||
.PHONY: testchdir
|
||||
testchdir:
|
||||
@@ -573,21 +607,23 @@ smoketest: testchdir
|
||||
@$(MD5SUM) test.hex
|
||||
# test simulated boards on play.tinygo.org
|
||||
ifneq ($(WASM), 0)
|
||||
$(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
|
||||
@$(MD5SUM) test.wasm
|
||||
$(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=pico examples/blinky1
|
||||
@$(MD5SUM) test.wasm
|
||||
endif
|
||||
# test all targets/boards
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Copyright (c) 2018-2023 The TinyGo Authors. All rights reserved.
|
||||
Copyright (c) 2018-2025 The TinyGo Authors. All rights reserved.
|
||||
|
||||
TinyGo includes portions of the Go standard library.
|
||||
Copyright (c) 2009-2023 The Go Authors. All rights reserved.
|
||||
Copyright (c) 2009-2024 The Go Authors. All rights reserved.
|
||||
|
||||
TinyGo includes portions of LLVM, which is under the Apache License v2.0 with
|
||||
LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
|
||||
|
||||
@@ -48,20 +48,22 @@ Here is a small TinyGo program for use by a WASI host application:
|
||||
```go
|
||||
package main
|
||||
|
||||
//go:wasm-module yourmodulename
|
||||
//export add
|
||||
//go:wasmexport add
|
||||
func add(x, y uint32) uint32 {
|
||||
return x + y
|
||||
}
|
||||
|
||||
// main is required for the `wasip1` target, even if it isn't used.
|
||||
func main() {}
|
||||
```
|
||||
|
||||
This compiles the above TinyGo program for use on any WASI runtime:
|
||||
This compiles the above TinyGo program for use on any WASI Preview 1 runtime:
|
||||
|
||||
```shell
|
||||
tinygo build -o main.wasm -target=wasip1 main.go
|
||||
tinygo build -buildmode=c-shared -o add.wasm -target=wasip1 add.go
|
||||
```
|
||||
|
||||
You can also use the same syntax as Go 1.24+:
|
||||
|
||||
```shell
|
||||
GOARCH=wasip1 GOOS=wasm tinygo build -buildmode=c-shared -o add.wasm add.go
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -69,7 +69,6 @@ func TestClangAttributes(t *testing.T) {
|
||||
{GOOS: "darwin", GOARCH: "arm64"},
|
||||
{GOOS: "windows", GOARCH: "amd64"},
|
||||
{GOOS: "windows", GOARCH: "arm64"},
|
||||
{GOOS: "wasip1", GOARCH: "wasm"},
|
||||
} {
|
||||
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
||||
if options.GOARCH == "arm" {
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
|
||||
|
||||
// Version range supported by TinyGo.
|
||||
const minorMin = 19
|
||||
const minorMax = 23
|
||||
const minorMax = 24
|
||||
|
||||
// Check that we support this Go toolchain version.
|
||||
gorootMajor, gorootMinor, err := goenv.GetGorootVersion()
|
||||
@@ -36,7 +36,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
|
||||
if gorootMajor != 1 || gorootMinor < minorMin || gorootMinor > minorMax {
|
||||
// Note: when this gets updated, also update the Go compatibility matrix:
|
||||
// https://github.com/tinygo-org/tinygo-site/blob/dev/content/docs/reference/go-compat-matrix.md
|
||||
return nil, fmt.Errorf("requires go version 1.19 through 1.23, got go%d.%d", gorootMajor, gorootMinor)
|
||||
return nil, fmt.Errorf("requires go version 1.%d through 1.%d, got go%d.%d", minorMin, minorMax, gorootMajor, gorootMinor)
|
||||
}
|
||||
|
||||
// Check that the Go toolchain version isn't too new, if we haven't been
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestBinarySize(t *testing.T) {
|
||||
// microcontrollers
|
||||
{"hifive1b", "examples/echo", 4560, 280, 0, 2268},
|
||||
{"microbit", "examples/serial", 2916, 388, 8, 2272},
|
||||
{"wioterminal", "examples/pininterrupt", 7315, 1489, 116, 6912},
|
||||
{"wioterminal", "examples/pininterrupt", 7359, 1489, 116, 6912},
|
||||
|
||||
// TODO: also check wasm. Right now this is difficult, because
|
||||
// wasm binaries are run through wasm-opt and therefore the
|
||||
|
||||
+45
-64
@@ -92,18 +92,18 @@ type noescapingFunc struct {
|
||||
// cgoAliases list type aliases between Go and C, for types that are equivalent
|
||||
// in both languages. See addTypeAliases.
|
||||
var cgoAliases = map[string]string{
|
||||
"C.int8_t": "int8",
|
||||
"C.int16_t": "int16",
|
||||
"C.int32_t": "int32",
|
||||
"C.int64_t": "int64",
|
||||
"C.uint8_t": "uint8",
|
||||
"C.uint16_t": "uint16",
|
||||
"C.uint32_t": "uint32",
|
||||
"C.uint64_t": "uint64",
|
||||
"C.uintptr_t": "uintptr",
|
||||
"C.float": "float32",
|
||||
"C.double": "float64",
|
||||
"C._Bool": "bool",
|
||||
"_Cgo_int8_t": "int8",
|
||||
"_Cgo_int16_t": "int16",
|
||||
"_Cgo_int32_t": "int32",
|
||||
"_Cgo_int64_t": "int64",
|
||||
"_Cgo_uint8_t": "uint8",
|
||||
"_Cgo_uint16_t": "uint16",
|
||||
"_Cgo_uint32_t": "uint32",
|
||||
"_Cgo_uint64_t": "uint64",
|
||||
"_Cgo_uintptr_t": "uintptr",
|
||||
"_Cgo_float": "float32",
|
||||
"_Cgo_double": "float64",
|
||||
"_Cgo__Bool": "bool",
|
||||
}
|
||||
|
||||
// builtinAliases are handled specially because they only exist on the Go side
|
||||
@@ -145,48 +145,46 @@ typedef unsigned long long _Cgo_ulonglong;
|
||||
// The string/bytes functions below implement C.CString etc. To make sure the
|
||||
// runtime doesn't need to know the C int type, lengths are converted to uintptr
|
||||
// first.
|
||||
// These functions will be modified to get a "C." prefix, so the source below
|
||||
// doesn't reflect the final AST.
|
||||
const generatedGoFilePrefixBase = `
|
||||
import "syscall"
|
||||
import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func __GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func __GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func __CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func __get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
`
|
||||
|
||||
const generatedGoFilePrefixOther = generatedGoFilePrefixBase + `
|
||||
func __get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
`
|
||||
|
||||
@@ -197,7 +195,7 @@ func __get_errno() error {
|
||||
// map the errno values to match the values in the syscall package.
|
||||
// Source of the errno values: lib/mingw-w64/mingw-w64-headers/crt/errno.h
|
||||
const generatedGoFilePrefixWindows = generatedGoFilePrefixBase + `
|
||||
var __errno_mapping = [...]syscall.Errno{
|
||||
var _Cgo___errno_mapping = [...]syscall.Errno{
|
||||
1: syscall.EPERM,
|
||||
2: syscall.ENOENT,
|
||||
3: syscall.ESRCH,
|
||||
@@ -238,10 +236,10 @@ var __errno_mapping = [...]syscall.Errno{
|
||||
42: syscall.EILSEQ,
|
||||
}
|
||||
|
||||
func __get_errno() error {
|
||||
num := C.__get_errno_num()
|
||||
if num < uintptr(len(__errno_mapping)) {
|
||||
if mapped := __errno_mapping[num]; mapped != 0 {
|
||||
func _Cgo___get_errno() error {
|
||||
num := _Cgo___get_errno_num()
|
||||
if num < uintptr(len(_Cgo___errno_mapping)) {
|
||||
if mapped := _Cgo___errno_mapping[num]; mapped != 0 {
|
||||
return mapped
|
||||
}
|
||||
}
|
||||
@@ -304,23 +302,6 @@ func Process(files []*ast.File, dir, importPath string, fset *token.FileSet, cfl
|
||||
// If the Comments field is not set to nil, the go/format package will get
|
||||
// confused about where comments should go.
|
||||
p.generated.Comments = nil
|
||||
// Adjust some of the functions in there.
|
||||
for _, decl := range p.generated.Decls {
|
||||
switch decl := decl.(type) {
|
||||
case *ast.FuncDecl:
|
||||
switch decl.Name.Name {
|
||||
case "CString", "GoString", "GoStringN", "__GoStringN", "GoBytes", "__GoBytes", "CBytes", "__CBytes", "__get_errno_num", "__get_errno", "__errno_mapping":
|
||||
// Adjust the name to have a "C." prefix so it is correctly
|
||||
// resolved.
|
||||
decl.Name.Name = "C." + decl.Name.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
// Patch some types, for example *C.char in C.CString.
|
||||
cf := p.newCGoFile(nil, -1) // dummy *cgoFile for the walker
|
||||
astutil.Apply(p.generated, func(cursor *astutil.Cursor) bool {
|
||||
return cf.walker(cursor, nil)
|
||||
}, nil)
|
||||
|
||||
// Find `import "C"` C fragments in the file.
|
||||
p.cgoHeaders = make([]string, len(files)) // combined CGo header fragment for each file
|
||||
@@ -399,7 +380,7 @@ func Process(files []*ast.File, dir, importPath string, fset *token.FileSet, cfl
|
||||
Tok: token.TYPE,
|
||||
}
|
||||
for _, name := range builtinAliases {
|
||||
typeSpec := p.getIntegerType("C."+name, names["_Cgo_"+name])
|
||||
typeSpec := p.getIntegerType("_Cgo_"+name, names["_Cgo_"+name])
|
||||
gen.Specs = append(gen.Specs, typeSpec)
|
||||
}
|
||||
p.generated.Decls = append(p.generated.Decls, gen)
|
||||
@@ -1272,7 +1253,7 @@ func (p *cgoPackage) getUnnamedDeclName(prefix string, itf interface{}) string {
|
||||
func (f *cgoFile) getASTDeclName(name string, found clangCursor, iscall bool) string {
|
||||
// Some types are defined in stdint.h and map directly to a particular Go
|
||||
// type.
|
||||
if alias := cgoAliases["C."+name]; alias != "" {
|
||||
if alias := cgoAliases["_Cgo_"+name]; alias != "" {
|
||||
return alias
|
||||
}
|
||||
node := f.getASTDeclNode(name, found)
|
||||
@@ -1282,7 +1263,7 @@ func (f *cgoFile) getASTDeclName(name string, found clangCursor, iscall bool) st
|
||||
}
|
||||
return node.Name.Name
|
||||
}
|
||||
return "C." + name
|
||||
return "_Cgo_" + name
|
||||
}
|
||||
|
||||
// getASTDeclNode will declare the given C AST node (if not already defined) and
|
||||
@@ -1382,8 +1363,8 @@ extern __typeof(%s) %s __attribute__((alias(%#v)));
|
||||
case *elaboratedTypeInfo:
|
||||
// Add struct bitfields.
|
||||
for _, bitfield := range elaboratedType.bitfields {
|
||||
f.createBitfieldGetter(bitfield, "C."+name)
|
||||
f.createBitfieldSetter(bitfield, "C."+name)
|
||||
f.createBitfieldGetter(bitfield, "_Cgo_"+name)
|
||||
f.createBitfieldSetter(bitfield, "_Cgo_"+name)
|
||||
}
|
||||
if elaboratedType.unionSize != 0 {
|
||||
// Create union getters/setters.
|
||||
@@ -1392,7 +1373,7 @@ extern __typeof(%s) %s __attribute__((alias(%#v)));
|
||||
f.addError(elaboratedType.pos, fmt.Sprintf("union must have field with a single name, it has %d names", len(field.Names)))
|
||||
continue
|
||||
}
|
||||
f.createUnionAccessor(field, "C."+name)
|
||||
f.createUnionAccessor(field, "_Cgo_"+name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1441,7 +1422,7 @@ func (f *cgoFile) walker(cursor *astutil.Cursor, names map[string]clangCursor) b
|
||||
node.Rhs = append(node.Rhs, &ast.CallExpr{
|
||||
Fun: &ast.Ident{
|
||||
NamePos: node.Lhs[1].End(),
|
||||
Name: "C.__get_errno",
|
||||
Name: "_Cgo___get_errno",
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1466,7 +1447,7 @@ func (f *cgoFile) walker(cursor *astutil.Cursor, names map[string]clangCursor) b
|
||||
return true
|
||||
}
|
||||
if x.Name == "C" {
|
||||
name := "C." + node.Sel.Name
|
||||
name := "_Cgo_" + node.Sel.Name
|
||||
if found, ok := names[node.Sel.Name]; ok {
|
||||
name = f.getASTDeclName(node.Sel.Name, found, false)
|
||||
}
|
||||
|
||||
+27
-27
@@ -219,7 +219,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
numArgs := int(C.tinygo_clang_Cursor_getNumArguments(c))
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Fun,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
}
|
||||
exportName := name
|
||||
localName := name
|
||||
@@ -257,7 +257,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
},
|
||||
Name: &ast.Ident{
|
||||
NamePos: pos,
|
||||
Name: "C." + localName,
|
||||
Name: "_Cgo_" + localName,
|
||||
Obj: obj,
|
||||
},
|
||||
Type: &ast.FuncType{
|
||||
@@ -319,7 +319,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
return decl, stringSignature
|
||||
case C.CXCursor_StructDecl, C.CXCursor_UnionDecl:
|
||||
typ := f.makeASTRecordType(c, pos)
|
||||
typeName := "C." + name
|
||||
typeName := "_Cgo_" + name
|
||||
typeExpr := typ.typeExpr
|
||||
if typ.unionSize != 0 {
|
||||
// Convert to a single-field struct type.
|
||||
@@ -340,7 +340,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
obj.Decl = typeSpec
|
||||
return typeSpec, typ
|
||||
case C.CXCursor_TypedefDecl:
|
||||
typeName := "C." + name
|
||||
typeName := "_Cgo_" + name
|
||||
underlyingType := C.tinygo_clang_getTypedefDeclUnderlyingType(c)
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Typ,
|
||||
@@ -378,12 +378,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
}
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Var,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
}
|
||||
valueSpec := &ast.ValueSpec{
|
||||
Names: []*ast.Ident{{
|
||||
NamePos: pos,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
Obj: obj,
|
||||
}},
|
||||
Type: typeExpr,
|
||||
@@ -407,12 +407,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
}
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Con,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
}
|
||||
valueSpec := &ast.ValueSpec{
|
||||
Names: []*ast.Ident{{
|
||||
NamePos: pos,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
Obj: obj,
|
||||
}},
|
||||
Values: []ast.Expr{expr},
|
||||
@@ -423,7 +423,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
case C.CXCursor_EnumDecl:
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Typ,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
}
|
||||
underlying := C.tinygo_clang_getEnumDeclIntegerType(c)
|
||||
// TODO: gc's CGo implementation uses types such as `uint32` for enums
|
||||
@@ -431,7 +431,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
typeSpec := &ast.TypeSpec{
|
||||
Name: &ast.Ident{
|
||||
NamePos: pos,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
Obj: obj,
|
||||
},
|
||||
Assign: pos,
|
||||
@@ -454,12 +454,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
|
||||
}
|
||||
obj := &ast.Object{
|
||||
Kind: ast.Con,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
}
|
||||
valueSpec := &ast.ValueSpec{
|
||||
Names: []*ast.Ident{{
|
||||
NamePos: pos,
|
||||
Name: "C." + name,
|
||||
Name: "_Cgo_" + name,
|
||||
Obj: obj,
|
||||
}},
|
||||
Values: []ast.Expr{expr},
|
||||
@@ -745,27 +745,27 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
|
||||
var typeName string
|
||||
switch typ.kind {
|
||||
case C.CXType_Char_S, C.CXType_Char_U:
|
||||
typeName = "C.char"
|
||||
typeName = "_Cgo_char"
|
||||
case C.CXType_SChar:
|
||||
typeName = "C.schar"
|
||||
typeName = "_Cgo_schar"
|
||||
case C.CXType_UChar:
|
||||
typeName = "C.uchar"
|
||||
typeName = "_Cgo_uchar"
|
||||
case C.CXType_Short:
|
||||
typeName = "C.short"
|
||||
typeName = "_Cgo_short"
|
||||
case C.CXType_UShort:
|
||||
typeName = "C.ushort"
|
||||
typeName = "_Cgo_ushort"
|
||||
case C.CXType_Int:
|
||||
typeName = "C.int"
|
||||
typeName = "_Cgo_int"
|
||||
case C.CXType_UInt:
|
||||
typeName = "C.uint"
|
||||
typeName = "_Cgo_uint"
|
||||
case C.CXType_Long:
|
||||
typeName = "C.long"
|
||||
typeName = "_Cgo_long"
|
||||
case C.CXType_ULong:
|
||||
typeName = "C.ulong"
|
||||
typeName = "_Cgo_ulong"
|
||||
case C.CXType_LongLong:
|
||||
typeName = "C.longlong"
|
||||
typeName = "_Cgo_longlong"
|
||||
case C.CXType_ULongLong:
|
||||
typeName = "C.ulonglong"
|
||||
typeName = "_Cgo_ulonglong"
|
||||
case C.CXType_Bool:
|
||||
typeName = "bool"
|
||||
case C.CXType_Float, C.CXType_Double, C.CXType_LongDouble:
|
||||
@@ -896,7 +896,7 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
|
||||
typeSpelling := getString(C.clang_getTypeSpelling(typ))
|
||||
typeKindSpelling := getString(C.clang_getTypeKindSpelling(typ.kind))
|
||||
f.addError(pos, fmt.Sprintf("unknown C type: %v (libclang type kind %s)", typeSpelling, typeKindSpelling))
|
||||
typeName = "C.<unknown>"
|
||||
typeName = "_Cgo_<unknown>"
|
||||
}
|
||||
return &ast.Ident{
|
||||
NamePos: pos,
|
||||
@@ -913,7 +913,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
|
||||
var goName string
|
||||
typeSize := C.clang_Type_getSizeOf(underlyingType)
|
||||
switch name {
|
||||
case "C.char":
|
||||
case "_Cgo_char":
|
||||
if typeSize != 1 {
|
||||
// This happens for some very special purpose architectures
|
||||
// (DSPs etc.) that are not currently targeted.
|
||||
@@ -926,7 +926,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
|
||||
case C.CXType_Char_U:
|
||||
goName = "uint8"
|
||||
}
|
||||
case "C.schar", "C.short", "C.int", "C.long", "C.longlong":
|
||||
case "_Cgo_schar", "_Cgo_short", "_Cgo_int", "_Cgo_long", "_Cgo_longlong":
|
||||
switch typeSize {
|
||||
case 1:
|
||||
goName = "int8"
|
||||
@@ -937,7 +937,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
|
||||
case 8:
|
||||
goName = "int64"
|
||||
}
|
||||
case "C.uchar", "C.ushort", "C.uint", "C.ulong", "C.ulonglong":
|
||||
case "_Cgo_uchar", "_Cgo_ushort", "_Cgo_uint", "_Cgo_ulong", "_Cgo_ulonglong":
|
||||
switch typeSize {
|
||||
case 1:
|
||||
goName = "uint8"
|
||||
|
||||
Vendored
+31
-31
@@ -5,50 +5,50 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
|
||||
Vendored
+38
-38
@@ -5,58 +5,58 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
|
||||
const C.foo = 3
|
||||
const C.bar = C.foo
|
||||
const C.unreferenced = 4
|
||||
const C.referenced = C.unreferenced
|
||||
const C.fnlike_val = 5
|
||||
const C.square_val = (20 * 20)
|
||||
const C.add_val = (3 + 5)
|
||||
const _Cgo_foo = 3
|
||||
const _Cgo_bar = _Cgo_foo
|
||||
const _Cgo_unreferenced = 4
|
||||
const _Cgo_referenced = _Cgo_unreferenced
|
||||
const _Cgo_fnlike_val = 5
|
||||
const _Cgo_square_val = (20 * 20)
|
||||
const _Cgo_add_val = (3 + 5)
|
||||
|
||||
Vendored
+46
-46
@@ -14,16 +14,16 @@
|
||||
// testdata/errors.go:3:1: function "unusedFunction" in #cgo noescape line is not used
|
||||
|
||||
// Type checking errors after CGo processing:
|
||||
// testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as C.char value in variable declaration (overflows)
|
||||
// testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as _Cgo_char value in variable declaration (overflows)
|
||||
// testdata/errors.go:105: unknown field z in struct literal
|
||||
// testdata/errors.go:108: undefined: C.SOME_CONST_1
|
||||
// testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows)
|
||||
// testdata/errors.go:112: undefined: C.SOME_CONST_4
|
||||
// testdata/errors.go:114: undefined: C.SOME_CONST_b
|
||||
// testdata/errors.go:116: undefined: C.SOME_CONST_startspace
|
||||
// testdata/errors.go:119: undefined: C.SOME_PARAM_CONST_invalid
|
||||
// testdata/errors.go:122: undefined: C.add_toomuch
|
||||
// testdata/errors.go:123: undefined: C.add_toolittle
|
||||
// testdata/errors.go:108: undefined: _Cgo_SOME_CONST_1
|
||||
// testdata/errors.go:110: cannot use _Cgo_SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows)
|
||||
// testdata/errors.go:112: undefined: _Cgo_SOME_CONST_4
|
||||
// testdata/errors.go:114: undefined: _Cgo_SOME_CONST_b
|
||||
// testdata/errors.go:116: undefined: _Cgo_SOME_CONST_startspace
|
||||
// testdata/errors.go:119: undefined: _Cgo_SOME_PARAM_CONST_invalid
|
||||
// testdata/errors.go:122: undefined: _Cgo_add_toomuch
|
||||
// testdata/errors.go:123: undefined: _Cgo_add_toolittle
|
||||
|
||||
package main
|
||||
|
||||
@@ -32,58 +32,58 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
type C.struct_point_t struct {
|
||||
x C.int
|
||||
y C.int
|
||||
type _Cgo_struct_point_t struct {
|
||||
x _Cgo_int
|
||||
y _Cgo_int
|
||||
}
|
||||
type C.point_t = C.struct_point_t
|
||||
type _Cgo_point_t = _Cgo_struct_point_t
|
||||
|
||||
const C.SOME_CONST_3 = 1234
|
||||
const C.SOME_PARAM_CONST_valid = 3 + 4
|
||||
const _Cgo_SOME_CONST_3 = 1234
|
||||
const _Cgo_SOME_PARAM_CONST_valid = 3 + 4
|
||||
|
||||
Vendored
+33
-33
@@ -10,53 +10,53 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
|
||||
const C.BAR = 3
|
||||
const C.FOO_H = 1
|
||||
const _Cgo_BAR = 3
|
||||
const _Cgo_FOO_H = 1
|
||||
|
||||
Vendored
+42
-42
@@ -5,80 +5,80 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
|
||||
//export foo
|
||||
func C.foo(a C.int, b C.int) C.int
|
||||
func _Cgo_foo(a _Cgo_int, b _Cgo_int) _Cgo_int
|
||||
|
||||
var C.foo$funcaddr unsafe.Pointer
|
||||
var _Cgo_foo$funcaddr unsafe.Pointer
|
||||
|
||||
//export variadic0
|
||||
//go:variadic
|
||||
func C.variadic0()
|
||||
func _Cgo_variadic0()
|
||||
|
||||
var C.variadic0$funcaddr unsafe.Pointer
|
||||
var _Cgo_variadic0$funcaddr unsafe.Pointer
|
||||
|
||||
//export variadic2
|
||||
//go:variadic
|
||||
func C.variadic2(x C.int, y C.int)
|
||||
func _Cgo_variadic2(x _Cgo_int, y _Cgo_int)
|
||||
|
||||
var C.variadic2$funcaddr unsafe.Pointer
|
||||
var _Cgo_variadic2$funcaddr unsafe.Pointer
|
||||
|
||||
//export _Cgo_static_173c95a79b6df1980521_staticfunc
|
||||
func C.staticfunc!symbols.go(x C.int)
|
||||
func _Cgo_staticfunc!symbols.go(x _Cgo_int)
|
||||
|
||||
var C.staticfunc!symbols.go$funcaddr unsafe.Pointer
|
||||
var _Cgo_staticfunc!symbols.go$funcaddr unsafe.Pointer
|
||||
|
||||
//export notEscapingFunction
|
||||
//go:noescape
|
||||
func C.notEscapingFunction(a *C.int)
|
||||
func _Cgo_notEscapingFunction(a *_Cgo_int)
|
||||
|
||||
var C.notEscapingFunction$funcaddr unsafe.Pointer
|
||||
var _Cgo_notEscapingFunction$funcaddr unsafe.Pointer
|
||||
//go:extern someValue
|
||||
var C.someValue C.int
|
||||
var _Cgo_someValue _Cgo_int
|
||||
|
||||
Vendored
+103
-99
@@ -5,158 +5,162 @@ import "unsafe"
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname C.CString runtime.cgo_CString
|
||||
func C.CString(string) *C.char
|
||||
//go:linkname _Cgo_CString runtime.cgo_CString
|
||||
func _Cgo_CString(string) *_Cgo_char
|
||||
|
||||
//go:linkname C.GoString runtime.cgo_GoString
|
||||
func C.GoString(*C.char) string
|
||||
//go:linkname _Cgo_GoString runtime.cgo_GoString
|
||||
func _Cgo_GoString(*_Cgo_char) string
|
||||
|
||||
//go:linkname C.__GoStringN runtime.cgo_GoStringN
|
||||
func C.__GoStringN(*C.char, uintptr) string
|
||||
//go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
|
||||
func _Cgo___GoStringN(*_Cgo_char, uintptr) string
|
||||
|
||||
func C.GoStringN(cstr *C.char, length C.int) string {
|
||||
return C.__GoStringN(cstr, uintptr(length))
|
||||
func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
|
||||
return _Cgo___GoStringN(cstr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__GoBytes runtime.cgo_GoBytes
|
||||
func C.__GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
//go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
|
||||
func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
|
||||
|
||||
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte {
|
||||
return C.__GoBytes(ptr, uintptr(length))
|
||||
func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
|
||||
return _Cgo___GoBytes(ptr, uintptr(length))
|
||||
}
|
||||
|
||||
//go:linkname C.__CBytes runtime.cgo_CBytes
|
||||
func C.__CBytes([]byte) unsafe.Pointer
|
||||
//go:linkname _Cgo___CBytes runtime.cgo_CBytes
|
||||
func _Cgo___CBytes([]byte) unsafe.Pointer
|
||||
|
||||
func C.CBytes(b []byte) unsafe.Pointer {
|
||||
return C.__CBytes(b)
|
||||
func _Cgo_CBytes(b []byte) unsafe.Pointer {
|
||||
return _Cgo___CBytes(b)
|
||||
}
|
||||
|
||||
//go:linkname C.__get_errno_num runtime.cgo_errno
|
||||
func C.__get_errno_num() uintptr
|
||||
//go:linkname _Cgo___get_errno_num runtime.cgo_errno
|
||||
func _Cgo___get_errno_num() uintptr
|
||||
|
||||
func C.__get_errno() error {
|
||||
return syscall.Errno(C.__get_errno_num())
|
||||
func _Cgo___get_errno() error {
|
||||
return syscall.Errno(_Cgo___get_errno_num())
|
||||
}
|
||||
|
||||
type (
|
||||
C.char uint8
|
||||
C.schar int8
|
||||
C.uchar uint8
|
||||
C.short int16
|
||||
C.ushort uint16
|
||||
C.int int32
|
||||
C.uint uint32
|
||||
C.long int32
|
||||
C.ulong uint32
|
||||
C.longlong int64
|
||||
C.ulonglong uint64
|
||||
_Cgo_char uint8
|
||||
_Cgo_schar int8
|
||||
_Cgo_uchar uint8
|
||||
_Cgo_short int16
|
||||
_Cgo_ushort uint16
|
||||
_Cgo_int int32
|
||||
_Cgo_uint uint32
|
||||
_Cgo_long int32
|
||||
_Cgo_ulong uint32
|
||||
_Cgo_longlong int64
|
||||
_Cgo_ulonglong uint64
|
||||
)
|
||||
type C.myint = C.int
|
||||
type C.struct_point2d_t struct {
|
||||
x C.int
|
||||
y C.int
|
||||
type _Cgo_myint = _Cgo_int
|
||||
type _Cgo_struct_point2d_t struct {
|
||||
x _Cgo_int
|
||||
y _Cgo_int
|
||||
}
|
||||
type C.point2d_t = C.struct_point2d_t
|
||||
type C.struct_point3d struct {
|
||||
x C.int
|
||||
y C.int
|
||||
z C.int
|
||||
type _Cgo_point2d_t = _Cgo_struct_point2d_t
|
||||
type _Cgo_struct_point3d struct {
|
||||
x _Cgo_int
|
||||
y _Cgo_int
|
||||
z _Cgo_int
|
||||
}
|
||||
type C.point3d_t = C.struct_point3d
|
||||
type C.struct_type1 struct {
|
||||
_type C.int
|
||||
__type C.int
|
||||
___type C.int
|
||||
type _Cgo_point3d_t = _Cgo_struct_point3d
|
||||
type _Cgo_struct_type1 struct {
|
||||
_type _Cgo_int
|
||||
__type _Cgo_int
|
||||
___type _Cgo_int
|
||||
}
|
||||
type C.struct_type2 struct{ _type C.int }
|
||||
type C.union_union1_t struct{ i C.int }
|
||||
type C.union1_t = C.union_union1_t
|
||||
type C.union_union3_t struct{ $union uint64 }
|
||||
type _Cgo_struct_type2 struct{ _type _Cgo_int }
|
||||
type _Cgo_union_union1_t struct{ i _Cgo_int }
|
||||
type _Cgo_union1_t = _Cgo_union_union1_t
|
||||
type _Cgo_union_union3_t struct{ $union uint64 }
|
||||
|
||||
func (union *C.union_union3_t) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) }
|
||||
func (union *C.union_union3_t) unionfield_d() *float64 {
|
||||
func (union *_Cgo_union_union3_t) unionfield_i() *_Cgo_int {
|
||||
return (*_Cgo_int)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *_Cgo_union_union3_t) unionfield_d() *float64 {
|
||||
return (*float64)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *C.union_union3_t) unionfield_s() *C.short {
|
||||
return (*C.short)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo_union_union3_t) unionfield_s() *_Cgo_short {
|
||||
return (*_Cgo_short)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
|
||||
type C.union3_t = C.union_union3_t
|
||||
type C.union_union2d struct{ $union [2]uint64 }
|
||||
type _Cgo_union3_t = _Cgo_union_union3_t
|
||||
type _Cgo_union_union2d struct{ $union [2]uint64 }
|
||||
|
||||
func (union *C.union_union2d) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) }
|
||||
func (union *C.union_union2d) unionfield_d() *[2]float64 {
|
||||
func (union *_Cgo_union_union2d) unionfield_i() *_Cgo_int {
|
||||
return (*_Cgo_int)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *_Cgo_union_union2d) unionfield_d() *[2]float64 {
|
||||
return (*[2]float64)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
|
||||
type C.union2d_t = C.union_union2d
|
||||
type C.union_unionarray_t struct{ arr [10]C.uchar }
|
||||
type C.unionarray_t = C.union_unionarray_t
|
||||
type C._Ctype_union___0 struct{ $union [3]uint32 }
|
||||
type _Cgo_union2d_t = _Cgo_union_union2d
|
||||
type _Cgo_union_unionarray_t struct{ arr [10]_Cgo_uchar }
|
||||
type _Cgo_unionarray_t = _Cgo_union_unionarray_t
|
||||
type _Cgo__Ctype_union___0 struct{ $union [3]uint32 }
|
||||
|
||||
func (union *C._Ctype_union___0) unionfield_area() *C.point2d_t {
|
||||
return (*C.point2d_t)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo__Ctype_union___0) unionfield_area() *_Cgo_point2d_t {
|
||||
return (*_Cgo_point2d_t)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *C._Ctype_union___0) unionfield_solid() *C.point3d_t {
|
||||
return (*C.point3d_t)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo__Ctype_union___0) unionfield_solid() *_Cgo_point3d_t {
|
||||
return (*_Cgo_point3d_t)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
|
||||
type C.struct_struct_nested_t struct {
|
||||
begin C.point2d_t
|
||||
end C.point2d_t
|
||||
tag C.int
|
||||
type _Cgo_struct_struct_nested_t struct {
|
||||
begin _Cgo_point2d_t
|
||||
end _Cgo_point2d_t
|
||||
tag _Cgo_int
|
||||
|
||||
coord C._Ctype_union___0
|
||||
coord _Cgo__Ctype_union___0
|
||||
}
|
||||
type C.struct_nested_t = C.struct_struct_nested_t
|
||||
type C.union_union_nested_t struct{ $union [2]uint64 }
|
||||
type _Cgo_struct_nested_t = _Cgo_struct_struct_nested_t
|
||||
type _Cgo_union_union_nested_t struct{ $union [2]uint64 }
|
||||
|
||||
func (union *C.union_union_nested_t) unionfield_point() *C.point3d_t {
|
||||
return (*C.point3d_t)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo_union_union_nested_t) unionfield_point() *_Cgo_point3d_t {
|
||||
return (*_Cgo_point3d_t)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *C.union_union_nested_t) unionfield_array() *C.unionarray_t {
|
||||
return (*C.unionarray_t)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo_union_union_nested_t) unionfield_array() *_Cgo_unionarray_t {
|
||||
return (*_Cgo_unionarray_t)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
func (union *C.union_union_nested_t) unionfield_thing() *C.union3_t {
|
||||
return (*C.union3_t)(unsafe.Pointer(&union.$union))
|
||||
func (union *_Cgo_union_union_nested_t) unionfield_thing() *_Cgo_union3_t {
|
||||
return (*_Cgo_union3_t)(unsafe.Pointer(&union.$union))
|
||||
}
|
||||
|
||||
type C.union_nested_t = C.union_union_nested_t
|
||||
type C.enum_option = C.int
|
||||
type C.option_t = C.enum_option
|
||||
type C.enum_option2_t = C.uint
|
||||
type C.option2_t = C.enum_option2_t
|
||||
type C.struct_types_t struct {
|
||||
type _Cgo_union_nested_t = _Cgo_union_union_nested_t
|
||||
type _Cgo_enum_option = _Cgo_int
|
||||
type _Cgo_option_t = _Cgo_enum_option
|
||||
type _Cgo_enum_option2_t = _Cgo_uint
|
||||
type _Cgo_option2_t = _Cgo_enum_option2_t
|
||||
type _Cgo_struct_types_t struct {
|
||||
f float32
|
||||
d float64
|
||||
ptr *C.int
|
||||
ptr *_Cgo_int
|
||||
}
|
||||
type C.types_t = C.struct_types_t
|
||||
type C.myIntArray = [10]C.int
|
||||
type C.struct_bitfield_t struct {
|
||||
start C.uchar
|
||||
__bitfield_1 C.uchar
|
||||
type _Cgo_types_t = _Cgo_struct_types_t
|
||||
type _Cgo_myIntArray = [10]_Cgo_int
|
||||
type _Cgo_struct_bitfield_t struct {
|
||||
start _Cgo_uchar
|
||||
__bitfield_1 _Cgo_uchar
|
||||
|
||||
d C.uchar
|
||||
e C.uchar
|
||||
d _Cgo_uchar
|
||||
e _Cgo_uchar
|
||||
}
|
||||
|
||||
func (s *C.struct_bitfield_t) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f }
|
||||
func (s *C.struct_bitfield_t) set_bitfield_a(value C.uchar) {
|
||||
func (s *_Cgo_struct_bitfield_t) bitfield_a() _Cgo_uchar { return s.__bitfield_1 & 0x1f }
|
||||
func (s *_Cgo_struct_bitfield_t) set_bitfield_a(value _Cgo_uchar) {
|
||||
s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0
|
||||
}
|
||||
func (s *C.struct_bitfield_t) bitfield_b() C.uchar {
|
||||
func (s *_Cgo_struct_bitfield_t) bitfield_b() _Cgo_uchar {
|
||||
return s.__bitfield_1 >> 5 & 0x1
|
||||
}
|
||||
func (s *C.struct_bitfield_t) set_bitfield_b(value C.uchar) {
|
||||
func (s *_Cgo_struct_bitfield_t) set_bitfield_b(value _Cgo_uchar) {
|
||||
s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5
|
||||
}
|
||||
func (s *C.struct_bitfield_t) bitfield_c() C.uchar {
|
||||
func (s *_Cgo_struct_bitfield_t) bitfield_c() _Cgo_uchar {
|
||||
return s.__bitfield_1 >> 6
|
||||
}
|
||||
func (s *C.struct_bitfield_t) set_bitfield_c(value C.uchar,
|
||||
func (s *_Cgo_struct_bitfield_t) set_bitfield_c(value _Cgo_uchar,
|
||||
|
||||
) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 }
|
||||
|
||||
type C.bitfield_t = C.struct_bitfield_t
|
||||
type _Cgo_bitfield_t = _Cgo_struct_bitfield_t
|
||||
|
||||
+3
-28
@@ -356,17 +356,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
||||
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
||||
}
|
||||
case "wasm":
|
||||
llvmarch = "wasm32"
|
||||
spec.CPU = "generic"
|
||||
spec.Features = "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types"
|
||||
spec.BuildTags = append(spec.BuildTags, "tinygo.wasm")
|
||||
spec.CFlags = append(spec.CFlags,
|
||||
"-mbulk-memory",
|
||||
"-mnontrapping-fptoint",
|
||||
"-mno-multivalue",
|
||||
"-mno-reference-types",
|
||||
"-msign-ext",
|
||||
)
|
||||
return nil, fmt.Errorf("GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
||||
}
|
||||
@@ -446,23 +436,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
||||
"--no-insert-timestamp",
|
||||
"--no-dynamicbase",
|
||||
)
|
||||
case "wasip1":
|
||||
spec.GC = "" // use default GC
|
||||
spec.Scheduler = "asyncify"
|
||||
spec.Linker = "wasm-ld"
|
||||
spec.RTLib = "compiler-rt"
|
||||
spec.Libc = "wasi-libc"
|
||||
spec.DefaultStackSize = 1024 * 64 // 64kB
|
||||
spec.LDFlags = append(spec.LDFlags,
|
||||
"--stack-first",
|
||||
"--no-demangle",
|
||||
)
|
||||
spec.Emulator = "wasmtime run --dir={tmpDir}::/tmp {}"
|
||||
spec.ExtraFiles = append(spec.ExtraFiles,
|
||||
"src/runtime/asm_tinygowasm.S",
|
||||
"src/internal/task/task_asyncify_wasm.S",
|
||||
)
|
||||
llvmos = "wasi"
|
||||
case "wasm", "wasip1", "wasip2":
|
||||
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
||||
}
|
||||
|
||||
+6
-5
@@ -18,11 +18,12 @@ var stdlibAliases = map[string]string{
|
||||
// crypto packages
|
||||
"crypto/ed25519/internal/edwards25519/field.feMul": "crypto/ed25519/internal/edwards25519/field.feMulGeneric",
|
||||
"crypto/internal/edwards25519/field.feSquare": "crypto/ed25519/internal/edwards25519/field.feSquareGeneric",
|
||||
"crypto/md5.block": "crypto/md5.blockGeneric",
|
||||
"crypto/sha1.block": "crypto/sha1.blockGeneric",
|
||||
"crypto/sha1.blockAMD64": "crypto/sha1.blockGeneric",
|
||||
"crypto/sha256.block": "crypto/sha256.blockGeneric",
|
||||
"crypto/sha512.blockAMD64": "crypto/sha512.blockGeneric",
|
||||
"crypto/md5.block": "crypto/md5.blockGeneric",
|
||||
"crypto/sha1.block": "crypto/sha1.blockGeneric",
|
||||
"crypto/sha1.blockAMD64": "crypto/sha1.blockGeneric",
|
||||
"crypto/sha256.block": "crypto/sha256.blockGeneric",
|
||||
"crypto/sha512.blockAMD64": "crypto/sha512.blockGeneric",
|
||||
"internal/chacha8rand.block": "internal/chacha8rand.block_generic",
|
||||
|
||||
// AES
|
||||
"crypto/aes.decryptBlockAsm": "crypto/aes.decryptBlock",
|
||||
|
||||
+3
-4
@@ -432,9 +432,8 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
||||
// pass for C variadic functions. This includes both explicit
|
||||
// (with ...) and implicit (no parameters in signature)
|
||||
// functions.
|
||||
if strings.HasPrefix(f.Name(), "C.") {
|
||||
// This prefix cannot naturally be created, it must have
|
||||
// been created as a result of CGo preprocessing.
|
||||
if strings.HasPrefix(f.Name(), "_Cgo_") {
|
||||
// This prefix was created as a result of CGo preprocessing.
|
||||
info.variadic = true
|
||||
}
|
||||
}
|
||||
@@ -447,7 +446,7 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
||||
// The list of allowed types is based on this proposal:
|
||||
// https://github.com/golang/go/issues/59149
|
||||
func (c *compilerContext) checkWasmImportExport(f *ssa.Function, pragma string) {
|
||||
if c.pkg.Path() == "runtime" || c.pkg.Path() == "syscall/js" || c.pkg.Path() == "syscall" {
|
||||
if c.pkg.Path() == "runtime" || c.pkg.Path() == "syscall/js" || c.pkg.Path() == "syscall" || c.pkg.Path() == "crypto/internal/sysrand" {
|
||||
// The runtime is a special case. Allow all kinds of parameters
|
||||
// (importantly, including pointers).
|
||||
return
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Version of TinyGo.
|
||||
// Update this value before release of new version of software.
|
||||
const version = "0.36.0-dev"
|
||||
const version = "0.36.0"
|
||||
|
||||
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
||||
// (like 0.30.0-dev-abcd012).
|
||||
|
||||
@@ -269,6 +269,8 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
||||
|
||||
if needsSyscallPackage {
|
||||
paths["syscall/"] = true // include syscall/js
|
||||
paths["internal/syscall/"] = true
|
||||
paths["internal/syscall/unix/"] = false
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
@@ -1684,8 +1684,24 @@ func main() {
|
||||
usage(command)
|
||||
os.Exit(1)
|
||||
}
|
||||
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
|
||||
options.Target = "wasm"
|
||||
if options.Target == "" {
|
||||
switch {
|
||||
case options.GOARCH == "wasm":
|
||||
switch options.GOOS {
|
||||
case "js":
|
||||
options.Target = "wasm"
|
||||
case "wasip1":
|
||||
options.Target = "wasip1"
|
||||
case "wasip2":
|
||||
options.Target = "wasip2"
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr, "GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||
os.Exit(1)
|
||||
}
|
||||
case filepath.Ext(outpath) == ".wasm":
|
||||
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
err := Build(pkgName, outpath, options)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey
|
||||
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt)
|
||||
|
||||
// If you update the above build constraint, you'll probably also need to update
|
||||
// src/runtime/rand_hwrng.go.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package abi
|
||||
|
||||
type Type struct {
|
||||
// Intentionally left empty. TinyGo uses a different way to represent types,
|
||||
// so this is unimplementable. The type definition here is purely for
|
||||
// compatibility.
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package unix
|
||||
|
||||
const (
|
||||
R_OK = 0x4
|
||||
W_OK = 0x2
|
||||
X_OK = 0x1
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package unix
|
||||
|
||||
import "syscall"
|
||||
|
||||
func Eaccess(path string, mode uint32) error {
|
||||
// We don't support this syscall on baremetal or wasm.
|
||||
// Callers are generally able to deal with this since unix.Eaccess also
|
||||
// isn't available on Android.
|
||||
return syscall.ENOSYS
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package unix
|
||||
|
||||
type GetRandomFlag uintptr
|
||||
|
||||
const (
|
||||
GRND_NONBLOCK GetRandomFlag = 0x0001
|
||||
GRND_RANDOM GetRandomFlag = 0x0002
|
||||
)
|
||||
|
||||
func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
panic("todo: unix.GetRandom")
|
||||
}
|
||||
@@ -21,6 +21,9 @@ type Task struct {
|
||||
// state is the underlying running state of the task.
|
||||
state state
|
||||
|
||||
// This is needed for some crypto packages.
|
||||
FipsIndicator uint8
|
||||
|
||||
// DeferFrame stores a pointer to the (stack allocated) defer frame of the
|
||||
// goroutine that is used for the recover builtin.
|
||||
DeferFrame unsafe.Pointer
|
||||
|
||||
@@ -64,3 +64,14 @@ type BlockDevice interface {
|
||||
// EraseBlockSize to map addresses to blocks.
|
||||
EraseBlocks(start, len int64) error
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func flashPad(p []byte, writeBlockSize int) []byte {
|
||||
overflow := len(p) % writeBlockSize
|
||||
if overflow != 0 {
|
||||
for i := 0; i < writeBlockSize-overflow; i++ {
|
||||
p = append(p, 0xff)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"device/arm"
|
||||
"device/sam"
|
||||
"errors"
|
||||
@@ -1917,7 +1916,7 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
f.ensureInitComplete()
|
||||
|
||||
address := FlashDataStart() + uintptr(off)
|
||||
padded := f.pad(p)
|
||||
padded := flashPad(p, int(f.WriteBlockSize()))
|
||||
|
||||
waitWhileFlashBusy()
|
||||
|
||||
@@ -1992,17 +1991,6 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
func (f flashBlockDevice) ensureInitComplete() {
|
||||
if f.initComplete {
|
||||
return
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"device/arm"
|
||||
"device/sam"
|
||||
"errors"
|
||||
@@ -2174,7 +2173,7 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
}
|
||||
|
||||
address := FlashDataStart() + uintptr(off)
|
||||
padded := f.pad(p)
|
||||
padded := flashPad(p, int(f.WriteBlockSize()))
|
||||
|
||||
settings := disableFlashCache()
|
||||
defer restoreFlashCache(settings)
|
||||
@@ -2263,17 +2262,6 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
func disableFlashCache() uint16 {
|
||||
settings := sam.NVMCTRL.CTRLA.Get()
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"device/nrf"
|
||||
"internal/binary"
|
||||
"runtime/interrupt"
|
||||
@@ -386,7 +385,7 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
}
|
||||
|
||||
address := FlashDataStart() + uintptr(off)
|
||||
padded := f.pad(p)
|
||||
padded := flashPad(p, int(f.WriteBlockSize()))
|
||||
|
||||
waitWhileFlashBusy()
|
||||
|
||||
@@ -444,17 +443,6 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
func waitWhileFlashBusy() {
|
||||
for nrf.NVMC.GetREADY() != nrf.NVMC_READY_READY_Ready {
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -101,17 +100,6 @@ func (f flashBlockDevice) EraseBlocks(start, length int64) error {
|
||||
return f.eraseBlocks(start, length)
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
// return the correct address to be used for write
|
||||
func writeAddress(off int64) uintptr {
|
||||
return readAddress(off) - uintptr(memoryStart)
|
||||
|
||||
@@ -230,7 +230,7 @@ func (f flashBlockDevice) writeAt(p []byte, off int64) (n int, err error) {
|
||||
// e.g. real address 0x10003000 is written to at
|
||||
// 0x00003000
|
||||
address := writeAddress(off)
|
||||
padded := f.pad(p)
|
||||
padded := flashPad(p, int(f.WriteBlockSize()))
|
||||
|
||||
C.flash_range_write(C.uint32_t(address),
|
||||
(*C.uint8_t)(unsafe.Pointer(&padded[0])),
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
cpuFreq = 200 * MHz
|
||||
_NUMBANK0_GPIOS = 30
|
||||
_NUMBANK0_IRQS = 4
|
||||
_NUMIRQ = 32
|
||||
@@ -207,3 +208,16 @@ func (clks *clocksType) initTicks() {} // No ticks on RP2040
|
||||
func (wd *watchdogImpl) startTick(cycles uint32) {
|
||||
rp.WATCHDOG.TICK.Set(cycles | rp.WATCHDOG_TICK_ENABLE)
|
||||
}
|
||||
|
||||
func adjustCoreVoltage() bool {
|
||||
if cpuFreq <= 133*MHz {
|
||||
return false
|
||||
}
|
||||
// The rp2040 is certified to run at 200MHz with the
|
||||
// core voltage set to 1150mV.
|
||||
const targetVoltage = 1150
|
||||
// 0b0101 maps to 800mV and each step is 50mV.
|
||||
const vreg = 0b0101 + (targetVoltage-800)/50
|
||||
rp.VREG_AND_CHIP_RESET.SetVREG_VSEL(vreg)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
cpuFreq = 150 * MHz
|
||||
_NUMBANK0_GPIOS = 48
|
||||
_NUMBANK0_IRQS = 6
|
||||
rp2350ExtraReg = 1
|
||||
@@ -221,3 +222,7 @@ func EnterBootloader() {
|
||||
func (wd *watchdogImpl) startTick(cycles uint32) {
|
||||
rp.TICKS.WATCHDOG_CTRL.SetBits(1)
|
||||
}
|
||||
|
||||
func adjustCoreVoltage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func CPUFrequency() uint32 {
|
||||
return 125 * MHz
|
||||
return cpuFreq
|
||||
}
|
||||
|
||||
// clockIndex identifies a hardware clock
|
||||
@@ -42,6 +42,10 @@ type clock struct {
|
||||
cix clockIndex
|
||||
}
|
||||
|
||||
// The delay in seconds for core voltage adjustments to
|
||||
// settle. Taken from the Pico SDK.
|
||||
const _VREG_VOLTAGE_AUTO_ADJUST_DELAY = 1 / 1e3
|
||||
|
||||
// clock returns the clock identified by cix.
|
||||
func (clks *clocksType) clock(cix clockIndex) clock {
|
||||
return clock{
|
||||
@@ -137,7 +141,19 @@ func (clk *clock) configure(src, auxsrc, srcFreq, freq uint32) {
|
||||
|
||||
}
|
||||
|
||||
const pllsysFB, pllsysPD1, pllsysPD2 uint32 = 125, 6, 2 // RP2040 running 125MHz with 1500MHz VCO.
|
||||
var pllsysFB, pllsysPD1, pllsysPD2 uint32
|
||||
|
||||
// Compute clock dividers.
|
||||
//
|
||||
// Note that the entire init function is computed at compile time
|
||||
// by interp.
|
||||
func init() {
|
||||
fb, _, pd1, pd2, err := pllSearch{LockRefDiv: 1}.CalcDivs(xoscFreq*MHz, cpuFreq, MHz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pllsysFB, pllsysPD1, pllsysPD2 = uint32(fb), uint32(pd1), uint32(pd2)
|
||||
}
|
||||
|
||||
// init initializes the clock hardware.
|
||||
//
|
||||
@@ -165,7 +181,7 @@ func (clks *clocksType) init() {
|
||||
// REF FBDIV VCO POSTDIV
|
||||
// pllSys: 12 / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
|
||||
// pllUSB: 12 / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
|
||||
pllSys.init(1, uint32(pllsysFB), uint32(pllsysPD1), uint32(pllsysPD2))
|
||||
pllSys.init(1, pllsysFB, pllsysPD1, pllsysPD2)
|
||||
pllUSB.init(1, 40, 5, 2)
|
||||
|
||||
// Configure clocks
|
||||
@@ -173,15 +189,23 @@ func (clks *clocksType) init() {
|
||||
cref := clks.clock(clkRef)
|
||||
cref.configure(rp.CLOCKS_CLK_REF_CTRL_SRC_XOSC_CLKSRC,
|
||||
0, // No aux mux
|
||||
12*MHz,
|
||||
12*MHz)
|
||||
xoscFreq,
|
||||
xoscFreq)
|
||||
|
||||
if adjustCoreVoltage() {
|
||||
// Wait for the voltage to settle.
|
||||
const cycles = _VREG_VOLTAGE_AUTO_ADJUST_DELAY * xoscFreq * MHz
|
||||
for i := 0; i < cycles; i++ {
|
||||
arm.Asm("nop")
|
||||
}
|
||||
}
|
||||
|
||||
// clkSys = pllSys (125MHz) / 1 = 125MHz
|
||||
csys := clks.clock(clkSys)
|
||||
csys.configure(rp.CLOCKS_CLK_SYS_CTRL_SRC_CLKSRC_CLK_SYS_AUX,
|
||||
rp.CLOCKS_CLK_SYS_CTRL_AUXSRC_CLKSRC_PLL_SYS,
|
||||
125*MHz,
|
||||
125*MHz)
|
||||
cpuFreq,
|
||||
cpuFreq)
|
||||
|
||||
// clkUSB = pllUSB (48MHz) / 1 = 48MHz
|
||||
cusb := clks.clock(clkUSB)
|
||||
@@ -205,8 +229,8 @@ func (clks *clocksType) init() {
|
||||
cperi := clks.clock(clkPeri)
|
||||
cperi.configure(0,
|
||||
rp.CLOCKS_CLK_PERI_CTRL_AUXSRC_CLK_SYS,
|
||||
125*MHz,
|
||||
125*MHz)
|
||||
cpuFreq,
|
||||
cpuFreq)
|
||||
|
||||
clks.initTicks()
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ type irqSummary struct {
|
||||
|
||||
type ioBank0Type struct {
|
||||
io [_NUMBANK0_GPIOS]ioType
|
||||
_ [rp2350ExtraReg][128]byte
|
||||
irqsum [rp2350ExtraReg]irqSummary
|
||||
intR [_NUMBANK0_IRQS]volatile.Register32
|
||||
proc0IRQctrl irqCtrl
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build rp2040 || rp2350 || gopher_badge
|
||||
//go:build rp2040 || rp2350 || gopher_badge || pico
|
||||
|
||||
package machine
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ var errVCOOverflow = errors.New("VCO calculation overflow; use lower MHz")
|
||||
//
|
||||
// Example for 12MHz crystal and RP2350:
|
||||
//
|
||||
// fbdiv, refdiv, pd1, pd2, _ := pllSearch{LockRefDiv:1}.CalcDivs(12*MHz, 133*MHz, MHz)
|
||||
// fbdiv, refdiv, pd1, pd2, _ := pllSearch{LockRefDiv:1}.CalcDivs(12*MHz, 150*MHz, MHz)
|
||||
type pllSearch struct {
|
||||
LowerVCO bool
|
||||
LockRefDiv uint8
|
||||
|
||||
@@ -104,13 +104,13 @@ func (spi SPI) Transfer(w byte) (byte, error) {
|
||||
}
|
||||
|
||||
func (spi SPI) SetBaudRate(br uint32) error {
|
||||
const freqin uint32 = 125 * MHz
|
||||
const maxBaud uint32 = 66.5 * MHz // max output frequency is 66.5MHz on rp2040. see Note page 527.
|
||||
// Find smallest prescale value which puts output frequency in range of
|
||||
// post-divide. Prescale is an even number from 2 to 254 inclusive.
|
||||
var prescale, postdiv uint32
|
||||
freq := CPUFrequency()
|
||||
for prescale = 2; prescale < 255; prescale += 2 {
|
||||
if freqin < (prescale+2)*256*br {
|
||||
if freq < (prescale+2)*256*br {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (spi SPI) SetBaudRate(br uint32) error {
|
||||
// Find largest post-divide which makes output <= baudrate. Post-divide is
|
||||
// an integer in the range 1 to 256 inclusive.
|
||||
for postdiv = 256; postdiv > 1; postdiv-- {
|
||||
if freqin/(prescale*(postdiv-1)) > br {
|
||||
if freq/(prescale*(postdiv-1)) > br {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (uart *UART) Configure(config UARTConfig) error {
|
||||
uart.Interrupt.SetPriority(0x80)
|
||||
uart.Interrupt.Enable()
|
||||
|
||||
// setup interrupt on receive
|
||||
// Setup interrupt on receive.
|
||||
uart.Bus.UARTIMSC.Set(rp.UART0_UARTIMSC_RXIM)
|
||||
|
||||
return nil
|
||||
@@ -75,7 +75,7 @@ func (uart *UART) Configure(config UARTConfig) error {
|
||||
|
||||
// SetBaudRate sets the baudrate to be used for the UART.
|
||||
func (uart *UART) SetBaudRate(br uint32) {
|
||||
div := 8 * 125 * MHz / br
|
||||
div := 8 * CPUFrequency() / br
|
||||
|
||||
ibrd := div >> 7
|
||||
var fbrd uint32
|
||||
@@ -153,7 +153,7 @@ func initUART(uart *UART) {
|
||||
// handleInterrupt should be called from the appropriate interrupt handler for
|
||||
// this UART instance.
|
||||
func (uart *UART) handleInterrupt(interrupt.Interrupt) {
|
||||
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_RXFE) {
|
||||
for !uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_RXFE) {
|
||||
uart.Receive(byte((uart.Bus.UARTDR.Get() & 0xFF)))
|
||||
}
|
||||
uart.Receive(byte((uart.Bus.UARTDR.Get() & 0xFF)))
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package machine
|
||||
import (
|
||||
"device/stm32"
|
||||
|
||||
"bytes"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -41,7 +40,8 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
unlockFlash()
|
||||
defer lockFlash()
|
||||
|
||||
return writeFlashData(FlashDataStart()+uintptr(off), f.pad(p))
|
||||
p = flashPad(p, int(f.WriteBlockSize()))
|
||||
return writeFlashData(FlashDataStart()+uintptr(off), p)
|
||||
}
|
||||
|
||||
// Size returns the number of bytes in this block device.
|
||||
@@ -90,17 +90,6 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
const memoryStart = 0x08000000
|
||||
|
||||
func unlockFlash() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package descriptor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"internal/bytealg"
|
||||
)
|
||||
|
||||
var configurationCDCHID = [configurationTypeLen]byte{
|
||||
@@ -87,7 +87,7 @@ func FindClassHIDType(des, class []byte) (ClassHIDType, error) {
|
||||
|
||||
// search only for ClassHIDType without the ClassLength,
|
||||
// in case it has already been set.
|
||||
idx := bytes.Index(des, class[:ClassHIDTypeLen-2])
|
||||
idx := bytealg.Index(des, class[:ClassHIDTypeLen-2])
|
||||
if idx == -1 {
|
||||
return ClassHIDType{}, errNoClassHIDFound
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
//go:build tinygo.riscv32 && virt
|
||||
|
||||
// Machine implementation for VirtIO targets.
|
||||
// At the moment only QEMU RISC-V is supported, but support for ARM for example
|
||||
// should not be difficult to add with a change to virtioFindDevice.
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime/volatile"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const deviceName = "riscv-qemu"
|
||||
|
||||
func (p Pin) Set(high bool) {
|
||||
// no pins defined
|
||||
}
|
||||
|
||||
var rngLock sync.Mutex
|
||||
var rngDevice *virtioDevice1
|
||||
var rngBuf volatile.Register32
|
||||
|
||||
var errNoRNG = errors.New("machine: no entropy source found")
|
||||
var errNoRNGData = errors.New("machine: entropy source didn't return enough data")
|
||||
|
||||
// GetRNG returns random numbers from a VirtIO entropy source.
|
||||
// When running in QEMU, it requires adding the RNG device:
|
||||
//
|
||||
// -device virtio-rng-device
|
||||
func GetRNG() (uint32, error) {
|
||||
rngLock.Lock()
|
||||
|
||||
// Initialize the device on first use.
|
||||
if rngDevice == nil {
|
||||
// Search for an available RNG.
|
||||
rngDevice = virtioFindDevice(virtioDeviceEntropySource)
|
||||
if rngDevice == nil {
|
||||
rngLock.Unlock()
|
||||
return 0, errNoRNG
|
||||
}
|
||||
|
||||
// Initialize the device.
|
||||
rngDevice.status.Set(0) // reset device
|
||||
rngDevice.status.Set(virtioDeviceStatusAcknowledge)
|
||||
rngDevice.status.Set(virtioDeviceStatusAcknowledge | virtioDeviceStatusDriver)
|
||||
rngDevice.hostFeaturesSel.Set(0)
|
||||
rngDevice.status.Set(virtioDeviceStatusAcknowledge | virtioDeviceStatusDriver | virtioDeviceStatusDriverOk)
|
||||
rngDevice.guestPageSize.Set(4096)
|
||||
|
||||
// Configure queue, according to section 4.2.4 "Legacy interface".
|
||||
// Note: we're skipping checks for queuePFM and queueNumMax.
|
||||
rngDevice.queueSel.Set(0) // use queue 0 (the only queue)
|
||||
rngDevice.queueNum.Set(1) // use a single buffer in the queue
|
||||
rngDevice.queueAlign.Set(4096) // default alignment appears to be 4096
|
||||
rngDevice.queuePFN.Set(uint32(uintptr(unsafe.Pointer(&rngQueue))) / 4096)
|
||||
|
||||
// Configure the only buffer in the queue (but don't increment
|
||||
// rngQueue.available yet).
|
||||
rngQueue.buffers[0].address = uint64(uintptr(unsafe.Pointer(&rngBuf)))
|
||||
rngQueue.buffers[0].length = uint32(unsafe.Sizeof(rngBuf))
|
||||
rngQueue.buffers[0].flags = 2 // 2 means write-only buffer
|
||||
}
|
||||
|
||||
// Increment the available ring buffer. This doesn't actually change the
|
||||
// buffer index (it's a ring with a single entry), but the number needs to
|
||||
// be incremented otherwise the device won't recognize a new buffer.
|
||||
index := rngQueue.available.index
|
||||
rngQueue.available.index = index + 1
|
||||
rngDevice.queueNotify.Set(0) // notify the device of the 'new' (reused) buffer
|
||||
for rngQueue.used.index.Get() != index+1 {
|
||||
// Busy wait until the RNG buffer is filled.
|
||||
// A better way would be to wait for an interrupt, but since this driver
|
||||
// implementation is mostly used for testing it's good enough for now.
|
||||
}
|
||||
|
||||
// Check that we indeed got 4 bytes back.
|
||||
if rngQueue.used.ring[0].length != 4 {
|
||||
rngLock.Unlock()
|
||||
return 0, errNoRNGData
|
||||
}
|
||||
|
||||
// Read the resulting random numbers.
|
||||
result := rngBuf.Get()
|
||||
|
||||
rngLock.Unlock()
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Implement a driver for the VirtIO entropy device.
|
||||
// https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html
|
||||
// http://wiki.osdev.org/Virtio
|
||||
// http://www.dumais.io/index.php?article=aca38a9a2b065b24dfa1dee728062a12
|
||||
|
||||
const (
|
||||
virtioDeviceStatusAcknowledge = 1
|
||||
virtioDeviceStatusDriver = 2
|
||||
virtioDeviceStatusDriverOk = 4
|
||||
virtioDeviceStatusFeaturesOk = 8
|
||||
virtioDeviceStatusFailed = 128
|
||||
)
|
||||
|
||||
const (
|
||||
virtioDeviceReserved = iota
|
||||
virtioDeviceNetworkCard
|
||||
virtioDeviceBlockDevice
|
||||
virtioDeviceConsole
|
||||
virtioDeviceEntropySource
|
||||
// there are more device types
|
||||
)
|
||||
|
||||
// VirtIO device version 1
|
||||
type virtioDevice1 struct {
|
||||
magic volatile.Register32 // always 0x74726976
|
||||
version volatile.Register32
|
||||
deviceID volatile.Register32
|
||||
vendorID volatile.Register32
|
||||
hostFeatures volatile.Register32
|
||||
hostFeaturesSel volatile.Register32
|
||||
_ [2]uint32
|
||||
guestFeatures volatile.Register32
|
||||
guestFeaturesSel volatile.Register32
|
||||
guestPageSize volatile.Register32
|
||||
_ uint32
|
||||
queueSel volatile.Register32
|
||||
queueNumMax volatile.Register32
|
||||
queueNum volatile.Register32
|
||||
queueAlign volatile.Register32
|
||||
queuePFN volatile.Register32
|
||||
_ [3]uint32
|
||||
queueNotify volatile.Register32
|
||||
_ [3]uint32
|
||||
interruptStatus volatile.Register32
|
||||
interruptAck volatile.Register32
|
||||
_ [2]uint32
|
||||
status volatile.Register32
|
||||
}
|
||||
|
||||
// VirtIO queue, with a single buffer.
|
||||
type virtioQueue struct {
|
||||
buffers [1]struct {
|
||||
address uint64
|
||||
length uint32
|
||||
flags uint16
|
||||
next uint16
|
||||
} // 16 bytes
|
||||
|
||||
available struct {
|
||||
flags uint16
|
||||
index uint16
|
||||
ring [1]uint16
|
||||
eventIndex uint16
|
||||
} // 8 bytes
|
||||
|
||||
_ [4096 - 16*1 - 8*1]byte // padding (to align on a 4096 byte boundary)
|
||||
|
||||
used struct {
|
||||
flags uint16
|
||||
index volatile.Register16
|
||||
ring [1]struct {
|
||||
index uint32
|
||||
length uint32
|
||||
}
|
||||
availEvent uint16
|
||||
}
|
||||
}
|
||||
|
||||
func virtioFindDevice(deviceID uint32) *virtioDevice1 {
|
||||
// On RISC-V, QEMU defines 8 VirtIO devices starting at 0x10001000 and
|
||||
// repeating every 0x1000 bytes.
|
||||
// The memory map can be seen in the QEMU source code:
|
||||
// https://github.com/qemu/qemu/blob/master/hw/riscv/virt.c
|
||||
for i := 0; i < 8; i++ {
|
||||
dev := (*virtioDevice1)(unsafe.Pointer(uintptr(0x10001000 + i*0x1000)))
|
||||
if dev.magic.Get() != 0x74726976 || dev.version.Get() != 1 || dev.deviceID.Get() != deviceID {
|
||||
continue
|
||||
}
|
||||
return dev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A VirtIO queue needs to be page-aligned.
|
||||
//
|
||||
//go:align 4096
|
||||
var rngQueue virtioQueue
|
||||
@@ -318,6 +318,17 @@ func (f *File) Chmod(mode FileMode) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Chdir changes the current working directory to the file, which must be a
|
||||
// directory. If there is an error, it will be of type *PathError.
|
||||
func (f *File) Chdir() (err error) {
|
||||
if f.handle == nil {
|
||||
err = ErrClosed
|
||||
} else {
|
||||
err = f.chdir()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LinkError records an error during a link or symlink or rename system call and
|
||||
// the paths that caused it.
|
||||
type LinkError struct {
|
||||
|
||||
@@ -42,6 +42,12 @@ func NewFile(fd uintptr, name string) *File {
|
||||
return &File{&file{handle: stdioFileHandle(fd), name: name}}
|
||||
}
|
||||
|
||||
// Chdir changes the current working directory to the named directory.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Chdir(dir string) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// Rename renames (moves) oldpath to newpath.
|
||||
// If newpath already exists and is not a directory, Rename replaces it.
|
||||
// OS-specific restrictions may apply when oldpath and newpath are in different directories.
|
||||
@@ -128,6 +134,10 @@ func Pipe() (r *File, w *File, err error) {
|
||||
return nil, nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
func Symlink(oldname, newname string) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func Readlink(name string) (string, error) {
|
||||
return "", ErrNotImplemented
|
||||
}
|
||||
@@ -153,3 +163,7 @@ func (f *File) Truncate(size int64) (err error) {
|
||||
func (f *File) chmod(mode FileMode) error {
|
||||
return ErrUnsupported
|
||||
}
|
||||
|
||||
func (f *File) chdir() error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -166,6 +166,22 @@ func (f *File) chmod(mode FileMode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) chdir() error {
|
||||
if f.handle == nil {
|
||||
return ErrClosed
|
||||
}
|
||||
|
||||
// TODO: use syscall.Fchdir instead
|
||||
longName := fixLongPath(f.name)
|
||||
e := ignoringEINTR(func() error {
|
||||
return syscall.Chdir(longName)
|
||||
})
|
||||
if e != nil {
|
||||
return &PathError{Op: "chdir", Path: f.name, Err: e}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
|
||||
// It returns the number of bytes read and any error encountered, possibly io.EOF.
|
||||
// At end of file, Pread returns 0, io.EOF.
|
||||
|
||||
@@ -146,3 +146,7 @@ func isWindowsNulName(name string) bool {
|
||||
func (f *File) chmod(mode FileMode) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (f *File) chdir() error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -271,6 +271,84 @@ func (v Value) Comparable() bool {
|
||||
}
|
||||
}
|
||||
|
||||
// Equal reports true if v is equal to u.
|
||||
// For two invalid values, Equal will report true.
|
||||
// For an interface value, Equal will compare the value within the interface.
|
||||
// Otherwise, If the values have different types, Equal will report false.
|
||||
// Otherwise, for arrays and structs Equal will compare each element in order,
|
||||
// and report false if it finds non-equal elements.
|
||||
// During all comparisons, if values of the same type are compared,
|
||||
// and the type is not comparable, Equal will panic.
|
||||
//
|
||||
// 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.
|
||||
func (v Value) Equal(u Value) bool {
|
||||
if v.Kind() == Interface {
|
||||
v = v.Elem()
|
||||
}
|
||||
if u.Kind() == Interface {
|
||||
u = u.Elem()
|
||||
}
|
||||
|
||||
if !v.IsValid() || !u.IsValid() {
|
||||
return v.IsValid() == u.IsValid()
|
||||
}
|
||||
|
||||
if v.Kind() != u.Kind() || v.Type() != u.Type() {
|
||||
return false
|
||||
}
|
||||
|
||||
// Handle each Kind directly rather than calling valueInterface
|
||||
// to avoid allocating.
|
||||
switch v.Kind() {
|
||||
default:
|
||||
panic("reflect.Value.Equal: invalid Kind")
|
||||
case Bool:
|
||||
return v.Bool() == u.Bool()
|
||||
case Int, Int8, Int16, Int32, Int64:
|
||||
return v.Int() == u.Int()
|
||||
case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
|
||||
return v.Uint() == u.Uint()
|
||||
case Float32, Float64:
|
||||
return v.Float() == u.Float()
|
||||
case Complex64, Complex128:
|
||||
return v.Complex() == u.Complex()
|
||||
case String:
|
||||
return v.String() == u.String()
|
||||
case Chan, Pointer, UnsafePointer:
|
||||
return v.Pointer() == u.Pointer()
|
||||
case Array:
|
||||
// u and v have the same type so they have the same length
|
||||
vl := v.Len()
|
||||
if vl == 0 {
|
||||
// panic on [0]func()
|
||||
if !v.Type().Elem().Comparable() {
|
||||
break
|
||||
}
|
||||
return true
|
||||
}
|
||||
for i := 0; i < vl; i++ {
|
||||
if !v.Index(i).Equal(u.Index(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case Struct:
|
||||
// u and v have the same type so they have the same fields
|
||||
nf := v.NumField()
|
||||
for i := 0; i < nf; i++ {
|
||||
if !v.Field(i).Equal(u.Field(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case Func, Map, Slice:
|
||||
break
|
||||
}
|
||||
panic("reflect.Value.Equal: values of type " + v.Type().String() + " are not comparable")
|
||||
}
|
||||
|
||||
func (v Value) Addr() Value {
|
||||
if !v.CanAddr() {
|
||||
panic("reflect.Value.Addr of unaddressable value")
|
||||
|
||||
@@ -226,3 +226,8 @@ func divideByZeroPanic() {
|
||||
func blockingPanic() {
|
||||
runtimePanicAt(returnAddress(0), "trying to do blocking operation in exported function")
|
||||
}
|
||||
|
||||
//go:linkname fips_fatal crypto/internal/fips140.fatal
|
||||
func fips_fatal(msg string) {
|
||||
runtimePanic(msg)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey)
|
||||
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt))
|
||||
|
||||
// If you update the above build constraint, you'll probably also need to update
|
||||
// src/crypto/rand/rand_baremetal.go.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey)
|
||||
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt))
|
||||
|
||||
package runtime
|
||||
|
||||
|
||||
@@ -31,3 +31,14 @@ func scheduleLogChan(msg string, ch *channel, t *task.Task) {
|
||||
func Goexit() {
|
||||
panicOrGoexit(nil, panicGoexit)
|
||||
}
|
||||
|
||||
//go:linkname fips_getIndicator crypto/internal/fips140.getIndicator
|
||||
func fips_getIndicator() uint8 {
|
||||
return task.Current().FipsIndicator
|
||||
}
|
||||
|
||||
//go:linkname fips_setIndicator crypto/internal/fips140.setIndicator
|
||||
func fips_setIndicator(indicator uint8) {
|
||||
// This indicator is stored per goroutine.
|
||||
task.Current().FipsIndicator = indicator
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package runtime
|
||||
|
||||
// Dummy implementation of synctest functions (we don't support synctest at the
|
||||
// moment).
|
||||
|
||||
//go:linkname synctest_acquire internal/synctest.acquire
|
||||
func synctest_acquire() any {
|
||||
// Dummy: we don't support synctest.
|
||||
return nil
|
||||
}
|
||||
|
||||
//go:linkname synctest_release internal/synctest.release
|
||||
func synctest_release(sg any) {
|
||||
// Dummy: we don't support synctest.
|
||||
}
|
||||
@@ -1,5 +1,18 @@
|
||||
package runtime
|
||||
|
||||
//go:linkname time_runtimeNano time.runtimeNano
|
||||
func time_runtimeNano() int64 {
|
||||
// Note: we're ignoring sync groups here (package testing/synctest).
|
||||
// See: https://github.com/golang/go/issues/67434
|
||||
return nanotime()
|
||||
}
|
||||
|
||||
//go:linkname time_runtimeNow time.runtimeNow
|
||||
func time_runtimeNow() (sec int64, nsec int32, mono int64) {
|
||||
// Also ignoring the sync group here, like time_runtimeNano above.
|
||||
return now()
|
||||
}
|
||||
|
||||
// timerNode is an element in a linked list of timers.
|
||||
type timerNode struct {
|
||||
next *timerNode
|
||||
|
||||
@@ -233,6 +233,10 @@ func (w WaitStatus) Continued() bool { return false }
|
||||
func (w WaitStatus) StopSignal() Signal { return 0 }
|
||||
func (w WaitStatus) TrapCause() int { return 0 }
|
||||
|
||||
// Purely here for compatibility.
|
||||
type Rusage struct {
|
||||
}
|
||||
|
||||
// since rusage is quite a big struct and we stub it out anyway no need to define it here
|
||||
func Wait4(pid int, wstatus *WaitStatus, options int, rusage uintptr) (wpid int, err error) {
|
||||
return 0, ENOSYS // TODO
|
||||
|
||||
@@ -120,8 +120,11 @@ const (
|
||||
SYS_FCNTL64
|
||||
SYS_FSTATAT64
|
||||
SYS_IOCTL
|
||||
SYS_MKDIRAT
|
||||
SYS_OPENAT
|
||||
SYS_READLINKAT
|
||||
SYS_UNLINKAT
|
||||
SYS_WAITID
|
||||
PATH_MAX = 4096
|
||||
)
|
||||
|
||||
@@ -438,6 +441,13 @@ type RawSockaddrInet6 struct {
|
||||
// stub
|
||||
}
|
||||
|
||||
func RandomGet(b []byte) error {
|
||||
if len(b) > 0 {
|
||||
libc_arc4random_buf(unsafe.Pointer(&b[0]), uint(len(b)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// This is a stub, it is not functional.
|
||||
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
|
||||
|
||||
@@ -483,3 +493,8 @@ func libc_fdclosedir(unsafe.Pointer) int32
|
||||
//
|
||||
//export readdir
|
||||
func libc_readdir(unsafe.Pointer) *Dirent
|
||||
|
||||
// void arc4random_buf(void *buf, size_t buflen);
|
||||
//
|
||||
//export arc4random_buf
|
||||
func libc_arc4random_buf(buf unsafe.Pointer, buflen uint)
|
||||
|
||||
+47
-2
@@ -17,6 +17,7 @@ import (
|
||||
"io/fs"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -208,8 +209,9 @@ func (c *common) Failed() bool {
|
||||
// current goroutine).
|
||||
func (c *common) FailNow() {
|
||||
c.Fail()
|
||||
|
||||
c.finished = true
|
||||
runtime.Goexit()
|
||||
c.Error("FailNow is incomplete, requires runtime.Goexit()")
|
||||
}
|
||||
|
||||
// log generates the output.
|
||||
@@ -281,7 +283,7 @@ func (c *common) Skipf(format string, args ...interface{}) {
|
||||
func (c *common) SkipNow() {
|
||||
c.skip()
|
||||
c.finished = true
|
||||
runtime.Goexit()
|
||||
c.Error("SkipNow is incomplete, requires runtime.Goexit()")
|
||||
}
|
||||
|
||||
func (c *common) skip() {
|
||||
@@ -390,6 +392,49 @@ func (c *common) Setenv(key, value string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Chdir calls os.Chdir(dir) and uses Cleanup to restore the current
|
||||
// working directory to its original value after the test. On Unix, it
|
||||
// also sets PWD environment variable for the duration of the test.
|
||||
//
|
||||
// Because Chdir affects the whole process, it cannot be used
|
||||
// in parallel tests or tests with parallel ancestors.
|
||||
func (c *common) Chdir(dir string) {
|
||||
// Note: function copied from the Go 1.24.0 source tree.
|
||||
|
||||
oldwd, err := os.Open(".")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
// On POSIX platforms, PWD represents “an absolute pathname of the
|
||||
// current working directory.” Since we are changing the working
|
||||
// directory, we should also set or update PWD to reflect that.
|
||||
switch runtime.GOOS {
|
||||
case "windows", "plan9":
|
||||
// Windows and Plan 9 do not use the PWD variable.
|
||||
default:
|
||||
if !filepath.IsAbs(dir) {
|
||||
dir, err = os.Getwd()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
c.Setenv("PWD", dir)
|
||||
}
|
||||
c.Cleanup(func() {
|
||||
err := oldwd.Chdir()
|
||||
oldwd.Close()
|
||||
if err != nil {
|
||||
// It's not safe to continue with tests if we can't
|
||||
// get back to the original working directory. Since
|
||||
// we are holding a dirfd, this is highly unlikely.
|
||||
panic("testing.Chdir: " + err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// runCleanup is called at the end of the test.
|
||||
func (c *common) runCleanup() {
|
||||
for {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"inherits": ["pico2"],
|
||||
"build-tags": ["pico2-w", "cyw43439"]
|
||||
}
|
||||
@@ -4,5 +4,5 @@
|
||||
"build-tags": ["virt", "qemu"],
|
||||
"default-stack-size": 4096,
|
||||
"linkerscript": "targets/riscv-qemu.ld",
|
||||
"emulator": "qemu-system-riscv32 -machine virt -nographic -bios none -kernel {}"
|
||||
"emulator": "qemu-system-riscv32 -machine virt -nographic -bios none -device virtio-rng-device -kernel {}"
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
/* Memory map:
|
||||
* https://github.com/qemu/qemu/blob/master/hw/riscv/virt.c
|
||||
* RAM and flash are set to 1MB each. That should be enough for the foreseeable
|
||||
* future. QEMU does not seem to limit the flash/RAM size and in fact doesn't
|
||||
* seem to differentiate between it.
|
||||
* Looks like we can use any address starting from 0x80000000 (so 2GB of space).
|
||||
* However, using a large space slows down tests.
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
FLASH_TEXT (rw) : ORIGIN = 0x80000000, LENGTH = 0x100000
|
||||
RAM (xrw) : ORIGIN = 0x80100000, LENGTH = 0x100000
|
||||
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 100M
|
||||
}
|
||||
|
||||
REGION_ALIAS("FLASH_TEXT", RAM)
|
||||
|
||||
_stack_size = 2K;
|
||||
|
||||
INCLUDE "targets/riscv.ld"
|
||||
|
||||
@@ -321,6 +321,7 @@
|
||||
|
||||
// func stringVal(value string) ref
|
||||
"syscall/js.stringVal": (value_ptr, value_len) => {
|
||||
value_ptr >>>= 0;
|
||||
const s = loadString(value_ptr, value_len);
|
||||
return boxValue(s);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user