From 99de78e175bed03e21e0da72d2f084c88e4f62ad Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Fri, 24 Mar 2023 23:07:58 -0700 Subject: all: add wasip1 asm and link logic Add wasip1 asm and symbols to cmd/internal/obj, cmd/link and runtime. For #58141 Co-authored-by: Richard Musiol Co-authored-by: Achille Roussel Co-authored-by: Julien Fabre Co-authored-by: Evan Phoenix Change-Id: Ie088d9b65ea13e231694af6341465f95be33093f Reviewed-on: https://go-review.googlesource.com/c/go/+/479617 Reviewed-by: Ian Lance Taylor TryBot-Bypass: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui Run-TryBot: Ian Lance Taylor --- src/runtime/asm_wasm.s | 41 +++++++++++++++++++++++++++++++++++++++++ src/runtime/rt0_js_wasm.s | 39 --------------------------------------- src/runtime/rt0_wasip1_wasm.s | 16 ++++++++++++++++ 3 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 src/runtime/rt0_wasip1_wasm.s (limited to 'src/runtime') diff --git a/src/runtime/asm_wasm.s b/src/runtime/asm_wasm.s index 330c10cc0c..9cd8b5a99f 100644 --- a/src/runtime/asm_wasm.s +++ b/src/runtime/asm_wasm.s @@ -15,7 +15,9 @@ TEXT runtime·rt0_go(SB), NOSPLIT|NOFRAME|TOPFRAME, $0 // set g to g0 MOVD $runtime·g0(SB), g CALLNORESUME runtime·check(SB) +#ifdef GOOS_js CALLNORESUME runtime·args(SB) +#endif CALLNORESUME runtime·osinit(SB) CALLNORESUME runtime·schedinit(SB) MOVD $runtime·mainPC(SB), 0(SP) @@ -482,3 +484,42 @@ TEXT runtime·gcWriteBarrier8(SB),NOSPLIT,$0 I64Const $64 Call gcWriteBarrier<>(SB) Return + +TEXT wasm_pc_f_loop(SB),NOSPLIT,$0 +// Call the function for the current PC_F. Repeat until PAUSE != 0 indicates pause or exit. +// The WebAssembly stack may unwind, e.g. when switching goroutines. +// The Go stack on the linear memory is then used to jump to the correct functions +// with this loop, without having to restore the full WebAssembly stack. +// It is expected to have a pending call before entering the loop, so check PAUSE first. + Get PAUSE + I32Eqz + If + loop: + Loop + // Get PC_B & PC_F from -8(SP) + Get SP + I32Const $8 + I32Sub + I32Load16U $0 // PC_B + + Get SP + I32Const $8 + I32Sub + I32Load16U $2 // PC_F + + CallIndirect $0 + Drop + + Get PAUSE + I32Eqz + BrIf loop + End + End + + I32Const $0 + Set PAUSE + + Return + +TEXT wasm_export_lib(SB),NOSPLIT,$0 + UNDEF diff --git a/src/runtime/rt0_js_wasm.s b/src/runtime/rt0_js_wasm.s index 6f67752d63..34a60474f7 100644 --- a/src/runtime/rt0_js_wasm.s +++ b/src/runtime/rt0_js_wasm.s @@ -48,42 +48,6 @@ TEXT wasm_export_resume(SB),NOSPLIT,$0 Return -TEXT wasm_pc_f_loop(SB),NOSPLIT,$0 -// Call the function for the current PC_F. Repeat until PAUSE != 0 indicates pause or exit. -// The WebAssembly stack may unwind, e.g. when switching goroutines. -// The Go stack on the linear memory is then used to jump to the correct functions -// with this loop, without having to restore the full WebAssembly stack. -// It is expected to have a pending call before entering the loop, so check PAUSE first. - Get PAUSE - I32Eqz - If - loop: - Loop - // Get PC_B & PC_F from -8(SP) - Get SP - I32Const $8 - I32Sub - I32Load16U $0 // PC_B - - Get SP - I32Const $8 - I32Sub - I32Load16U $2 // PC_F - - CallIndirect $0 - Drop - - Get PAUSE - I32Eqz - BrIf loop - End - End - - I32Const $0 - Set PAUSE - - Return - // wasm_export_getsp gets called from JavaScript to retrieve the SP. TEXT wasm_export_getsp(SB),NOSPLIT,$0 Get SP @@ -101,6 +65,3 @@ TEXT runtime·exit(SB), NOSPLIT, $0-4 I32Const $1 Set PAUSE RETUNWIND - -TEXT wasm_export_lib(SB),NOSPLIT,$0 - UNDEF diff --git a/src/runtime/rt0_wasip1_wasm.s b/src/runtime/rt0_wasip1_wasm.s new file mode 100644 index 0000000000..6dc239306b --- /dev/null +++ b/src/runtime/rt0_wasip1_wasm.s @@ -0,0 +1,16 @@ +// Copyright 2023 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. + +#include "go_asm.h" +#include "textflag.h" + +TEXT _rt0_wasm_wasip1(SB),NOSPLIT,$0 + MOVD $runtime·wasmStack+(m0Stack__size-16)(SB), SP + + I32Const $0 // entry PC_B + Call runtime·rt0_go(SB) + Drop + Call wasm_pc_f_loop(SB) + + Return -- cgit v1.3-5-g9baa