from collections import namedtuple
from copy import deepcopy
from functools import wraps
+import os
+import sys
from nmigen.sim import Settle
-from os import uname
import openpower.syscalls
from openpower.consts import (MSRb, PIb, # big-endian (PowerISA versions)
SVP64CROffs, SVP64MODEb)
class SyscallEmulator(openpower.syscalls.Dispatcher):
def __init__(self, isacaller):
- machine = uname().machine
- host = {
- "x86_64": "amd64",
- }.get(machine, machine)
-
self.__isacaller = isacaller
+ host = os.uname().machine
+ bits = (64 if (sys.maxsize > (2**32)) else 32)
+ host = openpower.syscalls.architecture(arch=host, bits=bits)
+
return super().__init__(guest="ppc64", host=host)
def __call__(self, identifier, *arguments):
-ARCH = {
- "powerpc": "ppc",
- "powerpc64": "ppc64",
- "ppc64le": "ppc64",
- "i686": "i386",
- "x86_64": "amd64",
- "x64": "amd64",
- "arm64": "aarch64",
- "aarch64_be": "aarch64",
- "armv8b": "aarch64",
- "armv8l": "aarch64",
-}
+def architecture(arch, bits=0):
+ assert bits in (0, 32, 64)
+ multilib = {
+ ("aarch64", 32): "arm",
+ ("amd64", 32): "i386",
+ ("ppc64", 32): "ppc",
+ }
+ arch = {
+ "powerpc": "ppc",
+ "powerpc64": "ppc64",
+ "ppc64le": "ppc64",
+ "i686": "i386",
+ "x86_64": "amd64",
+ "x64": "amd64",
+ "arm64": "aarch64",
+ "aarch64_be": "aarch64",
+ "armv8b": "aarch64",
+ "armv8l": "aarch64",
+ }.get(arch, arch)
+
+ return multilib.get((arch, bits), arch)
class Syscall:
if logger is None:
logger = lambda *args, **kwargs: None
- guest = ARCH.get(guest, guest)
- host = ARCH.get(host, host)
-
def i386(sysnums):
yield from sysnums["x86-32"]["i386"].items()
"riscv32": riscv32,
"riscv64": riscv64,
}
+ if guest not in arch:
+ raise ValueError(guest)
+ if host not in arch:
+ raise ValueError(host)
+
sysnums = table["sysnums"]
sysargs = table["sysargs"]
import re
-from . import ARCH
-from . import Dispatcher
-from . import UnknownSyscall
+from openpower.syscalls import architecture
+from openpower.syscalls import Dispatcher
+from openpower.syscalls import UnknownSyscall
def rename_entry(entry):
ecall_parser = main_subparsers.add_parser("ecall")
ecall_parser.add_argument("guest",
help="guest architecture",
- type=lambda arch: ARCH.get(arch, arch))
+ type=architecture)
ecall_parser.add_argument("host",
help="amd64 architecture",
- type=lambda arch: ARCH.get(arch, arch))
+ type=architecture)
ecall_parser.set_defaults(generate=ECallGenerator())
arguments = dict(vars(main_parser.parse_args()))