Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native simulator: Update & make host trampolines available to all posix arch boards #60093

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/posix/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if(CONFIG_NATIVE_APPLICATION)
posix_core.c
nsi_compat/nsi_compat.c
${ZEPHYR_BASE}/scripts/native_simulator/common/src/nce.c
${ZEPHYR_BASE}/scripts/native_simulator/common/src/nsi_host_trampolines.c
)
else()
zephyr_library_sources(
Expand Down
19 changes: 19 additions & 0 deletions arch/posix/core/nsi_compat/nsi_host_trampolines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*
* Note: This is a provisional header which exists to allow
* old POSIX arch based boards (i.e. native_posix) to provide access
* to the host C library as if the native simulator trampolines
* existed.
*
* Boards based on the native simulator do NOT use this file
*/

#ifndef ARCH_POSIX_CORE_NSI_COMPAT_NSI_HOST_TRAMPOLINES_H
#define ARCH_POSIX_CORE_NSI_COMPAT_NSI_HOST_TRAMPOLINES_H

#include "../scripts/native_simulator/common/src/include/nsi_host_trampolines.h"

#endif /* ARCH_POSIX_CORE_NSI_COMPAT_NSI_HOST_TRAMPOLINES_H */
2 changes: 2 additions & 0 deletions scripts/native_simulator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

NSI_CONFIG_FILE?=nsi_config
-include ${NSI_CONFIG_FILE}
#If the file does not exist, we don't use it as a build dependency
NSI_CONFIG_FILE:=$(wildcard ${NSI_CONFIG_FILE})

NSI_PATH?=./
NSI_BUILD_PATH?=$(abspath _build/)
Expand Down
10 changes: 10 additions & 0 deletions scripts/native_simulator/common/src/include/nsi_host_trampolines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@
extern "C" {
#endif

void *nsi_host_calloc(unsigned long nmemb, unsigned long size);
int nsi_host_close(int fd);
/* void nsi_host_exit (int status); Use nsi_exit() instead */
void nsi_host_free(void *ptr);
char *nsi_host_getcwd(char *buf, unsigned long size);
int nsi_host_isatty(int fd);
void *nsi_host_malloc(unsigned long size);
int nsi_host_open(const char *pathname, int flags);
/* int nsi_host_printf (const char *fmt, ...); Use the nsi_tracing.h equivalents */
long nsi_host_random(void);
long nsi_host_read(int fd, void *buffer, unsigned long size);
void nsi_host_srandom(unsigned int seed);
char *nsi_host_strdup(const char *s);
long nsi_host_write(int fd, void *buffer, unsigned long size);

#ifdef __cplusplus
}
Expand Down
53 changes: 53 additions & 0 deletions scripts/native_simulator/common/src/nsi_host_trampolines.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,66 @@
*/

#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

void *nsi_host_calloc(unsigned long nmemb, unsigned long size)
{
return calloc(nmemb, size);
}

int nsi_host_close(int fd)
{
return close(fd);
}

void nsi_host_free(void *ptr)
{
free(ptr);
}

char *nsi_host_getcwd(char *buf, unsigned long size)
{
return getcwd(buf, size);
}

int nsi_host_isatty(int fd)
{
return isatty(fd);
}

void *nsi_host_malloc(unsigned long size)
{
return malloc(size);
}

int nsi_host_open(const char *pathname, int flags)
{
return open(pathname, flags);
}

long nsi_host_random(void)
{
return random();
}

long nsi_host_read(int fd, void *buffer, unsigned long size)
{
return read(fd, buffer, size);
}

void nsi_host_srandom(unsigned int seed)
{
srandom(seed);
}

char *nsi_host_strdup(const char *s)
{
return strdup(s);
}

long nsi_host_write(int fd, void *buffer, unsigned long size)
{
return write(fd, buffer, size);
}
2 changes: 1 addition & 1 deletion scripts/native_simulator/common/src/nsi_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern "C" {
* The function must take no parameters and return nothing.
*/
#define NSI_TASK(fn, level, prio) \
static void (* const NSI_CONCAT(__nsi_task_, fn))() \
static void (* const NSI_CONCAT(__nsi_task_, fn))(void) \
__attribute__((__used__)) \
__attribute__((__section__(".nsi_" #level NSI_STRINGIFY(prio) "_task")))\
= fn
Expand Down
Loading