Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RARS freezes when printing and reading simultaneously (Keyboard and Display MMIO Simulator) #82

Closed
quinnlp opened this issue Jul 10, 2020 · 8 comments · May be fixed by #209
Closed

RARS freezes when printing and reading simultaneously (Keyboard and Display MMIO Simulator) #82

quinnlp opened this issue Jul 10, 2020 · 8 comments · May be fixed by #209

Comments

@quinnlp
Copy link

quinnlp commented Jul 10, 2020

Hello!

If a character is typed in the keyboard section of the Keyboard and Display MMIO Simulator while a character is printed to the display, RARS becomes unresponsive.

Below is a program that can demonstrate the issue. It loops moving the cursor to row zero, column zero, then printing '0' indefinitely.

To reproduce the issue, follow these steps:

  1. Open the "Keyboard and Display MMIO Simulator" from the "Tools" menu
  2. Assemble the program
  3. Connect the Keyboard and Display Simulator to the program
  4. Run the program
  5. Begin entering characters into the KEYBOARD section

RARS will freeze after one or two keypresses.

.text
main:
#	load MMIO register addresses
li	s0, 0xFFFF0008		# s0 <- Adr[DISPLAY_CONTROL]
li	s1, 0xFFFF000C		# s1 <- Adr[DISPLAY_DATA]
	
#	load characters that will be stored in DISPLAY_DATA
li	s2, 0x30		# s2 <- 0x00000030
li	s3, 0x7			# s3 <- 0x00000007 
	
forever:	
		#	wait for display to be ready to move cursor
		lw	t0, 0(s0)		# t0 <- DISPLAY_CONTROL
		andi	t0, t0, 0x1		# t0 <- 0th bit of DISPLAY_CONTROL
		beqz	t0, forever		# if (t0 == 0) goto forever
	
	#	move cursor to row=0 and col=0
	sw	s3, 0(s1)		# DISPLAY_DATA <- 0x00000007
	
waitForDisplay2:	
		#	wait for display to be ready to print '0'
		lw	t0, 0(s0)		# t0 <- DISPLAY_CONTROL
		andi	t0, t0, 0x1		# t0 <- 0th bit of DISPLAY_CONTROL
		beqz	t0, waitForDisplay2	# if (t0 == 0) goto waitForDisplay2
	
	#	print '0'
	sb	s2, 0(s1)		# DISPLAY_DATA <- 0x00000030
	
	j	forever			# goto forever
@TheThirdOne
Copy link
Owner

I have investigated and found that this is due to the tool locking the register and memory lock while also using the synchronized method. This allows the main simulator to hold the lock, the awt thread starts handling an keypress and enters the method and waits on the lock, the main simulator then tries to update via the method and gets stuck on the synchronized method.

private synchronized void updateMMIOControlAndData(int controlAddr, int controlValue, int dataAddr, int dataValue, boolean controlOnly) {
if (!this.isBeingUsedAsATool || (this.isBeingUsedAsATool && connectButton.isConnected())) {
Globals.memoryAndRegistersLock.lock();
try {
try {
Globals.memory.setRawWord(controlAddr, controlValue);
if (!controlOnly) Globals.memory.setRawWord(dataAddr, dataValue);
} catch (AddressErrorException aee) {
System.out.println("Tool author specified incorrect MMIO address!" + aee);
System.exit(0);
}
} finally {
Globals.memoryAndRegistersLock.unlock();

This was probably became an issue as a result of 43652d8, but its possible it existed before that.

@TheThirdOne
Copy link
Owner

The freezing should be fixed now. Check out the release for a build including the fix. Let me know if it is working correctly for you.

Thanks for the report. Your example program was very helpful to quickly reproducing this.

@quinnlp
Copy link
Author

quinnlp commented Jul 11, 2020

Awesome, it's working correctly for me now. You're welcome. Thanks for the quick fix!

@TheThirdOne
Copy link
Owner

I'm glad the fix worked for you.

@quinnlp
Copy link
Author

quinnlp commented Jul 13, 2020

@TheThirdOne
Hello, I was hoping you would be able to create a new release for RARS. I realized that the latest release does not include this bug fix. We will be providing a link to the repository to a class before the semester starts, and they will be mainly downloading the latest release.

Thanks again!

@TheThirdOne
Copy link
Owner

I do plan on making a new release before the new semester. I have been working on supporting 64 bit RISC-V and want to get that included into the release for the next semester.

@quinnlp
Copy link
Author

quinnlp commented Jul 14, 2020

Perfect! Thank you.

@TheThirdOne
Copy link
Owner

I just published the release (https://github.com/TheThirdOne/rars/releases/tag/v1.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants