Fix emulator arithmetic bugs #6

Open
opened 2025-06-22 21:13:49 +01:00 by zxq5 · 2 comments
Owner

executing certain instructions causes the emulator thread to hard crash, silently breaking the program.

this most often happens with integer overflow, suggesting that there's cases we're not handling properly.

Potential steps for a fix:

  • Debug to find instruction / register combinations that may cause the emulator to crash.
  • Review implementation of arithmetic instructions and ensure that they handle signed operations correctly.
  • Review memory implementation, as an integer overflow error has caused a crash when handling memory read/write operations.

Steps we should take to make debugging future issues of this nature easier:

  • Expanded unit tests, handling edge cases for each instruction type.
  • Custom error handling system for the emulator
    • detailed code review of all cases where .unwrap() .expect() panic!() etc are used within the codebase. we should verify that these methods are only called in places where errors should be impossible.
    • Invalid emulator state should trigger a "critical fault", calling a binary that is loaded whenever the emulator boots/resets.
    • Errors that are not the fault of the emulator's state should be handled robustly, giving the user detailed reasons for why the error has happened.
    • A critical error raised by the emulator should create a crash report that is printed to a logfile containing the state of all registers and the most recent instructions. especially the one that caused the error.
executing certain instructions causes the emulator thread to hard crash, silently breaking the program. this most often happens with integer overflow, suggesting that there's cases we're not handling properly. ### Potential steps for a fix: - [x] Debug to find instruction / register combinations that may cause the emulator to crash. - [ ] Review implementation of arithmetic instructions and ensure that they handle signed operations correctly. - [x] Review memory implementation, as an integer overflow error has caused a crash when handling memory read/write operations. ### Steps we should take to make debugging future issues of this nature easier: - [ ] Expanded unit tests, handling edge cases for each instruction type. - [x] Custom error handling system for the emulator - [ ] detailed code review of all cases where ```.unwrap() .expect() panic!()``` etc are used within the codebase. we should verify that these methods are only called in places where errors should be impossible. - [x] Invalid emulator state should trigger a "critical fault", calling a binary that is loaded whenever the emulator boots/resets. - [ ] Errors that are not the fault of the emulator's state should be handled robustly, giving the user detailed reasons for why the error has happened. - [ ] A critical error raised by the emulator should create a crash report that is printed to a logfile containing the state of all registers and the most recent instructions. especially the one that caused the error.
zxq5 added this to the Damn Simple Architecture project 2025-06-22 21:13:52 +01:00
zxq5 added this to the Emulator Working milestone 2025-06-22 21:13:56 +01:00
zxq5 added the BugTask labels 2025-06-22 21:14:05 +01:00
Author
Owner

(this is just one example, I've had this happen a few times. will look into this issue later.)

image
(this is just one example, I've had this happen a few times. will look into this issue later.) <img width="361" alt="image" src="attachments/b9827d07-6419-4051-abcd-61f274e884ac">
9.6 KiB
Author
Owner

found one of the causes of the issue. a program I was writing read a word that crossed the boundary between two blocks, resulting in an block offset of 255 leading to an overflow.

conclusions:

  • a cause of this type of bug is memory access that crosses over block boundaries.

steps to fix:

  • memory unit should return an error if access is not aligned correctly. (4 bits and 2 bits for word/halfword respectively) we will handle this error with a fault later on once an interrupt convention is agreed.
found one of the causes of the issue. a program I was writing read a word that crossed the boundary between two blocks, resulting in an block offset of 255 leading to an overflow. conclusions: - a cause of this type of bug is memory access that crosses over block boundaries. steps to fix: - [ ] memory unit should return an error if access is not aligned correctly. (4 bits and 2 bits for word/halfword respectively) we will handle this error with a fault later on once an interrupt convention is agreed.
zxq5 self-assigned this 2025-06-23 21:25:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: zxq5/damn_simple_architecture#6