Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes and enhancements #151

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
504553a
add locale
bebbo Sep 6, 2020
6f9ed08
fix ParsePattern
bebbo Sep 28, 2020
85ca7f8
implement AllocSignal, FreeSignal
bebbo Sep 28, 2020
1d8784f
Merge branch 'umaster'
bebbo Sep 28, 2020
55e3f3a
fix warning -> uint i;
bebbo Sep 28, 2020
6f9566b
cleanup imports
bebbo Sep 28, 2020
39ea831
handle common symbols
bebbo Sep 28, 2020
f4876aa
support more section names
bebbo Sep 28, 2020
f7d4cd8
remove unused imports
bebbo Oct 5, 2020
5ca329a
Merge remote-tracking branch 'upstream/master'
bebbo Feb 16, 2021
1812a61
add some missing modes
bebbo Feb 17, 2021
62a33bd
support reloc 68K_PC32
bebbo Feb 17, 2021
f2c0b15
READ_EA_FPE: add mode 7 reg 1
bebbo Feb 17, 2021
22e5efc
fix mode 7, reg 1: load extended float correctly
bebbo Feb 17, 2021
360f1e6
also dump fp registers for 68040
bebbo Feb 17, 2021
4a3a03e
support all constants
bebbo Feb 18, 2021
908f830
add missing modes
bebbo Feb 18, 2021
2df4c3c
add more modes
bebbo Feb 18, 2021
8dfc6c8
fix hunk loading
bebbo Feb 21, 2021
9f756b4
Merge branch 'locale.library'
bebbo Feb 26, 2021
c29d1ef
fix regster printing for non 68040...
bebbo Feb 26, 2021
f96c09a
Merge remote-tracking branch 'upstream/master'
bebbo Feb 26, 2021
cf7ea1e
default locale is 0 now
bebbo Feb 27, 2021
2a50619
suppress warning if chunk is too small
bebbo Feb 27, 2021
275010e
report proper cycles
bebbo Mar 27, 2021
56e352f
init process's tc_SPUpper and tc_SPLower
bebbo May 30, 2021
096d191
add READ_EA_FPE mode 6
bebbo May 30, 2021
22e38f8
add READ_EA_64 mode 4
bebbo May 30, 2021
d74865b
more reads mode 3/4
bebbo May 30, 2021
a8fc104
attempt to fix comparison with inf
bebbo May 30, 2021
a8d7051
also print fpu status register
bebbo May 31, 2021
e5300e1
Merge remote-tracking branch 'upstream/master'
bebbo May 31, 2021
07792d1
support more fpu insns
bebbo Jul 27, 2021
a22e784
merge enrique/master
bebbo Jul 27, 2021
9e832e6
add fsin/fcos/fsincos
bebbo Sep 23, 2021
43065a0
support rounding to single/double for all insns.
bebbo Sep 29, 2021
9f12c69
fix compilation problems on some systems
bebbo Sep 29, 2021
5cd3984
implement READ_EA_64 mode 0
bebbo Sep 29, 2021
ed1c945
fix rounding handling
bebbo Sep 29, 2021
2f36e83
remove debug output
bebbo Sep 29, 2021
c37870a
implement fmod
bebbo Nov 25, 2021
1eada7a
raise bus error on 68000/10 on odd addresses for w/l
bebbo Jan 13, 2022
87aeed8
fix merge after in deallocate
bebbo Apr 11, 2022
d32b275
use partial reads
bebbo Apr 23, 2023
d6c49fd
merge and patch upstream
bebbo Apr 29, 2023
522ec24
fix cycles for muls and mulu
bebbo Apr 29, 2023
b1eb54f
fix cycles for muls and mulu - only if CPU_TYPE_IS_010_LESS
bebbo Apr 29, 2023
16036ab
more shift cost fixing
bebbo May 1, 2023
a73628b
catch exception in tell for stdin/out
bebbo Dec 11, 2023
2906ceb
make pip install work
bebbo Feb 5, 2024
76ae633
init tc_SPLower and tc_SPUpper
bebbo Mar 24, 2024
8f7200b
fix version check
bebbo Mar 24, 2024
6b6f0a6
implement WaitForChar
bebbo Mar 24, 2024
ef0505c
implement some bsdsocket functions
bebbo Mar 24, 2024
4bae1c8
free hostByName struct - fix memory leak
bebbo Mar 24, 2024
c6ea9ed
fake reading vhposr
bebbo Mar 25, 2024
d107c23
simpler WaitForChar
bebbo Mar 25, 2024
0497727
use time_ns() for vhposr
bebbo Mar 25, 2024
d385a46
added DOSBase->dl_TimeReq->tr_node.io_Device + GetSysTime
bebbo Apr 18, 2024
4b3cfa2
Merge branch 'master' of https://github.com/bebbo/amitools
bebbo Apr 30, 2024
14df1be
don't append arg line to stdin
bebbo Apr 30, 2024
666c1ec
Revert "don't append arg line to stdin"
bebbo May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.egg-info
*.egg
*.pyc
__pycache__/
build/
dist/
Expand Down
271 changes: 271 additions & 0 deletions amitools/vamos/lib/BsdSocketLibrary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
from amitools.vamos.libcore.impl import LibImpl
from amitools.vamos.machine.regs import REG_D0, REG_D1, REG_D2, REG_A0, REG_A1, REG_A2, REG_A3

