diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 2afb1a5a7b..aa59c12e1b 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -76,7 +76,11 @@ endif endif VPATH = :sim -VPATH += :sim/posix +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + VPATH += :sim/win +else + VPATH += :sim/posix +endif DEPPATH = $(patsubst %,--dep-path %,$(subst :, ,$(VPATH))) CFLAGS += -fvisibility=default diff --git a/arch/sim/src/sim/posix/up_vpnkit.c b/arch/sim/src/sim/posix/up_vpnkit.c index fc9d3d864b..37408eb06c 100644 --- a/arch/sim/src/sim/posix/up_vpnkit.c +++ b/arch/sim/src/sim/posix/up_vpnkit.c @@ -257,23 +257,3 @@ void vpnkit_send(unsigned char *buf, unsigned int buflen) DEBUG("a packet sent (size %u)", buflen); } - -/**************************************************************************** - * Name: vpnkit_ifup - * - ****************************************************************************/ - -void vpnkit_ifup(in_addr_t ifaddr) -{ - DEBUG("vpnkit_ifup called"); -} - -/**************************************************************************** - * Name: vpnkit_ifdown - * - ****************************************************************************/ - -void vpnkit_ifdown(void) -{ - DEBUG("vpnkit_ifdown called"); -} diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index 86acc24e39..b9cb0c9d4e 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -32,7 +32,10 @@ #ifndef __ASSEMBLY__ # include # include -# include +# include +# if defined(CONFIG_SIM_NETDEV_TAP) +# include +# endif #endif /**************************************************************************** @@ -298,15 +301,13 @@ void vpnkit_init(void *priv, int vpnkit_avail(void); unsigned int vpnkit_read(unsigned char *buf, unsigned int buflen); void vpnkit_send(unsigned char *buf, unsigned int buflen); -void vpnkit_ifup(in_addr_t ifaddr); -void vpnkit_ifdown(void); # define netdev_init(priv,txcb,rxcb) vpnkit_init(priv,txcb,rxcb) # define netdev_avail() vpnkit_avail() # define netdev_read(buf,buflen) vpnkit_read(buf,buflen) # define netdev_send(buf,buflen) vpnkit_send(buf,buflen) -# define netdev_ifup(ifaddr) vpnkit_ifup(ifaddr) -# define netdev_ifdown() vpnkit_ifdown() +# define netdev_ifup(ifaddr) {} +# define netdev_ifdown() {} #endif /* up_netdriver.c ***********************************************************/ diff --git a/arch/sim/src/sim/win/up_hostirq.c b/arch/sim/src/sim/win/up_hostirq.c new file mode 100644 index 0000000000..2c22252cc1 --- /dev/null +++ b/arch/sim/src/sim/win/up_hostirq.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hostirq.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include "up_internal.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +volatile void *g_current_regs[CONFIG_SMP_NCPUS]; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_irq_save + * + * Description: + * Disable interrupts and returned the mask before disabling them. + * + ****************************************************************************/ + +uint64_t up_irq_save(void) +{ + return 0; +} + +/**************************************************************************** + * Name: up_irq_restore + * + * Input Parameters: + * flags - the mask used to restore interrupts + * + * Description: + * Re-enable interrupts using the specified mask in flags argument. + * + ****************************************************************************/ + +void up_irq_restore(uint64_t flags) +{ +} + +/**************************************************************************** + * Name: up_irqinitialize + ****************************************************************************/ + +void up_irqinitialize(void) +{ +} + +/**************************************************************************** + * Name: up_enable_irq + * + * Description: + * Enable the IRQ specified by 'irq' + * + ****************************************************************************/ + +void up_enable_irq(int irq) +{ +} + +/**************************************************************************** + * Name: up_disable_irq + * + * Description: + * Disable the IRQ specified by 'irq' + * + ****************************************************************************/ + +void up_disable_irq(int irq) +{ +} diff --git a/arch/sim/src/sim/win/up_hostmemory.c b/arch/sim/src/sim/win/up_hostmemory.c new file mode 100644 index 0000000000..47ad9bc047 --- /dev/null +++ b/arch/sim/src/sim/win/up_hostmemory.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hostmemory.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_alloc_heap + * + * Description: + * Allocate executable memory for heap. + * + ****************************************************************************/ + +void *host_alloc_heap(size_t sz) +{ + return _aligned_malloc(sz, 8); +} + +void *host_alloc_shmem(const char *name, size_t size, int master) +{ + HANDLE handle; + void *mem; + + handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, + PAGE_READWRITE, 0, 0, name); + if (handle == NULL) + { + return NULL; + } + + mem = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, size); + CloseHandle(handle); + + return mem; +} + +void host_free_shmem(void *mem) +{ + UnmapViewOfFile(mem); +} + +size_t host_malloc_size(void *mem) +{ + return _msize(mem); +} + +void *host_memalign(size_t alignment, size_t size) +{ + return _aligned_malloc(size, alignment); +} + +void host_free(void *mem) +{ + _aligned_free(mem); +} + +void *host_realloc(void *oldmem, size_t size) +{ + return _aligned_realloc(oldmem, size, 8); +} + +void host_mallinfo(int *aordblks, int *uordblks) +{ +} diff --git a/arch/sim/src/sim/win/up_hostmisc.c b/arch/sim/src/sim/win/up_hostmisc.c new file mode 100644 index 0000000000..795a9849a1 --- /dev/null +++ b/arch/sim/src/sim/win/up_hostmisc.c @@ -0,0 +1,49 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hostmisc.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_abort + * + * Description: + * Abort the simulation + * + * Input Parameters: + * status - Exit status to set + ****************************************************************************/ + +void host_abort(int status) +{ + ExitProcess(status); +} + +int host_backtrace(void** array, int size) +{ + return CaptureStackBackTrace(0, size, array, NULL); +} diff --git a/arch/sim/src/sim/win/up_hosttime.c b/arch/sim/src/sim/win/up_hosttime.c new file mode 100644 index 0000000000..cb857882e7 --- /dev/null +++ b/arch/sim/src/sim/win/up_hosttime.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_hosttime.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define POW10_9 (1000000000ull) + +/* Number of 100ns-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ + +#define DELTA_EPOCH_IN_100NS (0x19db1ded53e8000ull) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: host_gettime + ****************************************************************************/ + +uint64_t host_gettime(bool rtc) +{ + static LARGE_INTEGER start; + LARGE_INTEGER counter; + LARGE_INTEGER freq; + FILETIME ftime; + + if (rtc) + { + GetSystemTimeAsFileTime(&ftime); + + return (((uint64_t)ftime.dwHighDateTime << 32 | + ftime.dwLowDateTime) - DELTA_EPOCH_IN_100NS) * 100; + } + + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&counter); + + counter.QuadPart = counter.QuadPart * POW10_9 / freq.QuadPart; + + if (start.QuadPart == 0) + { + start.QuadPart = counter.QuadPart; + } + + return counter.QuadPart - start.QuadPart; +} + +/**************************************************************************** + * Name: host_sleep + ****************************************************************************/ + +void host_sleep(uint64_t nsec) +{ + LARGE_INTEGER due; + HANDLE timer; + + /* Convert to 100 nanosecond interval, + * negative value indicates relative time + */ + + due.QuadPart = -((nsec + 99) / 100); + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + if (timer != NULL) + { + SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); + } +} + +/**************************************************************************** + * Name: host_sleepuntil + ****************************************************************************/ + +void host_sleepuntil(uint64_t nsec) +{ + uint64_t now; + + now = host_gettime(false); + if (nsec > now) + { + host_sleep(nsec - now); + } +} + +/**************************************************************************** + * Name: host_settimer + * + * Description: + * Set up a timer to send periodic signals. + * + * Input Parameters: + * irq - a pointer where we save the host signal number for SIGALRM + * + * Returned Value: + * On success, (0) zero value is returned, otherwise a negative value. + * + ****************************************************************************/ + +int host_settimer(int *irq) +{ + return -ENOSYS; +} diff --git a/arch/sim/src/sim/win/up_simuart.c b/arch/sim/src/sim/win/up_simuart.c new file mode 100644 index 0000000000..9ce4c9ddfe --- /dev/null +++ b/arch/sim/src/sim/win/up_simuart.c @@ -0,0 +1,142 @@ +/**************************************************************************** + * arch/sim/src/sim/win/up_simuart.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static HANDLE g_stdin_handle; +static HANDLE g_stdout_handle; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: simuart_start + ****************************************************************************/ + +void simuart_start(void) +{ + DWORD mode; + + g_stdin_handle = GetStdHandle(STD_INPUT_HANDLE); + if (GetConsoleMode(g_stdin_handle, &mode)) + { + SetConsoleMode(g_stdin_handle, mode & ~(ENABLE_MOUSE_INPUT | + ENABLE_WINDOW_INPUT | + ENABLE_ECHO_INPUT | + ENABLE_LINE_INPUT)); + FlushConsoleInputBuffer(g_stdin_handle); + } + + g_stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); +} + +/**************************************************************************** + * Name: simuart_open + ****************************************************************************/ + +int simuart_open(const char *pathname) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: simuart_close + ****************************************************************************/ + +void simuart_close(int fd) +{ +} + +/**************************************************************************** + * Name: simuart_putc + ****************************************************************************/ + +int simuart_putc(int fd, int ch) +{ + DWORD nwritten; + + if (WriteConsole(g_stdout_handle, &ch, 1, &nwritten, NULL)) + { + return ch; + } + + return -EIO; +} + +/**************************************************************************** + * Name: simuart_getc + ****************************************************************************/ + +int simuart_getc(int fd) +{ + unsigned char ch; + DWORD nread; + + if (ReadConsole(g_stdin_handle, &ch, 1, &nread, 0)) + { + return ch; + } + + return -EIO; +} + +/**************************************************************************** + * Name: simuart_getcflag + ****************************************************************************/ + +int simuart_getcflag(int fd, unsigned int *cflag) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: simuart_setcflag + ****************************************************************************/ + +int simuart_setcflag(int fd, unsigned int cflag) +{ + return -ENOSYS; +} + +/**************************************************************************** + * Name: simuart_checkc + ****************************************************************************/ + +bool simuart_checkc(int fd) +{ + DWORD size; + + if (GetNumberOfConsoleInputEvents(g_stdin_handle, &size) && size > 1) + { + return true; + } + + return false; +} diff --git a/boards/sim/sim/sim/configs/windows/defconfig b/boards/sim/sim/sim/configs/windows/defconfig new file mode 100644 index 0000000000..fda3a4b07b --- /dev/null +++ b/boards/sim/sim/sim/configs/windows/defconfig @@ -0,0 +1,30 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +CONFIG_ARCH="sim" +CONFIG_ARCH_BOARD="sim" +CONFIG_ARCH_BOARD_SIM=y +CONFIG_ARCH_CHIP="sim" +CONFIG_ARCH_FLOAT_H=y +CONFIG_ARCH_SIM=y +CONFIG_BOARDCTL_POWEROFF=y +CONFIG_BUILTIN=y +CONFIG_DEV_LOOP=y +CONFIG_DEV_ZERO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_EXCLUDE_MEMINFO=y +CONFIG_FS_TMPFS=y +CONFIG_HOST_X86=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_SIM_STACKSIZE_ADJUSTMENT=10240 +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_OSTEST=y diff --git a/libs/libc/machine/sim/Make.defs b/libs/libc/machine/sim/Make.defs index d4067597ee..867d95179f 100644 --- a/libs/libc/machine/sim/Make.defs +++ b/libs/libc/machine/sim/Make.defs @@ -27,7 +27,11 @@ ifeq ($(CONFIG_LIBC_ARCH_ELF),y) CSRCS += arch_elf.c endif ifeq ($(CONFIG_ARCH_SETJMP_H),y) -ASRCS += arch_setjmp_x86.S + ifeq ($(CONFIG_HOST_WINDOWS),y) + ASRCS += arch_setjmp_x86.asm + else + ASRCS += arch_setjmp_x86.S + endif endif else ifeq ($(CONFIG_LIBC_ARCH_ELF),y) @@ -42,7 +46,11 @@ ifeq ($(CONFIG_LIBC_ARCH_ELF),y) CSRCS += arch_elf.c endif ifeq ($(CONFIG_ARCH_SETJMP_H),y) -ASRCS += arch_setjmp_x86.S + ifeq ($(CONFIG_HOST_WINDOWS),y) + ASRCS += arch_setjmp_x86.asm + else + ASRCS += arch_setjmp_x86.S + endif endif else ifeq ($(CONFIG_HOST_ARM),y) ifeq ($(CONFIG_ARCH_SETJMP_H),y) diff --git a/libs/libc/machine/sim/arch_setjmp_x86.asm b/libs/libc/machine/sim/arch_setjmp_x86.asm new file mode 100644 index 0000000000..b8758c653b --- /dev/null +++ b/libs/libc/machine/sim/arch_setjmp_x86.asm @@ -0,0 +1,73 @@ +;*************************************************************************** +; libs/libc/machine/sim/arch_setjmp_x86.asm +; +; Licensed to the Apache Software Foundation (ASF) under one or more +; contributor license agreements. See the NOTICE file distributed with +; this work for additional information regarding copyright ownership. The +; ASF licenses this file to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance with the +; License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +; License for the specific language governing permissions and limitations +; under the License. +; +;*************************************************************************** + +;*************************************************************************** +; Public Functions +;*************************************************************************** + +.model flat, c +.code + +public setjmp +public longjmp + +setjmp: + mov eax, dword ptr [esp+4] + mov dword ptr [eax], ebx + mov dword ptr [eax+4], esi + mov dword ptr [eax+8], edi + + ; Save the value of SP as will be after we return + + lea ecx, dword ptr [esp+4] + mov dword ptr [eax+10h], ecx + + ; Save the return PC + + mov ecx, dword ptr [esp] + mov dword ptr [eax+14h], ecx + + ; Save the framepointer + + mov dword ptr [eax+0ch], ebp + + ; And return 0 + + xor eax, eax + ret + +longjmp: + mov ecx, dword ptr [esp+4] ; jmpbuf in ecx. + mov eax, dword ptr [esp+8] ; Second argument is return value + + ; Save the return address now + + mov edx, dword ptr [ecx+14h] + + ; Restore registers + + mov ebx, dword ptr [ecx] + mov esi, dword ptr [ecx+4] + mov edi, dword ptr [ecx+8] + mov ebp, dword ptr [ecx+0ch] + mov esp, dword ptr [ecx+10h] + jmp dword ptr [ecx+14h] + +end diff --git a/tools/ci/testlist/sim-02.dat b/tools/ci/testlist/sim-02.dat index 44838f3ed5..5eac486758 100644 --- a/tools/ci/testlist/sim-02.dat +++ b/tools/ci/testlist/sim-02.dat @@ -12,3 +12,6 @@ # macOS doesn't have X11 -Darwin,sim:touchscreen + +# Do not build Windows configs +-,sim:windows