10 void sim_t::interactive()
14 std::cin
.getline(s
,sizeof(s
)-1);
16 char* p
= strtok(s
," ");
19 interactive_run_noisy(std::string("r"), std::vector
<std::string
>(1,"1"));
24 std::vector
<std::string
> args
;
25 while((p
= strtok(NULL
," ")))
29 typedef void (sim_t::*interactive_func
)(const std::string
&, const std::vector
<std::string
>&);
30 std::map
<std::string
,interactive_func
> funcs
;
32 funcs
["r"] = &sim_t::interactive_run_noisy
;
33 funcs
["rs"] = &sim_t::interactive_run_silent
;
34 funcs
["rp"] = &sim_t::interactive_run_proc_noisy
;
35 funcs
["rps"] = &sim_t::interactive_run_proc_silent
;
36 funcs
["reg"] = &sim_t::interactive_reg
;
37 funcs
["fregs"] = &sim_t::interactive_fregs
;
38 funcs
["fregd"] = &sim_t::interactive_fregd
;
39 funcs
["mem"] = &sim_t::interactive_mem
;
40 funcs
["str"] = &sim_t::interactive_str
;
41 funcs
["until"] = &sim_t::interactive_until
;
42 funcs
["while"] = &sim_t::interactive_until
;
43 funcs
["q"] = &sim_t::interactive_quit
;
48 (this->*funcs
[cmd
])(cmd
, args
);
53 void sim_t::interactive_run_noisy(const std::string
& cmd
, const std::vector
<std::string
>& args
)
55 interactive_run(cmd
,args
,true);
58 void sim_t::interactive_run_silent(const std::string
& cmd
, const std::vector
<std::string
>& args
)
60 interactive_run(cmd
,args
,false);
63 void sim_t::interactive_run(const std::string
& cmd
, const std::vector
<std::string
>& args
, bool noisy
)
66 step_all(atoll(args
[0].c_str()), 1, noisy
);
68 while (1) step_all(1, 1, noisy
);
71 void sim_t::interactive_run_proc_noisy(const std::string
& cmd
, const std::vector
<std::string
>& args
)
73 interactive_run_proc(cmd
,args
,true);
76 void sim_t::interactive_run_proc_silent(const std::string
& cmd
, const std::vector
<std::string
>& args
)
78 interactive_run_proc(cmd
,args
,false);
81 void sim_t::interactive_run_proc(const std::string
& cmd
, const std::vector
<std::string
>& a
, bool noisy
)
86 int p
= atoi(a
[0].c_str());
87 if(p
>= (int)num_cores())
91 procs
[p
]->step(atoi(a
[1].c_str()),noisy
);
93 while (1) procs
[p
]->step(1, noisy
);
96 void sim_t::interactive_quit(const std::string
& cmd
, const std::vector
<std::string
>& args
)
101 reg_t
sim_t::get_pc(const std::vector
<std::string
>& args
)
104 throw trap_illegal_instruction
;
106 int p
= atoi(args
[0].c_str());
107 if(p
>= (int)num_cores())
108 throw trap_illegal_instruction
;
113 reg_t
sim_t::get_reg(const std::vector
<std::string
>& args
)
116 throw trap_illegal_instruction
;
118 int p
= atoi(args
[0].c_str());
119 int r
= atoi(args
[1].c_str());
120 if(p
>= (int)num_cores() || r
>= NXPR
)
121 throw trap_illegal_instruction
;
123 return procs
[p
]->XPR
[r
];
126 reg_t
sim_t::get_freg(const std::vector
<std::string
>& args
)
129 throw trap_illegal_instruction
;
131 int p
= atoi(args
[0].c_str());
132 int r
= atoi(args
[1].c_str());
133 if(p
>= (int)num_cores() || r
>= NFPR
)
134 throw trap_illegal_instruction
;
136 return procs
[p
]->FPR
[r
];
139 void sim_t::interactive_reg(const std::string
& cmd
, const std::vector
<std::string
>& args
)
141 printf("0x%016llx\n",(unsigned long long)get_reg(args
));
151 void sim_t::interactive_fregs(const std::string
& cmd
, const std::vector
<std::string
>& args
)
154 f
.r
= get_freg(args
);
158 void sim_t::interactive_fregd(const std::string
& cmd
, const std::vector
<std::string
>& args
)
161 f
.r
= get_freg(args
);
165 reg_t
sim_t::get_mem(const std::vector
<std::string
>& args
)
167 if(args
.size() != 1 && args
.size() != 2)
168 throw trap_illegal_instruction
;
170 std::string addr_str
= args
[0];
173 int p
= atoi(args
[0].c_str());
174 if(p
>= (int)num_cores())
175 throw trap_illegal_instruction
;
176 mmu
->set_vm_enabled(!!(procs
[p
]->sr
& SR_VM
));
177 mmu
->set_ptbr(procs
[p
]->mmu
.get_ptbr());
181 reg_t addr
= strtol(addr_str
.c_str(),NULL
,16), val
;
183 addr
= strtoul(addr_str
.c_str(),NULL
,16);
188 val
= mmu
->load_uint64(addr
);
191 val
= mmu
->load_uint32(addr
);
195 val
= mmu
->load_uint16(addr
);
198 val
= mmu
->load_uint8(addr
);
204 void sim_t::interactive_mem(const std::string
& cmd
, const std::vector
<std::string
>& args
)
206 printf("0x%016llx\n",(unsigned long long)get_mem(args
));
209 void sim_t::interactive_str(const std::string
& cmd
, const std::vector
<std::string
>& args
)
212 throw trap_illegal_instruction
;
214 reg_t addr
= strtol(args
[0].c_str(),NULL
,16);
217 while((ch
= mmu
->load_uint8(addr
++)))
223 void sim_t::interactive_until(const std::string
& cmd
, const std::vector
<std::string
>& args
)
228 std::string scmd
= args
[0];
229 reg_t val
= strtol(args
[args
.size()-1].c_str(),NULL
,16);
231 val
= strtoul(args
[args
.size()-1].c_str(),NULL
,16);
233 std::vector
<std::string
> args2
;
234 args2
= std::vector
<std::string
>(args
.begin()+1,args
.end()-1);
240 current
= get_reg(args2
);
241 else if(scmd
== "pc")
242 current
= get_pc(args2
);
243 else if(scmd
== "mem")
244 current
= get_mem(args2
);
248 if(cmd
== "until" && current
== val
)
250 if(cmd
== "while" && current
!= val
)