Compare commits

..

1 Commits

Author SHA1 Message Date
Isaac Rodman 4223a60823 Add qtpy-rp2040 to TinyGo v0.25.0 2022-09-02 09:26:23 +09:00
42 changed files with 362 additions and 716 deletions
+17 -12
View File
@@ -16,6 +16,10 @@ jobs:
name: build-macos name: build-macos
runs-on: macos-11 runs-on: macos-11
steps: steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.18.1'
- name: Install Dependencies - name: Install Dependencies
shell: bash shell: bash
run: | run: |
@@ -31,13 +35,8 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: true submodules: true
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.18.1'
cache: true
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-macos-v1 key: llvm-source-14-macos-v1
@@ -51,7 +50,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-macos-v1 key: llvm-build-14-macos-v1
@@ -69,7 +68,7 @@ jobs:
make llvm-build make llvm-build
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache wasi-libc sysroot - name: Cache wasi-libc sysroot
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-wasi-libc id: cache-wasi-libc
with: with:
key: wasi-libc-sysroot-v4 key: wasi-libc-sysroot-v4
@@ -105,17 +104,23 @@ jobs:
name: homebrew-install name: homebrew-install
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.18'
- name: Install LLVM - name: Install LLVM
shell: bash shell: bash
run: | run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@14 HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@14
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install Go - name: Cache Go
uses: actions/setup-go@v3 uses: actions/cache@v2
with: with:
go-version: '1.18' key: go-cache-macos-homebrew-v1-${{ hashFiles('go.mod') }}
cache: true path: |
~/Library/Caches/go-build
~/go/pkg/mod
- name: Build TinyGo - name: Build TinyGo
run: go install run: go install
- name: Check binary - name: Check binary
+48 -26
View File
@@ -18,13 +18,14 @@ jobs:
# statically linked binary. # statically linked binary.
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: golang:1.18-alpine image: alpine:3.16
steps: steps:
- name: Install apk dependencies - name: Install apk dependencies
# tar: needed for actions/cache@v3 # tar: needed for actions/cache@v2
# git+openssh: needed for checkout (I think?) # git+openssh: needed for checkout (I think?)
# gcompat: needed for go binary
# ruby: needed to install fpm # ruby: needed to install fpm
run: apk add tar git openssh make g++ ruby run: apk add tar git openssh gcompat make g++ ruby
- name: Work around CVE-2022-24765 - name: Work around CVE-2022-24765
# We're not on a multi-user machine, so this is safe. # We're not on a multi-user machine, so this is safe.
run: git config --global --add safe.directory "$GITHUB_WORKSPACE" run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
@@ -32,15 +33,19 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: true submodules: true
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.18.1'
- name: Cache Go - name: Cache Go
uses: actions/cache@v3 uses: actions/cache@v2
with: with:
key: go-cache-linux-alpine-v1-${{ hashFiles('go.mod') }} key: go-cache-linux-alpine-v1-${{ hashFiles('go.mod') }}
path: | path: |
~/.cache/go-build ~/.cache/go-build
~/go/pkg/mod ~/go/pkg/mod
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-linux-alpine-v1 key: llvm-source-14-linux-alpine-v1
@@ -54,7 +59,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-linux-alpine-v1 key: llvm-build-14-linux-alpine-v1
@@ -72,7 +77,7 @@ jobs:
# Remove unnecessary object files (to reduce cache size). # Remove unnecessary object files (to reduce cache size).
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache Binaryen - name: Cache Binaryen
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-binaryen id: cache-binaryen
with: with:
key: binaryen-linux-alpine-v1 key: binaryen-linux-alpine-v1
@@ -83,7 +88,7 @@ jobs:
apk add cmake samurai python3 apk add cmake samurai python3
make binaryen STATIC=1 make binaryen STATIC=1
- name: Cache wasi-libc - name: Cache wasi-libc
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-wasi-libc id: cache-wasi-libc
with: with:
key: wasi-libc-sysroot-linux-alpine-v1 key: wasi-libc-sysroot-linux-alpine-v1
@@ -116,10 +121,9 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install Go - name: Install Go
uses: actions/setup-go@v3 uses: actions/setup-go@v2
with: with:
go-version: '1.18.1' go-version: '1.18.1'
cache: true
- name: Install wasmtime - name: Install wasmtime
run: | run: |
curl https://wasmtime.dev/install.sh -sSf | bash curl https://wasmtime.dev/install.sh -sSf | bash
@@ -169,10 +173,9 @@ jobs:
simavr \ simavr \
ninja-build ninja-build
- name: Install Go - name: Install Go
uses: actions/setup-go@v3 uses: actions/setup-go@v2
with: with:
go-version: '1.18.1' go-version: '1.18.1'
cache: true
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v2 uses: actions/setup-node@v2
with: with:
@@ -181,8 +184,15 @@ jobs:
run: | run: |
curl https://wasmtime.dev/install.sh -sSf | bash curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
- name: Cache Go
uses: actions/cache@v2
with:
key: go-cache-linux-asserts-v1-${{ hashFiles('go.mod') }}
path: |
~/.cache/go-build
~/go/pkg/mod
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-linux-asserts-v2 key: llvm-source-14-linux-asserts-v2
@@ -196,7 +206,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-linux-asserts-v1 key: llvm-build-14-linux-asserts-v1
@@ -212,7 +222,7 @@ jobs:
# Remove unnecessary object files (to reduce cache size). # Remove unnecessary object files (to reduce cache size).
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache Binaryen - name: Cache Binaryen
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-binaryen id: cache-binaryen
with: with:
key: binaryen-linux-asserts-v1 key: binaryen-linux-asserts-v1
@@ -221,7 +231,7 @@ jobs:
if: steps.cache-binaryen.outputs.cache-hit != 'true' if: steps.cache-binaryen.outputs.cache-hit != 'true'
run: make binaryen run: make binaryen
- name: Cache wasi-libc - name: Cache wasi-libc
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-wasi-libc id: cache-wasi-libc
with: with:
key: wasi-libc-sysroot-linux-asserts-v5 key: wasi-libc-sysroot-linux-asserts-v5
@@ -269,12 +279,18 @@ jobs:
g++-arm-linux-gnueabihf \ g++-arm-linux-gnueabihf \
libc6-dev-armhf-cross libc6-dev-armhf-cross
- name: Install Go - name: Install Go
uses: actions/setup-go@v3 uses: actions/setup-go@v2
with: with:
go-version: '1.18.1' go-version: '1.18.1'
cache: true - name: Cache Go
uses: actions/cache@v2
with:
key: go-cache-linux-arm-v2-${{ hashFiles('go.mod') }}
path: |
~/.cache/go-build
~/go/pkg/mod
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-linux-v2 key: llvm-source-14-linux-v2
@@ -288,7 +304,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-linux-arm-v1 key: llvm-build-14-linux-arm-v1
@@ -306,7 +322,7 @@ jobs:
# Remove unnecessary object files (to reduce cache size). # Remove unnecessary object files (to reduce cache size).
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache Binaryen - name: Cache Binaryen
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-binaryen id: cache-binaryen
with: with:
key: binaryen-linux-arm-v1 key: binaryen-linux-arm-v1
@@ -369,12 +385,18 @@ jobs:
libc6-dev-arm64-cross \ libc6-dev-arm64-cross \
ninja-build ninja-build
- name: Install Go - name: Install Go
uses: actions/setup-go@v3 uses: actions/setup-go@v2
with: with:
go-version: '1.18.1' go-version: '1.18.1'
cache: true - name: Cache Go
uses: actions/cache@v2
with:
key: go-cache-linux-arm64-v2-${{ hashFiles('go.mod') }}
path: |
~/.cache/go-build
~/go/pkg/mod
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-linux-v1 key: llvm-source-14-linux-v1
@@ -388,7 +410,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-linux-arm64-v1 key: llvm-build-14-linux-arm64-v1
@@ -404,7 +426,7 @@ jobs:
# Remove unnecessary object files (to reduce cache size). # Remove unnecessary object files (to reduce cache size).
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache Binaryen - name: Cache Binaryen
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-binaryen id: cache-binaryen
with: with:
key: binaryen-linux-arm64-v1 key: binaryen-linux-arm64-v1
+13 -7
View File
@@ -15,6 +15,10 @@ jobs:
build-windows: build-windows:
runs-on: windows-2022 runs-on: windows-2022
steps: steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.18.1'
- uses: brechtm/setup-scoop@v2 - uses: brechtm/setup-scoop@v2
with: with:
scoop_update: 'false' scoop_update: 'false'
@@ -26,13 +30,15 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
submodules: true submodules: true
- name: Install Go - name: Cache Go
uses: actions/setup-go@v3 uses: actions/cache@v2
with: with:
go-version: '1.18.1' key: go-cache-windows-v1-${{ hashFiles('go.mod') }}
cache: true path: |
~/AppData/Local/go-build
~/go/pkg/mod
- name: Cache LLVM source - name: Cache LLVM source
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-source id: cache-llvm-source
with: with:
key: llvm-source-14-windows-v2 key: llvm-source-14-windows-v2
@@ -46,7 +52,7 @@ jobs:
if: steps.cache-llvm-source.outputs.cache-hit != 'true' if: steps.cache-llvm-source.outputs.cache-hit != 'true'
run: make llvm-source run: make llvm-source
- name: Cache LLVM build - name: Cache LLVM build
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-llvm-build id: cache-llvm-build
with: with:
key: llvm-build-14-windows-v2 key: llvm-build-14-windows-v2
@@ -63,7 +69,7 @@ jobs:
# Remove unnecessary object files (to reduce cache size). # Remove unnecessary object files (to reduce cache size).
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \; find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
- name: Cache wasi-libc sysroot - name: Cache wasi-libc sysroot
uses: actions/cache@v3 uses: actions/cache@v2
id: cache-wasi-libc id: cache-wasi-libc
with: with:
key: wasi-libc-sysroot-v4 key: wasi-libc-sysroot-v4
+8 -20
View File
@@ -326,15 +326,11 @@ TEST_PACKAGES_FAST += crypto/elliptic/internal/fiat
endif endif
# archive/zip requires os.ReadAt, which is not yet supported on windows # archive/zip requires os.ReadAt, which is not yet supported on windows
# compress/flate appears to hang on wasi
# compress/lzw appears to hang on wasi
# 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 # debug/plan9obj requires os.ReadAt, which is not yet supported on windows
# io/fs requires os.ReadDir, which is not yet supported on windows or wasi # io/fs requires os.ReadDir, which is not yet supported on windows or wasi
# io/ioutil requires os.ReadDir, which is not yet supported on windows or wasi
# strconv requires recover() which is not yet supported on wasi
# text/template/parse requires recover(), which is not yet supported on wasi
# testing/fstest requires os.ReadDir, which is not yet supported on windows or wasi # testing/fstest requires os.ReadDir, which is not yet supported on windows or wasi
# compress/flate fails windows go 1.18, https://github.com/tinygo-org/tinygo/issues/2762
# compress/lzw fails windows go 1.18 wasi, https://github.com/tinygo-org/tinygo/issues/2762
# Additional standard library packages that pass tests on individual platforms # Additional standard library packages that pass tests on individual platforms
TEST_PACKAGES_LINUX := \ TEST_PACKAGES_LINUX := \
@@ -353,12 +349,7 @@ TEST_PACKAGES_LINUX := \
TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX)
TEST_PACKAGES_WINDOWS := \ TEST_PACKAGES_WINDOWS := \
compress/flate \ compress/lzw
compress/lzw \
crypto/hmac \
strconv \
text/template/parse \
$(nil)
# Report platforms on which each standard library package is known to pass tests # Report platforms on which each standard library package is known to pass tests
jointmp := $(shell echo /tmp/join.$$$$) jointmp := $(shell echo /tmp/join.$$$$)
@@ -395,9 +386,9 @@ tinygo-bench-fast:
# Same thing, except for wasi rather than the current platform. # Same thing, except for wasi rather than the current platform.
tinygo-test-wasi: tinygo-test-wasi:
$(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi $(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW)
tinygo-test-wasi-fast: tinygo-test-wasi-fast:
$(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) ./tests/runtime_wasi $(TINYGO) test -target wasi $(TEST_PACKAGES_FAST)
tinygo-bench-wasi: tinygo-bench-wasi:
$(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) $(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW)
tinygo-bench-wasi-fast: tinygo-bench-wasi-fast:
@@ -419,7 +410,6 @@ tinygo-baremetal:
.PHONY: smoketest .PHONY: smoketest
smoketest: smoketest:
$(TINYGO) version $(TINYGO) version
$(TINYGO) targets > /dev/null
# regression test for #2892 # regression test for #2892
cd tests/testing/recurse && ($(TINYGO) test ./... > recurse.log && cat recurse.log && test $$(wc -l < recurse.log) = 2 && rm recurse.log) cd tests/testing/recurse && ($(TINYGO) test ./... > recurse.log && cat recurse.log && test $$(wc -l < recurse.log) = 2 && rm recurse.log)
# compile-only platform-independent examples # compile-only platform-independent examples
@@ -529,8 +519,6 @@ endif
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=feather-m4 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=feather-m4 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=matrixportal-m4 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pybadge examples/blinky1 $(TINYGO) build -size short -o test.hex -target=pybadge examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=metro-m4-airlift examples/blinky1 $(TINYGO) build -size short -o test.hex -target=metro-m4-airlift examples/blinky1
@@ -693,9 +681,7 @@ ifneq ($(XTENSA), 0)
$(TINYGO) build -size short -o test.bin -target mch2022 examples/serial $(TINYGO) build -size short -o test.bin -target mch2022 examples/serial
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
endif endif
$(TINYGO) build -size short -o test.bin -target=esp32c3 examples/serial $(TINYGO) build -size short -o test.bin -target=esp32c3 examples/serial
@$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.bin -target=esp32c3-12f examples/serial
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.bin -target=m5stamp-c3 examples/serial $(TINYGO) build -size short -o test.bin -target=m5stamp-c3 examples/serial
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
@@ -703,6 +689,8 @@ endif
@$(MD5SUM) test.bin @$(MD5SUM) test.bin
$(TINYGO) build -size short -o test.hex -target=hifive1b examples/blinky1 $(TINYGO) build -size short -o test.hex -target=hifive1b examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=hifive1-qemu examples/serial
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=maixbit examples/blinky1 $(TINYGO) build -size short -o test.hex -target=maixbit examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
ifneq ($(WASM), 0) ifneq ($(WASM), 0)
+1 -1
View File
@@ -125,7 +125,7 @@ The following 91 microcontroller boards are currently supported:
* [Seeed LoRa-E5 Development Kit](https://www.seeedstudio.com/LoRa-E5-Dev-Kit-p-4868.html) * [Seeed LoRa-E5 Development Kit](https://www.seeedstudio.com/LoRa-E5-Dev-Kit-p-4868.html)
* [Seeed Sipeed MAix BiT](https://www.seeedstudio.com/Sipeed-MAix-BiT-for-RISC-V-AI-IoT-p-2872.html) * [Seeed Sipeed MAix BiT](https://www.seeedstudio.com/Sipeed-MAix-BiT-for-RISC-V-AI-IoT-p-2872.html)
* [Seeed Wio Terminal](https://www.seeedstudio.com/Wio-Terminal-p-4509.html) * [Seeed Wio Terminal](https://www.seeedstudio.com/Wio-Terminal-p-4509.html)
* [SiFIve HiFive1 Rev B](https://www.sifive.com/boards/hifive1-rev-b) * [SiFIve HiFive1 Rev B](https://www.sifive.com/boards/hifive1)
* [Sparkfun Thing Plus RP2040](https://www.sparkfun.com/products/17745) * [Sparkfun Thing Plus RP2040](https://www.sparkfun.com/products/17745)
* [ST Micro "Nucleo" F103RB](https://www.st.com/en/evaluation-tools/nucleo-f103rb.html) * [ST Micro "Nucleo" F103RB](https://www.st.com/en/evaluation-tools/nucleo-f103rb.html)
* [ST Micro "Nucleo" F722ZE](https://www.st.com/en/evaluation-tools/nucleo-f722ze.html) * [ST Micro "Nucleo" F722ZE](https://www.st.com/en/evaluation-tools/nucleo-f722ze.html)
-1
View File
@@ -142,7 +142,6 @@ var validLinkerFlags = []*regexp.Regexp{
re(`-L([^@\-].*)`), re(`-L([^@\-].*)`),
re(`-O`), re(`-O`),
re(`-O([^@\-].*)`), re(`-O([^@\-].*)`),
re(`--export=(.+)`), // for wasm-ld
re(`-f(no-)?(pic|PIC|pie|PIE)`), re(`-f(no-)?(pic|PIC|pie|PIE)`),
re(`-f(no-)?openmp(-simd)?`), re(`-f(no-)?openmp(-simd)?`),
re(`-fsanitize=([^@\-].*)`), re(`-fsanitize=([^@\-].*)`),
+1 -8
View File
@@ -457,14 +457,7 @@ func (c *Config) OpenOCDConfiguration() (args []string, err error) {
args = append(args, "-c", cmd) args = append(args, "-c", cmd)
} }
if c.Target.OpenOCDTransport != "" { if c.Target.OpenOCDTransport != "" {
transport := c.Target.OpenOCDTransport args = append(args, "-c", "transport select "+c.Target.OpenOCDTransport)
if transport == "swd" {
switch openocdInterface {
case "stlink-dap":
transport = "dapdirect_swd"
}
}
args = append(args, "-c", "transport select "+transport)
} }
args = append(args, "-f", "target/"+c.Target.OpenOCDTarget+".cfg") args = append(args, "-f", "target/"+c.Target.OpenOCDTarget+".cfg")
return args, nil return args, nil
+10 -17
View File
@@ -65,7 +65,7 @@ type TargetSpec struct {
} }
// overrideProperties overrides all properties that are set in child into itself using reflection. // overrideProperties overrides all properties that are set in child into itself using reflection.
func (spec *TargetSpec) overrideProperties(child *TargetSpec) error { func (spec *TargetSpec) overrideProperties(child *TargetSpec) {
specType := reflect.TypeOf(spec).Elem() specType := reflect.TypeOf(spec).Elem()
specValue := reflect.ValueOf(spec).Elem() specValue := reflect.ValueOf(spec).Elem()
childValue := reflect.ValueOf(child).Elem() childValue := reflect.ValueOf(child).Elem()
@@ -95,15 +95,14 @@ func (spec *TargetSpec) overrideProperties(child *TargetSpec) error {
for j := i + 1; j < dst.Len(); j++ { for j := i + 1; j < dst.Len(); j++ {
w := dst.Index(j).String() w := dst.Index(j).String()
if v == w { if v == w {
return fmt.Errorf("duplicate value '%s' in field %s", v, field.Name) panic("duplicate value '" + v + "' in field : " + field.Name)
} }
} }
} }
default: default:
return fmt.Errorf("unknown field type: %s", kind) panic("unknown field type : " + kind.String())
} }
} }
return nil
} }
// load reads a target specification from the JSON in the given io.Reader. It // load reads a target specification from the JSON in the given io.Reader. It
@@ -118,10 +117,10 @@ func (spec *TargetSpec) load(r io.Reader) error {
} }
// loadFromGivenStr loads the TargetSpec from the given string that could be: // loadFromGivenStr loads the TargetSpec from the given string that could be:
// - targets/ directory inside the compiler sources // - targets/ directory inside the compiler sources
// - a relative or absolute path to custom (project specific) target specification .json file; // - a relative or absolute path to custom (project specific) target specification .json file;
// the Inherits[] could contain the files from target folder (ex. stm32f4disco) // the Inherits[] could contain the files from target folder (ex. stm32f4disco)
// as well as path to custom files (ex. myAwesomeProject.json) // as well as path to custom files (ex. myAwesomeProject.json)
func (spec *TargetSpec) loadFromGivenStr(str string) error { func (spec *TargetSpec) loadFromGivenStr(str string) error {
path := "" path := ""
if strings.HasSuffix(str, ".json") { if strings.HasSuffix(str, ".json") {
@@ -151,17 +150,11 @@ func (spec *TargetSpec) resolveInherits() error {
if err != nil { if err != nil {
return err return err
} }
err = newSpec.overrideProperties(subtarget) newSpec.overrideProperties(subtarget)
if err != nil {
return err
}
} }
// When all properties are loaded, make sure they are properly inherited. // When all properties are loaded, make sure they are properly inherited.
err := newSpec.overrideProperties(spec) newSpec.overrideProperties(spec)
if err != nil {
return err
}
*spec = *newSpec *spec = *newSpec
return nil return nil
@@ -228,7 +221,7 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
// it includes all parents as specified in the "inherits" key. // it includes all parents as specified in the "inherits" key.
err = spec.resolveInherits() err = spec.resolveInherits()
if err != nil { if err != nil {
return nil, fmt.Errorf("%s : %w", options.Target, err) return nil, err
} }
if spec.Scheduler == "asyncify" { if spec.Scheduler == "asyncify" {
+3 -4
View File
@@ -1059,12 +1059,11 @@ func (b *builder) createFunctionStart(intrinsic bool) {
if b.info.section != "" { if b.info.section != "" {
b.llvmFn.SetSection(b.info.section) b.llvmFn.SetSection(b.info.section)
} }
if b.info.exported && b.info.module != "" && strings.HasPrefix(b.Triple, "wasm") { if b.info.exported && strings.HasPrefix(b.Triple, "wasm") {
// Set the exported name. This is necessary for WebAssembly because // Set the exported name. This is necessary for WebAssembly because
// otherwise the function is not exported. // otherwise the function is not exported.
b.llvmFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-name", b.info.linkName)) functionAttr := b.ctx.CreateStringAttribute("wasm-export-name", b.info.linkName)
// Set the export module. b.llvmFn.AddFunctionAttr(functionAttr)
b.llvmFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-module", b.info.module))
} }
// Some functions have a pragma controlling the inlining level. // Some functions have a pragma controlling the inlining level.
+31 -23
View File
@@ -163,20 +163,18 @@ func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value {
// External/exported functions may not retain pointer values. // External/exported functions may not retain pointer values.
// https://golang.org/cmd/cgo/#hdr-Passing_pointers // https://golang.org/cmd/cgo/#hdr-Passing_pointers
if info.exported { if info.exported {
if c.archFamily() == "wasm32" { // Set the wasm-import-module attribute if the function's module is set.
// We need to add the wasm-import-module and the wasm-import-name if info.module != "" {
// attributes.
module := info.module
if module == "" {
module = "env"
}
llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("wasm-import-module", module))
name := info.importName // We need to add the wasm-import-module and the wasm-import-name
if name == "" { wasmImportModuleAttr := c.ctx.CreateStringAttribute("wasm-import-module", info.module)
name = info.linkName llvmFn.AddFunctionAttr(wasmImportModuleAttr)
// Add the Wasm Import Name, if we are a named wasm import
if info.importName != "" {
wasmImportNameAttr := c.ctx.CreateStringAttribute("wasm-import-name", info.importName)
llvmFn.AddFunctionAttr(wasmImportNameAttr)
} }
llvmFn.AddFunctionAttr(c.ctx.CreateStringAttribute("wasm-import-name", name))
} }
nocaptureKind := llvm.AttributeKindID("nocapture") nocaptureKind := llvm.AttributeKindID("nocapture")
nocapture := c.ctx.CreateEnumAttribute(nocaptureKind, 0) nocapture := c.ctx.CreateEnumAttribute(nocaptureKind, 0)
@@ -210,9 +208,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value {
// exported. // exported.
func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo { func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
info := functionInfo{ info := functionInfo{
module: "env", // Pick the default linkName.
importName: f.Name(), linkName: f.RelString(nil),
linkName: f.RelString(nil), // pick the default linkName
} }
// Check for //go: pragmas, which may change the link name (among others). // Check for //go: pragmas, which may change the link name (among others).
info.parsePragmas(f) info.parsePragmas(f)
@@ -226,6 +223,10 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
return return
} }
if decl, ok := f.Syntax().(*ast.FuncDecl); ok && decl.Doc != nil { if decl, ok := f.Syntax().(*ast.FuncDecl); ok && decl.Doc != nil {
// Our importName for a wasm module (if we are compiling to wasm), or llvm link name
var importName string
for _, comment := range decl.Doc.List { for _, comment := range decl.Doc.List {
text := comment.Text text := comment.Text
if strings.HasPrefix(text, "//export ") { if strings.HasPrefix(text, "//export ") {
@@ -243,8 +244,7 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
continue continue
} }
info.importName = parts[1] importName = parts[1]
info.linkName = parts[1]
info.exported = true info.exported = true
case "//go:interrupt": case "//go:interrupt":
if hasUnsafeImport(f.Pkg.Pkg) { if hasUnsafeImport(f.Pkg.Pkg) {
@@ -252,13 +252,10 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
} }
case "//go:wasm-module": case "//go:wasm-module":
// Alternative comment for setting the import module. // Alternative comment for setting the import module.
if len(parts) == 1 { if len(parts) != 2 {
// Function must not be exported outside of the WebAssembly continue
// module (but only be made available for linking).
info.module = ""
} else if len(parts) == 2 {
info.module = parts[1]
} }
info.module = parts[1]
case "//go:inline": case "//go:inline":
info.inline = inlineHint info.inline = inlineHint
case "//go:noinline": case "//go:noinline":
@@ -298,6 +295,17 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
} }
} }
} }
// Set the importName for our exported function if we have one
if importName != "" {
if info.module == "" {
info.linkName = importName
} else {
// WebAssembly import
info.importName = importName
}
}
} }
} }
+2 -2
View File
@@ -62,7 +62,7 @@ declare void @main.undefinedFunctionNotInSection(i8*) #0
attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-export-module"="env" "wasm-export-name"="extern_func" "wasm-import-module"="env" "wasm-import-name"="extern_func" } attributes #2 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-export-name"="extern_func" }
attributes #3 = { inlinehint nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } attributes #3 = { inlinehint nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #4 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" } attributes #4 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #5 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-export-module"="env" "wasm-export-name"="exportedFunctionInSection" "wasm-import-module"="env" "wasm-import-name"="exportedFunctionInSection" } attributes #5 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-export-name"="exportedFunctionInSection" }
+5 -25
View File
@@ -243,36 +243,17 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
// Tests are always run in the package directory. // Tests are always run in the package directory.
cmd.Dir = result.MainDir cmd.Dir = result.MainDir
// wasmtime is the default emulator used for `-target=wasi`. wasmtime // Wasmtime needs a few extra flags to work.
// is a WebAssembly runtime CLI with WASI enabled by default. However,
// only stdio are allowed by default. For example, while STDOUT routes
// to the host, other files don't. It also does not inherit environment
// variables from the host. Some tests read testdata files, often from
// outside the package directory. Other tests require temporary
// writeable directories. We allow this by adding wasmtime flags below.
if config.EmulatorName() == "wasmtime" { if config.EmulatorName() == "wasmtime" {
// At this point, The current working directory is at the package // Add directories to the module root, but skip the current working
// directory. Ex. $GOROOT/src/compress/flate for compress/flate. // directory which is already added by buildAndRun.
// buildAndRun has already added arguments for wasmtime, that allow
// read-access to files such as "testdata/huffman-zero.in".
//
// Ex. main(.wasm) --dir=. -- -test.v
// Below adds additional wasmtime flags in case a test reads files
// outside its directory, like "../testdata/e.txt". This allows any
// relative directory up to the module root, even if the test never
// reads any files.
//
// Ex. --dir=.. --dir=../.. --dir=../../..
dirs := dirsToModuleRoot(result.MainDir, result.ModuleRoot) dirs := dirsToModuleRoot(result.MainDir, result.ModuleRoot)
var args []string var args []string
for _, d := range dirs[1:] { for _, d := range dirs[1:] {
args = append(args, "--dir="+d) args = append(args, "--dir="+d)
} }
// Some tests create temp directories using os.MkdirTemp or via // create a new temp directory just for this run, announce it to os.TempDir() via TMPDIR
// t.TempDir(). Create a writeable directory and map it to the
// default tempDir environment variable: TMPDIR.
tmpdir, err := os.MkdirTemp("", "tinygotmp") tmpdir, err := os.MkdirTemp("", "tinygotmp")
if err != nil { if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err) return fmt.Errorf("failed to create temporary directory: %w", err)
@@ -281,8 +262,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
// TODO: add option to not delete temp dir for debugging? // TODO: add option to not delete temp dir for debugging?
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
// The below re-organizes the arguments so that the current // Insert new argments at the front of the command line argments.
// directory is added last.
args = append(args, cmd.Args[1:]...) args = append(args, cmd.Args[1:]...)
cmd.Args = append(cmd.Args[:1:1], args...) cmd.Args = append(cmd.Args[:1:1], args...)
} }
+2 -2
View File
@@ -1,5 +1,5 @@
//go:build nrf52840 || stm32 || (sam && atsamd51) || (sam && atsame5x) || rp2040 //go:build stm32 || (sam && atsamd51) || (sam && atsame5x)
// +build nrf52840 stm32 sam,atsamd51 sam,atsame5x rp2040 // +build stm32 sam,atsamd51 sam,atsame5x
package rand package rand
+11 -9
View File
@@ -21,14 +21,12 @@ $ tinygo build -o ./wasm.wasm -target wasm ./main/main.go
This creates a `wasm.wasm` file, which we can load in JavaScript and execute in This creates a `wasm.wasm` file, which we can load in JavaScript and execute in
a browser. a browser.
Next, choose which example you want to use: This examples folder contains two examples that can be built using `make`:
* [callback](callback): Defines and configures callbacks in Wasm.
* [export](export): Defines callbacks in Wasm, but configures them in JavaScript. ```bash
* [invoke](invoke): Invokes a function defined in JavaScript from Wasm. $ make export
* [main](main): Prints a message to the JavaScript console from Wasm. ```
* [slices](slices): Splits an Array defined in JavaScript from Wasm.
Let's say you chose [main](main), you'd build it like so:
```bash ```bash
$ make main $ make main
``` ```
@@ -44,8 +42,12 @@ Serving ./html on http://localhost:8080
Use your web browser to visit http://localhost:8080. Use your web browser to visit http://localhost:8080.
* Tip: Open the browser development tools (e.g. Right-click, Inspect in * The wasm "export" example displays a simple math equation using HTML, with
FireFox) to see console output. the result calculated dynamically using WebAssembly. Changing any of the
values on the left hand side triggers the exported wasm `update` function to
recalculate the result.
* The wasm "main" example uses `println` to write to your browser JavaScript
console. You may need to open the browser development tools console to see it.
## How it works ## How it works
-2
View File
@@ -8,12 +8,10 @@ import (
var a, b int var a, b int
func main() { func main() {
wait := make(chan struct{}, 0)
document := js.Global().Get("document") document := js.Global().Get("document")
document.Call("getElementById", "a").Set("oninput", updater(&a)) document.Call("getElementById", "a").Set("oninput", updater(&a))
document.Call("getElementById", "b").Set("oninput", updater(&b)) document.Call("getElementById", "b").Set("oninput", updater(&b))
update() update()
<-wait
} }
func updater(n *int) js.Func { func updater(n *int) js.Func {
-4
View File
@@ -2,16 +2,12 @@
.functype start_unwind (i32) -> () .functype start_unwind (i32) -> ()
.import_module start_unwind, asyncify .import_module start_unwind, asyncify
.import_name start_unwind, start_unwind
.functype stop_unwind () -> () .functype stop_unwind () -> ()
.import_module stop_unwind, asyncify .import_module stop_unwind, asyncify
.import_name stop_unwind, stop_unwind
.functype start_rewind (i32) -> () .functype start_rewind (i32) -> ()
.import_module start_rewind, asyncify .import_module start_rewind, asyncify
.import_name start_rewind, start_rewind
.functype stop_rewind () -> () .functype stop_rewind () -> ()
.import_module stop_rewind, asyncify .import_module stop_rewind, asyncify
.import_name stop_rewind, stop_rewind
.global tinygo_unwind .global tinygo_unwind
.hidden tinygo_unwind .hidden tinygo_unwind
+2 -28
View File
@@ -1,8 +1,5 @@
// Windows on amd64 has a slightly different ABI than other (*nix) systems. // Windows on amd64 has a slightly different ABI than other (*nix) systems.
// Therefore, assembly functions need to be tweaked slightly. // Therefore, assembly functions need to be tweaked slightly.
//
// The calling convention is described here:
// https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170
.section .text.tinygo_startTask,"ax" .section .text.tinygo_startTask,"ax"
.global tinygo_startTask .global tinygo_startTask
@@ -20,9 +17,8 @@ tinygo_startTask:
// Branch to the "goroutine start" function. // Branch to the "goroutine start" function.
callq *%r12 callq *%r12
// After return, exit this goroutine. // After return, exit this goroutine. This is a tail call.
// This has to be a call, not a jump, to keep the stack correctly aligned. jmp tinygo_pause
callq tinygo_pause
.global tinygo_swapTask .global tinygo_swapTask
.section .text.tinygo_swapTask,"ax" .section .text.tinygo_swapTask,"ax"
@@ -39,17 +35,6 @@ tinygo_swapTask:
pushq %rsi pushq %rsi
pushq %rdi pushq %rdi
pushq %rbp pushq %rbp
sub $160, %rsp
movaps %xmm6, 144(%rsp)
movaps %xmm7, 128(%rsp)
movaps %xmm8, 112(%rsp)
movaps %xmm9, 96(%rsp)
movaps %xmm10, 80(%rsp)
movaps %xmm11, 64(%rsp)
movaps %xmm12, 48(%rsp)
movaps %xmm13, 32(%rsp)
movaps %xmm14, 16(%rsp)
movaps %xmm15, 0(%rsp)
pushq %rbx pushq %rbx
// Save the current stack pointer in oldStack. // Save the current stack pointer in oldStack.
@@ -60,17 +45,6 @@ tinygo_swapTask:
// Load saved register from the new stack. // Load saved register from the new stack.
popq %rbx popq %rbx
movaps 0(%rsp), %xmm15
movaps 16(%rsp), %xmm14
movaps 32(%rsp), %xmm13
movaps 48(%rsp), %xmm12
movaps 64(%rsp), %xmm11
movaps 80(%rsp), %xmm10
movaps 96(%rsp), %xmm9
movaps 112(%rsp), %xmm8
movaps 128(%rsp), %xmm7
movaps 144(%rsp), %xmm6
add $160, %rsp
popq %rbp popq %rbp
popq %rdi popq %rdi
popq %rsi popq %rsi
+8 -27
View File
@@ -13,34 +13,15 @@ var systemStack uintptr
// calleeSavedRegs is the list of registers that must be saved and restored when // calleeSavedRegs is the list of registers that must be saved and restored when
// switching between tasks. Also see task_stack_amd64_windows.S that relies on // switching between tasks. Also see task_stack_amd64_windows.S that relies on
// the exact layout of this struct. // the exact layout of this struct.
// The calling convention is described here:
// https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170
// Most importantly, these are the registers we need to save/restore:
//
// > The x64 ABI considers registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14,
// > R15, and XMM6-XMM15 nonvolatile. They must be saved and restored by a
// > function that uses them.
type calleeSavedRegs struct { type calleeSavedRegs struct {
// Note: rbx is placed here so that the stack is correctly aligned when rbx uintptr
// loading/storing the xmm registers. rbp uintptr
rbx uintptr rdi uintptr
xmm15 [2]uint64 rsi uintptr
xmm14 [2]uint64 r12 uintptr
xmm13 [2]uint64 r13 uintptr
xmm12 [2]uint64 r14 uintptr
xmm11 [2]uint64 r15 uintptr
xmm10 [2]uint64
xmm9 [2]uint64
xmm8 [2]uint64
xmm7 [2]uint64
xmm6 [2]uint64
rbp uintptr
rdi uintptr
rsi uintptr
r12 uintptr
r13 uintptr
r14 uintptr
r15 uintptr
pc uintptr pc uintptr
} }
+6 -6
View File
@@ -12,9 +12,9 @@ const (
const ( const (
PB0 = portB + 0 PB0 = portB + 0
PB1 = portB + 1 // peripherals: Timer1 channel A PB1 = portB + 1
PB2 = portB + 2 // peripherals: Timer1 channel B PB2 = portB + 2
PB3 = portB + 3 // peripherals: Timer2 channel A PB3 = portB + 3
PB4 = portB + 4 PB4 = portB + 4
PB5 = portB + 5 PB5 = portB + 5
PB6 = portB + 6 PB6 = portB + 6
@@ -30,9 +30,9 @@ const (
PD0 = portD + 0 PD0 = portD + 0
PD1 = portD + 1 PD1 = portD + 1
PD2 = portD + 2 PD2 = portD + 2
PD3 = portD + 3 // peripherals: Timer2 channel B PD3 = portD + 3
PD4 = portD + 4 PD4 = portD + 4
PD5 = portD + 5 // peripherals: Timer0 channel B PD5 = portD + 5
PD6 = portD + 6 // peripherals: Timer0 channel A PD6 = portD + 6
PD7 = portD + 7 PD7 = portD + 7
) )
+34 -34
View File
@@ -10,38 +10,38 @@ func CPUFrequency() uint32 {
// Hardware pins // Hardware pins
const ( const (
PA00 Pin = 0 // peripherals: TCC2 channel 0 PA00 Pin = 0
PA01 Pin = 1 // peripherals: TCC2 channel 1 PA01 Pin = 1
PA02 Pin = 2 PA02 Pin = 2
PA03 Pin = 3 PA03 Pin = 3
PA04 Pin = 4 // peripherals: TCC0 channel 0 PA04 Pin = 4
PA05 Pin = 5 // peripherals: TCC0 channel 1 PA05 Pin = 5
PA06 Pin = 6 // peripherals: TCC1 channel 0 PA06 Pin = 6
PA07 Pin = 7 // peripherals: TCC1 channel 1 PA07 Pin = 7
PA08 Pin = 8 // peripherals: TCC0 channel 0, TCC1 channel 2 PA08 Pin = 8
PA09 Pin = 9 // peripherals: TCC0 channel 1, TCC1 channel 3 PA09 Pin = 9
PA10 Pin = 10 // peripherals: TCC1 channel 0, TCC0 channel 2 PA10 Pin = 10
PA11 Pin = 11 // peripherals: TCC1 channel 1, TCC0 channel 3 PA11 Pin = 11
PA12 Pin = 12 // peripherals: TCC2 channel 0, TCC0 channel 2 PA12 Pin = 12
PA13 Pin = 13 // peripherals: TCC2 channel 1, TCC0 channel 3 PA13 Pin = 13
PA14 Pin = 14 // peripherals: TCC0 channel 0 PA14 Pin = 14
PA15 Pin = 15 // peripherals: TCC0 channel 1 PA15 Pin = 15
PA16 Pin = 16 // peripherals: TCC2 channel 0, TCC0 channel 2 PA16 Pin = 16
PA17 Pin = 17 // peripherals: TCC2 channel 1, TCC0 channel 3 PA17 Pin = 17
PA18 Pin = 18 // peripherals: TCC0 channel 2 PA18 Pin = 18
PA19 Pin = 19 // peripherals: TCC0 channel 3 PA19 Pin = 19
PA20 Pin = 20 // peripherals: TCC0 channel 2 PA20 Pin = 20
PA21 Pin = 21 // peripherals: TCC0 channel 3 PA21 Pin = 21
PA22 Pin = 22 // peripherals: TCC0 channel 0 PA22 Pin = 22
PA23 Pin = 23 // peripherals: TCC0 channel 1 PA23 Pin = 23
PA24 Pin = 24 // peripherals: TCC1 channel 2 PA24 Pin = 24
PA25 Pin = 25 // peripherals: TCC1 channel 3 PA25 Pin = 25
PA26 Pin = 26 PA26 Pin = 26
PA27 Pin = 27 PA27 Pin = 27
PA28 Pin = 28 PA28 Pin = 28
PA29 Pin = 29 PA29 Pin = 29
PA30 Pin = 30 // peripherals: TCC1 channel 0 PA30 Pin = 30
PA31 Pin = 31 // peripherals: TCC1 channel 1 PA31 Pin = 31
PB00 Pin = 32 PB00 Pin = 32
PB01 Pin = 33 PB01 Pin = 33
PB02 Pin = 34 PB02 Pin = 34
@@ -52,14 +52,14 @@ const (
PB07 Pin = 39 PB07 Pin = 39
PB08 Pin = 40 PB08 Pin = 40
PB09 Pin = 41 PB09 Pin = 41
PB10 Pin = 42 // peripherals: TCC0 channel 0 PB10 Pin = 42
PB11 Pin = 43 // peripherals: TCC0 channel 1 PB11 Pin = 43
PB12 Pin = 44 // peripherals: TCC0 channel 2 PB12 Pin = 44
PB13 Pin = 45 // peripherals: TCC0 channel 3 PB13 Pin = 45
PB14 Pin = 46 PB14 Pin = 46
PB15 Pin = 47 PB15 Pin = 47
PB16 Pin = 48 // peripherals: TCC0 channel 0 PB16 Pin = 48
PB17 Pin = 49 // peripherals: TCC0 channel 1 PB17 Pin = 49
PB18 Pin = 50 PB18 Pin = 50
PB19 Pin = 51 PB19 Pin = 51
PB20 Pin = 52 PB20 Pin = 52
@@ -72,6 +72,6 @@ const (
PB27 Pin = 59 PB27 Pin = 59
PB28 Pin = 60 PB28 Pin = 60
PB29 Pin = 61 PB29 Pin = 61
PB30 Pin = 62 // peripherals: TCC0 channel 0, TCC1 channel 2 PB30 Pin = 62
PB31 Pin = 63 // peripherals: TCC0 channel 1, TCC1 channel 3 PB31 Pin = 63
) )
+5 -4
View File
@@ -36,9 +36,10 @@ const (
) )
const ( const (
NEOPIXEL = GPIO12 NEOPIXELS = GPIO12
WS2812 = GPIO12 WS2812 = GPIO12
NEOPIXEL_POWER = GPIO11 NEOPIXELS_POWER = GPIO11
LED = GPIO20
) )
// I2C Pins. // I2C Pins.
@@ -115,5 +116,5 @@ const (
var ( var (
usb_VID uint16 = 0x239A usb_VID uint16 = 0x239A
usb_PID uint16 = 0x80F7 usb_PID uint16 = 0x80F1
) )
+15 -15
View File
@@ -38,10 +38,10 @@ const (
PB1 = portB + 1 PB1 = portB + 1
PB2 = portB + 2 PB2 = portB + 2
PB3 = portB + 3 PB3 = portB + 3
PB4 = portB + 4 // peripherals: Timer2 channel A PB4 = portB + 4
PB5 = portB + 5 // peripherals: Timer1 channel A PB5 = portB + 5
PB6 = portB + 6 // peripherals: Timer1 channel B PB6 = portB + 6
PB7 = portB + 7 // peripherals: Timer0 channel A PB7 = portB + 7
PC0 = portC + 0 PC0 = portC + 0
PC1 = portC + 1 PC1 = portC + 1
PC2 = portC + 2 PC2 = portC + 2
@@ -57,9 +57,9 @@ const (
PD7 = portD + 7 PD7 = portD + 7
PE0 = portE + 0 PE0 = portE + 0
PE1 = portE + 1 PE1 = portE + 1
PE3 = portE + 3 // peripherals: Timer3 channel A PE3 = portE + 3
PE4 = portE + 4 // peripherals: Timer3 channel B PE4 = portE + 4
PE5 = portE + 5 // peripherals: Timer3 channel C PE5 = portE + 5
PE6 = portE + 6 PE6 = portE + 6
PF0 = portF + 0 PF0 = portF + 0
PF1 = portF + 1 PF1 = portF + 1
@@ -72,13 +72,13 @@ const (
PG0 = portG + 0 PG0 = portG + 0
PG1 = portG + 1 PG1 = portG + 1
PG2 = portG + 2 PG2 = portG + 2
PG5 = portG + 5 // peripherals: Timer0 channel B PG5 = portG + 5
PH0 = portH + 0 PH0 = portH + 0
PH1 = portH + 1 PH1 = portH + 1
PH3 = portH + 3 // peripherals: Timer4 channel A PH3 = portH + 3
PH4 = portH + 4 // peripherals: Timer4 channel B PH4 = portH + 4
PH5 = portH + 5 // peripherals: Timer4 channel C PH5 = portH + 5
PH6 = portH + 6 // peripherals: Timer0 channel B PH6 = portH + 6
PJ0 = portJ + 0 PJ0 = portJ + 0
PJ1 = portJ + 1 PJ1 = portJ + 1
PK0 = portK + 0 PK0 = portK + 0
@@ -92,9 +92,9 @@ const (
PL0 = portL + 0 PL0 = portL + 0
PL1 = portL + 1 PL1 = portL + 1
PL2 = portL + 2 PL2 = portL + 2
PL3 = portL + 3 // peripherals: Timer5 channel A PL3 = portL + 3
PL4 = portL + 4 // peripherals: Timer5 channel B PL4 = portL + 4
PL5 = portL + 5 // peripherals: Timer5 channel C PL5 = portL + 5
PL6 = portL + 6 PL6 = portL + 6
PL7 = portL + 7 PL7 = portL + 7
) )
+64 -64
View File
@@ -78,86 +78,86 @@ const (
PA05 Pin = 5 PA05 Pin = 5
PA06 Pin = 6 PA06 Pin = 6
PA07 Pin = 7 PA07 Pin = 7
PA08 Pin = 8 // peripherals: TCC0 channel 0, TCC1 channel 4 PA08 Pin = 8
PA09 Pin = 9 // peripherals: TCC0 channel 1, TCC1 channel 5 PA09 Pin = 9
PA10 Pin = 10 // peripherals: TCC0 channel 2, TCC1 channel 6 PA10 Pin = 10
PA11 Pin = 11 // peripherals: TCC0 channel 3, TCC1 channel 7 PA11 Pin = 11
PA12 Pin = 12 // peripherals: TCC0 channel 6, TCC1 channel 2 PA12 Pin = 12
PA13 Pin = 13 // peripherals: TCC0 channel 7, TCC1 channel 3 PA13 Pin = 13
PA14 Pin = 14 // peripherals: TCC2 channel 0, TCC1 channel 2 PA14 Pin = 14
PA15 Pin = 15 // peripherals: TCC2 channel 1, TCC1 channel 3 PA15 Pin = 15
PA16 Pin = 16 // peripherals: TCC1 channel 0, TCC0 channel 4 PA16 Pin = 16
PA17 Pin = 17 // peripherals: TCC1 channel 1, TCC0 channel 5 PA17 Pin = 17
PA18 Pin = 18 // peripherals: TCC1 channel 2, TCC0 channel 6 PA18 Pin = 18
PA19 Pin = 19 // peripherals: TCC1 channel 3, TCC0 channel 7 PA19 Pin = 19
PA20 Pin = 20 // peripherals: TCC1 channel 4, TCC0 channel 0 PA20 Pin = 20
PA21 Pin = 21 // peripherals: TCC1 channel 5, TCC0 channel 1 PA21 Pin = 21
PA22 Pin = 22 // peripherals: TCC1 channel 6, TCC0 channel 2 PA22 Pin = 22
PA23 Pin = 23 // peripherals: TCC1 channel 7, TCC0 channel 3 PA23 Pin = 23
PA24 Pin = 24 // peripherals: TCC2 channel 2 PA24 Pin = 24
PA25 Pin = 25 // peripherals: TCC2 channel 3 PA25 Pin = 25
PA26 Pin = 26 PA26 Pin = 26
PA27 Pin = 27 PA27 Pin = 27
PA28 Pin = 28 PA28 Pin = 28
PA29 Pin = 29 PA29 Pin = 29
PA30 Pin = 30 // peripherals: TCC2 channel 0 PA30 Pin = 30
PA31 Pin = 31 // peripherals: TCC2 channel 1 PA31 Pin = 31
PB00 Pin = 32 PB00 Pin = 32
PB01 Pin = 33 PB01 Pin = 33
PB02 Pin = 34 // peripherals: TCC2 channel 2 PB02 Pin = 34
PB03 Pin = 35 // peripherals: TCC2 channel 3 PB03 Pin = 35
PB04 Pin = 36 PB04 Pin = 36
PB05 Pin = 37 PB05 Pin = 37
PB06 Pin = 38 PB06 Pin = 38
PB07 Pin = 39 PB07 Pin = 39
PB08 Pin = 40 PB08 Pin = 40
PB09 Pin = 41 PB09 Pin = 41
PB10 Pin = 42 // peripherals: TCC0 channel 4, TCC1 channel 0 PB10 Pin = 42
PB11 Pin = 43 // peripherals: TCC0 channel 5, TCC1 channel 1 PB11 Pin = 43
PB12 Pin = 44 // peripherals: TCC3 channel 0, TCC0 channel 0 PB12 Pin = 44
PB13 Pin = 45 // peripherals: TCC3 channel 1, TCC0 channel 1 PB13 Pin = 45
PB14 Pin = 46 // peripherals: TCC4 channel 0, TCC0 channel 2 PB14 Pin = 46
PB15 Pin = 47 // peripherals: TCC4 channel 1, TCC0 channel 3 PB15 Pin = 47
PB16 Pin = 48 // peripherals: TCC3 channel 0, TCC0 channel 4 PB16 Pin = 48
PB17 Pin = 49 // peripherals: TCC3 channel 1, TCC0 channel 5 PB17 Pin = 49
PB18 Pin = 50 // peripherals: TCC1 channel 0 PB18 Pin = 50
PB19 Pin = 51 // peripherals: TCC1 channel 1 PB19 Pin = 51
PB20 Pin = 52 // peripherals: TCC1 channel 2 PB20 Pin = 52
PB21 Pin = 53 // peripherals: TCC1 channel 3 PB21 Pin = 53
PB22 Pin = 54 PB22 Pin = 54
PB23 Pin = 55 PB23 Pin = 55
PB24 Pin = 56 PB24 Pin = 56
PB25 Pin = 57 PB25 Pin = 57
PB26 Pin = 58 // peripherals: TCC1 channel 2 PB26 Pin = 58
PB27 Pin = 59 // peripherals: TCC1 channel 3 PB27 Pin = 59
PB28 Pin = 60 // peripherals: TCC1 channel 4 PB28 Pin = 60
PB29 Pin = 61 // peripherals: TCC1 channel 5 PB29 Pin = 61
PB30 Pin = 62 // peripherals: TCC4 channel 0, TCC0 channel 6 PB30 Pin = 62
PB31 Pin = 63 // peripherals: TCC4 channel 1, TCC0 channel 7 PB31 Pin = 63
PC00 Pin = 64 PC00 Pin = 64
PC01 Pin = 65 PC01 Pin = 65
PC02 Pin = 66 PC02 Pin = 66
PC03 Pin = 67 PC03 Pin = 67
PC04 Pin = 68 // peripherals: TCC0 channel 0 PC04 Pin = 68
PC05 Pin = 69 // peripherals: TCC0 channel 1 PC05 Pin = 69
PC06 Pin = 70 PC06 Pin = 70
PC07 Pin = 71 PC07 Pin = 71
PC08 Pin = 72 PC08 Pin = 72
PC09 Pin = 73 PC09 Pin = 73
PC10 Pin = 74 // peripherals: TCC0 channel 0, TCC1 channel 4 PC10 Pin = 74
PC11 Pin = 75 // peripherals: TCC0 channel 1, TCC1 channel 5 PC11 Pin = 75
PC12 Pin = 76 // peripherals: TCC0 channel 2, TCC1 channel 6 PC12 Pin = 76
PC13 Pin = 77 // peripherals: TCC0 channel 3, TCC1 channel 7 PC13 Pin = 77
PC14 Pin = 78 // peripherals: TCC0 channel 4, TCC1 channel 0 PC14 Pin = 78
PC15 Pin = 79 // peripherals: TCC0 channel 5, TCC1 channel 1 PC15 Pin = 79
PC16 Pin = 80 // peripherals: TCC0 channel 0 PC16 Pin = 80
PC17 Pin = 81 // peripherals: TCC0 channel 1 PC17 Pin = 81
PC18 Pin = 82 // peripherals: TCC0 channel 2 PC18 Pin = 82
PC19 Pin = 83 // peripherals: TCC0 channel 3 PC19 Pin = 83
PC20 Pin = 84 // peripherals: TCC0 channel 4 PC20 Pin = 84
PC21 Pin = 85 // peripherals: TCC0 channel 5 PC21 Pin = 85
PC22 Pin = 86 // peripherals: TCC0 channel 6 PC22 Pin = 86
PC23 Pin = 87 // peripherals: TCC0 channel 7 PC23 Pin = 87
PC24 Pin = 88 PC24 Pin = 88
PC25 Pin = 89 PC25 Pin = 89
PC26 Pin = 90 PC26 Pin = 90
@@ -174,20 +174,20 @@ const (
PD05 Pin = 101 PD05 Pin = 101
PD06 Pin = 102 PD06 Pin = 102
PD07 Pin = 103 PD07 Pin = 103
PD08 Pin = 104 // peripherals: TCC0 channel 1 PD08 Pin = 104
PD09 Pin = 105 // peripherals: TCC0 channel 2 PD09 Pin = 105
PD10 Pin = 106 // peripherals: TCC0 channel 3 PD10 Pin = 106
PD11 Pin = 107 // peripherals: TCC0 channel 4 PD11 Pin = 107
PD12 Pin = 108 // peripherals: TCC0 channel 5 PD12 Pin = 108
PD13 Pin = 109 // peripherals: TCC0 channel 6 PD13 Pin = 109
PD14 Pin = 110 PD14 Pin = 110
PD15 Pin = 111 PD15 Pin = 111
PD16 Pin = 112 PD16 Pin = 112
PD17 Pin = 113 PD17 Pin = 113
PD18 Pin = 114 PD18 Pin = 114
PD19 Pin = 115 PD19 Pin = 115
PD20 Pin = 116 // peripherals: TCC1 channel 0 PD20 Pin = 116
PD21 Pin = 117 // peripherals: TCC1 channel 1 PD21 Pin = 117
PD22 Pin = 118 PD22 Pin = 118
PD23 Pin = 119 PD23 Pin = 119
PD24 Pin = 120 PD24 Pin = 120
-60
View File
@@ -1,60 +0,0 @@
//go:build nrf52840
// +build nrf52840
package machine
import (
"device/nrf"
)
// Implementation based on Nordic Semiconductor's nRF52840 documentation version 1.7 found here:
// https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.7.pdf
// SetRNGBiasCorrection configures the RNG peripheral's bias correction mechanism. Note that when
// bias correction is enabled, the peripheral is slower to produce random values.
func SetRNGBiasCorrection(enabled bool) {
var val uint32
if enabled {
val = nrf.RNG_CONFIG_DERCEN_Enabled
}
nrf.RNG.SetCONFIG_DERCEN(val)
}
// RNGBiasCorrectionEnabled determines whether the RNG peripheral's bias correction mechanism is
// enabled or not.
func RNGBiasCorrectionEnabled() bool {
return nrf.RNG.GetCONFIG_DERCEN() == nrf.RNG_CONFIG_DERCEN_Enabled
}
// StartRNG starts the RNG peripheral core. This is automatically called by GetRNG, but can be
// manually called for interacting with the RNG peripheral directly.
func StartRNG() {
nrf.RNG.SetTASKS_START(nrf.RNG_TASKS_START_TASKS_START_Trigger)
}
// StopRNG stops the RNG peripheral core. This is not called automatically. It may make sense to
// manually disable RNG peripheral for power conservation.
func StopRNG() {
nrf.RNG.SetTASKS_STOP(nrf.RNG_TASKS_STOP_TASKS_STOP_Trigger)
}
// GetRNG returns 32 bits of non-deterministic random data based on internal thermal noise.
// According to Nordic's documentation, the random output is suitable for cryptographic purposes.
func GetRNG() (ret uint32, err error) {
// There's no apparent way to check the status of the RNG peripheral's task, so simply start it
// to avoid deadlocking while waiting for output.
StartRNG()
// The RNG returns one byte at a time, so stack up four bytes into a single uint32 for return.
for i := 0; i < 4; i++ {
// Wait for data to be ready.
for nrf.RNG.GetEVENTS_VALRDY() == nrf.RNG_EVENTS_VALRDY_EVENTS_VALRDY_NotGenerated {
}
// Append random byte to output.
ret = (ret << 8) ^ nrf.RNG.GetVALUE()
// Unset the EVENTS_VALRDY register to avoid reading the same random output twice.
nrf.RNG.SetEVENTS_VALRDY(nrf.RNG_EVENTS_VALRDY_EVENTS_VALRDY_NotGenerated)
}
return ret, nil
}
+30 -30
View File
@@ -11,36 +11,36 @@ const deviceName = rp.Device
const ( const (
// GPIO pins // GPIO pins
GPIO0 Pin = 0 // peripherals: PWM0 channel A GPIO0 Pin = 0
GPIO1 Pin = 1 // peripherals: PWM0 channel B GPIO1 Pin = 1
GPIO2 Pin = 2 // peripherals: PWM1 channel A GPIO2 Pin = 2
GPIO3 Pin = 3 // peripherals: PWM1 channel B GPIO3 Pin = 3
GPIO4 Pin = 4 // peripherals: PWM2 channel A GPIO4 Pin = 4
GPIO5 Pin = 5 // peripherals: PWM2 channel B GPIO5 Pin = 5
GPIO6 Pin = 6 // peripherals: PWM3 channel A GPIO6 Pin = 6
GPIO7 Pin = 7 // peripherals: PWM3 channel B GPIO7 Pin = 7
GPIO8 Pin = 8 // peripherals: PWM4 channel A GPIO8 Pin = 8
GPIO9 Pin = 9 // peripherals: PWM4 channel B GPIO9 Pin = 9
GPIO10 Pin = 10 // peripherals: PWM5 channel A GPIO10 Pin = 10
GPIO11 Pin = 11 // peripherals: PWM5 channel B GPIO11 Pin = 11
GPIO12 Pin = 12 // peripherals: PWM6 channel A GPIO12 Pin = 12
GPIO13 Pin = 13 // peripherals: PWM6 channel B GPIO13 Pin = 13
GPIO14 Pin = 14 // peripherals: PWM7 channel A GPIO14 Pin = 14
GPIO15 Pin = 15 // peripherals: PWM7 channel B GPIO15 Pin = 15
GPIO16 Pin = 16 // peripherals: PWM0 channel A GPIO16 Pin = 16
GPIO17 Pin = 17 // peripherals: PWM0 channel B GPIO17 Pin = 17
GPIO18 Pin = 18 // peripherals: PWM1 channel A GPIO18 Pin = 18
GPIO19 Pin = 19 // peripherals: PWM1 channel B GPIO19 Pin = 19
GPIO20 Pin = 20 // peripherals: PWM2 channel A GPIO20 Pin = 20
GPIO21 Pin = 21 // peripherals: PWM2 channel B GPIO21 Pin = 21
GPIO22 Pin = 22 // peripherals: PWM3 channel A GPIO22 Pin = 22
GPIO23 Pin = 23 // peripherals: PWM3 channel B GPIO23 Pin = 23
GPIO24 Pin = 24 // peripherals: PWM4 channel A GPIO24 Pin = 24
GPIO25 Pin = 25 // peripherals: PWM4 channel B GPIO25 Pin = 25
GPIO26 Pin = 26 // peripherals: PWM5 channel A GPIO26 Pin = 26
GPIO27 Pin = 27 // peripherals: PWM5 channel B GPIO27 Pin = 27
GPIO28 Pin = 28 // peripherals: PWM6 channel A GPIO28 Pin = 28
GPIO29 Pin = 29 // peripherals: PWM6 channel B GPIO29 Pin = 29
// Analog pins // Analog pins
ADC0 Pin = GPIO26 ADC0 Pin = GPIO26
-38
View File
@@ -1,38 +0,0 @@
//go:build rp2040
// +build rp2040
// Implementation based on code located here:
// https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_lwip/random.c
package machine
import (
"device/rp"
)
const numberOfCycles = 32
// GetRNG returns 32 bits of semi-random data based on ring oscillator.
func GetRNG() (uint32, error) {
var val uint32
for i := 0; i < 4; i++ {
val = (val << 8) | uint32(roscRandByte())
}
return val, nil
}
var randomByte uint8
func roscRandByte() uint8 {
var poly uint8
for i := 0; i < numberOfCycles; i++ {
if randomByte&0x80 != 0 {
poly = 0x35
} else {
poly = 0
}
randomByte = ((randomByte << 1) | uint8(rp.ROSC.GetRANDOMBIT()) ^ poly)
// TODO: delay a little because the random bit is a little slow
}
return randomByte
}
+13 -40
View File
@@ -61,58 +61,31 @@ func growHeap() bool {
return true return true
} }
// The below functions override the default allocator of wasi-libc. This ensures // The below functions override the default allocator of wasi-libc.
// code linked from other languages can allocate memory without colliding with // Most functions are defined but unimplemented to make sure that if there is
// our GC allocations. // any code using them, they will get an error instead of (incorrectly) using
// the wasi-libc dlmalloc heap implementation instead. If they are needed by any
var allocs = make(map[uintptr][]byte) // program, they can certainly be implemented.
//export malloc //export malloc
//go:wasm-module
func libc_malloc(size uintptr) unsafe.Pointer { func libc_malloc(size uintptr) unsafe.Pointer {
buf := make([]byte, size) return alloc(size, nil)
ptr := unsafe.Pointer(&buf[0])
allocs[uintptr(ptr)] = buf
return ptr
} }
//export free //export free
//go:wasm-module
func libc_free(ptr unsafe.Pointer) { func libc_free(ptr unsafe.Pointer) {
if ptr == nil { free(ptr)
return
}
if _, ok := allocs[uintptr(ptr)]; ok {
delete(allocs, uintptr(ptr))
} else {
panic("free: invalid pointer")
}
} }
//export calloc //export calloc
//go:wasm-module
func libc_calloc(nmemb, size uintptr) unsafe.Pointer { func libc_calloc(nmemb, size uintptr) unsafe.Pointer {
// No difference between calloc and malloc. // Note: we could be even more correct here and check that nmemb * size
return libc_malloc(nmemb * size) // doesn't overflow. However the current implementation should normally work
// fine.
return alloc(nmemb*size, nil)
} }
//export realloc //export realloc
//go:wasm-module func libc_realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
func libc_realloc(oldPtr unsafe.Pointer, size uintptr) unsafe.Pointer { return realloc(ptr, size)
// It's hard to optimize this to expand the current buffer with our GC, but
// it is theoretically possible. For now, just always allocate fresh.
buf := make([]byte, size)
if oldPtr != nil {
if oldBuf, ok := allocs[uintptr(oldPtr)]; ok {
copy(buf, oldBuf)
delete(allocs, uintptr(oldPtr))
} else {
panic("realloc: invalid pointer")
}
}
ptr := unsafe.Pointer(&buf[0])
allocs[uintptr(ptr)] = buf
return ptr
} }
+2 -13
View File
@@ -10,7 +10,8 @@ import (
var ErrUnimplemented = errors.New("runtime/pprof: unimplemented") var ErrUnimplemented = errors.New("runtime/pprof: unimplemented")
type Profile struct{} type Profile struct {
}
func StartCPUProfile(w io.Writer) error { func StartCPUProfile(w io.Writer) error {
return nil return nil
@@ -27,18 +28,6 @@ func Lookup(name string) *Profile {
return nil return nil
} }
func (p *Profile) Name() string {
return ""
}
func (p *Profile) Count() int {
return 0
}
func (p *Profile) WriteTo(w io.Writer, debug int) error { func (p *Profile) WriteTo(w io.Writer, debug int) error {
return ErrUnimplemented return ErrUnimplemented
} }
func Profiles() []*Profile {
return nil
}
-13
View File
@@ -1,13 +0,0 @@
// Stubs for the runtime/trace package
package trace
import (
"errors"
"io"
)
func Start(w io.Writer) error {
return errors.New("not implemented")
}
func Stop() {}
-11
View File
@@ -34,17 +34,6 @@ func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bo
return value, false return value, false
} }
func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool) {
m.lock.Lock()
defer m.lock.Unlock()
value, ok := m.m[key]
if !ok {
return nil, false
}
delete(m.m, key)
return value, true
}
func (m *Map) Store(key, value interface{}) { func (m *Map) Store(key, value interface{}) {
m.lock.Lock() m.lock.Lock()
defer m.lock.Unlock() defer m.lock.Unlock()
-19
View File
@@ -1,19 +0,0 @@
package sync_test
import (
"sync"
"testing"
)
func TestMapLoadAndDelete(t *testing.T) {
var sm sync.Map
sm.Store("present", "value")
if v, ok := sm.LoadAndDelete("present"); !ok || v != "value" {
t.Errorf("LoadAndDelete returned %v, %v, want value, true", v, ok)
}
if v, ok := sm.LoadAndDelete("absent"); ok || v != nil {
t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok)
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"inherits": ["esp32c3"], "inherits": ["esp32c3"],
"build-tags": ["esp32c312f"] "build-tags": ["esp32c312f", "esp32c3", "esp"]
} }
+8
View File
@@ -0,0 +1,8 @@
{
"inherits": ["fe310"],
"build-tags": ["hifive1b", "qemu"],
"serial": "uart",
"default-stack-size": 4096,
"linkerscript": "targets/hifive1-qemu.ld",
"emulator": "qemu-system-riscv32 -machine sifive_e -nographic -kernel {}"
}
+16
View File
@@ -0,0 +1,16 @@
/* memory map:
* https://github.com/sifive/freedom-e-sdk/blob/v201908-branch/bsp/sifive-hifive1/metal.default.lds
* With one change: this linkerscript uses 64K RAM instead of 16K as specified
* in metal.default.lds. Not sure why this works, but it works, and it avoids
* out-of-memory issues when running tests.
*/
MEMORY
{
FLASH_TEXT (rw) : ORIGIN = 0x20400000, LENGTH = 0x1fc00000
RAM (xrw) : ORIGIN = 0x80000000, LENGTH = 64K
}
_stack_size = 2K;
INCLUDE "targets/riscv.ld"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"inherits": ["atsamd51j19a"], "inherits": ["atsamd51j19a"],
"build-tags": ["matrixportal_m4"], "build-tags": ["atsamd51j19a", "matrixportal_m4"],
"serial": "usb", "serial": "usb",
"serial-port": ["acm:239a:80c9", "acm:239a:00c9", "acm:239a:80ca"], "serial-port": ["acm:239a:80c9", "acm:239a:00c9", "acm:239a:80ca"],
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
+1 -1
View File
@@ -6,7 +6,7 @@
// rp2040-boot-stage2.S // rp2040-boot-stage2.S
// //
#define BOARD_PICO_FLASH_SPI_CLKDIV 2 #define BOARD_PICO_FLASH_SPI_CLKDIV 4
#define BOARD_CMD_READ 0xe7 #define BOARD_CMD_READ 0xe7
#define BOARD_QUAD_OK 1 #define BOARD_QUAD_OK 1
#define BOARD_QUAD_ENABLE_STATUS_BYTE 2 #define BOARD_QUAD_ENABLE_STATUS_BYTE 2
+2 -3
View File
@@ -2,11 +2,10 @@
"inherits": [ "inherits": [
"rp2040" "rp2040"
], ],
"serial-port": ["acm:239a:80f7"], "serial-port": ["acm:239a:80f1"],
"build-tags": ["qtpy_rp2040"], "build-tags": ["qtpy_rp2040"],
"linkerscript": "targets/qtpy-rp2040.ld", "linkerscript": "targets/qtpy-rp2040.ld",
"extra-files": [ "extra-files": [
"targets/qtpy-rp2040-boot-stage2.S" "targets/qtpy-rp2040-boot-stage2.S"
], ]
"default-stack-size": 4096
} }
+1
View File
@@ -15,6 +15,7 @@
"-msign-ext" "-msign-ext"
], ],
"ldflags": [ "ldflags": [
"--allow-undefined",
"--stack-first", "--stack-first",
"--no-demangle" "--no-demangle"
], ],
-16
View File
@@ -1,16 +0,0 @@
syscall/js.copyBytesToGo
syscall/js.copyBytesToJS
syscall/js.finalizeRef
syscall/js.stringVal
syscall/js.valueCall
syscall/js.valueDelete
syscall/js.valueGet
syscall/js.valueIndex
syscall/js.valueInstanceOf
syscall/js.valueInvoke
syscall/js.valueLength
syscall/js.valueLoadString
syscall/js.valueNew
syscall/js.valuePrepareString
syscall/js.valueSet
syscall/js.valueSetIndex
+1 -1
View File
@@ -15,7 +15,7 @@
"-msign-ext" "-msign-ext"
], ],
"ldflags": [ "ldflags": [
"--allow-undefined-file={root}/targets/wasm-undefined.txt", "--allow-undefined",
"--stack-first", "--stack-first",
"--no-demangle" "--no-demangle"
], ],
-1
View File
@@ -282,4 +282,3 @@
version: master version: master
- repo: github.com/russross/blackfriday - repo: github.com/russross/blackfriday
version: v2 version: v2
- repo: github.com/soypat/mu8
-127
View File
@@ -1,127 +0,0 @@
//go:build tinygo.wasm
// +build tinygo.wasm
package runtime_wasi
import (
"reflect"
"runtime"
"strconv"
"testing"
"unsafe"
)
//export malloc
func libc_malloc(size uintptr) unsafe.Pointer
//export free
func libc_free(ptr unsafe.Pointer)
//export calloc
func libc_calloc(nmemb, size uintptr) unsafe.Pointer
//export realloc
func libc_realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer
func getFilledBuffer_malloc() uintptr {
ptr := libc_malloc(5)
fillPanda(ptr)
return uintptr(ptr)
}
func getFilledBuffer_calloc() uintptr {
ptr := libc_calloc(2, 5)
fillPanda(ptr)
*(*byte)(unsafe.Add(ptr, 5)) = 'b'
*(*byte)(unsafe.Add(ptr, 6)) = 'e'
*(*byte)(unsafe.Add(ptr, 7)) = 'a'
*(*byte)(unsafe.Add(ptr, 8)) = 'r'
*(*byte)(unsafe.Add(ptr, 9)) = 's'
return uintptr(ptr)
}
func getFilledBuffer_realloc() uintptr {
origPtr := getFilledBuffer_malloc()
ptr := libc_realloc(unsafe.Pointer(origPtr), 9)
*(*byte)(unsafe.Add(ptr, 5)) = 'b'
*(*byte)(unsafe.Add(ptr, 6)) = 'e'
*(*byte)(unsafe.Add(ptr, 7)) = 'a'
*(*byte)(unsafe.Add(ptr, 8)) = 'r'
return uintptr(ptr)
}
func getFilledBuffer_reallocNil() uintptr {
ptr := libc_realloc(nil, 5)
fillPanda(ptr)
return uintptr(ptr)
}
func fillPanda(ptr unsafe.Pointer) {
*(*byte)(unsafe.Add(ptr, 0)) = 'p'
*(*byte)(unsafe.Add(ptr, 1)) = 'a'
*(*byte)(unsafe.Add(ptr, 2)) = 'n'
*(*byte)(unsafe.Add(ptr, 3)) = 'd'
*(*byte)(unsafe.Add(ptr, 4)) = 'a'
}
func checkFilledBuffer(t *testing.T, ptr uintptr, content string) {
t.Helper()
buf := *(*string)(unsafe.Pointer(&reflect.StringHeader{
Data: ptr,
Len: uintptr(len(content)),
}))
if buf != content {
t.Errorf("expected %q, got %q", content, buf)
}
}
func TestMallocFree(t *testing.T) {
tests := []struct {
name string
getBuffer func() uintptr
content string
}{
{
name: "malloc",
getBuffer: getFilledBuffer_malloc,
content: "panda",
},
{
name: "calloc",
getBuffer: getFilledBuffer_calloc,
content: "pandabears",
},
{
name: "realloc",
getBuffer: getFilledBuffer_realloc,
content: "pandabear",
},
{
name: "realloc nil",
getBuffer: getFilledBuffer_reallocNil,
content: "panda",
},
}
for _, tc := range tests {
tt := tc
t.Run(tt.name, func(t *testing.T) {
bufPtr := tt.getBuffer()
// Don't use defer to free the buffer as it seems to cause the GC to track it.
// Churn GC, the pointer should still be valid until free is called.
for i := 0; i < 1000; i++ {
a := "hello" + strconv.Itoa(i)
// Some conditional logic to ensure optimization doesn't remove the loop completely.
if len(a) < 0 {
break
}
runtime.GC()
}
checkFilledBuffer(t, bufPtr, tt.content)
libc_free(unsafe.Pointer(bufPtr))
})
}
}