2014-09-16 13:09:14 +02:00
|
|
|
/*
|
2015-09-27 18:58:30 +02:00
|
|
|
* Copyright (C) 2013, 2014 Ludwig Knüpfer
|
2014-09-16 13:09:14 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
2013-11-07 17:23:08 +01:00
|
|
|
/**
|
|
|
|
* Native CPU internal declarations
|
|
|
|
*/
|
|
|
|
|
2023-01-13 01:09:51 +01:00
|
|
|
/**
|
|
|
|
* @defgroup cpu_native_stdio STDIO for native
|
|
|
|
* @ingroup sys_stdio
|
|
|
|
* @brief Standard input/output backend for native
|
|
|
|
*
|
|
|
|
* This will hook up RIOT's stdio to the host's stdio fds. It is the default
|
|
|
|
* stdio implementation of the board `native`.
|
|
|
|
*
|
|
|
|
* @see cpu_native
|
|
|
|
*/
|
|
|
|
|
2013-11-07 17:23:08 +01:00
|
|
|
/**
|
2018-06-01 12:17:51 +02:00
|
|
|
* @ingroup cpu_native
|
2013-11-07 17:23:08 +01:00
|
|
|
* @{
|
2015-09-27 18:58:30 +02:00
|
|
|
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
2013-11-07 17:23:08 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#ifndef NATIVE_INTERNAL_H
|
|
|
|
#define NATIVE_INTERNAL_H
|
2013-11-07 17:23:08 +01:00
|
|
|
|
2013-12-22 23:26:54 +01:00
|
|
|
#include <signal.h>
|
2014-07-17 12:55:24 +02:00
|
|
|
#include <stdio.h>
|
2017-08-20 10:49:49 +02:00
|
|
|
#include <poll.h>
|
2014-04-10 14:58:12 +02:00
|
|
|
/* enable signal handler register access on different platforms
|
|
|
|
* check here for more:
|
|
|
|
* http://sourceforge.net/p/predef/wiki/OperatingSystems/
|
|
|
|
*/
|
2022-12-19 18:25:29 +01:00
|
|
|
#ifdef __FreeBSD__
|
2014-04-10 14:58:12 +02:00
|
|
|
#ifndef _XOPEN_SOURCE
|
|
|
|
#define _XOPEN_SOURCE
|
|
|
|
#include <ucontext.h>
|
|
|
|
#undef _XOPEN_SOURCE
|
|
|
|
#else
|
|
|
|
#include <ucontext.h>
|
|
|
|
#endif
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define GNU_SOURCE
|
|
|
|
#include <ucontext.h>
|
|
|
|
#undef GNU_SOURCE
|
|
|
|
#else
|
|
|
|
#include <ucontext.h>
|
|
|
|
#endif
|
2018-02-05 11:39:41 +01:00
|
|
|
#endif /* BSD/Linux */
|
2014-11-14 20:52:17 +01:00
|
|
|
#include <netdb.h>
|
2014-11-18 17:31:26 +01:00
|
|
|
#include <ifaddrs.h>
|
2014-11-18 19:59:30 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
2015-02-15 12:43:50 +01:00
|
|
|
#include <sys/stat.h>
|
2023-02-24 21:29:49 +01:00
|
|
|
#include <sys/statvfs.h>
|
2015-08-21 16:08:43 +02:00
|
|
|
#include <sys/uio.h>
|
2023-02-24 21:29:49 +01:00
|
|
|
#include <dirent.h>
|
2014-04-10 14:58:12 +02:00
|
|
|
|
2014-10-13 10:53:20 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2014-10-29 18:00:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prototype for native's internal callbacks
|
|
|
|
*/
|
|
|
|
typedef void (*_native_callback_t)(void);
|
|
|
|
|
2013-11-07 17:23:08 +01:00
|
|
|
/**
|
2017-01-15 13:06:13 +01:00
|
|
|
* @cond INTERNAL
|
2013-11-07 17:23:08 +01:00
|
|
|
* internal functions
|
|
|
|
*/
|
|
|
|
void native_cpu_init(void);
|
|
|
|
void native_interrupt_init(void);
|
|
|
|
|
2014-05-07 13:29:34 +02:00
|
|
|
void native_irq_handler(void);
|
2013-11-07 17:23:08 +01:00
|
|
|
extern void _native_sig_leave_tramp(void);
|
2014-11-28 12:14:54 +01:00
|
|
|
extern void _native_sig_leave_handler(void);
|
2013-11-07 17:23:08 +01:00
|
|
|
|
2014-05-07 13:29:34 +02:00
|
|
|
void _native_syscall_leave(void);
|
|
|
|
void _native_syscall_enter(void);
|
2014-07-18 10:07:02 +02:00
|
|
|
void _native_init_syscalls(void);
|
2013-11-07 17:23:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* external functions regularly wrapped in native for direct use
|
|
|
|
*/
|
|
|
|
extern ssize_t (*real_read)(int fd, void *buf, size_t count);
|
|
|
|
extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
|
2023-02-24 21:29:49 +01:00
|
|
|
extern off_t (*real_lseek)(int fd, off_t offset, int whence);
|
|
|
|
extern off_t (*real_fstat)(int fd, struct stat *statbuf);
|
|
|
|
extern int (*real_statvfs)(const char *restrict path, struct statvfs *restrict buf);
|
|
|
|
extern int (*real_fsync)(int fd);
|
2014-07-17 12:55:24 +02:00
|
|
|
extern size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
|
|
extern void (*real_clearerr)(FILE *stream);
|
2014-11-18 17:31:26 +01:00
|
|
|
extern __attribute__((noreturn)) void (*real_exit)(int status);
|
2014-01-24 17:03:01 +01:00
|
|
|
extern void (*real_free)(void *ptr);
|
|
|
|
extern void* (*real_calloc)(size_t nmemb, size_t size);
|
2014-07-18 10:07:02 +02:00
|
|
|
extern void* (*real_malloc)(size_t size);
|
2014-01-24 17:03:01 +01:00
|
|
|
extern void* (*real_realloc)(void *ptr, size_t size);
|
2014-11-14 20:52:17 +01:00
|
|
|
extern void (*real_freeaddrinfo)(struct addrinfo *res);
|
2014-11-18 17:31:26 +01:00
|
|
|
extern void (*real_freeifaddrs)(struct ifaddrs *ifa);
|
2014-11-19 11:53:16 +01:00
|
|
|
extern void (*real_srandom)(unsigned int seed);
|
2014-11-14 20:52:17 +01:00
|
|
|
/* The ... is a hack to save includes: */
|
2014-11-14 17:48:25 +01:00
|
|
|
extern int (*real_accept)(int socket, ...);
|
|
|
|
/* The ... is a hack to save includes: */
|
2014-10-01 21:54:04 +02:00
|
|
|
extern int (*real_bind)(int socket, ...);
|
2016-10-28 15:21:08 +02:00
|
|
|
extern int (*real_connect)(int socket, ...);
|
2023-01-10 14:24:16 +01:00
|
|
|
extern int (*real_recv)(int sockfd, void *buf, size_t len, int flags);
|
2015-02-15 12:43:50 +01:00
|
|
|
extern int (*real_chdir)(const char *path);
|
2014-06-13 23:52:05 +02:00
|
|
|
extern int (*real_close)(int);
|
2017-03-22 13:12:49 +01:00
|
|
|
extern int (*real_fcntl)(int, int, ...);
|
2014-11-18 17:31:26 +01:00
|
|
|
/* The ... is a hack to save includes: */
|
|
|
|
extern int (*real_creat)(const char *path, ...);
|
2014-07-18 10:07:02 +02:00
|
|
|
extern int (*real_dup2)(int, int);
|
|
|
|
extern int (*real_execve)(const char *, char *const[], char *const[]);
|
2014-07-17 12:55:24 +02:00
|
|
|
extern int (*real_feof)(FILE *stream);
|
|
|
|
extern int (*real_ferror)(FILE *stream);
|
2014-06-18 20:34:12 +02:00
|
|
|
extern int (*real_fork)(void);
|
2014-11-14 20:52:17 +01:00
|
|
|
/* The ... is a hack to save includes: */
|
|
|
|
extern int (*real_getaddrinfo)(const char *node, ...);
|
2014-11-18 17:31:26 +01:00
|
|
|
extern int (*real_getifaddrs)(struct ifaddrs **ifap);
|
2014-07-18 10:07:02 +02:00
|
|
|
extern int (*real_getpid)(void);
|
2016-10-28 15:21:08 +02:00
|
|
|
extern int (*real_gettimeofday)(struct timeval *t, ...);
|
2014-11-18 17:31:26 +01:00
|
|
|
extern int (*real_ioctl)(int fildes, int request, ...);
|
2014-10-01 21:54:04 +02:00
|
|
|
extern int (*real_listen)(int socket, int backlog);
|
2014-11-18 17:31:26 +01:00
|
|
|
extern int (*real_open)(const char *path, int oflag, ...);
|
2023-02-24 21:29:49 +01:00
|
|
|
extern int (*real_mkdir)(const char *pathname, mode_t mode);
|
|
|
|
extern int (*real_rmdir)(const char *pathname);
|
|
|
|
extern DIR *(*real_opendir)(const char *name);
|
|
|
|
extern struct dirent *(*real_readdir)(DIR *dirp);
|
|
|
|
extern int (*real_closedir)(DIR *dirp);
|
2014-06-20 20:00:20 +02:00
|
|
|
extern int (*real_pause)(void);
|
2014-07-18 10:07:02 +02:00
|
|
|
extern int (*real_pipe)(int[2]);
|
2014-11-18 17:31:26 +01:00
|
|
|
/* The ... is a hack to save includes: */
|
|
|
|
extern int (*real_select)(int nfds, ...);
|
2017-08-20 10:49:49 +02:00
|
|
|
extern int (*real_poll)(struct pollfd *nfds, ...);
|
2014-11-18 19:59:30 +01:00
|
|
|
extern int (*real_setitimer)(int which, const struct itimerval
|
2015-02-07 15:28:10 +01:00
|
|
|
*__restrict value, struct itimerval *__restrict ovalue);
|
2015-02-15 12:43:50 +01:00
|
|
|
extern int (*real_setsid)(void);
|
2014-11-14 20:52:17 +01:00
|
|
|
extern int (*real_setsockopt)(int socket, ...);
|
|
|
|
extern int (*real_socket)(int domain, int type, int protocol);
|
2014-07-18 10:07:02 +02:00
|
|
|
extern int (*real_printf)(const char *format, ...);
|
|
|
|
extern int (*real_unlink)(const char *);
|
2023-02-24 21:29:49 +01:00
|
|
|
extern int (*real_rename)(const char *, const char *);
|
2014-11-19 11:53:16 +01:00
|
|
|
extern long int (*real_random)(void);
|
2014-11-14 20:52:17 +01:00
|
|
|
extern const char* (*real_gai_strerror)(int errcode);
|
2014-07-17 12:55:24 +02:00
|
|
|
extern FILE* (*real_fopen)(const char *path, const char *mode);
|
2016-07-11 09:53:13 +02:00
|
|
|
extern int (*real_fclose)(FILE *stream);
|
|
|
|
extern int (*real_fseek)(FILE *stream, long offset, int whence);
|
2022-09-29 14:07:48 +02:00
|
|
|
extern long (*real_ftell)(FILE *stream);
|
2016-07-11 09:53:13 +02:00
|
|
|
extern int (*real_fputc)(int c, FILE *stream);
|
|
|
|
extern int (*real_fgetc)(FILE *stream);
|
2015-02-15 12:43:50 +01:00
|
|
|
extern mode_t (*real_umask)(mode_t cmask);
|
2015-08-21 16:08:43 +02:00
|
|
|
extern ssize_t (*real_writev)(int fildes, const struct iovec *iov, int iovcnt);
|
2021-01-14 18:31:49 +01:00
|
|
|
extern ssize_t (*real_send)(int sockfd, const void *buf, size_t len, int flags);
|
2013-11-07 17:23:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* data structures
|
|
|
|
*/
|
|
|
|
extern volatile int native_interrupts_enabled;
|
|
|
|
extern volatile unsigned int _native_saved_eip;
|
|
|
|
extern int _sig_pipefd[2];
|
|
|
|
extern volatile int _native_sigpend;
|
|
|
|
extern volatile int _native_in_isr;
|
|
|
|
extern volatile int _native_in_syscall;
|
|
|
|
|
2021-10-12 14:56:11 +02:00
|
|
|
extern char __isr_stack[];
|
|
|
|
extern char __end_stack[];
|
2013-11-07 17:23:08 +01:00
|
|
|
extern ucontext_t native_isr_context;
|
|
|
|
extern ucontext_t end_context;
|
|
|
|
extern ucontext_t *_native_cur_ctx, *_native_isr_ctx;
|
|
|
|
|
2013-12-10 12:10:05 +01:00
|
|
|
extern const char *_progname;
|
2014-02-14 16:18:40 +01:00
|
|
|
extern char **_native_argv;
|
2014-05-13 16:53:36 +02:00
|
|
|
extern pid_t _native_pid;
|
2014-05-16 15:40:06 +02:00
|
|
|
extern pid_t _native_id;
|
2015-01-10 10:22:51 +01:00
|
|
|
extern unsigned _native_rng_seed;
|
|
|
|
extern int _native_rng_mode; /**< 0 = /dev/random, 1 = random(3) */
|
2014-05-19 19:58:40 +02:00
|
|
|
extern const char *_native_unix_socket_path;
|
2013-12-10 12:10:05 +01:00
|
|
|
|
2014-03-26 13:49:01 +01:00
|
|
|
ssize_t _native_read(int fd, void *buf, size_t count);
|
|
|
|
ssize_t _native_write(int fd, const void *buf, size_t count);
|
2015-08-21 16:08:43 +02:00
|
|
|
ssize_t _native_writev(int fildes, const struct iovec *iov, int iovcnt);
|
2013-12-22 23:26:54 +01:00
|
|
|
|
2017-01-15 13:06:13 +01:00
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2013-12-22 23:26:54 +01:00
|
|
|
/**
|
|
|
|
* register interrupt handler handler for interrupt sig
|
|
|
|
*/
|
2014-10-29 18:00:38 +01:00
|
|
|
int register_interrupt(int sig, _native_callback_t handler);
|
2013-12-22 23:26:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* unregister interrupt handler for interrupt sig
|
|
|
|
*/
|
|
|
|
int unregister_interrupt(int sig);
|
|
|
|
|
2014-10-13 10:53:20 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-22 23:26:54 +01:00
|
|
|
#include "sched.h"
|
|
|
|
|
2013-11-07 17:23:08 +01:00
|
|
|
/** @} */
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* NATIVE_INTERNAL_H */
|