aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorElliott Sales de Andrade <[email protected]>2019-07-24 03:46:12 -0400
committerAyke <[email protected]>2019-08-04 18:15:06 +0200
commit9878f7ebc4b7451b6a3f24e2a58ba23bdc6f6963 (patch)
tree35981ec30f16050c859a7fef93cc52817ddf1155
parent4688664b4116283ffcc4d7652b6d8052f6dcdc60 (diff)
downloadtinygo-9878f7ebc4b7451b6a3f24e2a58ba23bdc6f6963.tar.gz
tinygo-9878f7ebc4b7451b6a3f24e2a58ba23bdc6f6963.zip
Add support for linux/386 syscalls.
-rw-r--r--compiler/syscall.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler/syscall.go b/compiler/syscall.go
index 96c120cf3..293480e62 100644
--- a/compiler/syscall.go
+++ b/compiler/syscall.go
@@ -58,6 +58,32 @@ func (c *Compiler) emitSyscall(frame *Frame, call *ssa.CallCommon) (llvm.Value,
fnType := llvm.FunctionType(c.uintptrType, argTypes, false)
target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel)
syscallResult = c.builder.CreateCall(target, args, "")
+ case c.GOARCH == "386" && c.GOOS == "linux":
+ // Sources:
+ // syscall(2) man page
+ // https://stackoverflow.com/a/2538212
+ // https://en.wikibooks.org/wiki/X86_Assembly/Interfacing_with_Linux#int_0x80
+ args := []llvm.Value{num}
+ argTypes := []llvm.Type{c.uintptrType}
+ // Constraints will look something like:
+ // "={eax},0,{ebx},{ecx},{edx},{esi},{edi},{ebp}"
+ constraints := "={eax},0"
+ for i, arg := range call.Args[1:] {
+ constraints += "," + [...]string{
+ "{ebx}",
+ "{ecx}",
+ "{edx}",
+ "{esi}",
+ "{edi}",
+ "{ebp}",
+ }[i]
+ llvmValue := c.getValue(frame, arg)
+ args = append(args, llvmValue)
+ argTypes = append(argTypes, llvmValue.Type())
+ }
+ fnType := llvm.FunctionType(c.uintptrType, argTypes, false)
+ target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel)
+ syscallResult = c.builder.CreateCall(target, args, "")
case c.GOARCH == "arm" && c.GOOS == "linux":
// Implement the EABI system call convention for Linux.
// Source: syscall(2) man page.