aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/rt0_js_wasm.s
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2018-03-31 23:14:17 +0200
committerBrad Fitzpatrick <bradfitz@golang.org>2018-05-08 00:17:34 +0000
commit35ea62468bf7e3a79011c3ad713e847daa9a45a2 (patch)
tree60e4870507f6d9bae6ed07539db29f650a6e10b5 /src/runtime/rt0_js_wasm.s
parentcc0aaff40e02192356ccb65d8acf571d12f74a95 (diff)
downloadgo-35ea62468bf7e3a79011c3ad713e847daa9a45a2.tar.gz
go-35ea62468bf7e3a79011c3ad713e847daa9a45a2.zip
runtime: add js/wasm architecture
This commit adds the js/wasm architecture to the runtime package. Currently WebAssembly has no support for threads yet, see https://github.com/WebAssembly/design/issues/1073. Because of that, there is no preemption of goroutines and no sysmon goroutine. Design doc: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4 About WebAssembly assembly files: https://docs.google.com/document/d/1GRmy3rA4DiYtBlX-I1Jr_iHykbX8EixC3Mq0TCYqbKc Updates #18892 Change-Id: I7f12d21b5180500d55ae9fd2f7e926a1731db391 Reviewed-on: https://go-review.googlesource.com/103877 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/rt0_js_wasm.s')
-rw-r--r--src/runtime/rt0_js_wasm.s49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/runtime/rt0_js_wasm.s b/src/runtime/rt0_js_wasm.s
new file mode 100644
index 0000000000..2a878d990c
--- /dev/null
+++ b/src/runtime/rt0_js_wasm.s
@@ -0,0 +1,49 @@
+// Copyright 2018 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"
+
+// _rt0_wasm_js does NOT follow the Go ABI. It has two WebAssembly parameters:
+// R0: argc (i32)
+// R1: argv (i32)
+TEXT _rt0_wasm_js(SB),NOSPLIT,$0
+ MOVD $runtime·wasmStack+m0Stack__size(SB), SP
+
+ Get SP
+ Get R0 // argc
+ I64ExtendUI32
+ I64Store $0
+
+ Get SP
+ Get R1 // argv
+ I64ExtendUI32
+ I64Store $8
+
+ I32Const $runtime·rt0_go(SB)
+ I32Const $16
+ I32ShrU
+ Set PC_F
+
+// Call the function for the current PC_F. Repeat until SP=0 indicates program end.
+// 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.
+loop:
+ Loop
+ Get SP
+ I32Eqz
+ If
+ Return
+ End
+
+ Get PC_F
+ CallIndirect $0
+ Drop
+
+ Br loop
+ End
+
+TEXT _rt0_wasm_js_lib(SB),NOSPLIT,$0
+ UNDEF