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

added a few features to maybe run WinUAE cputest #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 26 additions & 3 deletions amitools/vamos/lib/ExecLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,30 @@ def DeletePool(self, ctx):
"DeletePooled: invalid memory pool: ptr=%06x" % poolid
)

def SuperState(self, ctx):
# not complete with stack change and all but at least allows
# to run privileged instructions
ctx.cpu.w_sr(ctx.cpu.r_sr() | 0x2000)
#ctx.cpu.w_msp(ctx.cpu.r_usp()-0x400)

def UserState(self, ctx):
# not complete with stack change and all but at least allows
# to return to user state
ctx.cpu.w_sr(ctx.cpu.r_sr() & 0x7FF)
#ctx.cpu.w_msp(ctx.cpu.r_usp()-0x400)

# ----- Memory Handling -----

def AllocAbs(self, ctx):
size = ctx.cpu.r_reg(REG_D0)
location = ctx.cpu.r_reg(REG_A1)
# label alloc
pc = self.get_callee_pc(ctx)
name = "AllocAbs(%06x)" % pc
mb = self.alloc.alloc_abs_memory(location, size, label=name)
log_exec.info("AllocAbs: %s -> 0x%06x %d bytes" % (mb, mb.addr, size))
return mb.addr

def AllocMem(self, ctx):
size = ctx.cpu.r_reg(REG_D0)
flags = ctx.cpu.r_reg(REG_D1)
Expand All @@ -370,9 +392,10 @@ def FreeMem(self, ctx):
log_exec.info("FreeMem: 0x%06x %d bytes -> %s" % (addr, size, mb))
self.alloc.free_memory(mb)
else:
raise VamosInternalError(
"FreeMem: Unknown memory to free: ptr=%06x size=%06x" % (addr, size)
)
pass
#raise VamosInternalError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace with log_exec.info() instead of commenting out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg sorry. It should just be uncommented and left as it was! It was early tests with a AllocAbs I forgot to restore the old code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want me to submit another PR with the fix?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can update this PR by committing to your branch @jotd666, no need to create a new PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have amended my previous commit. Does that work?

# "FreeMem: Unknown memory to free: ptr=%06x size=%06x" % (addr, size)
#)

def AllocVec(self, ctx):
size = ctx.cpu.r_reg(REG_D0)
Expand Down
5 changes: 4 additions & 1 deletion amitools/vamos/lib/dos/Printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def printf_read_data(state, mem_access, data_ptr):
else:
data = mem_access.r16(data_ptr)
data_ptr += 2
data = chr(data)
try:
data = chr(data)
except ValueError:
data = 0x20
elif t == "%":
data = ord("%")
e.data = data
Expand Down
70 changes: 70 additions & 0 deletions amitools/vamos/mem/alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ def get_free_bytes(self):
def is_all_free(self):
return self.size == self.free_bytes

def _find_abs_chunk(self, address, size):
""" scan chunks, see which one we can split
return: index of chunk in free list or -1 if none found + bytes left in chunk
"""
chunk = self.free_first
while chunk != None:
# size matches, now check start address
delta_address = address - chunk.addr
if delta_address >= 0 and chunk.size - delta_address >= size:
# fits, but we can't return this chunk as 1) it doesn't start at the very address
# and 2) it may end way after the required end memory. So we need to split this
# chunk in 3

chunk_before = MemoryChunk(chunk.addr,address-chunk.addr)
self._replace_chunk(chunk,chunk_before)
chunk_after = MemoryChunk(address+size,chunk.size-size-delta_address)
self._insert_chunk(chunk_after)
return (chunk, 0)
chunk = chunk.next
# nothing found?
return (None, -1)

def _find_best_chunk(self, size):
"""find best chunk that could take the given alloc
return: index of chunk in free list or -1 if none found + bytes left in chunk
Expand Down Expand Up @@ -182,6 +204,39 @@ def _stat_info(self):
num_allocs,
)

def alloc_abs(self, addr, size, except_on_fail=True):
"""allocate absolute memory and return addr or 0 if no more memory"""
# align size to 4 bytes
size = (size + 3) & ~3
# align address to 4 bytes, rounded down, that's what we will return
addr &= ~3
chunk, left = self._find_abs_chunk(addr,size)
# out of memory?
if chunk == None:
if except_on_fail:
self.dump_orphans()
log_mem_alloc.error("[alloc: NO MEMORY for %06x bytes at %08x]" % (size,addr))
raise VamosInternalError("[alloc: NO MEMORY for %06x bytes at %08x]" % (size,addr))
return 0

# add to valid allocs map
self.addrs[addr] = size
self.free_bytes -= size
# erase memory
self.mem.clear_block(addr, size, 0)
log_mem_alloc.info(
"[allocabs @%06x-%06x: %06x bytes] %s",
addr,
addr + size,
size,
self._stat_info(),
)
if addr % 4:
raise VamosInternalError(
"Memory pool is invalid, return address not aligned by a long word"
)
return addr

def alloc_mem(self, size, except_on_fail=True):
"""allocate memory and return addr or 0 if no more memory"""
# align size to 4 bytes
Expand Down Expand Up @@ -328,6 +383,21 @@ def alloc_memory(self, size, label=None, except_on_failure=True):
self.mem_objs[addr] = mem
return mem

# memory
def alloc_abs_memory(self, addr, size, label=None, except_on_failure=True):
addr = self.alloc_abs(addr, size, except_on_failure)
if addr == 0:
return None
if label and self.label_mgr:
label_obj = LabelRange(label, addr, size)
self.label_mgr.add_label(label_obj)
else:
label_obj = None
mem = Memory(addr, size, label_obj, self.mem)
log_mem_alloc.info("alloc abs memory: %s", mem)
self.mem_objs[addr] = mem
return mem

def free_memory(self, mem):
log_mem_alloc.info("free memory: %s", mem)
if mem.label != None:
Expand Down