@@ -99,38 +99,36 @@ impl Emulator {
9999 /// It can panic
100100 #[ allow( clippy:: cast_possible_truncation) ]
101101 pub fn run_test ( & mut self ) {
102- //use std::io::{self, Write};
103-
104102 let mut s = String :: new ( ) ;
105103
106104 loop {
105+ let cycle = self . cpu . cycle ;
106+ let insn_addr = self . cpu . pc ;
107+ let insn_word = self . cpu . memop_disass ( insn_addr) ;
108+
109+ // XXX The disassemble API sucks
107110 s. clear ( ) ;
108111 self . cpu . disassemble ( & mut s) ;
109- // XXX might make sense to return the instruction
110112 let exceptional = self . tick ( 1 ) ;
111- let cycle = self . cpu . cycle ;
112- print ! ( "{cycle:5} {:1} {s:72}" , u64 :: from( self . cpu. mmu. prv) ) ;
113113
114- if let Ok ( word32) = self . cpu . memop_disass ( self . cpu . pc ) {
114+ print ! ( "{cycle:5} {:1} {s:72}" , u64 :: from( self . cpu. mmu. prv) ) ;
115+ if let Ok ( word32) = insn_word {
115116 #[ allow( clippy:: cast_sign_loss) ]
116117 let ( insn, _) = cpu:: decompress ( word32 as u32 ) ;
117118 if let Some ( decoded) = cpu:: decode ( & self . cpu . decode_dag , insn) {
118- let uop = ( decoded. decode ) ( self . cpu . pc , insn, decoded. execute ) ;
119- let wbr = uop. rd ;
120- if wbr. is_x0_dest ( ) || exceptional {
119+ let uop = ( decoded. decode ) ( insn_addr, insn, decoded. execute ) ;
120+ if uop. rd . is_x0_dest ( ) || exceptional {
121121 println ! ( ) ;
122122 } else {
123- println ! ( "{:16x}" , self . cpu. read_register( wbr ) ) ;
123+ println ! ( "{:16x}" , self . cpu. read_register( uop . rd ) ) ;
124124 }
125125 } else {
126- println ! ( ) ;
126+ unreachable ! ( "--can't decode {word32:08x}--" ) ;
127127 }
128128 } else {
129- println ! ( ) ;
129+ println ! ( "--can't fetch from {insn_addr:08x}--" ) ;
130130 }
131131
132- //let _ = io::stdout().flush();
133-
134132 if self . handle_htif ( ) {
135133 break ;
136134 }
0 commit comments