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

Command-Line issues with readchar syscall #135

Open
jplanck opened this issue Oct 22, 2021 · 4 comments
Open

Command-Line issues with readchar syscall #135

jplanck opened this issue Oct 22, 2021 · 4 comments

Comments

@jplanck
Copy link

jplanck commented Oct 22, 2021

There is an issue with readchar syscall. The readcall requires a newline to accept the character, and doesn't read the newline char itself. Perhaps the terminal mode line buffering is misconfigured for readchar.

The following code always causes a runtime exception "Error in /home/jplanck/./riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)"

# read chars in a loop, echoing the integer value of each char read 
# stores the chars as as a string and print the string.
.text
	la	t0, str
	li	t1, '\n'

loop:
	li 	a7, 12
	ecall
	li 	a7, 1
	ecall
	sb 	a0, 0(t0)
	addi	t0, t0, 1
	bne	a0, t1, loop
	sb	x0, 0(t0)
	
	li 	a7, 4
	la	a0, str
	ecall
	li 	a7, 10
	ecall
.data
str: .space 20

Here is the runtime response when i type "1234".
java -jar ~/opt/riscv/rars/rars1_5.jar riscv1.asm nc
1234
49
Error in /home/jplanck/riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)

Simulation terminated due to errors.

Here is the output when I type a newline after each char.
java -jar ~/opt/riscv/rars/rars1_5.jar riscv1.asm nc
1
492
503
514
52
Error in /home/jplanck/riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)

Simulation terminated due to errors.

system info,
Linux version 5.11.0-38-generic (buildd@lgw01-amd64-041) (gcc (Ubuntu 9.3.0-17ubuntu120.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #4220.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021

@TheThirdOne
Copy link
Owner

This is a issue for readchar on the terminal. In the GUI, it works without buffering.

I think it would be a little hard, but I think the best fix for this would be to modify L101 to act like L108.

private static String readStringInternal(String init, String prompt, int maxlength) {
String input = init;
if (Globals.getGui() == null) {
try {
input = getInputReader().readLine();
} catch (IOException e) {
}
} else {
if (Globals.getSettings().getBooleanSetting(Settings.Bool.POPUP_SYSCALL_INPUT)) {
input = Globals.getGui().getMessagesPane().getInputString(prompt);
} else {
input = Globals.getGui().getMessagesPane().getInputString(maxlength);
}
}

@tarvlad
Copy link

tarvlad commented Mar 2, 2023

Fixed it #174. Now, when you press enter (in nc mode), the line will be saved to the buffer and subsequent calls will reads from there (if there are characters there), which will allow you not to lose the next characters after reading from the input stream

@jplanck
Copy link
Author

jplanck commented Mar 29, 2023

This isn't quite fixed. The program doesn't crash, but the output does not match the GUI based output. There seems to be a terminal mode issue as well. The readchar does not take any input until a newline is entered. Using the sample code I provided, I have to type enter twice to leave the program in CLI mode. The ascii code of the chars typed are not printed in real-time as I enter them. When using redirected input, only the ascii code of the 1st char is printed.

@jplanck jplanck closed this as completed Mar 29, 2023
@jplanck
Copy link
Author

jplanck commented Mar 29, 2023

Accidentally closed.

@jplanck jplanck reopened this Mar 29, 2023
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

No branches or pull requests

3 participants