NJU-ProjectN / nemu

NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching
Other
858 stars 184 forks source link

cpu_exec里状态转换存在问题 #87

Closed czlx-github closed 7 months ago

czlx-github commented 8 months ago

复现:在NEMU开启device时,在am-tests目录下运行video测试,然后点击关闭按钮。NEMU会回到等待输入的状态,再次运行c命令后程序会继续运行。

解释: 当NEMU状态为NEMU_QUIT(在device_update()里检测到关闭窗口时会设置为这个状态),但cpu_exec()里刚开始的状态判断没有考虑这个情况:

switch (nemu_state.state) {
    case NEMU_END: case NEMU_ABORT:
      printf("Program execution has ended. To restart the program, exit NEMU and run again.\n");
      return;
    default: nemu_state.state = NEMU_RUNNING;
  }

执行指令返回后的状态判断中,case NEMU_QUIT: statistic();没有退出程序,故再次运行c命令会导致上面的状态判断里设置NEMU的状态为NEMU_RUNNING,从而继续执行指令。

sashimi-yzh commented 8 months ago

你应该是在非批处理模式下引发这个问题的?

czlx-github commented 8 months ago

是的

sashimi-yzh commented 8 months ago

你可以提一个PR, 以记录你的贡献.

czlx-github commented 8 months ago

抱歉,个人觉得PA作为教学系统,由我修改不太合适。还是麻烦老师修复了。

sashimi-yzh commented 8 months ago

没关系的, 之前已经有很多热心的爱好者提了很多PR, 你可以看看已合并PR的列表.

czlx-github commented 8 months ago

好的,之后我提个PR修复这个问题,谢谢老师。