import select
import socket as s
from amitools.vamos.astructs.astructdef import AmigaStructDef, AmigaClassDef
from amitools.vamos.astructs.astruct import AmigaStruct
from amitools.vamos.astructs.string import CSTR
from amitools.vamos.astructs.pointer import APTR_VOID
from amitools.vamos.astructs.scalar import LONG, UBYTE, UWORD, ULONG

class BsdSocketLibrary(LibImpl):

def setup_lib(self, ctx, base_addr):
self.alloc = ctx.alloc
self.cnt = 0
# track opened sockets
self.socks = {}
# get host by name
self.hostByName = None

def finish_lib(self, ctx):
self.cnt = None

def open_lib(self, ctx, open_cnt):
self.cnt = open_cnt

def close_lib(self, ctx, open_cnt):
if self.hostByName != None:
self.hostByName.free()
self.hostByName = None
self.cnt = open_cnt

def get_version(self):
return 4

def get_cnt(self):
return self.cnt

def putSock(self, sock):
n = 0
while True:
if not n in self.socks:
self.socks[n] = sock
return n
n = n + 1

def socket(self, ctx):
# domain = ctx.cpu.r_reg(REG_D0)
t = ctx.cpu.r_reg(REG_D1)
if t == 1:
t = s.SOCK_STREAM
elif t == 2:
t = s.SOCK_DGRAM
else:
t = s.SOCK_RAW
# protocol = ctx.cpu.r_reg(REG_D2)
sock = s.socket(s.AF_INET, t)
if sock != None:
return self.putSock(sock)
return 0

def CloseSocket(self, ctx):
n = ctx.cpu.r_reg(REG_D0)
if n in self.socks:
sock = self.socks[n]
sock.close()
del self.socks[n]

def gethostbyname(self, ctx):
name_ptr = ctx.cpu.r_reg(REG_A0)
name = ctx.mem.r_cstr(name_ptr)
h = s.gethostbyname(name)
if h != None:
ip = 0
for x in h.split("."):
ip = ip << 8
ip += int(x)
# print(name, h, ip)

if self.hostByName == None:
self.hostByName = HostEntClass.alloc(self.alloc)

self.hostByName.h_name.set(name_ptr)
self.hostByName.h_aliases.set(0)
self.hostByName.h_addrtype.set(0)
self.hostByName.h_length.set(1)
self.hostByName.h_addr_list.set(self.hostByName._addr + 20)
self.hostByName.h_addr.set(self.hostByName._addr + 24)
self.hostByName.h_addr_val.set(ip)
return self.hostByName._addr

return 0

def bind(self, ctx):
sockn = ctx.cpu.r_reg(REG_D0)
if not sockn in self.socks:
return -1

soalen = ctx.cpu.r_reg(REG_D1)
if soalen < 8:
return -2;

soar = ctx.cpu.r_reg(REG_A0)
soa = SockAddrClass(ctx.mem, soar)

# no bind necessary
if soa.sin_port.get() == 0:
return 0

sock = self.socks[sockn]
ip = soa.sin_addr.get()
s = self.ip2s(ip)
if sock.bind((s, soa.sin_port.get())) == None:
return -3

return 0

def connect(self, ctx):
n = ctx.cpu.r_reg(REG_D0)
if not n in self.socks:
return -1

soalen = ctx.cpu.r_reg(REG_D1)
if soalen < 8:
return -2;

soar = ctx.cpu.r_reg(REG_A0)
soa = SockAddrClass(ctx.mem, soar)

