[PATCH 14/17] arm: smh: Add some functions for working with the host console
Sean Anderson
sean.anderson at seco.com
Thu Mar 3 21:43:57 CET 2022
This adds three wrappers around the semihosting commands for reading and
writing to the host console. We use the more standard getc/putc/puts
names instead of readc/writec/write0 for familiarity.
Signed-off-by: Sean Anderson <sean.anderson at seco.com>
---
arch/arm/lib/semihosting.c | 18 ++++++++++++++++++
include/semihosting.h | 19 +++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 57ab25294f..7595dbc4a9 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -15,8 +15,11 @@
#define SYSOPEN 0x01
#define SYSCLOSE 0x02
+#define SYSWRITEC 0x03
+#define SYSWRITE0 0x04
#define SYSWRITE 0x05
#define SYSREAD 0x06
+#define SYSREADC 0x07
#define SYSSEEK 0x0A
#define SYSFLEN 0x0C
#define SYSERRNO 0x13
@@ -167,3 +170,18 @@ long smh_seek(long fd, long pos)
return smh_errno();
return 0;
}
+
+int smh_getc(void)
+{
+ return smh_trap(SYSREADC, NULL);
+}
+
+void smh_putc(char ch)
+{
+ smh_trap(SYSWRITEC, &ch);
+}
+
+void smh_puts(const char *s)
+{
+ smh_trap(SYSWRITE0, (char *)s);
+}
diff --git a/include/semihosting.h b/include/semihosting.h
index b53c650444..6f3c29786c 100644
--- a/include/semihosting.h
+++ b/include/semihosting.h
@@ -86,4 +86,23 @@ long smh_flen(long fd);
*/
long smh_seek(long fd, long pos);
+/**
+ * smh_getc() - Read a character from stdin
+ *
+ * Return: The character read, or a negative error on failure
+ */
+int smh_getc(void);
+
+/**
+ * smh_putc() - Print a character on stdout
+ * @ch: The character to print
+ */
+void smh_putc(char ch);
+
+/**
+ * smh_write0() - Print a nul-terminated string on stdout
+ * @s: The string to print
+ */
+void smh_puts(const char *s);
+
#endif /* _SEMIHOSTING_H */
--
2.25.1
More information about the U-Boot
mailing list