summaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/arch/aarch64/board.h51
-rw-r--r--sys/include/arch/aarch64/cdefs.h1
-rw-r--r--sys/include/arch/aarch64/cpu.h1
-rw-r--r--sys/include/arch/aarch64/exception.h54
-rw-r--r--sys/include/arch/aarch64/frame.h80
-rw-r--r--sys/include/arch/aarch64/frameasm.h89
-rw-r--r--sys/include/arch/aarch64/intr.h57
-rw-r--r--sys/include/arch/aarch64/param.h35
-rw-r--r--sys/include/arch/aarch64/pci/pci.h40
-rw-r--r--sys/include/arch/aarch64/pio.h1
-rw-r--r--sys/include/arch/amd64/asm.h10
-rw-r--r--sys/include/arch/amd64/bus.h8
-rw-r--r--sys/include/arch/amd64/cdefs.h12
-rw-r--r--sys/include/arch/amd64/cpu.h53
-rw-r--r--sys/include/arch/amd64/intr.h28
-rw-r--r--sys/include/arch/amd64/ipi.h67
-rw-r--r--sys/include/arch/amd64/isa/i8042var.h4
-rw-r--r--sys/include/arch/amd64/param.h35
-rw-r--r--sys/include/arch/amd64/pci/pci.h40
-rw-r--r--sys/include/arch/amd64/tsc.h55
-rw-r--r--sys/include/crypto/chacha20.h46
-rw-r--r--sys/include/crypto/siphash.h34
-rw-r--r--sys/include/dev/acpi/tables.h98
-rw-r--r--sys/include/dev/acpi/uacpi/uacpi/internal/namespace.h1
-rw-r--r--sys/include/dev/acpi/uacpi/uacpi/platform/config.h1
-rw-r--r--sys/include/dev/acpi/uacpi/uacpi/utilities.h1
-rw-r--r--sys/include/dev/cons/ansi.h75
-rw-r--r--sys/include/dev/cons/cons.h21
-rw-r--r--sys/include/dev/dmi/dmi.h42
-rw-r--r--sys/include/dev/dmi/dmivar.h41
-rw-r--r--sys/include/dev/ic/ahciregs.h7
-rw-r--r--sys/include/dev/ic/ahcivar.h2
-rw-r--r--sys/include/dev/ic/nvmevar.h85
-rw-r--r--sys/include/dev/mii/mii.h57
-rw-r--r--sys/include/dev/pci/pci.h1
-rw-r--r--sys/include/dev/phy/e1000regs.h119
-rw-r--r--sys/include/dev/phy/et131xregs.h275
-rw-r--r--sys/include/dev/phy/rtl.h (renamed from sys/include/dev/phy/rt8139.h)3
-rw-r--r--sys/include/dev/random/entropy.h40
-rw-r--r--sys/include/dev/timer.h6
-rw-r--r--sys/include/dev/usb/xhciregs.h1
-rw-r--r--sys/include/dev/video/fbdev.h1
-rw-r--r--sys/include/fs/ctlfs.h6
-rw-r--r--sys/include/fs/devfs.h2
-rw-r--r--sys/include/fs/tmpfs.h77
-rw-r--r--sys/include/lib/crc32.h37
-rw-r--r--sys/include/lib/string.h1
-rw-r--r--sys/include/net/ethertypes.h36
-rw-r--r--sys/include/net/if_arp.h51
-rw-r--r--sys/include/net/if_var.h82
-rw-r--r--sys/include/net/netbuf.h42
-rw-r--r--sys/include/netinet/if_ether.h56
-rw-r--r--sys/include/sys/atomic.h30
-rw-r--r--sys/include/sys/cdefs.h2
-rw-r--r--sys/include/sys/console.h (renamed from sys/include/net/if_ether.h)49
-rw-r--r--sys/include/sys/device.h9
-rw-r--r--sys/include/sys/devstat.h46
-rw-r--r--sys/include/sys/disk.h211
-rw-r--r--sys/include/sys/disklabel.h48
-rw-r--r--sys/include/sys/dmi.h63
-rw-r--r--sys/include/sys/driver.h69
-rw-r--r--sys/include/sys/elf.h66
-rw-r--r--sys/include/sys/endian.h54
-rw-r--r--sys/include/sys/exec.h4
-rw-r--r--sys/include/sys/fbdev.h40
-rw-r--r--sys/include/sys/fcntl.h1
-rw-r--r--sys/include/sys/filedesc.h17
-rw-r--r--sys/include/sys/krq.h40
-rw-r--r--sys/include/sys/limits.h7
-rw-r--r--sys/include/sys/mman.h24
-rw-r--r--sys/include/sys/mmio.h1
-rw-r--r--sys/include/sys/mount.h2
-rw-r--r--sys/include/sys/mutex.h52
-rw-r--r--sys/include/sys/namei.h3
-rw-r--r--sys/include/sys/param.h16
-rw-r--r--sys/include/sys/proc.h61
-rw-r--r--sys/include/sys/queue.h6
-rw-r--r--sys/include/sys/sched.h34
-rw-r--r--sys/include/sys/schedvar.h6
-rw-r--r--sys/include/sys/signal.h2
-rw-r--r--sys/include/sys/socket.h202
-rw-r--r--sys/include/sys/socketvar.h53
-rw-r--r--sys/include/sys/spawn.h3
-rw-r--r--sys/include/sys/spinlock.h3
-rw-r--r--sys/include/sys/stat.h4
-rw-r--r--sys/include/sys/syscall.h20
-rw-r--r--sys/include/sys/sysctl.h22
-rw-r--r--sys/include/sys/syslog.h2
-rw-r--r--sys/include/sys/systm.h1
-rw-r--r--sys/include/sys/termios.h29
-rw-r--r--sys/include/sys/time.h60
-rw-r--r--sys/include/sys/tree.h1
-rw-r--r--sys/include/sys/types.h25
-rw-r--r--sys/include/sys/ucred.h57
-rw-r--r--sys/include/sys/uio.h58
-rw-r--r--sys/include/sys/vfs.h1
-rw-r--r--sys/include/sys/vmstat.h48
-rw-r--r--sys/include/sys/vnode.h39
-rw-r--r--sys/include/sys/vsr.h165
-rw-r--r--sys/include/sys/wait.h37
-rw-r--r--sys/include/sys/workqueue.h101
-rw-r--r--sys/include/vm/physmem.h4
-rw-r--r--sys/include/vm/pmap.h16
-rw-r--r--sys/include/vm/stat.h39
-rw-r--r--sys/include/vm/vm_device.h43
-rw-r--r--sys/include/vm/vm_pager.h1
106 files changed, 3912 insertions, 153 deletions
diff --git a/sys/include/arch/aarch64/board.h b/sys/include/arch/aarch64/board.h
new file mode 100644
index 0000000..bba421f
--- /dev/null
+++ b/sys/include/arch/aarch64/board.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_BOARD_H_
+#define _MACHINE_BOARD_H_
+
+/* Board implementer */
+#define BOARD_ARM_LIMITED 0x41 /* ARM Limited */
+#define BOARD_BROADCOM 0x42 /* Broadcom corp */
+#define BOARD_CAVIUM 0x43 /* Calvium Inc */
+#define BOARD_DIGITAL_EQUIP 0x44 /* Digital Equipment Corporation */
+#define BOARD_FUJITSU 0x46 /* Fujitsu Ltd */
+
+/*
+ * Board information, contains a part number
+ * and an implementer number.
+ */
+struct board_info {
+ uint8_t implementer;
+ uint16_t partno : 12;
+};
+
+void md_get_board(struct board_info *res);
+
+#endif /* !_MACHINE_BOARD_H_ */
diff --git a/sys/include/arch/aarch64/cdefs.h b/sys/include/arch/aarch64/cdefs.h
index a22c436..aaf8649 100644
--- a/sys/include/arch/aarch64/cdefs.h
+++ b/sys/include/arch/aarch64/cdefs.h
@@ -36,5 +36,6 @@
#define md_pause() __ASMV("yield")
#define md_intoff() __ASMV("msr daifset, #2")
#define md_inton() __ASMV("msr daifclr, #2")
+#define md_hlt() __ASMV("hlt #0")
#endif /* !_AARCH64_CDEFS_H_ */
diff --git a/sys/include/arch/aarch64/cpu.h b/sys/include/arch/aarch64/cpu.h
index 2f62d95..8c2d837 100644
--- a/sys/include/arch/aarch64/cpu.h
+++ b/sys/include/arch/aarch64/cpu.h
@@ -39,6 +39,7 @@ struct cpu_info {
struct cpu_info *self;
};
+__dead void cpu_halt_all(void);
void cpu_startup(struct cpu_info *ci);
void cpu_halt_others(void);
diff --git a/sys/include/arch/aarch64/exception.h b/sys/include/arch/aarch64/exception.h
new file mode 100644
index 0000000..9e89c81
--- /dev/null
+++ b/sys/include/arch/aarch64/exception.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_EXCEPTION_H_
+#define _MACHINE_EXCEPTION_H_
+
+#include <sys/types.h>
+#include <machine/frame.h>
+
+/* Exception class */
+#define EC_UNKNOWN 0x00 /* Unknown type */
+#define EC_WF 0x01 /* Trapped WF instruction */
+#define EC_MCRMRC 0x03 /* Trapped MCR/MRC */
+#define EC_MCRRC 0x04 /* Trapped MCRR/MRRC */
+#define EC_LDCSTC 0x06 /* Trapped LDC/STC */
+#define EC_SVE 0x07 /* Trapped SVE/SIMD/FP op */
+#define EC_BRE 0x0D /* Branch target exception */
+#define EC_ILLX 0x0E /* Illegal execution state */
+#define EC_SVC64 0x15 /* AARCH64 SVC */
+#define EC_PCALIGN 0x22 /* PC alignment fault */
+#define EC_DABORT 0x24 /* Data abort (w/o ELx change) */
+#define EC_EDABORT 0x25 /* Data abort (w/ ELx change) */
+#define EC_SPALIGN 0x26 /* SP alignment fault */
+#define EC_SERR 0x2F /* System error (what the fuck!) */
+
+void handle_exception(struct trapframe *tf);
+
+#endif /* !_MACHINE_EXCEPTION_H_ */
diff --git a/sys/include/arch/aarch64/frame.h b/sys/include/arch/aarch64/frame.h
index fa4d33d..143f4d0 100644
--- a/sys/include/arch/aarch64/frame.h
+++ b/sys/include/arch/aarch64/frame.h
@@ -31,43 +31,10 @@
#define _MACHINE_FRAME_H_
#include <sys/types.h>
+#include <sys/cdefs.h>
typedef uint64_t lreg_t;
-
-/* General purpose registers */
-struct gpregs {
- lreg_t x0;
- lreg_t x1;
- lreg_t x2;
- lreg_t x3;
- lreg_t x4;
- lreg_t x5;
- lreg_t x6;
- lreg_t x7;
- lreg_t x8;
- lreg_t x9;
- lreg_t x10;
- lreg_t x11;
- lreg_t x12;
- lreg_t x13;
- lreg_t x14;
- lreg_t x15;
- lreg_t x16;
- lreg_t x17;
- lreg_t x18;
- lreg_t x19;
- lreg_t x20;
- lreg_t x21;
- lreg_t x22;
- lreg_t x23;
- lreg_t x24;
- lreg_t x25;
- lreg_t x26;
- lreg_t x27;
- lreg_t x28;
- lreg_t x29;
- lreg_t x30;
-};
+typedef uint64_t frament_t;
/* Stack regs */
struct sregs {
@@ -83,14 +50,41 @@ struct pstat {
lreg_t spsr_el3;
};
-struct trapframe {
- struct gpregs gp;
- struct sregs stack;
- struct pstat status;
- lreg_t elr_el1;
- lreg_t elr_el2;
- lreg_t elr_el3;
- lreg_t pc;
+struct __aligned(16) trapframe {
+ lreg_t x30;
+ lreg_t x29;
+ lreg_t x28;
+ lreg_t x27;
+ lreg_t x26;
+ lreg_t x25;
+ lreg_t x24;
+ lreg_t x23;
+ lreg_t x22;
+ lreg_t x21;
+ lreg_t x20;
+ lreg_t x19;
+ lreg_t x18;
+ lreg_t x17;
+ lreg_t x16;
+ lreg_t x15;
+ lreg_t x14;
+ lreg_t x13;
+ lreg_t x12;
+ lreg_t x11;
+ lreg_t x10;
+ lreg_t x9;
+ lreg_t x8;
+ lreg_t x7;
+ lreg_t x6;
+ lreg_t x5;
+ lreg_t x4;
+ lreg_t x3;
+ lreg_t x2;
+ lreg_t x1;
+ lreg_t x0;
+ lreg_t elr;
+ lreg_t esr;
+ frament_t trapno;
};
#define TF_IP(TFP) ((TFP)->pc)
diff --git a/sys/include/arch/aarch64/frameasm.h b/sys/include/arch/aarch64/frameasm.h
new file mode 100644
index 0000000..ca7f81a
--- /dev/null
+++ b/sys/include/arch/aarch64/frameasm.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_FRAMEASM_H_
+#define _MACHINE_FRAMEASM_H_
+
+/* XXX: Must be 16-byte aligned!!! */
+#define XFRAME_STACK_SIZE (38 * 8)
+
+/* Trap numbers */
+#define TRAPNO_UNKNOWN #0
+#define TRAPNO_XSYNC #1 /* Synchronous */
+#define TRAPNO_XIRQ #2 /* IRQ */
+#define TRAPNO_XFIQ #3 /* FIQ */
+#define TRAPNO_XSERR #4 /* System error */
+
+#define PUSH_XFRAME(TRAPNO) \
+ sub sp, sp, #XFRAME_STACK_SIZE ; \
+ stp x30, x29, [sp, #(0 * 8)] ; \
+ stp x28, x27, [sp, #(2 * 8)] ; \
+ stp x26, x25, [sp, #(4 * 8)] ; \
+ stp x24, x23, [sp, #(6 * 8)] ; \
+ stp x22, x21, [sp, #(8 * 8)] ; \
+ stp x20, x19, [sp, #(10 * 8)] ; \
+ stp x18, x17, [sp, #(12 * 8)] ; \
+ stp x16, x15, [sp, #(14 * 8)] ; \
+ stp x14, x13, [sp, #(16 * 8)] ; \
+ stp x12, x11, [sp, #(18 * 8)] ; \
+ stp x10, x9, [sp, #(20 * 8)] ; \
+ stp x8, x7, [sp, #(22 * 8)] ; \
+ stp x6, x5, [sp, #(24 * 8)] ; \
+ stp x4, x3, [sp, #(26 * 8)] ; \
+ stp x2, x1, [sp, #(28 * 8)] ; \
+ str x0, [sp, #(30 * 8)] ; \
+ ; \
+ mrs x0, elr_el1 ; \
+ str x0, [sp, #(31 * 8)] ; \
+ mrs x0, esr_el1 ; \
+ str x0, [sp, #(32 * 8)] ; \
+ mov x0, TRAPNO ; \
+ str x0, [sp, #(33 * 8)] ; \
+ mov x0, sp
+
+#define POP_XFRAME() \
+ ldr x0, [sp, #(30 * 8)] ; \
+ ldp x2, x1, [sp, #(28 * 8)] ; \
+ ldp x4, x3, [sp, #(26 * 8)] ; \
+ ldp x6, x5, [sp, #(24 * 8)] ; \
+ ldp x8, x7, [sp, #(22 * 8)] ; \
+ ldp x10, x9, [sp, #(20 * 8)] ; \
+ ldp x12, x11, [sp, #(18 * 8)] ; \
+ ldp x14, x13, [sp, #(16 * 8)] ; \
+ ldp x16, x15, [sp, #(14 * 8)] ; \
+ ldp x18, x17, [sp, #(12 * 8)] ; \
+ ldp x20, x19, [sp, #(10 * 8)] ; \
+ ldp x22, x21, [sp, #(8 * 8)] ; \
+ ldp x24, x23, [sp, #(6 * 8)] ; \
+ ldp x26, x25, [sp, #(4 * 8)] ; \
+ ldp x28, x27, [sp, #(2 * 8)] ; \
+ ldp x30, x29, [sp, #(0 * 8)] ; \
+ add sp, sp, #XFRAME_STACK_SIZE
+
+#endif /* !_MACHINE_FRAMEASM_H_ */
diff --git a/sys/include/arch/aarch64/intr.h b/sys/include/arch/aarch64/intr.h
new file mode 100644
index 0000000..b85564f
--- /dev/null
+++ b/sys/include/arch/aarch64/intr.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_INTR_H_
+#define _MACHINE_INTR_H_
+
+#include <sys/types.h>
+
+/*
+ * Interrupt priority levels
+ */
+#define IPL_NONE 0 /* Don't defer anything */
+#define IPL_BIO 1 /* Block I/O */
+#define IPL_CLOCK 2 /* Clock */
+#define IPL_HIGH 3 /* Defer everything */
+
+struct intr_entry {
+ int priority;
+};
+
+struct intr_hand {
+ int(*func)(void *);
+ char *name;
+ int priority;
+ int irq;
+ int vector;
+};
+
+void *intr_register(const char *name, const struct intr_hand *ih);
+
+#endif /* !_MACHINE_INTR_H_ */
diff --git a/sys/include/arch/aarch64/param.h b/sys/include/arch/aarch64/param.h
new file mode 100644
index 0000000..c074ffb
--- /dev/null
+++ b/sys/include/arch/aarch64/param.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _AARCH64_PARAM_H_
+#define _AARCH64_PARAM_H_
+
+#define M_WORD_SIZE 4
+
+#endif /* !_AARCH64_PARAM_H_ */
diff --git a/sys/include/arch/aarch64/pci/pci.h b/sys/include/arch/aarch64/pci/pci.h
new file mode 100644
index 0000000..189a423
--- /dev/null
+++ b/sys/include/arch/aarch64/pci/pci.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_PCI_H_
+#define _MACHINE_PCI_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <dev/pci/pci.h>
+
+__weak pcireg_t md_pci_readl(struct pci_device *dev, uint32_t off);
+__weak void md_pci_writel(struct pci_device *dev, uint32_t off, pcireg_t val);
+
+#endif /* !_MACHINE_PCI_H_ */
diff --git a/sys/include/arch/aarch64/pio.h b/sys/include/arch/aarch64/pio.h
index 4aaeece..41f07fb 100644
--- a/sys/include/arch/aarch64/pio.h
+++ b/sys/include/arch/aarch64/pio.h
@@ -39,5 +39,4 @@
#define outw(...) __nothing
#define outl(...) __nothing
-
#endif /* _MACHINE_PIO_H_ */
diff --git a/sys/include/arch/amd64/asm.h b/sys/include/arch/amd64/asm.h
index 8d2c812..aca49d2 100644
--- a/sys/include/arch/amd64/asm.h
+++ b/sys/include/arch/amd64/asm.h
@@ -34,6 +34,16 @@
#include <sys/param.h>
#include <machine/msr.h>
+/* CR4 bits */
+#define CR4_TSD BIT(2) /* Timestamp disable */
+#define CR4_DE BIT(3) /* Debugging extensions */
+#define CR4_PSE BIT(4) /* Page size extensions */
+#define CR4_PCE BIT(8) /* Performance monitoring counter enable */
+#define CR4_UMIP BIT(11) /* User mode instruction prevention */
+#define CR4_LA57 BIT(12) /* Level 5 paging enable */
+#define CR4_VMXE BIT(13) /* Virtual machine extensions enable */
+#define CR4_SMXE BIT(14) /* Safer mode extensions enable */
+
/*
* Contains information for the current
* core. Stored in %GS.
diff --git a/sys/include/arch/amd64/bus.h b/sys/include/arch/amd64/bus.h
index 00cb3ba..25088b4 100644
--- a/sys/include/arch/amd64/bus.h
+++ b/sys/include/arch/amd64/bus.h
@@ -36,13 +36,7 @@
struct bus_resource;
-/*
- * Hyra assumes that the bootloader uses PDE[256] for some
- * higher half mappings. To avoid conflicts with those mappings,
- * this offset is used to start device memory at PDE[257]. This
- * will give us more than enough space.
- */
-#define MMIO_OFFSET (VM_HIGHER_HALF + 0x8000000000)
+#define MMIO_OFFSET VM_HIGHER_HALF
/* Resource signature size max */
#define RSIG_MAX 16
diff --git a/sys/include/arch/amd64/cdefs.h b/sys/include/arch/amd64/cdefs.h
index 256fd8b..d038a15 100644
--- a/sys/include/arch/amd64/cdefs.h
+++ b/sys/include/arch/amd64/cdefs.h
@@ -31,7 +31,7 @@
#define _AMD64_CDEFS_H_
#include <sys/cdefs.h>
-#include <machine/sync.h>
+#include <machine/cpu.h>
/*
* Please use CLI wisely, it is a good idea to use
@@ -41,5 +41,15 @@
#define md_pause() __ASMV("rep; nop") /* (F3 90) PAUSE */
#define md_intoff() __ASMV("cli") /* Clear interrupts */
#define md_inton() __ASMV("sti") /* Enable interrupts */
+#define md_hlt() cpu_halt() /* Halt the processor */
+
+/*
+ * AMD64 specific defines
+ */
+#define __invlpg(VA) \
+ __ASMV("invlpg %0" \
+ : \
+ : "m" ((VA)) \
+ : "memory")
#endif /* !_AMD64_CDEFS_H_ */
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
index dd753b7..5adff29 100644
--- a/sys/include/arch/amd64/cpu.h
+++ b/sys/include/arch/amd64/cpu.h
@@ -33,18 +33,48 @@
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/proc.h>
+#include <sys/sched.h>
+#include <sys/spinlock.h>
#include <machine/tss.h>
+#include <machine/cdefs.h>
+#include <machine/intr.h>
#define CPU_IRQ(IRQ_N) (BIT((IRQ_N)) & 0xFF)
+/* Feature bits */
+#define CPU_FEAT_SMAP BIT(0)
+#define CPU_FEAT_SMEP BIT(1)
+#define CPU_FEAT_UMIP BIT(2)
+#define CPU_FEAT_TSCINV BIT(3) /* TSC invariant */
+
+/* CPU vendors */
+#define CPU_VENDOR_OTHER 0x00000000
+#define CPU_VENDOR_INTEL 0x00000001
+#define CPU_VENDOR_AMD 0x00000002
+
+typedef uint32_t ipi_pend_t;
+
struct cpu_info {
uint32_t apicid;
+ uint32_t feat;
+ uint32_t vendor; /* Vendor (see CPU_VENDOR_*) */
+ uint8_t preempt : 1; /* CPU is preemptable */
+ uint8_t ipi_dispatch : 1; /* 1: IPIs being dispatched */
+ ipi_pend_t ipi_pending;
+ uint8_t id; /* MI Logical ID */
+ uint8_t model : 4; /* CPU model number */
+ uint8_t family : 4; /* CPU family ID */
uint8_t has_x2apic : 1;
+ uint8_t tlb_shootdown : 1;
+ uint8_t online : 1; /* CPU online */
uint8_t ipl;
size_t lapic_tmr_freq;
uint8_t irq_mask;
+ vaddr_t shootdown_va;
+ struct sched_cpu stat;
struct tss_entry *tss;
struct proc *curtd;
+ struct spinlock lock;
struct cpu_info *self;
};
@@ -52,9 +82,32 @@ __dead void cpu_halt_all(void);
void cpu_halt_others(void);
void cpu_startup(struct cpu_info *ci);
+void cpu_enable_smep(void);
+void cpu_disable_smep(void);
+
+struct cpu_info *cpu_get(uint32_t index);
+struct sched_cpu *cpu_get_stat(uint32_t cpu_index);
+
+uint32_t cpu_count(void);
+void cpu_shootdown_tlb(vaddr_t va);
+
struct cpu_info *this_cpu(void);
void mp_bootstrap_aps(struct cpu_info *ci);
extern struct cpu_info g_bsp_ci;
+__always_inline static inline void
+cpu_halt(void)
+{
+ struct cpu_info *ci = this_cpu();
+
+ if (ci != NULL)
+ ci->online = 0;
+
+ __ASMV("hlt");
+
+ if (ci != NULL)
+ ci->online = 1;
+}
+
#endif /* !_MACHINE_CPU_H_ */
diff --git a/sys/include/arch/amd64/intr.h b/sys/include/arch/amd64/intr.h
index 2a8d487..6e011fa 100644
--- a/sys/include/arch/amd64/intr.h
+++ b/sys/include/arch/amd64/intr.h
@@ -35,6 +35,8 @@
#define IST_SCHED 1U
#define IST_HW_IRQ 2U
#define IST_SW_INT 3U
+#define IST_SYSCALL 4U
+#define IST_DBFLT 5U
/* Upper 4 bits of interrupt vector */
#define IPL_SHIFT 4
@@ -47,8 +49,23 @@
#define IPL_CLOCK 2 /* Clock */
#define IPL_HIGH 3 /* Defer everything */
-struct intr_entry {
- int priority;
+#define N_IPIVEC 4 /* Number of vectors reserved for IPIs */
+#define IPI_PER_VEC 16 /* Max IPIs per vector */
+
+struct intr_hand;
+
+/*
+ * Contains information passed to driver
+ *
+ * @ihp: Interrupt handler
+ * @data: Driver specific data
+ */
+struct intr_data {
+ struct intr_hand *ihp;
+ union {
+ void *data;
+ uint64_t data_u64;
+ };
};
/*
@@ -57,13 +74,18 @@ struct intr_entry {
* [r]: Required for intr_register()
* [o]: Not required for intr_register()
* [v]: Returned by intr_register()
+ * [i]: Internal
*
* @func: The actual handler [r]
+ * @data: Interrupt data [o/v]
+ * @nintr: Number of times it fired [o]
* @name: Interrupt name [v]
* @priority: Interrupt priority [r]
* @irq: Interrupt request number [o]
* @vector: Interrupt vector [v]
*
+ * XXX: `name' must be null terminated ('\0')
+ *
* XXX: `irq` can be set to -1 for MSI/MSI-X
* interrupts.
*
@@ -76,6 +98,8 @@ struct intr_entry {
*/
struct intr_hand {
int(*func)(void *);
+ size_t nintr;
+ struct intr_data data;
char *name;
int priority;
int irq;
diff --git a/sys/include/arch/amd64/ipi.h b/sys/include/arch/amd64/ipi.h
new file mode 100644
index 0000000..48243e7
--- /dev/null
+++ b/sys/include/arch/amd64/ipi.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_IPI_H_
+#define _MACHINE_IPI_H_
+
+#include <sys/types.h>
+#include <machine/cpu.h>
+#include <machine/lapic.h>
+
+/*
+ * IPI_VECTOR is the main vector used for all misc
+ * IPIs, the HALT_VECTOR is used to slam the system
+ * to a screetching halt.
+ */
+#define IPI_VECTOR 0x21
+#define HALT_VECTOR 0x22
+
+/* Fixed IPI IDs */
+#define IPI_TLB 0
+
+/*
+ * Represents an interprocessor interrupt
+ * handler.
+ *
+ * @cookie: Used to verifying an instance
+ * @id: IPI ID (identifies the IPI)
+ * @mask: If set, IPIs are ignored
+ * @handler: Handler routine
+ */
+struct cpu_ipi {
+ uint16_t cookie;
+ uint8_t id;
+ int(*handler)(struct cpu_ipi *ipi);
+};
+
+int md_ipi_alloc(struct cpu_ipi **res);
+int md_ipi_send(struct cpu_info *ci, ipi_pend_t ipi);
+void md_ipi_init(void);
+
+#endif /* !_MACHINE_IPI_H_ */
diff --git a/sys/include/arch/amd64/isa/i8042var.h b/sys/include/arch/amd64/isa/i8042var.h
index 13c3095..9619920 100644
--- a/sys/include/arch/amd64/isa/i8042var.h
+++ b/sys/include/arch/amd64/isa/i8042var.h
@@ -74,6 +74,10 @@
#define I8042_LED_NUM BIT(1)
#define I8042_LED_CAPS BIT(2)
+/* Extended scancode types */
+#define I8042_XSC_ENDPR 0 /* End pressed */
+#define I8042_XSC_ENDRL 1 /* End released */
+
/* Quirks */
#define I8042_HOSTILE BIT(0) /* If EC likes throwing NMIs */
diff --git a/sys/include/arch/amd64/param.h b/sys/include/arch/amd64/param.h
new file mode 100644
index 0000000..6ea3fca
--- /dev/null
+++ b/sys/include/arch/amd64/param.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _AMD64_PARAM_H_
+#define _AMD64_PARAM_H_
+
+#define M_WORD_SIZE 8
+
+#endif /* !_AMD64_PARAM_H_ */
diff --git a/sys/include/arch/amd64/pci/pci.h b/sys/include/arch/amd64/pci/pci.h
new file mode 100644
index 0000000..189a423
--- /dev/null
+++ b/sys/include/arch/amd64/pci/pci.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_PCI_H_
+#define _MACHINE_PCI_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <dev/pci/pci.h>
+
+__weak pcireg_t md_pci_readl(struct pci_device *dev, uint32_t off);
+__weak void md_pci_writel(struct pci_device *dev, uint32_t off, pcireg_t val);
+
+#endif /* !_MACHINE_PCI_H_ */
diff --git a/sys/include/arch/amd64/tsc.h b/sys/include/arch/amd64/tsc.h
new file mode 100644
index 0000000..d9eed4f
--- /dev/null
+++ b/sys/include/arch/amd64/tsc.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _MACHINE_TSC_H_
+#define _MACHINE_TSC_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/param.h>
+
+uint64_t rdtsc_rel(void);
+
+__always_inline static inline uint64_t
+rdtsc(void)
+{
+ uint32_t lo, hi;
+
+ __ASMV(
+ "rdtsc"
+ : "=d" (hi),
+ "=a" (lo)
+ :
+ : "memory"
+ );
+
+ return COMBINE32(hi, lo);
+}
+
+#endif /* !_MACHINE_TSC_H_ */
diff --git a/sys/include/crypto/chacha20.h b/sys/include/crypto/chacha20.h
new file mode 100644
index 0000000..267b13c
--- /dev/null
+++ b/sys/include/crypto/chacha20.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 <stdint.h>
+#include <stddef.h>
+#include <string.h>
+
+#define ROTL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
+
+#define QR(a,b,c,d) \
+ a += b; d ^= a; d = ROTL(d, 16); \
+ c += d; b ^= c; b = ROTL(b, 12); \
+ a += b; d ^= a; d = ROTL(d, 8); \
+ c += d; b ^= c; b = ROTL(b, 7);
+
+void chacha20_init(uint32_t state[16], const uint8_t key[32],
+ const uint8_t nonce[12], uint32_t counter);
+
+void chacha20_block(uint32_t state[16], uint8_t out[64]);
+void chacha20_encrypt(uint32_t state[16], uint8_t *in, uint8_t *out, size_t len);
diff --git a/sys/include/crypto/siphash.h b/sys/include/crypto/siphash.h
new file mode 100644
index 0000000..ecabb4a
--- /dev/null
+++ b/sys/include/crypto/siphash.h
@@ -0,0 +1,34 @@
+/* <MIT License>
+ Copyright (c) 2013 Marek Majkowski <marek@popcount.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ </MIT License>
+
+ Original location:
+ https://github.com/majek/csiphash/
+
+ Solution inspired by code from:
+ Samuel Neves (supercop/crypto_auth/siphash24/little)
+ djb (supercop/crypto_auth/siphash24/little2)
+ Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
+*/
+
+#include <stdint.h>
+
+uint64_t siphash24(const void *src, unsigned long src_sz, const char k[16]);
diff --git a/sys/include/dev/acpi/tables.h b/sys/include/dev/acpi/tables.h
index 5215c86..d31cbe0 100644
--- a/sys/include/dev/acpi/tables.h
+++ b/sys/include/dev/acpi/tables.h
@@ -118,6 +118,43 @@ struct __packed acpi_gas {
uint64_t address;
};
+/*
+ * ACPI Address Space ID definitions for GAS
+ *
+ * See section 5.2.3.2 of the ACPI software programming
+ * manual.
+ *
+ * XXX: 0x0B->0x7E is reserved as well as 0x80->0xBF
+ * and 0xC0->0xFF is OEM defined. Values other than
+ * the ones specified below are either garbage or
+ * OEM specific values.
+ */
+#define ACPI_GAS_SYSMEM 0x00 /* System memory space */
+#define ACPI_GAS_SYSIO 0x01 /* System I/O space */
+#define ACPI_GAS_PCICONF 0x02 /* PCI configuration space */
+#define ACPI_GAS_EC 0x03 /* Embedded controller */
+#define ACPI_GAS_SMBUS 0x04 /* System management bus */
+#define ACPI_GAS_CMOS 0x05 /* System CMOS */
+#define ACPI_GAS_PCIBAR 0x06 /* PCI BAR target */
+#define ACPI_GAS_IPMI 0x07 /* IPMI (sensor monitoring) */
+#define ACPI_GAS_GPIO 0x08 /* General Purpose I/O */
+#define ACPI_GAS_GSBUS 0x09 /* GenericSerialBus */
+#define ACPI_GAS_PLATCOM 0x0A /* Platform Communications Channel */
+
+/*
+ * ACPI address size definitions for GAS
+ *
+ * See section 5.2.3.2 of the ACPI software programming
+ * manual.
+ *
+ * This is really retarded Intel and Microsoft, thank you.
+ */
+#define ACPI_GAS_UNDEF 0 /* Undefined (legacy reasons) */
+#define ACPI_GAS_BYTE 1 /* Byte access */
+#define ACPI_GAS_WORD 2 /* Word access */
+#define ACPI_GAS_DWORD 3 /* Dword access */
+#define ACPI_GAS_QWORD 4 /* Qword access */
+
struct __packed acpi_hpet {
struct acpi_header hdr;
uint8_t hardware_rev_id;
@@ -132,4 +169,65 @@ struct __packed acpi_hpet {
uint8_t page_protection;
};
+/*
+ * PCIe / ACPI MCFG base address description
+ * table.
+ *
+ * @base_pa: Enhanced configuration base [physical]
+ * @seg_grpno: PCI segment group number
+ * @bus_start: Host bridge bus start
+ * @bus_end: Host bridge bus end
+ */
+struct __packed acpi_mcfg_base {
+ uint64_t base_pa;
+ uint16_t seg_grpno;
+ uint8_t bus_start;
+ uint8_t bus_end;
+ uint32_t reserved;
+};
+
+/*
+ * PCIe / ACPI MCFG structure
+ *
+ * @hdr: ACPI header
+ * @reserved: Do not use
+ * @base: ECAM MMIO address list
+ */
+struct __packed acpi_mcfg {
+ struct acpi_header hdr;
+ uint32_t reserved[2];
+ struct acpi_mcfg_base base[1];
+};
+
+struct __packed dmi_entry32 {
+ char signature[4]; /* _SM_ */
+ uint8_t checksum; /* Sum of table bytes */
+ uint8_t length; /* Length of entry table */
+ uint8_t major; /* DMI major */
+ uint8_t minor; /* DMI minor */
+ uint16_t max_size; /* Max structure size */
+ uint8_t rev; /* Entry revision */
+ char fmt_area[5]; /* Formatted area */
+ char isignature[5]; /* Intermediate signature */
+ uint8_t ichecksum; /* Intermediate checksum */
+ uint16_t table_len; /* Length of SMBIOS structure table */
+ uint32_t addr; /* 32-bit physical start of SMBIOS structure table */
+ uint16_t nstruct; /* Total number of structures */
+ uint8_t bcd_rev;
+};
+
+struct __packed dmi_entry64 {
+ char signature[5]; /* _SM_ */
+ uint8_t checksum; /* Sum of table bytes */
+ uint8_t length; /* Length of entry table */
+ uint8_t major; /* DMI major */
+ uint8_t minor; /* DMI minor */
+ uint8_t docrev;
+ uint8_t entry_rev;
+ uint8_t reserved;
+ uint16_t max_size; /* Max structure size */
+ uint16_t padding;
+ uint64_t addr; /* 64-bit physical address */
+};
+
#endif /* _ACPI_TABLES_H_ */
diff --git a/sys/include/dev/acpi/uacpi/uacpi/internal/namespace.h b/sys/include/dev/acpi/uacpi/uacpi/internal/namespace.h
index 369c5a4..045e402 100644
--- a/sys/include/dev/acpi/uacpi/uacpi/internal/namespace.h
+++ b/sys/include/dev/acpi/uacpi/uacpi/internal/namespace.h
@@ -42,7 +42,6 @@ void uacpi_deinitialize_namespace(void);
uacpi_namespace_node *uacpi_namespace_node_alloc(uacpi_object_name name);
void uacpi_namespace_node_unref(uacpi_namespace_node *node);
-
uacpi_status uacpi_namespace_node_type_unlocked(
const uacpi_namespace_node *node, uacpi_object_type *out_type
);
diff --git a/sys/include/dev/acpi/uacpi/uacpi/platform/config.h b/sys/include/dev/acpi/uacpi/uacpi/platform/config.h
index dff043f..b594338 100644
--- a/sys/include/dev/acpi/uacpi/uacpi/platform/config.h
+++ b/sys/include/dev/acpi/uacpi/uacpi/platform/config.h
@@ -67,7 +67,6 @@ UACPI_BUILD_BUG_ON_WITH_MSG(
*/
// #define UACPI_SIZED_FREES
-
/*
* Makes uacpi_kernel_alloc_zeroed mandatory to implement by the host, uACPI
* will not provide a default implementation if this is enabled.
diff --git a/sys/include/dev/acpi/uacpi/uacpi/utilities.h b/sys/include/dev/acpi/uacpi/uacpi/utilities.h
index dfc41c3..d7042e9 100644
--- a/sys/include/dev/acpi/uacpi/uacpi/utilities.h
+++ b/sys/include/dev/acpi/uacpi/uacpi/utilities.h
@@ -128,7 +128,6 @@ uacpi_status uacpi_eval_cls(uacpi_namespace_node*, uacpi_id_string **out_id);
*/
uacpi_status uacpi_eval_uid(uacpi_namespace_node*, uacpi_id_string **out_uid);
-
// uacpi_namespace_node_info->flags
#define UACPI_NS_NODE_INFO_HAS_ADR (1 << 0)
#define UACPI_NS_NODE_INFO_HAS_HID (1 << 1)
diff --git a/sys/include/dev/cons/ansi.h b/sys/include/dev/cons/ansi.h
new file mode 100644
index 0000000..7a336d1
--- /dev/null
+++ b/sys/include/dev/cons/ansi.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _CONS_ANSI_H_
+#define _CONS_ANSI_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/param.h>
+
+/* ANSI colors */
+#define ANSI_BLACK 0x000000
+#define ANSI_RED 0xAA0000
+#define ANSI_GREEN 0x00AA00
+#define ANSI_BLUE 0x00007F
+#define ANSI_YELLOW 0xAA5500
+#define ANSI_MAGENTA 0xAA00AA
+#define ANSI_CYAN 0x00AAAA
+#define ANSI_WHITE 0xAAAAAA
+
+/* ANSI_FEED update codes */
+#define ANSI_UPDATE_COLOR -1
+#define ANSI_UPDATE_CURSOR -2
+
+/*
+ * ANSI parser state machine.
+ *
+ * @prev: Previous char
+ * @csi: Encountered control seq introducer
+ * @reset_color: 1 if color is to be reset
+ * @set_fg: 1 if fg is being set
+ * @set_bg: 1 if bg is being set
+ * @fg: Foreground color
+ * @bg: Background color
+ * @flags: State flags
+ */
+struct ansi_state {
+ char prev;
+ uint8_t csi : 2;
+ uint8_t reset_color : 1;
+ uint8_t set_fg : 1;
+ uint8_t set_bg : 1;
+ uint32_t fg;
+ uint32_t bg;
+};
+
+int ansi_feed(struct ansi_state *statep, char c);
+
+#endif /* !_CONS_ANSI_H_ */
diff --git a/sys/include/dev/cons/cons.h b/sys/include/dev/cons/cons.h
index 3569c52..7c4e41a 100644
--- a/sys/include/dev/cons/cons.h
+++ b/sys/include/dev/cons/cons.h
@@ -32,8 +32,12 @@
#include <sys/types.h>
#include <sys/spinlock.h>
+#include <sys/proc.h>
+#include <sys/mutex.h>
+#include <sys/console.h>
#include <dev/video/fbdev.h>
#include <dev/cons/consvar.h>
+#include <dev/cons/ansi.h>
struct cons_char {
char c;
@@ -45,6 +49,11 @@ struct cons_char {
struct cons_screen {
struct fbdev fbdev;
+ struct ansi_state ansi_s;
+ struct console_feat feat; /* Features */
+ struct console_attr attr; /* Attributes */
+ struct proc *atproc; /* Attached proc */
+ struct mutex *atproc_lock;
uint32_t fg;
uint32_t bg;
@@ -54,17 +63,25 @@ struct cons_screen {
uint32_t ncols;
uint32_t ch_col; /* Current col */
uint32_t ch_row; /* Current row */
- uint32_t curs_col; /* Cursor col */
- uint32_t curs_row; /* Cursor row */
struct cons_buf *ib; /* Input buffer */
struct cons_buf **ob; /* Output buffers */
struct cons_char last_chr;
struct spinlock lock;
};
+#define curs_col attr.cursor_x
+#define curs_row attr.cursor_y
+
void cons_init(void);
void cons_expose(void);
+void cons_update_color(struct cons_screen *scr, uint32_t fg, uint32_t bg);
+void cons_clear_scr(struct cons_screen *scr, uint32_t bg);
+void cons_reset_color(struct cons_screen *scr);
+void cons_reset_cursor(struct cons_screen *scr);
+int cons_attach(void);
+int cons_detach(void);
int cons_putch(struct cons_screen *scr, char c);
+int cons_putstr(struct cons_screen *scr, const char *s, size_t len);
extern struct cons_screen g_root_scr;
diff --git a/sys/include/dev/dmi/dmi.h b/sys/include/dev/dmi/dmi.h
new file mode 100644
index 0000000..8b7030c
--- /dev/null
+++ b/sys/include/dev/dmi/dmi.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _DMI_DMI_H_
+#define _DMI_DMI_H_
+
+#include <sys/types.h>
+
+const char *dmi_vendor(void);
+const char *dmi_prodver(void);
+const char *dmi_prodfam(void);
+const char *dmi_product(void);
+const char *dmi_cpu_manufact(void);
+const char *dmi_cpu_version(void);
+
+#endif /* !_DMI_DMI_H_ */
diff --git a/sys/include/dev/dmi/dmivar.h b/sys/include/dev/dmi/dmivar.h
new file mode 100644
index 0000000..e5da92f
--- /dev/null
+++ b/sys/include/dev/dmi/dmivar.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _DEV_DMIVAR_H_
+#define _DEV_DMIVAR_H_
+
+#include <sys/types.h>
+#include <sys/sio.h>
+#include <fs/ctlfs.h>
+
+extern struct ctlops g_ctl_board_ident;
+
+int dmi_board_ctl_read(struct ctlfs_dev *cdp, struct sio_txn *sio);
+
+#endif /* !_DEV_DMIVAR_H_ */
diff --git a/sys/include/dev/ic/ahciregs.h b/sys/include/dev/ic/ahciregs.h
index f959a1e..232b41e 100644
--- a/sys/include/dev/ic/ahciregs.h
+++ b/sys/include/dev/ic/ahciregs.h
@@ -88,6 +88,7 @@ struct hba_memspace {
*/
#define AHCI_PXSSTS_DET(SSTS) (SSTS & 0xF)
#define AHCI_PXSSTS_IPM(SSTS) ((SSTS >> 8) & 0xF)
+#define AHCI_PXSSTS_SPD(SSTS) ((SSTS >> 4) & 0xF)
/*
* Port SATA control bits
@@ -100,6 +101,7 @@ struct hba_memspace {
* See section 3.3.7 of the AHCI spec.
*/
#define AHCI_PXCMD_ST BIT(0) /* Start */
+#define AHCI_PXCMD_SUD BIT(1) /* Spin-up device */
#define AHCI_PXCMD_FRE BIT(4) /* FIS Receive Enable */
#define AHCI_PXCMD_FR BIT(14) /* FIS Receive Running */
#define AHCI_PXCMD_CR BIT(15) /* Command List Running */
@@ -137,6 +139,9 @@ struct hba_memspace {
#define AHCI_DET_PRESENT 1 /* Device present (no PHY comm) */
#define AHCI_DET_COMM 3 /* Device present and phy comm established */
#define AHCI_IPM_ACTIVE 1
+#define AHCI_SPD_GEN1 1 /* 1.5 Gb/s */
+#define AHCI_SPD_GEN2 2 /* 3 Gb/s */
+#define AHCI_SPD_GEN3 3 /* 6 Gb/s */
/*
* PxSERR bits
@@ -158,6 +163,8 @@ struct hba_memspace {
#define AHCI_DIAG_T BIT(24) /* Transport state transition error */
#define AHCI_DIAG_F BIT(25) /* Unknown FIS type */
+#define ATAPI_SIG 0xEB140101
+
/*
* Device detection initialization values
* See section 3.3.11 of the AHCI spec.
diff --git a/sys/include/dev/ic/ahcivar.h b/sys/include/dev/ic/ahcivar.h
index a23a654..67f2efe 100644
--- a/sys/include/dev/ic/ahcivar.h
+++ b/sys/include/dev/ic/ahcivar.h
@@ -96,6 +96,7 @@ struct ahci_hba {
* @io: Memory mapped port registers
* @hba: HBA descriptor
* @cmdlist: Command list [p]
+ * @nlba: Max number of addressable blocks
* @fra: FIS receive area [p]
* @dev: Device minor number.
*/
@@ -104,6 +105,7 @@ struct hba_device {
struct ahci_hba *hba;
struct ahci_cmd_hdr *cmdlist;
struct dcdr *dcdr;
+ uint32_t nlba;
void *fra;
dev_t dev;
};
diff --git a/sys/include/dev/ic/nvmevar.h b/sys/include/dev/ic/nvmevar.h
index eab8b52..f361d0a 100644
--- a/sys/include/dev/ic/nvmevar.h
+++ b/sys/include/dev/ic/nvmevar.h
@@ -31,9 +31,11 @@
#define _IC_NVMEVAR_H_
#include <sys/types.h>
+#include <sys/cdefs.h>
/* Admin commands */
#define NVME_OP_CREATE_IOSQ 0x01
+#define NVME_OP_GET_LOGPAGE 0x02
#define NVME_OP_CREATE_IOCQ 0x05
#define NVME_OP_IDENTIFY 0x06
@@ -45,6 +47,67 @@
#define NVME_OP_WRITE 0x01
#define NVME_OP_READ 0x02
+/* Log page identifiers */
+#define NVME_LOGPAGE_SMART 0x02
+
+/*
+ * S.M.A.R.T health / information log
+ *
+ * See section 5.16.1.3, figure 207 of the
+ * NVMe base spec (rev 2.0a)
+ *
+ * @cwarn: Critical warning
+ * @temp: Composite tempature (kelvin)
+ * @avail_spare: Available spare (in percentage)
+ * @avail_spare_thr: Available spare threshold
+ * @percent_used: Estimate NVMe life used percentage
+ * @end_cwarn: Endurance group critical warning summary
+ * @data_units_read: Number of 512 byte data units read
+ * @data_units_written: Number of 512 byte data units written
+ * @host_reads: Number of host read commands completed
+ * @host_writes: Number of host write commands completed
+ * @ctrl_busy_time: Controller busy time
+ * @power_cycles: Number of power cycles
+ * @power_on_hours: Number of power on hours
+ * @unsafe_shutdowns: Number of unsafe shutdowns
+ * @media_errors: Media and data integrity errors
+ * @n_errlog_entries: Number of error log info entries
+ * @warning_temp_time: Warning composite tempature time
+ * @critical_comp_time: Critical composite tempature time
+ * @temp_sensor: Tempature sensor <n> data
+ * @temp1_trans_cnt: Tempature 1 transition count
+ * @temp2_trans_cnt: Tempature 2 transition count
+ * @temp1_total_time: Total time for tempature 1
+ * @temp2_total_time: Total time for tempature 2
+ */
+struct __packed nvme_smart_data {
+ uint8_t cwarn;
+ uint16_t temp;
+ uint8_t avail_spare;
+ uint8_t avail_spare_thr;
+ uint8_t percent_used;
+ uint8_t end_cwarn;
+ uint8_t reserved[25];
+ uint8_t data_units_read[16];
+ uint8_t data_units_written[16];
+ uint8_t host_reads[16];
+ uint8_t host_writes[16];
+ uint8_t ctrl_busy_time[16];
+ uint8_t power_cycles[16];
+ uint8_t power_on_hours[16];
+ uint8_t unsafe_shutdowns[16];
+ uint8_t media_errors[16];
+ uint8_t n_errlog_entries[16];
+ uint32_t warning_temp_time;
+ uint32_t critical_comp_time;
+ uint16_t temp_sensor[8];
+ uint32_t temp1_trans_cnt;
+ uint32_t temp2_trans_cnt;
+ uint32_t temp1_total_time;
+ uint32_t temp2_total_time;
+ uint8_t reserved1[280];
+};
+
struct nvme_identify_cmd {
uint8_t opcode;
uint8_t flags;
@@ -98,6 +161,26 @@ struct nvme_create_iosq_cmd {
uint64_t unused3[2];
};
+/* Get log page */
+struct nvme_get_logpage_cmd {
+ uint8_t opcode;
+ uint8_t flags;
+ uint16_t cid;
+ uint32_t nsid;
+ uint64_t unused[2];
+ uint64_t prp1;
+ uint64_t prp2;
+ uint8_t lid;
+ uint8_t lsp;
+ uint16_t numdl;
+ uint16_t numdu;
+ uint16_t lsi;
+ uint64_t lpo;
+ uint8_t unused1[3];
+ uint8_t csi;
+ uint32_t unused2;
+};
+
/* Read/write */
struct nvme_rw_cmd {
uint8_t opcode;
@@ -117,12 +200,12 @@ struct nvme_rw_cmd {
uint16_t appmask;
};
-
struct nvme_cmd {
union {
struct nvme_identify_cmd identify;
struct nvme_create_iocq_cmd create_iocq;
struct nvme_create_iosq_cmd create_iosq;
+ struct nvme_get_logpage_cmd get_logpage;
struct nvme_rw_cmd rw;
};
};
diff --git a/sys/include/dev/mii/mii.h b/sys/include/dev/mii/mii.h
new file mode 100644
index 0000000..5d77281
--- /dev/null
+++ b/sys/include/dev/mii/mii.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _DEV_MII_H_
+#define _DEV_MII_H_
+
+#include <sys/param.h>
+
+/*
+ * MII registers
+ */
+#define MII_BMCR 0x00 /* Basic Mode Config */
+#define MII_BMSR 0x01 /* Basic Mode Status */
+#define MII_PHYID 0x02 /* MII PHY identifier 1 */
+#define MII_PHYID2 0x03 /* MII PHY identifier 2 */
+#define MII_ADVER 0x04 /* Auto-negotiation advertisement */
+#define MII_LPA 0x05 /* Link parter abilities */
+#define MII_EXPAN 0x06 /* Auto-negotiation expansion */
+#define MII_ESTATUS 0x0F /* Extended status register */
+#define MII_IRQ 0x1B /* Interrupt control/status */
+
+/*
+ * MII BMCR bits
+ */
+#define MII_BMCR_RST BIT(15) /* PHY reset */
+#define MII_BCMR_LOOP BIT(14) /* Loopback mode enable */
+#define MII_BMCR_ANEN BIT(12) /* Auto-negotiation enable */
+#define MII_PWR_DOWN BIT(11) /* Power down PHY */
+#define MII_ISOLATE BIT(10) /* Electrically isolate PHY from MII */
+
+#endif /* !_DEV_MII_H_ */
diff --git a/sys/include/dev/pci/pci.h b/sys/include/dev/pci/pci.h
index a4de162..144b500 100644
--- a/sys/include/dev/pci/pci.h
+++ b/sys/include/dev/pci/pci.h
@@ -62,6 +62,7 @@ struct pci_device {
uint8_t pci_subclass;
uint8_t prog_if;
uint8_t hdr_type;
+ uint8_t pci_express : 1;
uint8_t pri_bus;
uint8_t sec_bus;
diff --git a/sys/include/dev/phy/e1000regs.h b/sys/include/dev/phy/e1000regs.h
new file mode 100644
index 0000000..7caceee
--- /dev/null
+++ b/sys/include/dev/phy/e1000regs.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _PHY_E1000_REGS_H_
+#define _PHY_E1000_REGS_H_
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+/*
+ * E1000 register offsets
+ *
+ * XXX: Notes about reserve fields:
+ *
+ * - The `EERD' register is reserved and should NOT be touched
+ * for the 82544GC/EI card.
+ *
+ * - The `FLA' register is only usable for the 82541xx and
+ * 82547GI/EI cards, this is reserved and should NOT be
+ * touched on any other cards.
+ *
+ * - The `TXCW' and `RXCW' registers are reserved and should NOT
+ * be touched for the 82540EP/EM, 82541xx and 82547GI/EI cards.
+ *
+ * - The `LEDCTL' register is reserved and should NOT be touched
+ * for the 82544GC/EI card.
+ */
+#define E1000_CTL 0x00000 /* Control register */
+#define E1000_STATUS 0x00008 /* Status register */
+#define E1000_EECD 0x00010 /* EEPROM/flash control and data register */
+#define E1000_EERD 0x00014 /* EEPROM/flash read register */
+#define E1000_FLA 0x0001C /* EEPROM/flash read register */
+#define E1000_CTRL_EXT 0x00018 /* Extended device control register */
+#define E1000_MDIC 0x00020 /* PHY management data interface control register */
+#define E1000_FCAL 0x00028 /* Flow control low register */
+#define E1000_FCAH 0x0002C /* Flow control high register */
+#define E1000_FCT 0x00030 /* Flow control type register */
+#define E1000_VET 0x00038 /* VLAN ethertype register */
+#define E1000_FCTTV 0x00170 /* Flow control transmit timer value register */
+#define E1000_TXCW 0x00178 /* Transmit config word register */
+#define E1000_RXCW 0x00180 /* Receive config word register */
+#define E1000_LEDCTL 0x00E00 /* LED control register */
+
+/*
+ * Device control register (`ctl') bits
+ *
+ * See section 13.4.1 of the PCI/PCI-X Intel Gigabit
+ * Ethernet Controllers spec
+ *
+ * XXX: Notes about reserved bits:
+ *
+ * - The CTL.LRST bit is reserved and should NOT be touched
+ * for the 82540EP/EM, 82541xx, or 82547GI/EI cards.
+ */
+#define E1000_CTL_FD BIT(0) /* Full-duplex */
+#define E1000_CTL_LRST BIT(3) /* Link-reset */
+#define E1000_CTL_RST BIT(26) /* Device reset */
+
+/*
+ * EEPROM/flash control and data register (`eecd')
+ * bits
+ *
+ * See section 13.4.3 of the PCI/PCI-X Intel Gigabit
+ * Ethernet controller spec
+ */
+#define E1000_EECD_SK BIT(0) /* EEPROM clock input */
+#define E1000_EECD_CS BIT(1) /* EEPROM chip select */
+#define E1000_EECD_DI BIT(2) /* EEPROM data input */
+#define E1000_EECD_DO BIT(3) /* EEPROM data output */
+#define E1000_EECD_FWE BIT(4) /* EEPROM flash write enable ctl (4:5) */
+#define E1000_EECD_REQ BIT(6) /* Request EEPROM access */
+#define E1000_EECD_GNT BIT(7) /* Grant EEPROM access */
+#define E1000_EECD_PRES BIT(8) /* EEPROM present */
+#define E1000_EECD_SIZE BIT(9) /* EEPROM size (1024-bit [0], 4096-bit [1]) */
+#define E1000_EECD_TYPE BIT(13) /* EEPROM type (microwire [0], SPI [1]) */
+
+/*
+ * EEPROM read (`eerd') register bits
+ *
+ * See section 13.4.4 of the PCI/PCI-X Intel Gigabit
+ * Ethernet controller spec
+ */
+#define E1000_EERD_START BIT(0) /* Start read */
+#define E1000_EERD_DONE BIT(4) /* EEPROM read finished */
+
+/*
+ * EEPROM word addresses
+ */
+#define E1000_HWADDR0 0x00 /* Word 0 */
+#define E1000_HWADDR1 0x01 /* Word 1 */
+#define E1000_HWADDR2 0x02 /* Word 2 */
+
+#endif /* !_PHY_E1000_REGS_H_ */
diff --git a/sys/include/dev/phy/et131xregs.h b/sys/include/dev/phy/et131xregs.h
new file mode 100644
index 0000000..1f8bfcb
--- /dev/null
+++ b/sys/include/dev/phy/et131xregs.h
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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.
+ */
+
+/*
+ * Please refer to share/docs/hw/et131x.txt
+ */
+
+#ifndef _PHYS_ET131XREGS_H_
+#define _PHYS_ET131XREGS_H_
+
+#include <sys/types.h>
+
+#define MAC_CFG1_SOFTRST 0x80000000 /* Soft reset */
+#define MAC_CFG1_SIMRST 0x40000000 /* SIM reset */
+#define MAC_CFG1_RESET_RXMC 0x00080000 /* RX MC reset */
+#define MAC_CFG1_RESET_TXMC 0x00040000 /* TX MC reset */
+#define MAC_CFG1_RESET_RXFUNC 0x00020000 /* RX func reset */
+#define MAC_CFG1_RESET_TXFUNC 0x00010000 /* TX func reset */
+
+#define PAD_N(N, NAME) uint8_t (NAME)[(N)]
+
+/*
+ * ET131X global registers
+ */
+struct global_regs {
+ uint32_t txq_start;
+ uint32_t txq_end;
+ uint32_t rxq_start;
+ uint32_t rxq_end;
+ uint32_t pm_csr;
+ uint32_t unused;
+ uint32_t istat;
+ uint32_t imask;
+ uint32_t ialias_clr_en;
+ uint32_t istat_alias;
+ uint32_t sw_reset;
+ uint32_t slv_timer;
+ uint32_t msi_config;
+ uint32_t loopback;
+ uint32_t watchdog_timer;
+};
+
+/*
+ * ET131X TX DMA registers
+ */
+struct txdma_regs {
+ uint32_t csr;
+ uint32_t pr_base_hi;
+ uint32_t pr_base_lo;
+ uint32_t pr_num_des;
+ uint32_t txq_wr_addr;
+ uint32_t txq_wr_addr_ext;
+ uint32_t txq_rd_addr;
+ uint32_t dma_wb_base_hi;
+ uint32_t dma_wb_base_lo;
+ uint32_t service_request;
+ uint32_t service_complete;
+ uint32_t cache_rd_index;
+ uint32_t cache_wr_index;
+ uint32_t tx_dma_error;
+ uint32_t des_abort_cnt;
+ uint32_t payload_abort_cnt;
+ uint32_t wb_abort_cnt;
+ uint32_t des_timeout_cnt;
+ uint32_t payload_timeout_cnt;
+ uint32_t wb_timeout_cnt;
+ uint32_t des_error_cnt;
+ uint32_t payload_err_cnt;
+ uint32_t wb_error_cnt;
+ uint32_t dropped_tlp_cnt;
+ uint32_t new_service_complete;
+ uint32_t ether_pkt_cnt;
+};
+
+/*
+ * ET131X RX DMA registers
+ */
+struct rxdma_regs {
+ uint32_t csr;
+ uint32_t dma_wb_base_lo;
+ uint32_t dma_wb_base_hi;
+ uint32_t num_pkt_done;
+ uint32_t max_pkt_time;
+ uint32_t rxq_rd_addr;
+ uint32_t rxq_rd_addr_ext;
+ uint32_t rxq_wr_addr;
+ uint32_t psr_base_lo;
+ uint32_t psr_base_hi;
+ uint32_t psr_num_des;
+ uint32_t psr_avail_offset;
+ uint32_t psr_full_offset;
+ uint32_t psr_access_index;
+ uint32_t psr_min_des;
+ uint32_t fbr0_base_lo;
+ uint32_t fbr0_base_hi;
+ uint32_t fbr0_num_des;
+ uint32_t fbr0_avail_offset;
+ uint32_t fbr0_full_offset;
+ uint32_t fbr0_rd_index;
+ uint32_t fbr0_min_des;
+ uint32_t fbr1_base_lo;
+ uint32_t fbr1_base_hi;
+ uint32_t fbr1_num_des;
+ uint32_t fbr1_avail_offset;
+ uint32_t fbr1_full_offset;
+ uint32_t fbr1_rd_index;
+ uint32_t fbr1_min_des;
+};
+
+/*
+ * ET131X TX MAC registers
+ */
+struct txmac_regs {
+ uint32_t ctl;
+ uint32_t shadow_ptr;
+ uint32_t err_cnt;
+ uint32_t max_fill;
+ uint32_t cf_param;
+ uint32_t tx_test;
+ uint32_t err;
+ uint32_t err_int;
+ uint32_t bp_ctrl;
+};
+
+/*
+ * ET131X RX MAC registers
+ */
+struct rxmac_regs {
+ uint32_t ctrl;
+ uint32_t crc0;
+ uint32_t crc12;
+ uint32_t crc34;
+ uint32_t sa_lo;
+ uint32_t sa_hi;
+ uint32_t mask0_word0;
+ uint32_t mask0_word1;
+ uint32_t mask0_word2;
+ uint32_t mask0_word3;
+ uint32_t mask1_word0;
+ uint32_t mask1_word1;
+ uint32_t mask1_word2;
+ uint32_t mask1_word3;
+ uint32_t mask2_word0;
+ uint32_t mask2_word1;
+ uint32_t mask2_word2;
+ uint32_t mask2_word3;
+ uint32_t mask3_word0;
+ uint32_t mask3_word1;
+ uint32_t mask3_word2;
+ uint32_t mask3_word3;
+ uint32_t mask4_word0;
+ uint32_t mask4_word1;
+ uint32_t mask4_word2;
+ uint32_t mask4_word3;
+ uint32_t uni_pf_addr1;
+ uint32_t uni_pf_addr2;
+ uint32_t uni_pf_addr3;
+ uint32_t multi_hash1;
+ uint32_t multi_hash2;
+ uint32_t multi_hash3;
+ uint32_t multi_hash4;
+ uint32_t pf_ctrl;
+ uint32_t mcif_ctrl_max_seg;
+ uint32_t mcif_water_mark;
+ uint32_t rxq_diag;
+ uint32_t space_avail;
+ uint32_t mif_ctrl;
+ uint32_t err_reg;
+};
+
+struct mac_regs {
+ uint32_t cfg1;
+ uint32_t cfg2;
+ uint32_t ipg;
+ uint32_t hfdp;
+ uint32_t max_fm_len;
+ uint32_t rsv1;
+ uint32_t rsv2;
+ uint32_t mac_test;
+ uint32_t mii_mgmt_cfg;
+ uint32_t mii_mgmt_cmd;
+ uint32_t mii_mgmt_addr;
+ uint32_t mii_mgmt_ctrl;
+ uint32_t mii_mgmt_stat;
+ uint32_t mii_mgmt_indicator;
+ uint32_t if_ctrl;
+ uint32_t if_stat;
+ uint32_t station_addr_1;
+ uint32_t station_addr_2;
+};
+
+/* Global reset */
+#define GBL_RESET_ALL 0x007F
+
+/* MII management address */
+#define MAC_MII_ADDR(PHY, REG) ((PHY) << 8 | (REG))
+
+/* MAC management indications */
+#define MAC_MGMT_BUSY 0x00000001
+#define MAC_MGMT_WAIT 0x00000005
+
+/* MAC management config values */
+#define MAC_MIIMGMT_CLK_RST 0x00007
+
+/* LED register defines */
+#define PHY_LED2 0x1C
+
+/* PCI config space offsets */
+#define PCI_EEPROM_STATUS 0xB2
+#define PCI_MAC_ADDRESS 0xA4
+
+/*
+ * LED control register 2 values
+ */
+#define LED_BLINK 0xD
+#define LED_ON 0xE
+#define LED_OFF 0xF
+#define LED_ALL_OFF 0xFFFF
+
+/*
+ * LED register bit-shift constants
+ *
+ * Bits [3:0]: 100BASE-T LED
+ * Bits [7:4]: 100BASE-TX LED
+ * Bits [11:8]: TX/RX LED
+ * Bits [15:12]: Link LED
+ */
+#define LED_TXRX_SHIFT 8
+#define LED_LINK_SHIFT 12
+
+struct et131x_iospace {
+#define _IO_PAD(NAME, REGSET) uint8_t NAME[4096 - sizeof(struct REGSET)]
+ struct global_regs global;
+ _IO_PAD(global_pad, global_regs);
+ struct txdma_regs txdma;
+ _IO_PAD(txdma_pad, txdma_regs);
+ struct rxdma_regs rxdma;
+ _IO_PAD(rxdma_pad, rxdma_regs);
+ struct txmac_regs txmac;
+ _IO_PAD(txmac_pad, txmac_regs);
+ struct rxmac_regs rxmac;
+ _IO_PAD(rxmac_pad, rxmac_regs);
+ struct mac_regs mac;
+ _IO_PAD(mac_pad, mac_regs);
+ /* ... TODO - add more */
+#undef _IO_PAD
+};
+
+#endif /* !_PHYS_ET131XREGS_H_ */
diff --git a/sys/include/dev/phy/rt8139.h b/sys/include/dev/phy/rtl.h
index 21c7d54..f3178d0 100644
--- a/sys/include/dev/phy/rt8139.h
+++ b/sys/include/dev/phy/rtl.h
@@ -71,6 +71,9 @@
#define RT_AS_LPAR 0x68 /* Auto-negotiation link partner reg (16 bits) */
#define RT_AS_EXPANSION 0x6A /* Auto-negotiation expansion reg (16 bits) */
+#define RT_TXAD_N(N) (RT_TXADDR0 + (N))
+#define RT_TXSTATUS_N(N) (RT_TXSTATUS0 + ((N)))
+
/* Command register bits */
#define RT_BUFEN BIT(0) /* Buffer empty */
#define RT_TE BIT(2) /* Transmitter enable */
diff --git a/sys/include/dev/random/entropy.h b/sys/include/dev/random/entropy.h
new file mode 100644
index 0000000..34d86df
--- /dev/null
+++ b/sys/include/dev/random/entropy.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 <stdint.h>
+
+#define ENTROPY_POOL_SIZE 32
+
+struct entropy_pool {
+ uint8_t pool[ENTROPY_POOL_SIZE];
+ uint32_t entropy_bits;
+};
+
+void mix_entropy(struct entropy_pool *ep, const uint8_t *input,
+ size_t input_len, uint32_t input_entropy_bits);
diff --git a/sys/include/dev/timer.h b/sys/include/dev/timer.h
index e54adcc..2ca6d62 100644
--- a/sys/include/dev/timer.h
+++ b/sys/include/dev/timer.h
@@ -31,11 +31,15 @@
#define _DEV_TIMER_H_
#include <sys/types.h>
+#include <sys/param.h>
/* Timer IDs */
#define TIMER_SCHED 0x00000000U /* Scheduler reserved timer */
#define TIMER_GP 0x00000001U /* General purpose timer */
+/* Timer flags */
+#define TIMER_MONOTONIC BIT(0)
+
/* Number of timer IDs, adjust when adding timer IDs */
#define TIMER_ID_COUNT 2
@@ -69,6 +73,7 @@ struct timer {
const char *name; /* e.g "HPET" */
size_t(*calibrate)(void); /* Returns frequency, 0 for unspecified */
size_t(*get_time_usec)(void); /* Time since init (microseconds) */
+ size_t(*get_time_nsec)(void); /* Time since init (nanoseconds) */
size_t(*get_time_sec)(void); /* Time since init (seconds) */
int(*msleep)(size_t ms);
int(*usleep)(size_t us);
@@ -78,6 +83,7 @@ struct timer {
void(*oneshot_ms)(size_t ms);
void(*oneshot_us)(size_t ms);
void(*stop)(void);
+ uint8_t flags;
};
tmrr_status_t register_timer(timer_id_t id, const struct timer *tmr);
diff --git a/sys/include/dev/usb/xhciregs.h b/sys/include/dev/usb/xhciregs.h
index 1cbfd14..cafd7c9 100644
--- a/sys/include/dev/usb/xhciregs.h
+++ b/sys/include/dev/usb/xhciregs.h
@@ -77,6 +77,7 @@ struct xhci_opregs {
/* USBSTS bits */
#define USBSTS_HCH BIT(0) /* HC halted */
+#define USBSTS_CNR BIT(11) /* Controller not ready */
/* CAPS.HCSPARAMS1 fields */
#define XHCI_MAXSLOTS(HCSPARAMS1) (HCSPARAMS1 & 0xFF)
diff --git a/sys/include/dev/video/fbdev.h b/sys/include/dev/video/fbdev.h
index c80fd92..c9fec94 100644
--- a/sys/include/dev/video/fbdev.h
+++ b/sys/include/dev/video/fbdev.h
@@ -52,5 +52,6 @@ fbdev_get_index(const struct fbdev *fbdev, uint32_t x, uint32_t y)
}
struct fbdev fbdev_get(void);
+void fbdev_init_dev(void);
#endif /* !_DEV_FBDEV_H_ */
diff --git a/sys/include/fs/ctlfs.h b/sys/include/fs/ctlfs.h
index 90f42f0..29ae358 100644
--- a/sys/include/fs/ctlfs.h
+++ b/sys/include/fs/ctlfs.h
@@ -42,12 +42,10 @@ struct ctlops {
/*
* Ctlfs op arguments
*
- * @devname: Device name.
- * @major: Device major
- * @minor: Device minor.
- * @mode: Access flags.
* @devname [1]: Device name (node name)
* @ctlname: [1]: Control name (node entry name)
+ * @ops: Callbacks / fs hooks
+ * @mode: Access flags.
*/
struct ctlfs_dev {
union {
diff --git a/sys/include/fs/devfs.h b/sys/include/fs/devfs.h
index 012c2eb..51b0b45 100644
--- a/sys/include/fs/devfs.h
+++ b/sys/include/fs/devfs.h
@@ -33,9 +33,11 @@
#include <sys/vnode.h>
#include <sys/types.h>
#include <sys/device.h>
+#include <sys/devstat.h>
extern const struct vops g_devfs_vops;
int devfs_create_entry(const char *name, devmajor_t major, dev_t dev, mode_t mode);
+int devfs_devstat(struct vnode *vp, struct devstat *res);
#endif /* !_FS_DEVFS_H_ */
diff --git a/sys/include/fs/tmpfs.h b/sys/include/fs/tmpfs.h
new file mode 100644
index 0000000..acb5256
--- /dev/null
+++ b/sys/include/fs/tmpfs.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _FS_TMPFS_H_
+#define _FS_TMPFS_H_
+
+#include <sys/types.h>
+#include <sys/limits.h>
+#include <sys/vnode.h>
+#include <sys/queue.h>
+#include <sys/spinlock.h>
+#include <vm/vm_obj.h>
+
+extern const struct vops g_tmpfs_vops;
+
+/* Tmpfs node types */
+#define TMPFS_NONE (VNON) /* No type */
+#define TMPFS_REG (VREG) /* Regular file [f] */
+#define TMPFS_DIR (VDIR) /* Directory [d] */
+
+struct tmpfs_node;
+
+/*
+ * A tmpfs node represents an object within the
+ * tmpfs namespace such as a file, directory, etc.
+ *
+ * @rpath: /tmp/ relative path (for lookups)
+ * @type: The tmpfs node type [one-to-one to vtype]
+ * @len: Length of buffer
+ * @real_size: Actual size of file
+ * @data: The backing file data
+ * @mode: File permissions
+ * @dirvp: Vnode of the parent node
+ * @vp: Vnode of the current node
+ * @lock: Lock protecting this node
+ */
+struct tmpfs_node {
+ char rpath[PATH_MAX];
+ uint8_t type;
+ size_t len;
+ size_t real_size;
+ void *data;
+ mode_t mode;
+ struct vnode *dirvp;
+ struct vnode *vp;
+ struct spinlock lock;
+ TAILQ_HEAD(, tmpfs_node) dirents;
+ TAILQ_ENTRY(tmpfs_node) link;
+};
+
+#endif /* !_FS_TMPFS_H_ */
diff --git a/sys/include/lib/crc32.h b/sys/include/lib/crc32.h
new file mode 100644
index 0000000..a7e5eeb
--- /dev/null
+++ b/sys/include/lib/crc32.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _LIB_CRC32_H_
+#define _LIB_CRC32_H_
+
+#include <sys/types.h>
+
+uint32_t crc32(const void *data, size_t len);
+
+#endif
diff --git a/sys/include/lib/string.h b/sys/include/lib/string.h
index c09e6f4..3255ae5 100644
--- a/sys/include/lib/string.h
+++ b/sys/include/lib/string.h
@@ -35,6 +35,7 @@
size_t strlen(const char *s);
char *itoa(int64_t value, char *buf, int base);
+char *strdup(const char *s);
int vsnprintf(char *s, size_t size, const char *fmt, va_list ap);
int snprintf(char *s, size_t size, const char *fmt, ...);
diff --git a/sys/include/net/ethertypes.h b/sys/include/net/ethertypes.h
new file mode 100644
index 0000000..753ea10
--- /dev/null
+++ b/sys/include/net/ethertypes.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _NET_ETHERTYPES_H_
+#define _NET_ETHERTYPES_H_
+
+#define ETHERTYPE_IPV4 0x0800
+#define ETHERTYPE_ARP 0x0806
+
+#endif /* !_NET_ETHERTYPES_H_ */
diff --git a/sys/include/net/if_arp.h b/sys/include/net/if_arp.h
new file mode 100644
index 0000000..cbfb2fe
--- /dev/null
+++ b/sys/include/net/if_arp.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _NETINET_IF_ARP_H_
+#define _NETINET_IF_ARP_H_
+
+#include <sys/types.h>
+#include <net/ethertypes.h>
+
+/* ARP hardware types */
+#define ARP_HWTYPE_ETHER 1
+
+/* ARP operation types */
+#define ARP_REQUEST 1
+#define ARP_REPLY 2
+
+struct arp_hdr {
+ uint16_t hw_type; /* See ARP_HWTYPE_* */
+ uint16_t proto_type; /* See ETHERTYPE_* */
+ uint8_t hw_len; /* See ETHER_ADDR_LEN */
+ uint8_t proto_len; /* Protocol address length */
+ uint16_t op_type; /* See operation types above */
+};
+
+#endif /* !_NETINET_IF_ARP_H_ */
diff --git a/sys/include/net/if_var.h b/sys/include/net/if_var.h
new file mode 100644
index 0000000..e032ff4
--- /dev/null
+++ b/sys/include/net/if_var.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _NET_IF_VAR_H_
+#define _NET_IF_VAR_H_
+
+#include <sys/queue.h>
+#include <sys/types.h>
+#include <net/if.h>
+#include <net/netbuf.h>
+
+#define NETIF_ADDR_LEN 32 /* In bytes */
+
+/* Return values for netif hooks */
+#define NETIF_ENQ_OK 0 /* Enqueued */
+#define NETIF_ENQ_FLUSHED 1 /* Internal queue flushed */
+
+/* Interface types */
+#define NETIF_TYPE_ANY 0 /* Any type */
+#define NETIF_TYPE_WIRE 1 /* Ethernet */
+
+/*
+ * Represents the address of a network
+ * interface.
+ *
+ * @data: Raw address bytes
+ */
+struct netif_addr {
+ uint8_t data[NETIF_ADDR_LEN];
+};
+
+/*
+ * Represents a network interface
+ *
+ * @name: Interface name
+ * @type: Interface type (see NETIF_TYPE*)
+ * @tx_enq: Enqueue a packet
+ * @tx_start: Start a packet
+ *
+ * XXX: tx_enq() returns 0 on success and 1 if a flush was needed
+ * and the packets have been transmitted. Less than zero values
+ * indicate failure.
+ */
+struct netif {
+ char name[IFNAMESIZ];
+ uint8_t type;
+ TAILQ_ENTRY(netif) link;
+ struct netif_addr addr;
+ int(*tx_enq)(struct netif *nifp, struct netbuf *nbp, void *data);
+ void(*tx_start)(struct netif *nifp);
+};
+
+void netif_add(struct netif *nifp);
+int netif_lookup(const char *name, uint8_t type, struct netif **res);
+
+#endif /* !_NET_IF_VAR_H_ */
diff --git a/sys/include/net/netbuf.h b/sys/include/net/netbuf.h
new file mode 100644
index 0000000..7067370
--- /dev/null
+++ b/sys/include/net/netbuf.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _NET_NETBUF_H_
+#define _NET_NETBUF_H_
+
+#include <sys/types.h>
+
+#define NETBUF_LEN 256
+
+struct netbuf {
+ char data[NETBUF_LEN];
+ size_t len;
+};
+
+#endif /* !_NET_NETBUF_H_ */
diff --git a/sys/include/netinet/if_ether.h b/sys/include/netinet/if_ether.h
new file mode 100644
index 0000000..d3dc9b7
--- /dev/null
+++ b/sys/include/netinet/if_ether.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _NETINET_IF_ETHER_H_
+#define _NETINET_IF_ETHER_H_
+
+#include <sys/types.h>
+#include <net/if_arp.h>
+#include <net/if_var.h>
+
+#define ETHER_ADDR_LEN 6
+
+struct ether_arp {
+ struct arp_hdr hdr;
+ uint8_t sha[ETHER_ADDR_LEN];
+ uint8_t spa[4];
+ uint8_t tha[ETHER_ADDR_LEN];
+ uint8_t tpa[4];
+};
+
+struct ether_frame {
+ uint8_t ether_daddr[ETHER_ADDR_LEN];
+ uint8_t ether_saddr[ETHER_ADDR_LEN];
+ uint16_t ether_type;
+};
+
+int arp_request(struct netif *nifp, uint8_t *sproto, uint8_t *tproto);
+int arp_reply(struct netif *netif, uint8_t *sproto, uint8_t *tproto);
+
+#endif /* !_NETINET_IF_ETHER_H_ */
diff --git a/sys/include/sys/atomic.h b/sys/include/sys/atomic.h
index f61bf62..d9b3bde 100644
--- a/sys/include/sys/atomic.h
+++ b/sys/include/sys/atomic.h
@@ -30,6 +30,8 @@
#ifndef _SYS_ATOMIC_H_
#define _SYS_ATOMIC_H_
+#include <sys/types.h>
+
static inline unsigned long
atomic_add_long_nv(volatile unsigned long *p, unsigned long v)
{
@@ -42,6 +44,12 @@ atomic_add_int_nv(volatile unsigned int *p, unsigned int v)
return __sync_add_and_fetch(p, v);
}
+static inline unsigned int
+atomic_add_64_nv(volatile uint64_t *p, unsigned int v)
+{
+ return __sync_add_and_fetch(p, v);
+}
+
static inline unsigned long
atomic_sub_long_nv(volatile unsigned long *p, unsigned long v)
{
@@ -55,6 +63,12 @@ atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
}
static inline unsigned int
+atomic_sub_64_nv(volatile uint64_t *p, unsigned int v)
+{
+ return __sync_sub_and_fetch(p, v);
+}
+
+static inline unsigned int
atomic_load_int_nv(volatile unsigned int *p, unsigned int v)
{
return __atomic_load_n(p, v);
@@ -66,6 +80,12 @@ atomic_load_long_nv(volatile unsigned long *p, unsigned int v)
return __atomic_load_n(p, v);
}
+static inline unsigned int
+atomic_load_64_nv(volatile uint64_t *p, unsigned int v)
+{
+ return __atomic_load_n(p, v);
+}
+
static inline void
atomic_store_int_nv(volatile unsigned int *p, int nv, unsigned int v)
{
@@ -78,20 +98,30 @@ atomic_store_long_nv(volatile unsigned long *p, long nv, unsigned int v)
__atomic_store_n(p, nv, v);
}
+static inline void
+atomic_store_64_nv(volatile uint64_t *p, long nv, unsigned int v)
+{
+ __atomic_store_n(p, nv, v);
+}
+
/* Atomic increment (and fetch) operations */
#define atomic_inc_long(P) atomic_add_long_nv((P), 1)
#define atomic_inc_int(P) atomic_add_int_nv((P), 1)
+#define atomic_inc_64(P) atomic_add_64_nv((P), 1)
/* Atomic decrement (and fetch) operations */
#define atomic_dec_long(P) atomic_sub_long_nv((P), 1)
#define atomic_dec_int(P) atomic_sub_int_nv((P), 1)
+#define atomic_dec_64(P) atomic_sub_64_nv((P), 1)
/* Atomic load operations */
#define atomic_load_int(P) atomic_load_int_nv((P), __ATOMIC_SEQ_CST)
#define atomic_load_long(P) atomic_load_long_nv((P), __ATOMIC_SEQ_CST)
+#define atomic_load_64(P) atomic_load_64_nv((P), __ATOMIC_SEQ_CST)
/* Atomic store operations */
#define atomic_store_int(P, NV) atomic_store_int_nv((P), (NV), __ATOMIC_SEQ_CST)
#define atomic_store_long(P, NV) atomic_store_long_nv((P), (NV), __ATOMIC_SEQ_CST)
+#define atomic_store_64(P, NV) atomic_store_64_nv((P), (NV), __ATOMIC_SEQ_CST)
#endif /* !_SYS_ATOMIC_H_ */
diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h
index 61106fa..725193e 100644
--- a/sys/include/sys/cdefs.h
+++ b/sys/include/sys/cdefs.h
@@ -42,7 +42,9 @@
#define __dead __attribute__((__noreturn__))
#define __cold __attribute__((__cold__))
#define __dead_cold __attribute__((__noreturn__, __cold__))
+#define __aligned(n) __attribute__((__aligned__((n))))
#define __unused __attribute__((__unused__))
+#define __used __attribute__((__used__))
#define __nothing ((void)0)
#define __likely(exp) __builtin_expect(((exp) != 0), 1)
#define __unlikely(exp) __builtin_expect(((exp) != 0), 0)
diff --git a/sys/include/net/if_ether.h b/sys/include/sys/console.h
index a8fcfa5..d0b89a8 100644
--- a/sys/include/net/if_ether.h
+++ b/sys/include/sys/console.h
@@ -27,48 +27,31 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _IF_ETHER_H_
-#define _IF_ETHER_H_
+#ifndef _SYS_CONSOLE_H_
+#define _SYS_CONSOLE_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
-#include <net/if.h>
-
-#define MACADDR_LEN 6
-
-struct __packed ether_frame {
- uint8_t sync[7]; /* Preamble (sync stuff) */
- uint8_t spd; /* Start frame delimiter */
- uint8_t macd[6]; /* MAC destination */
- uint8_t macs[6]; /* MAC source */
- uint16_t type; /* Protocol type */
- char payload[1]; /* sized @ 1+n */
-};
/*
- * Used by the driver to buffer packets.
+ * Console features
+ *
+ * @ansi_esc: If 1, ANSI escape codes are enabled
+ * @show_curs: If 1, show the cursor
*/
-struct etherbuf {
- struct ether_frame *frp;
- off_t head;
- off_t tail;
- size_t cap; /* In entries */
+struct console_feat {
+ uint8_t ansi_esc : 1;
+ uint8_t show_curs : 1;
};
/*
- * Ethernet device
- *
- * if_ether: E
- * driver: D
+ * Console attributes
*
- * @if_name: Interface name.
- * @tx: Transmit packets (D->E)
+ * @cursor_x: Cursor x position
+ * @cursor_y: Cursor y position
*/
-struct etherdev {
- char if_name[IFNAMESIZ];
- struct etherbuf *buf;
- ssize_t(*tx)(struct etherdev *ep, const void *buf, size_t len);
- char mac_addr[MACADDR_LEN];
+struct console_attr {
+ uint32_t cursor_x;
+ uint32_t cursor_y;
};
-#endif /* !_IF_ETHER_H_ */
+#endif /* !_SYS_CONSOLE_H_ */
diff --git a/sys/include/sys/device.h b/sys/include/sys/device.h
index f5f92ad..04b66fc 100644
--- a/sys/include/sys/device.h
+++ b/sys/include/sys/device.h
@@ -36,21 +36,28 @@
#include <sys/queue.h>
#include <sys/proc.h>
#include <sys/sio.h>
+#include <vm/vm_obj.h>
typedef uint8_t devmajor_t;
/* Device operation typedefs */
typedef int(*dev_read_t)(dev_t, struct sio_txn *, int);
typedef int(*dev_write_t)(dev_t, struct sio_txn *, int);
+typedef int(*dev_bsize_t)(dev_t);
struct cdevsw {
int(*read)(dev_t dev, struct sio_txn *sio, int flags);
int(*write)(dev_t dev, struct sio_txn *sio, int flags);
+ paddr_t(*mmap)(dev_t dev, size_t size, off_t off, int flags);
+
+ /* Private */
+ struct vm_object vmobj;
};
struct bdevsw {
int(*read)(dev_t dev, struct sio_txn *sio, int flags);
int(*write)(dev_t dev, struct sio_txn *sio, int flags);
+ int(*bsize)(dev_t dev);
};
void *dev_get(devmajor_t major, dev_t dev);
@@ -61,10 +68,12 @@ int dev_register(devmajor_t major, dev_t dev, void *devsw);
int dev_noread(void);
int dev_nowrite(void);
+int dev_nobsize(void);
/* Device operation stubs */
#define noread ((dev_read_t)dev_noread)
#define nowrite ((dev_write_t)dev_nowrite)
+#define nobsize ((dev_bsize_t)dev_nobsize)
#endif /* _KERNEL */
#endif /* !_SYS_DEVICE_H_ */
diff --git a/sys/include/sys/devstat.h b/sys/include/sys/devstat.h
new file mode 100644
index 0000000..91af30f
--- /dev/null
+++ b/sys/include/sys/devstat.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_DEVSTAT_H_
+#define _SYS_DEVSTAT_H_
+
+#include <sys/types.h>
+
+/*
+ * Stats for block devices
+ *
+ * @nwrites: Number of writes total
+ * @nreads: Number of reads total
+ */
+struct devstat {
+ size_t nwrites;
+ size_t nreads;
+};
+
+#endif /* !_SYS_DEVSTAT_H_ */
diff --git a/sys/include/sys/disk.h b/sys/include/sys/disk.h
new file mode 100644
index 0000000..4ad068b
--- /dev/null
+++ b/sys/include/sys/disk.h
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_DISK_H_
+#define _SYS_DISK_H_
+
+#include <sys/syscall.h>
+#include <sys/queue.h>
+#include <sys/device.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/limits.h>
+#include <sys/cdefs.h>
+#if defined(_KERNEL)
+#include <dev/dcdr/cache.h>
+#endif /* _KERNEL */
+
+#define DISK_NAME_MAX 64
+
+/*
+ * V_BSIZE is the virtual block size in bytes used
+ * by the disk framework. The virtual block size is a
+ * multiple of the hardware block size and defines
+ * how many bytes a virtual block is made up of.
+ *
+ * A virtual block is simply a unit specific to
+ * the disk framework that represents multiple
+ * hardware disk blocks.
+ */
+#if defined(__V_BSIZE)
+#define V_BSIZE __V_BSIZE
+#else
+#define V_BSIZE 4096
+#endif /* __V_BSIZE */
+
+/* Sanitize the silly human's input */
+_Static_assert(V_BSIZE > 512, "V_BSIZE must be > 512");
+_Static_assert((V_BSIZE & 1) == 0, "V_BSIZE must be a power of two");
+
+#define DISK_PRIMARY 0 /* ID of primary disk */
+
+/*
+ * To prevent unlikely cases of unintended disk
+ * operations (e.g., read, write, etc), we store
+ * a cookie within each set of parameters.
+ *
+ * Requests whose bundle of parameters have no valid
+ * cookie shall be rejected by us.
+ */
+#define DISK_PARAM_COOKIE 0xD1531001
+
+/* Valid disk operations */
+#define DISK_IO_READ 0x00 /* Read data from the disk */
+#define DISK_IO_WRITE 0x01 /* Write data to disk */
+#define DISK_IO_QUERY 0x02 /* Query disk information */
+
+/*
+ * A disk identifier is a zero-based index into
+ * the disk registry.
+ */
+typedef uint16_t diskid_t;
+
+/*
+ * Block offset / LBA
+ */
+typedef off_t blkoff_t;
+
+/*
+ * Disk operations may be requested by user
+ * programs by using a disk operation code.
+ */
+typedef uint8_t diskop_t;
+
+/*
+ * Describes basic disk information
+ *
+ * @block_size: Hardware block size
+ * @vblock_size: Virtual block size
+ * @n_block: Number of blocks total
+ */
+struct disk_info {
+ uint32_t block_size;
+ uint32_t vblock_size;
+ size_t n_block;
+};
+
+/*
+ * The disk metadata structure contains information
+ * describing the disk. It is used for Hyra's pbuf
+ * (persistent buffers / sls) support. This structure
+ * is to be stored at the very last sector of the drive.
+ *
+ * @canary: Boot canary to verify persistent instance
+ * @info: Disk attributes
+ */
+struct disk_root {
+ uint32_t canary;
+ struct disk_info info;
+};
+
+/*
+ * A disk I/O parameter contains information
+ * that is passed from a user application to
+ * the kernel for specific operations.
+ *
+ * @buf: User-side pointer to data buffer
+ * @size: Size of data buffer in bytes
+ * @cookie: Used to prevent unintended operations
+ * @blk: Disk block offset
+ * @u_buf: Used by the kernel to keep track of user buffer
+ */
+struct disk_param {
+ void *buf;
+ size_t size;
+ uint32_t cookie;
+ blkoff_t blk;
+#if defined(_KERNEL)
+ void *u_buf;
+#endif
+};
+
+/*
+ * Helper used to initialize disk I/O parameters.
+ * This is used by the user to initialize a declared
+ * set of parameters.
+ *
+ * @buf: Buffer to operate on
+ * @blk: Disk block to operate on
+ * @size: Operation size in bytes (block-aligned)
+ * @res: Pointer to params to be initialized
+ */
+__always_inline static inline void
+disk_param_init(void *buf, blkoff_t blk, size_t size, struct disk_param *res)
+{
+ if (res != NULL) {
+ res->buf = buf;
+ res->blk = blk;
+ res->size = size;
+ res->cookie = DISK_PARAM_COOKIE;
+ }
+}
+
+/*
+ * User side disk API
+ */
+#if !defined(_KERNEL)
+ssize_t __disk_io(diskid_t id, diskop_t op, const struct disk_param *param);
+#endif /* !_KERNEL */
+
+/* Common disk operations */
+int disk_query(diskid_t id, struct disk_info *res);
+ssize_t disk_read(diskid_t id, blkoff_t blk, void *buf, size_t len);
+ssize_t disk_write(diskid_t id, blkoff_t blk, const void *buf, size_t len);
+
+#if defined(_KERNEL)
+/*
+ * Represents a block storage device
+ *
+ * @name: Name of disk
+ * @cookie: Used internally to ensure validity
+ * @bsize: Hardware block size (defaults to 512 bytes)
+ * @dev: Device minor
+ * @id: Disk ID (zero-based index)
+ * @bdev: Block device operations
+ * @link: TAILQ link
+ */
+struct disk {
+ char name[DISK_NAME_MAX];
+ uint32_t cookie;
+ uint16_t bsize;
+ dev_t dev;
+ diskid_t id;
+ const struct bdevsw *bdev;
+ TAILQ_ENTRY(disk) link;
+};
+
+void *disk_buf_alloc(diskid_t id, size_t len);
+void disk_buf_free(void *p);
+
+int disk_add(const char *name, dev_t dev, const struct bdevsw *bdev, int flags);
+int disk_get_id(diskid_t id, struct disk **res);
+
+scret_t sys_disk(struct syscall_args *scargs);
+#endif /* _KERNEL */
+#endif /* !_SYS_DISK_H_ */
diff --git a/sys/include/sys/disklabel.h b/sys/include/sys/disklabel.h
new file mode 100644
index 0000000..895c35e
--- /dev/null
+++ b/sys/include/sys/disklabel.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_DISKLABEL_H_
+#define _SYS_DISKLABEL_H_
+
+#include <sys/types.h>
+
+#define DISK_MAG 0x4F445421UL /* "ODT!" */
+
+/*
+ * Represents a disk table.
+ *
+ * @magic: Magic number (`DISK_MAG')
+ * @sect_size: Disk sector size
+ */
+struct disklabel {
+ uint32_t magic;
+ uint32_t sect_size;
+};
+
+#endif /* !_SYS_DISKLABEL_H_ */
diff --git a/sys/include/sys/dmi.h b/sys/include/sys/dmi.h
new file mode 100644
index 0000000..a21cff6
--- /dev/null
+++ b/sys/include/sys/dmi.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_DMI_H_
+#define _SYS_DMI_H_
+
+#if defined(_KERNEL)
+#include <sys/types.h>
+#else
+#include <stdint.h>
+#include <stddef.h>
+#endif /* _KERNEL */
+
+/*
+ * Provides board information through
+ * DMI.
+ *
+ * @cpu_version: CPU version string
+ * @cpu_manuf: CPU manufacturer string
+ * @product: Board product string
+ * @vendor: Board vendor string
+ * @version: Product version string
+ *
+ * If index 0 of any of the strings contain
+ * '\0', then they are unsupported/unused.
+ *
+ * XXX: Strings are null terminated
+ */
+struct dmi_board {
+ char cpu_version[64];
+ char cpu_manuf[32];
+ char product[32];
+ char vendor[32];
+ char version[32];
+};
+
+#endif /* !_SYS_DMI_H_ */
diff --git a/sys/include/sys/driver.h b/sys/include/sys/driver.h
index 05c40fa..e10021a 100644
--- a/sys/include/sys/driver.h
+++ b/sys/include/sys/driver.h
@@ -31,27 +31,94 @@
#define _SYS_DRIVER_H_
#include <sys/cdefs.h>
+#include <sys/proc.h>
+#include <sys/types.h>
#if defined(_KERNEL)
+/* Variable driver data */
+struct driver_var {
+ uint8_t deferred : 1;
+};
+
struct driver {
int(*init)(void);
+ const char *name;
+ struct driver_var *data;
};
+extern struct proc g_proc0;
+
+/* Early (high priority) drivers */
extern char __drivers_init_start[];
extern char __drivers_init_end[];
-#define DRIVER_EXPORT(INIT) \
+/* Deferred (low priority) drivers */
+extern char __driversd_init_start[];
+extern char __driversd_init_end[];
+
+#define DRIVER_EXPORT(INIT, NAME) \
+ static struct driver_var __driver_var = { \
+ .deferred = 0 \
+ }; \
+ \
__attribute__((used, section(".drivers"))) \
static struct driver __driver_desc = { \
.init = INIT, \
+ .data = &__driver_var, \
+ .name = NAME \
}
+/*
+ * Some drivers are not required to start up
+ * early for proper system operation and may
+ * be deferred to start at a later time.
+ *
+ * Examples of such (deferrable) drivers include code
+ * that waits for I/O (e.g., disks, network cards,
+ * et cetera). This allows for faster boot times
+ * as only *required* drivers are started before
+ * everything else.
+ *
+ * Drivers that wish to be deferred may export themselves
+ * via the DRIVER_DEFER() macro. The DRIVER_DEFERRED()
+ * macro gives the value of 1 if the current driver
+ * context has yet to be initialized. The driver may
+ * use this to defer requests for I/O.
+ */
+#define DRIVER_DEFER(INIT, NAME) \
+ static struct driver_var __driver_var = { \
+ .deferred = 1 \
+ }; \
+ \
+ __attribute__((used, section(".drivers.defer"))) \
+ static struct driver __driver_desc = { \
+ .init = INIT, \
+ .data = &__driver_var, \
+ .name = NAME \
+ }
+
+#define DRIVER_DEFERRED() __driver_var.deferred
+
#define DRIVERS_INIT() \
for (struct driver *__d = (struct driver *)__drivers_init_start; \
(uintptr_t)__d < (uintptr_t)__drivers_init_end; ++__d) \
{ \
+ if (driver_blacklist_check((__d)->name)) { \
+ continue; \
+ } \
__d->init(); \
}
+
+#define DRIVERS_SCHED() \
+ spawn(&g_proc0, __driver_init_td, NULL, 0, NULL)
+
+/* Driver blacklist framework */
+int driver_blacklist(const char *name);
+int driver_blacklist_check(const char *name);
+void driver_blacklist_init(void);
+
+void __driver_init_td(void);
+
#endif /* _KERNEL */
#endif /* !_SYS_DRIVER_H_ */
diff --git a/sys/include/sys/elf.h b/sys/include/sys/elf.h
index af5f6d6..76c6d43 100644
--- a/sys/include/sys/elf.h
+++ b/sys/include/sys/elf.h
@@ -496,4 +496,70 @@ typedef struct {
Elf64_Xword sh_entsize; /* Entry size if section holds table */
} Elf64_Shdr;
+/* Special section indices. */
+
+#define SHN_UNDEF 0 /* Undefined section */
+#define SHN_LORESERVE 0xff00 /* Start of reserved indices */
+#define SHN_LOPROC 0xff00 /* Start of processor-specific */
+#define SHN_BEFORE 0xff00 /* Order section before all others
+ (Solaris). */
+#define SHN_AFTER 0xff01 /* Order section after all others
+ (Solaris). */
+#define SHN_HIPROC 0xff1f /* End of processor-specific */
+#define SHN_LOOS 0xff20 /* Start of OS-specific */
+#define SHN_HIOS 0xff3f /* End of OS-specific */
+#define SHN_ABS 0xfff1 /* Associated symbol is absolute */
+#define SHN_COMMON 0xfff2 /* Associated symbol is common */
+#define SHN_XINDEX 0xffff /* Index is in extra table. */
+#define SHN_HIRESERVE 0xffff /* End of reserved indices */
+
+/* Legal values for sh_type (section type). */
+
+#define SHT_NULL 0 /* Section header table entry unused */
+#define SHT_PROGBITS 1 /* Program data */
+#define SHT_SYMTAB 2 /* Symbol table */
+#define SHT_STRTAB 3 /* String table */
+#define SHT_RELA 4 /* Relocation entries with addends */
+#define SHT_HASH 5 /* Symbol hash table */
+#define SHT_DYNAMIC 6 /* Dynamic linking information */
+#define SHT_NOTE 7 /* Notes */
+#define SHT_NOBITS 8 /* Program space with no data (bss) */
+#define SHT_REL 9 /* Relocation entries, no addends */
+#define SHT_SHLIB 10 /* Reserved */
+#define SHT_DYNSYM 11 /* Dynamic linker symbol table */
+#define SHT_INIT_ARRAY 14 /* Array of constructors */
+#define SHT_FINI_ARRAY 15 /* Array of destructors */
+#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
+#define SHT_GROUP 17 /* Section group */
+#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
+#define SHT_NUM 19 /* Number of defined types. */
+#define SHT_LOOS 0x60000000 /* Start OS-specific. */
+#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */
+#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */
+#define SHT_SUNW_move 0x6ffffffa
+#define SHT_SUNW_COMDAT 0x6ffffffb
+#define SHT_SUNW_syminfo 0x6ffffffc
+#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */
+#define SHT_HIOS 0x6fffffff /* End OS-specific type */
+#define SHT_LOPROC 0x70000000 /* Start of processor-specific */
+#define SHT_HIPROC 0x7fffffff /* End of processor-specific */
+#define SHT_LOUSER 0x80000000 /* Start of application-specific */
+#define SHT_HIUSER 0x8fffffff /* End of application-specific */
+
+/* Legal values for sh_flags (section flags). */
+
+#define SHF_WRITE (1 << 0) /* Writable */
+#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
+#define SHF_EXECINSTR (1 << 2) /* Executable */
+#define SHF_MERGE (1 << 4) /* Might be merged */
+#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
+#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
+#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
+#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling
+ required */
+#define SHF_GROUP (1 << 9) /* Section is member of a group. */
+#define SHF_TLS (1 << 10) /* Section hold thread-local data. */
+#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
+#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
+#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
#endif /* _SYS_ELF_H_ */
diff --git a/sys/include/sys/endian.h b/sys/include/sys/endian.h
new file mode 100644
index 0000000..5cbc94a
--- /dev/null
+++ b/sys/include/sys/endian.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_ENDIAN_H_
+#define _SYS_ENDIAN_H_
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#define swap16(x) __swap16((x))
+#define swap32(x) __swap32((x))
+
+__always_inline static inline uint16_t
+__swap16(uint16_t x)
+{
+ return ((x << 8) & 0xFF00) | ((x >> 8) & 0x00FF);
+}
+
+__always_inline static inline uint32_t
+__swap32(uint32_t x)
+{
+ return ((x << 24) & 0xFF000000) |
+ ((x << 8) & 0x00FF0000) |
+ ((x >> 8) & 0x0000FF00) |
+ ((x >> 24) & 0x000000FF);
+}
+
+#endif /* !_SYS_ENDIAN_H_ */
diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h
index 7e720fc..43df59f 100644
--- a/sys/include/sys/exec.h
+++ b/sys/include/sys/exec.h
@@ -32,8 +32,6 @@
#include <sys/types.h>
-#if defined(_KERNEL)
-
/* Danger: Do not change these !! */
#define AT_NULL 0
#define AT_ENTRY 1
@@ -45,7 +43,9 @@
#define AT_RANDOM 7
#define AT_EXECFN 8
#define AT_PAGESIZE 9
+#define _AT_MAX 16
+#if defined(_KERNEL)
#define MAX_PHDRS 32
#define STACK_PUSH(PTR, VAL) *(--(PTR)) = VAL
#define AUXVAL(PTR, TAG, VAL) \
diff --git a/sys/include/sys/fbdev.h b/sys/include/sys/fbdev.h
new file mode 100644
index 0000000..e206889
--- /dev/null
+++ b/sys/include/sys/fbdev.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_FBDEV_H_
+#define _SYS_FBDEV_H_
+
+struct fbattr {
+ uint32_t width;
+ uint32_t height;
+ uint32_t pitch;
+ uint32_t bpp;
+};
+
+#endif /* !_SYS_FBDEV_H_ */
diff --git a/sys/include/sys/fcntl.h b/sys/include/sys/fcntl.h
index 122a378..83d38af 100644
--- a/sys/include/sys/fcntl.h
+++ b/sys/include/sys/fcntl.h
@@ -33,6 +33,7 @@
#define O_RDONLY 0x0000
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
+#define O_CREAT 0x0004
/* Makes seal checking easier */
#if defined(_KERNEL)
diff --git a/sys/include/sys/filedesc.h b/sys/include/sys/filedesc.h
index a544811..adbcfa8 100644
--- a/sys/include/sys/filedesc.h
+++ b/sys/include/sys/filedesc.h
@@ -31,8 +31,15 @@
#define _SYS_FILEDESC_H_
#include <sys/types.h>
+#if defined(_KERNEL)
#include <sys/vnode.h>
+#include <sys/syscall.h>
#include <sys/spinlock.h>
+#include <sys/syscall.h>
+
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
struct filedesc {
int fdno;
@@ -48,10 +55,14 @@ int fd_close(unsigned int fd);
int fd_read(unsigned int fd, void *buf, size_t count);
int fd_write(unsigned int fd, void *buf, size_t count);
-int fd_alloc(struct filedesc **fd_out);
+int fd_alloc(struct proc *td, struct filedesc **fd_out);
int fd_open(const char *pathname, int flags);
+off_t fd_seek(int fildes, off_t offset, int whence);
+
+int fd_dup(struct proc *td, int fd);
+struct filedesc *fd_get(struct proc *td, unsigned int fdno);
-int fd_dup(int fd);
-struct filedesc *fd_get(unsigned int fdno);
+scret_t sys_lseek(struct syscall_args *scargs);
+#endif /* _KERNEL */
#endif /* !_SYS_FILEDESC_H_ */
diff --git a/sys/include/sys/krq.h b/sys/include/sys/krq.h
new file mode 100644
index 0000000..9cb6ec6
--- /dev/null
+++ b/sys/include/sys/krq.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_KRQ_H_
+#define _SYS_KRQ_H_
+
+#include <sys/syscall.h>
+
+#if defined(_KERNEL)
+scret_t sys_inject(struct syscall_args *scargs);
+#else
+int inject(const char *path);
+#endif /* _KERNEL */
+#endif /* !_SYS_KRQ_H_ */
diff --git a/sys/include/sys/limits.h b/sys/include/sys/limits.h
index 6185719..c0ce5af 100644
--- a/sys/include/sys/limits.h
+++ b/sys/include/sys/limits.h
@@ -31,7 +31,12 @@
#define _SYS_LIMITS_H_
#define PATH_MAX 1024
+#define NAME_MAX 256
#define SSIZE_MAX 32767
+#define ARG_MAX 4096
#define CHAR_BIT 8
-
+#define CPU_MAX 256
+#define VSR_MAX_DOMAIN 16
+#define VSR_MAX_CAPSULE 16
+#define IOVEC_MAX 512
#endif /* !_SYS_LIMITS_H_ */
diff --git a/sys/include/sys/mman.h b/sys/include/sys/mman.h
index 4ead9ba..de360e4 100644
--- a/sys/include/sys/mman.h
+++ b/sys/include/sys/mman.h
@@ -35,6 +35,8 @@
#if defined(_KERNEL)
#include <sys/tree.h>
#include <vm/vm_obj.h>
+#else
+#include <stddef.h>
#endif /* _KERNEL */
/*
@@ -49,10 +51,10 @@
#endif /* !_KERNEL */
/* mmap() flags */
+#define MAP_ANON 0x0000
#define MAP_SHARED 0x0001
#define MAP_PRIVATE 0x0002
#define MAP_FIXED 0x0004
-#define MAP_ANON 0x0008
#if defined(_KERNEL)
/*
@@ -80,19 +82,19 @@ struct mmap_lgdr {
size_t nbytes;
};
-/* Kernel munmap() routine */
-int munmap_at(void *addr, size_t len);
-
-/* Kernel mmap() routine */
-void *mmap_at(void *addr, size_t len, int prot, int flags,
- int fildes, off_t off);
-
int mmap_entrycmp(const struct mmap_entry *a, const struct mmap_entry *b);
RBT_PROTOTYPE(lgdr_entries, mmap_entry, hd, mmap_entrycmp)
-#endif /* _KERNEL */
/* Syscall layer */
-scret_t mmap(struct syscall_args *scargs);
-scret_t munmap(struct syscall_args *scargs);
+scret_t sys_mmap(struct syscall_args *scargs);
+scret_t sys_munmap(struct syscall_args *scargs);
+#endif /* _KERNEL */
+
+/* Kernel munmap() routine */
+int munmap(void *addr, size_t len);
+
+/* Kernel mmap() routine */
+void *mmap(void *addr, size_t len, int prot, int flags,
+ int fildes, off_t off);
#endif /* !_SYS_MMAN_H_ */
diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h
index 9f6e4e2..0fa9e36 100644
--- a/sys/include/sys/mmio.h
+++ b/sys/include/sys/mmio.h
@@ -42,7 +42,6 @@
#if defined(_KERNEL)
-
/*
* mmio_write<n> - Writes to MMIO address with specific size
*
diff --git a/sys/include/sys/mount.h b/sys/include/sys/mount.h
index 1fcdbfa..636c7bf 100644
--- a/sys/include/sys/mount.h
+++ b/sys/include/sys/mount.h
@@ -47,6 +47,7 @@
#define MOUNT_RAMFS "initramfs"
#define MOUNT_DEVFS "devfs"
#define MOUNT_CTLFS "ctlfs"
+#define MOUNT_TMPFS "tmpfs"
struct vfsops;
struct mount;
@@ -59,6 +60,7 @@ extern mountlist_t g_mountlist;
extern const struct vfsops g_initramfs_vfsops;
extern const struct vfsops g_devfs_vfsops;
extern const struct vfsops g_ctlfs_vfsops;
+extern const struct vfsops g_tmpfs_vfsops;
struct mount {
char *name;
diff --git a/sys/include/sys/mutex.h b/sys/include/sys/mutex.h
new file mode 100644
index 0000000..8a4d50a
--- /dev/null
+++ b/sys/include/sys/mutex.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_MUTEX_H_
+#define _SYS_MUTEX_H_
+
+#include <sys/types.h>
+#include <vm/dynalloc.h>
+
+#define MUTEX_NAME_LEN 32
+
+#if defined(_KERNEL)
+
+struct mutex {
+ char name[MUTEX_NAME_LEN];
+ volatile uint8_t lock;
+};
+
+struct mutex *mutex_new(const char *name);
+void mutex_free(struct mutex *mtx);
+
+int mutex_acquire(struct mutex *mtx, int flags);
+void mutex_release(struct mutex *mtx);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_MUTEX_H_ */
diff --git a/sys/include/sys/namei.h b/sys/include/sys/namei.h
index f81f905..ccd7f35 100644
--- a/sys/include/sys/namei.h
+++ b/sys/include/sys/namei.h
@@ -32,6 +32,9 @@
#include <sys/types.h>
#include <sys/vnode.h>
+#include <sys/param.h>
+
+#define NAMEI_WANTPARENT BIT(0) /* Request parent only */
struct nameidata {
const char *path; /* Pathname */
diff --git a/sys/include/sys/param.h b/sys/include/sys/param.h
index c0a5686..2bbbabd 100644
--- a/sys/include/sys/param.h
+++ b/sys/include/sys/param.h
@@ -30,11 +30,20 @@
#ifndef _SYS_PARAM_H_
#define _SYS_PARAM_H_
+#if defined(_KERNEL)
+#include <machine/param.h>
+#endif
+
/* Assumed cache line size */
#ifndef COHERENCY_UNIT
#define COHERENCY_UNIT 64
#endif
+/* Assumed machine word size */
+#ifndef M_WORD_SIZE
+#define M_WORD_SIZE 4
+#endif
+
/* Bit related macros */
#define ISSET(v, f) ((v) & (f))
#define BIT(n) (1ULL << (n))
@@ -47,6 +56,7 @@
/* Align up/down a value */
#define ALIGN_DOWN(value, align) ((value) & ~((align)-1))
#define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1))
+#define MALIGN(value) ALIGN_UP((value), M_WORD_SIZE)
/* Bitmap helper macros */
#define setbit(a, b) ((a)[(b) >> 3] |= BIT(b % 8))
@@ -67,8 +77,12 @@
/* Gives 1 if pointer is aligned */
#define PTR_ALIGNED(PTR, ALIGN) (!((uintptr_t)PTR & (ALIGN - 1)))
-/* Adds a value to a pointer */
+/*
+ * PTR_OFFSET: Adds an offset to the pointer
+ * PTR_NOFFSET: Subtracts a negative offset from the pointer
+ */
#define PTR_OFFSET(PTR, OFF) ((void *)((uintptr_t)PTR + OFF))
+#define PTR_NOFFSET(PTR, NOFF) ((void *)((uintptr_t)PTR - NOFF))
#define NELEM(a) (sizeof(a) / sizeof(a[0]))
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index 1b59de9..809ee23 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -38,6 +38,9 @@
#include <sys/cdefs.h>
#include <sys/syscall.h>
#include <sys/exec.h>
+#include <sys/ucred.h>
+#include <sys/limits.h>
+#include <sys/vsr.h>
#include <sys/filedesc.h>
#include <sys/signal.h>
#include <sys/vnode.h>
@@ -53,22 +56,53 @@
#define PROC_MAX_FILEDES 256
#define PROC_SIGMAX 64
+/*
+ * The coredump structure, contains information
+ * about crashes.
+ *
+ * @pid: PID of process that has crashed
+ * @fault_addr: Address of faulting memory access
+ * @tf: Copy of the programs trapframe
+ * @checksum: CRC32 checksum of entire coredump
+ *
+ * XXX: DO NOT REORDER (always add to the end before 'checksum')
+ */
+struct __packed coredump {
+ pid_t pid;
+ uintptr_t fault_addr;
+ struct trapframe tf;
+
+ /* XXX: Add entries above the checksum */
+ uint32_t checksum;
+};
+
+/*
+ * Sometimes we may need to pin a process
+ * to a specific CPU. This type represents
+ * the (machine independent) logical processor
+ * ID for a process to be pinned to.
+ */
+typedef int16_t affinity_t;
+
struct proc {
pid_t pid;
struct exec_prog exec;
+ struct ucred cred;
struct ksiginfo *ksig_list[PROC_SIGMAX];
struct filedesc *fds[PROC_MAX_FILEDES];
+ struct vsr_domain *vsr_tab[VSR_MAX_DOMAIN];
struct mmap_lgdr *mlgdr;
struct vcache *vcache;
struct spinlock vcache_lock;
struct trapframe tf;
struct pcb pcb;
struct proc *parent;
- void *spawn_data;
+ affinity_t affinity;
+ void *data;
size_t priority;
int exit_status;
bool rested;
- uint32_t flags;
+ volatile uint32_t flags;
uint32_t nleaves;
uintptr_t stack_base;
struct spinlock ksigq_lock;
@@ -83,19 +117,38 @@ struct proc {
#define PROC_ZOMB BIT(2) /* Zombie (dead but not deallocated) */
#define PROC_LEAFQ BIT(3) /* Leaf queue is active */
#define PROC_WAITED BIT(4) /* Being waited on by parent */
+#define PROC_KTD BIT(5) /* Kernel thread */
+#define PROC_SLEEP BIT(6) /* Thread execution paused */
+#define PROC_PINNED BIT(7) /* Pinned to CPU */
struct proc *this_td(void);
+struct proc *td_copy(struct proc *td);
struct proc *get_child(struct proc *cur, pid_t pid);
+
+int proc_init(struct proc *td, struct proc *parent);
+void proc_pin(struct proc *td, affinity_t cpu);
+void proc_unpin(struct proc *td);
+
+void proc_reap(struct proc *td);
+void proc_coredump(struct proc *td, uintptr_t fault_addr);
+
+pid_t getpid(void);
+pid_t getppid(void);
+
+scret_t sys_getpid(struct syscall_args *scargs);
+scret_t sys_getppid(struct syscall_args *scargs);
+scret_t sys_waitpid(struct syscall_args *scargs);
+
int md_spawn(struct proc *p, struct proc *parent, uintptr_t ip);
scret_t sys_spawn(struct syscall_args *scargs);
pid_t spawn(struct proc *cur, void(*func)(void), void *p, int flags, struct proc **newprocp);
-void md_td_stackinit(struct proc *td, void *stack_top, struct exec_prog *prog);
+uintptr_t md_td_stackinit(struct proc *td, void *stack_top, struct exec_prog *prog);
__dead void md_td_kick(struct proc *td);
int fork1(struct proc *cur, int flags, void(*ip)(void), struct proc **newprocp);
-int exit1(struct proc *td);
+int exit1(struct proc *td, int flags);
__dead scret_t sys_exit(struct syscall_args *scargs);
#endif /* _KERNEL */
diff --git a/sys/include/sys/queue.h b/sys/include/sys/queue.h
index e5d607d..2226ccc 100644
--- a/sys/include/sys/queue.h
+++ b/sys/include/sys/queue.h
@@ -27,7 +27,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#if !defined(_KERNEL)
+#include <stdint.h>
+#include <stddef.h>
+#else
#include <sys/types.h>
+#endif /* !_KERNEL */
#ifndef _QUEUE_H_
#define _QUEUE_H_
@@ -79,7 +84,6 @@ struct { \
((tvar) = TAILQ_NEXT(var, field), 1); \
(var) = (tvar))
-
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head); \
diff --git a/sys/include/sys/sched.h b/sys/include/sys/sched.h
index 80f4d1c..7bba9df 100644
--- a/sys/include/sys/sched.h
+++ b/sys/include/sys/sched.h
@@ -32,11 +32,45 @@
#include <sys/proc.h>
#include <sys/cdefs.h>
+#include <sys/limits.h>
+#include <sys/time.h>
+
+/*
+ * Scheduler CPU information
+ *
+ * @nswitch: Number of context switches
+ * @idle: Number of milliseconds idle
+ */
+struct sched_cpu {
+ uint64_t nswitch;
+};
+
+/*
+ * Scheduler statistics
+ *
+ * @nproc: Number processes running
+ * @ncpu: Number of CPU cores
+ * @nhlt: Number of halted CPU cores
+ * @quantum_usec: Scheduler quantum (microseconds)
+ */
+struct sched_stat {
+ size_t nproc;
+ uint16_t ncpu;
+ uint16_t nhlt;
+ uint32_t quantum_usec;
+ struct sched_cpu cpus[CPU_MAX];
+};
#if defined(_KERNEL)
+void sched_stat(struct sched_stat *statp);
void sched_init(void);
+
+void sched_preempt_set(bool enable);
+bool sched_preemptable(void);
+
void sched_yield(void);
+void sched_suspend(struct proc *td, const struct timeval *tv);
void sched_detach(struct proc *td);
__dead void sched_enter(void);
diff --git a/sys/include/sys/schedvar.h b/sys/include/sys/schedvar.h
index 5ed9f5f..017fcb7 100644
--- a/sys/include/sys/schedvar.h
+++ b/sys/include/sys/schedvar.h
@@ -60,5 +60,11 @@ struct sched_queue {
size_t nthread;
};
+struct proc *sched_dequeue_td(void);
+void mi_sched_switch(struct proc *from);
+
+void md_sched_switch(struct trapframe *tf);
+void sched_oneshot(bool now);
+
#endif /* _KERNEL */
#endif /* !_SYS_SCHEDVAR_H_ */
diff --git a/sys/include/sys/signal.h b/sys/include/sys/signal.h
index 9fc767d..eaf2d41 100644
--- a/sys/include/sys/signal.h
+++ b/sys/include/sys/signal.h
@@ -37,6 +37,7 @@
#define SIGFPE 8 /* Floating point exception */
#define SIGKILL 9 /* Kill */
#define SIGSEGV 11 /* Segmentation violation */
+#define SIGTERM 15 /* Terminate gracefully */
typedef uint32_t sigset_t;
@@ -80,5 +81,6 @@ int sigismember(const sigset_t *set, int signo);
void sigfpe_default(int signo);
void sigkill_default(int signo);
void sigsegv_default(int signo);
+void sigterm_default(int signo);
#endif /* _KERNEL */
#endif /* !_SYS_SIGNAL_H_ */
diff --git a/sys/include/sys/socket.h b/sys/include/sys/socket.h
new file mode 100644
index 0000000..1a33108
--- /dev/null
+++ b/sys/include/sys/socket.h
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_SOCKET_H_
+#define _SYS_SOCKET_H_
+
+#include <sys/socketvar.h>
+#include <sys/queue.h>
+#include <sys/param.h>
+#include <sys/uio.h>
+#if defined(_KERNEL)
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/syscall.h>
+#include <sys/mutex.h>
+#else
+#include <stdint.h>
+#include <stddef.h>
+#endif /* _KERNEL */
+
+#ifndef _SA_FAMILY_T_DEFINED_
+#define _SA_FAMILY_T_DEFINED_
+typedef uint32_t sa_family_t;
+#endif /* _SA_FAMILY_T_DEFINED_ */
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef uint32_t socklen_t;
+#endif /* !_SOCKLEN_T_DEFINED_ */
+
+/*
+ * Socket level number
+ */
+#define SOL_SOCKET 0xFFFF
+
+/*
+ * Address family defines
+ */
+#define AF_UNSPEC 0
+#define AF_UNIX 1
+#define AF_LOCAL AF_UNIX
+
+/* Socket types */
+#define SOCK_STREAM 1
+
+/* Socket option names */
+#define SO_RCVTIMEO 0 /* Max time recv(2) waits */
+#define _SO_MAX 1 /* Max socket options */
+
+struct sockaddr_un {
+ sa_family_t sun_family;
+ char sun_path[108];
+};
+
+struct sockaddr {
+ sa_family_t sa_family;
+ char sa_data[14];
+};
+
+/*
+ * POSIX message header for recvmsg()
+ * and sendmsg() calls.
+ */
+struct msghdr {
+ void *msg_name; /* Optional address */
+ socklen_t msg_namelen; /* Size of address */
+ struct iovec *msg_iov; /* Scatter/gather array */
+ int msg_iovlen; /* Members in msg_iov */
+ void *msg_control; /* Ancillary data, see below */
+ socklen_t msg_controllen; /* Ancillary data buffer len */
+ int msg_flags; /* Message flags */
+};
+
+/*
+ * POSIX control message header for
+ * ancillary data objects.
+ */
+struct cmsghdr {
+ socklen_t cmsg_len;
+ int cmsg_level;
+ int cmsg_type;
+};
+
+#define CMSG_SPACE(len) (MALIGN(sizeof(struct cmsghdr)) + MALIGN(len))
+
+/* Return pointer to cmsg data */
+#define CMSG_DATA(cmsg) PTR_OFFSET(cmsg, sizeof(struct cmsghdr))
+
+/* Return length of control message */
+#define CMSG_LEN(len) (MALIGN(sizeof(struct cmsghdr)) + MALIGN(len))
+
+/* Return pointer to next cmsghdr */
+#define CMSG_NXTHDR(mhdr, cmsg) \
+ PTR_OFFSET(cmsg, MALIGN((cmsg)>cmsg_len)) + \
+ MALIGN(sizeof(struct cmsghdr)) > \
+ PTR_OFFSET((mhdr)->msg_control, (mhdr)->msg_controllen) ? \
+ (struct cmsghdr *)NULL : \
+ (struct cmsghdr *)PTR_OFFSET(cmsg, MALIGN((cmsg)->cmsg_len))
+
+/* Return pointer to first header */
+#define CMSG_FIRSTHDR(mhdr) \
+ ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
+ (struct cmsghdr *)(mhdr)->msg_control : \
+ (struct cmsghdr *)NULL);
+
+/* Socket level control messages */
+#define SCM_RIGHTS 0x01
+
+#if defined(_KERNEL)
+
+struct cmsg {
+ union {
+ struct cmsghdr hdr;
+ uint8_t buf[CMSG_SPACE(sizeof(int))];
+ };
+
+ size_t control_len;
+ TAILQ_ENTRY(cmsg) link;
+};
+
+/*
+ * List of cmsg headers and data, queued up
+ * during sendmsg()
+ */
+struct cmsg_list {
+ TAILQ_HEAD(, cmsg) list;
+ uint8_t is_init : 1;
+};
+
+/*
+ * Socket option that may be applied to
+ * sockets on the system.
+ */
+struct sockopt {
+ socklen_t len;
+ char data[];
+};
+
+struct ksocket {
+ int sockfd;
+ union {
+ struct sockaddr sockaddr;
+ struct sockaddr_un un;
+ };
+ struct sockopt *opt[_SO_MAX];
+ struct proc *owner;
+ struct cmsg_list cmsg_list;
+ struct sockbuf buf;
+ struct mutex *mtx;
+};
+
+scret_t sys_socket(struct syscall_args *scargs);
+scret_t sys_bind(struct syscall_args *scargs);
+scret_t sys_connect(struct syscall_args *scargs);
+
+scret_t sys_recv(struct syscall_args *scargs);
+scret_t sys_send(struct syscall_args *scargs);
+
+scret_t sys_recvmsg(struct syscall_args *scargs);
+scret_t sys_sendmsg(struct syscall_args *scargs);
+scret_t sys_setsockopt(struct syscall_args *scargs);
+#endif /* _KERNEL */
+
+int socket(int domain, int type, int protocol);
+int bind(int sockfd, const struct sockaddr *addr, socklen_t len);
+
+int setsockopt(int sockfd, int level, int name, const void *v, socklen_t len);
+int connect(int sockfd, const struct sockaddr *addr, socklen_t len);
+
+ssize_t send(int sockfd, const void *buf, size_t size, int flags);
+ssize_t recv(int sockfd, void *buf, size_t len, int flags);
+
+ssize_t sendmsg(int socket, const struct msghdr *msg, int flags);
+ssize_t recvmsg(int socket, struct msghdr *msg, int flags);
+
+#endif /* !_SYS_SOCKET_H_ */
diff --git a/sys/include/sys/socketvar.h b/sys/include/sys/socketvar.h
new file mode 100644
index 0000000..e090a70
--- /dev/null
+++ b/sys/include/sys/socketvar.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_SOCKETVAR_H_
+#define _SYS_SOCKETVAR_H_
+
+#include <sys/types.h>
+#if defined(_KERNEL)
+#include <net/netbuf.h>
+
+/*
+ * Socket buffer
+ *
+ * @buf: Actual data buffer
+ * @head: Buffer head
+ * @tail: Buffer tail
+ * @watermark: Max length
+ */
+struct sockbuf {
+ struct netbuf buf;
+ size_t head;
+ size_t tail;
+ size_t watermark;
+};
+
+#endif /* _KERNEL */
+#endif /* !_SYS_SOCKETVAR_H_ */
diff --git a/sys/include/sys/spawn.h b/sys/include/sys/spawn.h
index 3828d5c..28dbe5b 100644
--- a/sys/include/sys/spawn.h
+++ b/sys/include/sys/spawn.h
@@ -31,8 +31,9 @@
#define _SYS_SPAWN_H_
#include <sys/types.h>
+#include <sys/param.h>
#if !defined(_KERNEL)
-pid_t spawn(const char *pathname, int flags);
+pid_t spawn(const char *pathname, char **argv, char **envp, int flags);
#endif /* _KERNEL */
#endif /* !_SYS_SPAWN_H_ */
diff --git a/sys/include/sys/spinlock.h b/sys/include/sys/spinlock.h
index 140addc..b416152 100644
--- a/sys/include/sys/spinlock.h
+++ b/sys/include/sys/spinlock.h
@@ -44,9 +44,6 @@ void spinlock_release(struct spinlock *lock);
int spinlock_try_acquire(struct spinlock *lock);
int spinlock_usleep(struct spinlock *lock, size_t usec_max);
-/* System-wide locking (be careful!!) */
-int syslock(void);
-void sysrel(void);
#endif
#endif /* !_SYS_SPINLOCK_H_ */
diff --git a/sys/include/sys/stat.h b/sys/include/sys/stat.h
index 6303630..5409f2c 100644
--- a/sys/include/sys/stat.h
+++ b/sys/include/sys/stat.h
@@ -32,6 +32,8 @@
#include <sys/types.h>
+#define S_IFBLK 0060000
+
struct stat {
dev_t st_dev;
ino_t st_ino;
@@ -46,4 +48,6 @@ struct stat {
time_t st_ctime;
};
+int stat(const char *path, struct stat *buf);
+
#endif /* _SYS_STAT_H_ */
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 2223a96..604f937 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -48,6 +48,26 @@
#define SYS_write 7
#define SYS_spawn 8
#define SYS_reboot 9
+#define SYS_mmap 10
+#define SYS_munmap 11
+#define SYS_access 12
+#define SYS_lseek 13
+#define SYS_sleep 14
+#define SYS_inject 15
+#define SYS_getpid 16
+#define SYS_getppid 17
+#define SYS_setuid 18
+#define SYS_getuid 19
+#define SYS_waitpid 20
+#define SYS_socket 21
+#define SYS_bind 22
+#define SYS_recv 23
+#define SYS_send 24
+#define SYS_sendmsg 25
+#define SYS_recvmsg 26
+#define SYS_connect 27
+#define SYS_setsockopt 28
+#define SYS_disk 29
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/include/sys/sysctl.h b/sys/include/sys/sysctl.h
index 078135b..ce7510d 100644
--- a/sys/include/sys/sysctl.h
+++ b/sys/include/sys/sysctl.h
@@ -30,16 +30,35 @@
#ifndef _SYS_SYSCTL_H_
#define _SYS_SYSCTL_H_
-#include <sys/types.h>
#if defined(_KERNEL)
+#include <sys/types.h>
#include <sys/syscall.h>
+#else
+#include <stdint.h>
+#include <stddef.h>
#endif
#include <sys/param.h>
+/*
+ * List of 'kern.* ' identifiers
+ */
#define KERN_OSTYPE 0
#define KERN_OSRELEASE 1
#define KERN_VERSION 2
#define KERN_VCACHE_TYPE 3
+#define KERN_HOSTNAME 4
+
+/*
+ * List of 'hw.* ' identifiers
+ */
+#define HW_PAGESIZE 5
+#define HW_NCPU 6
+#define HW_MACHINE 7
+
+/*
+ * List of 'proc.*' identifiers
+ */
+#define PROC_COUNT 8
/*
* Option types (i.e., int, string, etc) for
@@ -61,6 +80,7 @@ struct sysctl_entry {
};
scret_t sys_sysctl(struct syscall_args *scargs);
+int sysctl_clearstr(int name);
#endif /* _KERNEL */
/*
diff --git a/sys/include/sys/syslog.h b/sys/include/sys/syslog.h
index defb341..b9d34ab 100644
--- a/sys/include/sys/syslog.h
+++ b/sys/include/sys/syslog.h
@@ -31,11 +31,13 @@
#define _SYS_SYSLOG_H_
#include <stdarg.h>
+#include <stdbool.h>
#if defined(_KERNEL)
#define OMIT_TIMESTAMP "\x01"
+void syslog_silence(bool option);
void kprintf(const char *fmt, ...);
void serial_init(void);
void serial_putc(char c);
diff --git a/sys/include/sys/systm.h b/sys/include/sys/systm.h
index 42e1723..2f69175 100644
--- a/sys/include/sys/systm.h
+++ b/sys/include/sys/systm.h
@@ -39,6 +39,7 @@
int copyin(const void *uaddr, void *kaddr, size_t len);
int copyout(const void *kaddr, void *uaddr, size_t len);
int copyinstr(const void *uaddr, char *kaddr, size_t len);
+int cpu_report_count(uint32_t count);
__always_inline static inline void
__sigraise(int signo)
diff --git a/sys/include/sys/termios.h b/sys/include/sys/termios.h
index 27339f1..a3ba794 100644
--- a/sys/include/sys/termios.h
+++ b/sys/include/sys/termios.h
@@ -33,8 +33,33 @@
/*
* c_iflag: Input flags
*/
-#define ISTRIP 0x00000000
-#define ICRNL 0x00000001
+#define ISTRIP 0x00000001 /* Strip char */
+#define ICRNL 0x00000002 /* Map CR to NL */
+#define BRKINT 0x00000004 /* Signal interrupt on break */
+#define IGNBRK 0x00000008 /* Ignore break condition */
+#define IGNCR 0x00000010 /* Ignore CR */
+#define IGNPAR 0x00000020 /* Ignore chars with parity errors */
+#define INCLR 0x00000040 /* Map NL to CR */
+#define INPCK 0x00000080 /* Enable input parity check */
+#define IXANY 0x00000100 /* Enable any char to restart output */
+#define IXOFF 0x00000200 /* Enable start/stop control */
+#define PARMRK 0x00000400 /* Mark parity errors */
+
+/*
+ * c_oflag: Output flags
+ */
+#define OPOST 0x00000001 /* Post-process output */
+#define ONLCR 0x00000002 /* Map NL to CR-NL on output */
+#define OCRNL 0x00000004 /* Map CR to NL on output */
+#define ONOCR 0x00000008 /* Map CR to output at col 0 */
+#define ONLRET 0x00000010 /* NL performs CR function */
+#define OFILL 0x00000020 /* Use fill chars for delay */
+#define NLDLY 0x00000040 /* Select newline type */
+#define CRDLY 0x00000080 /* Select carriage-return delays */
+#define TABDLY 0x00000100 /* Select horizontal-tab delays */
+#define BSDLY 0x00000200 /* Select backspace delays */
+#define VTDLY 0x00000400 /* Select veritcal tab delays */
+#define FFDLY 0x00000800 /* Select form-feed delays */
#define NCCS 20
diff --git a/sys/include/sys/time.h b/sys/include/sys/time.h
new file mode 100644
index 0000000..ce66885
--- /dev/null
+++ b/sys/include/sys/time.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_TIME_H_
+#define _SYS_TIME_H_
+
+#include <sys/types.h>
+#if defined(_KERNEL)
+#include <sys/syscall.h>
+#endif /* _KERNEL */
+
+struct timeval {
+ time_t tv_sec;
+ time_t tv_usec;
+};
+
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+
+struct date {
+ uint16_t year;
+ uint8_t month;
+ uint8_t day;
+ uint8_t sec;
+ uint8_t min;
+ uint8_t hour;
+};
+
+#if defined(_KERNEL)
+scret_t sys_sleep(struct syscall_args *scargs);
+#endif
+#endif /* !_SYS_TIME_H_ */
diff --git a/sys/include/sys/tree.h b/sys/include/sys/tree.h
index 1054ade..6954185 100644
--- a/sys/include/sys/tree.h
+++ b/sys/include/sys/tree.h
@@ -746,7 +746,6 @@ name##_RB_MINMAX(struct name *head, int val) \
((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \
(x) = (y))
-
/*
* Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
*
diff --git a/sys/include/sys/types.h b/sys/include/sys/types.h
index 5cb2fc7..223f455 100644
--- a/sys/include/sys/types.h
+++ b/sys/include/sys/types.h
@@ -82,11 +82,11 @@ typedef __uint64_t uint64_t;
#endif
#if __SIZEOF_SIZE_T__ == 8
-typedef uint64_t __size_t;
-typedef int64_t __ssize_t; /* Byte count or error */
+typedef __uint64_t __size_t;
+typedef __int64_t __ssize_t; /* Byte count or error */
#elif __SIZEOF_SIZE_T__ == 4
-typedef uint32_t __size_t;
-typedef int32_t __ssize_t; /* Byte count or error */
+typedef __uint32_t __size_t;
+typedef __int32_t __ssize_t; /* Byte count or error */
#else
#error "Unsupported size_t size"
#endif
@@ -100,14 +100,15 @@ typedef __size_t uintptr_t;
typedef __size_t off_t;
typedef int pid_t;
typedef int dev_t;
-typedef uint32_t mode_t;
-typedef uint32_t ino_t;
-typedef uint32_t nlink_t;
-typedef uint32_t uid_t;
-typedef uint32_t gid_t;
-typedef uint32_t blksize_t;
-typedef uint32_t blkcnt_t;
-typedef uint64_t time_t;
+typedef __uint32_t uid_t;
+typedef __uint32_t mode_t;
+typedef __uint32_t ino_t;
+typedef __uint32_t nlink_t;
+typedef __uint32_t uid_t;
+typedef __uint32_t gid_t;
+typedef __uint32_t blksize_t;
+typedef __uint32_t blkcnt_t;
+typedef __uint64_t time_t;
#if defined(_HAVE_PTRDIFF_T)
typedef __ptrdiff_t ptrdiff_t;
#endif /* _HAVE_PTRDIFF_T */
diff --git a/sys/include/sys/ucred.h b/sys/include/sys/ucred.h
new file mode 100644
index 0000000..f8cbbe0
--- /dev/null
+++ b/sys/include/sys/ucred.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_UCRED_H_
+#define _SYS_UCRED_H_
+
+#include <sys/types.h>
+#if defined(_KERNEL)
+#include <sys/spinlock.h>
+#include <sys/syscall.h>
+#endif
+
+/*
+ * Kernel structure for user credentials
+ */
+struct ucred {
+ uid_t euid;
+ uid_t ruid;
+#if defined(_KERNEL)
+ struct spinlock lock;
+#endif /* _KERNEL */
+};
+
+int setuid(uid_t new);
+uid_t getuid(void);
+
+#if defined(_KERNEL)
+scret_t sys_setuid(struct syscall_args *scargs);
+scret_t sys_getuid(struct syscall_args *scargs);
+#endif
+#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/include/sys/uio.h b/sys/include/sys/uio.h
new file mode 100644
index 0000000..4318a53
--- /dev/null
+++ b/sys/include/sys/uio.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_UIO_H_
+#define _SYS_UIO_H_
+
+#if defined(_KERNEL)
+#include <sys/types.h>
+#else
+#include <stdint.h>
+#include <stddef.h>
+#endif /* _KERNEL */
+
+/*
+ * POSIX I/O vector
+ */
+struct iovec {
+ void *iov_base;
+ size_t iov_len;
+};
+
+ssize_t readv(int filedes, const struct iovec *iov, int iovcnt);
+ssize_t writev(int filedes, const struct iovec *iov, int iovcnt);
+
+#if defined(_KERNEL)
+
+int uio_copyin(const struct iovec *u_iov, struct iovec *k_iov, int iovcnt);
+int uio_copyout(const struct iovec *k_iov, struct iovec *u_iov, int iovcnt);
+void uio_copyin_clean(struct iovec *copy, int iovcnt);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_UIO_H_ */
diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h
index 1ff722a..fcb7391 100644
--- a/sys/include/sys/vfs.h
+++ b/sys/include/sys/vfs.h
@@ -40,6 +40,7 @@ scret_t sys_close(struct syscall_args *args);
scret_t sys_read(struct syscall_args *scargs);
scret_t sys_write(struct syscall_args *sargs);
scret_t sys_stat(struct syscall_args *scargs);
+scret_t sys_access(struct syscall_args *scargs);
#endif /* _KERNEL */
#endif /* !_SYS_VFS_H_ */
diff --git a/sys/include/sys/vmstat.h b/sys/include/sys/vmstat.h
new file mode 100644
index 0000000..b7faeb2
--- /dev/null
+++ b/sys/include/sys/vmstat.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_VMSTAT_H_
+#define _SYS_VMSTAT_H_
+
+#include <sys/types.h>
+
+/*
+ * Virtual memory statistics
+ *
+ * @mem_avail: Available memory in MiB
+ * @mem_used: Allocated memory in MiB
+ * @mem_total: Total system memory in MiB
+ */
+struct vm_stat {
+ uint32_t mem_avail;
+ uint32_t mem_used;
+ size_t mem_total;
+};
+
+#endif /* !_VM_STAT_H_ */
diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h
index 33092f9..ff6f995 100644
--- a/sys/include/sys/vnode.h
+++ b/sys/include/sys/vnode.h
@@ -32,11 +32,11 @@
#include <sys/types.h>
#include <sys/queue.h>
+#include <sys/vnode.h>
#include <sys/atomic.h>
#include <sys/sio.h>
-#include <vm/vm_obj.h>
-
#if defined(_KERNEL)
+#include <vm/vm_obj.h>
struct vops;
@@ -47,6 +47,8 @@ struct vnode {
const struct vops *vops;
struct vm_object vobj;
uint32_t refcount;
+ dev_t major;
+ dev_t dev;
TAILQ_ENTRY(vnode) vcache_link;
};
@@ -74,6 +76,7 @@ struct vcache {
#define VDIR 0x02 /* Directory */
#define VCHR 0x03 /* Character device */
#define VBLK 0x04 /* Block device */
+#define VSOCK 0x05 /* Socket */
#define VNOVAL -1
@@ -83,6 +86,23 @@ struct vop_lookup_args {
struct vnode **vpp; /* Result vnode */
};
+struct vop_create_args {
+ const char *path; /* Full path */
+ const char *ppath; /* Parent path */
+ struct vnode *dirvp; /* Directory vnode */
+ struct vnode **vpp; /* Result vnode */
+};
+
+struct vop_getattr_args {
+ struct vnode *vp; /* Target vnode */
+ struct vattr *res; /* Result vattr */
+};
+
+struct vop_readdir_args {
+ struct vnode *vp; /* Target vnode */
+ struct sio_txn *sio; /* SIO data to read into */
+};
+
/*
* A field in this structure is unavailable
* if it has a value of VNOVAL.
@@ -92,34 +112,33 @@ struct vattr {
size_t size;
};
-struct vop_getattr_args {
- struct vnode *vp;
- struct vattr *res;
-};
-
struct vops {
int(*lookup)(struct vop_lookup_args *args);
int(*getattr)(struct vop_getattr_args *args);
+ int(*readdir)(struct vop_readdir_args *args);
int(*read)(struct vnode *vp, struct sio_txn *sio);
int(*write)(struct vnode *vp, struct sio_txn *sio);
int(*reclaim)(struct vnode *vp);
+ int(*create)(struct vop_create_args *args);
};
extern struct vnode *g_root_vnode;
+/* Vnode cache operations */
int vfs_vcache_type(void);
int vfs_vcache_migrate(int newtype);
-
int vfs_vcache_enter(struct vnode *vp);
struct vnode *vfs_recycle_vnode(void);
+/* Vnode operations */
int vfs_alloc_vnode(struct vnode **res, int type);
int vfs_release_vnode(struct vnode *vp);
-int vfs_vop_lookup(struct vnode *vp, struct vop_lookup_args *args);
+/* Vnode operation wrappers */
+int vfs_vop_lookup(struct vop_lookup_args *args);
+int vfs_vop_getattr(struct vop_getattr_args *args);
int vfs_vop_read(struct vnode *vp, struct sio_txn *sio);
int vfs_vop_write(struct vnode *vp, struct sio_txn *sio);
-int vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args);
#endif /* _KERNEL */
#endif /* !_SYS_VNODE_H_ */
diff --git a/sys/include/sys/vsr.h b/sys/include/sys/vsr.h
new file mode 100644
index 0000000..e63cce1
--- /dev/null
+++ b/sys/include/sys/vsr.h
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_VSR_H_
+#define _SYS_VSR_H_
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/limits.h>
+#if defined(_KERNEL)
+#include <sys/mutex.h>
+#endif /* _KERNEL */
+
+struct proc;
+
+#define VSR_FILE 0x00000000 /* Represented by file */
+
+/*
+ * Defines the access semantics of whether
+ * r/w operations should be passed down to the
+ * global state or soley affecting a per-process
+ * shallow copy.
+ */
+typedef uint32_t vsr_mode_t;
+
+/*
+ * The Virtual System Resource namespace consists of
+ * domains containing named "capsules". The domain is
+ * simply a table indexed by a type value e.g. VSR_FILE
+ * and a capsule is simply a structure containing global data
+ * as well as a shallow copy which is controlled locally by the
+ * process. The capsule also contains various access semantics
+ * that help the VSR subsystem determine whether the access should
+ * be passed down globally or virtualized locally within the process.
+ */
+typedef uint8_t vsr_domain_t;
+
+/*
+ * VSR mode bits
+ */
+#define VSR_GLOB_WRITE BIT(0) /* Writes are global */
+#define VSR_GLOB_READ BIT(1) /* Reads are global */
+#define VSR_GLOB_CRED BIT(2) /* Global for specific creds */
+
+#if defined(_KERNEL)
+
+struct vsr_capsule;
+
+/*
+ * VSR capsule operations
+ *
+ * @reclaim: Cleanup resources
+ */
+struct capsule_ops {
+ int(*reclaim)(struct vsr_capsule *cap, int flags);
+};
+
+/*
+ * Virtual system resource access
+ * semantics.
+ *
+ * @glob: Global data
+ * @shallow: Local per process copy
+ * @mode: VSR mode (see VSR_GLOB_*)
+ * @cred: Creds (used if VSR_GLOBAL_CRED set)
+ */
+struct vsr_access {
+ void *glob;
+ void *shallow;
+ vsr_mode_t mode;
+ struct ucred cred;
+};
+
+/*
+ * A virtual system resource capsule containing
+ * resource owner specific data and hashmap
+ * buckets.
+ *
+ * @name: Capsule name (e.g., "consfeat"), must be freed
+ * @data: Owner specific data
+ * @shadow: Local shadow copy (per-process)
+ * @buckets: Hashmap buckets
+ * @link: Bucket link
+ * @ops: Capsule operations
+ * @lock: Mutex lock protecting fields
+ */
+struct vsr_capsule {
+ char *name;
+ void *data;
+ void *shadow;
+ TAILQ_HEAD(, vsr_capsule) buckets;
+ TAILQ_ENTRY(vsr_capsule) link;
+ struct capsule_ops ops;
+ struct mutex lock;
+};
+
+/*
+ * Virtual system resource table containg
+ * VSRs for various types.
+ *
+ * Each VSR table belongs to a VSR domain
+ * (e.g., VSR_FILE).
+ *
+ * @ncaps: Number of capsules
+ * @is_init: Set if hashmap is set up
+ * @capsules: VSR capsule hashmap
+ */
+struct vsr_table {
+ struct vsr_capsule *capsules[VSR_MAX_CAPSULE];
+};
+
+/*
+ * Virtual system resource domain (VSR).
+ *
+ * A VSR is represented by a specific VSR type
+ * (see VSR_*). Each VSR has a table of VSR capsules
+ * looked up by a VSR capsule name.
+ *
+ * One per process.
+ *
+ * @type: VSR type
+ * @table: VSR table
+ */
+struct vsr_domain {
+ int type;
+ struct vsr_table table;
+};
+
+void vsr_init_domains(struct proc *td);
+void vsr_destroy_domains(struct proc *td);
+
+struct vsr_domain *vsr_new_domain(struct proc *td, vsr_domain_t type);
+struct vsr_capsule *vsr_new_capsule(struct proc *td, vsr_domain_t type, const char *name);
+struct vsr_capsule *vsr_lookup_capsule(struct proc *td, vsr_domain_t type, const char *name);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_VSR_H_ */
diff --git a/sys/include/sys/wait.h b/sys/include/sys/wait.h
new file mode 100644
index 0000000..07a2d4e
--- /dev/null
+++ b/sys/include/sys/wait.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_WAIT_H_
+#define _SYS_WAIT_H_
+
+#include <sys/types.h>
+
+pid_t waitpid(pid_t pid, int *wstatus, int options);
+
+#endif /* !_SYS_WAIT_H_ */
diff --git a/sys/include/sys/workqueue.h b/sys/include/sys/workqueue.h
new file mode 100644
index 0000000..9925f79
--- /dev/null
+++ b/sys/include/sys/workqueue.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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_WORKQUEUE_H_
+#define _SYS_WORKQUEUE_H_
+
+#if defined(_KERNEL)
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+
+struct workqueue;
+struct work;
+
+/*
+ * A work function can either refer to a work thread
+ * entry (or actual work to be done
+ */
+typedef void(*workfunc_t)(struct workqueue *wqp, struct work *wp);
+
+/*
+ * Represents work that may be added to a
+ * workqueue.
+ *
+ * @name: Name of this work/task [i]
+ * @data: Optional data to be passed with work [p]
+ * @func: Function with work to be done [p]
+ * @cookie: Used for validating the work structure [i]
+ *
+ * Field attributes:
+ * - [i]: Used internally
+ * - [p]: Used as parameter
+ */
+struct work {
+ char *name;
+ void *data;
+ workfunc_t func;
+ TAILQ_ENTRY(work) link;
+};
+
+/*
+ * A workqueue contains tasks that are
+ * queued up to be completed in their own
+ * thread context.
+ *
+ * @name: Name of workqueue.
+ * @work: Start of the workqueue
+ * @ipl: IPL that work here must run with
+ * @max_work: Max number of jobs that can be queued
+ * @nwork: Number of tasks to be done
+ * @cookie: For validating workqueues
+ * @worktd: Thread associated with the workqueue
+ * @lock: Protects the workqueue
+ */
+struct workqueue {
+ char *name;
+ TAILQ_HEAD(, work) work;
+ uint8_t ipl;
+ size_t max_work;
+ ssize_t nwork;
+ uint16_t cookie;
+ struct proc *worktd;
+ struct mutex *lock;
+};
+
+struct workqueue *workqueue_new(const char *name, size_t max_work, int ipl);
+
+int workqueue_enq(struct workqueue *wqp, const char *name, struct work *wp);
+int workqueue_destroy(struct workqueue *wqp);
+int work_destroy(struct work *wp);
+
+#endif /* !_KERNEL */
+#endif /* !_SYS_WORKQUEUE_H_ */
diff --git a/sys/include/vm/physmem.h b/sys/include/vm/physmem.h
index ae11530..3f1da61 100644
--- a/sys/include/vm/physmem.h
+++ b/sys/include/vm/physmem.h
@@ -32,6 +32,10 @@
#include <sys/types.h>
+uint32_t vm_mem_used(void);
+uint32_t vm_mem_free(void);
+size_t vm_mem_total(void);
+
void vm_physmem_init(void);
uintptr_t vm_alloc_frame(size_t count);
void vm_free_frame(uintptr_t base, size_t count);
diff --git a/sys/include/vm/pmap.h b/sys/include/vm/pmap.h
index 9eed184..e0549d4 100644
--- a/sys/include/vm/pmap.h
+++ b/sys/include/vm/pmap.h
@@ -76,9 +76,25 @@ int pmap_map(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot);
int pmap_unmap(struct vas vas, vaddr_t va);
/*
+ * Returns true if the page is clean (modified), otherwise
+ * returns false.
+ */
+bool pmap_is_clean(struct vas vas, vaddr_t va);
+
+/*
+ * Marks a page as clean (unmodified)
+ */
+void pmap_mark_clean(struct vas vas, vaddr_t va);
+
+/*
* Mark a virtual address with a specific
* caching type.
*/
int pmap_set_cache(struct vas vas, vaddr_t va, int type);
+/*
+ * Machine dependent pmap init code.
+ */
+int pmap_init(void);
+
#endif /* !_VM_PMAP_H_ */
diff --git a/sys/include/vm/stat.h b/sys/include/vm/stat.h
new file mode 100644
index 0000000..7e9a4a9
--- /dev/null
+++ b/sys/include/vm/stat.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _VM_STAT_H_
+#define _VM_STAT_H_
+
+#include <sys/types.h>
+#include <sys/vmstat.h>
+
+int vm_stat_get(struct vm_stat *vmstat);
+void vm_stat_init(void);
+
+#endif /* !_VM_STAT_H_ */
diff --git a/sys/include/vm/vm_device.h b/sys/include/vm/vm_device.h
new file mode 100644
index 0000000..da476e2
--- /dev/null
+++ b/sys/include/vm/vm_device.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * 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 Hyra 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 _VM_DEVICE_H_
+#define _VM_DEVICE_H_
+
+#include <sys/types.h>
+#include <sys/vnode.h>
+#include <sys/device.h>
+#include <vm/vm_pager.h>
+#include <vm/vm_obj.h>
+
+extern const struct vm_pagerops vm_vnops;
+
+struct vm_object *dv_attach(devmajor_t major, dev_t dev, vm_prot_t prot);
+
+#endif /* !_VM_DEVICE_H_ */
diff --git a/sys/include/vm/vm_pager.h b/sys/include/vm/vm_pager.h
index e0503e0..4732234 100644
--- a/sys/include/vm/vm_pager.h
+++ b/sys/include/vm/vm_pager.h
@@ -40,7 +40,6 @@ struct vm_pagerops;
extern const struct vm_pagerops vm_vnops;
extern const struct vm_pagerops vm_anonops;
-
/*
* Pager operations.
*