1

i made a polling sequence and when i first open the program (on QtSpim) it polls perfectly, when i reinitialize and reload the program a second time it just falls through and doesnt poll at all and have to close and reopen QTSpim for the program to properly poll again. am i reopening the program wrong?

    loopst: li  $a3, 0xffff0000     # base of memory-mapped IO area
    rloop:  lw  $t2,($a3)
    nop
    andi    $t2, $t2, 1     
    beqz    $t2, rloop      
    nop

this is my little poll program im trying to run, just to catch a key pressed on the keyboard.

4
  • It would have been better to edit your old question (stackoverflow.com/questions/72256886/…) instead of deleting and reposting, after finding more details on when the problem does/doesn't happen. But I guess at this point you should just leave this question up instead of deleting it and editing the old one. Since there weren't any essential details or hints in comments that aren't already addressed. Commented May 16, 2022 at 18:00
  • @PeterCordes apologies, this is just getting me frustrated Commented May 16, 2022 at 18:02
  • If your program calls (a function containing) this polling loop multiple times, does it eventually clear any buffered key presses and get stuck waiting again for a new one? I don't know if there even is a buffer associated with this keyboard input MMIO register, but if there is, I wonder if it could be capturing keypresses you made between runs? A qtspim bug is also possible, and perhaps other explanations, but at least now you've found the steps to reproduce the problem, i.e. a minimal reproducible example, assuming this does happen on other people's computers. (I haven't tried.) Commented May 16, 2022 at 18:05
  • @PeterCordes using this code stackoverflow.com/questions/36949500/… it does the same thing, first time it runs fine but if i try to reinitialize it skips the initial poll and i get errors, wondering if its a settings thing Commented May 16, 2022 at 18:44

1 Answer 1

0

I would guess this is some kind of bug/flaw/feature in QtSpim.

I wrote some code code to clear the input buffer in a loop until it is emptied, and it works way too well.  I was going to have a loop that printed and emptied each character in the buffer, then printed a message saying it had done so.

However, this turned out to be overkill: merely doing one single read from the data transfer location is sufficient to cause clearing the input buffer between Reloads, so suggest you add this to the beginning of your code, maybe as the first two lines of main.

li $a3, 0xffff0000
lw $t0, 4($a3)

Once that's executed in your simulation, QtSpim seems to reinitialize the input buffer upon Reinitialize and Reload menu command.  If you never read from the data transfer MMIO location during the simulation, QtSpim apparently won't clear the input buffer on Reinit & Reload.


I would venture that this issue is avoided in most situations, since all the simulation has to do a read just one character from the input buffer at any point in the simulation.

So what it takes to elicit this annoying behavior is that some characters are entered in the input buffer, but the program/simulation is stopped & restarted before reading even one character (and that the next program is using MMIO keyboard input).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.