diff options
Diffstat (limited to 'sys/include')
66 files changed, 1881 insertions, 134 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/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/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..0a20324 100644 --- a/sys/include/arch/amd64/cdefs.h +++ b/sys/include/arch/amd64/cdefs.h @@ -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() __ASMV("hlt") /* 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..46e5df7 100644 --- a/sys/include/arch/amd64/cpu.h +++ b/sys/include/arch/amd64/cpu.h @@ -33,18 +33,27 @@ #include <sys/types.h> #include <sys/cdefs.h> #include <sys/proc.h> +#include <sys/spinlock.h> #include <machine/tss.h> #define CPU_IRQ(IRQ_N) (BIT((IRQ_N)) & 0xFF) +/* Feature bits */ +#define CPU_FEAT_SMAP BIT(0) +#define CPU_FEAT_SMEP BIT(1) + struct cpu_info { uint32_t apicid; + uint32_t feat; uint8_t has_x2apic : 1; + uint8_t tlb_shootdown : 1; uint8_t ipl; size_t lapic_tmr_freq; uint8_t irq_mask; + vaddr_t shootdown_va; struct tss_entry *tss; struct proc *curtd; + struct spinlock lock; struct cpu_info *self; }; @@ -52,6 +61,13 @@ __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); +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); diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h index c6316a5..4dc075e 100644 --- a/sys/include/arch/amd64/frameasm.h +++ b/sys/include/arch/amd64/frameasm.h @@ -30,6 +30,8 @@ #ifndef _MACHINE_FRAMEASM_H_ #define _MACHINE_FRAMEASM_H_ +#define ALIGN_TEXT .align 8, 0x90 + /* * If the interrupt has an error code, this macro shall * be used to create the trapframe. diff --git a/sys/include/arch/amd64/gdt.h b/sys/include/arch/amd64/gdt.h index 55666a7..0c5faf1 100644 --- a/sys/include/arch/amd64/gdt.h +++ b/sys/include/arch/amd64/gdt.h @@ -4,18 +4,48 @@ #include <sys/types.h> #include <sys/cdefs.h> +#define GDT_TSS_INDEX 5 +#define GDT_ENTRY_COUNT 7 + +/* Segment selectors */ #define KERNEL_CS 0x08 #define KERNEL_DS 0x10 -#define USER_CS 0x18 -#define USER_DS 0x20 -#define GDT_TSS 5 +#define USER_CS 0x18 +#define USER_DS 0x20 + +/* + * Bit definitions for regular segment descriptors + * + * See Intel SPG 3/25 Section 3.4.5 - Segment Descriptors + */ + +#define GDT_ATTRIBUTE_ACCESSED BIT(0) /* Accessed */ +#define GDT_ATTRIBUTE_EXECUTABLE BIT(3) /* Executable */ +#define GDT_ATTRIBUTE_NONSYSTEM BIT(4) /* Code/data */ +#define GDT_ATTRIBUTE_PRESENT BIT(7) /* Present */ +#define GDT_ATTRIBUTE_64BIT_CODE BIT(13) /* 64-bit code */ +#define GDT_ATTRIBUTE_32BIT BIT(14) /* 32-bit code/data */ +#define GDT_ATTRIBUTE_GRANULARITY BIT(15) /* 4KiB limit granularity */ + +/* Attributes for executable segments */ +#define GDT_ATTRIBUTE_READABLE BIT(1) /* Readable */ +#define GDT_ATTRIBUTE_CONFORMING BIT(2) /* Conforming */ + +/* Attributes for non-executable segments */ +#define GDT_ATTRIBUTE_WRITABLE BIT(1) /* Writable */ +#define GDT_ATTRIBUTE_EXPANDS_DOWN BIT(2) /* See SPG 3/25 Section 6.8.1 */ + +/* DPL (Descriptor Privilege Level) specifier */ +#define GDT_ATTRIBUTE_DPL0 0 +#define GDT_ATTRIBUTE_DPL1 (1 << 5) +#define GDT_ATTRIBUTE_DPL2 (2 << 5) +#define GDT_ATTRIBUTE_DPL3 (3 << 5) struct __packed gdt_entry { uint16_t limit; uint16_t base_low; uint8_t base_mid; - uint8_t access; - uint8_t granularity; + uint16_t attributes; uint8_t base_hi; }; @@ -24,27 +54,28 @@ struct __packed gdtr { uintptr_t offset; }; +extern struct gdt_entry g_gdt_data[GDT_ENTRY_COUNT]; +extern const struct gdtr g_gdtr; + __always_inline static inline void -gdt_load(struct gdtr *gdtr) +gdt_load(void) { __ASMV("lgdt %0\n" - "push $8\n" /* Push CS */ - "lea 1f(%%rip), %%rax\n" /* Load 1 label address into RAX */ - "push %%rax\n" /* Push the return address (label 1) */ - "lretq\n" /* Far return to update CS */ + "push %1\n" /* Push code segment selector */ + "lea 1f(%%rip), %%rax\n" /* Load label 1 address into RAX */ + "push %%rax\n" /* Push return address (label 1) */ + "lretq\n" /* Far return to update CS */ "1:\n" - " mov $0x10, %%eax\n" - " mov %%eax, %%ds\n" - " mov %%eax, %%es\n" - " mov %%eax, %%fs\n" - " mov %%eax, %%gs\n" - " mov %%eax, %%ss\n" + " mov %2, %%ax\n" /* Load data segment selectors */ + " mov %%ax, %%ds\n" + " mov %%ax, %%es\n" + " mov %%ax, %%fs\n" + " mov %%ax, %%gs\n" + " mov %%ax, %%ss\n" : - : "m" (*gdtr) + : "m" (g_gdtr), "i"(KERNEL_CS), "i"(KERNEL_DS) : "rax", "memory" ); } -extern struct gdt_entry g_gdt_data[256]; - #endif /* !AMD64_GDT_H_ */ diff --git a/sys/include/arch/amd64/intr.h b/sys/include/arch/amd64/intr.h index c643945..c848b6f 100644 --- a/sys/include/arch/amd64/intr.h +++ b/sys/include/arch/amd64/intr.h @@ -47,11 +47,59 @@ #define IPL_CLOCK 2 /* Clock */ #define IPL_HIGH 3 /* Defer everything */ -struct intr_entry { +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; + }; +}; + +/* + * Interrupt handler + * + * [r]: Required for intr_register() + * [o]: Not required for intr_register() + * [v]: Returned by intr_register() + * + * @func: The actual handler [r] + * @data: Interrupt data [o/v] + * @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. + * + * XXX: `func` must be the first field in this + * structure so that it may be called through + * assembly. + * + * XXX: `ist' should usually be set to -1 but can be + * used if an interrupt requires its own stack. + */ +struct intr_hand { + int(*func)(void *); + struct intr_data data; + char *name; int priority; + int irq; + int vector; }; -int intr_alloc_vector(const char *name, uint8_t priority); +void *intr_register(const char *name, const struct intr_hand *ih); + int splraise(uint8_t s); void splx(uint8_t s); diff --git a/sys/include/arch/amd64/isa/i8042var.h b/sys/include/arch/amd64/isa/i8042var.h index ebd96ad..13c3095 100644 --- a/sys/include/arch/amd64/isa/i8042var.h +++ b/sys/include/arch/amd64/isa/i8042var.h @@ -82,7 +82,5 @@ void i8042_quirk(int mask); /* Internal - do not use */ void i8042_sync(void); -void i8042_kb_isr(void); -void i8042_kb_event(void); #endif /* _I8042VAR_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/dev/acpi/tables.h b/sys/include/dev/acpi/tables.h index 5215c86..5340c7f 100644 --- a/sys/include/dev/acpi/tables.h +++ b/sys/include/dev/acpi/tables.h @@ -132,4 +132,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/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..c82c3c5 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,10 @@ struct cons_char { struct cons_screen { struct fbdev fbdev; + struct ansi_state ansi_s; + struct console_feat feat; /* Features */ + struct proc *atproc; /* Attached proc */ + struct mutex *atproc_lock; uint32_t fg; uint32_t bg; @@ -64,7 +72,14 @@ struct cons_screen { 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..d24397a --- /dev/null +++ b/sys/include/dev/dmi/dmi.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 _DMI_DMI_H_ +#define _DMI_DMI_H_ + +#include <sys/types.h> + +const char *dmi_vendor(void); +const char *dmi_prodver(void); +const char *dmi_product(void); +const char *dmi_cpu_manufact(void); + +#endif /* !_DMI_DMI_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 fa24812..67f2efe 100644 --- a/sys/include/dev/ic/ahcivar.h +++ b/sys/include/dev/ic/ahcivar.h @@ -33,9 +33,12 @@ #include <sys/param.h> #include <sys/types.h> #include <sys/device.h> +#include <dev/dcdr/cache.h> #include <dev/ic/ahciregs.h> #include <fs/ctlfs.h> +#define AHCI_DCDR_CAP 16 + struct ahci_cmd_hdr; extern const struct ctlops g_sata_bsize_ops; @@ -93,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. */ @@ -100,6 +104,8 @@ struct hba_device { struct hba_port *io; 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/pci/pci.h b/sys/include/dev/pci/pci.h index de6d8fb..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; @@ -75,7 +76,7 @@ struct pci_device { struct msi_intr { const char *name; - void(*handler)(void *); + int(*handler)(void *); }; pcireg_t pci_readl(struct pci_device *dev, uint32_t offset); 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/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/timer.h b/sys/include/dev/timer.h index e54adcc..fe91323 100644 --- a/sys/include/dev/timer.h +++ b/sys/include/dev/timer.h @@ -69,6 +69,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); diff --git a/sys/include/dev/usb/xhciregs.h b/sys/include/dev/usb/xhciregs.h index 69515e4..1cbfd14 100644 --- a/sys/include/dev/usb/xhciregs.h +++ b/sys/include/dev/usb/xhciregs.h @@ -98,6 +98,13 @@ struct xhci_opregs { #define XHCI_RTS(BASE, RTSOFF) PTR_OFFSET(BASE, RTSOFF) #define XHCI_CMD_DB(BASE, DBOFF) PTR_OFFSET(BASE, DBOFF) +/* Runtime register offsets */ +#define XHCI_RT_IMAN 0x20 +#define XHCI_RT_IMOD 0x24 +#define XHCI_RT_ERSTSZ 0x28 +#define XHCI_RT_ERSTBA 0x30 +#define XHCI_RT_ERDP 0x38 + /* Support protocol cap fields */ #define XHCI_PROTO_ID(PROTO) (PROTO & 0xFF) #define XHCI_PROTO_MINOR(PROTO) ((PROTO >> 16) & 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/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/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..33ba06f --- /dev/null +++ b/sys/include/net/netbuf.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 _NET_NETBUF_H_ +#define _NET_NETBUF_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/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/sys/console.h b/sys/include/sys/console.h new file mode 100644 index 0000000..c912d28 --- /dev/null +++ b/sys/include/sys/console.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_CONSOLE_H_ +#define _SYS_CONSOLE_H_ + +#include <sys/types.h> + +/* + * Console features + * + * @ansi_esc: If 1, ANSI escape codes are enabled + * @show_curs: If 1, show the cursor + */ +struct console_feat { + uint8_t ansi_esc : 1; + uint8_t show_curs : 1; +}; + +#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/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/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/net/if_ether.h b/sys/include/sys/endian.h index a8fcfa5..5cbc94a 100644 --- a/sys/include/net/if_ether.h +++ b/sys/include/sys/endian.h @@ -27,48 +27,28 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _IF_ETHER_H_ -#define _IF_ETHER_H_ +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ #include <sys/cdefs.h> #include <sys/types.h> -#include <net/if.h> -#define MACADDR_LEN 6 +#define swap16(x) __swap16((x)) +#define swap32(x) __swap32((x)) -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 */ -}; +__always_inline static inline uint16_t +__swap16(uint16_t x) +{ + return ((x << 8) & 0xFF00) | ((x >> 8) & 0x00FF); +} -/* - * Used by the driver to buffer packets. - */ -struct etherbuf { - struct ether_frame *frp; - off_t head; - off_t tail; - size_t cap; /* In entries */ -}; - -/* - * Ethernet device - * - * if_ether: E - * driver: D - * - * @if_name: Interface name. - * @tx: Transmit packets (D->E) - */ -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]; -}; +__always_inline static inline uint32_t +__swap32(uint32_t x) +{ + return ((x << 24) & 0xFF000000) | + ((x << 8) & 0x00FF0000) | + ((x >> 8) & 0x0000FF00) | + ((x >> 24) & 0x000000FF); +} -#endif /* !_IF_ETHER_H_ */ +#endif /* !_SYS_ENDIAN_H_ */ diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h index 7e720fc..aa2a729 100644 --- a/sys/include/sys/exec.h +++ b/sys/include/sys/exec.h @@ -32,7 +32,6 @@ #include <sys/types.h> -#if defined(_KERNEL) /* Danger: Do not change these !! */ #define AT_NULL 0 @@ -45,7 +44,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..4ce2db2 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; @@ -50,8 +57,12 @@ int fd_write(unsigned int fd, void *buf, size_t count); int fd_alloc(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(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..f56958e 100644 --- a/sys/include/sys/limits.h +++ b/sys/include/sys/limits.h @@ -32,6 +32,9 @@ #define PATH_MAX 1024 #define SSIZE_MAX 32767 +#define ARG_MAX 4096 #define CHAR_BIT 8 - +#if defined(_KERNEL) +#define CPU_MAX 256 +#endif /* _KERNEL */ #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/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..7331d5f 100644 --- a/sys/include/sys/param.h +++ b/sys/include/sys/param.h @@ -67,8 +67,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..54764d0 100644 --- a/sys/include/sys/proc.h +++ b/sys/include/sys/proc.h @@ -53,6 +53,26 @@ #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; +}; + struct proc { pid_t pid; struct exec_prog exec; @@ -64,11 +84,11 @@ struct proc { struct trapframe tf; struct pcb pcb; struct proc *parent; - void *spawn_data; + 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 +103,31 @@ 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 */ struct proc *this_td(void); struct proc *get_child(struct proc *cur, pid_t pid); + +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); + 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/sched.h b/sys/include/sys/sched.h index 80f4d1c..7d17607 100644 --- a/sys/include/sys/sched.h +++ b/sys/include/sys/sched.h @@ -37,6 +37,8 @@ void sched_init(void); void sched_yield(void); + +void sched_switch_to(struct trapframe *tf, struct proc *td); void sched_detach(struct proc *td); __dead void sched_enter(void); diff --git a/sys/include/sys/spawn.h b/sys/include/sys/spawn.h index 3828d5c..0c54e4c 100644 --- a/sys/include/sys/spawn.h +++ b/sys/include/sys/spawn.h @@ -31,8 +31,11 @@ #define _SYS_SPAWN_H_ #include <sys/types.h> +#include <sys/param.h> + +#define SPAWN_WAIT BIT(0) #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/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..3650e7a 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -48,6 +48,14 @@ #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 #if defined(_KERNEL) /* Syscall return value and arg type */ 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/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/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/vnode.h b/sys/include/sys/vnode.h index 33092f9..b135433 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; }; @@ -83,6 +85,13 @@ 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 */ +}; + /* * A field in this structure is unavailable * if it has a value of VNOVAL. @@ -103,6 +112,7 @@ struct vops { 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; 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/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_ */ |