summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_console.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-10lib: sbi: Speed-up sbi_printf() and friends using nputs()Anup Patel1-22/+54
The sbi_printf() is slow for semihosting because it prints one character at a time. To speed-up sbi_printf() for semihosting, we use a temporary buffer and nputs(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-02-10lib: sbi: Add console_puts() callback in the console deviceAnup Patel1-7/+22
We add console_puts() callback in the console device which allows console drivers (such as semihosting) to implement a specialized way to output character string. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-02-09lib: sbi: Add sbi_ngets() functionAnup Patel1-0/+15
We add new sbi_ngets() which help us read characters into a physical memory location. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-02-09lib: sbi: Add sbi_nputs() functionAnup Patel1-0/+12
We add new sbi_nputs() which help us print a fixed number of characters from a physical memory location. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Xiang W <wxjstz@126.com>
2023-01-06treewide: Replace TRUE/FALSE with true/falseBin Meng1-2/+2
C language standard uses true/false for the boolean type. Let's switch to that for better language compatibility. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org> Tested-by: Samuel Holland <samuel@sholland.org>
2022-07-30lib: sbi: Fix printf handling of long longdramforever1-28/+2
Read long long arguments directly using va_arg. Remove original hack for RV32 that read a long long arg as two long args. This un-breaks the case on RV64 where e.g. the long long is followed by an odd number of ints: sbi_printf("%d %lld", (int) 1, (long long) 2LL); Also remove the acnt variable, which is now unused. Signed-off-by: dramforever <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Fix sbi_snprintfAndrew Jones1-16/+23
printc would happily write to 'out' even when 'out_len' was zero, potentially overflowing buffers. Rework printc to not do that and also ensure the null byte is written at the last position when necessary, as stated in the snprintf man page. Also, panic if sprintf or snprintf are called with NULL output strings (except the special case of snprintf having a NULL output string and a zero output size, allowing it to be used to get the number of characters that would have been written). Finally, rename a goto label which clashed with 'out'. Fixes: 9e8ff05cb61f ("Initial commit.") Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2021-12-02lib: sbi: Improve fatal error handlingJessica Clarke1-0/+14
BUG and BUG_ON are not informative and are rather lazy interfaces, only telling the user that something went wrong in a given function, but not what, requiring the user to find the sources corresponding to their firmware (which may not be available) and figure out how that BUG(_ON) was hit. Even SBI_ASSERT in its current form, which does include the condition that triggered it in the output, isn't necessarily very informative. In some cases, the error may be fixable by the user, but they need to know the problem in order to have any hope of fixing it. It's also a nuisance for developers, whose development trees may have changed significantly since the release in question being used, and so line numbers can make it harder for them to understand which error case a user has hit. This patch introduces a new sbi_panic function which is printf-like, allowing detailed error messages to be printed to the console. BUG and BUG_ON are removed, since the former is just a worse form of sbi_panic and the latter is a worse version of SBI_ASSERT. Finally, SBI_ASSERT is augmented to take a set of arguments to pass to sbi_panic on failure, used like so (sbi_boot_print_hart's current error case, which currently manually calls sbi_printf and sbi_hart_hang): SBI_ASSERT(xlen >= 1, ("Error %d getting MISA XLEN\n", xlen)); The existing users of BUG are replaced with calls to sbi_panic along with informative error messages. BUG_ON and SBI_ASSERT were unused (and, in the case of SBI_ASSERT, remain unused). Many existing users of sbi_hart_hang should be converted to use either sbi_panic or SBI_ASSERT after this commit. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2021-08-30lib: sbi: protect dprintf output with spinlockDong Du1-1/+4
Avoid getting messages from multiple harts (using dprintf and printf) concurrently with a spinlock serializaing calls to sbi_dprintf(), sbi_printf() and sbi_puts() Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-28lib: sbi: Simplify console platform operationsAnup Patel1-8/+23
Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2020-03-28include: sbi_console: Remove scratch parameter from sbi_dprintf()Anup Patel1-3/+5
This patch removes scratch parameter from sbi_dprintf() function because sbi_dprintf() can use sbi_scratch_thishart_ptr() to get current HART scratch space. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-09lib: Introduce sbi_dprintf() APIAnup Patel1-0/+13
This patch introduces new sbi_dprintf() API for runtime debug prints. The sbi_dprintf() will print to console for a given HART only when SBI_SCRATCH_DEBUG_PRINTS option in enabled in sbi_scratch for this HART. We can now add debug prints using sbi_dprintf() at important places in OpenSBI sources. These debug prints will only show up when previous booting stage or compile time parameter sets the SBI_SCRATCH_DEBUG_PRINTS option in scratch space. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra1-0/+383
Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>