# port necessary
if soa.sin_port.get() == 0:
return -3

sock = self.socks[n]
ip = soa.sin_addr.get()
s = self.ip2s(ip)
# print("connect to:", ip, s, soa.sin_port.get())
sock.connect((s, soa.sin_port.get()))
return 0

def ip2s(self, ip):
return str((ip >> 24) & 0xff) + "." + str((ip >> 16) & 0xff) + "." + str((ip >> 8) & 0xff) + "." + str(ip & 0xff)

def send(self, ctx):
n = ctx.cpu.r_reg(REG_D0)
if not n in self.socks:
return -1

buf_ptr = ctx.cpu.r_reg(REG_A0)
size = ctx.cpu.r_reg(REG_D1)
flags = ctx.cpu.r_reg(REG_D2)
data = ctx.mem.r_block(buf_ptr, size)

sock = self.socks[n]
return sock.send(data, flags)

def recv(self, ctx):
n = ctx.cpu.r_reg(REG_D0)
if not n in self.socks:
return -1

buf_ptr = ctx.cpu.r_reg(REG_A0)
size = ctx.cpu.r_reg(REG_D1)
flags = ctx.cpu.r_reg(REG_D2)

sock = self.socks[n]
read = sock.recv(size, flags)
sz = len(read)
ctx.mem.w_block(buf_ptr, read)
return sz

def listFromFdSet(self, mem, addr, sz):
fdset = ULongULongClass(mem, addr)
l = fdset.l0.get() + (fdset.l1.get() << 32)
r = []
for i in range (0, sz):
if l & (1 << i) != 0 and i in self.socks:
r.append(self.socks[i])
return r

def markFdSet(self, mem, lst, addr, sz):
if addr != 0:
s = set(lst)
fdset = ULongULongClass(mem, addr)
l = 0
for i in range (0, sz):
if i in self.socks and self.socks[i] in s:
l = l | (1 << i)
#print("set ULongULong", l)
fdset.l0.set(l)
fdset.l1.set(l >> 32)

def WaitSelect(self, ctx):
sz = ctx.cpu.r_reg(REG_D0)
rfds = ctx.cpu.r_reg(REG_A0)
wfds = ctx.cpu.r_reg(REG_A1)
xfds = ctx.cpu.r_reg(REG_A2)
timevalp = ctx.cpu.r_reg(REG_A3)
signals = ctx.cpu.r_reg(REG_D1)

# clear signals
if signals != 0:
sig = ULongULongStruct(ctx.mem, signals)
sig.l0.set(0)

rlist, wlist, xlist = [], [], []
if rfds != 0:
rlist = self.listFromFdSet(ctx.mem, rfds, sz)
if wfds != 0:
wlist = self.listFromFdSet(ctx.mem, wfds, sz)
if xfds != 0:
xlist = self.listFromFdSet(ctx.mem, xfds, sz)

r, w, x = None, None, None
if timevalp != 0:
timeval = ULongULongClass(ctx.mem, timevalp)
timeout = timeval.l0.get() + timeval.l1.get() * 1e-6
#print("WaitSelect timeout", timeout, rlist, wlist, xlist)
r,w,x = select.select(rlist, wlist, xlist, timeout)
else:
#print("WaitSelect no timeout", rlist, wlist, xlist)
r,w,x = select.select(rlist, wlist, xlist)

self.markFdSet(ctx.mem, r, rfds, sz)
self.markFdSet(ctx.mem, w, wfds, sz)
self.markFdSet(ctx.mem, x, xfds, sz)

@AmigaStructDef
class ULongULongStruct(AmigaStruct):
_format = [
(ULONG, "l0"),
(UBYTE, "l1"),
]

@AmigaClassDef
class ULongULongClass(ULongULongStruct):
pass

@AmigaStructDef
class SockAddrStruct(AmigaStruct):
_format = [
(UBYTE, "sin_len"),
(UBYTE, "sin_family"),
(UWORD, "sin_port"),
(ULONG, "sin_addr"),
(ULONG, "sin_zero0"),
(ULONG, "sin_zero1"),
]

@AmigaClassDef
class SockAddrClass(SockAddrStruct):
pass

@AmigaStructDef
class HostEntStruct(AmigaStruct):
_format = [
(CSTR, "h_name"),
(APTR_VOID, "h_aliases"),
(LONG, "h_addrtype"),
(LONG, "h_length"),
(APTR_VOID, "h_addr_list"),
# internal
(LONG, "h_addr"),
(LONG, "h_addr_val"),
]

