diff --git a/arch/sim/include/spinlock.h b/arch/sim/include/spinlock.h index 9bfc5f40a87..bb19669ca1d 100644 --- a/arch/sim/include/spinlock.h +++ b/arch/sim/include/spinlock.h @@ -41,7 +41,6 @@ ****************************************************************************/ #include -#include /**************************************************************************** * Pre-processor Definitions @@ -49,15 +48,15 @@ /* Must match definitions in up_testset.c */ -#define SP_UNLOCKED false /* The Un-locked state */ -#define SP_LOCKED true /* The Locked state */ +#define SP_UNLOCKED 0 /* The Un-locked state */ +#define SP_LOCKED 1 /* The Locked state */ /**************************************************************************** * Public Types ****************************************************************************/ /* Must match definitions in up_testset.c */ -typedef bool spinlock_t; +typedef uint8_t spinlock_t; /**************************************************************************** * Public Functions diff --git a/arch/sim/src/sim/up_allocateheap.c b/arch/sim/src/sim/up_allocateheap.c index 73eca44de19..ae440402263 100644 --- a/arch/sim/src/sim/up_allocateheap.c +++ b/arch/sim/src/sim/up_allocateheap.c @@ -48,10 +48,6 @@ #include "up_internal.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/sim/src/sim/up_deviceimage.c b/arch/sim/src/sim/up_deviceimage.c index 58a565f3fbd..9ff89c14a07 100644 --- a/arch/sim/src/sim/up_deviceimage.c +++ b/arch/sim/src/sim/up_deviceimage.c @@ -63,14 +63,6 @@ # define kmm_free(mem) free(mem) #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -188,11 +180,6 @@ static const unsigned char g_vfatdata[] = 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x77, 0x7d, 0x06 }; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/sim/src/sim/up_exit.c b/arch/sim/src/sim/up_exit.c index 4241e6025b5..8cac071baf6 100644 --- a/arch/sim/src/sim/up_exit.c +++ b/arch/sim/src/sim/up_exit.c @@ -95,4 +95,8 @@ void up_exit(int status) /* Then switch contexts */ up_longjmp(tcb->xcp.regs, 1); + + /* The function does not return */ + + for (; ; ); } diff --git a/arch/sim/src/sim/up_head.c b/arch/sim/src/sim/up_head.c index ec45563e892..40cfe1079de 100644 --- a/arch/sim/src/sim/up_head.c +++ b/arch/sim/src/sim/up_head.c @@ -89,11 +89,10 @@ int main(int argc, char **argv, char **envp) /* Start the CPU0 emulation. This should not return. */ sim_cpu0_start(); -#else +#endif /* Start the Nuttx emulation. This should not return. */ nx_start(); -#endif } return g_exitcode; diff --git a/arch/sim/src/sim/up_hostfs.c b/arch/sim/src/sim/up_hostfs.c index 2c6e2514f27..f2e60f7e2a3 100644 --- a/arch/sim/src/sim/up_hostfs.c +++ b/arch/sim/src/sim/up_hostfs.c @@ -37,8 +37,6 @@ * Included Files ****************************************************************************/ -#define _GNU_SOURCE 1 - #include #include #include @@ -55,7 +53,7 @@ #include "hostfs.h" /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /**************************************************************************** diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index ef90ae9d1a5..81f98b3f8a9 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -41,20 +41,12 @@ * Included Files ****************************************************************************/ -#include -#include - -#ifndef __ASSEMBLY__ +#ifdef __ASSEMBLY__ +# include +#else # include # include # include - -# include -# include -# ifdef CONFIG_SMP -# include -# include -# endif #endif /**************************************************************************** @@ -186,16 +178,21 @@ #define STACK_COLOR 0xdeadbeef +#ifndef __ASSEMBLY__ + /**************************************************************************** - * Public Types + * Public Type Definitions ****************************************************************************/ +struct tcb_s; +struct spi_dev_s; +struct qspi_dev_s; +struct ioexpander_dev_s; + /**************************************************************************** * Public Data ****************************************************************************/ -#ifndef __ASSEMBLY__ - #ifdef CONFIG_SMP /* These spinlocks are used in the SMP configuration in order to implement * up_cpu_pause(). The protocol for CPUn to pause CPUm is as follows @@ -211,8 +208,8 @@ * so that it will be ready for the next pause operation. */ -extern volatile spinlock_t g_cpu_wait[CONFIG_SMP_NCPUS] SP_SECTION; -extern volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS] SP_SECTION; +extern volatile uint8_t g_cpu_wait[CONFIG_SMP_NCPUS]; +extern volatile uint8_t g_cpu_paused[CONFIG_SMP_NCPUS]; #endif /**************************************************************************** @@ -221,8 +218,8 @@ extern volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS] SP_SECTION; /* up_setjmp32.S ************************************************************/ -int up_setjmp(xcpt_reg_t *jb); -void up_longjmp(xcpt_reg_t *jb, int val) noreturn_function; +int up_setjmp(void *jb); +void up_longjmp(void *jb, int val); /* up_hostmemory.c **********************************************************/ @@ -246,6 +243,8 @@ void sim_cpu0_start(void); #ifdef CONFIG_SMP void up_cpu_started(void); +int up_cpu_paused(int cpu); +struct tcb_s *up_this_task(void); #endif /* up_oneshot.c *************************************************************/ @@ -315,8 +314,7 @@ int sim_ajoy_initialize(void); /* up_ioexpander.c **********************************************************/ #ifdef CONFIG_SIM_IOEXPANDER -struct ioexpander_dev_s; -FAR struct ioexpander_dev_s *sim_ioexpander_initialize(void); +struct ioexpander_dev_s *sim_ioexpander_initialize(void); #endif /* up_tapdev.c **************************************************************/ @@ -372,12 +370,10 @@ void vpnkit_ifdown(void); /* up_netdriver.c ***********************************************************/ -#ifdef CONFIG_SIM_NETDEV int netdriver_init(void); void netdriver_setmacaddr(unsigned char *macaddr); void netdriver_setmtu(int mtu); void netdriver_loop(void); -#endif /* up_rptun.c ***************************************************************/ @@ -387,19 +383,17 @@ void up_rptun_loop(void); #endif #ifdef CONFIG_SIM_SPIFLASH -struct spi_dev_s; -struct spi_dev_s *up_spiflashinitialize(FAR const char *name); +struct spi_dev_s *up_spiflashinitialize(const char *name); #endif #ifdef CONFIG_SIM_QSPIFLASH -struct qspi_dev_s; struct qspi_dev_s *up_qspiflashinitialize(void); #endif /* Debug ********************************************************************/ #ifdef CONFIG_STACK_COLORATION -void up_stack_color(FAR void *stackbase, size_t nbytes); +void up_stack_color(void *stackbase, size_t nbytes); #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index 6a2ac32f440..243f89b9629 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -44,25 +44,12 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Must match definitions in arch/sim/include/spinlock.h */ - -#define SP_UNLOCKED 0 /* The Un-locked state */ -#define SP_LOCKED 1 /* The Locked state */ +#include "up_internal.h" /**************************************************************************** * Private Types ****************************************************************************/ -/* Must match definitions in arch/sim/include/spinlock.h. Assuming that - * bool and unsigned char are equivalent. - */ - -typedef unsigned char spinlock_t; - struct sim_cpuinfo_s { int cpu; /* CPU number */ @@ -90,20 +77,14 @@ static pthread_t g_cpu_thread[CONFIG_SMP_NCPUS]; * so that it will be ready for the next pause operation. */ -volatile spinlock_t g_cpu_wait[CONFIG_SMP_NCPUS]; -volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS]; +volatile uint8_t g_cpu_wait[CONFIG_SMP_NCPUS]; +volatile uint8_t g_cpu_paused[CONFIG_SMP_NCPUS]; /**************************************************************************** * NuttX domain function prototypes ****************************************************************************/ -void nx_start(void); -void up_cpu_started(void); -int up_cpu_paused(int cpu); -void host_sleepuntil(uint64_t nsec); - #ifdef CONFIG_SCHED_INSTRUMENTATION -struct tcb_s *up_this_task(void); void sched_note_cpu_start(struct tcb_s *tcb, int cpu); void sched_note_cpu_pause(struct tcb_s *tcb, int cpu); void sched_note_cpu_resume(struct tcb_s *tcb, int cpu); @@ -278,10 +259,6 @@ void sim_cpu0_start(void) { return; } - - /* Give control to nx_start() */ - - nx_start(); } /**************************************************************************** @@ -408,8 +385,8 @@ int up_cpu_pause(int cpu) /* Take the spinlock that will prevent the CPU thread from running */ - g_cpu_wait[cpu] = SP_LOCKED; - g_cpu_paused[cpu] = SP_LOCKED; + g_cpu_wait[cpu] = 1; + g_cpu_paused[cpu] = 1; /* Signal the CPU thread */ @@ -454,6 +431,6 @@ int up_cpu_resume(int cpu) /* Release the spinlock that will alloc the CPU thread to continue */ - g_cpu_wait[cpu] = SP_UNLOCKED; + g_cpu_wait[cpu] = 0; return 0; } diff --git a/arch/sim/src/sim/up_spiflash.c b/arch/sim/src/sim/up_spiflash.c index d6a13aa1f7c..548cf730799 100644 --- a/arch/sim/src/sim/up_spiflash.c +++ b/arch/sim/src/sim/up_spiflash.c @@ -327,10 +327,6 @@ struct sim_spiflashdev_s *gp_spidev[] = NULL }; -/************************************************************************************ - * Public Data - ************************************************************************************/ - /************************************************************************************ * Private Functions ************************************************************************************/ diff --git a/arch/sim/src/sim/up_tapdev.c b/arch/sim/src/sim/up_tapdev.c index 7b9e8e6fb49..34dc83a3a67 100644 --- a/arch/sim/src/sim/up_tapdev.c +++ b/arch/sim/src/sim/up_tapdev.c @@ -66,6 +66,8 @@ #include #include +#include "up_internal.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -87,13 +89,6 @@ struct sel_arg_struct struct timeval *tvp; }; -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void netdriver_setmacaddr(unsigned char *macaddr); -void netdriver_setmtu(int mtu); - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/arch/sim/src/sim/up_testset.c b/arch/sim/src/sim/up_testset.c index d0c8d5c9564..a8dc66077cf 100644 --- a/arch/sim/src/sim/up_testset.c +++ b/arch/sim/src/sim/up_testset.c @@ -43,23 +43,6 @@ # include #endif -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Must match definitions in arch/sim/include/spinlock.h */ - -#define SP_UNLOCKED 0 /* The Un-locked state */ -#define SP_LOCKED 1 /* The Locked state */ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Must match definitions in arch/sim/include/spinlock.h */ - -typedef uint8_t spinlock_t; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -84,22 +67,22 @@ typedef uint8_t spinlock_t; * ****************************************************************************/ -spinlock_t up_testset(volatile spinlock_t *lock) +uint8_t up_testset(volatile uint8_t *lock) { #ifdef CONFIG_SMP /* In the multi-CPU SMP case, we use atomic operation to assure that the * following test and set is atomic. */ - return atomic_exchange(lock, SP_LOCKED); + return atomic_exchange(lock, 1); #else /* In the non-SMP case, the simulation is implemented with a single thread * the test-and-set operation is inherently atomic. */ - spinlock_t ret = *lock; - *lock = SP_LOCKED; + uint8_t ret = *lock; + *lock = 1; return ret; #endif } diff --git a/arch/sim/src/sim/up_vpnkit.c b/arch/sim/src/sim/up_vpnkit.c index df551f42fc9..05cffe947fb 100644 --- a/arch/sim/src/sim/up_vpnkit.c +++ b/arch/sim/src/sim/up_vpnkit.c @@ -35,6 +35,7 @@ #include #include +#include "up_internal.h" #include "vpnkit/protocol.h" /**************************************************************************** @@ -47,10 +48,6 @@ fprintf(stderr, "up_vpnkit: " fmt "\r\n", ##__VA_ARGS__) #define DEBUG(fmt, ...) -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -64,9 +61,6 @@ static bool g_connect_warned; * Private Functions ****************************************************************************/ -int negotiate(int fd, struct vif_info *vif); -void netdriver_setmacaddr(unsigned char *macaddr); - static int vpnkit_connect(void) { struct sockaddr_un sun; diff --git a/arch/sim/src/sim/up_wpcap.c b/arch/sim/src/sim/up_wpcap.c index ef7b4b3a0cb..a15421e80c6 100644 --- a/arch/sim/src/sim/up_wpcap.c +++ b/arch/sim/src/sim/up_wpcap.c @@ -55,6 +55,8 @@ #include +#include "up_internal.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -114,12 +116,6 @@ static pcap_open_live_t pcap_open_live; static pcap_next_ex_t pcap_next_ex; static pcap_sendpacket_t pcap_sendpacket; -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -void netdriver_setmacaddr(unsigned char *macaddr); - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/arch/sim/src/sim/up_x11eventloop.c b/arch/sim/src/sim/up_x11eventloop.c index 35d01efe450..158dda26ee6 100644 --- a/arch/sim/src/sim/up_x11eventloop.c +++ b/arch/sim/src/sim/up_x11eventloop.c @@ -38,14 +38,9 @@ ****************************************************************************/ #include - #include -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -extern void up_buttonevent(int x, int y, int buttons); +#include "up_internal.h" /**************************************************************************** * Public Data diff --git a/arch/sim/src/sim/vpnkit/protocol.h b/arch/sim/src/sim/vpnkit/protocol.h index 8a66dbf9e8e..7f93d09fda4 100644 --- a/arch/sim/src/sim/vpnkit/protocol.h +++ b/arch/sim/src/sim/vpnkit/protocol.h @@ -140,6 +140,8 @@ extern char expected_hello_old[5]; * Public Function Prototypes ****************************************************************************/ +int negotiate(int fd, struct vif_info *vif); + extern struct init_message *create_init_message(void); extern int read_init_message(int fd, struct init_message *ci); extern int write_init_message(int fd, struct init_message *ci);