syscall test

This commit is contained in:
Peter McGoron 2023-02-12 20:37:45 +00:00
parent 4f14e48ba5
commit 304e5d63c5
2 changed files with 28 additions and 2 deletions

View File

@ -89,7 +89,7 @@ class Environment:
return creole.from_2c(self.cenv.reg[reg])
else:
return self.cenv.reg[reg]
def getstk(self, stk):
def getstk(self, stk, signed=False):
""" Get the value at the stack position.
:param reg: Register number.
@ -98,7 +98,16 @@ class Environment:
"""
if stk >= self.cenv.stklen or stk < 0:
raise StackOverflowError(r)
if signed:
return creole.from_2c(self.cenv.stk[stk])
else:
return self.cenv.stk[stk]
def pop(self):
if stk == 0:
return None
stk = stk - 1
return self.cenv.stk[stk]
def __init__(self, prog=None, reglen=32, lablen=32, stklen=4096, prglen=4096):
cenv = CEnv()

View File

@ -434,5 +434,22 @@ class ProgramTest(unittest.TestCase):
self.range_test(0x7FFFF00, 0x8000000, sgn=True)
self.range_test(-100, 0, sgn=True)
class SCEnv(ffi.Environment):
def syscall(self, s):
self.s = s.value
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class ProgramTest(unittest.TestCase):
def range_test(self, st, en, sgn=False):
for i in range(st, en):
p = Program()
p.parse_asm_line(f"sys {i}")
ex = SCEnv(p())
self.assertEqual(ex(), ffi.RunRet.STOP)
self.assertEqual(ex.s, i)
def test_syscall_imm(self):
self.range_test(0, 1000)
if __name__ == "__main__":
unittest.main()