@AmigaClassDef
class HostEntClass(HostEntStruct):
pass

22 changes: 22 additions & 0 deletions amitools/vamos/lib/DosLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ctypes
import re
import os
import select

from amitools.vamos.machine.regs import *
from amitools.vamos.libcore import LibImpl
Expand Down Expand Up @@ -43,6 +44,7 @@
from .dos.CSource import *
from .dos.Item import *
from amitools.vamos.dos import run_command, run_sub_process
from amitools.vamos.libstructs.dos import TimeRequestStruct


class DosLibrary(LibImpl):
Expand Down Expand Up @@ -95,8 +97,18 @@ def setup_lib(self, ctx, base_addr):
self.file_mgr = FileManager(
ctx.path_mgr, ctx.exec_lib.port_mgr, ctx.alloc, ctx.mem
)

self.timerDevice = ctx.exec_lib.lib_mgr.open_lib("timer.device", 0)
self.timeRequest = ctx.alloc.alloc_struct(TimeRequestStruct, label="TimeRequest")
self.timeRequest.access.w_s("tr_node.io_Device", self.timerDevice)
self.access.w_s("dl_TimeReq", self.timeRequest.addr)

def finish_lib(self, ctx):

# close TimerDevice, free timeRequest
ctx.exec_lib.lib_mgr.close_lib(self.timerDevice)
ctx.alloc.free_struct(self.timeRequest)

# finish file manager
self.file_mgr.finish()
# free dos list
Expand Down Expand Up @@ -594,6 +606,16 @@ def Close(self, ctx):
self.setioerr(ctx, 0)
return self.DOSTRUE

def WaitForChar(self, ctx):
# file,timeout)(d1/d2)
fh_b_addr = ctx.cpu.r_reg(REG_D1)
fh = self.file_mgr.get_by_b_addr(fh_b_addr, False)
ms = ctx.cpu.r_reg(REG_D2)
if select.select([fh.obj], [], [], ms * 1e-3)[0]:
return self.DOSTRUE

return self.DOSFALSE

def Read(self, ctx):
fh_b_addr = ctx.cpu.r_reg(REG_D1)
buf_ptr = ctx.cpu.r_reg(REG_D2)
Expand Down
2 changes: 2 additions & 0 deletions amitools/vamos/lib/LibList.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .UtilityLibrary import UtilityLibrary
from .VamosTestLibrary import VamosTestLibrary
from .VamosTestDevice import VamosTestDevice
from .BsdSocketLibrary import BsdSocketLibrary

vamos_libs = {
"dos.library": DosLibrary,
Expand All @@ -26,6 +27,7 @@
"mathtrans.library": MathTransLibrary,
"timer.device": TimerDevice,
"utility.library": UtilityLibrary,
"bsdsocket.library": BsdSocketLibrary,
"vamostest.library": VamosTestLibrary,
"vamostestdev.device": VamosTestDevice,
}
12 changes: 7 additions & 5 deletions amitools/vamos/lib/TimerDevice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from amitools.vamos.libcore import LibImpl
from amitools.vamos.machine.regs import REG_A0
from amitools.vamos.astructs import AccessStruct
from amitools.vamos.libstructs import DateStampStruct
from amitools.vamos.libstructs.dos import TimeValStruct

from datetime import datetime

Expand All @@ -12,9 +12,11 @@ def ReadEClock(self, ctx):

dt = datetime.now()

# abuse DateStampStruct
tv = AccessStruct(ctx.mem, DateStampStruct, struct_addr=eclockval)
tv.ds_Days = dt.microsecond / 1000000
tv.ds_Minute = dt.microsecond % 1000000
tv = AccessStruct(ctx.mem, TimeValStruct, struct_addr=eclockval)
tv.tv_secs = dt.microsecond / 1000000
tv.tv_micros = dt.microsecond % 1000000

return 50

def GetSysTime(self, ctx):
self.ReadEClock(ctx)
7 changes: 5 additions & 2 deletions amitools/vamos/lib/dos/FileHandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def write(self, data):

def read(self, len):
try:
d = self.obj.read(len)
d = self.obj.read1(len)
return d
except IOError:
return -1
Expand Down Expand Up @@ -135,7 +135,10 @@ def getbuf(self):
return self.unch

def tell(self):
return self.obj.tell()
try:
return self.obj.tell()
except IOError:
return -1

def seek(self, pos, whence):
try:
Expand Down
Loading