diff options
| author | Ian Moffett <ian@osmora.org> | 2025-10-23 19:37:46 -0400 |
|---|---|---|
| committer | Ian Moffett <ian@osmora.org> | 2025-10-23 19:38:30 -0400 |
| commit | d4bf8c00f8cb2fec953bbf184b2f4da667c07d76 (patch) | |
| tree | 837d3b824bb9bd2da2e744a51af23ede7e71534f | |
| parent | 47fb5dc037d368cd374562df21200dd33665343f (diff) | |
Signed-off-by: Ian Moffett <ian@osmora.org>
| -rw-r--r-- | src/sys/include/compat/unix/syscall.h | 4 | ||||
| -rw-r--r-- | src/sys/include/os/sleep.h | 41 | ||||
| -rw-r--r-- | src/sys/include/sys/syscall.h | 1 | ||||
| -rw-r--r-- | src/sys/os/os_sleep.c | 51 |
4 files changed, 96 insertions, 1 deletions
diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index 5df3c51..4c388d4 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -37,6 +37,7 @@ #include <sys/syscall.h> #include <os/ucred.h> #include <os/iotap.h> +#include <os/sleep.h> #include <os/reboot.h> #include <dms/dms.h> #include <vm/map.h> @@ -102,7 +103,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_socket] = sys_socket, [SYS_listen] = sys_listen, [SYS_seteuid] = sys_seteuid, - [SYS_mmap] = sys_mmap + [SYS_mmap] = sys_mmap, + [SYS_usleep] = sys_usleep }; #endif /* !_NEED_UNIX_SCTAB */ diff --git a/src/sys/include/os/sleep.h b/src/sys/include/os/sleep.h new file mode 100644 index 0000000..6caaaf4 --- /dev/null +++ b/src/sys/include/os/sleep.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and L5 engineers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SLEEP_H_ +#define _SYS_SLEEP_H_ 1 + +#include <sys/types.h> +#include <sys/syscall.h> + +/* + * Sleep for n microseconds + */ +scret_t sys_usleep(struct syscall_args *scargs); + +#endif /* !_SYS_SLEEP_H_ */ diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index ee6ef48..c9af8a1 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -63,6 +63,7 @@ #define SYS_listen 0x12 /* listen on a socket */ #define SYS_seteuid 0x13 /* set effective UID */ #define SYS_mmap 0x14 /* map a virtual address */ +#define SYS_usleep 0x15 /* Sleep for n microseconds */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; diff --git a/src/sys/os/os_sleep.c b/src/sys/os/os_sleep.c new file mode 100644 index 0000000..a75ca25 --- /dev/null +++ b/src/sys/os/os_sleep.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and L5 engineers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/syscall.h> +#include <sys/errno.h> +#include <sys/cdefs.h> +#include <os/clkdev.h> +#include <os/sleep.h> + +static struct clkdev *clk = NULL; + +scret_t +sys_usleep(struct syscall_args *scargs) +{ + uint32_t usec = SCARG(scargs, uint32_t, 0); + + if (clk == NULL) + clkdev_get(CLKDEV_GET_USEC | CLKDEV_MSLEEP, &clk); + if (__unlikely(clk == NULL)) + return -EIO; + + /* TODO: Suspend the calling thread */ + clk->usleep(usec); + return 0; +} |
