ARC: LIB: MWDT: add stdout hooks, timespec header
ARC MWDT toolchain misses stdout hooks implementation and
itimerspec structure in timespec header. Let's add them in
arcmwdt compatibility layer.
The implementation was inspired by libc-hooks.c for NEWLIB.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
diff --git a/include/sys/libc-hooks.h b/include/sys/libc-hooks.h
index aee9581..a33b005 100644
--- a/include/sys/libc-hooks.h
+++ b/include/sys/libc-hooks.h
@@ -16,7 +16,7 @@
* that need to call into the kernel as system calls
*/
-#ifdef CONFIG_NEWLIB_LIBC
+#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARCMWDT_LIBC)
/* syscall generation ignores preprocessor, ensure this is defined to ensure
* we don't have compile errors
diff --git a/lib/libc/arcmwdt/CMakeLists.txt b/lib/libc/arcmwdt/CMakeLists.txt
index 7ef6846..1db9773 100644
--- a/lib/libc/arcmwdt/CMakeLists.txt
+++ b/lib/libc/arcmwdt/CMakeLists.txt
@@ -1,6 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
+zephyr_system_include_directories(include)
+
zephyr_library()
zephyr_library_sources(
arcmwdt-string.c
+ libc-hooks.c
)
diff --git a/lib/libc/arcmwdt/include/sys/timespec.h b/lib/libc/arcmwdt/include/sys/timespec.h
new file mode 100644
index 0000000..4f9c4f4
--- /dev/null
+++ b/lib/libc/arcmwdt/include/sys/timespec.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, 2021 Linaro Limited
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef ZEPHYR_LIB_LIBC_ARCMWDT_INCLUDE_SYS_TIMESPEC_H_
+#define ZEPHYR_LIB_LIBC_ARCMWDT_INCLUDE_SYS_TIMESPEC_H_
+
+#include <sys/_timespec.h>
+
+struct itimerspec {
+ struct timespec it_interval; /* Timer interval */
+ struct timespec it_value; /* Timer expiration */
+};
+
+#endif /* ZEPHYR_LIB_LIBC_ARCMWDT_INCLUDE_SYS_TIMESPEC_H_ */
diff --git a/lib/libc/arcmwdt/libc-hooks.c b/lib/libc/arcmwdt/libc-hooks.c
new file mode 100644
index 0000000..2bcc022
--- /dev/null
+++ b/lib/libc/arcmwdt/libc-hooks.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015, 2021 Intel Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdio.h>
+#include <sys/libc-hooks.h>
+#include <syscall_handler.h>
+#include <string.h>
+#include <sys/errno_private.h>
+#include <errno.h>
+
+static int _stdout_hook_default(int c)
+{
+ ARG_UNUSED(c);
+
+ return EOF;
+}
+
+static int (*_stdout_hook)(int) = _stdout_hook_default;
+
+void __stdout_hook_install(int (*hook)(int))
+{
+ _stdout_hook = hook;
+}
+
+int z_impl_zephyr_write_stdout(const void *buffer, int nbytes)
+{
+ const char *buf = buffer;
+ int i;
+
+ for (i = 0; i < nbytes; i++) {
+ if (*(buf + i) == '\n') {
+ _stdout_hook('\r');
+ }
+ _stdout_hook(*(buf + i));
+ }
+ return nbytes;
+}
+
+#ifdef CONFIG_USERSPACE
+static inline int z_vrfy_z_zephyr_write_stdout(const void *buf, int nbytes)
+{
+ Z_OOPS(Z_SYSCALL_MEMORY_READ(buf, nbytes));
+ return z_impl_zephyr_write_stdout(buf, nbytes);
+}
+#include <syscalls/z_zephyr_write_stdout_mrsh.c>
+#endif
+
+#ifndef CONFIG_POSIX_API
+int _write(int fd, const char *buf, unsigned int nbytes)
+{
+ ARG_UNUSED(fd);
+
+ return z_impl_zephyr_write_stdout(buf, nbytes);
+}
+#endif
diff --git a/lib/os/fdtable.c b/lib/os/fdtable.c
index ee3052e..17bb227 100644
--- a/lib/os/fdtable.c
+++ b/lib/os/fdtable.c
@@ -333,7 +333,7 @@
{
#if defined(CONFIG_BOARD_NATIVE_POSIX)
return write(1, buffer, count);
-#elif defined(CONFIG_NEWLIB_LIBC)
+#elif defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARCMWDT_LIBC)
return z_impl_zephyr_write_stdout(buffer, count);
#else
return 0;