forked from cnvogelg/amitools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vamos
executable file
·189 lines (163 loc) · 7.01 KB
/
vamos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python2.7
#
# vamos [optoins] <amiga binary> [args ...]
#
# run an m68k AmigaOS binary
#
# written by Christian Vogelgsang ([email protected])
import sys
import argparse
import os
from musashi import m68k
from amitools.vamos.CPU import CPU
from amitools.vamos.MEM import MEM
from amitools.vamos.Log import *
from amitools.vamos.Vamos import Vamos
from amitools.vamos.Exceptions import *
from amitools.vamos.AccessMemory import AccessMemory
from amitools.vamos.VamosConfig import VamosConfig
from amitools.vamos.PathManager import PathManager
from amitools.vamos.VamosRun import VamosRun
from amitools.vamos.Process import Process
# ----- classes -----
class MusashiCPU(CPU):
def __init__(self):
CPU.__init__(self,"musashi")
def w_reg(self,reg, val):
m68k.set_reg(reg,val)
def r_reg(self,reg):
return m68k.get_reg(reg)
def w_pc(self, val):
m68k.set_reg(m68k.M68K_REG_PC,val)
def r_pc(self):
return m68k.get_reg(m68k.M68K_REG_PC)
def w_sr(self, val):
m68k.set_reg(m68k.M68K_REG_SR,val)
def r_sr(sefl):
return m68k.get_reg(m68k.M68K_REG_SR)
def pulse_reset(self):
m68k.pulse_reset()
def execute(self, num_cycles):
return m68k.execute(num_cycles)
def end(self):
m68k.end_timeslice()
class MusashiMEM(MEM):
def __init__(self):
MEM.__init__(self,"musashi")
def init(self,ram_size_kib):
self.ram_size = ram_size_kib * 1024
return m68k.mem_init(ram_size_kib)
def free(self):
m68k.mem_free()
def reserve_special_range(self,num_pages):
return m68k.mem_reserve_special_range(num_pages)
def set_special_range_read_func(self,page_addr, width, func):
m68k.mem_set_special_range_read_func(page_addr, width, func)
def set_special_range_write_func(self,page_addr, width, func):
m68k.mem_set_special_range_write_func(page_addr, width, func)
def set_mem_trace_mode(self,on):
m68k.mem_set_trace_mode(on)
def set_mem_trace_func(self,func):
m68k.mem_set_trace_func(func)
def read_ram(self,width, addr):
return m68k.mem_ram_read(width, addr)
def write_ram(self,width, addr, val):
m68k.mem_ram_write(width,addr,val)
def read_ram_block(self,addr,size,data):
m68k.mem_ram_read_block(addr,size,data)
def write_ram_block(self,addr,size,data):
m68k.mem_ram_write_block(addr,size,data)
def clear_ram_block(self,addr,size,value):
m68k.mem_ram_clear_block(addr,size,value)
# ----- main -----------------------------------------------------------------
# retrieve vamos home and data dir
home_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
data_dir = os.path.join(home_dir, "data")
# --- args --
parser = argparse.ArgumentParser()
parser.add_argument('bin', help="AmigaOS binary to run")
parser.add_argument('args', nargs='*', help="AmigaOS binary arguments")
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
parser.add_argument('-q', '--quiet', action='store_true', default=False, help="do not output any logging")
parser.add_argument('-C', '--max-cycles', action='store', type=int, default=0, help="maximum number of cycles to execute")
parser.add_argument('-B', '--cycles-per-block', action='store', type=int, default=1000, help="cycles per block")
parser.add_argument('-l', '--logging', action='store', default=None, help="logging settings: <chan>:<level>,*:<level>,...")
parser.add_argument('-L', '--log-file', action='store', default=None, help="write all log messages to a file")
parser.add_argument('-i', '--lib-versions', action='store', default=None, help="set lib version: <lib>:<version>,...")
parser.add_argument('-P', '--lib-profile', action='store', default=None, help="enable lib profiling: <lib>,<lib>,...")
parser.add_argument('-m', '--ram-size', action='store', default=1024, type=int, help="set RAM size in KiB")
parser.add_argument('-s', '--stack-size', action='store', default=4, help="set stack size in KiB")
parser.add_argument('-t', '--memory-trace', action='store_true', default=False, help="enable memory tracing (slower)")
parser.add_argument('-T', '--internal-memory-trace', action='store_true', default=False, help="enable internal memory tracing (slow)")
parser.add_argument('-I', '--instr-trace', action='store_true', default=False, help="enable instruction trace")
parser.add_argument('-c', '--config-file', action='store', default=None, help="vamos config file")
parser.add_argument('-a', '--assign', action='append', default=None, help="add AmigaOS assign: name:[+]/sys/path[,/more/path]")
parser.add_argument('-V', '--volume', action='append', default=None, help="define AmigaOS volume: name:/abs/sys/path")
parser.add_argument('-A', '--auto-assign', action='store', default=None, help="define auto assign ami path, e.g. vol:/ami/path")
parser.add_argument('-p', '--path', action='append', default=None, help="define command search ami path, e.g. c:")
parser.add_argument('-D', '--data-dir', action='store', default=data_dir, help="set vamos data directory (default: %s)" % data_dir)
args = parser.parse_args()
# --- init config ---
cfg = VamosConfig(extra_file=args.config_file, args=args)
# --- init logging ---
if not log_setup(cfg.logging, cfg.verbose, cfg.quiet, cfg.log_file):
log_help()
sys.exit(1)
cfg.log()
# ----- vamos! ---------------------------------------------------------------
cpu = MusashiCPU()
mem = MusashiMEM()
log_main.info("setting up main memory with %s KiB RAM: top=%06x" % (cfg.ram_size, cfg.ram_size * 1024))
if not mem.init(cfg.ram_size):
log_main.error("can't allocate vamos RAM: %d KiB" % cfg.ram_size)
sys.exit(1)
vamos = Vamos(mem, cpu, cfg)
# enable mem trace?
if cfg.memory_trace:
mem.set_mem_trace_mode(1)
mem.set_mem_trace_func(vamos.label_mgr.trace_mem)
if not log_mem.isEnabledFor(logging.INFO):
log_mem.setLevel(logging.INFO)
# enable internal memory trace?
if cfg.internal_memory_trace:
AccessMemory.label_mgr = vamos.label_mgr
if not log_mem_int.isEnabledFor(logging.INFO):
log_mem_int.setLevel(logging.INFO)
# set invalid access handler for memory
m68k.mem_set_invalid_func(vamos.error_tracker.report_invalid_memory)
# --- setup vamos ---
if not vamos.init(cfg):
sys.exit(1)
# --- create main process ---
proc = Process(vamos, args.bin, args.args, stack_size=cfg.stack_size*1024)
if not proc.ok:
sys.exit(1)
vamos.set_main_process(proc)
# ------ main loop ------
# set CPU type
m68k.set_cpu_type(m68k.M68K_CPU_TYPE_68000)
# init cpu and initial registers
run = VamosRun(vamos)
run.init_cpu()
# set reset opcode/trap handler
m68k.set_reset_instr_callback(run.reset_func)
# enable instruction trace?
def instr_hook():
pc = m68k.get_reg(m68k.M68K_REG_PC)
label = vamos.label_mgr.get_mem_str(pc)
txt = m68k.disassemble(pc, m68k.M68K_CPU_TYPE_68000)
log_instr.info("%-40s %06x %s" % (label, pc, txt))
if cfg.instr_trace:
if not log_instr.isEnabledFor(logging.INFO):
log_instr.setLevel(logging.INFO)
m68k.set_instr_hook_callback(instr_hook)
# main loop
exit_code = run.run(cfg.cycles_per_block, cfg.max_cycles)
# free process
proc.free()
# shutdown vamos
vamos.cleanup()
# clean up native memory module
mem.free()
# exit
sys.exit(exit_code)