From 272a239d0e475de8574dbf6ccaed0d586f0027df Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 6 Oct 2025 14:50:54 -0400 Subject: usb: Add EHCI skeleton Signed-off-by: Ian Moffett --- src/sys/io/usb/ehci.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/sys/io/usb/ehci.c diff --git a/src/sys/io/usb/ehci.c b/src/sys/io/usb/ehci.c new file mode 100644 index 0000000..62c1c0e --- /dev/null +++ b/src/sys/io/usb/ehci.c @@ -0,0 +1,77 @@ +/* + * 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 +#include +#include +#include +#include + +#define pr_trace(fmt, ...) printf("ehci: " fmt, ##__VA_ARGS__) +#if defined(AHCI_DEBUG) +#define dtrace(fmt, ...) printf("ehci: " fmt, ##__VA_ARGS__) +#else +#define dtrace(...) __nothing +#endif /* AHCI_DEBUG */ + +static struct pci_device dev; +static struct pci_adv driver; + +static int +ehci_init(struct module *modp) +{ + int error; + + if ((error = pci_advoc(&driver)) < 0) { + pr_trace("failed to advocate for xhc\n"); + return error; + } + + return 0; +} + +/* + * Called when an EHCI host controller is detected + * on the machine + */ +static int +ehci_attach(struct pci_adv *adv) +{ + dev = adv->lookup; + pr_trace("detected EHCI controller\n"); + return 0; +} + +static struct pci_adv driver = { + .lookup = PCI_CS_ID(0x0C, 0x03), + .attach = ehci_attach, + .classrev = 1, +}; + +MODULE_EXPORT("ehci", MODTYPE_PCI, ehci_init); -- cgit v1.2.3 From 25461d1d5df8f6d1cf415eeb7d8d7c073171def5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 6 Oct 2025 21:25:02 -0400 Subject: kern: filedesc: Add fd_open() function Introduce the fd_open() function as apart of the kernel file descriptor API to open a file and get a file descriptor. Signed-off-by: Ian Moffett --- src/sys/include/os/filedesc.h | 11 +++++++++++ src/sys/os/os_filedes.c | 45 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/sys/include/os/filedesc.h b/src/sys/include/os/filedesc.h index 87bf242..c339ed6 100644 --- a/src/sys/include/os/filedesc.h +++ b/src/sys/include/os/filedesc.h @@ -59,6 +59,17 @@ struct filedesc { */ int fdtab_init(struct proc *procp); +/* + * Open a file + * + * @path: Path to file in which we wish to open + * @mode: Mode of our desired file + * + * Returns the file descriptor on success, + * otherwise a less than zero value on failure. + */ +int fd_open(const char *path, mode_t mode); + /* * Write to a file descriptor * diff --git a/src/sys/os/os_filedes.c b/src/sys/os/os_filedes.c index e7cc83a..dde7f22 100644 --- a/src/sys/os/os_filedes.c +++ b/src/sys/os/os_filedes.c @@ -31,10 +31,12 @@ #include #include #include +#include +#include #include #include #include -#include +#include #include #define STDOUT_FILENO 1 @@ -86,6 +88,47 @@ fd_alloc(struct proc *procp, struct filedesc **fd_res) return -EMFILE; } +int +fd_open(const char *path, mode_t mode) +{ + struct filedesc *fd; + struct nameidata nd; + struct proc *self = proc_self(); + struct vnode *vp; + int error; + + /* We need the current proc */ + if (self == NULL) { + return -ESRCH; + } + + if (path == NULL) { + return -ESRCH; + } + + /* Allocate a new file descriptor */ + error = fd_alloc(self, &fd); + if (error < 0) { + return error; + } + + /* + * Now we try to do the lookup, we'll need + * the vnode for file references to be + * useful + */ + nd.path = path; + nd.flags = 0; + nd.vp_res = &vp; + error = namei(&nd); + if (error < 0) { + return error; + } + + fd->vp = vp; + return fd->fdno; +} + /* * Initialize file descriptor table */ -- cgit v1.2.3 From 6ce9297e61d5dbc1640392ed6d253d9769953dcf Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 6 Oct 2025 21:52:15 -0400 Subject: kern: filedes: Add SYS_open system call Signed-off-by: Ian Moffett --- src/sys/include/compat/unix/syscall.h | 5 +++++ src/sys/include/sys/syscall.h | 1 + src/sys/os/os_filedes.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index ab464c4..1b51d26 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -54,6 +54,11 @@ scret_t sys_cross(struct syscall_args *scargs); */ scret_t sys_query(struct syscall_args *scargs); +/* + * Open a file + */ +scret_t sys_open(struct syscall_args *scargs); + #ifdef _NEED_UNIX_SCTAB scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_none] = NULL, diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index c1c06bb..7dcd266 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -49,6 +49,7 @@ #define SYS_sigaction 0x04 #define SYS_query 0x05 /* query a border (mandatory) */ #define SYS_spawn 0x06 /* spawn a process */ +#define SYS_open 0x07 /* open a file */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; diff --git a/src/sys/os/os_filedes.c b/src/sys/os/os_filedes.c index dde7f22..3353a5f 100644 --- a/src/sys/os/os_filedes.c +++ b/src/sys/os/os_filedes.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -181,3 +182,23 @@ write(int fd, const void *buf, size_t count) return count; } + +/* + * ARG0: Path + * ARG1: Mode + */ +scret_t +sys_open(struct syscall_args *scargs) +{ + const char *u_path = SCARG(scargs, const char *, 0); + mode_t mode = SCARG(scargs, mode_t, 1); + char pathbuf[PATH_MAX]; + int error; + + error = copyinstr(u_path, pathbuf, sizeof(PATH_MAX)); + if (error < 0) { + return error; + } + + return fd_open(pathbuf, mode); +} -- cgit v1.2.3 From 473afa3b7e826063b66e579cfbebaa99ee4602ab Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 6 Oct 2025 21:52:49 -0400 Subject: lib: libc: Add SYS_open system call interface Signed-off-by: Ian Moffett --- src/lib/libc/include/unistd.h | 10 +++++++++ src/lib/libc/src/unistd/open.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/lib/libc/src/unistd/open.c diff --git a/src/lib/libc/include/unistd.h b/src/lib/libc/include/unistd.h index b50fc12..fa7f951 100644 --- a/src/lib/libc/include/unistd.h +++ b/src/lib/libc/include/unistd.h @@ -37,6 +37,16 @@ #define STDOUT_FILENO 1 #define STDERR_FILENO 2 +/* + * POSIX open system call + * + * @path: Path to open + * @flags: O_ flags + * + * Returns the file descriptor on success + */ +int open(const char *path, int flags); + /* * POSIX write system call * diff --git a/src/lib/libc/src/unistd/open.c b/src/lib/libc/src/unistd/open.c new file mode 100644 index 0000000..b8eca60 --- /dev/null +++ b/src/lib/libc/src/unistd/open.c @@ -0,0 +1,46 @@ +/* + * 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 +#include +#include + +int +open(const char *path, int flags) +{ + if (path == NULL) { + return -EINVAL; + } + + return syscall( + SYS_open, + (uintptr_t)path, + flags + ); +} -- cgit v1.2.3