forked from M-Labs/artiq
1
0
Fork 0

devices/runtime: use regular function call instead of syscall

This commit is contained in:
Sebastien Bourdeauducq 2014-07-05 19:39:05 +02:00
parent 99c99484ae
commit de238503d2
1 changed files with 11 additions and 17 deletions

View File

@ -1,22 +1,16 @@
from llvm import core as lc from llvm import core as lc
syscall_map = { _syscalls = [
"rpc": 0, ("printint", lc.Type.void(), [lc.Type.int()])
"rtio_set": 1, ]
"rtio_sync": 2,
"dds_program": 3,
}
class Environment: class Environment:
def __init__(self, module):
for func_name, func_type_ret, func_type_args in _syscalls:
function_type = lc.Type.function(func_type_ret, func_type_args)
module.add_function(function_type, "__syscall_"+func_name)
self.module = module
def emit_syscall(self, builder, syscall_name, args): def emit_syscall(self, builder, syscall_name, args):
syscall_nr = syscall_map[syscall_name] builder.call(self.module.get_function_named("__syscall_"+syscall_name), args)
assert(0 <= syscall_nr <= 0xffff)
# FIXME: replace with "l.sys syscall_nr" after the LLVM problems are fixed
opcode = 0x20000000 | syscall_nr
asm_string = "\n".join(".byte 0x{:02x}".format((opcode >> 8*i) & 0xff)
for i in reversed(range(4)))
sc_type = lc.Type.function(lc.Type.void(), [])
asm = lc.InlineAsm.get(sc_type, asm_string, "")
builder.call(asm, [])