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>
This commit is contained in:
parent
e479d9aea0
commit
a5788ff12d
5 changed files with 80 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
17
lib/libc/arcmwdt/include/sys/timespec.h
Normal file
17
lib/libc/arcmwdt/include/sys/timespec.h
Normal file
|
@ -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_ */
|
58
lib/libc/arcmwdt/libc-hooks.c
Normal file
58
lib/libc/arcmwdt/libc-hooks.c
Normal file
|
@ -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
|
|
@ -333,7 +333,7 @@ static ssize_t stdinout_write_vmeth(void *obj, const void *buffer, size_t count)
|
|||
{
|
||||
#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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue