1 // See LICENSE for license details.
12 void sim_t::interactive()
16 std::cin
.getline(s
,sizeof(s
)-1);
18 char* p
= strtok(s
," ");
21 interactive_run_noisy(std::string("r"), std::vector
<std::string
>(1,"1"));
26 std::vector
<std::string
> args
;
27 while((p
= strtok(NULL
," ")))
31 typedef void (sim_t::*interactive_func
)(const std::string
&, const std::vector
<std::string
>&);
32 std::map
<std::string
,interactive_func
> funcs
;
34 funcs
["r"] = &sim_t::interactive_run_noisy
;
35 funcs
["rs"] = &sim_t::interactive_run_silent
;
36 funcs
["rp"] = &sim_t::interactive_run_proc_noisy
;
37 funcs
["rps"] = &sim_t::interactive_run_proc_silent
;
38 funcs
["reg"] = &sim_t::interactive_reg
;
39 funcs
["fregs"] = &sim_t::interactive_fregs
;
40 funcs
["fregd"] = &sim_t::interactive_fregd
;
41 funcs
["mem"] = &sim_t::interactive_mem
;
42 funcs
["str"] = &sim_t::interactive_str
;
43 funcs
["until"] = &sim_t::interactive_until
;
44 funcs
["while"] = &sim_t::interactive_until
;
45 funcs
["q"] = &sim_t::interactive_quit
;
50 (this->*funcs
[cmd
])(cmd
, args
);
55 void sim_t::interactive_run_noisy(const std::string
& cmd
, const std::vector
<std::string
>& args
)
57 interactive_run(cmd
,args
,true);
60 void sim_t::interactive_run_silent(const std::string
& cmd
, const std::vector
<std::string
>& args
)
62 interactive_run(cmd
,args
,false);
65 void sim_t::interactive_run(const std::string
& cmd
, const std::vector
<std::string
>& args
, bool noisy
)
68 step_all(atoll(args
[0].c_str()), 1, noisy
);
70 while (1) step_all(1, 1, noisy
);
73 void sim_t::interactive_run_proc_noisy(const std::string
& cmd
, const std::vector
<std::string
>& args
)
75 interactive_run_proc(cmd
,args
,true);
78 void sim_t::interactive_run_proc_silent(const std::string
& cmd
, const std::vector
<std::string
>& args
)
80 interactive_run_proc(cmd
,args
,false);
83 void sim_t::interactive_run_proc(const std::string
& cmd
, const std::vector
<std::string
>& a
, bool noisy
)
88 int p
= atoi(a
[0].c_str());
89 if(p
>= (int)num_cores())
93 procs
[p
]->step(atoi(a
[1].c_str()),noisy
);
95 while (1) procs
[p
]->step(1, noisy
);
98 void sim_t::interactive_quit(const std::string
& cmd
, const std::vector
<std::string
>& args
)
103 reg_t
sim_t::get_pc(const std::vector
<std::string
>& args
)
106 throw trap_illegal_instruction
;
108 int p
= atoi(args
[0].c_str());
109 if(p
>= (int)num_cores())
110 throw trap_illegal_instruction
;
115 reg_t
sim_t::get_reg(const std::vector
<std::string
>& args
)
118 throw trap_illegal_instruction
;
120 int p
= atoi(args
[0].c_str());
121 int r
= atoi(args
[1].c_str());
122 if(p
>= (int)num_cores() || r
>= NXPR
)
123 throw trap_illegal_instruction
;
125 return procs
[p
]->XPR
[r
];
128 reg_t
sim_t::get_freg(const std::vector
<std::string
>& args
)
131 throw trap_illegal_instruction
;
133 int p
= atoi(args
[0].c_str());
134 int r
= atoi(args
[1].c_str());
135 if(p
>= (int)num_cores() || r
>= NFPR
)
136 throw trap_illegal_instruction
;
138 return procs
[p
]->FPR
[r
];
141 void sim_t::interactive_reg(const std::string
& cmd
, const std::vector
<std::string
>& args
)
143 printf("0x%016llx\n",(unsigned long long)get_reg(args
));
153 void sim_t::interactive_fregs(const std::string
& cmd
, const std::vector
<std::string
>& args
)
156 f
.r
= get_freg(args
);
160 void sim_t::interactive_fregd(const std::string
& cmd
, const std::vector
<std::string
>& args
)
163 f
.r
= get_freg(args
);
167 reg_t
sim_t::get_mem(const std::vector
<std::string
>& args
)
169 if(args
.size() != 1 && args
.size() != 2)
170 throw trap_illegal_instruction
;
172 std::string addr_str
= args
[0];
175 int p
= atoi(args
[0].c_str());
176 if(p
>= (int)num_cores())
177 throw trap_illegal_instruction
;
178 mmu
->set_sr(procs
[p
]->sr
);
179 mmu
->set_ptbr(procs
[p
]->mmu
.get_ptbr());
183 reg_t addr
= strtol(addr_str
.c_str(),NULL
,16), val
;
185 addr
= strtoul(addr_str
.c_str(),NULL
,16);
190 val
= mmu
->load_uint64(addr
);
193 val
= mmu
->load_uint32(addr
);
197 val
= mmu
->load_uint16(addr
);
200 val
= mmu
->load_uint8(addr
);
206 void sim_t::interactive_mem(const std::string
& cmd
, const std::vector
<std::string
>& args
)
208 printf("0x%016llx\n",(unsigned long long)get_mem(args
));
211 void sim_t::interactive_str(const std::string
& cmd
, const std::vector
<std::string
>& args
)
214 throw trap_illegal_instruction
;
216 reg_t addr
= strtol(args
[0].c_str(),NULL
,16);
219 while((ch
= mmu
->load_uint8(addr
++)))
225 void sim_t::interactive_until(const std::string
& cmd
, const std::vector
<std::string
>& args
)
230 std::string scmd
= args
[0];
231 reg_t val
= strtol(args
[args
.size()-1].c_str(),NULL
,16);
233 val
= strtoul(args
[args
.size()-1].c_str(),NULL
,16);
235 std::vector
<std::string
> args2
;
236 args2
= std::vector
<std::string
>(args
.begin()+1,args
.end()-1);
242 current
= get_reg(args2
);
243 else if(scmd
== "pc")
244 current
= get_pc(args2
);
245 else if(scmd
== "mem")
246 current
= get_mem(args2
);
250 if(cmd
== "until" && current
== val
)
252 if(cmd
== "while" && current
!= val
)