@@ -32,16 +32,6 @@ library UArchStep {
3232 UArchHalted // microarchitecture reached or was already at its halted fixed point
3333 }
3434
35- function uarch_halt_to_step_status (uint64 halt )
36- private
37- pure
38- returns (UArchStepStatus)
39- {
40- return halt == EmulatorConstants.UARCH_HALT_CYCLE_OVERFLOW
41- ? UArchStepStatus.UArchCycleOverflow
42- : UArchStepStatus.UArchHalted;
43- }
44-
4535 // Memory read/write access
4636
4737 function readUint64 (AccessLogs.Context memory a , uint64 paddr )
@@ -1082,8 +1072,7 @@ library UArchStep {
10821072 // return value is in a0 (and maybe also in a1)
10831073 uint64 fn = EmulatorCompat.readX (a, 17 ); // a7 contains the function number
10841074 if (fn == EmulatorConstants.UARCH_ECALL_FN_HALT) {
1085- return
1086- EmulatorCompat.writeHalt (a, EmulatorConstants.UARCH_HALT_HALTED);
1075+ return EmulatorCompat.writeHalt (a, 1 );
10871076 }
10881077 if (fn == EmulatorConstants.UARCH_ECALL_FN_PUTCHAR) {
10891078 uint64 c = EmulatorCompat.readX (a, 10 ); // a0 contains the character to print
@@ -1328,38 +1317,29 @@ library UArchStep {
13281317 pure
13291318 returns (UArchStepStatus)
13301319 {
1331- // Report existing halt fixed point
1332- uint64 halt = EmulatorCompat.readHalt (a);
1333- if (halt != 0 ) {
1334- return uarch_halt_to_step_status (halt);
1335- }
1336- // Report existing overflow fixed point if the cycle is at or beyond its limit
1320+ // Report the derived overflow fixed point before all other break reasons.
13371321 uint64 cycle = EmulatorCompat.readCycle (a);
13381322 if (cycle >= EmulatorConstants.UARCH_CYCLE_MAX) {
1339- EmulatorCompat.writeHalt (
1340- a, EmulatorConstants.UARCH_HALT_CYCLE_OVERFLOW
1341- );
13421323 return UArchStepStatus.UArchCycleOverflow;
13431324 }
1325+ // Report an existing ordinary halt fixed point.
1326+ if (EmulatorCompat.readHalt (a) != 0 ) {
1327+ return UArchStepStatus.UArchHalted;
1328+ }
13441329 // Execute next instruction
13451330 uint64 pc = EmulatorCompat.readPc (a);
13461331 uint32 insn = readUint32 (a, pc);
13471332 executeInsn (a, insn, pc);
13481333 cycle = cycle + 1 ;
13491334 EmulatorCompat.writeCycle (a, cycle);
1350- // Materialize overflow immediately when this step reaches the cycle limit
1335+ // Overflow has precedence when this step reaches the cycle limit.
13511336 if (cycle >= EmulatorConstants.UARCH_CYCLE_MAX) {
1352- EmulatorCompat.writeHalt (
1353- a, EmulatorConstants.UARCH_HALT_CYCLE_OVERFLOW
1354- );
13551337 return UArchStepStatus.UArchCycleOverflow;
13561338 }
1357- // ECALL is the only instruction that can halt the uarch. Overflow was handled above,
1358- // so a non-zero halt value here can only report a normal halt.
1339+ // ECALL is the only instruction that can halt the uarch.
13591340 if (insn == uint32 (0x73 )) {
1360- halt = EmulatorCompat.readHalt (a);
1361- if (halt != 0 ) {
1362- return uarch_halt_to_step_status (halt);
1341+ if (EmulatorCompat.readHalt (a) != 0 ) {
1342+ return UArchStepStatus.UArchHalted;
13631343 }
13641344 }
13651345 return UArchStepStatus.Success;
0 commit comments