summaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/arch/amd64/frame.h116
-rw-r--r--sys/include/arch/amd64/gdt.h80
-rw-r--r--sys/include/arch/amd64/idt.h72
-rw-r--r--sys/include/arch/amd64/trap.h78
-rw-r--r--sys/include/dev/video/fbdev.h52
-rw-r--r--sys/include/lib/bitmap.h58
-rw-r--r--sys/include/lib/logo.h41
-rw-r--r--sys/include/lib/stdarg.h46
-rw-r--r--sys/include/lib/string.h44
-rw-r--r--sys/include/lib/tty_font.h42
-rw-r--r--sys/include/sys/ascii.h47
-rw-r--r--sys/include/sys/cdefs.h141
-rw-r--r--sys/include/sys/errno.h37
-rw-r--r--sys/include/sys/limine.h497
-rw-r--r--sys/include/sys/machdep.h53
-rw-r--r--sys/include/sys/panic.h43
-rw-r--r--sys/include/sys/queue.h161
-rw-r--r--sys/include/sys/spinlock.h53
-rw-r--r--sys/include/sys/syslog.h53
-rw-r--r--sys/include/sys/termios.h62
-rw-r--r--sys/include/sys/tty.h123
-rw-r--r--sys/include/sys/types.h71
-rw-r--r--sys/include/vm/vm.h45
-rw-r--r--sys/include/vm/vm_physseg.h37
24 files changed, 2052 insertions, 0 deletions
diff --git a/sys/include/arch/amd64/frame.h b/sys/include/arch/amd64/frame.h
new file mode 100644
index 0000000..6239eff
--- /dev/null
+++ b/sys/include/arch/amd64/frame.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _AMD64_FRAME_H_
+#define _AMD64_FRAME_H_
+
+#if !defined(__ASSEMBLER__)
+struct trapframe {
+ uint64_t trapno;
+ uint64_t rax;
+ uint64_t rcx;
+ uint64_t rdx;
+ uint64_t rbx;
+ uint64_t rsi;
+ uint64_t rdi;
+ uint64_t rbp;
+ uint64_t r8;
+ uint64_t r9;
+ uint64_t r10;
+ uint64_t r11;
+ uint64_t r12;
+ uint64_t r13;
+ uint64_t r14;
+ uint64_t r15;
+ /* Pushed by hardware */
+ uint64_t error_code;
+ uint64_t rip;
+ uint64_t cs;
+ uint64_t rflags;
+ uint64_t rsp;
+ uint64_t ss;
+};
+#else
+/*
+ * XXX: Before this macro is invoked,
+ * you should determine if an error
+ * code will be present already on the
+ * stack. If not, push a null qword as
+ * padding (e.g push $0).
+ *
+ * There *must* be a value used
+ * as an error code whether that be
+ * a real error code or just padding.
+ *
+ * Failing to do so will result in
+ * undefined behaviour.
+ *
+ */
+.macro push_trapframe trapno
+ push %r15
+ push %r14
+ push %r13
+ push %r12
+ push %r11
+ push %r10
+ push %r9
+ push %r8
+ push %rbp
+ push %rdi
+ push %rsi
+ push %rbx
+ push %rdx
+ push %rcx
+ push %rax
+ push \trapno
+.endm
+
+.macro pop_trapframe trapno
+ add $8, %rsp /* Trapno */
+ pop %rax
+ pop %rcx
+ pop %rdx
+ pop %rbx
+ pop %rsi
+ pop %rdi
+ pop %rbp
+ pop %r8
+ pop %r9
+ pop %r10
+ pop %r12
+ pop %r13
+ pop %r14
+ pop %r15
+ add $8, %rsp /* Pop error code */
+ iretq
+.endm
+#endif /* !defined(__ASSEMBLER__) */
+#endif /* !_AMD64_FRAME_H_ */
diff --git a/sys/include/arch/amd64/gdt.h b/sys/include/arch/amd64/gdt.h
new file mode 100644
index 0000000..756e2a6
--- /dev/null
+++ b/sys/include/arch/amd64/gdt.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef AMD64_GDT_H_
+#define AMD64_GDT_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+#define GDT_TSS 5
+#define KERNEL_CS 0x8
+#define KERNEL_DS 0x10
+
+struct __packed gdt_entry {
+ uint16_t limit;
+ uint16_t base_low;
+ uint8_t base_mid;
+ uint8_t access;
+ uint8_t granularity;
+ uint8_t base_hi;
+};
+
+struct __packed gdtr {
+ uint16_t limit;
+ uintptr_t offset;
+};
+
+static inline void
+gdt_load(struct gdtr *gdtr)
+{
+ __asm("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 */
+ "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"
+ :
+ : "m" (*gdtr)
+ : "rax", "memory"
+ );
+}
+
+extern struct gdt_entry g_dmmy_gdt[256];
+extern struct gdtr g_early_gdtr;
+
+#endif /* !AMD64_GDT_H_ */
diff --git a/sys/include/arch/amd64/idt.h b/sys/include/arch/amd64/idt.h
new file mode 100644
index 0000000..d3b623d
--- /dev/null
+++ b/sys/include/arch/amd64/idt.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _AMD64_IDT_H_
+#define _AMD64_IDT_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+#define LIDT(idtr) __ASMV("lidt %0" \
+ :: "m" (idtr))
+
+#define IDT_TRAP_GATE_FLAGS 0x8F
+#define IDT_INT_GATE_FLAGS 0x8E
+#define IDT_INT_GATE_USER 0xEE
+
+/*
+ * AMD64 Interrupt Gate Descriptor.
+ */
+struct idt_entry {
+ uint16_t off_lo; /* Low 16 bits of ISR offset */
+ uint16_t segsel; /* Segment selector, hardcode to kernel CS */
+ uint8_t ist : 2; /* Interrupt stack table */
+ uint8_t zero : 1; /* Unused: keep zero */
+ uint8_t zero1 : 4; /* Unused: keep zero */
+ uint8_t type : 4; /* Gate type */
+ uint8_t zero2 : 1; /* Unused: keep zero */
+ uint8_t dpl : 2; /* Descriptor privilege level */
+ uint8_t p : 1; /* Present (keep 1 to mark as valid) */
+ uint16_t off_mid; /* Middle 16 bits of ISR offset */
+ uint32_t off_hi; /* High 32-bits of ISR offset */
+ uint32_t reserved; /* Reserved: keep zero */
+};
+
+struct __packed idtr {
+ uint16_t limit;
+ uintptr_t offset;
+};
+
+
+void idt_set_desc(uint8_t vec, uint8_t type, uintptr_t isr, uint8_t ist);
+void idt_load(void);
+
+#endif /* !_AMD64_IDT_H_ */
diff --git a/sys/include/arch/amd64/trap.h b/sys/include/arch/amd64/trap.h
new file mode 100644
index 0000000..e72ae11
--- /dev/null
+++ b/sys/include/arch/amd64/trap.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _AMD64_TRAP_H_
+#define _AMD64_TRAP_H_
+
+#if !defined(__ASSEMBLER__)
+#include <sys/types.h>
+#include <machine/frame.h>
+#endif /* !defined(__ASSEMBLER__) */
+
+#define TRAP_BREAKPOINT 0 /* Breakpoint */
+#define TRAP_ARITH_ERR 1 /* Arithmetic error (e.g division by 0) */
+#define TRAP_OVERFLOW 2 /* Overflow */
+#define TRAP_BOUND_RANGE 3 /* BOUND range exceeded */
+#define TRAP_INVLOP 4 /* Invalid opcode */
+#define TRAP_DOUBLE_FAULT 5 /* Double fault */
+#define TRAP_INVLTSS 6 /* Invalid TSS */
+#define TRAP_SEGNP 7 /* Segment not present */
+#define TRAP_PROTFLT 8 /* General protection */
+#define TRAP_PAGEFLT 9 /* Page fault */
+#define TRAP_NMI 10 /* Non-maskable interrupt */
+
+/* Trap is coming from user mode */
+#define TRAP_USER 0x100
+
+#if !defined(__ASSEMBLER__)
+typedef void(*ftrap_handler_t)(void);
+
+void breakpoint_handler(void *sf);
+void arith_err(void *sf);
+void overflow(void *sf);
+void bound_range(void *sf);
+void invl_op(void *sf);
+void double_fault(void *sf);
+void invl_tss(void *sf);
+void segnp(void *sf);
+void general_prot(void *sf);
+void page_fault(void *sf);
+void nmi(void *sf);
+void register_ftrap_handler(ftrap_handler_t handler);
+void trap_handler(struct trapframe *tf);
+#else
+.macro handle_trap
+ mov %rsp, %rdi
+ call trap_handler
+.endm
+#endif /* !defined(__ASSEMBLER__) */
+
+#endif /* !_AMD64_TRAP_H_ */
diff --git a/sys/include/dev/video/fbdev.h b/sys/include/dev/video/fbdev.h
new file mode 100644
index 0000000..23cc10a
--- /dev/null
+++ b/sys/include/dev/video/fbdev.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _FBDEV_H_
+#define _FBDEV_H_
+
+#include <sys/types.h>
+
+struct fbdev {
+ void *mem;
+ uint32_t width;
+ uint32_t height;
+ uint32_t pitch;
+};
+
+static inline size_t
+fbdev_get_index(const struct fbdev *fbdev, uint32_t x, uint32_t y)
+{
+ return x + y * (fbdev->pitch/4);
+}
+
+struct fbdev fbdev_get_front(void);
+
+#endif /* !_FBDEV_H_ */
diff --git a/sys/include/lib/bitmap.h b/sys/include/lib/bitmap.h
new file mode 100644
index 0000000..98c677e
--- /dev/null
+++ b/sys/include/lib/bitmap.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _LIB_BITMAP_H_
+#define _LIB_BITMAP_H_
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+typedef uint8_t *bitmap_t;
+
+static inline void
+bitmap_set_bit(bitmap_t bitmap, size_t bit)
+{
+ bitmap[bit / 8] |= __BIT(bit % 8);
+}
+
+static inline void
+bitmap_unset_bit(bitmap_t bitmap, size_t bit)
+{
+ bitmap[bit / 8] &= ~(__BIT(bit % 8));
+}
+
+static inline bool
+bitmap_test_bit(bitmap_t bitmap, size_t bit)
+{
+ return __TEST(bitmap[bit / 8], __BIT(bit % 8));
+}
+
+#endif /* !_LIB_BITMAP_H_ */
diff --git a/sys/include/lib/logo.h b/sys/include/lib/logo.h
new file mode 100644
index 0000000..77e90aa
--- /dev/null
+++ b/sys/include/lib/logo.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#include <sys/types.h>
+#include <sys/syslog.h>
+
+#define COPYRIGHT "Copyright (c) 2023 Ian Marco Moffett and the VegaOS team."
+
+#define PRINT_LOGO() \
+ kprintf("%s v%s\n\n", g_logo, VEGA_VERSION); \
+ kprintf("\t%s\n\n", COPYRIGHT);
+
+extern uint8_t g_logo[];
diff --git a/sys/include/lib/stdarg.h b/sys/include/lib/stdarg.h
new file mode 100644
index 0000000..6676de8
--- /dev/null
+++ b/sys/include/lib/stdarg.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _LIB_STDARG_H_
+#define _LIB_STDARG_H_
+
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST
+typedef __builtin_va_list __gnuc_va_list;
+#endif /* __GNUC_VA_LIST */
+
+typedef __gnuc_va_list va_list;
+
+#define va_start(ap, last) __builtin_va_start((ap), last)
+#define va_end(ap) __builtin_va_end((ap))
+#define va_arg(ap, type) __builtin_va_arg((ap), type)
+
+#endif /* !_LIB_STDARG_H_ */
diff --git a/sys/include/lib/string.h b/sys/include/lib/string.h
new file mode 100644
index 0000000..490ae1a
--- /dev/null
+++ b/sys/include/lib/string.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _LIB_STRING_H_
+#define _LIB_STRING_H_
+
+#include <sys/types.h>
+
+size_t strlen(const char *s);
+char *itoa(int64_t value, char *buf, int base);
+void *memmove(void *s1, const void *s2, size_t n);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memcpy32(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+
+#endif /* !_LIB_STRING_H_ */
diff --git a/sys/include/lib/tty_font.h b/sys/include/lib/tty_font.h
new file mode 100644
index 0000000..7dacf4c
--- /dev/null
+++ b/sys/include/lib/tty_font.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _LIB_TTY_FONT_H_
+#define _LIB_TTY_FONT_H_
+
+#include <sys/types.h>
+
+#define FONT_WIDTH 8
+#define FONT_HEIGHT 16
+
+extern const uint8_t DEFAULT_FONT_DATA[];
+
+#endif /* !_LIB_TTY_FONT_H_ */
diff --git a/sys/include/sys/ascii.h b/sys/include/sys/ascii.h
new file mode 100644
index 0000000..dc4cd86
--- /dev/null
+++ b/sys/include/sys/ascii.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_ASCII_H_
+#define _SYS_ASCII_H_
+
+#define ASCII_NUL 0x00 /* Nul */
+#define ASCII_BEL 0x07 /* Bell */
+#define ASCII_BS 0x08 /* Backspace */
+#define ASCII_HT 0x09 /* Horizontal tab */
+#define ASCII_LF 0x0A /* Line feed */
+#define ASCII_VT 0x0B /* Vertical tab */
+#define ASCII_FF 0x0C /* Form feed */
+#define ASCII_CR 0x0D /* Carriage return */
+#define ASCII_SO 0x0E /* Shift out */
+#define ASCII_SI 0x0F /* Shift in */
+#define ASCII_ESC 0x1B /* Escape */
+
+#endif
diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h
new file mode 100644
index 0000000..b57be39
--- /dev/null
+++ b/sys/include/sys/cdefs.h
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_CDEFS_H_
+#define _SYS_CDEFS_H_
+
+#if !defined(__ASSEMBLER__)
+
+/* Misc helpers */
+#define __attr(x) __attribute__((x))
+#define __used __attr(used)
+#define __weak __attr(weak)
+#define __used __attr(used)
+
+/* __BIT(n): Set nth bit, where __BIT(0) == 0x1 */
+#define __BIT(n) (1ULL << n)
+
+/* MASK(n): Sets first n bits, where __MASK(2) == 0b11 */
+#define __MASK(n) (__BIT(n) - 1)
+
+/* Max/min helpers */
+#define __MIN(a, b) ((a <= b) ? (a) : (b))
+#define __MAX(a, b) ((a >= b) ? (a) : (b))
+
+/* Aligns up/down a value */
+#define __ALIGN_DOWN(value, align) ((value) & ~((align)-1))
+#define __ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1))
+
+/* Rounds up and divides */
+#define __DIV_ROUNDUP(value, div) __extension__ ({ \
+ __auto_type __val = value; \
+ __auto_type __div = div; \
+ (__val + (__div - 1)) / __div; \
+})
+
+/* Find least significant bit that is set */
+#define __LOWEST_SET_BIT(mask) ((((mask) - 1) & (mask)) ^ (mask))
+
+/* Extract value with `mask` from `x` */
+#define __SHIFTOUT(x, mask) (((x) & (mask)) / __LOWEST_SET_BIT(mask))
+
+/* Test if bits are set, where __TEST(0b1111, 0xF) == 1 */
+#define __TEST(a, mask) (__SHIFTOUT(a, mask) != 0)
+
+/* Return the number of elements within an array */
+#define __ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0]))
+
+/* Suppress `variable set but not used' warnings */
+#define __USE(x) ((void)(x))
+
+/* Computes 2^x i.e 2 to the power of 'x' */
+#define __POW2(x) (1ULL << x)
+
+/* Wrapper for inline asm */
+#define __ASMV __asm__ __volatile__
+
+/*
+ * Used to give metadata to
+ * a specific module. Example
+ * metadata string:
+ *
+ * $Vega$: module.c, Programmer Bob, A module that does stuff and things
+ * ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * Cookie; Module Author of this A short description
+ * always name module
+ * first
+ *
+ * Example usage:
+ *
+ * __KERNEL_META("$Vega$: module.c, Programmer Bob, "
+ * "A module that does stuff and things");
+ *
+ * The above is the preferred style for this
+ * macro.
+ */
+#define __KERNEL_META(meta_str) \
+ __asm__(".section .meta.note\n" \
+ ".align 4\n" \
+ ".string \"" meta_str "\"\n" \
+ ".previous" \
+ )
+
+#define __MODULE_NAME(name) \
+ __used static const char *__THIS_MODULE = name
+
+/* Pack a structure */
+#define __packed __attribute__((__packed__))
+
+/* Align by `n` */
+#define __aligned(n) __attribute__((__aligned__(n)))
+
+/*
+ * Align to a cacheline-boundary which is
+ * typically 64 bytes.
+ *
+ * XXX: Should probably deal with the case of the
+ * cacheline alignment boundary not being 64 bytes.
+ */
+#define __cacheline_aligned __aligned(64)
+
+/*
+ * To be used when an empty body is required like:
+ *
+ * #ifdef DEBUG
+ * #define dprintf(a) printf(a)
+ * #else
+ * #define dprintf(a) __nothing
+ * #endif
+ */
+#define __nothing ((void)0)
+
+#endif /* !defined(__ASSEMBLER__) */
+#endif /* !_SYS_CDEFS_H_ */
diff --git a/sys/include/sys/errno.h b/sys/include/sys/errno.h
new file mode 100644
index 0000000..a6ec5af
--- /dev/null
+++ b/sys/include/sys/errno.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_ERRNO_H_
+#define _SYS_ERRNO_H_
+
+#define EXIT_FAILURE -1
+
+#endif
diff --git a/sys/include/sys/limine.h b/sys/include/sys/limine.h
new file mode 100644
index 0000000..298de81
--- /dev/null
+++ b/sys/include/sys/limine.h
@@ -0,0 +1,497 @@
+/* BSD Zero Clause License */
+
+/* Copyright (C) 2022-2023 mintsuki and contributors.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LIMINE_H
+#define _LIMINE_H 1
+
+/* $Id$ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+/* Misc */
+
+#ifdef LIMINE_NO_POINTERS
+# define LIMINE_PTR(TYPE) uint64_t
+#else
+# define LIMINE_PTR(TYPE) TYPE
+#endif
+
+#ifdef __GNUC__
+# define LIMINE_DEPRECATED __attribute__((__deprecated__))
+# define LIMINE_DEPRECATED_IGNORE_START \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+# define LIMINE_DEPRECATED_IGNORE_END \
+ _Pragma("GCC diagnostic pop")
+#else
+# define LIMINE_DEPRECATED
+# define LIMINE_DEPRECATED_IGNORE_START
+# define LIMINE_DEPRECATED_IGNORE_END
+#endif
+
+#define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
+
+struct limine_uuid {
+ uint32_t a;
+ uint16_t b;
+ uint16_t c;
+ uint8_t d[8];
+};
+
+#define LIMINE_MEDIA_TYPE_GENERIC 0
+#define LIMINE_MEDIA_TYPE_OPTICAL 1
+#define LIMINE_MEDIA_TYPE_TFTP 2
+
+struct limine_file {
+ uint64_t revision;
+ LIMINE_PTR(void *) address;
+ uint64_t size;
+ LIMINE_PTR(char *) path;
+ LIMINE_PTR(char *) cmdline;
+ uint32_t media_type;
+ uint32_t unused;
+ uint32_t tftp_ip;
+ uint32_t tftp_port;
+ uint32_t partition_index;
+ uint32_t mbr_disk_id;
+ struct limine_uuid gpt_disk_uuid;
+ struct limine_uuid gpt_part_uuid;
+ struct limine_uuid part_uuid;
+};
+
+/* Boot info */
+
+#define LIMINE_BOOTLOADER_INFO_REQUEST { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
+
+struct limine_bootloader_info_response {
+ uint64_t revision;
+ LIMINE_PTR(char *) name;
+ LIMINE_PTR(char *) version;
+};
+
+struct limine_bootloader_info_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_bootloader_info_response *) response;
+};
+
+/* Stack size */
+
+#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
+
+struct limine_stack_size_response {
+ uint64_t revision;
+};
+
+struct limine_stack_size_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_stack_size_response *) response;
+ uint64_t stack_size;
+};
+
+/* HHDM */
+
+#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
+
+struct limine_hhdm_response {
+ uint64_t revision;
+ uint64_t offset;
+};
+
+struct limine_hhdm_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_hhdm_response *) response;
+};
+
+/* Framebuffer */
+
+#define LIMINE_FRAMEBUFFER_REQUEST { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
+
+#define LIMINE_FRAMEBUFFER_RGB 1
+
+struct limine_video_mode {
+ uint64_t pitch;
+ uint64_t width;
+ uint64_t height;
+ uint16_t bpp;
+ uint8_t memory_model;
+ uint8_t red_mask_size;
+ uint8_t red_mask_shift;
+ uint8_t green_mask_size;
+ uint8_t green_mask_shift;
+ uint8_t blue_mask_size;
+ uint8_t blue_mask_shift;
+};
+
+struct limine_framebuffer {
+ LIMINE_PTR(void *) address;
+ uint64_t width;
+ uint64_t height;
+ uint64_t pitch;
+ uint16_t bpp;
+ uint8_t memory_model;
+ uint8_t red_mask_size;
+ uint8_t red_mask_shift;
+ uint8_t green_mask_size;
+ uint8_t green_mask_shift;
+ uint8_t blue_mask_size;
+ uint8_t blue_mask_shift;
+ uint8_t unused[7];
+ uint64_t edid_size;
+ LIMINE_PTR(void *) edid;
+ /* Response revision 1 */
+ uint64_t mode_count;
+ LIMINE_PTR(struct limine_video_mode **) modes;
+};
+
+struct limine_framebuffer_response {
+ uint64_t revision;
+ uint64_t framebuffer_count;
+ LIMINE_PTR(struct limine_framebuffer **) framebuffers;
+};
+
+struct limine_framebuffer_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_framebuffer_response *) response;
+};
+
+/* Terminal */
+
+#define LIMINE_TERMINAL_REQUEST { LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
+
+#define LIMINE_TERMINAL_CB_DEC 10
+#define LIMINE_TERMINAL_CB_BELL 20
+#define LIMINE_TERMINAL_CB_PRIVATE_ID 30
+#define LIMINE_TERMINAL_CB_STATUS_REPORT 40
+#define LIMINE_TERMINAL_CB_POS_REPORT 50
+#define LIMINE_TERMINAL_CB_KBD_LEDS 60
+#define LIMINE_TERMINAL_CB_MODE 70
+#define LIMINE_TERMINAL_CB_LINUX 80
+
+#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t)(-1))
+#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t)(-2))
+#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t)(-3))
+#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t)(-4))
+
+/* Response revision 1 */
+#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t)(-10))
+#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t)(-11))
+
+#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
+#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
+#define LIMINE_TERMINAL_OOB_OUTPUT_OFILL (1 << 2)
+#define LIMINE_TERMINAL_OOB_OUTPUT_OLCUC (1 << 3)
+#define LIMINE_TERMINAL_OOB_OUTPUT_ONLCR (1 << 4)
+#define LIMINE_TERMINAL_OOB_OUTPUT_ONLRET (1 << 5)
+#define LIMINE_TERMINAL_OOB_OUTPUT_ONOCR (1 << 6)
+#define LIMINE_TERMINAL_OOB_OUTPUT_OPOST (1 << 7)
+
+LIMINE_DEPRECATED_IGNORE_START
+
+struct LIMINE_DEPRECATED limine_terminal;
+
+typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t);
+typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
+
+struct LIMINE_DEPRECATED limine_terminal {
+ uint64_t columns;
+ uint64_t rows;
+ LIMINE_PTR(struct limine_framebuffer *) framebuffer;
+};
+
+struct LIMINE_DEPRECATED limine_terminal_response {
+ uint64_t revision;
+ uint64_t terminal_count;
+ LIMINE_PTR(struct limine_terminal **) terminals;
+ LIMINE_PTR(limine_terminal_write) write;
+};
+
+struct LIMINE_DEPRECATED limine_terminal_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_terminal_response *) response;
+ LIMINE_PTR(limine_terminal_callback) callback;
+};
+
+LIMINE_DEPRECATED_IGNORE_END
+
+/* 5-level paging */
+
+#define LIMINE_5_LEVEL_PAGING_REQUEST { LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
+
+struct limine_5_level_paging_response {
+ uint64_t revision;
+};
+
+struct limine_5_level_paging_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_5_level_paging_response *) response;
+};
+
+/* SMP */
+
+#define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
+
+struct limine_smp_info;
+
+typedef void (*limine_goto_address)(struct limine_smp_info *);
+
+#if defined (__x86_64__) || defined (__i386__)
+
+#define LIMINE_SMP_X2APIC (1 << 0)
+
+struct limine_smp_info {
+ uint32_t processor_id;
+ uint32_t lapic_id;
+ uint64_t reserved;
+ LIMINE_PTR(limine_goto_address) goto_address;
+ uint64_t extra_argument;
+};
+
+struct limine_smp_response {
+ uint64_t revision;
+ uint32_t flags;
+ uint32_t bsp_lapic_id;
+ uint64_t cpu_count;
+ LIMINE_PTR(struct limine_smp_info **) cpus;
+};
+
+#elif defined (__aarch64__)
+
+struct limine_smp_info {
+ uint32_t processor_id;
+ uint32_t gic_iface_no;
+ uint64_t mpidr;
+ uint64_t reserved;
+ LIMINE_PTR(limine_goto_address) goto_address;
+ uint64_t extra_argument;
+};
+
+struct limine_smp_response {
+ uint64_t revision;
+ uint32_t flags;
+ uint64_t bsp_mpidr;
+ uint64_t cpu_count;
+ LIMINE_PTR(struct limine_smp_info **) cpus;
+};
+
+#else
+#error Unknown architecture
+#endif
+
+struct limine_smp_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_smp_response *) response;
+ uint64_t flags;
+};
+
+/* Memory map */
+
+#define LIMINE_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
+
+#define LIMINE_MEMMAP_USABLE 0
+#define LIMINE_MEMMAP_RESERVED 1
+#define LIMINE_MEMMAP_ACPI_RECLAIMABLE 2
+#define LIMINE_MEMMAP_ACPI_NVS 3
+#define LIMINE_MEMMAP_BAD_MEMORY 4
+#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
+#define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
+#define LIMINE_MEMMAP_FRAMEBUFFER 7
+
+struct limine_memmap_entry {
+ uint64_t base;
+ uint64_t length;
+ uint64_t type;
+};
+
+struct limine_memmap_response {
+ uint64_t revision;
+ uint64_t entry_count;
+ LIMINE_PTR(struct limine_memmap_entry **) entries;
+};
+
+struct limine_memmap_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_memmap_response *) response;
+};
+
+/* Entry point */
+
+#define LIMINE_ENTRY_POINT_REQUEST { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
+
+typedef void (*limine_entry_point)(void);
+
+struct limine_entry_point_response {
+ uint64_t revision;
+};
+
+struct limine_entry_point_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_entry_point_response *) response;
+ LIMINE_PTR(limine_entry_point) entry;
+};
+
+/* Kernel File */
+
+#define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
+
+struct limine_kernel_file_response {
+ uint64_t revision;
+ LIMINE_PTR(struct limine_file *) kernel_file;
+};
+
+struct limine_kernel_file_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_kernel_file_response *) response;
+};
+
+/* Module */
+
+#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
+
+#define LIMINE_INTERNAL_MODULE_REQUIRED (1 << 0)
+
+struct limine_internal_module {
+ LIMINE_PTR(const char *) path;
+ LIMINE_PTR(const char *) cmdline;
+ uint64_t flags;
+};
+
+struct limine_module_response {
+ uint64_t revision;
+ uint64_t module_count;
+ LIMINE_PTR(struct limine_file **) modules;
+};
+
+struct limine_module_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_module_response *) response;
+
+ /* Request revision 1 */
+ uint64_t internal_module_count;
+ LIMINE_PTR(struct limine_internal_module **) internal_modules;
+};
+
+/* RSDP */
+
+#define LIMINE_RSDP_REQUEST { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
+
+struct limine_rsdp_response {
+ uint64_t revision;
+ LIMINE_PTR(void *) address;
+};
+
+struct limine_rsdp_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_rsdp_response *) response;
+};
+
+/* SMBIOS */
+
+#define LIMINE_SMBIOS_REQUEST { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
+
+struct limine_smbios_response {
+ uint64_t revision;
+ LIMINE_PTR(void *) entry_32;
+ LIMINE_PTR(void *) entry_64;
+};
+
+struct limine_smbios_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_smbios_response *) response;
+};
+
+/* EFI system table */
+
+#define LIMINE_EFI_SYSTEM_TABLE_REQUEST { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
+
+struct limine_efi_system_table_response {
+ uint64_t revision;
+ LIMINE_PTR(void *) address;
+};
+
+struct limine_efi_system_table_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_efi_system_table_response *) response;
+};
+
+/* Boot time */
+
+#define LIMINE_BOOT_TIME_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
+
+struct limine_boot_time_response {
+ uint64_t revision;
+ int64_t boot_time;
+};
+
+struct limine_boot_time_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_boot_time_response *) response;
+};
+
+/* Kernel address */
+
+#define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
+
+struct limine_kernel_address_response {
+ uint64_t revision;
+ uint64_t physical_base;
+ uint64_t virtual_base;
+};
+
+struct limine_kernel_address_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_kernel_address_response *) response;
+};
+
+/* Device Tree Blob */
+
+#define LIMINE_DTB_REQUEST { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
+
+struct limine_dtb_response {
+ uint64_t revision;
+ LIMINE_PTR(void *) dtb_ptr;
+};
+
+struct limine_dtb_request {
+ uint64_t id[4];
+ uint64_t revision;
+ LIMINE_PTR(struct limine_dtb_response *) response;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/sys/include/sys/machdep.h b/sys/include/sys/machdep.h
new file mode 100644
index 0000000..5f2112c
--- /dev/null
+++ b/sys/include/sys/machdep.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_MACHDEP_H_
+#define _SYS_MACHDEP_H_
+
+#include <sys/types.h>
+#if defined(_KERNEL)
+#include <machine/gdt.h>
+#endif /* defined(_KERNEL) */
+
+#if defined(_KERNEL)
+
+struct processor {
+ struct gdtr *gdtr;
+ struct gdt_entry *gdt;
+};
+
+__weak void processor_init(struct processor *processor);
+__weak void interrupts_init(struct processor *processor);
+
+void processor_halt(void);
+
+#endif /* defined(_KERNEL) */
+#endif /* !_SYS_MACHDEP_H_ */
diff --git a/sys/include/sys/panic.h b/sys/include/sys/panic.h
new file mode 100644
index 0000000..8529441
--- /dev/null
+++ b/sys/include/sys/panic.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_PANIC_H_
+#define _SYS_PANIC_H_
+
+#include <stdarg.h>
+
+#if defined(_KERNEL)
+
+void panic(const char *fmt, ...);
+
+#endif
+
+#endif
diff --git a/sys/include/sys/queue.h b/sys/include/sys/queue.h
new file mode 100644
index 0000000..acd0703
--- /dev/null
+++ b/sys/include/sys/queue.h
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#define _Q_INVALIDATE(a)
+
+/*
+ * Tail queue definitions.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * Tail queue access methods.
+ */
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+#define TAILQ_END(head) NULL
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+/* XXX */
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define TAILQ_EMPTY(head) \
+ (TAILQ_FIRST(head) == TAILQ_END(head))
+
+#define TAILQ_FOREACH(var, head, field) \
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_NEXT(var, field))
+
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_PREV(var, headname, field))
+
+#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
+ for ((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_PREV(var, headname, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_INIT(head) do { \
+ (head)->tqh_first = NULL; \
+ (head)->tqh_last = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
+ (head)->tqh_first->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (head)->tqh_first = (elm); \
+ (elm)->field.tqe_prev = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+ (elm)->field.tqe_next->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (listelm)->field.tqe_next = (elm); \
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ (elm)->field.tqe_next = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if (((elm)->field.tqe_next) != NULL) \
+ (elm)->field.tqe_next->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_REPLACE(head, elm, elm2, field) do { \
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
+ (elm2)->field.tqe_next->field.tqe_prev = \
+ &(elm2)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm2)->field.tqe_next; \
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
+ *(elm2)->field.tqe_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_CONCAT(head1, head2, field) do { \
+ if (!TAILQ_EMPTY(head2)) { \
+ *(head1)->tqh_last = (head2)->tqh_first; \
+ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+ (head1)->tqh_last = (head2)->tqh_last; \
+ TAILQ_INIT((head2)); \
+ } \
+} while (0)
diff --git a/sys/include/sys/spinlock.h b/sys/include/sys/spinlock.h
new file mode 100644
index 0000000..8153041
--- /dev/null
+++ b/sys/include/sys/spinlock.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_SPINLOCK_H_
+#define _SYS_SPINLOCK_H_
+
+#include <sys/types.h>
+
+struct spinlock {
+ volatile _Atomic bool lock;
+};
+
+static inline bool
+spinlock_acquire(struct spinlock *lock)
+{
+ return __atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE);
+}
+
+static inline void
+spinlock_release(struct spinlock *lock)
+{
+ __atomic_clear(&lock->lock, __ATOMIC_RELEASE);
+}
+
+#endif /* !_SYS_SPINLOCK_H_ */
diff --git a/sys/include/sys/syslog.h b/sys/include/sys/syslog.h
new file mode 100644
index 0000000..bb6c512
--- /dev/null
+++ b/sys/include/sys/syslog.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_SYSLOG_H_
+#define _SYS_SYSLOG_H_
+
+#include <stdarg.h>
+
+#if defined(_KERNEL)
+
+#define KINFO(...) \
+ kprintf("%s[info]: ", __THIS_MODULE); \
+ kprintf(__VA_ARGS__);
+
+#define KDEBUG(...) \
+ kprintf("%s[debug]: ", __THIS_MODULE); \
+ kprintf(__VA_ARGS__);
+
+void syslog_init(void);
+void kprintf(const char *fmt, ...);
+void vkprintf(const char *fmt, va_list *ap);
+
+#endif /* defined(_KERNEL) */
+
+#endif /* !_SYS_SYSLOG_H_ */
diff --git a/sys/include/sys/termios.h b/sys/include/sys/termios.h
new file mode 100644
index 0000000..4cbef9d
--- /dev/null
+++ b/sys/include/sys/termios.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_TERMIOS_H_
+#define _SYS_TERMIOS_H_
+
+#include <sys/types.h>
+
+#define NCCS 20
+
+/*
+ * Output flags - software output processing
+ */
+#define OPOST 0x00000001U /* Enable output processing */
+#if defined(_KERNEL) || defined(_VEGA_SOURCE)
+#define OCRNL 0x00000002U /* Map NL to CR-NL */
+#define ORBUF 0x00000004U /* Buffer bytes */
+#endif /* defined(_KERNEL) || defined(_VEGA_SOURCE) */
+
+typedef uint32_t tcflag_t;
+typedef uint32_t speed_t;
+typedef uint8_t cc_t;
+
+struct termios {
+ tcflag_t c_iflag; /* Input flags */
+ tcflag_t c_oflag; /* Output flags */
+ tcflag_t c_cflag; /* Control flags */
+ tcflag_t c_lflag; /* Local flags */
+ cc_t c_cc[NCCS]; /* Control chars */
+ int c_ispeed; /* Input speed */
+ int c_ospeed; /* Output speed */
+};
+
+#endif /* !_SYS_TERMIOS_H_ */
diff --git a/sys/include/sys/tty.h b/sys/include/sys/tty.h
new file mode 100644
index 0000000..0edbaab
--- /dev/null
+++ b/sys/include/sys/tty.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_TTY_H_
+#define _SYS_TTY_H_
+
+#include <sys/types.h>
+#include <sys/termios.h>
+#include <sys/queue.h>
+#include <sys/cdefs.h>
+#include <sys/spinlock.h>
+#include <dev/video/fbdev.h>
+
+/*
+ * Max chars an entire line can hold:
+ * 2^9 => 512 bytes
+ */
+#define LINE_RING_SIZE __POW2(9)
+
+/* Default TTY tab width */
+#define DEFAULT_TAB_WIDTH 4
+
+/*
+ * Describes the size
+ * of a TTY window.
+ */
+struct winsize {
+ uint16_t ws_row; /* Rows, in chars */
+ uint16_t ws_col; /* Columns, in chars */
+ uint16_t ws_xpixel; /* Horizontal size, in pixels */
+ uint16_t ws_ypixel; /* Vertical size, in pixels */
+};
+
+/*
+ * TTY ring buffer.
+ */
+struct tty_ring {
+ char buf[LINE_RING_SIZE]; /* Actual buffer */
+ size_t len;
+};
+
+/*
+ * Describes a TTY. Each TTY
+ * shall be described by a
+ * `struct tty`.
+ */
+struct tty {
+ uint32_t chpos_x; /* Next char X position */
+ uint32_t chpos_y; /* Next char Y position */
+ uint32_t curspos_x; /* Cursor X position */
+ uint32_t curspos_y; /* Cursor Y position */
+ uint32_t fg; /* Foreground (hex color) */
+ uint32_t bg; /* Background (hex color) */
+ uint8_t tab_width; /* Width of a tab (in chars) */
+ struct fbdev fbdev; /* Framebuffer device */
+ struct termios termios; /* Termios state */
+ struct winsize winsize; /* Window size */
+ struct tty_ring ring; /* Ring buffer */
+ struct spinlock lock; /* Protects TTY */
+ TAILQ_ENTRY(tty) link; /* TTY list link */
+};
+
+/*
+ * Some helper macros to facilitate
+ * locking/unlocking a TTY.
+ */
+#define TTY_LOCK(tty_ptr) spinlock_acquire(&(tty_ptr)->lock)
+#define TTY_UNLOCK(tty_ptr) spinlock_release(&(tty_ptr)->lock)
+
+/*
+ * Macros to allow easy access for
+ * termios and winsize flags, e.g usage:
+ *
+ * struct tty *tty = ...
+ * tty->t_cflag = ...
+ */
+#define t_cflag termios.c_cflag
+#define t_iflag termios.c_iflag
+#define t_lflag termios.c_lflag
+#define t_oflag termios.c_oflag
+#define t_ispeed termios.c_ispeed
+#define t_ospeed termios.c_ospeed
+#define t_ws_row winsize.ws_row
+#define t_ws_col winsize.ws_col
+#define t_ws_xpixel winsize.ws_xpixel
+#define t_ws_ypixel winsize.ws_ypixel
+
+void tty_push_char(struct tty *tty, int c);
+void tty_flush(struct tty *tty);
+ssize_t tty_write(struct tty *tty, const char *buf, size_t len);
+void tty_set_defaults(struct tty *tty);
+void tty_attach(struct tty *tty);
+void tty_init(void);
+
+#endif /* !_SYS_TTY_H_ */
diff --git a/sys/include/sys/types.h b/sys/include/sys/types.h
new file mode 100644
index 0000000..8fc285a
--- /dev/null
+++ b/sys/include/sys/types.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_TYPES_H_
+#define _SYS_TYPES_H_
+
+#define NULL ((void *)0)
+#define true 1
+#define false 0
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+#if __SIZEOF_LONG__ == 8
+typedef long int64_t;
+typedef unsigned long uint64_t;
+#elif __SIZEOF_LONG__ == 4
+__extension__
+typedef long long int64_t;
+__extension__
+typedef unsigned long long uint64_t;
+#else
+#error "Unsupported long size"
+#endif
+
+#if __SIZEOF_SIZE_T__ == 8
+typedef uint64_t size_t;
+typedef int64_t ssize_t; /* Byte count or error */
+#elif __SIZEOF_SIZE_T__ == 4
+typedef uint32_t size_t;
+typedef int32_t ssize_t; /* Byte count or error */
+#else
+#error "Unsupported size_t size"
+#endif
+
+typedef _Bool bool;
+typedef ssize_t off_t;
+typedef size_t uintptr_t;
+
+#endif /* !_SYS_TYPES_H_ */
diff --git a/sys/include/vm/vm.h b/sys/include/vm/vm.h
new file mode 100644
index 0000000..35775cc
--- /dev/null
+++ b/sys/include/vm/vm.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _SYS_VM_VM_H_
+#define _SYS_VM_VM_H_
+
+#include <sys/types.h>
+#include <sys/limine.h>
+
+extern volatile struct limine_hhdm_request g_hhdm_request;
+
+#define VM_HIGHER_HALF (g_hhdm_request.response->offset)
+
+#define PHYS_TO_VIRT(phys) (void *)(phys + VM_HIGHER_HALF)
+#define VIRT_TO_PHYS(virt) ((uintptr_t)virt - VM_HIGHER_HALF)
+
+#endif /* !_SYS_VM_VM_H_ */
diff --git a/sys/include/vm/vm_physseg.h b/sys/include/vm/vm_physseg.h
new file mode 100644
index 0000000..ed815ec
--- /dev/null
+++ b/sys/include/vm/vm_physseg.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023 Ian Marco Moffett and the VegaOS 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 VegaOS 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.
+ */
+
+/* $Id$ */
+
+#ifndef _VM_VM_PHYSSEG_H_
+#define _VM_VM_PHYSSEG_H_
+
+void vm_physseg_init(void);
+
+#endif /* !_VM_VM_PHYSSEG_H_ */