diff options
author | Kautuk Consul <kconsul@ventanamicro.com> | 2022-09-12 13:52:53 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2022-09-13 15:54:42 +0300 |
commit | 7f09fba86e439808e0b40bdf536937c42e1ea2c9 (patch) | |
tree | f3197b83a54fb67ee9f6143aca28abb563b8f887 /include | |
parent | 49372f2691a006d5a8d424b5a90be23539b06067 (diff) | |
download | opensbi-7f09fba86e439808e0b40bdf536937c42e1ea2c9.tar.xz |
lib: utils/serial: add semihosting support
We add RISC-V semihosting based serial console for JTAG based early
debugging.
The RISC-V semihosting specification is available at:
https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Signed-off-by: Kautuk Consul <kconsul@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/sbi_utils/serial/semihosting.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/sbi_utils/serial/semihosting.h b/include/sbi_utils/serial/semihosting.h new file mode 100644 index 0000000..8cc4a86 --- /dev/null +++ b/include/sbi_utils/serial/semihosting.h @@ -0,0 +1,47 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel <apatel@ventanamicro.com> + * Kautuk Consul <kconsul@ventanamicro.com> + */ + +#ifndef __SERIAL_SEMIHOSTING_H__ +#define __SERIAL_SEMIHOSTING_H__ + +#include <sbi/sbi_types.h> + +/** + * enum semihosting_open_mode - Numeric file modes for use with semihosting_open() + * MODE_READ: 'r' + * MODE_BINARY: 'b' + * MODE_PLUS: '+' + * MODE_WRITE: 'w' + * MODE_APPEND: 'a' + * + * These modes represent the mode string used by fopen(3) in a form which can + * be passed to semihosting_open(). These do NOT correspond directly to %O_RDONLY, + * %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS + * effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC. + * For compatibility, @MODE_BINARY should be added when opening non-text files + * (such as images). + */ +enum semihosting_open_mode { + MODE_READ = 0x0, + MODE_BINARY = 0x1, + MODE_PLUS = 0x2, + MODE_WRITE = 0x4, + MODE_APPEND = 0x8, +}; + +#ifdef CONFIG_SERIAL_SEMIHOSTING +int semihosting_init(void); +int semihosting_enabled(void); +#else +static inline int semihosting_init(void) { return SBI_ENODEV; } +static inline int semihosting_enabled(void) { return 0; } +#endif + +#endif |