From 7486277012185e98d3896bfd81271b417ddbb029 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 27 Jan 2024 18:57:29 +0100 Subject: [PATCH] all: make TinyGo code usable with "big Go" CGo I managed to get CGo sort-of working in VSCode (meaning that it will typecheck code in the IDE itself) using a few crude hacks, but it requires a few minor changes to the TinyGo standard library. I intend to eventually add this support in the TinyGo extension for VSCode directly, but for now I've manually updated .vscode/settings.json to get IDE support. In any case, it would be nice to have this for when I hopefully add this to the TinyGo extension eventually. --- src/internal/task/task_stack_arm.S | 2 ++ src/internal/task/task_stack_avr.S | 2 ++ src/internal/task/task_stack_cortexm.S | 2 ++ src/internal/task/task_stack_cortexm.go | 8 ++++---- src/internal/task/task_stack_esp32.S | 2 ++ src/internal/task/task_stack_esp8266.S | 2 ++ src/internal/task/task_stack_tinygoriscv.S | 2 ++ src/machine/machine_rp2040_rom.go | 2 +- 8 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/internal/task/task_stack_arm.S b/src/internal/task/task_stack_arm.S index 3a1e3f0a..81a5aa8a 100644 --- a/src/internal/task/task_stack_arm.S +++ b/src/internal/task/task_stack_arm.S @@ -1,3 +1,5 @@ +//go:build tinygo + // Only generate .debug_frame, don't generate .eh_frame. .cfi_sections .debug_frame diff --git a/src/internal/task/task_stack_avr.S b/src/internal/task/task_stack_avr.S index 2cba528f..2e68b175 100644 --- a/src/internal/task/task_stack_avr.S +++ b/src/internal/task/task_stack_avr.S @@ -1,3 +1,5 @@ +//go:build tinygo + .section .bss.tinygo_systemStack .global tinygo_systemStack .type tinygo_systemStack, %object diff --git a/src/internal/task/task_stack_cortexm.S b/src/internal/task/task_stack_cortexm.S index fe1f44e0..dfe71355 100644 --- a/src/internal/task/task_stack_cortexm.S +++ b/src/internal/task/task_stack_cortexm.S @@ -1,3 +1,5 @@ +//go:build tinygo + // Only generate .debug_frame, don't generate .eh_frame. .cfi_sections .debug_frame diff --git a/src/internal/task/task_stack_cortexm.go b/src/internal/task/task_stack_cortexm.go index 39b90b75..226a088c 100644 --- a/src/internal/task/task_stack_cortexm.go +++ b/src/internal/task/task_stack_cortexm.go @@ -52,17 +52,17 @@ func (s *state) archInit(r *calleeSavedRegs, fn uintptr, args unsafe.Pointer) { } func (s *state) resume() { - switchToTask(s.sp) + tinygo_switchToTask(s.sp) } //export tinygo_switchToTask -func switchToTask(uintptr) +func tinygo_switchToTask(uintptr) //export tinygo_switchToScheduler -func switchToScheduler(*uintptr) +func tinygo_switchToScheduler(*uintptr) func (s *state) pause() { - switchToScheduler(&s.sp) + tinygo_switchToScheduler(&s.sp) } // SystemStack returns the system stack pointer. On Cortex-M, it is always diff --git a/src/internal/task/task_stack_esp32.S b/src/internal/task/task_stack_esp32.S index 364759b1..c2e4acc2 100644 --- a/src/internal/task/task_stack_esp32.S +++ b/src/internal/task/task_stack_esp32.S @@ -1,3 +1,5 @@ +//go:build tinygo + .section .text.tinygo_startTask,"ax",@progbits .global tinygo_startTask .type tinygo_startTask, %function diff --git a/src/internal/task/task_stack_esp8266.S b/src/internal/task/task_stack_esp8266.S index e7334edc..07f4e265 100644 --- a/src/internal/task/task_stack_esp8266.S +++ b/src/internal/task/task_stack_esp8266.S @@ -1,3 +1,5 @@ +//go:build tinygo + .section .text.tinygo_startTask,"ax",@progbits .global tinygo_startTask .type tinygo_startTask, %function diff --git a/src/internal/task/task_stack_tinygoriscv.S b/src/internal/task/task_stack_tinygoriscv.S index 0ac6f123..5f612742 100644 --- a/src/internal/task/task_stack_tinygoriscv.S +++ b/src/internal/task/task_stack_tinygoriscv.S @@ -1,3 +1,5 @@ +//go:build tinygo + .section .text.tinygo_startTask .global tinygo_startTask .type tinygo_startTask, %function diff --git a/src/machine/machine_rp2040_rom.go b/src/machine/machine_rp2040_rom.go index 2cf96d89..eea46188 100644 --- a/src/machine/machine_rp2040_rom.go +++ b/src/machine/machine_rp2040_rom.go @@ -1,4 +1,4 @@ -//go:build rp2040 +//go:build tinygo && rp2040 package machine