Commit Graph

4591 Commits

Author SHA1 Message Date
deadprogram 1f114b2acf Release 0.41.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
v0.41.0
2026-04-21 02:42:54 +01:00
deadprogram 94ebddbdfe espflasher: update to espflasher 0.6.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-20 06:41:54 +01:00
deadprogram aa1ca27789 machine_atmega328p_simulator: add correct build tag for arduino_uno after renaming
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-19 10:48:04 +01:00
deadprogram 9999320cd0 build: actually use the version of llvm we are supposed to be testing by using brew link command
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-19 08:04:45 +01:00
deadprogram 74429b4a14 targets: rename arduino target to arduino-uno
Rename the "arduino" target to "arduino-uno" to better reflect the
board it represents. The "arduino" name is kept as an alias that
inherits from "arduino-uno" for backward compatibility.

- Rename targets/arduino.json to targets/arduino-uno.json
- Create targets/arduino.json as alias inheriting from arduino-uno
- Rename board_arduino.go to board_arduino_uno.go
- Update build tag from "arduino" to "arduino_uno"
- Rename corresponding example files

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 23:58:39 +01:00
Jake Bailey bcb191c01e runtime: handle GODEBUG on wasip2 (#5312)
* runtime: handle GODEBUG on wasip2
* Support env on more platforms to get GODEBUG working
2026-04-18 23:15:47 +02:00
deadprogram ddb848816f machine/esp32xx: add WASM simulator support for ESP32-C3/ESP32-S3 targets
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 19:40:04 +01:00
deadprogram 889911d0a6 machine/esp32c3: clear GPIO STATUS before dispatching pin callbacks
Move STATUS_W1TC clear to before the callback loop so that new GPIO
events arriving during handler execution generate a fresh edge on the
CPU interrupt line and are not lost. Matches the same fix applied to
ESP32-S3.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 18:18:42 +01:00
deadprogram a4dd38de81 machine/esp32s3: use edge-triggered CPU interrupt for GPIO pin interrupts
When SPI is configured via the GPIO Matrix, SPI signal transitions set
GPIO.STATUS bits on the routed pins. With a level-triggered CPU interrupt
(line 8), the ISR re-enters continuously as long as any STATUS bit is
asserted — causing user GPIO callbacks to fire spuriously.

Switch cpuInterruptFromPin to CPU interrupt 10, which is edge-triggered
(level 1) on the Xtensa LX7. This ensures the ISR fires once per GPIO
event rather than looping while SPI is active.

Also move STATUS_W1TC clears to before callback dispatch so that new
GPIO events arriving during handler execution generate a fresh edge, and
add writeINTCLEAR(active) in handleInterrupt to properly acknowledge
edge-triggered CPU interrupt pending bits via the INTCLEAR register.

Fixes GPIO interrupts firing constantly when SPI and pin interrupts are
used together.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 18:18:42 +01:00
deadprogram 486ee37a40 machine/esp32: default SPI CS pin to NoPin when unset
SPIConfig.CS has a zero value of Pin(0) (GPIO0), but NoPin is Pin(0xff).
When the user does not set CS, the SPI driver sees Pin(0) != NoPin and
configures GPIO0 as the chip select output, hijacking whatever function
that pin was serving such as a button interrupt.

Default config.CS to NoPin when it is the zero value, so an omitted CS
field correctly means "no hardware CS pin". Applied to both ESP32-S3 and
ESP32-C3 SPI drivers.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 17:12:21 +01:00
deadprogram 944176beef testdata: fix flaky timers test by draining ticker channel after Stop
Ticker.Stop does not drain already-buffered ticks from the channel,
so on slow CI runners a tick may already be queued before Stop takes
effect, causing a spurious "fail: ticker should have stopped!" failure.

Drain the channel immediately after Stop before checking that no new
ticks arrive.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 15:38:13 +01:00
Ayke van Laethem c396418187 ci: don't double zip release artifacts
See: https://github.blog/changelog/2026-02-26-github-actions-now-supports-uploading-and-downloading-non-zipped-artifacts/
2026-04-18 12:54:54 +01:00
deadprogram 1b4ab772d2 test: increase default timeout from 1 to 2 minutes to prevent spurious fails in CI from slow runners
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 10:20:25 +01:00
Jake Bailey aca0fe0412 Add errors package to passing list 2026-04-18 08:19:32 +01:00
deadprogram af511c1118 net: update to latest net submodule with UDP and JS improvements
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-18 07:17:08 +01:00
Jake Bailey 5ba8766cbc compiler: implement method-set based AssignableTo and Implements (#5304)
* reflect: implement method-set based AssignableTo and Implements

Based on the design from #4376 by aykevl.
Fixes #4277, fixes #3580.

Co-authored-by: Ayke van Laethem <aykevanlaethem@gmail.com>

* builder: update expected binary sizes for reflect changes

* Make interface checks similar to invoke, allowing typeImplementsMethodSet and method info to be dropped when reflect is not present

* Add more tests that BigGo reflect tests

* Even more pruning

* Add go/token and net/url to passing tests

* Prune even further, I am less happy with this, though

* Update size test now that we are smaller

* Skip some tests

* elide method lists

* format, oops

* fix tests

* Add a panic, pull out constant to keep in sync

* Add debug info

* Remove code that was leftover from a previous refactor

---------

Co-authored-by: Ayke van Laethem <aykevanlaethem@gmail.com>
2026-04-17 21:57:03 +02:00
Jake Bailey b792c10680 internal/tools: move into root 2026-04-17 19:18:17 +01:00
Jake Bailey 12d41ba0c1 go.mod, compiler: bump minimum Go version to 1.23
This enables gotypesalias=1 by default, which is needed for
generic type aliases to work correctly in go/types.
2026-04-17 19:18:17 +01:00
Ayke van Laethem 020cca8c3c wasm: add more stubbed file operations
This fixes issue #5037. A few more wasip1 syscalls needed to be present,
and in particular fd_prestat_get needed to return EBADF on invalid file
descriptors.
2026-04-17 16:02:45 +01:00
deadprogram 4cbd34d32f machine/esp32s3: implement Pin.SetInterrupt for GPIO pin change interrupts
Add support for rising, falling, and toggle edge interrupts on all
ESP32-S3 GPIO pins (0-48). The GPIO peripheral interrupt is routed
to CPU interrupt 8 via the interrupt matrix. The ISR reads both
STATUS and STATUS1 registers to cover the full 49-pin range.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-17 14:48:01 +01:00
Damian Gryski 6426bf79b4 make spellfix (+ manual tweak) 2026-04-17 10:33:07 +02:00
Damian Gryski aed8116b22 GNUmakefile: add context and expvar to stdlib tests 2026-04-17 09:12:32 +01:00
Damian Gryski f6c759ccbf GNUmakefile: add encoding/xml to stdlib tests on Linux 2026-04-15 22:43:04 +01:00
deadprogram 4b389b90e8 targets: add pins/setup for Arduino UNO Q board QWIIC connector
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-15 16:52:32 +01:00
deadprogram 4c3680635e machine/stm32: fix UART interrupt storm caused by uncleared overrun error
The UART handleInterrupt handler unconditionally read RDR on every
interrupt without checking which flag triggered it. On newer STM32
USART peripherals (U5, L4, L5, L0, G0, F7, WL), RXNEIE enables
interrupts for both RXFNE (data ready) and ORE (overrun error).
Unlike older families (F1, F4), ORE is not cleared by reading the
data register, it must be explicitly cleared via the ICR register.

When an overrun occurred (e.g. serial data arriving while ADC
busy-waits in Get()), ORE would trigger the interrupt, the handler
would fire without clearing it, and the interrupt would re-trigger
immediately, causing an infinite interrupt storm that locks up the
CPU.

Fix by:
- Checking RXFNE/RXNE (bit 5) before reading data from RDR
- Clearing ORE (bit 3) via ICR on newer peripherals when set
- Adding errClearReg field to UART struct, set to &Bus.ICR in
  setRegisters() for all ICR-capable families
- Preserving the SR+DR clearing sequence for older F1/F4 families

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-15 15:42:06 +01:00
Joel Wetzell 0755145824 create generic targets for esp32 boards 2026-04-15 10:28:33 +01:00
Jake Bailey eabd1ddce0 os: add UserCacheDir and UserConfigDir 2026-04-15 08:19:08 +01:00
deadprogram 0e84235f9a machine/esp32s3,esp32c3: add txStalled flag to skip USB serial spin when no host
When no USB host is reading, flushAndWait() spins 50K iterations per
FIFO-full event. With putchar calling WriteByte per byte, the cumulative
delay starves I2C and other peripherals, freezing displays.

Add a txStalled flag: the first FIFO-full triggers one flushAndWait
attempt. If it fails (no host), txStalled is set and all subsequent
writes return immediately with no spin — just a register read and a
bool check. When a host reconnects, SERIAL_IN_EP_DATA_FREE goes back
to 1, bypassing the stall path and clearing the flag automatically.
2026-04-14 18:26:30 +01:00
deadprogram 894839484c net: update to Go 1.26.2 net package
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-14 07:57:09 +01:00
deadprogram 1fadd0e772 builder: use target-specific -march for RISC-V library compilation
The -march flag for compiling C libraries (compiler-rt, picolibc) was
hardcoded to rv32imac for all riscv32 targets. This is incorrect for
targets that lack the atomic extension, such as ESP32-C3 (rv32imc) and
TKey (rv32iczmmul).

Extract the -march value from the target's cflags when available,
falling back to the previous defaults (rv32imac, rv64gc) for targets
that don't override it.

Fixes #5114

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-13 08:09:26 +01:00
deadprogram eba6e7a428 machine/esp32s3,esp32c3: make USB Serial/JTAG writes non-blocking when FIFO is full
When no USB host is reading (e.g. board not connected to a serial
monitor), WriteByte and Write would spin for up to 200k iterations
per byte waiting for the FIFO to drain. This stalled the entire
application, freezing unrelated peripherals like I2C displays.

Reduce flushTimeout from 200,000 to 50,000 iterations (~3ms) which
is enough for 2-3 USB frames when a host is connected, but short
enough that serial output won't freeze the application when no host
is reading. Serial output is best-effort; callers like putchar
already ignore write errors.

Applies to both ESP32-S3 and ESP32-C3 which share the same USB
Serial/JTAG controller design.
2026-04-13 06:23:23 +01:00
deadprogram f4a6e0373b main: update espflasher and auto-use best available flashing options on esp32
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-11 20:31:21 +01:00
deadprogram d274545e63 targets: add "adb" flash method using Android Debug Bridge
Add a new flash method that uses adb to flash boards over Android Debug
Bridge. The method supports running pre-flash shell commands via
"adb shell", pushing the firmware binary via "adb push", and running
post-flash shell commands with a {remote} token for the remote path.

New target JSON fields:
- adb-pre-commands: shell commands to run before pushing firmware
- adb-push-remote: remote device path for adb push
- adb-post-commands: shell commands to run after pushing firmware

Switch arduino-uno-q target to use the new adb flash method with
openocd running on the remote device.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-11 17:19:46 +01:00
deadprogram f74d25c882 build: use Golang 1.26 for all builds
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-11 12:38:36 +01:00
deadprogram 618c689246 runtime: fix Darwin syscall return value truncation and lost arguments
Go 1.26 replaced the individual Darwin syscall entry points (syscall,
syscallX, syscallPtr, syscall6, syscall6X) with two variadic functions:
syscalln and rawsyscalln. The old wrappers now have Go bodies that call
these, then use errno/errnoX/errnoPtr to interpret the result.

This caused two bugs in our rawsyscalln implementation:

1. Return value truncation: We used call_syscall/call_syscall6 which
   return int32, truncating 64-bit results (pointers from fdopendir,
   offsets from lseek, addresses from mmap). For example, a DIR* pointer
   returned by fdopendir would lose its upper 32 bits on arm64, causing
   SIGSEGV when later accessed.

2. Lost 4th argument: The case 4/5/6 fallthrough had 'a3 = args[3]'
   instead of 'a4 = args[3]', and a3 was immediately overwritten by
   'a1, a2, a3 = args[0], args[1], args[2]'. This lost the 4th syscall
   argument entirely, breaking pread (offset=0) and causing wrong data
   to be read from files.

Fix by using call_syscallX/call_syscall6X (returning full uintptr),
always reading errno (letting the Go wrappers decide what to do with
it), and correcting the argument assignment.
2026-04-11 12:38:36 +01:00
deadprogram 9d29971755 interp: make ptrtoint size mismatch a recoverable error
Go 1.26 changed Darwin's rawSyscall/Syscall from assembly stubs to Go
wrappers that call variadic rawsyscalln/syscalln. When the interp tries
to evaluate syscall.init() at compile time (which calls Getrlimit →
rawSyscall → rawsyscalln), it encounters a ptrtoint of a function
pointer and fails with 'ptrtoint integer size does not equal pointer
size'.

Make this a recoverable error so the interp reverts the init
interpretation and defers it to runtime, matching the behavior for other
uninterpretable init functions.
2026-04-11 12:38:36 +01:00
deadprogram 451c57af92 runtime: add syscall.runtimeClearenv for Go 1.26
Go 1.26 added syscall.runtimeClearenv (called by syscall.Clearenv) which
must be provided by the runtime via go:linkname. Without it, the os
package fails to link.
2026-04-11 12:38:36 +01:00
deadprogram 59feac28b9 internal/syscall/unix: implement GetRandom for WASI targets
Go 1.26's crypto/internal/sysrand uses internal/syscall/unix.GetRandom
on Linux-like targets (including wasip2 which sets GOOS=linux). The
existing stub panicked with 'todo: unix.GetRandom', causing crypto/ecdsa
tests to fail on wasip2.

Implement GetRandom on WASI targets (wasip1, wasip2) by calling the
arc4random_buf libc function that TinyGo's runtime already provides.
For other TinyGo targets, return ENOSYS so sysrand can fall back to
/dev/urandom.
2026-04-11 12:38:36 +01:00
deadprogram c1f48fc79a loader, crypto/internal/entropy: fix 32 MiB RAM overflow on microcontrollers
Go 1.26 added a CPU jitter-based SP 800-90B entropy source for FIPS 140-3
compliance (crypto/internal/entropy/v1.0.0). It declares a 32 MiB global
ScratchBuffer ([1<<25]byte) used for memory access timing noise. On systems
with virtual memory this stays in .noptrbss and is lazily paged, but on
baremetal targets it becomes static RAM, causing fatal overflow (e.g.
pybadge with 192 KB SRAM reports 33 MB overflow).

Since FIPS jitter entropy is never used on TinyGo targets (fips140.Enabled
is always false, so drbg.Read falls through to sysrand.Read), provide a
TinyGo overlay that replaces ScratchBuffer with [0]byte and stubs out all
entropy functions with panics.
2026-04-11 12:38:36 +01:00
deadprogram 3c07a36e95 loader, unicode/utf8: fix hiBits overflow on 16-bit AVR targets
Go 1.26 added SWAR optimizations to unicode/utf8 that use:

  const ptrSize = 4 << (^uintptr(0) >> 63)
  const hiBits = 0x8080808080808080 >> (64 - 8*ptrSize)

This formula only distinguishes 32-bit and 64-bit architectures.
On AVR (16-bit uintptr), ptrSize computes as 4, and hiBits becomes
0x80808080 (2155905152) which overflows the 16-bit uintptr type.

Fix by providing a patched unicode/utf8 overlay for Go 1.26+ that
uses a ptrSize formula handling all three sizes (16/32/64-bit):

  const ptrSize = 1 << (^uintptr(0)>>15&1 + ^uintptr(0)>>31&1 + ^uintptr(0)>>63&1)

This evaluates to 2 on AVR, 4 on 32-bit, and 8 on 64-bit. The
word() helper also gains a ptrSize==2 case for 16-bit loads.
2026-04-11 12:38:36 +01:00
deadprogram 98b3c27c76 builder: fix SIGSEGV when stripping duplicate function definitions
The previous approach of erasing basic blocks one-by-one from
duplicate function definitions could crash with a segfault. When
a function has complex control flow (branches, switches, PHI nodes),
deleting a basic block that is still referenced by instructions in
other blocks of the same function causes use-after-free in LLVM.

LLVM's C++ Function::deleteBody() avoids this by calling
dropAllReferences() on all blocks first, but that API is not
exposed in the Go LLVM bindings.

Fix this by using a completely different approach: instead of
manually deleting the function body, set the duplicate function's
linkage to LinkOnceODRLinkage. This tells the LLVM linker that the
definition can be merged with another copy, causing it to prefer
the already-linked ExternalLinkage definition in the destination
module. The result is the same (the runtime's definition wins) but
without any unsafe block manipulation.
2026-04-11 12:38:36 +01:00
deadprogram ddacdfacd5 compiler, runtime: fix SyscallN handling for Windows on Go 1.26+
Go 1.26 changed all Windows syscall wrappers in zsyscall_windows.go
to use SyscallN instead of fixed-argument Syscall/Syscall6/etc. The
SyscallN function now has a body that calls an unexported syscalln
function (provided by runtime via //go:linkname).

TinyGo's existing createSyscall compiler builtin used call.Args[2:]
to extract syscall arguments, but for variadic SyscallN the SSA
representation passes args as a slice value (not individual args),
causing call.Args[2:] to be empty -- resulting in zero arguments
being passed to Windows API calls and 0xc0000005 access violations.

Fix this by:
1. Excluding syscall.SyscallN from builtin interception, letting
   Go 1.26's function body compile normally (it calls syscalln)
2. Adding a new createSyscalln compiler builtin that intercepts
   syscall.syscalln and correctly handles the variadic slice:
   - Generates a switch on the arg count n (0-18 cases)
   - Each case loads args from the slice via GEP/Load
   - Wraps calls with SetLastError(0)/GetLastError() as before
   - Handles i386 stdcall conventions
3. Adding runtime stubs for both Go versions:
   - go1.26: syscall.syscalln stub (body intercepted by compiler)
   - pre-go1.26: syscall.SyscallN stub (linker satisfaction)
2026-04-11 12:38:36 +01:00
deadprogram 2d477e069d builder, runtime: fix duplicate symbol error with Go 1.26+ on Windows
Go 1.26 changed syscall.loadlibrary, syscall.loadsystemlibrary, and
syscall.getprocaddress from declarations to definitions in
syscall/dll_windows.go. TinyGo's runtime also defines these via
//go:linkname, causing "symbol multiply defined!" during LLVM module
linking.

Resolve this by detecting duplicate function definitions before calling
llvm.LinkModules and turning the incoming duplicate into a declaration,
so the runtime's version wins. TinyGo's implementations must take
precedence because Go 1.26's versions depend on //go:cgo_import_dynamic,
which TinyGo does not support.

Also fix the signature of syscall_loadsystemlibrary to match the
standard library (remove unused absoluteFilepath parameter).

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-04-11 12:38:36 +01:00
Damian Gryski ed1a56785a internal, runtime: add internal fips bool 2026-04-11 12:38:36 +01:00
Damian Gryski f496571747 compiler: add instrinsic for crypto/internal/constanttime.boolToUint8 2026-04-11 12:38:36 +01:00
Damian Gryski 17fed5980b internal/abi: add EscapeNonString, EscapeToResultNonString 2026-04-11 12:38:36 +01:00
Damian Gryski 2ff04f1a87 runtime: split syscall functions for darwin changes for 1.26 2026-04-11 12:38:36 +01:00
Damian Gryski f763865c5c src/internal/itoa: resurrect from Go stdlib
We use this a bunch. Upstream switched to `internal/strconv` which is much heavier.
2026-04-11 12:38:36 +01:00
Damian Gryski 52edf52245 builder: claim we support 1.26 now 2026-04-11 12:38:36 +01:00
Patricio Whittingslow 8161b766d3 add soypat/lneto to corpus 2026-04-09 16:19:33 +01:00