SBI_EXT_0_1_CONSOLE_GETCHAR returns error when key pressed
roadriverrail opened this issue · comments
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?