riscv-software-src / riscv-software-src/opensbi
SBI_EXT_0_1_CONSOLE_GETCHAR returns error when key pressed
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 712
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
I might be doing something wrong, but I was playing around with extending the test firmware load, and I noticed that the CONSOLE_GETCHAR ecall extension appears to trigger an error for every keypress.
Basically, modeling my code after the existing ecall interface for printing to the console, I declared a form of getc( ) that makes an ecall to the SBI_EXT_0_1_CONSOLE_GETCHAR:
#define sbi_ecall_console_getc_impl(c) SBI_ECALL_0(SBI_EXT_0_1_CONSOLE_GETCHAR, 0)
I'm then subsequently calling it from inside a loop in test_main( ) to just do a crude console. When no keys are pressed, it's fine. When I press a key, though, the ASCII value for the character pressed gets reported as an error. You can see here as I press some keys alphabetically, starting with lower-case a:
sbi_ecall_handler: Invalid error 97 for ext=0x2 func=0x0
sbi_ecall_handler: Invalid error 98 for ext=0x2 func=0x0
sbi_ecall_handler: Invalid error 99 for ext=0x2 func=0x0
sbi_ecall_handler: Invalid error 100 for ext=0x2 func=0x0
sbi_ecall_handler: Invalid error 101 for ext=0x2 func=0x0
sbi_ecall_handler: Invalid error 102 for ext=0x2 func=0x0
You'll notice those are the ASCII codes for a, b, c, d, e, and f.
I think this boils down to the fact that the handler for this ecall calls sbi_getc( ), which returns the character pressed or a -1.
This gets interpreted as an error in ecall.c due to this code:
if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
sbi_printf("%s: Invalid error %d for ext=0x%lx "
"func=0x%lx\n", __func__, ret,
extension_id, func_id);
ret = SBI_ERR_FAILED;
}
I suspect that I'm not the first person to try to perform console IO, so I suspect I'm missing something obvious here. Any ideas?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ecall.c at the return-value validation shown in the report, then trace the CONSOLE_GETCHAR handler through sbi_getc(). Compare the expected character and error-value conventions for this ecall, and verify the result with the test firmware loop in test_main(). Done means keypresses are returned as characters without producing invalid-error messages, while no-input behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100