summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-06-24 22:55:29 -0400
committerIan Moffett <ian@osmora.org>2024-06-24 22:55:29 -0400
commit236963e7563be3e3f8220dac7bb4af446928e194 (patch)
treee521ea226db0345bbb3679fffe09d96254b7dc73 /sys
parent214eadc62b5578f76c98a38a28f8b3d80ac4d6ad (diff)
Clean out for expt
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/bus_machdep.c83
-rw-r--r--sys/arch/amd64/amd64/cpu.c40
-rw-r--r--sys/arch/amd64/amd64/cpu_mp.c142
-rw-r--r--sys/arch/amd64/amd64/gdt.c85
-rw-r--r--sys/arch/amd64/amd64/hpet.c208
-rw-r--r--sys/arch/amd64/amd64/idt.c66
-rw-r--r--sys/arch/amd64/amd64/ioapic.c200
-rw-r--r--sys/arch/amd64/amd64/lapic.c435
-rw-r--r--sys/arch/amd64/amd64/local_intr.S47
-rw-r--r--sys/arch/amd64/amd64/machdep.c401
-rw-r--r--sys/arch/amd64/amd64/pmap.c389
-rw-r--r--sys/arch/amd64/amd64/spectre.S54
-rw-r--r--sys/arch/amd64/amd64/spectre.c85
-rw-r--r--sys/arch/amd64/amd64/syscall.S43
-rw-r--r--sys/arch/amd64/amd64/syscall.c54
-rw-r--r--sys/arch/amd64/amd64/trap.S155
-rw-r--r--sys/arch/amd64/amd64/trap.c269
-rw-r--r--sys/arch/amd64/amd64/tss.S41
-rw-r--r--sys/arch/amd64/amd64/tss.c174
-rw-r--r--sys/arch/amd64/amd64/uart.c98
-rw-r--r--sys/arch/amd64/conf/GENERIC9
-rw-r--r--sys/arch/amd64/isa/i8042.c297
-rw-r--r--sys/arch/amd64/isa/i8254.c75
-rw-r--r--sys/arch/amd64/isa/spkr.c68
-rw-r--r--sys/dev/ic/ahci.c771
-rw-r--r--sys/dev/ic/nvme.c614
-rw-r--r--sys/dev/pci/pci.c344
-rw-r--r--sys/dev/usb/xhci.c463
-rw-r--r--sys/dev/vcons/vcons.c227
-rw-r--r--sys/dev/vcons/vcons_io.c84
-rw-r--r--sys/dev/video/fbdev.c120
-rw-r--r--sys/firmware/acpi/acpi_init.c111
-rw-r--r--sys/firmware/acpi/acpi_madt.c150
-rw-r--r--sys/firmware/acpi/acpi_subr.c81
-rw-r--r--sys/fs/devfs.c295
-rw-r--r--sys/fs/initramfs.c262
-rw-r--r--sys/fs/procfs.c206
-rw-r--r--sys/fs/procfs_subr.c114
-rw-r--r--sys/include/arch/amd64/bus.h39
-rw-r--r--sys/include/arch/amd64/cpu.h158
-rw-r--r--sys/include/arch/amd64/cpu_mp.h40
-rw-r--r--sys/include/arch/amd64/cpuid.h40
-rw-r--r--sys/include/arch/amd64/frame.h82
-rw-r--r--sys/include/arch/amd64/frameasm.h103
-rw-r--r--sys/include/arch/amd64/gdt.h79
-rw-r--r--sys/include/arch/amd64/hpet.h40
-rw-r--r--sys/include/arch/amd64/idt.h70
-rw-r--r--sys/include/arch/amd64/intr.h37
-rw-r--r--sys/include/arch/amd64/io.h78
-rw-r--r--sys/include/arch/amd64/ioapic.h43
-rw-r--r--sys/include/arch/amd64/ioapicvar.h57
-rw-r--r--sys/include/arch/amd64/isa/i8042regs.h69
-rw-r--r--sys/include/arch/amd64/isa/i8254.h44
-rw-r--r--sys/include/arch/amd64/isa/spkr.h37
-rw-r--r--sys/include/arch/amd64/lapic.h59
-rw-r--r--sys/include/arch/amd64/lapicvar.h102
-rw-r--r--sys/include/arch/amd64/msr.h66
-rw-r--r--sys/include/arch/amd64/pcb.h39
-rw-r--r--sys/include/arch/amd64/spectre.h38
-rw-r--r--sys/include/arch/amd64/sysvec.h55
-rw-r--r--sys/include/arch/amd64/tlb.h42
-rw-r--r--sys/include/arch/amd64/trap.h78
-rw-r--r--sys/include/arch/amd64/tss.h120
-rw-r--r--sys/include/arch/amd64/uart.h40
-rw-r--r--sys/include/arch/amd64/vas.h54
-rw-r--r--sys/include/dev/ic/ahciregs.h142
-rw-r--r--sys/include/dev/ic/ahcivar.h146
-rw-r--r--sys/include/dev/ic/nvmevar.h280
-rw-r--r--sys/include/dev/pci/pci.h83
-rw-r--r--sys/include/dev/pci/pciregs.h66
-rw-r--r--sys/include/dev/pci/pcivar.h40
-rw-r--r--sys/include/dev/usb/xhciregs.h110
-rw-r--r--sys/include/dev/usb/xhcivar.h113
-rw-r--r--sys/include/dev/vcons/vcons.h72
-rw-r--r--sys/include/dev/vcons/vcons_io.h37
-rw-r--r--sys/include/dev/video/fbdev.h51
-rw-r--r--sys/include/firmware/acpi/acpi.h46
-rw-r--r--sys/include/firmware/acpi/tables.h130
-rw-r--r--sys/include/fs/devfs.h42
-rw-r--r--sys/include/fs/initramfs.h41
-rw-r--r--sys/include/fs/procfs.h51
-rw-r--r--sys/include/lib/assert.h42
-rw-r--r--sys/include/lib/bitmap.h56
-rw-r--r--sys/include/lib/logo.h39
-rw-r--r--sys/include/lib/stdarg.h44
-rw-r--r--sys/include/lib/string.h48
-rw-r--r--sys/include/lib/sysfont.h40
-rw-r--r--sys/include/sys/ascii.h45
-rw-r--r--sys/include/sys/cdefs.h182
-rw-r--r--sys/include/sys/cpu.h41
-rw-r--r--sys/include/sys/device.h68
-rw-r--r--sys/include/sys/driver.h57
-rw-r--r--sys/include/sys/elf.h499
-rw-r--r--sys/include/sys/errno.h159
-rw-r--r--sys/include/sys/exec.h37
-rw-r--r--sys/include/sys/fbdev.h48
-rw-r--r--sys/include/sys/filedesc.h72
-rw-r--r--sys/include/sys/intr.h55
-rw-r--r--sys/include/sys/ksyms.h44
-rw-r--r--sys/include/sys/limine.h495
-rw-r--r--sys/include/sys/loader.h77
-rw-r--r--sys/include/sys/machdep.h56
-rw-r--r--sys/include/sys/mmio.h112
-rw-r--r--sys/include/sys/mount.h80
-rw-r--r--sys/include/sys/mutex.h42
-rw-r--r--sys/include/sys/panic.h41
-rw-r--r--sys/include/sys/proc.h91
-rw-r--r--sys/include/sys/queue.h173
-rw-r--r--sys/include/sys/reboot.h45
-rw-r--r--sys/include/sys/sched.h53
-rw-r--r--sys/include/sys/sched_state.h42
-rw-r--r--sys/include/sys/schedvar.h61
-rw-r--r--sys/include/sys/signal.h46
-rw-r--r--sys/include/sys/sio.h57
-rw-r--r--sys/include/sys/spinlock.h51
-rw-r--r--sys/include/sys/syscall.h68
-rw-r--r--sys/include/sys/syslog.h55
-rw-r--r--sys/include/sys/system.h43
-rw-r--r--sys/include/sys/termios.h69
-rw-r--r--sys/include/sys/timer.h91
-rw-r--r--sys/include/sys/tty.h74
-rw-r--r--sys/include/sys/types.h77
-rw-r--r--sys/include/sys/vfs.h67
-rw-r--r--sys/include/sys/vnode.h79
-rw-r--r--sys/include/vm/dynalloc.h44
-rw-r--r--sys/include/vm/fault.h38
-rw-r--r--sys/include/vm/map.h84
-rw-r--r--sys/include/vm/obj.h61
-rw-r--r--sys/include/vm/page.h41
-rw-r--r--sys/include/vm/pager.h51
-rw-r--r--sys/include/vm/physseg.h48
-rw-r--r--sys/include/vm/pmap.h117
-rw-r--r--sys/include/vm/tlsf.h90
-rw-r--r--sys/include/vm/vm.h78
-rw-r--r--sys/kern/init_main.c113
-rw-r--r--sys/kern/kern_cpu.c76
-rw-r--r--sys/kern/kern_device.c84
-rw-r--r--sys/kern/kern_exec.c240
-rw-r--r--sys/kern/kern_filedesc.c494
-rw-r--r--sys/kern/kern_intr.c127
-rw-r--r--sys/kern/kern_ioctl.c72
-rw-r--r--sys/kern/kern_loader.c220
-rw-r--r--sys/kern/kern_mutex.c52
-rw-r--r--sys/kern/kern_panic.c63
-rw-r--r--sys/kern/kern_reboot.c51
-rw-r--r--sys/kern/kern_sched.c490
-rw-r--r--sys/kern/kern_signal.c102
-rw-r--r--sys/kern/kern_subr.c134
-rw-r--r--sys/kern/kern_syscall.c54
-rw-r--r--sys/kern/kern_syslog.c168
-rw-r--r--sys/kern/kern_timer.c112
-rw-r--r--sys/kern/kern_tty.c304
-rw-r--r--sys/kern/vfs_init.c89
-rw-r--r--sys/kern/vfs_lookup.c182
-rw-r--r--sys/kern/vfs_mount.c217
-rw-r--r--sys/kern/vfs_subr.c258
-rw-r--r--sys/lib/logo.c90
-rw-r--r--sys/lib/string/itoa.c134
-rw-r--r--sys/lib/string/memcmp.c46
-rw-r--r--sys/lib/string/memcpy.c50
-rw-r--r--sys/lib/string/memmove.c49
-rw-r--r--sys/lib/string/memset.c50
-rw-r--r--sys/lib/string/strcmp.c39
-rw-r--r--sys/lib/string/strlen.c40
-rw-r--r--sys/lib/string/vsnprintf.c139
-rw-r--r--sys/lib/sysfont.c376
-rw-r--r--sys/vm/tlsf.c1264
-rw-r--r--sys/vm/vm_device.c119
-rw-r--r--sys/vm/vm_dynalloc.c93
-rw-r--r--sys/vm/vm_fault.c132
-rw-r--r--sys/vm/vm_init.c91
-rw-r--r--sys/vm/vm_map.c540
-rw-r--r--sys/vm/vm_obj.c93
-rw-r--r--sys/vm/vm_page.c73
-rw-r--r--sys/vm/vm_pager.c68
-rw-r--r--sys/vm/vm_physseg.c272
-rw-r--r--sys/vm/vm_stat.c42
-rw-r--r--sys/vm/vm_vnode.c114
178 files changed, 0 insertions, 22508 deletions
diff --git a/sys/arch/amd64/amd64/bus_machdep.c b/sys/arch/amd64/amd64/bus_machdep.c
deleted file mode 100644
index 91e7963..0000000
--- a/sys/arch/amd64/amd64/bus_machdep.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <machine/bus.h>
-#include <vm/physseg.h>
-#include <vm/pmap.h>
-#include <vm/map.h>
-#include <vm/vm.h>
-
-/*
- * Map a physical device address into the kernel address
- * space.
- *
- * @addr: Physical address to map.
- * @size: Size to map.
- * @flags: Mapping flags.
- * @vap: Resulting virtual address.
- */
-int
-bus_map(bus_addr_t addr, size_t size, int flags, void **vap)
-{
- struct vm_ctx *vmctx = vm_get_ctx();
- struct vas vas;
- size_t pagesize;
- vaddr_t va;
- int status;
-
- pagesize = vm_get_page_size();
- size = __ALIGN_UP(size, pagesize);
-
- va = (vaddr_t)PHYS_TO_VIRT(addr);
- vas = pmap_read_vas();
-
- /* Ensure the size is valid */
- if (size == 0) {
- return -EINVAL;
- }
-
- /* Map the device address to our new VA */
- if ((status = vm_map_create(vas, va, addr, PROT_WRITE, size)) != 0) {
- return status;
- }
-
- /*
- * Mark the memory as uncachable because this is
- * for device I/O
- */
- if ((status = pmap_set_cache(vmctx, vas, va, VM_CACHE_UC)) != 0) {
- return status;
- }
-
- *vap = (void *)va;
- return 0;
-}
diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c
deleted file mode 100644
index e608535..0000000
--- a/sys/arch/amd64/amd64/cpu.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/cpu_mp.h>
-#include <sys/cdefs.h>
-
-__KERNEL_META("$Hyra$: cpu.c, Ian Marco Moffett, "
- "AMD64 CPU abstraction module");
-
-struct cpu_info *
-amd64_this_cpu(void)
-{
- return (void *)amd64_read_gs_base();
-}
diff --git a/sys/arch/amd64/amd64/cpu_mp.c b/sys/arch/amd64/amd64/cpu_mp.c
deleted file mode 100644
index b9de227..0000000
--- a/sys/arch/amd64/amd64/cpu_mp.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/cpu_mp.h>
-#include <sys/machdep.h>
-#include <sys/limine.h>
-#include <sys/types.h>
-#include <sys/syslog.h>
-#include <sys/sched.h>
-#include <sys/cpu.h>
-#include <sys/intr.h>
-#include <vm/dynalloc.h>
-#include <assert.h>
-
-__MODULE_NAME("cpu_mp");
-__KERNEL_META("$Hyra$: cpu_mp.c, Ian Marco Moffett, "
- "SMP related code");
-
-#define pr_trace(fmt, ...) kprintf("cpu_mp: " fmt, ##__VA_ARGS__)
-
-static volatile struct limine_smp_request g_smp_req = {
- .id = LIMINE_SMP_REQUEST,
- .revision = 0
-};
-
-static bool is_mp_supported = false;
-static struct intr_info *tmr_irqlist[MAXCPUS];
-
-void handle_local_tmr(void);
-
-/*
- * Add local timer IRQ stat
- */
-static inline void
-tmr_irqstat_add(struct cpu_info *ci)
-{
- tmr_irqlist[ci->idx] = intr_info_alloc("LAPIC", "LAPIC-TMR");
- tmr_irqlist[ci->idx]->affinity = ci->idx;
- intr_register(tmr_irqlist[ci->idx]);
-}
-
-/*
- * Update local timer IRQ stats from
- * interrupt.
- */
-void
-handle_local_tmr(void)
-{
- struct cpu_info *ci = this_cpu();
-
- ++tmr_irqlist[ci->idx]->count;
-}
-
-static void
-ap_trampoline(struct limine_smp_info *si)
-{
- static struct spinlock lock = {0};
- struct cpu_info *ci;
-
- spinlock_acquire(&lock);
-
- pre_init();
- processor_init();
-
- ci = this_cpu();
- cpu_attach(ci);
- tmr_irqstat_add(ci);
-
- spinlock_release(&lock);
- sched_enter();
-
- /* Should not be reached */
- __assert(0);
- __builtin_unreachable();
-}
-
-/*
- * Returns true if SMP is supported.
- */
-bool
-mp_supported(void)
-{
- return is_mp_supported;
-}
-
-void
-ap_bootstrap(struct cpu_info *ci)
-{
- struct limine_smp_response *resp = g_smp_req.response;
- struct limine_smp_info **cpus;
- size_t cpu_init_counter;
-
- /* Should not happen */
- __assert(resp != NULL);
-
- cpus = resp->cpus;
- cpu_init_counter = resp->cpu_count - 1;
-
- cpu_attach(ci);
- tmr_irqstat_add(ci);
-
- if (resp->cpu_count == 1) {
- pr_trace("CPU has 1 core, no APs to bootstrap...\n");
- return;
- }
-
- pr_trace("Bootstrapping %d cores...\n", cpu_init_counter);
- for (size_t i = 0; i < resp->cpu_count; ++i) {
- if (ci->id == cpus[i]->lapic_id) {
- pr_trace("Skip %d (BSP)... continue\n", ci->id);
- continue;
- }
-
- cpus[i]->goto_address = ap_trampoline;
- }
-}
diff --git a/sys/arch/amd64/amd64/gdt.c b/sys/arch/amd64/amd64/gdt.c
deleted file mode 100644
index f48e27a..0000000
--- a/sys/arch/amd64/amd64/gdt.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/gdt.h>
-
-struct gdt_entry g_gdt[256] = {
- /* Null */
- {0},
-
- /* Kernel code (0x8) */
- {
- .limit = 0x0000,
- .base_low = 0x0000,
- .base_mid = 0x00,
- .access = 0x9A,
- .granularity = 0x20,
- .base_hi = 0x00
- },
-
- /* Kernel data (0x10) */
- {
- .limit = 0x0000,
- .base_low = 0x0000,
- .base_mid = 0x00,
- .access = 0x92,
- .granularity = 0x00,
- .base_hi = 0x00
- },
-
- /* User code (0x18) */
- {
- .limit = 0x0000,
- .base_low = 0x0000,
- .base_mid = 0x00,
- .access = 0xFA,
- .granularity = 0xAF,
- .base_hi = 0x00
- },
-
- /* User data (0x20) */
- {
- .limit = 0x0000,
- .base_low = 0x0000,
- .base_mid = 0x00,
- .access = 0xF2,
- .granularity = 0x00,
- .base_hi = 0x00
- },
-
- /* TSS segment (0x28) */
- {0}
-};
-
-struct gdt_entry *g_gdt_tss = &g_gdt[GDT_TSS];
-
-struct gdtr g_gdtr = {
- .limit = sizeof(struct gdt_entry) * 256 - 1,
- .offset = (uintptr_t)&g_gdt[0]
-};
diff --git a/sys/arch/amd64/amd64/hpet.c b/sys/arch/amd64/amd64/hpet.c
deleted file mode 100644
index 69dc0dd..0000000
--- a/sys/arch/amd64/amd64/hpet.c
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/hpet.h>
-#include <machine/cpu.h>
-#include <firmware/acpi/acpi.h>
-#include <sys/panic.h>
-#include <sys/cdefs.h>
-#include <sys/timer.h>
-#include <sys/errno.h>
-#include <sys/syslog.h>
-#include <sys/mmio.h>
-
-__MODULE_NAME("hpet");
-__KERNEL_META("$Hyra$: hpet.c, Ian Marco Moffett, "
- "HPET driver");
-
-#define pr_trace(fmt, ...) kprintf("hpet: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-#define HPET_REG_CAPS 0x00
-#define HPET_GENERAL_CONFIG 0x10
-#define HPET_REG_MAIN_COUNTER 0xF0
-
-#define CAP_REV_ID(caps) __SHIFTOUT(caps, 0xFF)
-#define CAP_NUM_TIM(caps) __SHIFTOUT(caps, 0x1F << 8)
-#define CAP_COUNT_SIZE(caps) __SHIFTOUT(caps, __BIT(13))
-#define CAP_VENDOR_ID(caps) __SHIFTOUT(caps, 0xFFFF << 16)
-#define CAP_CLK_PERIOD(caps) (caps >> 32)
-
-#define FSEC_PER_SECOND 1000000000000000ULL
-#define USEC_PER_SECOND 1000000ULL
-
-static struct timer timer = { 0 };
-static struct hpet *acpi_hpet = NULL;
-static void *hpet_base = NULL;
-static bool is_faulty = false;
-
-/*
- * Read from HPET register space.
- *
- * @reg: Register to read from.
- */
-static inline uint64_t
-hpet_read(uint32_t reg)
-{
- void *addr;
-
- addr = (void *)((uintptr_t)hpet_base + reg);
- return mmio_read64(addr);
-}
-
-/*
- * Write to HPET register space.
- *
- * @reg: Register to write to.
- * @val: Value to write.
- */
-static inline void
-hpet_write(uint32_t reg, uint64_t val)
-{
- void *addr;
-
- addr = (void *)((uintptr_t)hpet_base + reg);
- mmio_write64(addr, val);
-}
-
-static int
-hpet_sleep(uint64_t n, uint64_t units)
-{
- uint64_t caps;
- uint32_t period;
- uint64_t counter_val;
- volatile size_t ticks;
-
- /* Don't even try if faulty, would probably cause deadlock */
- if (is_faulty) {
- return EXIT_FAILURE;
- }
-
- caps = hpet_read(HPET_REG_CAPS);
- period = CAP_CLK_PERIOD(caps);
- counter_val = hpet_read(HPET_REG_MAIN_COUNTER);
-
- ticks = counter_val + (n * (units / period));
-
- while (hpet_read(HPET_REG_MAIN_COUNTER) < ticks) {
- hint_spinwait();
- }
-
- return EXIT_SUCCESS;
-}
-
-int
-hpet_msleep(size_t ms)
-{
- return hpet_sleep(ms, 1000000000000);
-}
-
-int
-hpet_usleep(size_t us)
-{
- return hpet_sleep(us, 1000000000);
-}
-
-int
-hpet_nsleep(size_t ns)
-{
- return hpet_sleep(ns, 1000000);
-}
-
-static size_t
-hpet_time_usec(void)
-{
- uint64_t period, freq, caps;
- uint64_t counter;
-
- caps = hpet_read(HPET_REG_CAPS);
- period = CAP_CLK_PERIOD(caps);
- freq = FSEC_PER_SECOND / period;
-
- counter = hpet_read(HPET_REG_MAIN_COUNTER);
- return (counter * USEC_PER_SECOND) / freq;
-}
-
-static size_t
-hpet_time_sec(void)
-{
- return hpet_time_usec() / USEC_PER_SECOND;
-}
-
-int
-hpet_init(void)
-{
- struct acpi_gas *gas;
- uint64_t caps;
-
- acpi_hpet = acpi_query("HPET");
- if (acpi_hpet == NULL)
- return 1; /* Not found */
-
- gas = &acpi_hpet->gas;
- hpet_base = (void *)gas->address;
- caps = hpet_read(HPET_REG_CAPS);
-
- /* Ensure caps aren't bogus */
- if (CAP_REV_ID(caps) == 0) {
- pr_error("Found bogus revision, assuming faulty\n");
- is_faulty = true;
- return 1;
- }
- if (CAP_CLK_PERIOD(caps) > 0x05F5E100) {
- /*
- * The spec states this counter clk period
- * must be <= 0x05F5E100. So we'll consider it
- * as bogus if it exceeds this value
- */
- pr_error("Found bogus COUNTER_CLK_PERIOD, assuming faulty\n");
- pr_trace("HPET REV - 0x%x\n", CAP_REV_ID(caps));
- pr_trace("COUNTER_CLK_PERIOD - 0x%x\n", CAP_CLK_PERIOD(caps));
- is_faulty = true;
- return 1;
- }
-
- pr_trace("HPET integrity verified\n");
-
- hpet_write(HPET_REG_MAIN_COUNTER, 0);
- hpet_write(HPET_GENERAL_CONFIG, 1);
-
- /* Setup the timer descriptor */
- timer.name = "HIGH_PRECISION_EVENT_TIMER";
- timer.msleep = hpet_msleep;
- timer.usleep = hpet_usleep;
- timer.nsleep = hpet_nsleep;
- timer.get_time_usec = hpet_time_usec;
- timer.get_time_sec = hpet_time_sec;
- register_timer(TIMER_GP, &timer);
-
- /* Not faulty */
- is_faulty = false;
- return 0;
-}
diff --git a/sys/arch/amd64/amd64/idt.c b/sys/arch/amd64/amd64/idt.c
deleted file mode 100644
index 03a2af0..0000000
--- a/sys/arch/amd64/amd64/idt.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/idt.h>
-
-static struct idt_entry idt[256];
-static struct idtr idtr = {
- .limit = sizeof(struct idt_entry) * 256 - 1,
- .offset = (uintptr_t)&idt[0]
-};
-
-void
-idt_load(void)
-{
- LIDT(idtr);
-}
-
-void
-idt_set_desc(uint8_t vec, uint8_t type, uintptr_t isr, uint8_t ist)
-{
- struct idt_entry *desc;
-
- if (vec >= 255) {
- /* Invalid vector */
- return;
- }
-
- desc = &idt[vec];
- desc->off_lo = __SHIFTOUT(isr, __MASK(16));
- desc->off_mid = __SHIFTOUT(isr, __MASK(16) << 16);
- desc->off_hi = __SHIFTOUT(isr, __MASK(32) << 32);
- desc->segsel = 0x8; /* Kernel CS */
- desc->type = type;
- desc->dpl = 3;
- desc->p = 1;
- desc->zero = 0;
- desc->zero1 = 0;
- desc->reserved = 0;
- desc->ist = ist;
-}
diff --git a/sys/arch/amd64/amd64/ioapic.c b/sys/arch/amd64/amd64/ioapic.c
deleted file mode 100644
index 5dfdfa8..0000000
--- a/sys/arch/amd64/amd64/ioapic.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/ioapic.h>
-#include <machine/ioapicvar.h>
-#include <firmware/acpi/acpi.h>
-#include <sys/panic.h>
-#include <sys/mmio.h>
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-
-__MODULE_NAME("ioapic");
-__KERNEL_META("$Hyra$: ioapic.c, Ian Marco Moffett, "
- "I/O APIC driver");
-
-#define pr_trace(fmt, ...) kprintf("ioapic: " fmt, ##__VA_ARGS__)
-#define IOAPIC_BASE_OFF(off) ((void *)((uintptr_t)ioapic_base + off))
-
-static void *ioapic_base = NULL;
-
-/*
- * Reads a 32 bit value from the IOAPIC
- * register space.
- *
- * @reg: Register to read from.
- */
-static uint32_t
-ioapic_readl(uint16_t reg)
-{
- mmio_write32(IOAPIC_BASE_OFF(IOREGSEL), reg);
- return mmio_read32(IOAPIC_BASE_OFF(IOWIN));
-}
-
-/*
- * Writes a 32 bit value to the IOAPIC
- * register space.
- *
- * @reg: Register to write to.
- * @val: Value to write.
- */
-static void
-ioapic_writel(uint16_t reg, uint32_t val)
-{
- mmio_write32(IOAPIC_BASE_OFF(IOREGSEL), reg);
- mmio_write32(IOAPIC_BASE_OFF(IOWIN), val);
-}
-
-/*
- * Reads an I/O APIC redirection entry.
- *
- * @entry: Entry variable to read into.
- * @index: Index to read.
- */
-static void
-ioapic_read_redentry(union ioapic_redentry *entry, uint8_t index)
-{
- uint32_t lo, hi;
-
- lo = ioapic_readl(IOREDTBL + index * 2);
- hi = ioapic_readl(IOREDTBL + index * 2 + 1);
-
- entry->value = ((uint64_t)hi << 32) | lo;
-}
-
-/*
- * Writes an I/O APIC redirection entry.
- *
- * @entry: Entry variable to write.
- * @index: Index to write to.
- */
-static void
-ioapic_write_redentry(const union ioapic_redentry *entry, uint8_t index)
-{
- ioapic_writel(IOREDTBL + index * 2, (uint32_t)entry->value);
- ioapic_writel(IOREDTBL + index * 2 + 1, (uint32_t)(entry->value >> 32));
-}
-
-/*
- * Mask I/O APIC pin with "raw" pin number
- * (Global System Interrupt)
- *
- * @gsi: Global System Interrupt number
- */
-void
-ioapic_gsi_mask(uint8_t gsi)
-{
- union ioapic_redentry redentry;
-
- ioapic_read_redentry(&redentry, gsi);
- redentry.interrupt_mask = 1;
- ioapic_write_redentry(&redentry, gsi);
-}
-
-/*
- * Unmask I/O APIC pin with "raw" pin number
- * (Global System Interrupt)
- *
- * @gsi: Global System Interrupt number
- */
-void
-ioapic_gsi_unmask(uint8_t gsi)
-{
- union ioapic_redentry redentry;
-
- ioapic_read_redentry(&redentry, gsi);
- redentry.interrupt_mask = 0;
- ioapic_write_redentry(&redentry, gsi);
-}
-
-/*
- * Masks I/O APIC pin via IRQ number
- *
- * @irq: Interrupt Request number
- */
-void
-ioapic_irq_mask(uint8_t irq)
-{
- uint8_t gsi;
-
- gsi = irq_to_gsi(irq);
- ioapic_gsi_mask(gsi);
-}
-
-/*
- * Unmasks I/O APIC pin via IRQ number
- *
- * @irq: Interrupt Request number
- */
-void
-ioapic_irq_unmask(uint8_t irq)
-{
- uint8_t gsi;
-
- gsi = irq_to_gsi(irq);
- ioapic_gsi_unmask(gsi);
-}
-
-void
-ioapic_set_base(void *mmio_base)
-{
- if (ioapic_base == NULL)
- ioapic_base = mmio_base;
-}
-
-void
-ioapic_set_vec(uint8_t irq, uint8_t vector)
-{
- union ioapic_redentry redentry;
- uint8_t gsi = irq_to_gsi(irq);
-
- ioapic_read_redentry(&redentry, gsi);
- redentry.vector = vector;
- ioapic_write_redentry(&redentry, gsi);
-}
-
-void
-ioapic_init(void)
-{
- size_t tmp;
- uint8_t redir_entry_cnt;
-
- /* Sanity check */
- if (ioapic_base == NULL)
- panic("ioapic base not set!\n");
-
- tmp = ioapic_readl(IOAPICVER);
- redir_entry_cnt = __SHIFTOUT(tmp, 0xFF << 16) + 1;
-
- pr_trace("Masking %d GSIs...\n", redir_entry_cnt);
-
- for (uint8_t i = 0; i < redir_entry_cnt; ++i) {
- ioapic_gsi_mask(i);
- }
-}
diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c
deleted file mode 100644
index 81432dd..0000000
--- a/sys/arch/amd64/amd64/lapic.c
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/lapic.h>
-#include <machine/lapicvar.h>
-#include <machine/cpuid.h>
-#include <machine/msr.h>
-#include <machine/cpu.h>
-#include <machine/idt.h>
-#include <machine/intr.h>
-#include <machine/sysvec.h>
-#include <machine/isa/i8254.h>
-#include <vm/vm.h>
-#include <sys/cdefs.h>
-#include <sys/timer.h>
-#include <sys/syslog.h>
-#include <sys/panic.h>
-#include <sys/mmio.h>
-
-__MODULE_NAME("lapic");
-__KERNEL_META("$Hyra$: lapic.c, Ian Marco Moffett, "
- "Local APIC driver");
-
-#define pr_trace(fmt, ...) kprintf("lapic: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-/*
- * Only calls pr_trace if we are the BSP.
- */
-#define BSP_TRACE(...) do { \
- uint64_t msr_val; \
- \
- msr_val = rdmsr(IA32_APIC_BASE_MSR); \
- if (__TEST(msr_val, 1 << 8)) { \
- pr_trace(__VA_ARGS__); \
- } \
- } while (0);
-
-static struct timer lapic_timer = { 0 };
-
-__naked void lapic_tmr_isr(void);
-
-/*
- * Returns true if LAPIC is supported.
- *
- * LAPIC is supported if CPUID.(EAX=1H):EDX[9] == 1
- */
-static inline bool
-lapic_check_support(void)
-{
- uint32_t eax, edx, tmp;
-
- __CPUID(0x00000001, eax, tmp, tmp, edx);
- return __TEST(edx, 1 << 9);
-}
-
-/*
- * Reads a 32 bit value from Local APIC
- * register space.
- *
- * @reg: Register to read from.
- */
-static inline uint64_t
-lapic_readl(uint32_t reg)
-{
- void *addr;
- const struct cpu_info *ci = this_cpu();
-
- if (!ci->has_x2apic) {
- addr = (void *)((uintptr_t)ci->lapic_base + reg);
- return mmio_read32(addr);
- } else {
- reg >>= 4;
- return rdmsr(x2APIC_MSR_BASE + reg);
- }
-}
-
-/*
- * Writes a 32 bit value to Local APIC
- * register space.
- *
- * @reg: Register to write to.
- */
-static inline void
-lapic_writel(uint32_t reg, uint64_t val)
-{
- void *addr;
- const struct cpu_info *ci = this_cpu();
-
- if (!ci->has_x2apic) {
- addr = (void *)((uintptr_t)ci->lapic_base + reg);
- mmio_write32(addr, val);
- } else {
- reg >>= 4;
- wrmsr(x2APIC_MSR_BASE + reg, val);
- }
-}
-
-/*
- * Calibrates the Local APIC timer - Timer abstraction
- */
-static size_t
-lapic_timer_calibrate(void)
-{
- size_t freq;
-
- lapic_timer_init(&freq);
- return freq;
-}
-
-/*
- * Stops the Local APIC timer - Timer abstraction
- */
-static void
-lapic_timer_stop(void)
-{
- lapic_writel(LAPIC_INIT_CNT, 0);
- lapic_writel(LAPIC_LVT_TMR, LAPIC_LVT_MASK);
-}
-
-/*
- * Set bits within a LAPIC register
- * without overwriting the whole thing.
- *
- * @reg: Reg with bits to be set.
- * @value: Value in reg will be ORd with this.
- */
-static inline void
-lapic_reg_set(uint32_t reg, uint32_t value)
-{
- uint32_t old;
-
- old = lapic_readl(reg);
- lapic_writel(reg, old | value);
-}
-
-/*
- * Clear bits within a LAPIC register
- * without overwriting the whole thing.
- *
- * @reg: Reg with bits to be cleared.
- * @value: Value in reg will be cleared by this value.
- */
-static inline void
-lapic_reg_clear(uint32_t reg, uint32_t value)
-{
- uint32_t old;
-
- old = lapic_readl(reg);
- lapic_writel(reg, old & ~(value));
-}
-
-/*
- * Reads the Local APIC ID of the
- * current processor.
- */
-static inline uint32_t
-lapic_get_id(const struct cpu_info *ci)
-{
- if (!ci->has_x2apic) {
- return (lapic_readl(LAPIC_ID) >> 24) & 0xF;
- } else {
- return lapic_readl(LAPIC_ID);
- }
-}
-
-/*
- * Checks if the processor supports x2APIC
- * mode. Returns true if so.
- */
-static inline bool
-has_x2apic(void)
-{
- uint32_t ecx, tmp;
-
- __CPUID(0x00000001, tmp, tmp, ecx, tmp);
- return __TEST(ecx, 1 << 21);
-}
-
-/*
- * Updates LDR to LAPIC_STARTUP_LID.
- *
- * XXX: This does *not* happen with x2APIC
- * as the LDR register in x2APIC mode
- * is readonly.
- */
-static inline void
-lapic_set_ldr(struct cpu_info *ci)
-{
- if (!ci->has_x2apic)
- lapic_writel(LAPIC_LDR, LAPIC_STARTUP_LID);
-}
-
-/*
- * Starts the Local APIC countdown timer...
- *
- * @mask: True to mask timer.
- * @mode: Timer mode.
- * @count: Count to start at.
- */
-static inline void
-lapic_timer_start(bool mask, uint8_t mode, uint32_t count)
-{
- uint32_t tmp;
-
- tmp = (mode << 17) | (mask << 16) | SYSVEC_LAPIC_TIMER;
- lapic_writel(LAPIC_LVT_TMR, tmp);
- lapic_writel(LAPIC_DCR, 0);
- lapic_writel(LAPIC_INIT_CNT, count);
-}
-
-/*
- * Start Local APIC timer oneshot with number
- * of ticks to count down from.
- *
- * @mask: If `true', timer will be masked, `count' should be 0.
- * @count: Number of ticks.
- */
-void
-lapic_timer_oneshot(bool mask, uint32_t count)
-{
- lapic_timer_start(mask, LVT_TMR_ONESHOT, count);
-}
-
-/*
- * Start Local APIC timer oneshot in microseconds.
- *
- * @us: Microseconds.
- */
-void
-lapic_timer_oneshot_us(size_t us)
-{
- uint64_t ticks;
- struct cpu_info *ci = this_cpu();
-
- ticks = us * (ci->lapic_tmr_freq / 1000000);
- lapic_timer_oneshot(false, ticks);
-}
-
-/*
- * Send an Interprocessor interrupt.
- *
- * @id: Target LAPIC ID
- * @shorthand: Dest shorthand
- * @vector: Interrupt vector
- */
-void
-lapic_send_ipi(uint8_t id, uint8_t shorthand, uint8_t vector)
-{
- const uint32_t x2APIC_IPI_SELF = 0x3F0;
- uint64_t icr_lo = vector | IPI_DEST_PHYSICAL;
- bool x2apic_supported = has_x2apic();
-
- if (x2apic_supported && shorthand == IPI_SHORTHAND_SELF) {
- lapic_writel(x2APIC_IPI_SELF, vector);
- return;
- }
-
- switch (shorthand) {
- case IPI_SHORTHAND_SELF:
- icr_lo |= (1 << 18);
- break;
- case IPI_SHORTHAND_ALL:
- icr_lo |= (2 << 18);
- break;
- case IPI_SHORTHAND_OTHERS:
- icr_lo |= (3 << 18);
- break;
- }
-
- /*
- * In contrast to xAPICs two 32-bit ICR registers, the x2APIC
- * ICR register is one big 64-bit register, thus requiring only
- * a single write. In xAPIC mode, the Delivery Status bit (bit 12)
- * must be polled until clear. However, in x2APIC mode, this bit
- * does not exist meaning we do not need to worry about it.
- */
- if (x2apic_supported) {
- lapic_writel(LAPIC_ICRLO, ((uint64_t)id << 32) | icr_lo);
- } else {
- lapic_writel(LAPIC_ICRHI, ((uint32_t)id << 24));
- lapic_writel(LAPIC_ICRLO, icr_lo);
- while (__TEST(lapic_readl(LAPIC_ICRLO), __BIT(12)));
- }
-}
-
-void
-lapic_send_eoi(void)
-{
- lapic_writel(LAPIC_EOI, 0);
-}
-
-/*
- * Calibrates the Local APIC timer
- *
- * TODO: Disable interrupts and put them back in
- * old state.
- *
- * XXX: Will unmask IRQs if masked; will restore
- * IRQ mask state after.
- */
-void
-lapic_timer_init(size_t *freq_out)
-{
- struct cpu_info *ci;
- bool irq_mask = is_intr_mask();
- uint16_t init_tick, final_tick;
- size_t total_ticks;
- const uint16_t SAMPLES = 0xFFFF;
-
- ci = this_cpu();
-
- if (irq_mask) {
- __ASMV("sti");
- }
-
- /* Stop the timer */
- lapic_timer_oneshot(true, 0);
-
- i8254_set_reload(SAMPLES);
- init_tick = i8254_get_count();
-
- lapic_writel(LAPIC_INIT_CNT, SAMPLES);
- while (lapic_readl(LAPIC_CUR_CNT) != 0);
-
- final_tick = i8254_get_count();
- total_ticks = init_tick - final_tick;
-
- /* Calculate the frequency */
- CPU_INFO_LOCK(ci);
- ci->lapic_tmr_freq = (SAMPLES / total_ticks) * i8254_DIVIDEND;
- if (freq_out != NULL) *freq_out = ci->lapic_tmr_freq;
- CPU_INFO_UNLOCK(ci);
-
- /* Stop timer again */
- lapic_timer_oneshot(true, 0);
-
- if (irq_mask) {
- __ASMV("cli");
- }
-}
-
-void
-lapic_init(void)
-{
- struct cpu_info *ci;
- union tss_stack tmr_stack;
- uint64_t tmp;
-
- if (!lapic_check_support()) {
- /*
- * Hyra currently depends on the existance
- * of a Local APIC.
- */
- panic("This machine does not support LAPIC!\n");
- }
-
- /* Get the current processor, and lock its structure */
- ci = this_cpu();
- CPU_INFO_LOCK(ci);
-
- ci->has_x2apic = has_x2apic();
-
- /* Sanity check */
- if (ci->lapic_base == NULL) {
- panic("LAPIC base not set!\n");
- }
-
- /* Hardware enable the Local APIC */
- tmp = rdmsr(IA32_APIC_BASE_MSR);
- tmp |= ci->has_x2apic << x2APIC_ENABLE_SHIFT;
- wrmsr(IA32_APIC_BASE_MSR, tmp | LAPIC_HW_ENABLE);
-
- /* Software enable the Local APIC via SVR */
- lapic_reg_set(LAPIC_SVR, LAPIC_SW_ENABLE);
-
- BSP_TRACE("Enabled Local APIC for BSP\n");
- lapic_set_ldr(ci);
-
- /* Setup the timer descriptor */
- lapic_timer.name = "LAPIC_INTEGRATED_TIMER";
- lapic_timer.calibrate = lapic_timer_calibrate;
- lapic_timer.stop = lapic_timer_stop;
- lapic_timer.oneshot_us = lapic_timer_oneshot_us;
-
- /* Register the timer for scheduler usage */
- register_timer(TIMER_SCHED, &lapic_timer);
-
- /* Set the Local APIC ID */
- ci->id = lapic_get_id(ci);
- BSP_TRACE("BSP Local APIC ID: %d\n", ci->id);
-
- /* Setup LAPIC Timer TSS stack */
- if (tss_alloc_stack(&tmr_stack, vm_get_page_size()) != 0) {
- panic("Failed to allocate LAPIC TMR stack! (1 page of mem)\n");
- }
- tss_update_ist(ci, tmr_stack, IST_SCHED);
- CPU_INFO_UNLOCK(ci);
-
- /* Calibrate timer */
- lapic_timer_init(NULL);
-
- /* Setup LAPIC Timer ISR */
- idt_set_desc(SYSVEC_LAPIC_TIMER, IDT_INT_GATE_FLAGS,
- (uintptr_t)lapic_tmr_isr, IST_SCHED);
-
- BSP_TRACE("LAPIC Timer on Interrupt Stack %d (IST_SCHED) with vector 0x%x\n",
- IST_SCHED, SYSVEC_LAPIC_TIMER);
-}
diff --git a/sys/arch/amd64/amd64/local_intr.S b/sys/arch/amd64/amd64/local_intr.S
deleted file mode 100644
index c2d53e9..0000000
--- a/sys/arch/amd64/amd64/local_intr.S
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/frameasm.h>
-#include <machine/trap.h>
-#include <sys/cdefs.h>
-
-__KERNEL_META "$Hyra$: local_intr.S, Ian Marco Moffett, \
- Routines for handling Local Interrupts"
-
-.text
- .globl lapic_tmr_isr
-
-lapic_tmr_isr:
- push_trapframe $0
- mov %rsp, %rdi
- call sched_context_switch
- call handle_local_tmr
- call lapic_send_eoi
- pop_trapframe
- iretq
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
deleted file mode 100644
index 0c2718a..0000000
--- a/sys/arch/amd64/amd64/machdep.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/machdep.h>
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <sys/ksyms.h>
-#include <sys/timer.h>
-#include <machine/trap.h>
-#include <machine/idt.h>
-#include <machine/io.h>
-#include <machine/gdt.h>
-#include <machine/ioapic.h>
-#include <machine/hpet.h>
-#include <machine/lapic.h>
-#include <machine/tss.h>
-#include <machine/spectre.h>
-#include <machine/isa/spkr.h>
-#include <machine/cpu.h>
-#include <machine/uart.h>
-#include <machine/cpuid.h>
-#include <machine/sysvec.h>
-#include <dev/pci/pci.h>
-#include <vm/vm.h>
-#include <vm/dynalloc.h>
-#include <vm/physseg.h>
-#include <firmware/acpi/acpi.h>
-#include <sys/syslog.h>
-#include <assert.h>
-#include <string.h>
-
-__MODULE_NAME("machdep");
-__KERNEL_META("$Hyra$: machdep.c, Ian Marco Moffett, "
- "Core machine dependent code");
-
-#define ISR(func) ((uintptr_t)func)
-#define INIT_FLAG_IOAPIC 0x00000001U
-#define INIT_FLAG_ACPI 0x00000002U
-
-/* Set by kconf(1) */
-#define PANIC_BEEP_HZ __PANIC_BEEP_HZ
-#define PANIC_BEEP __PANIC_BEEP
-
-void syscall_isr(void);
-
-__attr(interrupt)
-static void
-halt_isr(void *sf)
-{
- processor_halt();
-}
-
-static inline void
-init_tss(struct cpu_info *cur_cpu)
-{
- struct tss_desc *desc;
-
- desc = (struct tss_desc *)g_gdt_tss;
- write_tss(cur_cpu, desc);
- tss_load();
-}
-
-static void
-interrupts_init(void)
-{
- idt_set_desc(0x0, IDT_TRAP_GATE_FLAGS, ISR(arith_err), 0);
- idt_set_desc(0x2, IDT_TRAP_GATE_FLAGS, ISR(nmi), 0);
- idt_set_desc(0x3, IDT_TRAP_GATE_FLAGS, ISR(breakpoint_handler), 0);
- idt_set_desc(0x4, IDT_TRAP_GATE_FLAGS, ISR(overflow), 0);
- idt_set_desc(0x5, IDT_TRAP_GATE_FLAGS, ISR(bound_range), 0);
- idt_set_desc(0x6, IDT_TRAP_GATE_FLAGS, ISR(invl_op), 0);
- idt_set_desc(0x8, IDT_TRAP_GATE_FLAGS, ISR(double_fault), 0);
- idt_set_desc(0xA, IDT_TRAP_GATE_FLAGS, ISR(invl_tss), 0);
- idt_set_desc(0xB, IDT_TRAP_GATE_FLAGS, ISR(segnp), 0);
- idt_set_desc(0xC, IDT_TRAP_GATE_FLAGS, ISR(ss_fault), 0);
- idt_set_desc(0xD, IDT_TRAP_GATE_FLAGS, ISR(general_prot), 0);
- idt_set_desc(0xE, IDT_TRAP_GATE_FLAGS, ISR(page_fault), 0);
- idt_set_desc(0x80, IDT_INT_GATE_USER, ISR(syscall_isr), 0);
- idt_set_desc(SYSVEC_HLT, IDT_INT_GATE_FLAGS, ISR(halt_isr), 0);
- idt_load();
-}
-
-static bool
-is_sse_supported(void)
-{
- uint32_t edx, unused;
-
- __CPUID(0x00000001, unused, unused, unused, edx);
- return __TEST(edx, __BIT(25)) && __TEST(edx, __BIT(26));
-}
-
-static const char*
-backtrace_addr_to_name(uintptr_t addr, off_t *off)
-{
- uintptr_t prev_addr = 0;
- const char *name = NULL;
-
- for (size_t i = 0;;) {
- if (g_ksym_table[i].addr > addr) {
- *off = addr - prev_addr;
- return name;
- }
-
- prev_addr = g_ksym_table[i].addr;
- name = g_ksym_table[i].name;
- if (g_ksym_table[i++].addr == (uint64_t)-1)
- break;
- }
-
- return NULL;
-}
-
-static void
-backtrace(void)
-{
- uintptr_t *rbp;
- uintptr_t rip;
-
- off_t off;
- const char *name;
-
- kprintf(OMIT_TIMESTAMP "** Backtrace **\n");
- __ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory");
-
- while (1) {
- rip = rbp[1];
- rbp = (uintptr_t *)rbp[0];
- name = backtrace_addr_to_name(rip, &off);
-
- if (rbp == NULL)
- break;
- if (name == NULL)
- name = "???";
-
- kprintf(OMIT_TIMESTAMP "[0x%p] <%s+0x%x>\n", rip, name, off);
- }
-}
-
-static void
-panic_beep(void)
-{
- struct timer tmr = {0};
- bool has_timer = true;
-
- if (req_timer(TIMER_GP, &tmr) != TMRR_SUCCESS)
- has_timer = false;
- if (tmr.msleep == NULL)
- has_timer = false;
-
- /*
- * If we can use the timer, beep twice to
- * alert the user.
- */
- if (has_timer) {
- for (int i = 0; i < 2; ++i) {
- pcspkr_tone(PANIC_BEEP_HZ, 200);
- tmr.msleep(100);
- }
- }
-}
-
-void
-processor_halt(void)
-{
- __ASMV("cli; hlt");
-}
-
-/*
- * Send char to serial for debugging purposes.
- */
-void
-serial_dbgch(char c)
-{
- uart8250_write(c);
-}
-
-void
-chips_init(void)
-{
- /* Hyra requires HPET on x86_64 */
- if (hpet_init() != 0)
- panic("Machine does not support HPET!\n");
-
- pci_init();
-}
-
-/*
- * These are critical things that need to be set up as soon as possible
- * way before the processor_init() call.
- */
-void
-pre_init(void)
-{
- static bool is_bsp = true;
-
- /*
- * Certain things like serial ports, virtual memory,
- * etc, need to be set up only once! These things
- * are to be done on the BSP only...
- */
- if (is_bsp) {
- is_bsp = false;
-
- uart8250_try_init();
- vm_physseg_init();
- vm_init();
- }
- interrupts_init();
- gdt_load(&g_gdtr);
-}
-
-void
-intr_mask(void)
-{
- __ASMV("cli");
-}
-
-void
-intr_unmask(void)
-{
- __ASMV("sti");
-}
-
-/*
- * Called last within panic()
- */
-void
-machine_panic(void)
-{
- backtrace();
-
- if (PANIC_BEEP)
- panic_beep();
-
- processor_halt();
-}
-
-void
-cpu_halt_others(void)
-{
- struct cpu_info *ci = this_cpu();
-
- /* Is the current CPU structure even valid? */
- if (ci == NULL)
- return;
-
- /*
- * If the Local APIC base address is NULL, we can't
- * use lapic_send_ipi() but we we can assume the APs
- * are still parked.
- */
- if (ci->lapic_base != NULL)
- lapic_send_ipi(0, IPI_SHORTHAND_OTHERS, SYSVEC_HLT);
-}
-
-int
-processor_init_pcb(struct proc *proc)
-{
- struct pcb *pcb = &proc->pcb;
- const uint16_t FPU_FCW = 0x33F;
- const uint32_t SSE_MXCSR = 0x1F80;
-
- /* Allocate FPU save area, aligned on a 16 byte boundary */
- pcb->fpu_state = PHYS_TO_VIRT(vm_alloc_pageframe(1));
- if (pcb->fpu_state == NULL) {
- return -1;
- }
-
- /*
- * Setup x87 FPU control word and SSE MXCSR bits
- * as per the sysv ABI
- */
- __ASMV("fldcw %0\n"
- "ldmxcsr %1"
- :: "m" (FPU_FCW),
- "m" (SSE_MXCSR) : "memory");
-
- amd64_fxsave(pcb->fpu_state);
- return 0;
-}
-
-int
-processor_free_pcb(struct proc *proc)
-{
- struct pcb *pcb = &proc->pcb;
-
- if (pcb->fpu_state == NULL) {
- return -1;
- }
-
- vm_free_pageframe(VIRT_TO_PHYS(pcb->fpu_state), 1);
- return 0;
-}
-
-void
-processor_switch_to(struct proc *old_td, struct proc *new_td)
-{
- struct pcb *old_pcb = (old_td != NULL) ? &old_td->pcb : NULL;
- struct pcb *new_pcb = &new_td->pcb;
-
- if (old_pcb != NULL) {
- amd64_fxsave(old_pcb->fpu_state);
- }
- amd64_fxrstor(new_pcb->fpu_state);
-}
-
-void
-cpu_reset(void)
-{
- for (;;) {
- /* Pulse the reset line */
- outb(0x64, 0xFE);
- }
-}
-
-void
-processor_init(void)
-{
- /* Indicates what doesn't need to be init anymore */
- static uint8_t init_flags = 0;
- static uint64_t reg_tmp;
- struct cpu_info *cur_cpu;
-
- /* Create our cpu_info structure */
- cur_cpu = dynalloc(sizeof(struct cpu_info));
- __assert(cur_cpu != NULL);
- memset(cur_cpu, 0, sizeof(struct cpu_info));
-
- /* Set %GS to cpu_info */
- amd64_write_gs_base((uintptr_t)cur_cpu);
-
- /* Try to enable SSE/SSE2 */
- if (is_sse_supported()) {
- reg_tmp = amd64_read_cr0();
- reg_tmp &= ~(__BIT(2));
- reg_tmp |= __BIT(1);
- amd64_write_cr0(reg_tmp);
-
- /* Enable FXSAVE/FXRSTOR */
- reg_tmp = amd64_read_cr4();
- reg_tmp |= 3 << 9;
- amd64_write_cr4(reg_tmp);
- } else {
- panic("SSE/SSE2 not supported!\n");
- }
-
- CPU_INFO_LOCK(cur_cpu);
- init_tss(cur_cpu);
-
- /* Set up some ACPI things */
- if (!__TEST(init_flags, INIT_FLAG_ACPI)) {
- /*
- * Parse the MADT... This is needed to fetch required information
- * to set up the Local APIC(s) and I/O APIC(s)...
- */
- init_flags |= INIT_FLAG_ACPI;
- acpi_parse_madt(cur_cpu);
- }
-
- /* Setup I/O APIC */
- if (!__TEST(init_flags, INIT_FLAG_IOAPIC)) {
- init_flags |= INIT_FLAG_IOAPIC;
- ioapic_init();
- }
-
- cur_cpu->lapic_base = acpi_get_lapic_base();
- CPU_INFO_UNLOCK(cur_cpu);
- lapic_init();
-
- /* Use spectre mitigation if enabled */
- if (try_spectre_mitigate != NULL)
- try_spectre_mitigate();
-
- __ASMV("sti");
-}
diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c
deleted file mode 100644
index 9443727..0000000
--- a/sys/arch/amd64/amd64/pmap.c
+++ /dev/null
@@ -1,389 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/pmap.h>
-#include <vm/vm.h>
-#include <vm/physseg.h>
-#include <sys/cdefs.h>
-#include <sys/cpu.h>
-#include <sys/intr.h>
-#include <machine/tlb.h>
-#include <machine/lapic.h>
-#include <machine/sysvec.h>
-#include <machine/idt.h>
-#include <assert.h>
-#include <string.h>
-
-/*
- * Page-Table Entry (PTE) flags
- *
- * See Intel SDM Vol 3A, Section 4.5, Table 4-19
- */
-#define PTE_ADDR_MASK 0x000FFFFFFFFFF000
-#define PTE_P __BIT(0) /* Present */
-#define PTE_RW __BIT(1) /* Writable */
-#define PTE_US __BIT(2) /* User r/w allowed */
-#define PTE_PWT __BIT(3) /* Page-level write-through */
-#define PTE_PCD __BIT(4) /* Page-level cache disable */
-#define PTE_ACC __BIT(5) /* Accessed */
-#define PTE_DIRTY __BIT(6) /* Dirty (written-to page) */
-#define PTE_PAT __BIT(7)
-#define PTE_GLOBAL __BIT(8)
-#define PTE_NX __BIT(63) /* Execute-disable */
-
-__attr(interrupt) static void
-tlb_shootdown_isr(void *sf)
-{
- struct cpu_info *ci = this_cpu();
- struct intr_info *intr_info = ci->tlb_shootdown;
-
- /* Setup interrupt information if needed */
- if (ci->tlb_shootdown == NULL) {
- intr_info = intr_info_alloc("TLB-Shootdown", "LAPIC-IPI");
- intr_info->affinity = ci->id;
-
- ci->tlb_shootdown = intr_info;
- intr_register(intr_info);
- }
-
- ++intr_info->count;
- tlb_flush(ci->tlb_flush_ptr);
-
- ci->tlb_flush_ptr = 0;
- lapic_send_eoi();
-}
-
-static void
-tlb_shootdown(vaddr_t flush_va)
-{
- struct cpu_info *curcpu, *ci = NULL;
- size_t idx = 0;
-
- curcpu = this_cpu();
- while ((ci = cpu_get(idx++)) != NULL) {
- if (ci->id == curcpu->id)
- continue;
-
- ci->tlb_flush_ptr = flush_va;
- }
-
- lapic_send_ipi(0, IPI_SHORTHAND_OTHERS, SYSVEC_TLB);
-}
-
-/*
- * Convert pmap prot flags to PTE flags.
- */
-static uint64_t
-pmap_prot_to_pte(vm_prot_t prot)
-{
- uint64_t pte_flags = PTE_P | PTE_NX;
-
- if (__TEST(prot, PROT_WRITE))
- pte_flags |= PTE_RW;
- if (__TEST(prot, PROT_EXEC))
- pte_flags &= ~(PTE_NX);
- if (__TEST(prot, PROT_USER))
- pte_flags |= PTE_US;
-
- return pte_flags;
-}
-
-/*
- * Returns index for a specific pagemap level.
- *
- * @level: Requested level.
- * @va: Virtual address.
- */
-static size_t
-pmap_get_level_index(uint8_t level, vaddr_t va)
-{
- /* TODO: Make this bullshit assertion better */
- __assert(level <= 4 && level != 0);
-
- switch (level) {
- case 4:
- return (va >> 39) & 0x1FF;
- case 3:
- return (va >> 30) & 0x1FF;
- case 2:
- return (va >> 21) & 0x1FF;
- case 1:
- return (va >> 12) & 0x1FF;
- default: /* Should not be reachable */
- return 0;
- }
-}
-
-static inline uintptr_t *
-pmap_extract(uint8_t level, vaddr_t va, uintptr_t *pmap, bool allocate)
-{
- uintptr_t next;
- uintptr_t level_alloc;
- size_t idx;
-
- idx = pmap_get_level_index(level, va);
-
- if (__TEST(pmap[idx], PTE_P)) {
- next = pmap[idx] & PTE_ADDR_MASK;
- return PHYS_TO_VIRT(next);
- }
-
- if (!allocate) {
- return 0;
- }
-
- /*
- * TODO: If we are out of pageframes here, we don't want to panic
- * here. We need to have some sort of clean error reporting.
- */
- level_alloc = vm_alloc_pageframe(1);
- __assert(level_alloc != 0);
-
- /* Zero the memory */
- memset(PHYS_TO_VIRT(level_alloc), 0, vm_get_page_size());
-
- pmap[idx] = level_alloc | (PTE_P | PTE_RW | PTE_US);
- return PHYS_TO_VIRT(level_alloc);
-}
-
-/*
- * Modify a page table by writing `val' to it.
- *
- * @ctx: Virtual memory context.
- * @vas: Virtual address space.
- * @va: Virtual address.
- * @alloc: True to alloc new entries.
- * @res: Result
- */
-static int
-pmap_get_tbl(struct vm_ctx *ctx, struct vas vas, vaddr_t va, bool alloc,
- uintptr_t **res)
-{
- uintptr_t *pml4 = PHYS_TO_VIRT(vas.top_level);
- uintptr_t *pdpt, *pd, *tbl;
- int status = 0;
-
- pdpt = pmap_extract(4, va, pml4, alloc);
- if (pdpt == NULL) {
- status = 1;
- goto done;
- }
-
- pd = pmap_extract(3, va, pdpt, alloc);
- if (pd == NULL) {
- status = 1;
- goto done;
- }
-
- tbl = pmap_extract(2, va, pd, alloc);
- if (tbl == NULL) {
- status = 1;
- goto done;
- }
-
- *res = tbl;
-done:
- return status;
-}
-
-/*
- * Flush a virtual address.
- *
- * @va: VA to flush from TLB.
- */
-static void
-pmap_flush(vaddr_t va)
-{
- /*
- * Do TLB shootdown if multiple CPUs are listed.
- *
- * XXX: Some might not be listed during early
- * startup.
- */
- if (cpu_count() > 1) {
- tlb_shootdown(va);
- }
-
- tlb_flush(va);
-}
-
-/*
- * Modify a page table by writing `val' to it.
- *
- * TODO: Ensure operations here are serialized.
- */
-static int
-pmap_modify_tbl(struct vm_ctx *ctx, struct vas vas, vaddr_t va, size_t val)
-{
- uintptr_t *tbl;
- int status;
-
- if ((status = pmap_get_tbl(ctx, vas, va, true, &tbl) != 0)) {
- return status;
- }
-
- /* Map our page */
- tbl[pmap_get_level_index(1, va)] = val;
- pmap_flush(va);
- return 0;
-}
-
-int
-pmap_set_cache(struct vm_ctx *ctx, struct vas vas, vaddr_t va, int type)
-{
- uintptr_t *tbl;
- int status;
- size_t idx;
-
- if ((status = pmap_get_tbl(ctx, vas, va, false, &tbl)) != 0) {
- return status;
- }
-
- idx = pmap_get_level_index(1, va);
-
- /* Set the policy based on the type */
- switch (type) {
- case VM_CACHE_UC:
- tbl[idx] |= PTE_PCD;
- tbl[idx] &= ~(PTE_PWT);
- break;
- case VM_CACHE_WT:
- tbl[idx] &= ~(PTE_PCD);
- tbl[idx] |= PTE_PWT;
- break;
- default:
- /* Invalid type */
- return 1;
- }
-
- pmap_flush(va);
- return 0;
-}
-
-int
-pmap_map(struct vm_ctx *ctx, struct vas vas, vaddr_t va, paddr_t pa,
- vm_prot_t prot)
-{
- uint32_t flags = pmap_prot_to_pte(prot);
-
- return pmap_modify_tbl(ctx, vas, va, (pa | flags));
-}
-
-int
-pmap_unmap(struct vm_ctx *ctx, struct vas vas, vaddr_t va)
-{
- return pmap_modify_tbl(ctx, vas, va, 0);
-}
-
-int
-pmap_create_vas(struct vm_ctx *ctx, struct vas *res)
-{
- struct vas current_vas = pmap_read_vas();
- struct vas new_vas = {0};
- uint64_t *src, *dest;
-
- /*
- * We want to allocate a zeroed pageframe
- * and copy the higher half to it. The lower
- * half can remain zero for userland.
- */
- new_vas.top_level = vm_alloc_pageframe(1);
-
- if (new_vas.top_level == 0) {
- return -1;
- }
-
- src = PHYS_TO_VIRT(current_vas.top_level);
- dest = PHYS_TO_VIRT(new_vas.top_level);
-
- /*
- * Copy the top half and zero the bottom
- * half.
- */
- for (size_t i = 0; i < 512; ++i) {
- if (i < 256) {
- dest[i] = 0;
- continue;
- }
- dest[i] = src[i];
- }
-
- *res = new_vas;
- return 0;
-}
-
-void
-pmap_switch_vas(struct vm_ctx *ctx, struct vas vas)
-{
- uintptr_t cr3_val = vas.cr3_flags | vas.top_level;
-
- __ASMV("mov %0, %%cr3"
- :
- : "r" (cr3_val)
- : "memory");
-}
-
-/*
- * TODO: During the mapping of a virtual address, a level
- * may be allocated. This function does not handle the
- * freeing of allocated levels. We should keep track
- * of levels allocated and free them here.
- */
-int
-pmap_free_vas(struct vm_ctx *ctx, struct vas vas)
-{
- vm_free_pageframe(vas.top_level, 1);
- return 0;
-}
-
-struct vas
-pmap_read_vas(void)
-{
- struct vas vas;
- uintptr_t cr3_raw;
-
- __ASMV("mov %%cr3, %0"
- : "=r" (cr3_raw)
- );
-
- vas.cr3_flags = cr3_raw & ~PTE_ADDR_MASK;
- vas.top_level = cr3_raw & PTE_ADDR_MASK;
- vas.use_l5_paging = false; /* TODO: Check for support */
- vas.lock.lock = 0;
- return vas;
-}
-
-int
-pmap_init(struct vm_ctx *ctx)
-{
- idt_set_desc(SYSVEC_TLB, IDT_INT_GATE_FLAGS,
- (uintptr_t)tlb_shootdown_isr, 0);
-
- return 0;
-}
diff --git a/sys/arch/amd64/amd64/spectre.S b/sys/arch/amd64/amd64/spectre.S
deleted file mode 100644
index 08ff9f8..0000000
--- a/sys/arch/amd64/amd64/spectre.S
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__KERNEL_META "$Hyra$: spectre.S, Ian Marco Moffett, \
- Spectre mitigation detection"
-
-.text
-.globl __can_mitigate_spectre
-
-__can_mitigate_spectre:
- xor %ecx, %ecx // NULL out ECX
- mov $0x7, %eax // 0x7 (Check IBRS)
- cpuid
-
- /* Check if supported (if EDX[26] == 1) */
- mov $1, %ebx
- shl $26, %ebx
- test %ebx, %edx
- jnz supported
-not_supported:
- xor %rax, %rax
- jmp 1f
-supported:
- mov $1, %rax
-1:
- ret
diff --git a/sys/arch/amd64/amd64/spectre.c b/sys/arch/amd64/amd64/spectre.c
deleted file mode 100644
index 05aa557..0000000
--- a/sys/arch/amd64/amd64/spectre.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/spectre.h>
-#include <machine/cpuid.h>
-#include <machine/msr.h>
-#include <sys/syslog.h>
-#include <sys/types.h>
-
-__MODULE_NAME("spectre");
-__KERNEL_META("$Hyra$: spectre.c, Ian Marco Moffett, "
- "Spectre mitigation support");
-
-#if __SPECTRE_MITIGATION == 1
-
-/*
- * Returns true if Indirect Branch Restricted Speculation (IBRS)
- * is supported.
- */
-__naked bool
-__can_mitigate_spectre(void);
-
-/*
- * Returns EXIT_FAILURE if not supported, returns
- * EXIT_SUCCESS if mitigation is now active.
- *
- * This function will be NULL if spectre mitigation isn't enabled;
- * therefore it is wise to verify to prevent access violations and
- * undefined behaviour.
- *
- * This behaviour is governed by the __SPECTRE_MITIGATION define
- *
- * TODO: Try to enable others, not just IBRS
- */
-__weak int
-try_spectre_mitigate(void)
-{
- uint64_t tmp;
- static bool should_log = true;
-
- if (!__can_mitigate_spectre()) {
- KINFO("IBRS not supported; spectre mitigation NOT enabled\n");
- return EXIT_FAILURE;
- }
-
- /* This is called per processor, only log once */
- if (should_log) {
- KINFO("IBRS supported; spectre mitigation enabled\n");
- should_log = false;
- }
-
- tmp = rdmsr(IA32_SPEC_CTL);
- tmp |= __BIT(0); /* IBRS */
- wrmsr(IA32_SPEC_CTL, tmp);
-
- return EXIT_SUCCESS;
-}
-
-#endif /* __SPECTRE_MITIGATION == 1 */
diff --git a/sys/arch/amd64/amd64/syscall.S b/sys/arch/amd64/amd64/syscall.S
deleted file mode 100644
index fe70523..0000000
--- a/sys/arch/amd64/amd64/syscall.S
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
- #include <sys/cdefs.h>
- #include <machine/frameasm.h>
-
-__KERNEL_META "$Hyra$: syscall.S, Ian Marco Moffett, \
- Syscall ISR code"
-
-.text
-.globl syscall_isr
-syscall_isr:
- push_trapframe $0
- mov %rsp, %rdi
- call __syscall
- pop_trapframe
- iretq
diff --git a/sys/arch/amd64/amd64/syscall.c b/sys/arch/amd64/amd64/syscall.c
deleted file mode 100644
index 264c8df..0000000
--- a/sys/arch/amd64/amd64/syscall.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/syscall.h>
-
-void
-__syscall(struct trapframe *tf)
-{
- struct syscall_args args = {
- .code = tf->rax,
- .arg0 = tf->rdi,
- .arg1 = tf->rsi,
- .arg2 = tf->rdx,
- .arg3 = tf->r10,
- .arg4 = tf->r9,
- .arg5 = tf->r8,
- .sp = tf->rsp,
- .ip = tf->rip
- };
-
- if (args.code < __MAX_SYSCALLS && args.code > 0) {
- args.code -= 1;
- tf->rax = g_syscall_table[args.code](&args);
- }
-
- tf->rip = args.ip;
- tf->rsp = args.sp;
-}
diff --git a/sys/arch/amd64/amd64/trap.S b/sys/arch/amd64/amd64/trap.S
deleted file mode 100644
index 3cf6888..0000000
--- a/sys/arch/amd64/amd64/trap.S
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/frameasm.h>
-#include <machine/trap.h>
-#include <sys/cdefs.h>
-
-__KERNEL_META "$Hyra$: trap.S, Ian Marco Moffett, \
- Trap handling routines"
-
-.text
-.globl breakpoint_handler
-breakpoint_handler:
- push_trapframe_ec $TRAP_BREAKPOINT
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl arith_err
-arith_err:
- push_trapframe_ec $TRAP_ARITH_ERR
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl overflow
-overflow:
- push_trapframe_ec $TRAP_OVERFLOW
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl bound_range
-bound_range:
- push_trapframe_ec $TRAP_BOUND_RANGE
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl invl_op
-invl_op:
- push_trapframe_ec $TRAP_INVLOP
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl double_fault
-double_fault:
- push_trapframe_ec $TRAP_DOUBLE_FAULT
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl invl_tss
-invl_tss:
- push_trapframe_ec $TRAP_INVLTSS
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl segnp
-segnp:
- push_trapframe_ec $TRAP_SEGNP
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl general_prot
-general_prot:
- push_trapframe_ec $TRAP_PROTFLT
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl page_fault
-page_fault:
- push_trapframe_ec $TRAP_PAGEFLT
-
- handle_trap
-
- pop_trapframe
- iretq
-
-.globl nmi
-nmi:
- push_trapframe_ec $TRAP_NMI
-
- handle_trap
-
- /* TODO */
- cli
- hlt
-
-.globl ss_fault
-ss_fault:
- push_trapframe_ec $TRAP_SS
-
- handle_trap
-
- /* TODO */
- cli
- hlt
diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c
deleted file mode 100644
index 531f2f5..0000000
--- a/sys/arch/amd64/amd64/trap.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/trap.h>
-#include <sys/cdefs.h>
-#include <sys/spinlock.h>
-#include <sys/syslog.h>
-#include <sys/panic.h>
-#include <sys/signal.h>
-#include <sys/proc.h>
-#include <sys/sched.h>
-#include <sys/schedvar.h>
-#include <sys/timer.h>
-#include <sys/machdep.h>
-#include <vm/fault.h>
-
-__MODULE_NAME("trap");
-__KERNEL_META("$Hyra$: trap.c, Ian Marco Moffett, "
- "Trap handling");
-
-#define pr_error(fmt, ...) kprintf("trap: " fmt, ##__VA_ARGS__)
-
-static const char *trap_type[] = {
- [TRAP_BREAKPOINT] = "breakpoint",
- [TRAP_ARITH_ERR] = "arithmetic error",
- [TRAP_OVERFLOW] = "overflow",
- [TRAP_BOUND_RANGE] = "bound range exceeded",
- [TRAP_INVLOP] = "invalid opcode",
- [TRAP_DOUBLE_FAULT] = "double fault",
- [TRAP_INVLTSS] = "invalid TSS",
- [TRAP_SEGNP] = "segment not present",
- [TRAP_PROTFLT] = "general protection",
- [TRAP_PAGEFLT] = "page fault",
- [TRAP_NMI] = "non-maskable interrupt",
- [TRAP_SS] = "stack-segment fault"
-};
-
-static const int TRAP_COUNT = __ARRAY_COUNT(trap_type);
-
-static inline vaddr_t
-pf_faultaddr(void)
-{
- uintptr_t cr2;
- __ASMV("mov %%cr2, %0\n" : "=r" (cr2) :: "memory");
- return cr2;
-}
-
-static inline vm_prot_t
-pf_accesstype(struct trapframe *tf)
-{
- vm_prot_t prot = 0;
- uint64_t ec = tf->error_code;
-
- if (__TEST(ec, __BIT(1)))
- prot |= PROT_WRITE;
- if (__TEST(ec, __BIT(2)))
- prot |= PROT_USER;
- if (__TEST(ec, __BIT(4)))
- prot |= PROT_EXEC;
-
- return prot;
-}
-
-static void
-dbg_errcode(struct trapframe *tf)
-{
- uint64_t ec = tf->error_code;
-
- switch (tf->trapno) {
- case TRAP_PAGEFLT:
- kprintf(OMIT_TIMESTAMP
- "bits (pwui): %c%c%c%c\n",
- __TEST(ec, __BIT(0)) ? 'p' : '-',
- __TEST(ec, __BIT(1)) ? 'w' : '-',
- __TEST(ec, __BIT(2)) ? 'u' : '-',
- __TEST(ec, __BIT(4)) ? 'i' : '-');
- break;
- case TRAP_SS:
- kprintf(OMIT_TIMESTAMP "ss: 0x%x\n", ec);
- break;
- }
-}
-
-static void
-trap_print(struct trapframe *tf)
-{
- if (tf->trapno < TRAP_COUNT) {
- kprintf(OMIT_TIMESTAMP "** Fatal %s **\n", trap_type[tf->trapno]);
- } else {
- kprintf(OMIT_TIMESTAMP "** Unknown trap %d **\n", tf->trapno);
- }
-
- dbg_errcode(tf);
-}
-
-static void
-regdump(struct trapframe *tf)
-{
- uintptr_t cr3, cr2 = pf_faultaddr();
-
- __ASMV("mov %%cr3, %0\n"
- : "=r" (cr3)
- :
- : "memory"
- );
-
- kprintf(OMIT_TIMESTAMP
- "RAX=%p RCX=%p RDX=%p\n"
- "RBX=%p RSI=%p RDI=%p\n"
- "RFL=%p CR2=%p CR3=%p\n"
- "RBP=%p RSP=%p RIP=%p\n",
- tf->rax, tf->rcx, tf->rdx,
- tf->rbx, tf->rsi, tf->rdi,
- tf->rflags, cr2, cr3,
- tf->rbp, tf->rsp, tf->rip);
-}
-
-static inline void
-handle_fatal(struct trapframe *tf)
-{
- trap_print(tf);
- regdump(tf);
- panic("Halted\n");
-}
-
-/*
- * Raise a fatal signal.
- *
- * @curtd: Current thread.
- * @sched_tmr: Scheduler timer.
- * @sig: Signal to raise.
- */
-static void
-raise_fatal(struct proc *curtd, struct timer *sched_tmr, int sig)
-{
- /*
- * trap_handler() disables interrupts. We will be
- * killing the current process but before we do that
- * we need to make sure interrupts are running and the
- * scheduler timer is still going...
- */
- intr_unmask();
- sched_tmr->oneshot_us(DEFAULT_TIMESLICE_USEC);
- signal_raise(curtd, sig);
-}
-
-/*
- * Handle a pagefault occuring in the userland
- *
- * @curtd: Current thread.
- * @tf: Trapframe.
- * @sched_tmr: Scheduler timer.
- */
-static void
-handle_user_pf(struct proc *curtd, struct trapframe *tf,
- struct timer *sched_tmr)
-{
- uintptr_t fault_addr;
- vm_prot_t access_type;
- int s;
-
- fault_addr = pf_faultaddr();
- access_type = pf_accesstype(tf);
- s = vm_fault(fault_addr, access_type);
-
- if (s != 0) {
- pr_error("Got page fault @ 0x%p\n", fault_addr);
- pr_error("Fault access mask: 0x%x\n", access_type);
- pr_error("Raising SIGSEGV to PID %d...\n", curtd->pid);
- regdump(tf);
- raise_fatal(curtd, sched_tmr, SIGSEGV);
- }
-}
-
-/*
- * Handles traps.
- */
-void
-trap_handler(struct trapframe *tf)
-{
- struct proc *curtd = this_td();
- struct timer sched_tmr;
- tmrr_status_t tmrr_s;
-
- /*
- * Mask interrupts so we don't get put in a funky
- * state as we are dealing with this trap. Then the next
- * thing we want to do is fetch the sched timer so we can
- * ensure it is running after we unmask the interrupts.
- */
- intr_mask();
- tmrr_s = req_timer(TIMER_SCHED, &sched_tmr);
- if (__unlikely(tmrr_s != TMRR_SUCCESS)) {
- trap_print(tf);
- panic("Could not fetch TIMER_SCHED (tmrr_s=0x%x)\n", tmrr_s);
- }
-
- /*
- * We should be able to perform a usec oneshot but
- * make sure just in case.
- */
- if (__unlikely(sched_tmr.oneshot_us == NULL)) {
- trap_print(tf);
- panic("Timer oneshot_us is NULL!\n");
- }
-
- /*
- * XXX: Handle NMIs better. For now we just
- * panic.
- */
- if (tf->trapno == TRAP_NMI) {
- trap_print(tf);
- kprintf(OMIT_TIMESTAMP "Possible hardware failure?\n");
- panic(OMIT_TIMESTAMP "Caught NMI; bailing out\n");
- }
-
- if (curtd == NULL) {
- handle_fatal(tf);
- } else if (!curtd->is_user) {
- handle_fatal(tf);
- }
-
- switch (tf->trapno) {
- case TRAP_ARITH_ERR:
- pr_error("Got arithmetic error - raising SIGFPE...\n");
- pr_error("SIGFPE -> PID %d\n", curtd->pid);
- raise_fatal(curtd, &sched_tmr, SIGFPE);
- break;
- case TRAP_PAGEFLT:
- handle_user_pf(curtd, tf, &sched_tmr);
- break;
- default:
- pr_error("Got %s - raising SIGSEGV...\n", trap_type[tf->trapno]);
- pr_error("SIGSEGV -> PID %d\n", curtd->pid);
- regdump(tf);
- raise_fatal(curtd, &sched_tmr, SIGSEGV);
- break;
- }
-
- /* All good, unmask and start sched timer */
- intr_unmask();
- sched_tmr.oneshot_us(DEFAULT_TIMESLICE_USEC);
-}
diff --git a/sys/arch/amd64/amd64/tss.S b/sys/arch/amd64/amd64/tss.S
deleted file mode 100644
index 8cff06b..0000000
--- a/sys/arch/amd64/amd64/tss.S
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-
-__KERNEL_META "$Hyra$: tss.S, Ian Marco Moffett, \
- Low level TSS code"
-
-.globl tss_load
-tss_load:
- str %ax /* Store task register value into AX */
- mov $0x28, %ax /* Store TSS GDT selector into AX */
- or $3, %ax
- ltr %ax /* Load the task register */
- retq
diff --git a/sys/arch/amd64/amd64/tss.c b/sys/arch/amd64/amd64/tss.c
deleted file mode 100644
index c9fc3bb..0000000
--- a/sys/arch/amd64/amd64/tss.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/tss.h>
-#include <machine/cpu.h>
-#include <lib/string.h>
-#include <vm/dynalloc.h>
-#include <sys/panic.h>
-#include <sys/errno.h>
-#include <assert.h>
-
-__MODULE_NAME("TSS");
-__KERNEL_META("$Hyra$: tss.c, Ian Marco Moffett, "
- "AMD64 Task state segment code");
-
-static void
-alloc_resources(struct cpu_info *cpu)
-{
- struct tss_entry *tss;
- const size_t STACK_SIZE = 0x1000;
- static uintptr_t rsp0_base = 0, rsp0 = 0;
-
- /*
- * Allocate TSS entries for this CPU
- */
- if (cpu->tss == NULL) {
- /* Allocate a TSS for this CPU */
- tss = dynalloc(sizeof(*tss));
-
- if (tss == NULL)
- panic("Failed to alloc %d bytes for TSS\n", sizeof(*tss));
-
- memset(tss, 0, sizeof(*tss));
- rsp0_base = (uintptr_t)dynalloc_memalign(STACK_SIZE, 16);
-
- if (rsp0_base == 0)
- panic("Could not allocate rsp0 base\n");
-
- rsp0 = rsp0_base + STACK_SIZE;
- tss->rsp0_lo = __SHIFTOUT(rsp0, __MASK(32));
- tss->rsp0_hi = __SHIFTOUT(rsp0, __MASK(32) << 32);
- cpu->tss = tss;
- }
-}
-
-/*
- * Update interrupt stack table entry `istno' with `stack'
- *
- * @stack: Interrupt stack.
- * @istno: IST number, must be 1-based.
- *
- * Returns 0 on success.
- */
-int
-tss_update_ist(struct cpu_info *ci, union tss_stack stack, uint8_t istno)
-{
- volatile struct tss_entry *tss = ci->tss;
-
- __assert(tss != NULL);
-
- switch (istno) {
- case 1:
- tss->ist1_lo = stack.top_lo;
- tss->ist1_hi = stack.top_hi;
- break;
- case 2:
- tss->ist2_lo = stack.top_lo;
- tss->ist2_hi = stack.top_hi;
- break;
- case 3:
- tss->ist3_lo = stack.top_lo;
- tss->ist3_hi = stack.top_hi;
- break;
- case 4:
- tss->ist4_lo = stack.top_lo;
- tss->ist4_hi = stack.top_hi;
- break;
- case 5:
- tss->ist5_lo = stack.top_lo;
- tss->ist5_hi = stack.top_hi;
- break;
- case 6:
- tss->ist6_lo = stack.top_lo;
- tss->ist6_hi = stack.top_hi;
- break;
- case 7:
- tss->ist7_lo = stack.top_lo;
- tss->ist7_hi = stack.top_hi;
- break;
- default:
- return -EXIT_FAILURE;
- };
-
- return 0;
-}
-
-/*
- * Allocates TSS stack.
- *
- * Returns 0 on success.
- *
- * @entry_out: Pointer to location where allocated entry
- * will be sent.
- */
-int
-tss_alloc_stack(union tss_stack *entry_out, size_t size)
-{
- uintptr_t base = (uintptr_t)dynalloc_memalign(size, 16);
-
- if (base == 0) {
- return -EXIT_FAILURE;
- }
-
- entry_out->top = base + size;
- return 0;
-}
-
-void
-write_tss(struct cpu_info *cpu, struct tss_desc *desc)
-{
- volatile struct tss_entry *tss;
- uintptr_t tss_base;
-
- alloc_resources(cpu);
-
- tss_base = (uintptr_t)cpu->tss;
-
- /*
- * XXX: The AVL (Available for use by system software)
- * bit is ignored by hardware and it is up to us
- * to decide how to use it... As of now, it is useless
- * to us and shall remain 0.
- */
- desc->seglimit = sizeof(struct tss_entry);
- desc->p = 1; /* Must be present to be valid! */
- desc->g = 0; /* Granularity -> 0 */
- desc->avl = 0; /* Not used */
- desc->dpl = 0; /* Descriptor Privilege Level -> 0 */
- desc->type = 0x9; /* For TSS -> 0x9 (0b1001) */
-
- desc->base_lo16 = __SHIFTOUT(tss_base, __MASK(16));
- desc->base_mid8 = __SHIFTOUT(tss_base, __MASK(8) << 16);
- desc->base_hi_mid8 = __SHIFTOUT(tss_base, __MASK(8) << 24);
- desc->base_hi32 = __SHIFTOUT(tss_base, __MASK(32) << 32);
-
- tss = cpu->tss;
- tss->io_base = 0xFF; /* Disallow ring 3 port I/O */
-}
diff --git a/sys/arch/amd64/amd64/uart.c b/sys/arch/amd64/amd64/uart.c
deleted file mode 100644
index 0bf0236..0000000
--- a/sys/arch/amd64/amd64/uart.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <machine/uart.h>
-#include <machine/io.h>
-
-#define UART_COM1 0x3F8
-
-#define UART_PORTNO(OFFSET) (UART_COM1 + 1)
-
-static bool
-uart8250_transmit_empty(void)
-{
- return __TEST(UART_PORTNO(5), __BIT(5));
-}
-
-void
-uart8250_write(char byte)
-{
- while (!uart8250_transmit_empty());
- outb(UART_COM1, byte);
-}
-
-int
-uart8250_try_init(void)
-{
- /* Disable interrutps */
- outb(UART_PORTNO(1), 0x00);
-
- /* Enable DLAB to set divisor latches */
- outb(UART_PORTNO(3), 0x80);
-
- /* Set to 38400 baud via divisor latches (DLL and DLH)*/
- outb(UART_PORTNO(0), 0x03);
- outb(UART_PORTNO(1), 0x00);
-
- /*
- * Set Data Word Length to 8 bits...
- *
- * XXX: Our write does not preserve the DLAB bit...
- * We want to clear it to make the baud latches
- * readonly
- */
- outb(UART_PORTNO(3), 0x03);
-
- /*
- * We want FIFO to be enabled, and want to clear the
- * TX/RX queues. We also want to set the interrupt
- * watermark at 14 bytes.
- */
- outb(UART_PORTNO(2), 0xC7);
-
- /*
- * Enable auxiliary output 2 (used as interrupt line) and
- * mark data terminal ready.
- */
- outb(UART_PORTNO(4), 0x0B);
-
- /* Enable interrupts */
- outb(UART_PORTNO(1), 0x01);
-
- /* Put chip in loopback mode... test chip w/ test byte */
- outb(UART_PORTNO(4), 0x1E);
- outb(UART_PORTNO(0), 0xAE);
- if (inb(UART_PORTNO(0) != 0xAE)) {
- /* Not the same byte, something is wrong */
- return 1;
- }
- return 0;
-}
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC
deleted file mode 100644
index 032519d..0000000
--- a/sys/arch/amd64/conf/GENERIC
+++ /dev/null
@@ -1,9 +0,0 @@
-// Kernel options
-option SPECTRE_MITIGATION no
-option SERIAL_DEBUG yes
-option PANIC_BEEP yes
-
-// Kernel constants
-setval PANIC_BEEP_HZ 1050
-setval SCHED_NQUEUE 4
-setval KMSG_BUF_SHIFT 16
diff --git a/sys/arch/amd64/isa/i8042.c b/sys/arch/amd64/isa/i8042.c
deleted file mode 100644
index 8c790ec..0000000
--- a/sys/arch/amd64/isa/i8042.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/driver.h>
-#include <sys/errno.h>
-#include <sys/spinlock.h>
-#include <sys/tty.h>
-#include <sys/intr.h>
-#include <machine/ioapic.h>
-#include <machine/idt.h>
-#include <machine/io.h>
-#include <machine/lapic.h>
-#include <machine/hpet.h>
-#include <machine/sysvec.h>
-#include <machine/isa/i8042regs.h>
-
-__MODULE_NAME("i8042");
-__KERNEL_META("$Hyra$: i8042.c, Ian Marco Moffett, "
- "i8042 PS/2 driver");
-
-static struct spinlock data_lock;
-static bool shift_key = false;
-static bool capslock = false;
-static bool capslock_released = true;
-static struct intr_info *irq_info;
-
-static int dev_send(bool aux, uint8_t data);
-
-static char keytab[] = {
- '\0', '\0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
- '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
- 'o', 'p', '[', ']', '\n', '\0', 'a', 's', 'd', 'f', 'g', 'h',
- 'j', 'k', 'l', ';', '\'', '`', '\0', '\\', 'z', 'x', 'c', 'v',
- 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0', ' '
-};
-
-static char keytab_shift[] = {
- '\0', '\0', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
- '_', '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
- 'O', 'P', '{', '}', '\n', '\0', 'A', 'S', 'D', 'F', 'G', 'H',
- 'J', 'K', 'L', ':', '\"', '~', '\0', '|', 'Z', 'X', 'C', 'V',
- 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', ' '
-};
-
-static char keytab_caps[] = {
- '\0', '\0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
- '-','=', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
- 'O', 'P', '[', ']', '\n', '\0', 'A', 'S', 'D', 'F', 'G', 'H',
- 'J', 'K', 'L', ';', '\'', '`', '\0', '\\', 'Z', 'X', 'C', 'V',
- 'B', 'N', 'M', ',', '.', '/', '\0', '\0', '\0', ' '
-};
-
-static void
-kbd_set_leds(uint8_t mask)
-{
- dev_send(false, 0xED);
- dev_send(false, mask);
-}
-
-/*
- * Convert scancode to character
- *
- * @sc: Scancode
- * @chr: Character output
- *
- * Returns 0 when a char is given back.
- */
-static int
-scancode_to_chr(uint8_t sc, char *chr)
-{
- bool release = __TEST(sc, __BIT(7));
-
- switch (sc) {
- /* Capslock pressed */
- case 0x3A:
- /*
- * If we are holding down caps-lock, we do not
- * want a stream of presses that constantly cause
- * it to toggle, only toggle if released then pushed
- * again.
- */
- if (!capslock_released)
- return -EAGAIN;
-
- capslock_released = false;
- capslock = !capslock;
-
- if (!capslock) {
- kbd_set_leds(0);
- } else {
- kbd_set_leds(I8042_LED_CAPS);
- }
- return -EAGAIN;
- /* Capslock released */
- case 0xBA:
- capslock_released = true;
- return -EAGAIN;
- /* Shift */
- case 0x36:
- case 0xAA:
- case 0x2A:
- case 0xB6:
- if (!release) {
- shift_key = true;
- } else {
- shift_key = false;
- }
- return -EAGAIN;
- }
-
- if (release) {
- return -EAGAIN;
- }
-
- if (capslock) {
- *chr = keytab_caps[sc];
- return 0;
- }
-
- if (shift_key) {
- *chr = keytab_shift[sc];
- return 0;
- }
-
- *chr = keytab[sc];
- return 0;
-}
-
-/*
- * Write to an i8042 register.
- *
- * @port: I/O port
- * @val: Value to write
- */
-static void
-i8042_write(uint16_t port, uint8_t val)
-{
- while (__TEST(I8042_STATUS, I8042_IBUF_FULL));
- outb(port, val);
-}
-
-/*
- * Read the i8042 config register
- */
-static uint8_t
-i8042_read_conf(void)
-{
- i8042_write(I8042_COMMAND, I8042_GET_CONFB);
- return inb(I8042_DATA);
-}
-
-/*
- * Write the i8042 config register
- */
-static void
-i8042_write_conf(uint8_t value)
-{
- i8042_write(I8042_COMMAND, I8042_SET_CONFB);
- i8042_write(I8042_DATA, value);
-}
-
-/*
- * Flush the data register until it is empty.
- */
-static void
-i8042_drain(void)
-{
- spinlock_acquire(&data_lock);
- while (__TEST(inb(I8042_STATUS), I8042_OBUF_FULL)) {
- inb(I8042_DATA);
- }
-
- spinlock_release(&data_lock);
-}
-
-/*
- * Send a data to a device
- *
- * @aux: If true, send to aux device (mouse)
- * @data: Data to send.
- */
-static int
-dev_send(bool aux, uint8_t data)
-{
- if (aux) {
- i8042_write(I8042_COMMAND, I8042_PORT1_SEND);
- }
-
- for (;;) {
- if (!__TEST(inb(I8042_STATUS), I8042_IBUF_FULL)) {
- break;
- }
- }
-
- i8042_write(I8042_DATA, data);
- inb(0x80); /* Waste a cycle */
- return inb(I8042_DATA);
-}
-
-__attr(interrupt)
-static void
-kb_isr(void *sf)
-{
- uint8_t data;
- char c;
-
- spinlock_acquire(&irq_info->lock);
- ++irq_info->count;
- spinlock_release(&irq_info->lock);
-
- spinlock_acquire(&data_lock);
- while (__TEST(inb(I8042_STATUS), I8042_OBUF_FULL)) {
- data = inb(I8042_DATA);
- if (scancode_to_chr(data, &c) == 0) {
- tty_putc(&g_root_tty, c, TTY_SOURCE_DEV);
- }
- }
- spinlock_release(&data_lock);
- lapic_send_eoi();
-}
-
-static int
-i8042_init(void)
-{
- uint8_t conf;
-
- /*
- * Disable the ports and drain the output buffer
- * to avoid interferance with the initialization
- * process.
- */
- i8042_write(I8042_COMMAND, I8042_DISABLE_PORT0);
- i8042_write(I8042_COMMAND, I8042_DISABLE_PORT1);
- i8042_drain();
-
- /* Disable aux data streaming */
- dev_send(true, I8042_AUX_DISABLE);
- i8042_drain();
-
- /* Setup kbd interrupts */
- idt_set_desc(SYSVEC_PCKBD, IDT_INT_GATE_FLAGS, (uintptr_t)kb_isr, 0);
- ioapic_set_vec(1, SYSVEC_PCKBD);
- ioapic_irq_unmask(1);
-
- /* Register the interrupt */
- irq_info = intr_info_alloc("IOAPIC", "i8042");
- irq_info->affinity = 0;
- intr_register(irq_info);
-
- /* Setup config bits */
- conf = i8042_read_conf();
- conf |= I8042_PORT0_INTR;
- conf &= ~I8042_PORT1_INTR;
- i8042_write_conf(conf);
-
- /* Enable the keyboard */
- i8042_write(I8042_COMMAND, I8042_ENABLE_PORT0);
-
- /*
- * It seems one I/O bus cycle isn't enough to wait for data
- * to accumulate on some machines... Give it around 50ms then
- * drain the output buffer.
- */
- hpet_msleep(50);
- i8042_drain();
- return 0;
-}
-
-DRIVER_EXPORT(i8042_init);
diff --git a/sys/arch/amd64/isa/i8254.c b/sys/arch/amd64/isa/i8254.c
deleted file mode 100644
index f19fb6b..0000000
--- a/sys/arch/amd64/isa/i8254.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/isa/i8254.h>
-#include <machine/io.h>
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-/*
- * Fetches the current count.
- */
-uint16_t
-i8254_get_count(void)
-{
- uint8_t lo, hi;
-
- outb(i8254_COMMAND, 0x00);
- lo = inb(0x40);
- hi = inb(0x40);
- return __COMBINE8(hi, lo);
-}
-
-/*
- * Set the reload value
- *
- * The reload value is where the i8254's counter
- * starts...
- */
-void
-i8254_set_reload(uint16_t val)
-{
- /* Channel 0, lo/hi access, rate generator */
- outb(i8254_COMMAND, 0x34);
-
- outb(0x40, (val & 0xFF));
- outb(0x40, (val >> 8) & 0xFF);
-}
-
-void
-i8254_set_frequency(uint64_t freq_hz)
-{
- uint64_t divisor = i8254_DIVIDEND / freq_hz;
-
- if ((i8254_DIVIDEND % freq_hz) > (freq_hz / 2)) {
- ++divisor;
- }
-
- i8254_set_reload(freq_hz);
-}
diff --git a/sys/arch/amd64/isa/spkr.c b/sys/arch/amd64/isa/spkr.c
deleted file mode 100644
index 109054e..0000000
--- a/sys/arch/amd64/isa/spkr.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/timer.h>
-#include <sys/errno.h>
-#include <machine/isa/spkr.h>
-#include <machine/isa/i8254.h>
-#include <machine/io.h>
-
-#define DIVIDEND 1193180
-#define CTRL_PORT 0x61
-
-int
-pcspkr_tone(uint16_t freq, uint32_t msec)
-{
- uint32_t divisor;
- uint8_t tmp;
- struct timer tmr;
-
- if (req_timer(TIMER_GP, &tmr) != TMRR_SUCCESS)
- return -ENOTSUP;
- if (__unlikely(tmr.msleep == NULL))
- return -ENOTSUP;
-
- divisor = DIVIDEND / freq;
- outb(i8254_COMMAND, 0xB6);
- outb(i8254_CHANNEL_2, divisor & 0xFF);
- outb(i8254_CHANNEL_2, (divisor >> 8) & 0xFF);
-
- /* Oscillate the speaker */
- tmp = inb(CTRL_PORT);
- if (!__TEST(tmp, 3)) {
- tmp |= 3;
- outb(CTRL_PORT, tmp);
- }
-
- /* Sleep then turn off the speaker */
- tmr.msleep(msec);
- outb(CTRL_PORT, tmp & ~3);
- return 0;
-}
diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c
deleted file mode 100644
index 257fd00..0000000
--- a/sys/dev/ic/ahci.c
+++ /dev/null
@@ -1,771 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/driver.h>
-#include <sys/timer.h>
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-#include <sys/mmio.h>
-#include <sys/errno.h>
-#include <sys/device.h>
-#include <fs/devfs.h>
-#include <dev/pci/pci.h>
-#include <dev/ic/ahciregs.h>
-#include <dev/ic/ahcivar.h>
-#include <machine/bus.h>
-#include <vm/vm.h>
-#include <string.h>
-
-__KERNEL_META("$Hyra$: ahci.c, Ian Marco Moffett, "
- "AHCI driver");
-
-#define pr_trace(fmt, ...) kprintf("ahci: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-static TAILQ_HEAD(, ahci_device) sata_devs;
-
-static struct pci_device *dev;
-static struct timer driver_tmr;
-static struct mutex io_lock;
-static size_t dev_count = 0;
-
-static bool
-is_word_aligned(void *ptr)
-{
- return (((uintptr_t)ptr) & 1) == 0;
-}
-
-/*
- * Fetch a SATA device with a SATA device
- * minor.
- *
- * @dev_minor: SATA device minor.
- */
-static struct ahci_device *
-ahci_get_sata(dev_t dev_minor)
-{
- struct ahci_device *dev;
-
- TAILQ_FOREACH(dev, &sata_devs, link) {
- if (dev->minor == dev_minor) {
- return dev;
- }
- }
-
- return NULL;
-}
-
-/*
- * Poll register to have `bits' set/unset.
- *
- * @reg: Register to poll.
- * @bits: Bits expected to be set/unset.
- * @pollset: True to poll as set.
- */
-static int
-ahci_poll_reg32(volatile uint32_t *reg, uint32_t bits, bool pollset)
-{
- uint32_t time_waited = 0;
- uint32_t val;
- bool tmp;
-
- for (;;) {
- val = mmio_read32(reg);
- tmp = (pollset) ? __TEST(val, bits) : !__TEST(val, bits);
- if (tmp)
- break;
- if (time_waited >= AHCI_TIMEOUT)
- /* Timeout */
- return -1;
-
- driver_tmr.msleep(10);
- time_waited += 10;
- }
-
- return 0;
-}
-
-/*
- * Put the HBA in AHCI mode.
- */
-static inline void
-ahci_set_ahci(struct ahci_hba *hba)
-{
- struct hba_memspace *abar = hba->abar;
- uint32_t ghc;
-
- /* Enable AHCI mode */
- ghc = mmio_read32(&abar->ghc);
- ghc |= AHCI_GHC_AE;
- mmio_write32(&abar->ghc, ghc);
-}
-
-/*
- * Reset the HBA with GHC.HR
- *
- * XXX: The spec states that all port registers *except*
- * PxFB, PxFBU, PxCLB, PxCLBU are reset.
- */
-static int
-ahci_hba_reset(struct ahci_hba *hba)
-{
- struct hba_memspace *abar = hba->abar;
- uint32_t ghc;
- uint8_t attempts = 0;
- int status;
-
- ghc = mmio_read32(&abar->ghc);
- ghc |= AHCI_GHC_HR;
- mmio_write32(&abar->ghc, ghc);
-
- /*
- * Poll the GHC.HR bit. The HBA is supposed to flip
- * it back to zero once the reset is complete. If
- * the HBA does not do this, something is screwed
- * up.
- *
- * XXX: We do this twice in case of slow hardware...
- */
- while ((attempts++) < 2) {
- status = ahci_poll_reg32(&abar->ghc, AHCI_GHC_HR, false);
- if (status == 0) {
- break;
- }
- }
-
- /* We hope this doesn't happen */
- if (status != 0) {
- pr_error("HBA reset failure: GHC.HR stuck (HBA hung)\n");
- return status;
- }
-
- ahci_set_ahci(hba);
- return 0;
-}
-
-/*
- * Stop port and put it in an idle state.
- */
-static int
-ahci_stop_port(struct hba_port *port)
-{
- const uint32_t RUN_MASK = (AHCI_PXCMD_FR | AHCI_PXCMD_CR);
- uint32_t cmd = mmio_read32(&port->cmd);
-
- /* Check if it is already stopped */
- if (!__TEST(cmd, RUN_MASK))
- return 0;
-
- /*
- * Stop the FIS receive and disable proessing
- * of the command list.
- */
- cmd &= ~(AHCI_PXCMD_ST | AHCI_PXCMD_FRE);
- mmio_write32(&port->cmd, cmd);
- return ahci_poll_reg32(&port->cmd, RUN_MASK, false);
-}
-
-/*
- * Put a port in a running state.
- */
-static int
-ahci_start_port(struct hba_port *port)
-{
- const uint32_t RUN_MASK = (AHCI_PXCMD_FR | AHCI_PXCMD_CR);
- uint32_t cmd = mmio_read32(&port->cmd);
-
- /* Check if it is already running */
- if (__TEST(cmd, RUN_MASK))
- return 0;
-
- /* Start everything up */
- cmd |= (AHCI_PXCMD_ST | AHCI_PXCMD_FRE);
- mmio_write32(&port->cmd, cmd);
- return ahci_poll_reg32(&port->cmd, RUN_MASK, true);
-}
-
-/*
- * Check if a port is active.
- *
- * @port: Port to check.
- */
-static bool
-ahci_port_active(struct hba_port *port)
-{
- uint32_t ssts;
- uint8_t det, ipm;
-
- ssts = mmio_read32(&port->ssts);
- det = AHCI_PXSSTS_DET(ssts);
- ipm = AHCI_PXSSTS_IPM(ssts);
- return (det == AHCI_DET_COMM && ipm == AHCI_IPM_ACTIVE);
-}
-
-/*
- * Dump identify structure for debugging
- * purposes.
- */
-static void
-ahci_dump_identity(struct ata_identity *identity)
-{
- char serial_number[20];
- char model_number[40];
- char tmp;
-
- memcpy(serial_number, identity->serial_number, sizeof(serial_number));
- memcpy(model_number, identity->model_number, sizeof(model_number));
-
- serial_number[sizeof(serial_number) - 1] = '\0';
- model_number[sizeof(model_number) - 1] = '\0';
-
- /* Fixup endianess for serial number */
- for (size_t i = 0; i < sizeof(serial_number); i += 2) {
- tmp = serial_number[i];
- serial_number[i] = serial_number[i + 1];
- serial_number[i + 1] = tmp;
- }
-
- /* Fixup endianess for model number */
- for (size_t i = 0; i < sizeof(model_number); i += 2) {
- tmp = model_number[i];
- model_number[i] = model_number[i + 1];
- model_number[i + 1] = tmp;
- }
-
- pr_trace("DRIVE MODEL NUMBER: %s\n", model_number);
- pr_trace("DRIVE SERIAL NUMBER: %s\n", serial_number);
-}
-
-/*
- * Allocate a command slot.
- */
-static int
-ahci_alloc_cmdslot(struct ahci_hba *hba, struct hba_port *port)
-{
- uint32_t slotlist = (port->ci | port->sact);
-
- for (uint16_t i = 0; i < hba->ncmdslots; ++i) {
- if (!__TEST(slotlist, i))
- return i;
- }
-
- return -1;
-}
-
-/*
- * Submit a command to a device
- *
- * @port: Port of device to submit command to
- * @cmdslot: Command slot.
- */
-static int
-ahci_submit_cmd(struct ahci_hba *hba, struct hba_port *port, uint8_t cmdslot)
-{
- const uint32_t BUSY_BITS = (AHCI_PXTFD_BSY | AHCI_PXTFD_DRQ);
- const uint8_t MAX_ATTEMPTS = 3;
- uint8_t attempts = 0;
- int status = 0;
-
- /*
- * Ensure the port isn't busy before we try to send
- * any commands. Spin on BSY and DRQ bits until they
- * become unset or we timeout.
- */
- if (ahci_poll_reg32(&port->tfd, BUSY_BITS, false) < 0) {
- pr_error("Command failed: Port is busy! (slot=%d)\n", cmdslot);
- return -EBUSY;
- }
-
- /* Activate the command slot */
- mutex_acquire(&io_lock);
- mmio_write32(&port->ci, __BIT(cmdslot));
-
- /*
- * Wait for completion. since this might take a bit, we
- * give it a few attempts in case it doesn't finish
- * right away.
- */
- while ((attempts++) < MAX_ATTEMPTS) {
- status = ahci_poll_reg32(&port->ci, __BIT(cmdslot), false);
- if (status == 0) {
- break;
- }
- }
-
- /* Did we timeout? */
- if (status != 0) {
- pr_error("IDENTIFY timeout: slot %d still set!\n", cmdslot);
- }
-
- mutex_release(&io_lock);
- return status;
-}
-
-static int
-ahci_sata_rw(struct ahci_hba *hba, struct hba_port *port, struct sio_txn *sio,
- bool write)
-{
- paddr_t buf_phys;
- struct ahci_cmd_hdr *cmdhdr;
- struct ahci_cmdtab *cmdtbl;
- struct ahci_fis_h2d *fis;
- int cmdslot, status;
-
- if (sio->buf == NULL || !is_word_aligned(sio->buf))
- return -EINVAL;
- if (sio->len == 0)
- return -EINVAL;
-
- buf_phys = VIRT_TO_PHYS(sio->buf);
- cmdslot = ahci_alloc_cmdslot(hba, port);
-
- /* Setup command header */
- cmdhdr = PHYS_TO_VIRT(port->clb + cmdslot * sizeof(struct ahci_cmd_hdr));
- cmdhdr->w = 0;
- cmdhdr->cfl = sizeof(struct ahci_fis_h2d) / 4;
- cmdhdr->prdtl = 1;
-
- /* Setup physical region descriptor */
- cmdtbl = PHYS_TO_VIRT(cmdhdr->ctba);
- cmdtbl->prdt[0].dba = buf_phys;
- cmdtbl->prdt[0].dbc = (sio->len << 9) - 1;
- cmdtbl->prdt[0].i = 0;
-
- /* Setup command FIS */
- fis = (void *)&cmdtbl->cfis;
- fis->type = FIS_TYPE_H2D;
- fis->command = write ? ATA_CMD_WRITE_DMA : ATA_CMD_READ_DMA;
- fis->c = 1;
- fis->device = (1 << 6);
-
- /* Setup LBA */
- fis->lba0 = sio->offset & 0xFF;
- fis->lba1 = (sio->offset >> 8) & 0xFF;
- fis->lba2 = (sio->offset >> 16) & 0xFF;
- fis->lba3 = (sio->offset >> 24) & 0xFF;
- fis->lba4 = (sio->offset >> 32) & 0xFF;
- fis->lba5 = (sio->offset >> 40) & 0xFF;
-
- /* Setup count */
- fis->countl = sio->len & 0xFF;
- fis->counth = (sio->len >> 8) & 0xFF;
-
- if ((status = ahci_submit_cmd(hba, port, cmdslot)) != 0) {
- return status;
- }
-
- return 0;
-}
-
-/*
- * Send the IDENTIFY command to a device and
- * log info for debugging purposes.
- */
-static int
-ahci_identify(struct ahci_hba *hba, struct hba_port *port)
-{
- paddr_t buf_phys;
- struct ahci_cmd_hdr *cmdhdr;
- struct ahci_cmdtab *cmdtbl;
- struct ahci_fis_h2d *fis;
- int cmdslot;
- void *buf;
- int status = 0;
-
- cmdslot = ahci_alloc_cmdslot(hba, port);
- buf_phys = vm_alloc_pageframe(1);
- buf = PHYS_TO_VIRT(buf_phys);
-
- if (buf_phys == 0) {
- status = -ENOMEM;
- goto done;
- }
-
- if (cmdslot < 0) {
- status = cmdslot;
- goto done;
- }
-
- memset(buf, 0, vm_get_page_size());
- cmdhdr = PHYS_TO_VIRT(port->clb + cmdslot * sizeof(struct ahci_cmd_hdr));
- cmdhdr->w = 0;
- cmdhdr->cfl = sizeof(struct ahci_fis_h2d) / 4;
- cmdhdr->prdtl = 1;
-
- cmdtbl = PHYS_TO_VIRT(cmdhdr->ctba);
- cmdtbl->prdt[0].dba = VIRT_TO_PHYS(buf);
- cmdtbl->prdt[0].dbc = 511;
- cmdtbl->prdt[0].i = 0;
-
- fis = (void *)&cmdtbl->cfis;
- fis->command = ATA_CMD_IDENTIFY;
- fis->c = 1;
- fis->type = FIS_TYPE_H2D;
-
- if ((status = ahci_submit_cmd(hba, port, cmdslot)) != 0) {
- goto done;
- }
-
- ahci_dump_identity(buf);
-done:
- vm_free_pageframe(VIRT_TO_PHYS(buf), 1);
- return status;
-}
-
-/*
- * Device interface read/write helper
- */
-static int
-sata_dev_rw(struct device *dev, struct sio_txn *sio, bool write)
-{
- struct ahci_device *sata;
-
- if (sio == NULL)
- return -1;
- if (sio->buf == NULL)
- return -1;
-
- sata = ahci_get_sata(dev->minor);
-
- if (sata == NULL)
- return -1;
-
- return ahci_sata_rw(sata->hba, sata->port, sio, write);
-}
-
-/*
- * Device interface read
- */
-static int
-sata_dev_read(struct device *dev, struct sio_txn *sio)
-{
- return sata_dev_rw(dev, sio, false);
-}
-
-/*
- * Device interface write
- */
-static int
-sata_dev_write(struct device *dev, struct sio_txn *sio)
-{
- return sata_dev_rw(dev, sio, true);
-}
-
-/*
- * Device interface open
- */
-static int
-sata_dev_open(struct device *dev)
-{
- return 0;
-}
-
-/*
- * Device interface close
- */
-static int
-sata_dev_close(struct device *dev)
-{
- return 0;
-}
-
-/*
- * Register a SATA device to the rest of the system
- * and expose to userland as a device file.
- */
-static int
-ahci_sata_register(struct ahci_hba *hba, struct hba_port *port)
-{
- char devname[128];
- struct device *dev = NULL;
- struct ahci_device *sata = NULL;
- dev_t dev_id;
- dev_t major;
-
- sata = dynalloc(sizeof(struct ahci_device));
- if (sata == NULL) {
- return -ENOMEM;
- }
-
- dev_id = ++dev_count;
- major = device_alloc_major();
-
- dev = device_alloc();
- dev->open = sata_dev_open;
- dev->close = sata_dev_close;
- dev->read = sata_dev_read;
- dev->write = sata_dev_write;
- dev->blocksize = 512;
- device_create(dev, dev_id, major);
-
- sata->port = port;
- sata->hba = hba;
- sata->minor = dev->minor;
-
- snprintf(devname, sizeof(devname), "sd%d", dev_id);
- devfs_add_dev(devname, dev);
- TAILQ_INSERT_TAIL(&sata_devs, sata, link);
- return 0;
-}
-
-/*
- * Init a single port.
- *
- * @port: Port to init.
- */
-static int
-ahci_init_port(struct ahci_hba *hba, struct hba_port *port, size_t portno)
-{
- paddr_t tmp;
- struct ahci_cmd_hdr *cmdlist;
- void *fis;
- size_t cmdlist_size, pagesize;
- uint32_t sig;
- uint8_t ncmdslots;
- int status = 0;
-
- sig = mmio_read32(&port->sig);
- status = ahci_stop_port(port);
- if (status != 0) {
- pr_trace("Failed to stop port %d\n", portno);
- return status;
- }
-
- /* Try to report device type based on signature */
- switch (sig) {
- case AHCI_SIG_PM:
- pr_trace("Port %d has port multiplier signature\n", portno);
- return 0; /* TODO */
- case AHCI_SIG_ATA:
- pr_trace("Port %d has ATA signature (SATA drive)\n", portno);
- break;
- default:
- return 0; /* TODO */
- }
-
- ncmdslots = hba->ncmdslots;
- pagesize = vm_get_page_size();
-
- /* Allocate our command list */
- cmdlist_size = __ALIGN_UP(ncmdslots * AHCI_CMDENTRY_SIZE, pagesize);
- tmp = vm_alloc_pageframe(cmdlist_size / pagesize);
- cmdlist = PHYS_TO_VIRT(tmp);
- if (tmp == 0) {
- pr_trace("Failed to allocate cmdlist\n");
- status = -ENOMEM;
- goto done;
- }
-
- tmp = vm_alloc_pageframe(1);
- fis = PHYS_TO_VIRT(tmp);
- if (tmp == 0) {
- pr_trace("Failed to allocate FIS\n");
- status = -ENOMEM;
- goto done;
- }
-
- memset(cmdlist, 0, cmdlist_size);
- memset(fis, 0, AHCI_FIS_SIZE);
- hba->cmdlist = cmdlist;
-
- /* Set the registers */
- port->clb = VIRT_TO_PHYS(cmdlist);
- port->fb = VIRT_TO_PHYS(fis);
-
- for (int i = 0; i < ncmdslots; ++i) {
- cmdlist[i].prdtl = 1;
- cmdlist[i].ctba = vm_alloc_pageframe(1);
- }
-
- /* Now try to start up the port */
- if ((status = ahci_start_port(port)) != 0) {
- pr_trace("Failed to start port %d\n", portno);
- goto done;
- }
-
- ahci_identify(hba, port);
- ahci_sata_register(hba, port);
-done:
- if (status != 0 && cmdlist != NULL)
- vm_free_pageframe(port->clb, cmdlist_size / pagesize);
- if (status != 0 && fis != NULL)
- vm_free_pageframe(port->fb, 1);
-
- return status;
-}
-
-/*
- * Hard reset port and reinitialize
- * link.
- */
-static int
-ahci_reset_port(struct hba_port *port)
-{
- uint32_t sctl, ssts;
-
- /*
- * Some odd behaviour may occur if a COMRESET is sent
- * to the port while it is in an idle state...
- * A workaround to this is to bring the port up
- * then immediately transmit the COMRESET to the device.
- */
- ahci_start_port(port);
- sctl = mmio_read32(&port->sctl);
-
- /* Transmit COMRESET for ~2ms */
- sctl = (sctl & ~0xF) | AHCI_DET_COMRESET;
- mmio_write32(&port->sctl, sctl);
- driver_tmr.msleep(2);
-
- /* Stop transmission of COMRESET */
- sctl &= ~AHCI_DET_COMRESET;
- mmio_write32(&port->sctl, sctl);
-
- /*
- * Give around ~150ms for the link to become
- * reestablished. Then make sure that it is
- * actually established by checking PxSSTS.DET
- */
- driver_tmr.msleep(150);
- ssts = mmio_read32(&port->ssts);
- if (AHCI_PXSSTS_DET(ssts) != AHCI_DET_COMM) {
- return -1;
- }
-
- return 0;
-}
-
-/*
- * Sets up devices connected to the physical ports
- * on the HBA.
- *
- * XXX: Since this is called after ahci_init_hba() which also
- * resets the HBA, we'll need to reestablish the link
- * between the devices and the HBA.
- */
-static int
-ahci_init_ports(struct ahci_hba *hba)
-{
- struct hba_memspace *abar = hba->abar;
- uint32_t ports_impl;
- struct hba_port *port;
-
- pr_trace("HBA supports max %d port(s)\n", hba->nports);
- ports_impl = mmio_read32(&abar->pi);
-
- /* Initialize active ports */
- for (size_t i = 0; i < sizeof(abar->pi) * 8; ++i) {
- if (!__TEST(ports_impl, __BIT(i))) {
- continue;
- }
-
- port = &abar->ports[i];
- if (ahci_reset_port(port) != 0) {
- continue;
- }
-
- if (ahci_port_active(port)) {
- ahci_init_port(hba, port, i);
- }
- }
-
- return 0;
-}
-
-/*
- * Sets up the HBA
- */
-static int
-ahci_init_hba(struct ahci_hba *hba)
-{
- struct hba_memspace *abar = hba->abar;
- uint32_t cap;
-
- /* Reset the HBA to ensure it is a known state */
- ahci_hba_reset(hba);
-
- /* Setup HBA structure and save some state */
- cap = mmio_read32(&abar->cap);
- hba->ncmdslots = AHCI_CAP_NCS(cap) + 1;
- hba->nports = AHCI_CAP_NP(cap) + 1;
-
- ahci_init_ports(hba);
- return 0;
-}
-
-static int
-ahci_init(void)
-{
- int status;
- uint16_t cmdreg_bits;
- uint32_t bar_size;
- struct ahci_hba hba = {0};
- struct pci_lookup ahci_lookup = {
- .pci_class = 0x01,
- .pci_subclass = 0x06
- };
-
- dev = pci_get_device(ahci_lookup, PCI_CLASS | PCI_SUBCLASS);
-
- if (dev == NULL) {
- return -1;
- }
-
- cmdreg_bits = PCI_BUS_MASTERING | PCI_MEM_SPACE;
- pci_set_cmdreg(dev, cmdreg_bits);
-
- if (req_timer(TIMER_GP, &driver_tmr) != TMRR_SUCCESS) {
- pr_error("Failed to fetch general purpose timer\n");
- return -1;
- }
-
- if (driver_tmr.msleep == NULL) {
- pr_error("Timer does not have msleep()\n");
- return -1;
- }
-
- if ((bar_size = pci_bar_size(dev, 5)) == 0) {
- pr_error("Failed to fetch BAR size\n");
- return -1;
- }
-
- status = bus_map(dev->bar[5], bar_size, 0, (void *)&hba.abar);
- if (status != 0) {
- pr_error("Failed to map BAR into higher half\n");
- return -1;
- }
-
- pr_trace("AHCI HBA memspace @ 0x%p\n", hba.abar);
- TAILQ_INIT(&sata_devs);
- ahci_init_hba(&hba);
- return 0;
-}
-
-DRIVER_EXPORT(ahci_init);
diff --git a/sys/dev/ic/nvme.c b/sys/dev/ic/nvme.c
deleted file mode 100644
index df533a3..0000000
--- a/sys/dev/ic/nvme.c
+++ /dev/null
@@ -1,614 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/driver.h>
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-#include <sys/timer.h>
-#include <sys/device.h>
-#include <dev/pci/pci.h>
-#include <dev/ic/nvmevar.h>
-#include <vm/dynalloc.h>
-#include <vm/vm.h>
-#include <fs/devfs.h>
-#include <string.h>
-
-__MODULE_NAME("nvme");
-__KERNEL_META("$Hyra$: nvme.c, Ian Marco Moffett, "
- "NVMe driver");
-
-#define pr_trace(fmt, ...) kprintf("nvme: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-static struct pci_device *nvme_dev;
-static struct timer driver_tmr;
-static TAILQ_HEAD(,nvme_ns) namespaces;
-
-static inline int
-is_4k_aligned(void *ptr)
-{
- return ((uintptr_t)ptr & (0x1000 - 1)) == 0;
-}
-
-/*
- * Poll CSTS.RDY to equal `val'
- *
- * Returns `val' on success, returns < 0 value
- * upon failure.
- */
-static int
-nvme_poll_ready(struct nvme_bar *bar, uint8_t val)
-{
- uint8_t timeout = CAP_TIMEOUT(bar->caps);
- uint8_t time_waited = 0;
-
- do {
- if (STATUS_READY(bar->status) == val) {
- /* Done waiting */
- break;
- }
-
- /*
- * If CSTS.RDY hasn't changed, we can try to wait a
- * little longer.
- *
- * XXX: The spec states that CAP.TO (Timeout) is in 500
- * millisecond units.
- */
- if (time_waited < timeout) {
- driver_tmr.msleep(500);
- ++time_waited;
- } else {
- return -1;
- }
- } while (1);
-
- return val;
-}
-
-/*
- * Create an NVMe queue.
- */
-static int
-nvme_create_queue(struct nvme_state *s, struct nvme_queue *queue, size_t id)
-{
- struct nvme_bar *bar = s->bar;
- const size_t PAGESZ = vm_get_page_size();
- const uint8_t DBSTRIDE = CAP_STRIDE(bar->caps);
- const uint16_t SLOTS = CAP_MQES(bar->caps);
-
- queue->sq = dynalloc_memalign(sizeof(void *) * SLOTS, 0x1000);
- queue->cq = dynalloc_memalign(sizeof(void *) * SLOTS, 0x1000);
-
- if (queue->sq == NULL) {
- return -1;
- }
- if (queue->cq == NULL) {
- dynfree(queue->sq);
- return -1;
- }
-
- memset(queue->sq, 0, sizeof(void *) * SLOTS);
- memset(queue->cq, 0, sizeof(void *) * SLOTS);
-
- queue->sq_head = 0;
- queue->sq_tail = 0;
- queue->size = SLOTS;
- queue->sq_db = PHYS_TO_VIRT((uintptr_t)bar + PAGESZ + (2 * id * (4 << DBSTRIDE)));
- queue->cq_db = PHYS_TO_VIRT((uintptr_t)bar + PAGESZ + ((2 * id + 1) * (4 << DBSTRIDE)));
- queue->cq_phase = 1;
- return 0;
-}
-
-/*
- * Submit a command
- *
- * @queue: Target queue.
- * @cmd: Command to submit
- */
-static void
-nvme_submit_cmd(struct nvme_queue *queue, struct nvme_cmd cmd)
-{
- /* Submit the command to the queue */
- queue->sq[queue->sq_tail++] = cmd;
- if (queue->sq_tail >= queue->size) {
- queue->sq_tail = 0;
- }
- *(queue->sq_db) = queue->sq_tail;
-}
-
-/*
- * Submit a command and poll for completion
- *
- * @queue: Target queue.
- * @cmd: Command to submit
- */
-static int
-nvme_poll_submit_cmd(struct nvme_queue *queue, struct nvme_cmd cmd)
-{
- uint16_t status;
- size_t spins = 0;
-
- nvme_submit_cmd(queue, cmd);
-
- /*
- * Wait for the current command to complete by
- * polling the phase bit.
- */
- while (1) {
- status = queue->cq[queue->cq_head].status;
- if ((status & 1) == queue->cq_phase) {
- /*
- * The phase bit matches the phase for the most
- * recently submitted command, the command has completed.
- */
- break;
- }
- if ((status & ~1) != 0) {
- pr_trace("NVMe cmd error (bits=0x%x)\n", status >> 1);
- break;
- }
- if (spins > 5) {
- /* Attempts exhausted */
- pr_error("Hang on phase bit poll, giving up (cmd error)\n");
- break;
- }
-
- /* Not done, give it some more time */
- driver_tmr.msleep(150);
- ++spins;
- }
-
- ++queue->cq_head;
- if (queue->cq_head >= queue->size) {
- queue->cq_head = 0;
- queue->cq_phase = !queue->cq_phase;
- }
-
- /* Tell the controller that `head' updated */
- *(queue->cq_db) = queue->cq_head;
- return 0;
-}
-
-/*
- * Create an I/O queue for a specific namespace.
- *
- * @ns: Namespace
- * @id: I/O queue ID
- */
-static int
-nvme_create_ioq(struct nvme_ns *ns, size_t id)
-{
- struct nvme_queue *ioq = &ns->ioq;
- struct nvme_state *cntl = ns->cntl;
-
- struct nvme_bar *bar = cntl->bar;
- struct nvme_cmd cmd = {0};
- size_t mqes = CAP_MQES(bar->caps);
-
- struct nvme_create_iocq_cmd *create_iocq;
- struct nvme_create_iosq_cmd *create_iosq;
- int status;
-
- if ((status = nvme_create_queue(ns->cntl, ioq, id)) != 0) {
- return status;
- }
-
- create_iocq = &cmd.create_iocq;
- create_iocq->opcode = NVME_OP_CREATE_IOCQ;
- create_iocq->qflags |= __BIT(0); /* Physically contiguous */
- create_iocq->qsize = mqes;
- create_iocq->qid = id;
- create_iocq->prp1 = VIRT_TO_PHYS(ns->ioq.cq);
-
- if ((status = nvme_poll_submit_cmd(&cntl->adminq, cmd)) != 0) {
- return status;
- }
-
- create_iosq = &cmd.create_iosq;
- create_iosq->opcode = NVME_OP_CREATE_IOSQ;
- create_iosq->qflags |= __BIT(0); /* Physically contiguous */
- create_iosq->qsize = mqes;
- create_iosq->cqid = id;
- create_iosq->sqid = id;
- create_iosq->prp1 = VIRT_TO_PHYS(ns->ioq.sq);
- return nvme_poll_submit_cmd(&cntl->adminq, cmd);
-}
-
-/*
- * Issue an identify command for the current
- * controller.
- *
- * XXX: `id' must be aligned on a 4k byte boundary to avoid
- * crossing a page boundary. This keeps the implementation
- * as simple as possible here.
- */
-static int
-nvme_identify(struct nvme_state *state, struct nvme_id *id)
-{
- struct nvme_cmd cmd = {0};
- struct nvme_identify_cmd *identify = &cmd.identify;
-
- /* Ensure `id' is aligned on a 4k byte boundary */
- if (!is_4k_aligned(id)) {
- return -1;
- }
-
- identify->opcode = NVME_OP_IDENTIFY;
- identify->nsid = 0;
- identify->cns = 1; /* Identify controller */
- identify->prp1 = VIRT_TO_PHYS(id);
- identify->prp2 = 0; /* No need, data address is 4k aligned */
- return nvme_poll_submit_cmd(&state->adminq, cmd);
-}
-
-/*
- * Issue a read/write command for a specific
- * namespace.
- *
- * `buf' must be 4k aligned.
- */
-static int
-nvme_rw(struct nvme_ns *ns, char *buf, off_t slba, size_t count, bool write)
-{
- struct nvme_cmd cmd = {0};
- struct nvme_rw_cmd *rw = &cmd.rw;
-
- if (!is_4k_aligned(buf)) {
- return -1;
- }
-
- rw->opcode = write ? NVME_OP_WRITE : NVME_OP_READ;
- rw->nsid = ns->nsid;
- rw->slba = slba;
- rw->len = count - 1;
- rw->prp1 = VIRT_TO_PHYS(buf);
- return nvme_poll_submit_cmd(&ns->ioq, cmd);
-}
-
-/*
- * Fetch a namespace from its ID
- *
- * @nsid: Namespace ID of namespace to fetch
- */
-static struct nvme_ns *
-nvme_get_ns(size_t nsid)
-{
- struct nvme_ns *ns;
-
- TAILQ_FOREACH(ns, &namespaces, link) {
- if (ns->nsid == nsid) {
- return ns;
- }
- }
-
- return NULL;
-}
-
-/*
- * Device interface read/write helper
- */
-static int
-nvme_dev_rw(struct device *dev, struct sio_txn *sio, bool write)
-{
- struct nvme_ns *ns;
-
- if (sio == NULL) {
- return -1;
- }
-
- ns = nvme_get_ns(dev->minor);
- if (ns == NULL || sio->buf == NULL) {
- return -1;
- }
-
- return nvme_rw(ns, sio->buf, sio->offset, sio->len, write);
-}
-
-/*
- * Device interface read
- */
-static int
-nvme_dev_read(struct device *dev, struct sio_txn *sio)
-{
- return nvme_dev_rw(dev, sio, false);
-}
-
-/*
- * Device interface write
- */
-static int
-nvme_dev_write(struct device *dev, struct sio_txn *sio)
-{
- return nvme_dev_rw(dev, sio, true);
-}
-
-static int
-nvme_dev_open(struct device *dev)
-{
- return 0;
-}
-
-/*
- * Get identify data for namespace
- *
- * @id_ns: Data will be written to this pointer via DMA.
- * @nsid: Namespace ID.
- *
- * XXX: `id_ns' must be 4k aligned.
- */
-static int
-nvme_id_ns(struct nvme_state *s, struct nvme_id_ns *id_ns, uint16_t nsid)
-{
- struct nvme_cmd cmd = {0};
- struct nvme_identify_cmd *identify = &cmd.identify;
-
- if (!is_4k_aligned(id_ns)) {
- return -1;
- }
-
- identify->opcode = NVME_OP_IDENTIFY;
- identify->nsid = nsid;
- identify->cns = 0;
- identify->prp1 = VIRT_TO_PHYS(id_ns);
- return nvme_poll_submit_cmd(&s->adminq, cmd);
-}
-
-/*
- * Init a namespace.
- *
- * @nsid: Namespace ID
- */
-static int
-nvme_init_ns(struct nvme_state *state, uint16_t nsid)
-{
- char devname[128];
- struct nvme_ns *ns = NULL;
- struct nvme_id_ns *id_ns = NULL;
- struct device *dev;
- uint8_t lba_format;
- int status = 0;
-
- ns = dynalloc(sizeof(struct nvme_ns));
- if (ns == NULL) {
- status = -1;
- goto done;
- }
-
- id_ns = dynalloc_memalign(sizeof(struct nvme_id_ns), 0x1000);
- if ((status = nvme_id_ns(state, id_ns, nsid)) != 0) {
- dynfree(ns);
- goto done;
- }
-
- lba_format = id_ns->flbas & 0xF;
- ns->lba_fmt = id_ns->lbaf[lba_format];
- ns->nsid = nsid;
- ns->lba_bsize = 1 << ns->lba_fmt.ds;
- ns->size = id_ns->size;
- ns->cntl = state;
- nvme_create_ioq(ns, ns->nsid);
-
- dev = device_alloc();
- dev->read = nvme_dev_read;
- dev->write = nvme_dev_write;
- dev->open = nvme_dev_open;
- dev->blocksize = ns->lba_bsize;
- dev->mmap = NULL;
- ns->dev_id = device_create(dev, state->major, nsid);
-
- snprintf(devname, sizeof(devname), "nvme0n%d", nsid);
- if (devfs_add_dev(devname, dev) != 0) {
- pr_error("Failed to create /dev/%s\n", devname);
- }
-
- TAILQ_INSERT_TAIL(&namespaces, ns, link);
-done:
- if (id_ns != NULL)
- dynfree(id_ns);
-
- return status;
-}
-
-static int
-nvme_disable_controller(struct nvme_state *state)
-{
- struct nvme_bar *bar = state->bar;
-
- if (__TEST(bar->config, CONFIG_EN)) {
- bar->config &= ~CONFIG_EN;
- }
-
- if (nvme_poll_ready(bar, 0) < 0) {
- pr_error("Failed to disable controller\n");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * For debugging purposes, logs some information
- * found within the controller identify data structure.
- */
-static void
-nvme_log_ctrl_id(struct nvme_id *id)
-{
- char mn[41] = {0};
- char fr[9] = {0};
-
- for (size_t i = 0; i < sizeof(id->mn); ++i) {
- mn[i] = id->mn[i];
- }
- for (size_t i = 0; i < sizeof(id->fr); ++i) {
- fr[i] = id->fr[i];
- }
-
- pr_trace("NVMe model: %s\n", mn);
- pr_trace("NVMe firmware revision: %s\n", fr);
-}
-
-/*
- * Fetch the list of namespace IDs
- *
- * @nsids_out: NSIDs will be written here via DMA.
- *
- * XXX: `nsids_out' must be 4k aligned.
- */
-static int
-nvme_get_nsids(struct nvme_state *state, uint32_t *nsids_out)
-{
- struct nvme_cmd cmd = {0};
- struct nvme_identify_cmd *identify = &cmd.identify;
-
- if (!is_4k_aligned(nsids_out)) {
- return -1;
- }
-
- identify->opcode = NVME_OP_IDENTIFY;
- identify->cns = 2; /* Active NSID list */
- identify->prp1 = VIRT_TO_PHYS(nsids_out);
- return nvme_poll_submit_cmd(&state->adminq, cmd);
-}
-
-static int
-nvme_enable_controller(struct nvme_state *state)
-{
- struct nvme_bar *bar = state->bar;
- struct nvme_id *id;
-
- uint32_t *nsids;
- uint8_t max_sqes, max_cqes;
-
- if (!__TEST(bar->config, CONFIG_EN)) {
- bar->config |= CONFIG_EN;
- }
-
- if (nvme_poll_ready(bar, 1) < 0) {
- pr_error("Failed to enable controller\n");
- return -1;
- }
-
- id = dynalloc_memalign(sizeof(struct nvme_id), 0x1000);
- if (id == NULL) {
- return -1;
- }
-
- nsids = dynalloc_memalign(0x1000, 0x1000);
- if (nsids == NULL) {
- return -1;
- }
-
- nvme_identify(state, id);
- nvme_log_ctrl_id(id);
- nvme_get_nsids(state, nsids);
-
- /*
- * Before creating any I/O queues we need to set CC.IOCQES
- * and CC.IOSQES... Bits 3:0 is the minimum and bits 7:4
- * is the maximum. We'll choose the maximum.
- */
- max_sqes = id->sqes >> 4;
- max_cqes = id->cqes >> 4;
- bar->config |= (max_sqes << CONFIG_IOSQES_SHIFT);
- bar->config |= (max_cqes << CONFIG_IOCQES_SHIFT);
-
- /* Init NVMe namespaces */
- for (size_t i = 0; i < id->nn; ++i) {
- if (nsids[i] != 0) {
- pr_trace("Found NVMe namespace (id=%d)\n", nsids[i]);
- nvme_init_ns(state, nsids[i]);
- }
- }
-
- dynfree(nsids);
- dynfree(id);
- return 0;
-}
-
-static int
-nvme_init_controller(struct nvme_bar *bar)
-{
- struct nvme_state state = { . bar = bar };
- struct nvme_queue *adminq = &state.adminq;
-
- uint16_t mqes = CAP_MQES(bar->caps);
- uint16_t cmdreg_bits = PCI_BUS_MASTERING |
- PCI_MEM_SPACE;
-
- pci_set_cmdreg(nvme_dev, cmdreg_bits);
- nvme_disable_controller(&state);
-
- nvme_create_queue(&state, adminq, 0);
-
- /* Setup admin submission and admin completion queues */
- bar->aqa = (mqes | mqes << 16);
- bar->asq = VIRT_TO_PHYS(adminq->sq);
- bar->acq = VIRT_TO_PHYS(adminq->cq);
-
- state.major = device_alloc_major();
- return nvme_enable_controller(&state);
-}
-
-static int
-nvme_init(void)
-{
- struct nvme_bar *bar;
- struct pci_lookup nvme_lookup = {
- .pci_class = 1,
- .pci_subclass = 8
- };
-
- if (req_timer(TIMER_GP, &driver_tmr) != 0) {
- pr_error("Failed to fetch general purpose timer\n");
- return -1;
- }
-
- if (driver_tmr.msleep == NULL) {
- pr_error("Timer does not have msleep()\n");
- return -1;
- }
-
- nvme_dev = pci_get_device(nvme_lookup, PCI_CLASS | PCI_SUBCLASS);
- if (nvme_dev == NULL) {
- return -1;
- }
-
- bar = PCI_BAR_MEMBASE(nvme_dev->bar[0]);
- pr_trace("NVMe BAR0 @ 0x%p\n", bar);
- TAILQ_INIT(&namespaces);
-
- if (nvme_init_controller(bar) < 0) {
- return -1;
- }
-
- return 0;
-}
-
-DRIVER_EXPORT(nvme_init);
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
deleted file mode 100644
index 9a8eae4..0000000
--- a/sys/dev/pci/pci.c
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <dev/pci/pci.h>
-#include <dev/pci/pcivar.h>
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <sys/queue.h>
-#include <sys/syslog.h>
-#include <sys/errno.h>
-#include <vm/dynalloc.h>
-#include <machine/bus.h>
-#if defined(__x86_64__)
-#include <machine/io.h>
-#endif
-#include <assert.h>
-
-__MODULE_NAME("pci");
-__KERNEL_META("$Hyra$: pci.c, Ian Marco Moffett, "
- "PCI driver core");
-
-#define pr_trace(fmt, ...) kprintf("pci: " fmt, ##__VA_ARGS__)
-
-static TAILQ_HEAD(, pci_device) device_list;
-static int access_method = PCI_ACCESS_CAM;
-
-/*
- * Read device's legacy PCI CAM space
- *
- * @dev: Device to read.
- * @offset: Offset to read at.
- *
- * XXX: Do not use directly!
- */
-static uint32_t
-pci_cam_read(const struct pci_device *dev, uint32_t offset)
-{
-#if defined(__x86_64__)
- uint32_t address, data;
-
- address = __BIT(31) |
- (offset & ~3) |
- (dev->func << 8) |
- (dev->slot << 11) |
- (dev->bus << 16);
-
- outl(0xCF8, address);
- data = inl(0xCFC) >> ((offset & 3) * 8);
- return data;
-#else
- panic("Invalid arch (%s())\n", __func__);
-#endif
-}
-
-/*
- * Write to device's legacy PCI CAM space
- *
- * @dev: Device to write to.
- * @offset: Offset to write at.
- *
- * XXX: Do not use directly!
- */
-static void
-pci_cam_write(const struct pci_device *dev, uint32_t offset, uint32_t value)
-{
-#if defined(__x86_64__)
- uint32_t address;
-
- address = __BIT(31) |
- (offset & ~3) |
- (dev->func << 8) |
- (dev->slot << 11) |
- (dev->bus << 16);
-
- outl(0xCF8, address);
- outb(0xCFC, value);
-#else
- panic("Invalid arch (%s())\n", __func__);
-#endif
-}
-
-static bool
-pci_device_exists(uint8_t bus, uint8_t slot, uint8_t func)
-{
- uint16_t vendor_id;
- struct pci_device dev_tmp = {
- .bus = bus,
- .slot = slot,
- .func = func
- };
-
- vendor_id = pci_cam_read(&dev_tmp, 0x0) & 0xFFFF;
-
- if (vendor_id == 0xFFFF) {
- return false;
- }
-
- return true;
-}
-
-/*
- * Sets other device information e.g., device id, vendor id, etc
- *
- * @dev: Device descriptor to set up.
- *
- * XXX: Expects device bus, slot and func to be set.
- */
-static void
-pci_set_device_info(struct pci_device *dev)
-{
- uint32_t classrev;
-
- dev->vendor_id = pci_readl(dev, PCIREG_VENDOR_ID) & __MASK(16);
- dev->device_id = pci_readl(dev, PCIREG_DEVICE_ID) & __MASK(16);
- classrev = pci_readl(dev, PCIREG_CLASSREV);
-
- dev->pci_class = PCIREG_CLASS(classrev);
- dev->pci_subclass = PCIREG_SUBCLASS(classrev);
- dev->prog_if = PCIREG_PROGIF(classrev);
-
- dev->bar[0] = pci_readl(dev, PCIREG_BAR0);
- dev->bar[1] = pci_readl(dev, PCIREG_BAR1);
- dev->bar[2] = pci_readl(dev, PCIREG_BAR2);
- dev->bar[3] = pci_readl(dev, PCIREG_BAR3);
- dev->bar[4] = pci_readl(dev, PCIREG_BAR4);
- dev->bar[5] = pci_readl(dev, PCIREG_BAR5);
-
- dev->irq_line = pci_readl(dev, PCIREG_IRQLINE) & __MASK(8);
-}
-
-static void
-pci_register_device(uint8_t bus, uint8_t slot, uint8_t func)
-{
- struct pci_device *dev = NULL;
-
- if (!pci_device_exists(bus, slot, func)) {
- return;
- }
-
- dev = dynalloc(sizeof(struct pci_device));
- __assert(dev != NULL);
-
- dev->bus = bus;
- dev->slot = slot;
- dev->func = func;
-
- pci_set_device_info(dev);
- TAILQ_INSERT_TAIL(&device_list, dev, link);
-}
-
-static void
-pci_scan_bus(uint8_t bus)
-{
- for (int slot = 0; slot < 32; ++slot) {
- for (int func = 0; func < 8; ++func) {
- pci_register_device(bus, slot, func);
- }
- }
-}
-
-/*
- * Convert a BAR number to BAR register offset.
- *
- * @dev: Device of BAR to check.
- * @bar: Bar number.
- */
-static uint8_t
-pci_get_barreg(struct pci_device *dev, uint8_t bar)
-{
- switch (bar) {
- case 0: return PCIREG_BAR0;
- case 1: return PCIREG_BAR1;
- case 2: return PCIREG_BAR2;
- case 3: return PCIREG_BAR3;
- case 4: return PCIREG_BAR4;
- case 5: return PCIREG_BAR5;
- default: return 0;
- }
-}
-
-/*
- * Get size length of memory region that a PCI(e) BAR
- * covers. A returned value of zero is invalid and indicates
- * an error.
- *
- * @dev: Device of BAR to get.
- * @bar: BAR number.
- */
-uint32_t
-pci_bar_size(struct pci_device *dev, uint8_t bar)
-{
- uint8_t bar_reg = pci_get_barreg(dev, bar);
- uint32_t tmp, size;
-
- if (bar_reg == 0) {
- return 0;
- }
-
- /*
- * Get the length of the region this BAR covers by writing a
- * mask of 32 bits into the BAR register and seeing how many
- * bits are unset. We can use this to compute the size of the
- * region. We know that log2(len) bits must be unset.
- */
- tmp = pci_readl(dev, bar_reg);
- pci_writel(dev, bar_reg, __MASK(32));
- size = pci_readl(dev, bar_reg);
- size = ~size + 1;
-
- /* Now we need to restore the previous value */
- pci_writel(dev, bar_reg, tmp);
- return size;
-}
-
-/*
- * Read PCI(e) configuration space.
- *
- * @dev: Device to read from.
- * @offset: Offset to read at.
- */
-uint32_t
-pci_readl(struct pci_device *dev, uint32_t offset)
-{
- if (access_method == PCI_ACCESS_CAM) {
- return pci_cam_read(dev, offset);
- }
-
- panic("Invalid access method (%s())\n", __func__);
- __builtin_unreachable();
-}
-
-/*
- * Write to PCI(e) configuration space.
- *
- * @dev: Device to write to.
- * @offset: Offset to write at.
- */
-void
-pci_writel(struct pci_device *dev, uint32_t offset, uint32_t val)
-{
- if (access_method == PCI_ACCESS_CAM) {
- pci_cam_write(dev, offset, val);
- return;
- }
-
- panic("Invalid access method (%s())\n", __func__);
- __builtin_unreachable();
-}
-
-/*
- * Set command register bits.
- *
- * @dev: Device whose command register to modify.
- * @bits: Bits to set.
- */
-void
-pci_set_cmdreg(struct pci_device *dev, uint16_t bits)
-{
- uint32_t tmp;
-
- tmp = pci_readl(dev, 0x4) | bits;
- pci_writel(dev, 0x4, tmp);
-}
-
-struct pci_device *
-pci_get_device(struct pci_lookup lookup, uint16_t lookup_type)
-{
- struct pci_device *dev;
- uint16_t lookup_matches = 0;
-
- TAILQ_FOREACH(dev, &device_list, link) {
- if (__TEST(lookup_type, PCI_DEVICE_ID)) {
- /* Check device ID */
- if (lookup.device_id == dev->device_id)
- lookup_matches |= PCI_DEVICE_ID;
- }
-
- if (__TEST(lookup_type, PCI_VENDOR_ID)) {
- /* Check vendor ID */
- if (lookup.vendor_id == dev->vendor_id)
- lookup_matches |= PCI_VENDOR_ID;
- }
-
- if (__TEST(lookup_type, PCI_CLASS)) {
- /* Check PCI class */
- if (lookup.pci_class == dev->pci_class)
- lookup_matches |= PCI_CLASS;
- }
-
- if (__TEST(lookup_type, PCI_SUBCLASS)) {
- /* Check PCI subclass */
- if (lookup.pci_subclass == dev->pci_subclass)
- lookup_matches |= PCI_SUBCLASS;
- }
-
- if (lookup_type == lookup_matches) {
- /* We found the device! */
- return dev;
- }
- lookup_matches = 0;
- }
-
- return NULL;
-}
-
-int
-pci_init(void)
-{
- TAILQ_INIT(&device_list);
-
- pr_trace("Scanning each bus...\n");
-
- for (uint16_t i = 0; i < 256; ++i) {
- pci_scan_bus(i);
- }
-
- return 0;
-}
diff --git a/sys/dev/usb/xhci.c b/sys/dev/usb/xhci.c
deleted file mode 100644
index f221843..0000000
--- a/sys/dev/usb/xhci.c
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/driver.h>
-#include <dev/pci/pci.h>
-#include <sys/syslog.h>
-#include <sys/timer.h>
-#include <dev/usb/xhciregs.h>
-#include <dev/usb/xhcivar.h>
-#include <vm/physseg.h>
-#include <vm/dynalloc.h>
-#include <vm/vm.h>
-#include <string.h>
-#include <assert.h>
-
-__MODULE_NAME("xhci");
-__KERNEL_META("$Hyra$: xhci.c, Ian Marco Moffett, "
- "xHCI driver");
-
-#define pr_trace(fmt, ...) kprintf("xhci: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-static struct pci_device *hci_dev;
-static struct timer driver_tmr;
-
-static inline uint32_t *
-xhci_get_portsc(struct xhci_hc *hc, uint8_t portno)
-{
- if (portno > hc->maxports) {
- portno = hc->maxports;
- }
- return XHCI_BASE_OFF(hc->opregs, 0x400 + (0x10 * (portno - 1)));
-}
-
-/*
- * Set event ring segment table base
- * address.
- *
- * @hc: Host controler descriptor.
- * @pa: Physical address.
- */
-static inline void
-xhci_set_erst_base(struct xhci_hc *hc, uintptr_t pa)
-{
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
- void *runtime_base = XHCI_RTS(hc->base, caps->rtsoff);
- uintptr_t *erstba;
-
- /*
- * The spec states that the Event Ring Segment Table
- * Base Address register is at 'runtime_base + 0x30 +
- * (32 * interrupter)'. See the xHCI spec, section 5.5.2.3.2
- */
- erstba = XHCI_BASE_OFF(runtime_base, 0x30);
- *erstba = pa;
-}
-
-/*
- * Submit a command by pushing a TRB to the
- * command ring.
- *
- * @hc: Host controller descriptor.
- * @trb: Transfer Request Block of command.
- */
-static int
-xhci_submit_cmd(struct xhci_hc *hc, struct xhci_trb trb)
-{
- volatile uint32_t *cmd_db;
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
-
- /* Push the TRB to the command ring */
- hc->cmd_ring[hc->cmd_ptr++] = trb.dword0;
- hc->cmd_ring[hc->cmd_ptr++] = trb.dword1;
- hc->cmd_ring[hc->cmd_ptr++] = trb.dword2;
- hc->cmd_ring[hc->cmd_ptr++] = trb.dword3 | hc->cycle;
- hc->cmd_count++;
-
- /* Ring the command doorbell */
- cmd_db = XHCI_CMD_DB(hc->base, caps->dboff);
- *cmd_db = 0;
-
- if (hc->cmd_count >= XHCI_CMDRING_LEN - 1) {
- /*
- * Create raw link TRB and ring the doorbell. We want the
- * xHC to flip its cycle bit so it doesn't confuse existing
- * entries (that we'll overwrite) in the ring with current
- * entries, so we set the Toggle Cycle bit.
- *
- * See the xHCI spec, section 6.4.4.1 for information regarding
- * the format of link TRBs.
- */
- hc->cmd_ring[hc->cmd_ptr++] = VIRT_TO_PHYS(hc->cmd_ring) & 0xFFFFFFFF;
- hc->cmd_ring[hc->cmd_ptr++] = VIRT_TO_PHYS(hc->cmd_ring) >> 32;
- hc->cmd_ring[hc->cmd_ptr++] = 0;
- hc->cmd_ring[hc->cmd_ptr++] = hc->cycle | (XHCI_LINK << 10) | __BIT(1);
- *cmd_db = 0;
-
- /* Reset command state and flip cycle */
- hc->cmd_ptr = 0;
- hc->cmd_count = 0;
- hc->cycle = ~hc->cycle;
- }
-
- return 0;
-}
-
-/*
- * Parse xHCI extended caps
- */
-static int
-xhci_parse_ecp(struct xhci_hc *hc)
-{
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
- struct xhci_proto *proto;
- uint32_t *p, val, dword2;
- uint32_t cap_ptr = XHCI_ECP(caps->hccparams1);
-
- p = XHCI_BASE_OFF(hc->base, cap_ptr*4);
- while (cap_ptr != 0) {
- val = *p;
- dword2 = *((uint32_t *)XHCI_BASE_OFF(p, 8));
-
- /* Get the next cap */
- p = XHCI_BASE_OFF(p, XHCI_PROTO_NEXT(val) * 4);
- cap_ptr = XHCI_PROTO_NEXT(val);
-
- if (XHCI_PROTO_ID(val) != XHCI_ECAP_PROTO) {
- /* Not a Supported Protocol Capability */
- continue;
- }
-
- if (hc->protocnt > XHCI_MAX_PROTOS) {
- /* Too many protocols */
- break;
- }
-
- proto = &hc->protos[hc->protocnt++];
- proto->major = XHCI_PROTO_MAJOR(val);
- proto->port_count = XHCI_PROTO_PORTCNT(dword2);
- proto->port_start = XHCI_PROTO_PORTOFF(dword2);
- }
-
- return 0;
-}
-
-/*
- * Set of xHCI scratchpad buffers.
- */
-static int
-xhci_init_scratchpads(struct xhci_hc *hc)
-{
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
- uint16_t max_bufs_lo, max_bufs_hi, max_bufs;
- uintptr_t *buffer_array, tmp;
-
- max_bufs_lo = XHCI_MAX_SP_LO(caps->hcsparams2);
- max_bufs_hi = XHCI_MAX_SP_HI(caps->hcsparams2);
- max_bufs = (max_bufs_hi << 5) | max_bufs_lo;
- if (max_bufs == 0) {
- /*
- * Some emulators like QEMU don't need any
- * scratchpad buffers so we can just return
- * early.
- */
- return 0;
- }
-
- pr_trace("Need %d scratchpad buffers\n", max_bufs);
-
- /* Allocate buffer array */
- buffer_array = dynalloc_memalign(sizeof(uintptr_t)*max_bufs, 0x1000);
- if (buffer_array == NULL) {
- pr_error("Failed to allocate scratchpad buffer array\n");
- return -1;
- }
-
- memset(buffer_array, 0, sizeof(uintptr_t)*max_bufs);
-
- /* Fill the buffer array */
- for (size_t i = 0; i < max_bufs; ++i) {
- tmp = vm_alloc_pageframe(1);
-
- if (tmp == 0) {
- /* TODO: Shutdown, free memory */
- pr_error("Failed to fill scratchpad buffer array\n");
- return -1;
- }
-
- buffer_array[i] = tmp;
- }
-
- hc->dcbaap[0] = VIRT_TO_PHYS(buffer_array);
- return 0;
-}
-
-/*
- * Init USB ports on the root hub.
- */
-static int
-xhci_init_ports(struct xhci_hc *hc)
-{
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
- size_t maxports = XHCI_MAXPORTS(caps->hcsparams1);
- uint32_t *portsc;
-
- for (size_t i = 1; i < maxports; ++i) {
- portsc = xhci_get_portsc(hc, i);
- if (__TEST(*portsc, XHCI_PORTSC_CCS)) {
- pr_trace("Device connected on port %d, resetting...\n", i);
- *portsc |= XHCI_PORTSC_PR;
- }
- }
-
- return 0;
-}
-
-/*
- * Poll USBSTS.HCH to be val
- *
- * Returns 0 on success. Non-zero values returned
- * indicate a hang.
- */
-static int
-xhci_poll_hch(struct xhci_hc *hc, uint8_t val)
-{
- struct xhci_opregs *opregs = hc->opregs;
- size_t time_waiting = 0;
-
- while ((opregs->usbsts & USBSTS_HCH) != val) {
- if (time_waiting >= XHCI_TIMEOUT) {
- /* Hang */
- return -1;
- }
-
- time_waiting += 50;
- driver_tmr.msleep(50);
- }
-
- return 0;
-}
-
-/*
- * Start up the host controller by setting
- * the USBCMD run/stop bit.
- */
-static int
-xhci_start_hc(struct xhci_hc *hc)
-{
- struct xhci_opregs *opregs = hc->opregs;
- int status;
-
- opregs->usbcmd |= USBCMD_RUN;
-
- if ((status = xhci_poll_hch(hc, 0)) != 0) {
- return status;
- }
-
- return 0;
-}
-
-static int
-xhci_reset_hc(struct xhci_hc *hc)
-{
- struct xhci_opregs *opregs = hc->opregs;
- size_t time_waiting = 0; /* In ms */
-
- pr_trace("Resetting host controller...\n");
-
- /*
- * Set USBCMD.HCRST to reset the controller and
- * wait for it to become zero.
- */
- opregs->usbcmd |= USBCMD_HCRST;
- while (1) {
- if (!__TEST(opregs->usbcmd, USBCMD_HCRST)) {
- /* Reset is complete */
- break;
- }
- if (time_waiting >= XHCI_TIMEOUT) {
- pr_error("Hang while polling USBCMD.HCRST to be zero\n");
- return -1;
- }
- driver_tmr.msleep(50);
- time_waiting += 50;
- }
- return 0;
-}
-
-/*
- * Allocate the Device Context Base Address
- * Array.
- *
- * Returns the physical address and sets
- * hc->dcbaap to the virtual address.
- */
-static uintptr_t
-xhci_alloc_dcbaa(struct xhci_hc *hc)
-{
- size_t dcbaa_size;
-
- dcbaa_size = sizeof(uintptr_t) * hc->maxslots;
- hc->dcbaap = dynalloc_memalign(dcbaa_size, 0x1000);
- __assert(hc->dcbaap != NULL);
-
- return VIRT_TO_PHYS(hc->dcbaap);
-}
-
-/*
- * Allocates command ring and sets hc->cmd_ring
- * to the virtual address.
- *
- * Returns the physical address.
- */
-static uintptr_t
-xhci_alloc_cmdring(struct xhci_hc *hc)
-{
- size_t cmdring_size;
-
- cmdring_size = XHCI_TRB_SIZE * XHCI_CMDRING_LEN;
- hc->cmd_ring = dynalloc_memalign(cmdring_size, 0x1000);
- __assert(hc->cmd_ring != NULL);
-
- return VIRT_TO_PHYS(hc->cmd_ring);
-}
-
-/*
- * Sets up the event ring.
- */
-static void
-xhci_init_evring(struct xhci_hc *hc)
-{
- struct xhci_caps *caps = XHCI_CAPS(hc->base);
- struct xhci_evring_segment *seg;
- uint64_t *erdp, *erstba;
- uint32_t *erst_size;
- void *runtime = XHCI_RTS(hc->base, caps->rtsoff);
- size_t size;
-
- size = XHCI_EVRING_LEN * XHCI_TRB_SIZE;
- seg = dynalloc_memalign(size, 64);
- memset(seg, 0, size);
-
- /* Set the size of the event ring segment table */
- erst_size = XHCI_BASE_OFF(runtime, 0x28);
- *erst_size = 1;
-
- /* Setup the event ring segment */
- memset(seg, 0, size);
- seg->base = VIRT_TO_PHYS(seg);
- seg->size = XHCI_EVRING_LEN;
-
- /* Setup the event ring dequeue pointer */
- erdp = XHCI_BASE_OFF(runtime, 0x38);
- *erdp = seg->base;
-
- /* Point ERSTBA to our event ring segment */
- erstba = XHCI_BASE_OFF(runtime, 0x30);
- *erstba = VIRT_TO_PHYS(seg);
-
- hc->event_ring = PHYS_TO_VIRT(seg->base);
-}
-
-static int
-xhci_init_hc(struct xhci_hc *hc)
-{
- struct xhci_caps *caps;
- struct xhci_opregs *opregs;
-
- /* Get some information from the controller */
- caps = XHCI_CAPS(hc->base);
- hc->caplen = caps->caplength;
- hc->maxslots = XHCI_MAXSLOTS(caps->hcsparams1);
- hc->maxports = XHCI_MAXSLOTS(caps->hcsparams1);
-
- opregs->config |= hc->maxslots;
-
- /* Fetch the opregs */
- opregs = XHCI_OPBASE(hc->base, hc->caplen);
- hc->opregs = XHCI_OPBASE(hc->base, hc->caplen);
-
- if (xhci_reset_hc(hc) != 0) {
- return -1;
- }
-
- /* Set cmdring state */
- hc->cycle = 1;
- hc->cmd_ptr = 0;
- hc->cmd_count = 0;
-
- /* Allocate resources and tell the HC about them */
- opregs->dcbaa_ptr = xhci_alloc_dcbaa(hc);
- xhci_init_scratchpads(hc);
- xhci_init_evring(hc);
- opregs->cmd_ring = xhci_alloc_cmdring(hc);
-
- /* We're ready, start up the HC and ports */
- xhci_start_hc(hc);
- xhci_parse_ecp(hc);
- xhci_init_ports(hc);
- return 0;
-}
-
-static int
-xhci_init(void)
-{
- uintptr_t bar0, bar1, base;
- struct xhci_hc hc;
- struct pci_lookup hc_lookup = {
- .pci_class = 0x0C,
- .pci_subclass = 0x03
- };
-
- /* Find the host controller on the bus */
- hci_dev = pci_get_device(hc_lookup, PCI_CLASS | PCI_SUBCLASS);
- if (hci_dev == NULL) {
- return -1;
- }
-
- bar0 = hci_dev->bar[0] & ~7;
- bar1 = hci_dev->bar[1] & ~7;
- base = __COMBINE32(bar1, bar0);
- hc.base = PHYS_TO_VIRT(base);
- pr_trace("xHCI HC base @ 0x%p\n", base);
-
- if (req_timer(TIMER_GP, &driver_tmr) != 0) {
- pr_error("Failed to fetch general purpose timer\n");
- return -1;
- }
- if (driver_tmr.msleep == NULL) {
- pr_error("Timer does not have msleep()\n");
- return -1;
- }
-
- return xhci_init_hc(&hc);
-}
-
-DRIVER_EXPORT(xhci_init);
diff --git a/sys/dev/vcons/vcons.c b/sys/dev/vcons/vcons.c
deleted file mode 100644
index fe1a3f0..0000000
--- a/sys/dev/vcons/vcons.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <dev/vcons/vcons.h>
-#include <dev/vcons/vcons_io.h>
-#include <dev/video/fbdev.h>
-#include <sys/syslog.h>
-#include <sys/cdefs.h>
-#include <string.h>
-
-__MODULE_NAME("kern_vcons");
-__KERNEL_META("$Hyra$: kern_vcons.c, Ian Marco Moffett, "
- "Hyra video console code");
-
-/* Get x or y values in pixels */
-#define PIX_CPY_X(scrptr) ((scrptr)->cpy_x * FONT_WIDTH)
-#define PIX_CPY_Y(scrptr) ((scrptr)->cpy_y * FONT_HEIGHT)
-
-#define PIX_BOUNDS_MAX_X(scrptr) ((scrptr)->fbdev.width - FONT_WIDTH)
-#define PIX_BOUNDS_MAX_Y(scrptr) ((scrptr)->fbdev.height - FONT_HEIGHT)
-
-static struct vcons_screen *screen = NULL;
-
-/*
- * Draw the console cursor.
- *
- * @color: Cursor color
- */
-static void
-vcons_draw_cursor(struct vcons_screen *scr, uint32_t color)
-{
- struct vcons_cursor *cursor = &scr->cursor;
- struct fbdev fbdev = scr->fbdev;
-
- uint32_t *fbdev_mem = fbdev.mem;
- uint32_t fbdev_idx = 0;
- uint32_t cx, cy;
-
- for (size_t y = VCONS_CURSOR_HEIGHT; y > 0; --y) {
- for (size_t x = VCONS_CURSOR_WIDTH; x > 0; --x) {
- cx = cursor->old_xpos + x;
- cy = cursor->old_ypos + y;
-
- fbdev_idx = fbdev_get_index(&fbdev, cx, cy);
- fbdev_mem[fbdev_idx] = color;
- }
- }
-}
-
-/*
- * Clear everything out of the console.
- */
-static void
-vcons_clear_scr(struct vcons_screen *scr)
-{
- struct fbdev fbdev = scr->fbdev;
-
- scr->cpy_x = 0, scr->cpy_y = 0;
-
- memset(scr->fbdev_mem, scr->bg, (fbdev.pitch * fbdev.height));
- vcons_update_cursor(scr);
-}
-
-/*
- * Renders a char onto the screen specified by `scr`.
- *
- * @x,y: In chars
- */
-static void
-vcons_draw_char(struct vcons_screen *scr, char c, uint32_t x, uint32_t y)
-{
- uint32_t *fb_ptr;
- size_t idx;
- const uint8_t *glyph;
-
- /* Get a pointer to framebuffer memory */
- fb_ptr = scr->fbdev_mem;
-
- /* Get the specific glyph of `c` */
- glyph = &DEFAULT_FONT_DATA[(int)c*16];
-
- for (uint32_t cy = 0; cy < FONT_HEIGHT; ++cy) {
- for (uint32_t cx = 0; cx < FONT_WIDTH; ++cx) {
- idx = fbdev_get_index(&scr->fbdev, x+FONT_WIDTH-cx, y+cy);
- fb_ptr[idx] = __TEST(glyph[cy], __BIT(cx)) ? scr->fg : scr->bg;
- }
- }
-}
-
-/*
- * Update the cursor position.
- *
- * XXX: This function also accounts for the old cursor
- * and clears it before drawing the new cursor.
- */
-void
-vcons_update_cursor(struct vcons_screen *scr)
-{
- struct vcons_cursor *cursor = &scr->cursor;
-
- cursor->is_drawing = true;
-
- if (cursor->is_drawn) {
- /* Clear old cursor */
- vcons_draw_cursor(scr, scr->bg);
- }
-
- cursor->old_xpos = cursor->xpos;
- cursor->old_ypos = cursor->ypos;
- vcons_draw_cursor(scr, scr->fg);
-
- cursor->is_drawn = true;
- cursor->is_drawing = false;
-}
-
-/*
- * Write out a character on the console.
- *
- * @c: Character to write.
- */
-int
-vcons_putch(struct vcons_screen *scr, char c)
-{
- uint32_t x = PIX_CPY_X(scr);
- uint32_t y = PIX_CPY_Y(scr);
- struct vcons_cursor *cursor = &scr->cursor;
- bool cursor_newline = false;
-
- while (cursor->is_drawing);
-
- if (scr == NULL) {
- return 1;
- }
-
- /* Check cursor bounds */
- if (cursor->xpos >= PIX_BOUNDS_MAX_X(scr)) {
- cursor->xpos = FONT_WIDTH;
- cursor->ypos += FONT_HEIGHT;
- cursor_newline = true;
- }
- if (cursor->ypos >= PIX_BOUNDS_MAX_Y(scr)) {
- cursor->xpos = FONT_WIDTH;
- cursor->ypos = 0;
- }
-
- /* Check text bounds */
- if (x >= PIX_BOUNDS_MAX_X(scr)) {
- /* Wrap to the next row */
- ++scr->cpy_y, scr->cpy_x = 0;
- x = PIX_CPY_X(scr), y = PIX_CPY_Y(scr);
- }
- if (y >= PIX_BOUNDS_MAX_Y(scr)) {
- scr->cpy_y = 0;
- scr->cpy_x = 0;
- vcons_clear_scr(scr);
- x = PIX_CPY_X(scr), y = PIX_CPY_Y(scr);
- }
-
- if (!cursor_newline) {
- cursor->xpos += FONT_WIDTH;
- }
-
- vcons_update_cursor(scr);
- vcons_draw_char(scr, c, x, y);
- ++scr->cpy_x;
- return 0;
-}
-
-/*
- * Write out a string on the console.
- *
- * @s: String to write.
- */
-int
-vcons_putstr(struct vcons_screen *scr, const char *s, size_t len)
-{
- int status;
-
- for (size_t i = 0; i < len; ++i) {
- if (vcons_process_output(scr, s[i]) > 0)
- continue;
- if ((status = vcons_putch(scr, s[i])) != 0) {
- return status;
- }
- }
-
- return 0;
-}
-
-void
-vcons_attach(struct vcons_screen *scr)
-{
- scr->fbdev = fbdev_get_front();
- scr->fbdev_mem = scr->fbdev.mem;
-
- scr->nrows = scr->fbdev.height;
- scr->ncols = scr->fbdev.width;
-
- screen = scr;
- vcons_clear_scr(scr);
-}
diff --git a/sys/dev/vcons/vcons_io.c b/sys/dev/vcons/vcons_io.c
deleted file mode 100644
index f4e693e..0000000
--- a/sys/dev/vcons/vcons_io.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <dev/vcons/vcons_io.h>
-#include <dev/vcons/vcons.h>
-#include <sys/cdefs.h>
-#include <sys/ascii.h>
-
-static void
-vcons_expand_tab(struct vcons_screen *scr)
-{
- for (size_t i = 0; i < VCONS_TAB_WIDTH; ++i) {
- vcons_putch(scr, ' ');
- }
-}
-
-/*
- * This routine tries to process the output `c'.
- *
- * Returns < 0 value on failure. Values >= 0
- * is `c' which may differ from the original.
- *
- * This routine also may modify the screen state
- * if `c' is a control character.
- */
-int
-vcons_process_output(struct vcons_screen *scr, int c)
-{
- struct vcons_cursor *cursor = &scr->cursor;
-
- switch (c) {
- case ASCII_LF:
- scr->cpy_y++;
- cursor->ypos += FONT_HEIGHT;
-
- scr->cpy_x = 0;
- cursor->xpos = 0;
- break;
- case ASCII_CR:
- scr->cpy_x = 0;
- cursor->xpos = 0;
- break;
- case ASCII_HT:
- vcons_expand_tab(scr);
- break;
- case ASCII_BS:
- if (cursor->xpos > 0) {
- scr->cpy_x--;
- cursor->xpos -= FONT_WIDTH;
- }
- break;
- default:
- return -1;
- }
-
- vcons_update_cursor(scr);
- return c;
-}
diff --git a/sys/dev/video/fbdev.c b/sys/dev/video/fbdev.c
deleted file mode 100644
index d9b680f..0000000
--- a/sys/dev/video/fbdev.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/limine.h>
-#include <sys/device.h>
-#include <sys/driver.h>
-#include <sys/system.h>
-#include <sys/errno.h>
-#include <dev/video/fbdev.h>
-#include <vm/vm.h>
-#include <fs/devfs.h>
-
-#define FRAMEBUFFER \
- framebuffer_req.response->framebuffers[0]
-
-static volatile struct limine_framebuffer_request framebuffer_req = {
- .id = LIMINE_FRAMEBUFFER_REQUEST,
- .revision = 0
-};
-
-static struct device *dev;
-
-static int
-fbdev_ioctl(struct device *dev, uint32_t cmd, uintptr_t arg)
-{
- struct fbdev_info info = {
- .width = FRAMEBUFFER->width,
- .height = FRAMEBUFFER->height,
- .pitch = FRAMEBUFFER->pitch,
- .bits_per_pixel = FRAMEBUFFER->bpp
- };
-
- switch (cmd) {
- case FBIOCTL_INFO:
- copyout(&info, arg, sizeof(info));
- break;
- default:
- return -EINVAL;
- }
-
- return 0;
-}
-
-static paddr_t
-fbdev_mmap(struct device *dev, off_t off, vm_prot_t prot)
-{
- struct fbdev fbdev = fbdev_get_front();
- paddr_t len = fbdev.width * fbdev.pitch;
- paddr_t base = VIRT_TO_PHYS(fbdev.mem);
- paddr_t max_paddr = base + len;
-
- if (base + off > max_paddr) {
- return 0;
- }
-
- return base + off;
-}
-
-static int
-fbdev_open(struct device *dev)
-{
- return 0;
-}
-
-struct fbdev
-fbdev_get_front(void)
-{
- struct fbdev ret;
-
- ret.mem = FRAMEBUFFER->address;
- ret.width = FRAMEBUFFER->width;
- ret.height = FRAMEBUFFER->height;
- ret.pitch = FRAMEBUFFER->pitch;
- return ret;
-}
-
-static int
-fbdev_init(void)
-{
- dev = device_alloc();
- dev->blocksize = 1;
- dev->read = NULL;
- dev->write = NULL;
- dev->mmap = fbdev_mmap;
- dev->ioctl = fbdev_ioctl;
- dev->open = fbdev_open;
-
- device_create(dev, device_alloc_major(), 1);
- devfs_add_dev("fb", dev);
- return 0;
-}
-
-DRIVER_EXPORT(fbdev_init);
diff --git a/sys/firmware/acpi/acpi_init.c b/sys/firmware/acpi/acpi_init.c
deleted file mode 100644
index a98e429..0000000
--- a/sys/firmware/acpi/acpi_init.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <firmware/acpi/acpi.h>
-#include <sys/limine.h>
-#include <sys/syslog.h>
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <sys/syslog.h>
-#include <vm/vm.h>
-
-__MODULE_NAME("acpi");
-__KERNEL_META("$Hyra$: acpi_init.c, Ian Marco Moffett, "
- "ACPI init logic");
-
-#define pr_trace(fmt, ...) kprintf("acpi: " fmt, ##__VA_ARGS__)
-
-static volatile struct limine_rsdp_request rsdp_req = {
- .id = LIMINE_RSDP_REQUEST,
- .revision = 0
-};
-
-static size_t root_sdt_entries = 0;
-static bool using_xsdt = false;
-static struct acpi_root_sdt *root_sdt = NULL;
-
-/*
- * Writes out OEMID of ACPI header.
- *
- * @type: Type of structure (e.g RSDP)
- * @hdr: Header of structure.
- */
-static void
-acpi_print_oemid(const char *type, char oemid[OEMID_SIZE])
-{
- if (type != NULL) {
- pr_trace("%s OEMID: ", type);
- }
-
- for (size_t i = 0; i < OEMID_SIZE; ++i) {
- kprintf(OMIT_TIMESTAMP "%c", oemid[i]);
- }
- kprintf(OMIT_TIMESTAMP "\n");
-}
-
-struct acpi_root_sdt *
-acpi_get_root_sdt(void)
-{
- return root_sdt;
-}
-
-size_t
-acpi_get_root_sdt_len(void)
-{
- return root_sdt_entries;
-}
-
-void
-acpi_init(void)
-{
- struct acpi_rsdp *rsdp;
-
- /* Can't do anything if we have no response! */
- if (rsdp_req.response == NULL) {
- panic("RSDP request has no response affiliated...\n");
- }
-
- /* Fetch the RSDP */
- rsdp = rsdp_req.response->address;
- acpi_print_oemid("RSDP", rsdp->oemid);
-
- /* Fetch the RSDT/XSDT */
- if (rsdp->revision >= 2) {
- using_xsdt = true;
- root_sdt = PHYS_TO_VIRT(rsdp->xsdt_addr);
- pr_trace("Using XSDT as root SDT\n");
- } else {
- root_sdt = PHYS_TO_VIRT(rsdp->rsdt_addr);
- pr_trace("Using RSDT as root SDT\n");
- }
- if (!acpi_is_checksum_valid(&root_sdt->hdr)) {
- panic("Root SDT has an invalid checksum!\n");
- }
- root_sdt_entries = (root_sdt->hdr.length - sizeof(root_sdt->hdr)) / 4;
-}
diff --git a/sys/firmware/acpi/acpi_madt.c b/sys/firmware/acpi/acpi_madt.c
deleted file mode 100644
index 0e2b338..0000000
--- a/sys/firmware/acpi/acpi_madt.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <firmware/acpi/acpi.h>
-#include <firmware/acpi/tables.h>
-#include <machine/ioapic.h>
-#include <machine/lapic.h>
-#include <machine/cpu.h>
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <sys/syslog.h>
-
-#define APIC_TYPE_LOCAL_APIC 0
-#define APIC_TYPE_IO_APIC 1
-#define APIC_TYPE_INTERRUPT_OVERRIDE 2
-
-#define pr_trace(fmt, ...) kprintf("acpi: " fmt, ##__VA_ARGS__)
-
-__MODULE_NAME("acpi");
-__KERNEL_META("$Hyra$: acpi_madt.c, Ian Marco Moffett, "
- "ACPI MADT parsing");
-
-
-static struct acpi_madt *madt = NULL;
-
-void *
-acpi_get_lapic_base(void)
-{
- if (madt == NULL)
- return NULL;
- return (void *)(uint64_t)madt->lapic_addr;
-}
-
-static void
-do_parse(struct cpu_info *ci)
-{
- uint8_t *cur = NULL;
- uint8_t *end = NULL;
-
- void *ioapic_mmio_base = NULL;
-
- struct apic_header *hdr = NULL;
- struct ioapic *ioapic = NULL;
-
- cur = (uint8_t *)(madt + 1);
- end = (uint8_t *)madt + madt->hdr.length;
-
- /* Parse the rest of the MADT */
- while (cur < end) {
- hdr = (void *)cur;
-
- switch (hdr->type) {
- case APIC_TYPE_IO_APIC:
- /*
- * TODO: Figure out how to use multiple
- * I/O APICs.
- */
- if (ioapic != NULL) {
- break;
- }
-
- ioapic = (struct ioapic *)cur;
-
- pr_trace("Detected I/O APIC (id=%d, gsi_base=%d)\n",
- ioapic->ioapic_id, ioapic->gsi_base);
-
- ioapic_mmio_base = (void *)(uintptr_t)ioapic->ioapic_addr;
- ioapic_set_base(ioapic_mmio_base);
- break;
- }
-
- cur += hdr->length;
- }
-}
-
-/*
- * Converts IRQ numbers to its corresponding
- * Global System Interrupt (GSI) number.
- *
- * @irq: IRQ number.
- */
-uint32_t
-irq_to_gsi(uint8_t irq)
-{
- struct apic_header *hdr = NULL;
- struct interrupt_override *override = NULL;
- uint8_t *cur = NULL;
- uint8_t *end = NULL;
-
- cur = (uint8_t *)(madt + 1);
- end = (uint8_t *)madt + madt->hdr.length;
-
- while (cur < end) {
- hdr = (void *)cur;
-
- switch (hdr->type) {
- case APIC_TYPE_INTERRUPT_OVERRIDE:
- override = (struct interrupt_override *)cur;
- if (override->source == irq) {
- return override->interrupt;
- }
- }
-
- cur += hdr->length;
- }
-
- return irq;
-}
-
-void
-acpi_parse_madt(struct cpu_info *ci)
-{
- /* Prevent this function from running twice */
- if (madt != NULL) {
- return;
- }
-
- madt = acpi_query("APIC");
- if (madt == NULL) {
- panic("Failed to query for ACPI MADT\n");
- }
-
- do_parse(ci);
-}
diff --git a/sys/firmware/acpi/acpi_subr.c b/sys/firmware/acpi/acpi_subr.c
deleted file mode 100644
index 4ca7555..0000000
--- a/sys/firmware/acpi/acpi_subr.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <firmware/acpi/acpi.h>
-#include <firmware/acpi/tables.h>
-#include <vm/vm.h>
-#include <string.h>
-
-bool
-acpi_is_checksum_valid(struct acpi_header *hdr)
-{
- uint8_t sum;
-
- sum = 0;
- for (int i = 0; i < hdr->length; ++i) {
- sum += ((char *)hdr)[i];
- }
-
- /* Sum of table (from header to end) must be zero!! */
- return sum == 0;
-}
-
-/*
- * Looks up an ACPI table with a specific
- * signature e.g "APIC" for MADT (if present).
- *
- * @query: The specific query to make e.g "APIC"
- */
-void *
-acpi_query(const char *query)
-{
- struct acpi_header *hdr;
- struct acpi_root_sdt *root_sdt;
- size_t root_sdt_len, signature_len;
-
- root_sdt = acpi_get_root_sdt();
- root_sdt_len = acpi_get_root_sdt_len();
-
- /*
- * XXX: Just a reminder, sizeof() is compile time.
- * There will be no actual reading,
- * so this is safe.
- */
- signature_len = sizeof(hdr->signature);
-
- for (size_t i = 0; i < root_sdt_len; ++i) {
- hdr = (struct acpi_header *)PHYS_TO_VIRT(root_sdt->tables[i]);
-
- if (memcmp(hdr->signature, query, signature_len) == 0) {
- return (void *)hdr;
- }
- }
-
- return NULL;
-}
diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c
deleted file mode 100644
index 7fcdbad..0000000
--- a/sys/fs/devfs.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <fs/devfs.h>
-#include <sys/vfs.h>
-#include <sys/mount.h>
-#include <sys/spinlock.h>
-#include <sys/queue.h>
-#include <sys/vnode.h>
-#include <sys/errno.h>
-#include <sys/cdefs.h>
-#include <vm/dynalloc.h>
-#include <string.h>
-
-struct device_node {
- struct spinlock lock;
- char *name;
- uint8_t is_block : 1;
- dev_t major, minor;
- TAILQ_ENTRY(device_node) link;
-};
-
-static TAILQ_HEAD(, device_node) nodes;
-static bool nodelist_init = false;
-
-static struct device_node *
-node_from_name(const char *name)
-{
- struct device_node *n;
-
- TAILQ_FOREACH(n, &nodes, link) {
- if (strcmp(n->name, name) == 0) {
- return n;
- }
- }
-
- return NULL;
-}
-
-static int
-cdev_read(struct device *dev, struct device_node *node, struct sio_txn *sio)
-{
- size_t n_bytes;
-
- spinlock_acquire(&node->lock);
- n_bytes = dev->read(dev, sio);
- spinlock_release(&node->lock);
- return n_bytes;
-}
-
-static int
-blkdev_read(struct device *dev, struct device_node *node, struct sio_txn *sio)
-{
- char *buf;
- struct sio_txn dev_txn = {0};
- size_t n_blocks = __DIV_ROUNDUP(sio->len, dev->blocksize);
- size_t n_bytes = n_blocks * dev->blocksize;
- size_t cpy_off;
-
- if (dev->blocksize == 0 || sio->len == 0) {
- /* Sizes can't be zero! */
- return -EIO;
- }
-
- spinlock_acquire(&node->lock);
- buf = dynalloc_memalign(n_bytes, 0x1000);
-
- if (buf == NULL) {
- spinlock_release(&node->lock);
- return -ENOMEM;
- }
-
- dev_txn.len = n_blocks;
- dev_txn.buf = buf;
- dev_txn.offset = sio->offset / dev->blocksize;
- dev->read(dev, &dev_txn);
- spinlock_release(&node->lock);
-
- cpy_off = sio->offset - (dev_txn.offset * dev->blocksize);
- for (size_t i = 0; i < sio->len; ++i) {
- ((uint8_t *)sio->buf)[i] = buf[i + cpy_off];
- }
-
- dynfree(buf);
- return sio->len;
-}
-
-static int
-vop_vget(struct vnode *parent, const char *name, struct vnode **vp)
-{
- struct device_node *dev;
- struct vnode *vnode;
- int status, vtype;
-
- if (!nodelist_init) {
- return -EIO;
- }
-
- if ((dev = node_from_name(name)) == NULL) {
- return -ENOENT;
- }
-
- vtype = dev->is_block ? VBLK : VCHR;
- if ((status = vfs_alloc_vnode(&vnode, NULL, vtype)) != 0) {
- return status;
- }
-
- vnode->parent = parent;
- vnode->data = dev;
- vnode->vops = &g_devfs_vops;
- *vp = vnode;
- return 0;
-}
-
-static int
-vop_read(struct vnode *vp, struct sio_txn *sio)
-{
- struct device_node *node;
- struct device *dev;
-
- if (vp == NULL) {
- return -EIO;
- }
-
- node = vp->data;
- dev = device_fetch(node->major, node->minor);
-
- if (dev->blocksize > 1)
- return blkdev_read(dev, node, sio);
-
- return cdev_read(dev, node, sio);
-}
-
-static int
-vop_open(struct vnode *vp)
-{
- struct device_node *node;
- struct device *dev;
-
- if (vp == NULL) {
- return -EIO;
- }
-
- node = vp->data;
- dev = device_fetch(node->major, node->minor);
-
- if (dev->open == NULL) {
- return -EIO;
- }
-
- return dev->open(dev);
-}
-
-static int
-vop_close(struct vnode *vp)
-{
- struct device_node *node;
- struct device *dev;
-
- if (vp == NULL) {
- return -EIO;
- }
-
- node = vp->data;
- dev = device_fetch(node->major, node->minor);
-
- if (dev->close == NULL) {
- return -EIO;
- }
-
- return dev->close(dev);
-}
-
-static int
-devfs_init(struct fs_info *info, struct vnode *source)
-{
- if (source != NULL)
- return -EINVAL;
-
- TAILQ_INIT(&nodes);
- nodelist_init = true;
- return 0;
-}
-
-static int
-devfs_make_devicenode(const char *name, struct device_node **node_out)
-{
- size_t name_len = 0;
- const char *p = name;
- struct device_node *node;
-
- /*
- * Only one filename, no paths.
- *
- * TODO: Do something better here...
- */
- for (; *p; ++p, ++name_len) {
- if (*p == '/')
- return -EINVAL;
- }
-
- /* Ensure this filename has valid chars */
- if (!vfs_is_valid_path(name)) {
- return -EINVAL;
- }
-
- node = dynalloc(sizeof(struct device_node));
- if (node == NULL)
- return -ENOMEM;
-
- node->name = dynalloc(sizeof(char) * name_len);
- if (node->name == NULL)
- return -ENOMEM;
-
- memcpy(node->name, name, name_len + 1);
- *node_out = node;
- return 0;
-}
-
-int
-devfs_add_dev(const char *name, const struct device *dev)
-{
- struct device_node *node;
- int status;
-
- if ((status = devfs_make_devicenode(name, &node)) != 0) {
- return status;
- }
-
- node->major = dev->major;
- node->minor = dev->minor;
- node->is_block = dev->blocksize > 1;
- TAILQ_INSERT_HEAD(&nodes, node, link);
- return 0;
-}
-
-/*
- * Fetch a device descriptor from a vnode.
- */
-int
-devfs_get_dev(struct vnode *vp, struct device **res)
-{
- struct device_node *n;
- struct device *dev;
-
- /* Is this really a device? */
- if (vp->type != VBLK && vp->type != VCHR) {
- return -ENODEV;
- }
-
- n = vp->data;
- if ((dev = device_fetch(n->major, n->minor)) == NULL) {
- return -ENODEV;
- }
-
- *res = dev;
- return 0;
-}
-
-struct vfsops g_devfs_ops = {
- .init = devfs_init
-};
-
-struct vops g_devfs_vops = {
- .vget = vop_vget,
- .read = vop_read,
- .open = vop_open,
- .close = vop_close
-};
diff --git a/sys/fs/initramfs.c b/sys/fs/initramfs.c
deleted file mode 100644
index e15c00d..0000000
--- a/sys/fs/initramfs.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <fs/initramfs.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/limine.h>
-#include <sys/errno.h>
-#include <sys/panic.h>
-#include <sys/vfs.h>
-#include <sys/vnode.h>
-#include <vm/dynalloc.h>
-#include <string.h>
-
-__MODULE_NAME("initramfs");
-__KERNEL_META("$Hyra$: initramfs.c, Ian Marco Moffett, "
- "Initial ram filesystem");
-
-static volatile struct limine_module_request mod_req = {
- .id = LIMINE_MODULE_REQUEST,
- .revision = 0
-};
-
-static const char *initramfs = NULL;
-static size_t initramfs_size = 0;
-
-#define TAR_TYPEFLAG_NORMAL '0'
-#define TAR_TYPEFLAG_HARDLINK '1'
-#define TAR_TYPEFLAG_DIR '5'
-
-struct tar_hdr {
- char filename[100];
- char mode[8];
- char uid[8];
- char gid[8];
- char size[12];
- char mtime[12];
- char checksum[8];
- char type;
- char link_name[100];
- char magic[6];
- char version[2];
- char uname[32];
- char gname[32];
- char dev_major[8];
- char dev_minor[8];
- char prefix[155];
-};
-
-static struct tar_hdr *initramfs_from_path(struct tar_hdr *hdr,
- const char *path);
-
-static size_t
-getsize(const char *in);
-
-static inline char *
-hdr_to_contents(struct tar_hdr *hdr)
-{
- return ((char*)hdr) + 0x200;
-}
-
-static int
-vop_vget(struct vnode *parent, const char *name, struct vnode **vp)
-{
- struct tar_hdr *hdr;
- struct vnode *vnode;
- int status;
- int vtype = VREG;
-
- if (initramfs == NULL) {
- return -EIO;
- }
-
- hdr = initramfs_from_path((void *)initramfs, name);
-
- if (hdr == NULL) {
- return -ENOENT;
- }
-
- if (hdr->type == TAR_TYPEFLAG_DIR) {
- vtype = VDIR;
- }
-
- /* Allocate vnode for this file */
- if ((status = vfs_alloc_vnode(&vnode, NULL, vtype)) != 0) {
- return status;
- }
-
- vnode->parent = parent;
- vnode->data = hdr;
-
- vnode->vops = &g_initramfs_vops;
- *vp = vnode;
- return 0;
-}
-
-static int
-vop_read(struct vnode *vp, struct sio_txn *sio)
-{
- struct tar_hdr *hdr;
- size_t size;
- char *contents;
- char *buf = sio->buf;
-
- if (vp->data == NULL) {
- return -EIO;
- }
-
- hdr = vp->data;
- size = getsize(hdr->size);
- contents = hdr_to_contents(hdr);
-
- for (size_t i = sio->offset; i < sio->len; ++i) {
- if (i >= size) {
- return i + 1;
- }
- buf[i - sio->offset] = contents[i];
- }
-
- return sio->len;
-}
-
-static int
-vop_getattr(struct vnode *vp, struct vattr *vattr)
-{
- struct tar_hdr *hdr = vp->data;
-
- if (hdr == NULL) {
- return -EIO;
- }
-
- switch (hdr->type) {
- case TAR_TYPEFLAG_NORMAL:
- vattr->type = VREG;
- break;
- case TAR_TYPEFLAG_DIR:
- vattr->type = VDIR;
- break;
- }
-
- vattr->size = getsize(hdr->size);
- return 0;
-}
-
-static char *
-get_module(const char *path, uint64_t *size) {
- for (uint64_t i = 0; i < mod_req.response->module_count; ++i) {
- if (strcmp(mod_req.response->modules[i]->path, path) == 0) {
- *size = mod_req.response->modules[i]->size;
- return mod_req.response->modules[i]->address;
- }
- }
-
- return NULL;
-}
-
-static size_t
-getsize(const char *in)
-{
- size_t size = 0, count = 1;
-
- for (size_t j = 11; j > 0; --j, count *= 8) {
- size += (in[j-1]-'0')*count;
- }
-
- return size;
-}
-
-static int
-initramfs_init(struct fs_info *info, struct vnode *source)
-{
- if (source != NULL)
- return -EINVAL;
-
- initramfs = get_module("/boot/initramfs.tar", &initramfs_size);
- info->caps = FSCAP_FULLPATH;
-
- if (initramfs == NULL) {
- panic("Failed to load initramfs\n");
- }
-
- return 0;
-}
-
-static struct tar_hdr *
-initramfs_from_path(struct tar_hdr *hdr, const char *path)
-{
-
- uintptr_t addr = (uintptr_t)hdr;
- size_t size;
-
- if (*path != '/') {
- return NULL;
- }
- ++path;
-
- while (strcmp(hdr->magic, "ustar") == 0) {
- size = getsize(hdr->size);
-
- if (strcmp(hdr->filename, path) == 0) {
- return hdr;
- }
-
- addr += 512 + __ALIGN_UP(size, 512);
- hdr = (struct tar_hdr *)addr;
- }
-
- return NULL;
-}
-
-const char *
-initramfs_open(const char *path)
-{
- struct tar_hdr *hdr;
-
- if (initramfs == NULL) {
- return NULL;
- }
-
- if (strlen(path) > 99) {
- return NULL;
- }
-
- hdr = initramfs_from_path((void *)initramfs, path);
- return (hdr == NULL) ? NULL : hdr_to_contents(hdr);
-}
-
-struct vfsops g_initramfs_ops = {
- .init = initramfs_init,
-};
-
-struct vops g_initramfs_vops = {
- .vget = vop_vget,
- .read = vop_read,
- .getattr = vop_getattr
-};
diff --git a/sys/fs/procfs.c b/sys/fs/procfs.c
deleted file mode 100644
index 3a0e2d3..0000000
--- a/sys/fs/procfs.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/mount.h>
-#include <sys/queue.h>
-#include <sys/errno.h>
-#include <vm/dynalloc.h>
-#include <sys/vfs.h>
-#include <fs/procfs.h>
-#include <string.h>
-
-struct proc_node {
- struct spinlock lock;
- struct proc_entry *entry;
- char *name;
- TAILQ_ENTRY(proc_node) link;
-};
-
-static TAILQ_HEAD(, proc_node) proc_nodes;
-static bool nodelist_init = false;
-
-static struct proc_node *
-name_to_node(const char *name)
-{
- struct proc_node *n;
-
- TAILQ_FOREACH(n, &proc_nodes, link) {
- if (strcmp(n->name, name) == 0) {
- return n;
- }
- }
-
- return NULL;
-}
-
-static int
-procfs_make_node(const char *name, struct proc_node **res)
-{
- size_t name_len = 0;
- const char *p = name;
- struct proc_node *n;
-
- /* Disallow paths */
- for (; *p; ++p, ++name_len) {
- if (*p == '/') {
- return -EINVAL;
- }
- }
-
- if (!vfs_is_valid_path(name))
- return -EINVAL;
-
- n = dynalloc(sizeof(struct proc_node));
- if (n == NULL)
- return -ENOMEM;
-
- n->name = dynalloc(sizeof(char) * name_len);
- if (n->name == NULL)
- return -ENOMEM;
-
- memcpy(n->name, name, name_len + 1);
- *res = n;
- return 0;
-}
-
-struct proc_entry *
-procfs_alloc_entry(void)
-{
- struct proc_entry *entry;
-
- entry = dynalloc(sizeof(*entry));
- if (entry == NULL)
- return NULL;
-
- memset(entry, 0, sizeof(*entry));
- return entry;
-}
-
-int
-procfs_add_entry(const char *name, struct proc_entry *entry)
-{
- struct proc_node *proc;
- int status;
-
- if (name == NULL || entry == NULL)
- return -EINVAL;
- if ((status = procfs_make_node(name, &proc)) != 0)
- return status;
-
- proc->entry = entry;
- TAILQ_INSERT_HEAD(&proc_nodes, proc, link);
- return 0;
-}
-
-static int
-procfs_init(struct fs_info *info, struct vnode *source)
-{
- if (source != NULL)
- return -EINVAL;
-
-
- TAILQ_INIT(&proc_nodes);
- nodelist_init = true;
- procfs_populate();
- return 0;
-}
-
-static int
-procfs_rw_vnode(struct vnode *vp, struct sio_txn *sio, bool write)
-{
- struct proc_node *proc;
- struct proc_entry *entry;
-
- if (vp == NULL)
- return -EIO;
-
- proc = vp->data;
- entry = proc->entry;
-
- return write ? entry->write(entry, sio)
- : entry->read(entry, sio);
-}
-
-static int
-vop_write(struct vnode *vp, struct sio_txn *sio)
-{
- return procfs_rw_vnode(vp, sio, true);
-}
-
-static int
-vop_read(struct vnode *vp, struct sio_txn *sio)
-{
- return procfs_rw_vnode(vp, sio, false);
-}
-
-static int
-vop_open(struct vnode *vp)
-{
- return 0;
-}
-
-static int
-vop_close(struct vnode *vp)
-{
- return 0;
-}
-
-static int
-vop_vget(struct vnode *parent, const char *name, struct vnode **vp)
-{
- struct proc_node *proc;
- struct vnode *vnode;
- int status;
-
- if (!nodelist_init)
- return -EIO;
- if ((proc = name_to_node(name)) == NULL)
- return -ENOENT;
- if ((status = vfs_alloc_vnode(&vnode, NULL, VREG)) != 0)
- return status;
-
- vnode->parent = parent;
- vnode->data = proc;
- vnode->vops = &g_procfs_vops;
- *vp = vnode;
- return 0;
-}
-
-struct vfsops g_procfs_ops = {
- .init = procfs_init
-};
-
-struct vops g_procfs_vops = {
- .vget = vop_vget,
- .read = vop_read,
- .write = vop_write,
- .open = vop_open,
- .close = vop_close
-};
diff --git a/sys/fs/procfs_subr.c b/sys/fs/procfs_subr.c
deleted file mode 100644
index 8b95919..0000000
--- a/sys/fs/procfs_subr.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/panic.h>
-#include <sys/intr.h>
-#include <sys/syslog.h>
-#include <machine/cpu.h>
-#include <fs/procfs.h>
-#include <vm/vm.h>
-#include <string.h>
-
-static bool populated = false;
-
-static int
-procfs_ver_read(struct proc_entry *p, struct sio_txn *sio)
-{
- char buf[1024];
- size_t len;
-
- len = snprintf(buf, sizeof(buf), "Hyra/%s v%s: %s (%s)\n",
- HYRA_ARCH, HYRA_VERSION,
- HYRA_BUILDDATE, HYRA_BUILDBRANCH);
-
- /* Truncate if needed */
- if (len > sio->len)
- len = sio->len;
-
- memcpy(sio->buf, buf, len);
- return len;
-}
-
-static int
-procfs_memstat_read(struct proc_entry *p, struct sio_txn *sio)
-{
- struct vm_memstat stat;
- struct physmem_stat *pstat;
- char buf[1024];
- size_t len;
-
- stat = vm_memstat();
- pstat = &stat.pmem_stat;
- len = snprintf(buf, sizeof(buf),
- "TotalMem: %d KiB\n"
- "ReservedMem: %d KiB\n"
- "AvailableMem: %d KiB\n"
- "AllocatedMem: %d KiB\n"
- "VMemObjCount: %d\n",
- pstat->total_kib,
- pstat->reserved_kib,
- pstat->avl_kib,
- pstat->alloc_kib,
- stat.vmobj_cnt);
-
- /* Truncate if needed */
- if (len > sio->len)
- len = sio->len;
-
- memcpy(sio->buf, buf, len);
- return len;
-}
-
-/*
- * Populate procfs with basic misc entries
- */
-void
-procfs_populate(void)
-{
- struct proc_entry *version;
- struct proc_entry *memstat;
-
- if (populated)
- return;
-
- populated = true;
-
- /* Kernel version */
- version = procfs_alloc_entry();
- version->read = procfs_ver_read;
- procfs_add_entry("version", version);
-
- /* Memstat */
- memstat = procfs_alloc_entry();
- memstat->read = procfs_memstat_read;
- procfs_add_entry("memstat", memstat);
-
- intr_init_proc();
- syslog_init_proc();
-}
diff --git a/sys/include/arch/amd64/bus.h b/sys/include/arch/amd64/bus.h
deleted file mode 100644
index 53d1fe2..0000000
--- a/sys/include/arch/amd64/bus.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_BUS_H_
-#define _AMD64_BUS_H_
-
-#include <sys/types.h>
-
-typedef uint64_t bus_addr_t;
-
-int bus_map(bus_addr_t addr, size_t size, int flags, void **vap);
-
-#endif /* !_AMD64_BUS_H_ */
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
deleted file mode 100644
index 3febf5a..0000000
--- a/sys/include/arch/amd64/cpu.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_CPU_H_
-#define _AMD64_CPU_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/spinlock.h>
-#include <sys/sched_state.h>
-#include <sys/queue.h>
-#include <sys/intr.h>
-#include <machine/tss.h>
-#include <machine/msr.h>
-/*
- * XXX: We are not using the PAUSE instruction for the sake of
- * ensuring compatibility... PAUSE is F3 90, REP NOP is
- * F3 90... REP NOP will be read as a PAUSE on processors
- * that support it.
- */
-#define hint_spinwait() __ASMV("rep; nop")
-
-#define this_cpu() amd64_this_cpu()
-#define get_bsp() amd64_get_bsp()
-#define is_intr_mask() amd64_is_intr_mask()
-#define CPU_INFO_LOCK(info) spinlock_acquire(&(info->lock))
-#define CPU_INFO_UNLOCK(info) spinlock_release(&(info->lock))
-
-/*
- * Info about a specific processor.
- *
- * XXX: Spinlock must be acquired outside of this module!
- * None of these module's internal functions should
- * acquire the spinlock themselves!
- */
-struct cpu_info {
- /* Per-arch fields */
- void *pmap; /* Current pmap */
- uint32_t id;
- uint32_t idx;
- struct spinlock lock;
- struct sched_state sched_state;
- TAILQ_ENTRY(cpu_info) link;
-
- /* AMD64 */
- volatile size_t lapic_tmr_freq;
- volatile void *lapic_base;
- volatile bool has_x2apic;
- volatile struct tss_entry *tss;
- volatile uintptr_t tlb_flush_ptr; /* Address to flush */
- struct intr_info *tlb_shootdown; /* Shootdown interrupt info */
-};
-
-/*
- * Contains information for the current
- * core. Stored in %GS.
- *
- * MUST REMAIN IN ORDER!!!
- */
-struct cpu_ctx {
- struct cpu_info *ci;
-};
-
-/*
- * Returns true for this core if maskable
- * interrupts are masked (CLI) and false if
- * they aren't (STI).
- */
-static inline bool
-amd64_is_intr_mask(void)
-{
- uint64_t flags;
-
- __ASMV("pushfq; pop %0" : "=rm" (flags) :: "memory");
- return !__TEST(flags, 1 << 9);
-}
-
-static inline void
-amd64_write_gs_base(uintptr_t val)
-{
- wrmsr(IA32_KERNEL_GS_BASE, val);
-}
-
-static inline uintptr_t
-amd64_read_gs_base(void)
-{
- return rdmsr(IA32_KERNEL_GS_BASE);
-}
-
-static inline uint64_t
-amd64_read_cr0(void)
-{
- uint64_t cr0;
- __ASMV("mov %%cr0, %0" : "=r" (cr0) :: "memory");
- return cr0;
-}
-
-static inline void
-amd64_write_cr0(uint64_t val)
-{
- __ASMV("mov %0, %%cr0" :: "r" (val) : "memory");
-}
-
-static inline uint64_t
-amd64_read_cr4(void)
-{
- uint64_t cr4;
- __ASMV("mov %%cr4, %0" : "=r" (cr4) :: "memory");
- return cr4;
-}
-
-static inline void
-amd64_write_cr4(uint64_t val)
-{
- __ASMV("mov %0, %%cr4" :: "r" (val) : "memory");
-}
-
-static inline void
-amd64_fxsave(void *area)
-{
- __ASMV("fxsave (%0)" :: "r" (area) : "memory");
-}
-
-static inline void
-amd64_fxrstor(void *area)
-{
- __ASMV("fxrstor (%0)" :: "r" (area) : "memory");
-}
-
-struct cpu_info *amd64_this_cpu(void);
-
-#endif /* !_AMD64_CPU_H_ */
diff --git a/sys/include/arch/amd64/cpu_mp.h b/sys/include/arch/amd64/cpu_mp.h
deleted file mode 100644
index 4047f3b..0000000
--- a/sys/include/arch/amd64/cpu_mp.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_CPU_AP_H_
-#define _SYS_CPU_AP_H_
-
-#include <machine/cpu.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-__weak void ap_bootstrap(struct cpu_info *ci);
-__weak bool mp_supported(void);
-
-#endif /* !_SYS_CPU_AP_H_ */
diff --git a/sys/include/arch/amd64/cpuid.h b/sys/include/arch/amd64/cpuid.h
deleted file mode 100644
index b193d60..0000000
--- a/sys/include/arch/amd64/cpuid.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_CPUID_H_
-#define _AMD64_CPUID_H_
-
-#include <sys/cdefs.h>
-
-#define __CPUID(level, a, b, c, d) \
- __ASMV("cpuid\n\t" \
- : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
- : "0" (level))
-
-#endif /* !_AMD64_CPUID_H_ */
diff --git a/sys/include/arch/amd64/frame.h b/sys/include/arch/amd64/frame.h
deleted file mode 100644
index 85edea9..0000000
--- a/sys/include/arch/amd64/frame.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_FRAME_H_
-#define _AMD64_FRAME_H_
-
-#if !defined(__ASSEMBLER__)
-
-#include <sys/types.h>
-
-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;
-};
-
-#define init_frame(FRAME, IP, SP) \
- (FRAME)->rip = IP; \
- (FRAME)->cs = 0x08; \
- (FRAME)->rflags = 0x202; \
- (FRAME)->rsp = SP; \
- (FRAME)->ss = 0x10; \
-
-#define init_frame_user(FRAME, IP, SP) \
- (FRAME)->rip = IP; \
- (FRAME)->cs = 0x18 | 3; \
- (FRAME)->rflags = 0x202; \
- (FRAME)->rsp = SP; \
- (FRAME)->ss = 0x20 | 3; \
-
-#define set_frame_sp(FRAME, SP) (FRAME)->rsp = SP
-#define set_frame_ip(FRAME, IP) (FRAME)->rip = IP
-#define get_frame_ip(FRAME) (FRAME)->rip
-
-#endif /* !defined(__ASSEMBLER__) */
-#endif /* !_AMD64_FRAME_H_ */
diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h
deleted file mode 100644
index cdcdd20..0000000
--- a/sys/include/arch/amd64/frameasm.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_FRAMEASM_H_
-#define _AMD64_FRAMEASM_H_
-
-/*
- * If the interrupt has an error code, this macro shall
- * be used to create the trapframe.
- *
- * XXX: A trapframe created with this must be popped with
- * pop_trapframe_ec
- */
-.macro push_trapframe_ec 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
-
-/*
- * If the interrupt has an error code, this macro shall
- * be used to cleanup the trapframe.
- */
-.macro pop_trapframe_ec
- 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 %r11
- pop %r12
- pop %r13
- pop %r14
- pop %r15
-.endm
-
-/*
- * If the interrupt has no error code, this macro
- * shall be used to create the trapframe.
- *
- * XXX: A trapframe created with this must be popped
- * with pop_trapframe
- */
-.macro push_trapframe trapno
- push $0
- push_trapframe_ec \trapno
-.endm
-
-
-/*
- * If the interrupt has no error code, this macro shall
- * be used to cleanup the trapframe.
- */
-.macro pop_trapframe
- pop_trapframe_ec
- add $8, %rsp /* Pop error code */
-.endm
-#endif /* !_AMD64_FRAMEASM_H_ */
diff --git a/sys/include/arch/amd64/gdt.h b/sys/include/arch/amd64/gdt.h
deleted file mode 100644
index c3ea8e8..0000000
--- a/sys/include/arch/amd64/gdt.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef AMD64_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_gdt[256];
-extern struct gdt_entry *g_gdt_tss;
-extern struct gdtr g_gdtr;
-
-#endif /* !AMD64_GDT_H_ */
diff --git a/sys/include/arch/amd64/hpet.h b/sys/include/arch/amd64/hpet.h
deleted file mode 100644
index dc4366c..0000000
--- a/sys/include/arch/amd64/hpet.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _TIMER_HPET_H_
-#define _TIMER_HPET_H_
-
-#include <sys/types.h>
-
-int hpet_init(void);
-int hpet_msleep(size_t ms);
-int hpet_usleep(size_t us);
-int hpet_nsleep(size_t ns);
-
-#endif /* !_TIMER_HPET_H_ */
diff --git a/sys/include/arch/amd64/idt.h b/sys/include/arch/amd64/idt.h
deleted file mode 100644
index 36ce44e..0000000
--- a/sys/include/arch/amd64/idt.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_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/intr.h b/sys/include/arch/amd64/intr.h
deleted file mode 100644
index d48a573..0000000
--- a/sys/include/arch/amd64/intr.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_INTR_H_
-#define _AMD64_INTR_H_
-
-#define IST_SCHED 1U
-#define IST_HW_IRQ 2U
-#define IST_SW_INT 3U
-
-#endif /* !_AMD64_INTR_H_ */
diff --git a/sys/include/arch/amd64/io.h b/sys/include/arch/amd64/io.h
deleted file mode 100644
index c24c08d..0000000
--- a/sys/include/arch/amd64/io.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_IO_H_
-#define _AMD64_IO_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-static inline uint8_t
-inb(uint16_t port)
-{
- uint8_t result;
- __asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
- return result;
-}
-
-static inline void
-outb(uint16_t port, uint8_t data)
-{
- __asm__("out %%al, %%dx" : :"a" (data), "d" (port));
-}
-
-static inline void
-outw(uint16_t port, uint16_t data)
-{
- __ASMV("outw %w0, %w1" : : "a" (data), "Nd" (port));
-}
-
-static inline uint16_t
-inw(uint16_t port)
-{
- uint16_t data;
- __ASMV("inw %w1, %w0" : "=a" (data) : "Nd" (port));
- return data;
-}
-
-static inline void
-outl(uint16_t port, uint32_t data)
-{
- __ASMV("outl %0, %w1" : : "a" (data), "Nd" (port));
-}
-
-static inline uint32_t
-inl(uint16_t port)
-{
- uint32_t data;
- __ASMV("inl %w1, %0" : "=a" (data) : "Nd" (port));
- return data;
-}
-
-#endif /* !_AMD64_IO_H_ */
diff --git a/sys/include/arch/amd64/ioapic.h b/sys/include/arch/amd64/ioapic.h
deleted file mode 100644
index 0d86441..0000000
--- a/sys/include/arch/amd64/ioapic.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_IOAPIC_H_
-#define _AMD64_IOAPIC_H_
-
-#include <sys/types.h>
-
-void ioapic_irq_mask(uint8_t irq);
-void ioapic_irq_unmask(uint8_t irq);
-void ioapic_gsi_mask(uint8_t gsi);
-void ioapic_gsi_unmask(uint8_t gsi);
-void ioapic_set_base(void *mmio_base);
-void ioapic_set_vec(uint8_t irq, uint8_t vector);
-void ioapic_init(void);
-
-#endif /* !_AMD64_IOAPIC_H_ */
diff --git a/sys/include/arch/amd64/ioapicvar.h b/sys/include/arch/amd64/ioapicvar.h
deleted file mode 100644
index 5128bc8..0000000
--- a/sys/include/arch/amd64/ioapicvar.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_IOAPICVAR_H_
-#define _AMD64_IOAPICVAR_H_
-
-#include <sys/types.h>
-
-/* Register offsets */
-#define IOREGSEL 0x00
-#define IOWIN 0x10
-#define IOAPICVER 0x01
-#define IOREDTBL 0x10
-
-union ioapic_redentry {
- struct {
- uint8_t vector;
- uint8_t delmod : 3;
- uint8_t destmod : 1;
- uint8_t delivs : 1;
- uint8_t intpol : 1;
- uint8_t remote_irr : 1;
- uint8_t trigger_mode : 1;
- uint8_t interrupt_mask : 1;
- uint64_t reserved : 39;
- uint8_t dest_field;
- };
- uint64_t value;
-};
-
-#endif /* !_AMD64_IOAPICVAR_H_ */
diff --git a/sys/include/arch/amd64/isa/i8042regs.h b/sys/include/arch/amd64/isa/i8042regs.h
deleted file mode 100644
index edef2ee..0000000
--- a/sys/include/arch/amd64/isa/i8042regs.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_I8042REG_H_
-#define _AMD64_I8042REG_H_
-
-#include <sys/cdefs.h>
-
-#define I8042_DATA 0x60
-#define I8042_STATUS 0x64
-#define I8042_COMMAND 0x64
-
-/* Status register bits */
-#define I8042_OBUF_FULL __BIT(0) /* Output buffer full */
-#define I8042_IBUF_FULL __BIT(1) /* Input buffer full */
-
-/* Commands */
-#define I8042_DISABLE_PORT0 0xAD
-#define I8042_DISABLE_PORT1 0xA7
-#define I8042_ENABLE_PORT0 0xAE
-#define I8042_ENABLE_PORT1 0xA8
-#define I8042_GET_CONFB 0x20
-#define I8042_SET_CONFB 0x60
-#define I8042_PORT1_SEND 0xD4
-
-/* Controller config bits */
-#define I8042_PORT0_INTR __BIT(0)
-#define I8042_PORT1_INTR __BIT(1)
-#define I8042_PORT0_CLK __BIT(4)
-#define I8042_PORT1_CLK __BIT(5)
-
-/* Aux commands */
-#define I8042_AUX_DEFAULTS 0xF5
-#define I8042_AUX_ENABLE 0xF4
-#define I8042_AUX_DISABLE 0xF5
-#define I8042_AUX_RESET 0xFF
-
-/* LED bits */
-#define I8042_LED_SCROLL __BIT(0)
-#define I8042_LED_NUM __BIT(1)
-#define I8042_LED_CAPS __BIT(2)
-
-#endif /* !_AMD64_I8042REG_H_ */
diff --git a/sys/include/arch/amd64/isa/i8254.h b/sys/include/arch/amd64/isa/i8254.h
deleted file mode 100644
index 8215bf4..0000000
--- a/sys/include/arch/amd64/isa/i8254.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_ISA_i8254_H_
-#define _AMD64_ISA_i8254_H_
-
-#include <sys/types.h>
-
-#define i8254_COMMAND 0x43
-#define i8254_CHANNEL_0 0x40
-#define i8254_CHANNEL_2 0x42
-#define i8254_DIVIDEND 1193182ULL
-
-uint16_t i8254_get_count(void);
-void i8254_set_reload(uint16_t val);
-void i8254_set_frequency(uint64_t frequency_hz);
-
-#endif /* !_AMD64_ISA_i8254_H_ */
diff --git a/sys/include/arch/amd64/isa/spkr.h b/sys/include/arch/amd64/isa/spkr.h
deleted file mode 100644
index 2691721..0000000
--- a/sys/include/arch/amd64/isa/spkr.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _ISA_SPKR_H_
-#define _ISA_SPKR_H_
-
-#include <sys/types.h>
-
-int pcspkr_tone(uint16_t freq, uint32_t msec);
-
-#endif
diff --git a/sys/include/arch/amd64/lapic.h b/sys/include/arch/amd64/lapic.h
deleted file mode 100644
index c8a4de4..0000000
--- a/sys/include/arch/amd64/lapic.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_LAPIC_H_
-#define _AMD64_LAPIC_H_
-
-#include <sys/types.h>
-
-#define LAPIC_TMR_ONESHOT 0x00
-#define LAPIC_TMR_PERIODIC 0x01
-
-/* IPI Destination Shorthands */
-enum {
- IPI_SHORTHAND_NONE,
- IPI_SHORTHAND_SELF,
- IPI_SHORTHAND_ALL,
- IPI_SHORTHAND_OTHERS
-};
-
-/* IPI Destination Modes */
-enum {
- IPI_DEST_PHYSICAL,
- IPI_DEST_LOGICAL
-};
-
-void lapic_timer_init(size_t *freq_out);
-void lapic_timer_oneshot(bool mask, uint32_t count);
-void lapic_timer_oneshot_us(size_t us);
-void lapic_send_ipi(uint8_t id, uint8_t shorthand, uint8_t vector);
-void lapic_send_eoi(void);
-void lapic_init(void);
-
-#endif /* !_AMD64_LAPIC_H_ */
diff --git a/sys/include/arch/amd64/lapicvar.h b/sys/include/arch/amd64/lapicvar.h
deleted file mode 100644
index 84f73d2..0000000
--- a/sys/include/arch/amd64/lapicvar.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_LAPICVAR_H_
-#define _AMD64_LAPICVAR_H_
-
-#include <sys/cdefs.h>
-
-/* LAPIC register offsets */
-#define LAPIC_ID 0x0020U /* ID Register */
-#define LAPIC_VERSION 0x0030U /* Version Register */
-#define LAPIC_TPR 0x0080U /* Task Priority Register */
-#define LAPIC_APR 0x0090U /* Arbitration Priority Register */
-#define LAPIC_PPR 0x00A0U /* Processor Priority Register */
-#define LAPIC_EOI 0x00B0U /* End Of Interrupt Register */
-#define LAPIC_RRD 0x00C0U /* Remote Read Register */
-#define LAPIC_LDR 0x00D0U /* Logical Destination Register */
-#define LAPIC_DFR 0x00E0U /* Destination Format Register */
-#define LAPIC_SVR 0x00F0U /* Spurious Vector Register */
-#define LAPIC_ISR 0x0100U /* In service register (max=0x0220) */
-#define LAPIC_TMR 0x0180U /* Trigger Mode Register (max=0x0220) */
-#define LAPIC_IRR 0x0200U /* Interrupt Request Register (max=0x0270) */
-#define LAPIC_ERR 0x0280U /* Error Status Register */
-#define LAPIC_ICRLO 0x0300U /* Interrupt Command Low Register */
-#define LAPIC_ICRHI 0x0310U /* Interrupt Command High Register */
-#define LAPIC_LVT_TMR 0x0320U /* LVT Timer Register */
-#define LAPIC_DCR 0x03E0U /* Divide Configuration Register (for timer) */
-#define LAPIC_INIT_CNT 0x0380U /* Initial Count Register (for timer) */
-#define LAPIC_CUR_CNT 0x0390U /* Current Count Register (for timer) */
-
-#define IA32_APIC_BASE_MSR 0x1B
-
-/*
- * The x2APIC register space is accessed via
- * RDMSR/WRMSR instructions. The below defines
- * the base MSR address for the register space.
- */
-#define x2APIC_MSR_BASE 0x00000800
-
-/*
- * To hardware enable, OR the value
- * of the IA32_APIC_BASE MSR with
- * LAPIC_HW_ENABLE and rewrite it.
- *
- * To software enable, OR the value
- * of the SVR with LAPIC_SW_ENABLE
- * and rewrite it.
- *
- * LAPIC_SW_ENABLE has the low 8 bits set
- * as some hardware requires the spurious
- * vector to be hardwired to 1s so we'll
- * go with that to be safe.
- */
-#define LAPIC_HW_ENABLE __BIT(11)
-#define LAPIC_SW_ENABLE (__BIT(8) | 0xFF)
-#define x2APIC_ENABLE_SHIFT 10
-
-/*
- * The initial logical APIC ID to be set
- *
- * XXX: This value does *not* apply to processors
- * that support x2APIC mode. In x2APIC mode
- * the LDR register is readonly to system software.
- */
-#define LAPIC_STARTUP_LID 0x1
-
-/* LVT bits */
-#define LAPIC_LVT_MASK __BIT(16)
-#define LVT_TMR_ONESHOT 0x00
-#define LVT_TMR_PERIODIC 0x01
-#define LVT_TMR_TSC_DEADLINE 0x02
-
-/* LAPIC timer interrupt stack size in bytes */
-#define LAPIC_TMR_STACKSZ 4096
-
-#endif /* !_AMD64_LAPICVAR_H_ */
diff --git a/sys/include/arch/amd64/msr.h b/sys/include/arch/amd64/msr.h
deleted file mode 100644
index d36548b..0000000
--- a/sys/include/arch/amd64/msr.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_MSR_H_
-#define _AMD64_MSR_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-#define IA32_SPEC_CTL 0x00000048
-#define IA32_KERNEL_GS_BASE 0xC0000102
-
-static inline uint64_t
-rdmsr(uint32_t msr_addr)
-{
- uint32_t lo, hi;
-
- __ASMV("rdmsr"
- : "=a" (lo), "=d" (hi)
- : "c" (msr_addr)
- );
- return ((uint64_t)hi << 32) | lo;
-}
-
-static inline void
-wrmsr(uint32_t msr_addr, uint64_t value)
-{
- uint32_t lo, hi;
-
- lo = (uint32_t)value;
- hi = (uint32_t)(value >> 32);
-
- __ASMV("wrmsr"
- : /* No outputs */
- : "a" (lo), "d" (hi),
- "c" (msr_addr)
- );
-}
-
-#endif /* !_AMD64_MSR_H_ */
diff --git a/sys/include/arch/amd64/pcb.h b/sys/include/arch/amd64/pcb.h
deleted file mode 100644
index 0e0aab8..0000000
--- a/sys/include/arch/amd64/pcb.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_PCB_H_
-#define _AMD64_PCB_H_
-
-#include <sys/types.h>
-
-struct pcb {
- uint8_t *fpu_state;
-};
-
-#endif /* !_AMD64_PCB_H_ */
diff --git a/sys/include/arch/amd64/spectre.h b/sys/include/arch/amd64/spectre.h
deleted file mode 100644
index d12df21..0000000
--- a/sys/include/arch/amd64/spectre.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_SPECTRE_H_
-#define _AMD64_SPECTRE_H_
-
-#include <sys/cdefs.h>
-#include <sys/errno.h>
-
-__weak int try_spectre_mitigate(void);
-
-#endif
diff --git a/sys/include/arch/amd64/sysvec.h b/sys/include/arch/amd64/sysvec.h
deleted file mode 100644
index 99a84c0..0000000
--- a/sys/include/arch/amd64/sysvec.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_SYSVEC_H_
-#define _AMD64_SYSVEC_H_
-
-#include <sys/cdefs.h>
-
-/*
- * Interrupt vectors reserved
- * to core system usage excluding
- * device IRQs routed by 8259 PIC,
- * I/O APIC, etc.
- */
-typedef enum {
- SYSVEC_LAPIC_TIMER = 0x21, /* Local APIC timer */
- SYSVEC_IPI, /* IPI vector */
- SYSVEC_HLT, /* Halt vector */
- SYSVEC_PCKBD, /* Keyboard vector */
- SYSVEC_TLB, /* TLB shootdown */
-
- /* -- XXX: New vectors go above -- */
- NSYSVEC_BASE, /* Non-system vector base */
-} sysvec_t;
-
-/* Unlikely, but just in case */
-__STATIC_ASSERT(NSYSVEC_BASE <= 0xFF, "VECTOR OVERFLOW CAUGHT");
-
-#endif /* !_AMD64_SYSVEC_H_ */
diff --git a/sys/include/arch/amd64/tlb.h b/sys/include/arch/amd64/tlb.h
deleted file mode 100644
index c85e0e1..0000000
--- a/sys/include/arch/amd64/tlb.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _ASM_TLB_H_
-#define _ASM_TLB_H_
-
-#include <sys/cdefs.h>
-
-#define tlb_flush(va) \
- __ASMV("invlpg (%0)" \
- : \
- : "r" (va) \
- : "memory" \
- )
-
-#endif /* !_ASM_TLB_H_ */
diff --git a/sys/include/arch/amd64/trap.h b/sys/include/arch/amd64/trap.h
deleted file mode 100644
index c75fa28..0000000
--- a/sys/include/arch/amd64/trap.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_TRAP_H_
-#define _AMD64_TRAP_H_
-
-#if !defined(__ASSEMBLER__)
-#include <sys/types.h>
-#include <machine/frame.h>
-#endif /* !defined(__ASSEMBLER__) */
-
-#define TRAP_NONE 0 /* Used for general interrupts */
-#define TRAP_BREAKPOINT 1 /* Breakpoint */
-#define TRAP_ARITH_ERR 2 /* Arithmetic error (e.g division by 0) */
-#define TRAP_OVERFLOW 3 /* Overflow */
-#define TRAP_BOUND_RANGE 4 /* BOUND range exceeded */
-#define TRAP_INVLOP 5 /* Invalid opcode */
-#define TRAP_DOUBLE_FAULT 6 /* Double fault */
-#define TRAP_INVLTSS 7 /* Invalid TSS */
-#define TRAP_SEGNP 8 /* Segment not present */
-#define TRAP_PROTFLT 9 /* General protection */
-#define TRAP_PAGEFLT 10 /* Page fault */
-#define TRAP_NMI 11 /* Non-maskable interrupt */
-#define TRAP_SS 12 /* Stack-segment fault */
-
-/* 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 ss_fault(void *sf);
-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/arch/amd64/tss.h b/sys/include/arch/amd64/tss.h
deleted file mode 100644
index ca0ba57..0000000
--- a/sys/include/arch/amd64/tss.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_TSS_H_
-#define _AMD64_TSS_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-/*
- * cpu_info is from machine/cpu.h
- *
- * XXX: machine/cpu.h includes this header
- * so we must create this as including
- * machine/cpu.h will not do anything...
- */
-struct cpu_info;
-
-/*
- * A TSS entry (64-bit)
- *
- * See Intel SDM Section 8.2.1 - Task-State Segment (TSS)
- */
-struct __packed tss_entry {
- uint32_t reserved1;
- uint32_t rsp0_lo;
- uint32_t rsp0_hi;
- uint32_t rsp1_lo;
- uint32_t rsp1_hi;
- uint32_t rsp2_lo;
- uint32_t rsp2_hi;
- uint64_t reserved2;
- uint32_t ist1_lo;
- uint32_t ist1_hi;
- uint32_t ist2_lo;
- uint32_t ist2_hi;
- uint32_t ist3_lo;
- uint32_t ist3_hi;
- uint32_t ist4_lo;
- uint32_t ist4_hi;
- uint32_t ist5_lo;
- uint32_t ist5_hi;
- uint32_t ist6_lo;
- uint32_t ist6_hi;
- uint32_t ist7_lo;
- uint32_t ist7_hi;
- uint64_t reserved3;
- uint16_t reserved4;
- uint16_t io_base;
-};
-
-/*
- * TSS descriptor (64-bit)
- *
- * The TSS descriptor describes the location
- * of the TSS segments among other things...
- *
- * See Intel SDM Section 8.2.3 - TSS Descriptor in 64-bit mode
- */
-struct __packed tss_desc {
- uint16_t seglimit;
- uint16_t base_lo16;
- uint8_t base_mid8;
- uint8_t type : 4;
- uint8_t zero : 1;
- uint8_t dpl : 2;
- uint8_t p : 1;
- uint8_t seglimit_hi : 4;
- uint8_t avl : 1;
- uint8_t unused : 2;
- uint8_t g : 1;
- uint8_t base_hi_mid8;
- uint32_t base_hi32;
- uint32_t reserved;
-};
-
-/*
- * Holds the address of the address pointing
- * to the top of an interrupt stack.
- */
-union tss_stack {
- struct {
- uint32_t top_lo;
- uint32_t top_hi;
- };
- uint64_t top;
-};
-
-int tss_alloc_stack(union tss_stack *entry_out, size_t size);
-int tss_update_ist(struct cpu_info *ci, union tss_stack stack, uint8_t istno);
-void write_tss(struct cpu_info *cpu, struct tss_desc *desc);
-void tss_load(void); /* In tss.S */
-
-#endif /* _!_AMD64_TSS_H_ */
diff --git a/sys/include/arch/amd64/uart.h b/sys/include/arch/amd64/uart.h
deleted file mode 100644
index a49e626..0000000
--- a/sys/include/arch/amd64/uart.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/* UART 8250 init logic */
-
-#ifndef _UART_H_
-#define _UART_H_
-
-#include <sys/types.h>
-
-int uart8250_try_init(void);
-void uart8250_write(char byte);
-
-#endif
diff --git a/sys/include/arch/amd64/vas.h b/sys/include/arch/amd64/vas.h
deleted file mode 100644
index b8eef89..0000000
--- a/sys/include/arch/amd64/vas.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _AMD64_PMAP_H_
-#define _AMD64_PMAP_H_
-
-#include <sys/types.h>
-#include <sys/spinlock.h>
-
-/*
- * VAS structure - describes a virtual address space
- *
- * XXX: This structure shall exist per-process.
- *
- * TODO: As of now, VAS operations are *not* serialized!!!
- * This must change once Hyra becomes multi-threaded
- * or things will go wrong *very* quickly. Ensure of
- * this or you will suffer the consequences of undefined
- * behavior and you will not like it!
- */
-struct vas {
- size_t cr3_flags; /* CR3 flags */
- uintptr_t top_level; /* PML5 if `use_l5_paging' true, otherwise PML4 */
- bool use_l5_paging; /* True if 5-level paging is supported */
- struct spinlock lock;
-};
-
-#endif /* !_AMD64_PMAP_H_ */
diff --git a/sys/include/dev/ic/ahciregs.h b/sys/include/dev/ic/ahciregs.h
deleted file mode 100644
index b2da5b7..0000000
--- a/sys/include/dev/ic/ahciregs.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _AHCIREGS_H_
-#define _AHCIREGS_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-struct hba_port {
- volatile uint64_t clb; /* Command list base (1k-byte aligned) */
- volatile uint64_t fb; /* FIS base (256-byte aligned) */
- volatile uint32_t is; /* Interrupt status */
- volatile uint32_t ie; /* Interrupt enable */
- volatile uint32_t cmd; /* Command and status */
- volatile uint32_t rsvd0; /* Reserved */
- volatile uint32_t tfd; /* Task file data */
- volatile uint32_t sig; /* Signature */
- volatile uint32_t ssts; /* SATA status */
- volatile uint32_t sctl; /* SATA control */
- volatile uint32_t serr; /* SATA error */
- volatile uint32_t sact; /* SATA active */
- volatile uint32_t ci; /* Command issue */
- volatile uint32_t sntf; /* SATA notification */
- volatile uint32_t fbs; /* FIS-based switch control */
- volatile uint32_t rsvd1[11];
- volatile uint32_t vendor[4];
-};
-
-struct hba_memspace {
- volatile uint32_t cap; /* Host Capabilities */
- volatile uint32_t ghc; /* Global host control */
- volatile uint32_t is; /* Interrupt status */
- volatile uint32_t pi; /* Ports implemented */
- volatile uint32_t vs; /* Version */
- volatile uint32_t ccc_ctl; /* Command completion coalescing control */
- volatile uint32_t ccc_pts; /* Command completion coalescing ports */
- volatile uint32_t em_loc; /* Enclosure management location */
- volatile uint32_t em_ctl; /* Enclosure management control */
- volatile uint32_t cap2; /* Host capabilities extended */
- volatile uint32_t bohc; /* BIOS/OS Handoff Control and Status */
- volatile uint8_t rsvd[0x74]; /* Reserved */
- volatile uint8_t vendor[0x60]; /* Vendor specific */
- struct hba_port ports[1];
-};
-
-/* Global host control bits */
-#define AHCI_GHC_AE __BIT(31) /* AHCI enable */
-#define AHCI_GHC_IE __BIT(1) /* Interrupt enable */
-#define AHCI_GHC_HR __BIT(0) /* HBA reset */
-
-/* AHCI port signatures */
-#define AHCI_SIG_ATA 0x00000101
-#define AHCI_SIG_SEMB 0xC33C0101
-#define AHCI_SIG_PM 0x96690101
-
-/*
- * Port SATA status
- * See section 3.3.10 of the AHCI spec.
- */
-#define AHCI_PXSSTS_DET(SSTS) (SSTS & 0xF)
-#define AHCI_PXSSTS_IPM(SSTS) ((SSTS >> 8) & 0xF)
-
-/*
- * Port SATA control bits
- * See section 3.3.11 of the AHCI spec.
- */
-#define AHCI_PXSCTL_DET(SCTL) (SCTL & 0xF)
-
-/*
- * Port command and status bits
- * See section 3.3.7 of the AHCI spec.
- */
-#define AHCI_PXCMD_ST __BIT(0) /* Start */
-#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 */
-
-/*
- * Interrupt status bits
- * See section 3.3.5 of the AHCI spec.
- */
-#define AHCI_PXIS_TFES __BIT(31)
-
-/*
- * Task file data bits
- * See section 3.3.8 of the AHCI spec.
- */
-#define AHCI_PXTFD_ERR __BIT(0)
-#define AHCI_PXTFD_DRQ __BIT(3)
-#define AHCI_PXTFD_BSY __BIT(7)
-
-/*
- * Capability bits
- * See section 3.1.1 of the AHCI spec.
- */
-#define AHCI_CAP_NP(CAP) (CAP & 0x1F) /* Number of ports */
-#define AHCI_CAP_NCS(CAP) ((CAP >> 8) & 0x1F) /* Number of command slots */
-
-/*
- * Device detection (DET) and Interface power
- * management (IPM) values
- * See section 3.3.10 of the AHCI spec.
- */
-#define AHCI_DET_NULL 0 /* No device detected */
-#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
-
-/*
- * Device detection initialization values
- * See section 3.3.11 of the AHCI spec.
- */
-#define AHCI_DET_COMRESET 1
-
-#endif /* !_AHCIREGS_H_ */
diff --git a/sys/include/dev/ic/ahcivar.h b/sys/include/dev/ic/ahcivar.h
deleted file mode 100644
index edef4f6..0000000
--- a/sys/include/dev/ic/ahcivar.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _AHCIVAR_H_
-#define _AHCIVAR_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/mutex.h>
-#include <sys/queue.h>
-#include <dev/ic/ahciregs.h>
-
-struct ata_identity {
- uint16_t rsvd0 : 1;
- uint16_t unused0 : 1;
- uint16_t incomplete : 1;
- uint16_t unused1 : 3;
- uint16_t fixed_dev : 1;
- uint16_t removable : 1;
- uint16_t unused2 : 7;
- uint16_t device_type : 1;
- uint16_t ncylinders;
- uint16_t specific_config;
- uint16_t nheads;
- uint16_t unused3[2];
- uint16_t sectors_per_track;
- uint16_t vendor[3];
- char serial_number[20];
- uint16_t unused4[2];
- uint16_t unused5;
- char firmware_rev[8];
- char model_number[40];
- char pad[256];
-};
-
-/* Physical region descriptor table entry */
-struct ahci_prdt_entry {
- uintptr_t dba; /* Data base address */
- uint32_t rsvd0; /* Reserved */
- uint32_t dbc : 22; /* Count */
- uint16_t rsvd1 : 9; /* Reserved */
- uint8_t i : 1; /* Interrupt on completion */
-};
-
-/* Command header */
-struct ahci_cmd_hdr {
- uint8_t cfl : 5; /* Command FIS length */
- uint8_t a : 1; /* ATAPI */
- uint8_t w : 1; /* Write */
- uint8_t p : 1; /* Prefetchable */
- uint8_t r : 1; /* Reset */
- uint8_t c : 1; /* Clear busy upon R_OK */
- uint8_t rsvd0 : 1; /* Reserved */
- uint8_t pmp : 4; /* Port multiplier port */
- uint16_t prdtl; /* PRDT length (in entries) */
- volatile uint32_t prdbc; /* PRDT bytes transferred count */
- uintptr_t ctba; /* Command table descriptor base addr */
- uint32_t rsvd1[4]; /* Reserved */
-};
-
-/* Command table */
-struct ahci_cmdtab {
- uint8_t cfis[64];
- uint8_t acmd[16];
- uint8_t rsvd[48];
- struct ahci_prdt_entry prdt[1];
-};
-
-struct ahci_fis_h2d {
- uint8_t type;
- uint8_t pmp : 4;
- uint8_t rsvd0 : 3;
- uint8_t c : 1;
- uint8_t command;
- uint8_t featurel;
- uint8_t lba0;
- uint8_t lba1;
- uint8_t lba2;
- uint8_t device;
- uint8_t lba3;
- uint8_t lba4;
- uint8_t lba5;
- uint8_t featureh;
- uint8_t countl;
- uint8_t counth;
- uint8_t icc;
- uint8_t control;
- uint8_t rsvd1[4];
-};
-
-struct ahci_device {
- struct ahci_hba *hba;
- struct hba_port *port;
- dev_t minor;
- TAILQ_ENTRY(ahci_device) link;
-};
-
-struct ahci_hba {
- struct hba_memspace *abar;
- struct ahci_cmd_hdr *cmdlist;
- uint32_t ncmdslots;
- uint32_t nports;
-};
-
-/* Commands */
-#define ATA_CMD_NOP 0x00
-#define ATA_CMD_IDENTIFY 0xEC
-#define ATA_CMD_READ_DMA 0x25
-#define ATA_CMD_WRITE_DMA 0x35
-
-/* FIS types */
-#define FIS_TYPE_H2D 0x27
-#define FIS_TYPE_D2H 0x34
-
-#define AHCI_TIMEOUT 500
-#define AHCI_FIS_SIZE 256
-#define AHCI_CMDTAB_SIZE 256
-#define AHCI_CMDENTRY_SIZE 32
-
-#endif /* !_AHCIVAR_H_ */
diff --git a/sys/include/dev/ic/nvmevar.h b/sys/include/dev/ic/nvmevar.h
deleted file mode 100644
index 4a40071..0000000
--- a/sys/include/dev/ic/nvmevar.h
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _IC_NVMEVAR_H_
-#define _IC_NVMEVAR_H_
-
-#include <sys/cdefs.h>
-
-/* Admin commands */
-#define NVME_OP_CREATE_IOSQ 0x01
-#define NVME_OP_CREATE_IOCQ 0x05
-#define NVME_OP_IDENTIFY 0x06
-
-/* I/O commands */
-#define NVME_OP_WRITE 0x01
-#define NVME_OP_READ 0x02
-
-/* Controller Capabilities */
-#define CAP_MPSMIN(caps) ((caps >> 48) & 0xF)
-#define CAP_MPSMAX(caps) ((caps >> 52) & 0xF)
-#define CAP_TIMEOUT(caps) ((caps >> 24) & 0xFF)
-#define CAP_STRIDE(caps) ((caps >> 32) & 0xF)
-#define CAP_MQES(caps) (caps & 0xFFFF)
-#define CAP_CSS(caps) (caps & 0xFF)
-
-/* Controller Configuration */
-#define CONFIG_EN __BIT(0)
-#define CONFIG_CSS_SHIFT 4
-#define CONFIG_IOSQES_SHIFT 16
-#define CONFIG_IOCQES_SHIFT 20
-
-#define COMMAND_SIZE 64 /* In bytes (defined by spec) */
-#define STATUS_READY(status) (status & 1)
-
-struct nvme_common_cmd {
- uint8_t opcode;
- uint8_t flags;
- uint16_t cid;
- uint32_t nsid;
- uint32_t cdw1[2];
- uint64_t metadata;
- uint64_t prp1;
- uint64_t prp2;
- uint32_t cdw2[6];
-};
-
-struct nvme_identify_cmd {
- uint8_t opcode;
- uint8_t flags;
- uint16_t cid;
- uint32_t nsid;
- uint64_t unused1;
- uint64_t unused2;
- uint64_t prp1;
- uint64_t prp2;
- uint32_t cns;
- uint32_t unused3[5];
-};
-
-/* Read/write */
-struct nvme_rw_cmd {
- uint8_t opcode;
- uint8_t flags;
- uint16_t cid;
- uint32_t nsid;
- uint64_t unused;
- uint64_t metadata;
- uint64_t prp1;
- uint64_t prp2;
- uint64_t slba;
- uint16_t len;
- uint16_t control;
- uint32_t dsmgmt;
- uint32_t ref;
- uint16_t apptag;
- uint16_t appmask;
-};
-
-/* Create I/O completion queue */
-struct nvme_create_iocq_cmd {
- uint8_t opcode;
- uint8_t flags;
- uint16_t cid;
- uint32_t unused1[5];
- uint64_t prp1;
- uint64_t unused2;
- uint16_t qid;
- uint16_t qsize;
- uint16_t qflags;
- uint16_t irqvec;
- uint64_t unused3[2];
-};
-
-struct nvme_create_iosq_cmd {
- uint8_t opcode;
- uint8_t flags;
- uint16_t cid;
- uint32_t unused1[5];
- uint64_t prp1;
- uint64_t unused2;
- uint16_t sqid;
- uint16_t qsize;
- uint16_t qflags;
- uint16_t cqid;
- uint64_t unused3[2];
-};
-
-struct nvme_cmd {
- union {
- struct nvme_identify_cmd identify;
- struct nvme_common_cmd common;
- struct nvme_create_iocq_cmd create_iocq;
- struct nvme_create_iosq_cmd create_iosq;
- struct nvme_rw_cmd rw;
- };
-};
-
-struct nvme_id {
- uint16_t vid;
- uint16_t ssvid;
- char sn[20];
- char mn[40];
- char fr[8];
- uint8_t rab;
- uint8_t ieee[3];
- uint8_t mic;
- uint8_t mdts;
- uint16_t ctrlid;
- uint32_t version;
- uint32_t unused1[43];
- uint16_t oacs;
- uint8_t acl;
- uint8_t aerl;
- uint8_t fw;
- uint8_t lpa;
- uint8_t elpe;
- uint8_t npss;
- uint8_t avscc;
- uint8_t apsta;
- uint16_t wctemp;
- uint16_t cctemp;
- uint16_t unused2[121];
- uint8_t sqes;
- uint8_t cqes;
- uint16_t unused3;
- uint32_t nn;
- uint16_t oncs;
- uint16_t fuses;
- uint8_t fna;
- uint8_t vwc;
- uint16_t awun;
- uint16_t awupf;
- uint8_t nvscc;
- uint8_t unused4;
- uint16_t acwu;
- uint16_t unused5;
- uint32_t sgls;
- uint32_t unused6[1401];
- uint8_t vs[1024];
-};
-
-/* Command completion queue entry */
-struct nvme_cq_entry {
- uint32_t res;
- uint32_t unused;
- uint16_t sqhead;
- uint16_t sqid;
- uint16_t cid;
- uint16_t status;
-};
-
-/* NVMe controller */
-struct __packed nvme_bar {
- uint64_t caps;
- uint32_t version;
- uint32_t intms; /* Interrupt mask set */
- uint32_t intmc; /* Interrupt mask clear */
- uint32_t config;
- uint32_t unused1;
- uint32_t status;
- uint32_t unused2;
- uint32_t aqa; /* Admin queue attributes */
- uint64_t asq; /* Admin submission queue */
- uint64_t acq; /* Admin completion queue */
-};
-
-struct nvme_lbaf {
- uint16_t ms; /* Number of metadata bytes per LBA */
- uint8_t ds; /* Data size */
- uint8_t rp;
-};
-
-/* Identify namespace data */
-struct nvme_id_ns {
- uint64_t size;
- uint64_t capabilities;
- uint64_t nuse;
- uint8_t features;
- uint8_t nlbaf;
- uint8_t flbas;
- uint8_t mc;
- uint8_t dpc;
- uint8_t dps;
- uint8_t nmic;
- uint8_t rescap;
- uint8_t fpi;
- uint8_t unused1;
- uint16_t nawun;
- uint16_t nawupf;
- uint16_t nacwu;
- uint16_t nabsn;
- uint16_t nabo;
- uint16_t nabspf;
- uint16_t unused2;
- uint64_t nvmcap[2];
- uint64_t unusued3[5];
- uint8_t nguid[16];
- uint8_t eui64[8];
- struct nvme_lbaf lbaf[16];
- uint64_t unused3[24];
- uint8_t vs[3712];
-};
-
-struct nvme_queue {
- struct nvme_cmd *sq; /* Submission queue */
- struct nvme_cq_entry *cq; /* Completion queue */
- uint16_t sq_head; /* Submission queue head */
- uint16_t sq_tail; /* Submission queue tail */
- uint16_t cq_head; /* Completion queue head */
- uint8_t cq_phase : 1; /* Completion queue phase bit */
- uint16_t size; /* Size in elements */
- volatile uint32_t *sq_db; /* Submission doorbell */
- volatile uint32_t *cq_db; /* Completion doorbell */
-};
-
-struct nvme_state {
- struct nvme_queue adminq;
- struct nvme_bar *bar;
- dev_t major;
-};
-
-/* NVMe namespace */
-struct nvme_ns {
- size_t nsid; /* Namespace ID */
- size_t lba_bsize; /* LBA block size */
- size_t size; /* Size in logical blocks */
- struct nvme_queue ioq; /* I/O queue */
- struct nvme_lbaf lba_fmt; /* LBA format */
- struct nvme_state *cntl; /* NVMe controller */
- dev_t dev_id;
- TAILQ_ENTRY(nvme_ns) link;
-};
-
-#endif
diff --git a/sys/include/dev/pci/pci.h b/sys/include/dev/pci/pci.h
deleted file mode 100644
index d6edf3b..0000000
--- a/sys/include/dev/pci/pci.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _DEV_PCI_H_
-#define _DEV_PCI_H_
-
-#include <sys/syscall.h>
-#include <sys/queue.h>
-#include <sys/cdefs.h>
-#include <dev/pci/pciregs.h>
-#include <vm/vm.h>
-
-/* Lookup bits */
-#define PCI_DEVICE_ID __BIT(0)
-#define PCI_VENDOR_ID __BIT(1)
-#define PCI_CLASS __BIT(2)
-#define PCI_SUBCLASS __BIT(3)
-
-/* Base address masks for BARs */
-#define PCI_BAR_MEMMASK ~7
-#define PCI_BAR_IOMASK ~3
-
-/* Macros to fetch base address from BAR */
-#define PCI_BAR_MEMBASE(BAR) PHYS_TO_VIRT(BAR & PCI_BAR_MEMMASK)
-#define PCI_BAR_IOBASE(BAR) PHYS_TO_VIRT(BAR & PCI_BAR_IOMASK)
-
-/* For PCI lookups */
-struct pci_lookup {
- uint16_t device_id;
- uint16_t vendor_id;
- uint8_t pci_class;
- uint8_t pci_subclass;
-};
-
-struct pci_device {
- uint8_t bus;
- uint8_t slot;
- uint8_t func;
-
- uint16_t device_id;
- uint16_t vendor_id;
- uint8_t pci_class;
- uint8_t pci_subclass;
- uint8_t prog_if;
- uintptr_t bar[6];
- uint8_t irq_line;
- TAILQ_ENTRY(pci_device) link;
-};
-
-int pci_init(void);
-uint32_t pci_readl(struct pci_device *dev, uint32_t offset);
-uint32_t pci_bar_size(struct pci_device *dev, uint8_t bar);
-void pci_writel(struct pci_device *dev, uint32_t offset, uint32_t val);
-void pci_set_cmdreg(struct pci_device *dev, uint16_t bits);
-struct pci_device *pci_get_device(struct pci_lookup lookup, uint16_t lookup_type);
-
-#endif /* !_DEV_PCI_H_ */
diff --git a/sys/include/dev/pci/pciregs.h b/sys/include/dev/pci/pciregs.h
deleted file mode 100644
index 13a9fc0..0000000
--- a/sys/include/dev/pci/pciregs.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _PCIREGS_H_
-#define _PCIREGS_H_
-
-#include <sys/cdefs.h>
-
-#define PCIREG_VENDOR_ID 0x00 /* 16 bits */
-#define PCIREG_DEVICE_ID 0x02 /* 16 bits */
-#define PCIREG_CLASSREV 0x08 /* 32 bits */
-#define PCIREG_BAR0 0x10 /* 32 bits */
-#define PCIREG_BAR1 0x14 /* 32 bits */
-#define PCIREG_BAR2 0x18 /* 32 bits */
-#define PCIREG_BAR3 0x1C /* 32 bits */
-#define PCIREG_BAR4 0x20 /* 32 bits */
-#define PCIREG_BAR5 0x24 /* 32 bits */
-#define PCIREG_IRQLINE 0x3C /* 8 bits */
-#define PCIREG_CMDSTATUS 0x04 /* command (15:0), status (31:16) */
-
-/* Macros to extract PCIREG_CLASSREV bits */
-#define PCIREG_CLASS(CLASSREV) (CLASSREV >> 24)
-#define PCIREG_SUBCLASS(CLASSREV) ((CLASSREV >> 16) & 0xFF)
-#define PCIREG_REVID(CLASSREV) (CLASSREV & 0xFF)
-#define PCIREG_PROGIF(CLASSREV) ((CLASSREV >> 8) & 0xFF)
-
-/* Macros to extract PCIREG_CMDSTATUS bits */
-#define PCIREG_COMMAND(CMDSTATUS) (CMDSTATUS & 0xFFFF)
-#define PCIREG_STATUS(CMDSTATUS) (CMDSTATUS >> 16)
-
-/* PCI command register bits */
-#define PCI_IO_SPACE __BIT(0) /* Respond to I/O space accesses */
-#define PCI_MEM_SPACE __BIT(1) /* Respond to mem space accesses */
-#define PCI_BUS_MASTERING __BIT(2) /* Enable bus mastering */
-
-/* PCI status register bits */
-#define PCI_STATUS_CAPLIST __BIT(4)
-#define PCI_STATUS_66MHZ __BIT(5)
-
-#endif /* !_PCIREGS_H_ */
diff --git a/sys/include/dev/pci/pcivar.h b/sys/include/dev/pci/pcivar.h
deleted file mode 100644
index ba45a53..0000000
--- a/sys/include/dev/pci/pcivar.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _DEV_PCIVAR_H_
-#define _DEV_PCIVAR_H_
-
-#include <sys/types.h>
-
-enum {
- PCI_ACCESS_CAM,
- PCI_ACCESS_ECAM
-};
-
-#endif /* !_DEV_PCIVAR_H_ */
diff --git a/sys/include/dev/usb/xhciregs.h b/sys/include/dev/usb/xhciregs.h
deleted file mode 100644
index 0b07524..0000000
--- a/sys/include/dev/usb/xhciregs.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _USB_XHCIREGS_H_
-#define _USB_XHCIREGS_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-/*
- * Host Controller Capability Registers
- *
- * See xHCI spec, section 5.3, table 5-9
- */
-struct __packed xhci_caps {
- volatile uint8_t caplength;
- volatile uint8_t reserved;
- volatile uint16_t hciversion;
- volatile uint32_t hcsparams1;
- volatile uint32_t hcsparams2;
- volatile uint32_t hcsparams3;
- volatile uint32_t hccparams1;
- volatile uint32_t dboff;
- volatile uint32_t rtsoff;
- volatile uint32_t hccparams2;
-};
-
-/*
- * Host Controller Operational Registers
- *
- * See xHCI spec, section 5.4, table 5-18
- */
-struct __packed xhci_opregs {
- volatile uint32_t usbcmd;
- volatile uint32_t usbsts;
- volatile uint32_t pagesize;
- volatile uint32_t reserved;
- volatile uint32_t reserved1;
- volatile uint32_t dnctrl;
- volatile uint64_t cmd_ring;
- volatile uint32_t reserved2[4];
- volatile uint64_t dcbaa_ptr;
- volatile uint32_t config;
-};
-
-/* USBCMD bits */
-#define USBCMD_RUN __BIT(0) /* Run/stop */
-#define USBCMD_HCRST __BIT(1) /* xHC reset */
-
-/* USBSTS bits */
-#define USBSTS_HCH __BIT(0) /* HC halted */
-
-/* CAPS.HCSPARAMS1 fields */
-#define XHCI_MAXSLOTS(HCSPARAMS1) (HCSPARAMS1 & 0xFF)
-#define XHCI_MAXPORTS(HCSPARAMS1) ((HCSPARAMS1 >> 24) & 0xFF)
-#define XHCI_ECP(HCCPARAMS1) ((HCCPARAMS1 >> 16) & 0xFFFF)
-
-/* CAPS.HCSPARAMS2 fields */
-#define XHCI_MAX_SP_HI(HCSPARAMS2) ((HCSPARAMS2 >> 25) & 0x1F)
-#define XHCI_MAX_SP_LO(HCSPARAMS2) ((HCSPARAMS2 >> 31) & 0x1F)
-
-/* PORTSC bits */
-#define XHCI_PORTSC_CCS __BIT(0) /* Current connect status */
-#define XHCI_PORTSC_PR __BIT(4) /* Port reset */
-
-/* Registers */
-#define XHCI_BASE_OFF(BASE, OFF) (void *)((uintptr_t)BASE + OFF)
-#define XHCI_CAPS(BASE) XHCI_BASE_OFF(BASE, 0)
-#define XHCI_OPBASE(BASE, CAP_LEN) XHCI_BASE_OFF(BASE, CAP_LEN)
-#define XHCI_RTS(BASE, RTSOFF) XHCI_BASE_OFF(BASE, RTSOFF)
-#define XHCI_CMD_DB(BASE, DBOFF) XHCI_BASE_OFF(BASE, DBOFF)
-
-/* Support protocol cap fields */
-#define XHCI_PROTO_ID(PROTO) (PROTO & 0xFF)
-#define XHCI_PROTO_MINOR(PROTO) ((PROTO >> 16) & 0xFF)
-#define XHCI_PROTO_MAJOR(PROTO) ((PROTO >> 24) & 0xFF)
-#define XHCI_PROTO_NEXT(PROTO) ((PROTO >> 8) & 0xFF)
-#define XHCI_PROTO_PORTOFF(PROTO2) (PROTO2 & 0xFF)
-#define XHCI_PROTO_PORTCNT(PROTO2) ((PROTO2 >> 8) & 0xFF)
-
-/* Extended cap IDs */
-#define XHCI_ECAP_PROTO 2
-
-#endif /* !_USB_XHCIREGS_H_ */
diff --git a/sys/include/dev/usb/xhcivar.h b/sys/include/dev/usb/xhcivar.h
deleted file mode 100644
index 71c1f20..0000000
--- a/sys/include/dev/usb/xhcivar.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _USB_XHCIVAR_H_
-#define _USB_XHCIVAR_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <dev/usb/xhciregs.h>
-
-#define XHCI_TIMEOUT 500 /* In ms */
-#define XHCI_CMDRING_LEN 16
-#define XHCI_EVRING_LEN 16
-#define XHCI_TRB_SIZE 16 /* In bytes */
-#define XHCI_EVENTRING_LEN XHCI_CMDRING_LEN
-#define XHCI_MAX_PROTOS 4
-
-struct xhci_nop_trb {
- uint32_t reserved;
- uint32_t reserved1;
- uint32_t reserved2;
- uint8_t cycle : 1;
- uint16_t reserved3 : 9;
- uint8_t type : 6;
- uint16_t reserved4;
-};
-
-/*
- * xHCI Transfer Request Block
- */
-struct xhci_trb {
- union {
- struct xhci_nop_trb nop;
- struct {
- uint32_t dword0;
- uint32_t dword1;
- uint32_t dword2;
- uint32_t dword3;
- };
- };
-};
-
-/*
- * USB proto (USB 2.0 or 3.0)
- */
-struct xhci_proto {
- uint8_t major; /* Revision major */
- uint8_t port_start; /* Port offset start */
- uint8_t port_count; /* Number of ports */
-};
-
-/*
- * xHCI event ring segment
- *
- * See xHCI spec, section 6.5, table 6-40
- */
-struct __packed xhci_evring_segment {
- uint64_t base;
- uint32_t size;
- uint32_t reserved;
-};
-
-/*
- * Host controller.
- */
-struct xhci_hc {
- void *base;
- uint8_t caplen;
- uint8_t maxslots;
- size_t maxports;
- size_t protocnt;
- uintptr_t *dcbaap;
- uint8_t cycle : 1;
- uint16_t cmd_ptr; /* Command ring index */
- uint16_t cmd_count; /* Command ring entry count */
- uint32_t *cmd_ring;
- uint32_t *event_ring;
- struct xhci_opregs *opregs;
- struct xhci_proto protos[XHCI_MAX_PROTOS];
- struct xhci_evring_segment *evring_seg;
-};
-
-/* TRB types */
-#define XHCI_ENABLE_SLOT 9
-#define XHCI_LINK 6
-
-#endif /* !_USB_XHCIVAR_H_ */
diff --git a/sys/include/dev/vcons/vcons.h b/sys/include/dev/vcons/vcons.h
deleted file mode 100644
index 492940f..0000000
--- a/sys/include/dev/vcons/vcons.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _DEV_VCONS_H_
-#define _DEV_VCONS_H_
-
-#include <sys/types.h>
-#include <sys/termios.h>
-#include <dev/video/fbdev.h>
-#include <sysfont.h>
-
-#define VCONS_TAB_WIDTH 4
-#define VCONS_CURSOR_WIDTH FONT_WIDTH
-#define VCONS_CURSOR_HEIGHT FONT_HEIGHT
-
-struct vcons_cursor {
- size_t xpos, ypos;
- uint32_t rgb;
-
- /* Internal */
- uint32_t old_xpos, old_ypos;
- volatile bool is_drawing;
- volatile bool is_drawn; /* If it has been drawn before */
-};
-
-struct vcons_screen {
- size_t nrows, ncols;
- size_t cpy_x, cpy_y; /* In chars */
- size_t cpy_len;
-
- uint32_t bg;
- uint32_t fg;
- void *fbdev_mem;
-
- struct fbdev fbdev;
- struct vcons_cursor cursor;
-};
-
-#define is_cursor_drawing(screenptr) (screenptr)->cursor.is_drawing
-
-void vcons_attach(struct vcons_screen *scr);
-int vcons_putch(struct vcons_screen *scr, char c);
-int vcons_putstr(struct vcons_screen *scr, const char *s, size_t len);
-void vcons_update_cursor(struct vcons_screen *scr);
-
-#endif /* !_DEV_VCONS_H_ */
diff --git a/sys/include/dev/vcons/vcons_io.h b/sys/include/dev/vcons/vcons_io.h
deleted file mode 100644
index a75d811..0000000
--- a/sys/include/dev/vcons/vcons_io.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _VCONS_IO_H_
-#define _VCONS_IO_H_
-
-#include <dev/vcons/vcons.h>
-
-int vcons_process_output(struct vcons_screen *scr, int c);
-
-#endif /* !_VCONS_IO_H_ */
diff --git a/sys/include/dev/video/fbdev.h b/sys/include/dev/video/fbdev.h
deleted file mode 100644
index 5ad6bf6..0000000
--- a/sys/include/dev/video/fbdev.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _FBDEV_H_
-#define _FBDEV_H_
-
-#include <sys/types.h>
-#include <sys/fbdev.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/firmware/acpi/acpi.h b/sys/include/firmware/acpi/acpi.h
deleted file mode 100644
index 66a955f..0000000
--- a/sys/include/firmware/acpi/acpi.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _ACPI_ACPI_H_
-#define _ACPI_ACPI_H_
-
-#include <firmware/acpi/tables.h>
-#include <machine/cpu.h>
-#include <sys/types.h>
-
-void acpi_init(void);
-uint32_t irq_to_gsi(uint8_t irq);
-void *acpi_query(const char *query);
-bool acpi_is_checksum_valid(struct acpi_header *hdr);
-struct acpi_root_sdt *acpi_get_root_sdt(void);
-size_t acpi_get_root_sdt_len(void);
-void acpi_parse_madt(struct cpu_info *ci);
-void *acpi_get_lapic_base(void);
-
-#endif /* !_ACPI_ACPI_H_ */
diff --git a/sys/include/firmware/acpi/tables.h b/sys/include/firmware/acpi/tables.h
deleted file mode 100644
index 32fef09..0000000
--- a/sys/include/firmware/acpi/tables.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _ACPI_TABLES_H_
-#define _ACPI_TABLES_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-
-#define OEMID_SIZE 6
-
-struct __packed acpi_header {
- char signature[4]; /* ASCII signature string */
- uint32_t length; /* Length of table in bytes */
- uint8_t revision; /* Revision of the structure */
- uint8_t checksum; /* Checksum of the header */
- char oemid[OEMID_SIZE]; /* OEM-supplied string that IDs the OEM */
- char oem_table_id[8]; /* OEM-supplied string (used by OEM) */
- uint32_t oem_revision; /* OEM-supplied revision number */
- uint32_t creator_id; /* Vendor ID of creator utility */
- uint32_t creator_revision; /* Revision of creator utility */
-};
-
-struct __packed acpi_rsdp {
- uint64_t signature; /* RSD PTR */
- uint8_t checksum; /* Structure checksum */
- char oemid[OEMID_SIZE]; /* OEM-supplied string that IDs the OEM */
- uint8_t revision; /* Revision of the structure */
- uint32_t rsdt_addr; /* RSDT physical address */
-
- /* Reserved if revision < 2 */
- uint32_t length; /* Length of table in bytes */
- uint64_t xsdt_addr; /* XSDT physical address */
- uint8_t ext_checksum; /* Extended checksum */
- uint8_t reserved[3];
-};
-
-/*
- * XSDT or RSDT depending
- * on what revision the header
- * says.
- */
-struct __packed acpi_root_sdt {
- struct acpi_header hdr;
- uint32_t tables[];
-};
-
-struct __packed acpi_madt {
- struct acpi_header hdr;
- uint32_t lapic_addr;
- uint32_t flags;
-};
-
-struct __packed apic_header {
- uint8_t type;
- uint8_t length;
-};
-
-struct __packed local_apic {
- struct apic_header hdr;
- uint8_t processor_id;
- uint8_t apic_id;
- uint32_t flags;
-};
-
-struct __packed ioapic {
- struct apic_header hdr;
- uint8_t ioapic_id;
- uint8_t reserved;
- uint32_t ioapic_addr;
- uint32_t gsi_base;
-};
-
-struct __packed interrupt_override {
- struct apic_header hdr;
- uint8_t bus;
- uint8_t source; /* IRQ */
- uint32_t interrupt; /* GSI */
- uint16_t flags;
-};
-
-struct __packed acpi_gas {
- uint8_t address_space_id;
- uint8_t register_bit_width;
- uint8_t register_bit_offset;
- uint8_t reserved;
- uint64_t address;
-};
-
-struct __packed hpet {
- struct acpi_header hdr;
- uint8_t hardware_rev_id;
- uint8_t comparator_count : 5;
- uint8_t counter_size : 1;
- uint8_t reserved : 1;
- uint8_t legacy_replacement : 1;
- uint16_t pci_vendor_id;
- struct acpi_gas gas;
- uint8_t hpet_number;
- uint16_t minimum_tick;
- uint8_t page_protection;
-};
-
-#endif /* !_ACPI_TABLES_H_ */
diff --git a/sys/include/fs/devfs.h b/sys/include/fs/devfs.h
deleted file mode 100644
index 66128ef..0000000
--- a/sys/include/fs/devfs.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_DEVFS_H_
-#define _FS_DEVFS_H_
-
-#include <sys/vnode.h>
-#include <sys/device.h>
-
-extern struct vfsops g_devfs_ops;
-extern struct vops g_devfs_vops;
-
-int devfs_add_dev(const char *name, const struct device *dev);
-int devfs_get_dev(struct vnode *vp, struct device **res);
-
-#endif
diff --git a/sys/include/fs/initramfs.h b/sys/include/fs/initramfs.h
deleted file mode 100644
index 223e962..0000000
--- a/sys/include/fs/initramfs.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_INITRAMFS_H_
-#define _FS_INITRAMFS_H_
-
-#include <sys/mount.h>
-#include <sys/vnode.h>
-
-extern struct vfsops g_initramfs_ops;
-extern struct vops g_initramfs_vops;
-
-const char *initramfs_open(const char *path);
-
-#endif /* !_FS_INITRAMFS_H_ */
diff --git a/sys/include/fs/procfs.h b/sys/include/fs/procfs.h
deleted file mode 100644
index ed3a19f..0000000
--- a/sys/include/fs/procfs.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _PROCFS_H_
-#define _PROCFS_H_
-
-#include <sys/types.h>
-#include <sys/mount.h>
-#include <sys/sio.h>
-
-struct proc_entry {
- int(*read)(struct proc_entry *p, struct sio_txn *sio);
- int(*write)(struct proc_entry *p, struct sio_txn *sio);
-};
-
-extern struct vfsops g_procfs_ops;
-extern struct vops g_procfs_vops;
-
-int procfs_add_entry(const char *name, struct proc_entry *entry);
-struct proc_entry *procfs_alloc_entry(void);
-
-/* procfs_subr.c */
-void procfs_populate(void);
-
-#endif /* !_PROCFS_H_ */
diff --git a/sys/include/lib/assert.h b/sys/include/lib/assert.h
deleted file mode 100644
index 78ebe05..0000000
--- a/sys/include/lib/assert.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_ASSERT_H_
-#define _LIB_ASSERT_H_
-
-#include <sys/panic.h>
-#include <sys/types.h>
-
-#define __assert(condition) \
- if ((uintptr_t)(condition) == 0) { \
- panic("Assert \"%s\" failed (%s() at %s:%d)\n", #condition, \
- __func__, __FILE__, __LINE__); \
- }
-
-#endif /* !_LIB_ASSERT_H_ */
diff --git a/sys/include/lib/bitmap.h b/sys/include/lib/bitmap.h
deleted file mode 100644
index da900a2..0000000
--- a/sys/include/lib/bitmap.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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
deleted file mode 100644
index c33d3d2..0000000
--- a/sys/include/lib/logo.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/syslog.h>
-
-#define COPYRIGHT "Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team."
-
-#define PRINT_LOGO() \
- kprintf(OMIT_TIMESTAMP "%s v%s\n\n", g_logo, HYRA_VERSION); \
- kprintf(OMIT_TIMESTAMP "\t%s\n\n", COPYRIGHT);
-
-extern uint8_t g_logo[];
diff --git a/sys/include/lib/stdarg.h b/sys/include/lib/stdarg.h
deleted file mode 100644
index 5a3d67d..0000000
--- a/sys/include/lib/stdarg.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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
deleted file mode 100644
index f4ee93d..0000000
--- a/sys/include/lib/string.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_STRING_H_
-#define _LIB_STRING_H_
-
-#include <sys/types.h>
-#include <stdarg.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);
-void *memset64(void *s, int c, size_t n);
-int memcmp(const void *s1, const void *s2, size_t n);
-int strcmp(const char *s1, const char *s2);
-int vsnprintf(char *s, size_t size, const char *fmt, va_list ap);
-int snprintf(char *s, size_t size, const char *fmt, ...);
-
-#endif /* !_LIB_STRING_H_ */
diff --git a/sys/include/lib/sysfont.h b/sys/include/lib/sysfont.h
deleted file mode 100644
index 62b4ec0..0000000
--- a/sys/include/lib/sysfont.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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
deleted file mode 100644
index 2421c8c..0000000
--- a/sys/include/sys/ascii.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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
deleted file mode 100644
index 110205b..0000000
--- a/sys/include/sys/cdefs.h
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_CDEFS_H_
-#define _SYS_CDEFS_H_
-
-#if !defined(__ASSEMBLER__)
-
-/* Misc helpers */
-#define __attr(x) __attribute__((x))
-#define __weak __attr(weak)
-#define __used __attr(used)
-#define __naked __attr(naked)
-#define __noreturn __attr(noreturn)
-
-#define __likely(x) __builtin_expect(!!(x), 1)
-#define __unlikely(x) __builtin_expect(!!(x), 0)
-
-/* Wrapper for inline asm */
-#define __ASMV __asm__ __volatile__
-
-/* 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)
-
-/*
- * Memory barrier, ensure compiler doesn't reorder
- * memory accesses.
- */
-#define __mem_barrier() __ASMV("" ::: "memory")
-
-/*
- * 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)
-
-/* __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))
-
-/* A cleaner wrapper over _Static_assert() */
-#define __STATIC_ASSERT _Static_assert
-
-/* Computes 2^x i.e 2 to the power of 'x' */
-#define __POW2(x) (1ULL << x)
-
-/* Combine two 8-bit values into a 16-bit value */
-#define __COMBINE8(HI, LO) ((uint16_t)((uint16_t)HI << 8) | LO)
-
-/* Combine two 16-bit values into a 32-bit value */
-#define __COMBINE16(HI, LO) ((uint32_t)((uint32_t)HI << 16) | LO)
-
-/* Combine two 32-bit values into a 64-bit value */
-#define __COMBINE32(HI, LO) ((uint64_t)((uint64_t)HI << 32) | LO)
-
-/*
- * Used to give metadata to
- * a specific module. Example
- * metadata string:
- *
- * $Hyra$: 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("$Hyra$: 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
-
-/*
- * Attempts to call a __weak function. Does nothing
- * if routine not implemented.
- */
-#define __TRY_CALL(routine, ...) \
- if (routine != NULL) routine(__VA_ARGS__)
-
-#else
-
-/*
- * XXX: Will work; however, maybe move this??
- */
-#if defined(__x86_64__)
-.macro __KERNEL_META meta_str
- .section .meta.note
- .align 4
- .string "\meta_str"
- .previous
-.endm
-#endif /* defined(__x86_64__) */
-
-#endif /* !defined(__ASSEMBLER__) */
-#endif /* !_SYS_CDEFS_H_ */
diff --git a/sys/include/sys/cpu.h b/sys/include/sys/cpu.h
deleted file mode 100644
index f22cba4..0000000
--- a/sys/include/sys/cpu.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_CPU_H_
-#define _SYS_CPU_H_
-
-#include <machine/cpu.h>
-
-#define cpu_index(ci) ci->idx
-
-size_t cpu_count(void);
-void cpu_attach(struct cpu_info *ci);
-struct cpu_info *cpu_get(size_t i);
-
-#endif /* !_SYS_CPU_H_ */
diff --git a/sys/include/sys/device.h b/sys/include/sys/device.h
deleted file mode 100644
index 1bca4a8..0000000
--- a/sys/include/sys/device.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_DEVICE_H_
-#define _SYS_DEVICE_H_
-
-#include <sys/sio.h>
-#include <sys/queue.h>
-#include <sys/types.h>
-#include <string.h>
-#include <vm/dynalloc.h>
-
-struct device {
- dev_t major, minor;
- size_t blocksize;
- int(*write)(struct device *dev, struct sio_txn *sio);
- int(*read)(struct device *dev, struct sio_txn *sio);
- int(*ioctl)(struct device *dev, uint32_t cmd, uintptr_t arg);
- int(*open)(struct device *dev);
- int(*close)(struct device *dev);
- paddr_t(*mmap)(struct device *dev, off_t off, vm_prot_t prot);
- TAILQ_ENTRY(device) link;
-};
-
-static inline struct device *
-device_alloc(void)
-{
- struct device *dev;
-
- dev = dynalloc(sizeof(struct device));
- if (dev == NULL)
- return dev;
-
- memset(dev, 0, sizeof(struct device));
- return dev;
-}
-
-struct device *device_fetch(dev_t major, dev_t minor);
-dev_t device_alloc_major(void);
-dev_t device_create(struct device *dev, dev_t major, dev_t minor);
-
-#endif
diff --git a/sys/include/sys/driver.h b/sys/include/sys/driver.h
deleted file mode 100644
index 415f4e2..0000000
--- a/sys/include/sys/driver.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_DRIVER_H_
-#define _SYS_DRIVER_H_
-
-#include <sys/cdefs.h>
-
-#if defined(_KERNEL)
-
-struct driver {
- int(*init)(void);
-};
-
-extern char __drivers_init_start[];
-extern char __drivers_init_end[];
-
-#define DRIVER_EXPORT(INIT) \
- __attribute__((used, section(".drivers"))) \
- static struct driver __driver_desc = { \
- .init = INIT, \
- }
-
-#define DRIVERS_INIT() \
- for (struct driver *__d = (struct driver *)__drivers_init_start; \
- (uintptr_t)__d < (uintptr_t)__drivers_init_end; ++__d) \
- { \
- __d->init(); \
- }
-#endif
-#endif /* !_SYS_DRIVER_H_ */
diff --git a/sys/include/sys/elf.h b/sys/include/sys/elf.h
deleted file mode 100644
index af2d65a..0000000
--- a/sys/include/sys/elf.h
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_ELF_H_
-#define _SYS_ELF_H_
-
-#include <sys/types.h>
-
-/* Type for a 16-bit quantity. */
-typedef uint16_t Elf32_Half;
-typedef uint16_t Elf64_Half;
-
-/* Types for signed and unsigned 32-bit quantities. */
-typedef uint32_t Elf32_Word;
-typedef int32_t Elf32_Sword;
-typedef uint32_t Elf64_Word;
-typedef int32_t Elf64_Sword;
-
-/* Types for signed and unsigned 64-bit quantities. */
-typedef uint64_t Elf32_Xword;
-typedef int64_t Elf32_Sxword;
-typedef uint64_t Elf64_Xword;
-typedef int64_t Elf64_Sxword;
-
-/* Type of addresses. */
-typedef uint32_t Elf32_Addr;
-typedef uint64_t Elf64_Addr;
-
-/* Type of file offsets. */
-typedef uint32_t Elf32_Off;
-typedef uint64_t Elf64_Off;
-
-/* Type for section indices, which are 16-bit quantities. */
-typedef uint16_t Elf32_Section;
-typedef uint16_t Elf64_Section;
-
-/* Type for version symbol information. */
-typedef Elf32_Half Elf32_Versym;
-typedef Elf64_Half Elf64_Versym;
-
-#define EI_MAG0 0 /* File identification byte 0 index */
-#define ELFMAG0 0x7f /* Magic number byte 0 */
-
-#define EI_MAG1 1 /* File identification byte 1 index */
-#define ELFMAG1 'E' /* Magic number byte 1 */
-
-#define EI_MAG2 2 /* File identification byte 2 index */
-#define ELFMAG2 'L' /* Magic number byte 2 */
-
-#define EI_MAG3 3 /* File identification byte 3 index */
-#define ELFMAG3 'F' /* Magic number byte 3 */
-
-/* Conglomeration of the identification bytes, for easy testing as a word. */
-#define ELFMAG "\177ELF"
-#define SELFMAG 4
-
-#define EI_CLASS 4 /* File class byte index */
-#define ELFCLASSNONE 0 /* Invalid class */
-#define ELFCLASS32 1 /* 32-bit objects */
-#define ELFCLASS64 2 /* 64-bit objects */
-#define ELFCLASSNUM 3
-
-#define EI_DATA 5 /* Data encoding byte index */
-#define ELFDATANONE 0 /* Invalid data encoding */
-#define ELFDATA2LSB 1 /* 2's complement, little endian */
-#define ELFDATA2MSB 2 /* 2's complement, big endian */
-#define ELFDATANUM 3
-
-#define EI_VERSION 6 /* File version byte index */
- /* Value must be EV_CURRENT */
-
-#define EI_OSABI 7 /* OS ABI identification */
-#define ELFOSABI_NONE 0 /* UNIX System V ABI */
-#define ELFOSABI_SYSV 0 /* Alias. */
-#define ELFOSABI_HPUX 1 /* HP-UX */
-#define ELFOSABI_NETBSD 2 /* NetBSD. */
-#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */
-#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */
-#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
-#define ELFOSABI_AIX 7 /* IBM AIX. */
-#define ELFOSABI_IRIX 8 /* SGI Irix. */
-#define ELFOSABI_FREEBSD 9 /* FreeBSD. */
-#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
-#define ELFOSABI_MODESTO 11 /* Novell Modesto. */
-#define ELFOSABI_OPENBSD 12 /* OpenBSD. */
-#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
-#define ELFOSABI_ARM 97 /* ARM */
-#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
-
-#define EI_ABIVERSION 8 /* ABI version */
-
-#define EI_PAD 9 /* Byte index of padding bytes */
-
-/* Legal values for e_type (object file type). */
-
-#define ET_NONE 0 /* No file type */
-#define ET_REL 1 /* Relocatable file */
-#define ET_EXEC 2 /* Executable file */
-#define ET_DYN 3 /* Shared object file */
-#define ET_CORE 4 /* Core file */
-#define ET_NUM 5 /* Number of defined types */
-#define ET_LOOS 0xfe00 /* OS-specific range start */
-#define ET_HIOS 0xfeff /* OS-specific range end */
-#define ET_LOPROC 0xff00 /* Processor-specific range start */
-#define ET_HIPROC 0xffff /* Processor-specific range end */
-
-/* Legal values for e_machine (architecture). */
-
-#define EM_NONE 0 /* No machine */
-#define EM_M32 1 /* AT&T WE 32100 */
-#define EM_SPARC 2 /* SUN SPARC */
-#define EM_386 3 /* Intel 80386 */
-#define EM_68K 4 /* Motorola m68k family */
-#define EM_88K 5 /* Motorola m88k family */
-#define EM_IAMCU 6 /* Intel MCU */
-#define EM_860 7 /* Intel 80860 */
-#define EM_MIPS 8 /* MIPS R3000 big-endian */
-#define EM_S370 9 /* IBM System/370 */
-#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */
- /* reserved 11-14 */
-#define EM_PARISC 15 /* HPPA */
- /* reserved 16 */
-#define EM_VPP500 17 /* Fujitsu VPP500 */
-#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
-#define EM_960 19 /* Intel 80960 */
-#define EM_PPC 20 /* PowerPC */
-#define EM_PPC64 21 /* PowerPC 64-bit */
-#define EM_S390 22 /* IBM S390 */
-#define EM_SPU 23 /* IBM SPU/SPC */
- /* reserved 24-35 */
-#define EM_V800 36 /* NEC V800 series */
-#define EM_FR20 37 /* Fujitsu FR20 */
-#define EM_RH32 38 /* TRW RH-32 */
-#define EM_RCE 39 /* Motorola RCE */
-#define EM_ARM 40 /* ARM */
-#define EM_FAKE_ALPHA 41 /* Digital Alpha */
-#define EM_SH 42 /* Hitachi SH */
-#define EM_SPARCV9 43 /* SPARC v9 64-bit */
-#define EM_TRICORE 44 /* Siemens Tricore */
-#define EM_ARC 45 /* Argonaut RISC Core */
-#define EM_H8_300 46 /* Hitachi H8/300 */
-#define EM_H8_300H 47 /* Hitachi H8/300H */
-#define EM_H8S 48 /* Hitachi H8S */
-#define EM_H8_500 49 /* Hitachi H8/500 */
-#define EM_IA_64 50 /* Intel Merced */
-#define EM_MIPS_X 51 /* Stanford MIPS-X */
-#define EM_COLDFIRE 52 /* Motorola Coldfire */
-#define EM_68HC12 53 /* Motorola M68HC12 */
-#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
-#define EM_PCP 55 /* Siemens PCP */
-#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
-#define EM_NDR1 57 /* Denso NDR1 microprocessor */
-#define EM_STARCORE 58 /* Motorola Start*Core processor */
-#define EM_ME16 59 /* Toyota ME16 processor */
-#define EM_ST100 60 /* STMicroelectronic ST100 processor */
-#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam */
-#define EM_X86_64 62 /* AMD x86-64 architecture */
-#define EM_PDSP 63 /* Sony DSP Processor */
-#define EM_PDP10 64 /* Digital PDP-10 */
-#define EM_PDP11 65 /* Digital PDP-11 */
-#define EM_FX66 66 /* Siemens FX66 microcontroller */
-#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
-#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
-#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
-#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
-#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
-#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
-#define EM_SVX 73 /* Silicon Graphics SVx */
-#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
-#define EM_VAX 75 /* Digital VAX */
-#define EM_CRIS 76 /* Axis Communications 32-bit emb.proc */
-#define EM_JAVELIN 77 /* Infineon Technologies 32-bit emb.proc */
-#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
-#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
-#define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc */
-#define EM_HUANY 81 /* Harvard University machine-independent object files */
-#define EM_PRISM 82 /* SiTera Prism */
-#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
-#define EM_FR30 84 /* Fujitsu FR30 */
-#define EM_D10V 85 /* Mitsubishi D10V */
-#define EM_D30V 86 /* Mitsubishi D30V */
-#define EM_V850 87 /* NEC v850 */
-#define EM_M32R 88 /* Mitsubishi M32R */
-#define EM_MN10300 89 /* Matsushita MN10300 */
-#define EM_MN10200 90 /* Matsushita MN10200 */
-#define EM_PJ 91 /* picoJava */
-#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
-#define EM_ARC_COMPACT 93 /* ARC International ARCompact */
-#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
-#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore */
-#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Proc */
-#define EM_NS32K 97 /* National Semi. 32000 */
-#define EM_TPC 98 /* Tenor Network TPC */
-#define EM_SNP1K 99 /* Trebia SNP 1000 */
-#define EM_ST200 100 /* STMicroelectronics ST200 */
-#define EM_IP2K 101 /* Ubicom IP2xxx */
-#define EM_MAX 102 /* MAX processor */
-#define EM_CR 103 /* National Semi. CompactRISC */
-#define EM_F2MC16 104 /* Fujitsu F2MC16 */
-#define EM_MSP430 105 /* Texas Instruments msp430 */
-#define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */
-#define EM_SE_C33 107 /* Seiko Epson S1C33 family */
-#define EM_SEP 108 /* Sharp embedded microprocessor */
-#define EM_ARCA 109 /* Arca RISC */
-#define EM_UNICORE 110 /* PKU-Unity & MPRC Peking Uni. mc series */
-#define EM_EXCESS 111 /* eXcess configurable cpu */
-#define EM_DXP 112 /* Icera Semi. Deep Execution Processor */
-#define EM_ALTERA_NIOS2 113 /* Altera Nios II */
-#define EM_CRX 114 /* National Semi. CompactRISC CRX */
-#define EM_XGATE 115 /* Motorola XGATE */
-#define EM_C166 116 /* Infineon C16x/XC16x */
-#define EM_M16C 117 /* Renesas M16C */
-#define EM_DSPIC30F 118 /* Microchip Technology dsPIC30F */
-#define EM_CE 119 /* Freescale Communication Engine RISC */
-#define EM_M32C 120 /* Renesas M32C */
- /* reserved 121-130 */
-#define EM_TSK3000 131 /* Altium TSK3000 */
-#define EM_RS08 132 /* Freescale RS08 */
-#define EM_SHARC 133 /* Analog Devices SHARC family */
-#define EM_ECOG2 134 /* Cyan Technology eCOG2 */
-#define EM_SCORE7 135 /* Sunplus S+core7 RISC */
-#define EM_DSP24 136 /* New Japan Radio (NJR) 24-bit DSP */
-#define EM_VIDEOCORE3 137 /* Broadcom VideoCore III */
-#define EM_LATTICEMICO32 138 /* RISC for Lattice FPGA */
-#define EM_SE_C17 139 /* Seiko Epson C17 */
-#define EM_TI_C6000 140 /* Texas Instruments TMS320C6000 DSP */
-#define EM_TI_C2000 141 /* Texas Instruments TMS320C2000 DSP */
-#define EM_TI_C5500 142 /* Texas Instruments TMS320C55x DSP */
-#define EM_TI_ARP32 143 /* Texas Instruments App. Specific RISC */
-#define EM_TI_PRU 144 /* Texas Instruments Prog. Realtime Unit */
- /* reserved 145-159 */
-#define EM_MMDSP_PLUS 160 /* STMicroelectronics 64bit VLIW DSP */
-#define EM_CYPRESS_M8C 161 /* Cypress M8C */
-#define EM_R32C 162 /* Renesas R32C */
-#define EM_TRIMEDIA 163 /* NXP Semi. TriMedia */
-#define EM_QDSP6 164 /* QUALCOMM DSP6 */
-#define EM_8051 165 /* Intel 8051 and variants */
-#define EM_STXP7X 166 /* STMicroelectronics STxP7x */
-#define EM_NDS32 167 /* Andes Tech. compact code emb. RISC */
-#define EM_ECOG1X 168 /* Cyan Technology eCOG1X */
-#define EM_MAXQ30 169 /* Dallas Semi. MAXQ30 mc */
-#define EM_XIMO16 170 /* New Japan Radio (NJR) 16-bit DSP */
-#define EM_MANIK 171 /* M2000 Reconfigurable RISC */
-#define EM_CRAYNV2 172 /* Cray NV2 vector architecture */
-#define EM_RX 173 /* Renesas RX */
-#define EM_METAG 174 /* Imagination Tech. META */
-#define EM_MCST_ELBRUS 175 /* MCST Elbrus */
-#define EM_ECOG16 176 /* Cyan Technology eCOG16 */
-#define EM_CR16 177 /* National Semi. CompactRISC CR16 */
-#define EM_ETPU 178 /* Freescale Extended Time Processing Unit */
-#define EM_SLE9X 179 /* Infineon Tech. SLE9X */
-#define EM_L10M 180 /* Intel L10M */
-#define EM_K10M 181 /* Intel K10M */
- /* reserved 182 */
-#define EM_AARCH64 183 /* ARM AARCH64 */
- /* reserved 184 */
-#define EM_AVR32 185 /* Amtel 32-bit microprocessor */
-#define EM_STM8 186 /* STMicroelectronics STM8 */
-#define EM_TILE64 187 /* Tileta TILE64 */
-#define EM_TILEPRO 188 /* Tilera TILEPro */
-#define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */
-#define EM_CUDA 190 /* NVIDIA CUDA */
-#define EM_TILEGX 191 /* Tilera TILE-Gx */
-#define EM_CLOUDSHIELD 192 /* CloudShield */
-#define EM_COREA_1ST 193 /* KIPO-KAIST Core-A 1st gen. */
-#define EM_COREA_2ND 194 /* KIPO-KAIST Core-A 2nd gen. */
-#define EM_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */
-#define EM_OPEN8 196 /* Open8 RISC */
-#define EM_RL78 197 /* Renesas RL78 */
-#define EM_VIDEOCORE5 198 /* Broadcom VideoCore V */
-#define EM_78KOR 199 /* Renesas 78KOR */
-#define EM_56800EX 200 /* Freescale 56800EX DSC */
-#define EM_BA1 201 /* Beyond BA1 */
-#define EM_BA2 202 /* Beyond BA2 */
-#define EM_XCORE 203 /* XMOS xCORE */
-#define EM_MCHP_PIC 204 /* Microchip 8-bit PIC(r) */
- /* reserved 205-209 */
-#define EM_KM32 210 /* KM211 KM32 */
-#define EM_KMX32 211 /* KM211 KMX32 */
-#define EM_EMX16 212 /* KM211 KMX16 */
-#define EM_EMX8 213 /* KM211 KMX8 */
-#define EM_KVARC 214 /* KM211 KVARC */
-#define EM_CDP 215 /* Paneve CDP */
-#define EM_COGE 216 /* Cognitive Smart Memory Processor */
-#define EM_COOL 217 /* Bluechip CoolEngine */
-#define EM_NORC 218 /* Nanoradio Optimized RISC */
-#define EM_CSR_KALIMBA 219 /* CSR Kalimba */
-#define EM_Z80 220 /* Zilog Z80 */
-#define EM_VISIUM 221 /* Controls and Data Services VISIUMcore */
-#define EM_FT32 222 /* FTDI Chip FT32 */
-#define EM_MOXIE 223 /* Moxie processor */
-#define EM_AMDGPU 224 /* AMD GPU */
- /* reserved 225-242 */
-#define EM_RISCV 243 /* RISC-V */
-
-#define EM_BPF 247 /* Linux BPF -- in-kernel virtual machine */
-
-#define EM_NUM 248
-
-/* Old spellings/synonyms. */
-
-#define EM_ARC_A5 EM_ARC_COMPACT
-
-/* If it is necessary to assign new unofficial EM_* values, please
- pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
- chances of collision with official or non-GNU unofficial values. */
-
-#define EM_ALPHA 0x9026
-
-/* Legal values for e_version (version). */
-
-#define EV_NONE 0 /* Invalid ELF version */
-#define EV_CURRENT 1 /* Current version */
-#define EV_NUM 2
-
-#define EI_NIDENT (16)
-
-#define PT_NULL 0 /* Program header table entry unused */
-#define PT_LOAD 1 /* Loadable program segment */
-#define PT_DYNAMIC 2 /* Dynamic linking information */
-#define PT_INTERP 3 /* Program interpreter */
-#define PT_NOTE 4 /* Auxiliary information */
-#define PT_SHLIB 5 /* Reserved */
-#define PT_PHDR 6 /* Entry for header table itself */
-#define PT_TLS 7 /* Thread-local storage segment */
-#define PT_NUM 8 /* Number of defined types */
-#define PT_LOOS 0x60000000 /* Start of OS-specific */
-#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
-#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */
-#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
-#define PT_LOSUNW 0x6ffffffa
-#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
-#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
-#define PT_HISUNW 0x6fffffff
-#define PT_HIOS 0x6fffffff /* End of OS-specific */
-#define PT_LOPROC 0x70000000 /* Start of processor-specific */
-#define PT_HIPROC 0x7fffffff /* End of processor-specific */
-
-/* Legal values for p_flags (segment flags). */
-
-#define PF_X (1 << 0) /* Segment is executable */
-#define PF_W (1 << 1) /* Segment is writable */
-#define PF_R (1 << 2) /* Segment is readable */
-#define PF_MASKOS 0x0ff00000 /* OS-specific */
-#define PF_MASKPROC 0xf0000000 /* Processor-specific */
-
-/* Legal values for note segment descriptor types for core files. */
-
-#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
-#define NT_PRFPREG 2 /* Contains copy of fpregset
- struct. */
-#define NT_FPREGSET 2 /* Contains copy of fpregset struct */
-#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
-#define NT_PRXREG 4 /* Contains copy of prxregset struct */
-#define NT_TASKSTRUCT 4 /* Contains copy of task structure */
-#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */
-#define NT_AUXV 6 /* Contains copy of auxv array */
-#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */
-#define NT_ASRS 8 /* Contains copy of asrset struct */
-#define NT_PSTATUS 10 /* Contains copy of pstatus struct */
-#define NT_PSINFO 13 /* Contains copy of psinfo struct */
-#define NT_PRCRED 14 /* Contains copy of prcred struct */
-#define NT_UTSNAME 15 /* Contains copy of utsname struct */
-#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */
-#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */
-#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */
-#define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t,
- size might increase */
-#define NT_FILE 0x46494c45 /* Contains information about mapped
- files */
-#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */
-#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
-#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
-#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
-#define NT_PPC_TAR 0x103 /* Target Address Register */
-#define NT_PPC_PPR 0x104 /* Program Priority Register */
-#define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
-#define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
-#define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
-#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
-#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
-#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
-#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
-#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
-#define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address
- Register */
-#define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority
- Register */
-#define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control
- Register */
-#define NT_PPC_PKEY 0x110 /* Memory Protection Keys
- registers. */
-#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
-#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
-#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
-#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
-#define NT_S390_TIMER 0x301 /* s390 timer register */
-#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
-#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
-#define NT_S390_CTRS 0x304 /* s390 control registers */
-#define NT_S390_PREFIX 0x305 /* s390 prefix register */
-#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
-#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
-#define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
-#define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15
- upper half. */
-#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31. */
-#define NT_S390_GS_CB 0x30b /* s390 guarded storage registers. */
-#define NT_S390_GS_BC 0x30c /* s390 guarded storage
- broadcast control block. */
-#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */
-#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
-#define NT_ARM_TLS 0x401 /* ARM TLS register */
-#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
-#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
-#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
-#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
- registers */
-#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
-
-/* Legal values for the note segment descriptor types for object files. */
-
-#define NT_VERSION 1 /* Contains a version string. */
-
-typedef struct
-{
- unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
- Elf64_Half e_type; /* Object file type */
- Elf64_Half e_machine; /* Architecture */
- Elf64_Word e_version; /* Object file version */
- Elf64_Addr e_entry; /* Entry point virtual address */
- Elf64_Off e_phoff; /* Program header table file offset */
- Elf64_Off e_shoff; /* Section header table file offset */
- Elf64_Word e_flags; /* Processor-specific flags */
- Elf64_Half e_ehsize; /* ELF header size in bytes */
- Elf64_Half e_phentsize; /* Program header table entry size */
- Elf64_Half e_phnum; /* Program header table entry count */
- Elf64_Half e_shentsize; /* Section header table entry size */
- Elf64_Half e_shnum; /* Section header table entry count */
- Elf64_Half e_shstrndx; /* Section header string table index */
-} Elf64_Ehdr;
-
-typedef struct
-{
- Elf64_Word p_type; /* Segment type */
- Elf64_Word p_flags; /* Segment flags */
- Elf64_Off p_offset; /* Segment file offset */
- Elf64_Addr p_vaddr; /* Segment virtual address */
- Elf64_Addr p_paddr; /* Segment physical address */
- Elf64_Xword p_filesz; /* Segment size in file */
- Elf64_Xword p_memsz; /* Segment size in memory */
- Elf64_Xword p_align; /* Segment alignment */
-} Elf64_Phdr;
-
-typedef struct {
- Elf64_Addr r_offset; /* Location at which to apply the action */
- Elf64_Xword r_info; /* index and type of relocation */
-} Elf64_Rel;
-
-typedef struct {
- Elf64_Word sh_name; /* Section name, index in string tbl */
- Elf64_Word sh_type; /* Type of section */
- Elf64_Xword sh_flags; /* Miscellaneous section attributes */
- Elf64_Addr sh_addr; /* Section virtual addr at execution */
- Elf64_Off sh_offset; /* Section file offset */
- Elf64_Xword sh_size; /* Size of section in bytes */
- Elf64_Word sh_link; /* Index of another section */
- Elf64_Word sh_info; /* Additional section information */
- Elf64_Xword sh_addralign; /* Section alignment */
- Elf64_Xword sh_entsize; /* Entry size if section holds table */
-} Elf64_Shdr;
-
-#endif /* _SYS_ELF_H_ */
diff --git a/sys/include/sys/errno.h b/sys/include/sys/errno.h
deleted file mode 100644
index a93cf18..0000000
--- a/sys/include/sys/errno.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_ERRNO_H_
-#define _SYS_ERRNO_H_
-
-#define EXIT_SUCCESS 0
-#define EXIT_FAILURE 1
-
-#define EPERM 1 /* Not super-user */
-#define ENOENT 2 /* No such file or directory */
-#define ESRCH 3 /* No such process */
-#define EINTR 4 /* Interrupted system call */
-#define EIO 5 /* I/O error */
-#define ENXIO 6 /* No such device or address */
-#define E2BIG 7 /* Arg list too long */
-#define ENOEXEC 8 /* Exec format error */
-#define EBADF 9 /* Bad file number */
-#define ECHILD 10 /* No children */
-#define EAGAIN 11 /* No more processes */
-#define ENOMEM 12 /* Not enough core */
-#define EACCES 13 /* Permission denied */
-#define EFAULT 14 /* Bad address */
-#define ENOTBLK 15 /* Block device required */
-#define EBUSY 16 /* Mount device busy */
-#define EEXIST 17 /* File exists */
-#define EXDEV 18 /* Cross-device link */
-#define ENODEV 19 /* No such device */
-#define ENOTDIR 20 /* Not a directory */
-#define EISDIR 21 /* Is a directory */
-#define EINVAL 22 /* Invalid argument */
-#define ENFILE 23 /* Too many open files in system */
-#define EMFILE 24 /* Too many open files */
-#define ENOTTY 25 /* Not a typewriter */
-#define ETXTBSY 26 /* Text file busy */
-#define EFBIG 27 /* File too large */
-#define ENOSPC 28 /* No space left on device */
-#define ESPIPE 29 /* Illegal seek */
-#define EROFS 30 /* Read only file system */
-#define EMLINK 31 /* Too many links */
-#define EPIPE 32 /* Broken pipe */
-#define EDOM 33 /* Math arg out of domain of func */
-#define ERANGE 34 /* Math result not representable */
-#define ENOMSG 35 /* No message of desired type */
-#define EIDRM 36 /* Identifier removed */
-#define ECHRNG 37 /* Channel number out of range */
-#define EL2NSYNC 38 /* Level 2 not synchronized */
-#define EL3HLT 39 /* Level 3 halted */
-#define EL3RST 40 /* Level 3 reset */
-#define ELNRNG 41 /* Link number out of range */
-#define EUNATCH 42 /* Protocol driver not attached */
-#define ENOCSI 43 /* No CSI structure available */
-#define EL2HLT 44 /* Level 2 halted */
-#define EDEADLK 45 /* Deadlock condition */
-#define ENOLCK 46 /* No record locks available */
-#define EBADE 50 /* Invalid exchange */
-#define EBADR 51 /* Invalid request descriptor */
-#define EXFULL 52 /* Exchange full */
-#define ENOANO 53 /* No anode */
-#define EBADRQC 54 /* Invalid request code */
-#define EBADSLT 55 /* Invalid slot */
-#define EDEADLOCK 56 /* File locking deadlock error */
-#define EBFONT 57 /* Bad font file fmt */
-#define ENOSTR 60 /* Device not a stream */
-#define ENODATA 61 /* No data (for no delay io) */
-#define ETIME 62 /* Timer expired */
-#define ENOSR 63 /* Out of streams resources */
-#define ENONET 64 /* Machine is not on the network */
-#define ENOPKG 65 /* Package not installed */
-#define EREMOTE 66 /* The object is remote */
-#define ENOLINK 67 /* The link has been severed */
-#define EADV 68 /* Advertise error */
-#define ESRMNT 69 /* Srmount error */
-#define ECOMM 70 /* Communication error on send */
-#define EPROTO 71 /* Protocol error */
-#define EMULTIHOP 74 /* Multihop attempted */
-#define ELBIN 75 /* Inode is remote (not really error) */
-#define EDOTDOT 76 /* Cross mount point (not really error) */
-#define EBADMSG 77 /* Trying to read unreadable message */
-#define EFTYPE 79 /* Inappropriate file type or format */
-#define ENOTUNIQ 80 /* Given log. name not unique */
-#define EBADFD 81 /* f.d. invalid for this operation */
-#define EREMCHG 82 /* Remote address changed */
-#define ELIBACC 83 /* Can't access a needed shared lib */
-#define ELIBBAD 84 /* Accessing a corrupted shared lib */
-#define ELIBSCN 85 /* .lib section in a.out corrupted */
-#define ELIBMAX 86 /* Attempting to link in too many libs */
-#define ELIBEXEC 87 /* Attempting to exec a shared library */
-#define ENOSYS 88 /* Function not implemented */
-#define ENMFILE 89 /* No more files */
-#define ENOTEMPTY 90 /* Directory not empty */
-#define ENAMETOOLONG 91 /* File or path name too long */
-#define ELOOP 92 /* Too many symbolic links */
-#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
-#define EPFNOSUPPORT 96 /* Protocol family not supported */
-#define ECONNRESET 104 /* Connection reset by peer */
-#define ENOBUFS 105 /* No buffer space available */
-#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
-#define EPROTOTYPE 107 /* Protocol wrong type for socket */
-#define ENOTSOCK 108 /* Socket operation on non-socket */
-#define ENOPROTOOPT 109 /* Protocol not available */
-#define ESHUTDOWN 110 /* Can't send after socket shutdown */
-#define ECONNREFUSED 111 /* Connection refused */
-#define EADDRINUSE 112 /* Address already in use */
-#define ECONNABORTED 113 /* Connection aborted */
-#define ENETUNREACH 114 /* Network is unreachable */
-#define ENETDOWN 115 /* Network interface is not configured */
-#define ETIMEDOUT 116 /* Connection timed out */
-#define EHOSTDOWN 117 /* Host is down */
-#define EHOSTUNREACH 118 /* Host is unreachable */
-#define EINPROGRESS 119 /* Connection already in progress */
-#define EALREADY 120 /* Socket already connected */
-#define EDESTADDRREQ 121 /* Destination address required */
-#define EMSGSIZE 122 /* Message too long */
-#define EPROTONOSUPPORT 123 /* Unknown protocol */
-#define ESOCKTNOSUPPORT 124 /* Socket type not supported */
-#define EADDRNOTAVAIL 125 /* Address not available */
-#define ENETRESET 126
-#define EISCONN 127 /* Socket is already connected */
-#define ENOTCONN 128 /* Socket is not connected */
-#define ETOOMANYREFS 129
-#define EPROCLIM 130
-#define EUSERS 131
-#define EDQUOT 132
-#define ESTALE 133
-#define ENOTSUP 134 /* Not supported */
-#define ENOMEDIUM 135 /* No medium (in tape drive) */
-#define ENOSHARE 136 /* No such host or network path */
-#define ECASECLASH 137 /* Filename exists with different case */
-#define EILSEQ 138
-#define EOVERFLOW 139 /* Value too large for defined data type */
-
-#endif
diff --git a/sys/include/sys/exec.h b/sys/include/sys/exec.h
deleted file mode 100644
index 5832a3f..0000000
--- a/sys/include/sys/exec.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_EXEC_H_
-#define _SYS_EXEC_H_
-
-#include <sys/syscall.h>
-
-uint64_t sys_execv(struct syscall_args *args);
-
-#endif
diff --git a/sys/include/sys/fbdev.h b/sys/include/sys/fbdev.h
deleted file mode 100644
index 7308a92..0000000
--- a/sys/include/sys/fbdev.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_
-
-#if defined(_KERNEL)
-#include <sys/types.h>
-#else
-#include <stdint.h>
-#endif
-
-#define FBIOCTL_INFO 0x00000000
-
-struct fbdev_info {
- uint32_t width;
- uint32_t height;
- uint32_t pitch;
- uint32_t bits_per_pixel;
-};
-
-#endif
diff --git a/sys/include/sys/filedesc.h b/sys/include/sys/filedesc.h
deleted file mode 100644
index f2c2778..0000000
--- a/sys/include/sys/filedesc.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_FILEDESC_H_
-#define _SYS_FILEDESC_H_
-
-#include <sys/vnode.h>
-#include <sys/mutex.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
-
-#define O_RDONLY 0x00000
-#define O_WRONLY 0x00001
-#define O_RDWR 0x00002
-
-#define SEEK_SET 0
-#define SEEK_CUR 1
-#define SEEK_END 2
-
-struct proc;
-
-struct filedesc {
- int fdno;
- int oflag;
- off_t offset;
- bool is_dir;
- struct vnode *vnode;
- struct mutex lock;
-};
-
-#if defined(_KERNEL)
-int fd_alloc(struct proc *td, struct filedesc **fd_out);
-struct filedesc *fd_from_fdnum(const struct proc *td, int fdno);
-void fd_close_fdnum(struct proc *td, int fdno);
-ssize_t write(int fd, const void *buf, size_t count);
-int open(const char *pathname, int oflag);
-int read(int fd, void *buf, size_t count);
-off_t lseek(int fd, off_t offset, int whence);
-
-uint64_t sys_write(struct syscall_args *args);
-uint64_t sys_open(struct syscall_args *args);
-uint64_t sys_close(struct syscall_args *args);
-uint64_t sys_read(struct syscall_args *args);
-uint64_t sys_lseek(struct syscall_args *args);
-#endif
-#endif
diff --git a/sys/include/sys/intr.h b/sys/include/sys/intr.h
deleted file mode 100644
index 0590f87..0000000
--- a/sys/include/sys/intr.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_INTR_H_
-#define _SYS_INTR_H_
-
-#if defined(_KERNEL)
-#include <sys/types.h>
-#include <sys/spinlock.h>
-#include <sys/queue.h>
-
-/*
- * Interrupt information
- */
-struct intr_info {
- struct spinlock lock;
- const char *source;
- const char *device;
- uint8_t affinity;
- size_t count; /* Interrupt count */
- TAILQ_ENTRY(intr_info) link;
-};
-
-struct intr_info *intr_info_alloc(const char *source, const char *dev);
-void intr_register(struct intr_info *info);
-void intr_init_proc(void);
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SYS_INTR_H_ */
diff --git a/sys/include/sys/ksyms.h b/sys/include/sys/ksyms.h
deleted file mode 100644
index 2862cbc..0000000
--- a/sys/include/sys/ksyms.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_KSYMS_H_
-#define _SYS_KSYMS_H_
-
-#include <sys/cdefs.h>
-
-#if defined(_KERNEL)
-struct kernel_symbol {
- uint64_t addr;
- char* name;
-};
-
-__weak extern struct kernel_symbol g_ksym_table[];
-
-#endif /* defined(_KERNEL) */
-#endif
diff --git a/sys/include/sys/limine.h b/sys/include/sys/limine.h
deleted file mode 100644
index f26d8c5..0000000
--- a/sys/include/sys/limine.h
+++ /dev/null
@@ -1,495 +0,0 @@
-/* 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
-
-#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/loader.h b/sys/include/sys/loader.h
deleted file mode 100644
index 43ad36e..0000000
--- a/sys/include/sys/loader.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_LOADER_H_
-#define _SYS_LOADER_H_
-
-#include <sys/types.h>
-#include <vm/pmap.h>
-#include <vm/vm.h>
-
-/* DANGER!: DO NOT CHANGE THESE DEFINES */
-#define AT_NULL 0
-#define AT_ENTRY 1
-#define AT_PHDR 2
-#define AT_PHENT 3
-#define AT_PHNUM 4
-#define AT_EXECPATH 5
-#define AT_SECURE 6
-#define AT_RANDOM 7
-#define AT_EXECFN 8
-#define AT_PAGESIZE 9
-
-#define STACK_PUSH(ptr, val) *(--ptr) = val
-#define AUXVAL(ptr, tag, val) __extension__ ({ \
- STACK_PUSH(ptr, val); \
- STACK_PUSH(ptr, tag); \
-});
-
-/* Auxiliary Vector */
-struct auxval {
- uint64_t at_entry;
- uint64_t at_phdr;
- uint64_t at_phent;
- uint64_t at_phnum;
-};
-
-struct exec_args {
- char **argp, **envp;
- struct auxval auxv;
- struct vas vas;
-};
-
-#if defined(_KERNEL)
-
-uintptr_t loader_init_stack(void *stack_top, struct exec_args args);
-int loader_unload(struct vas vas, struct vm_range *exec_range);
-int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv,
- size_t load_base, char **ld_path, struct vm_range *prog_range);
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SYS_LOADER_H_ */
diff --git a/sys/include/sys/machdep.h b/sys/include/sys/machdep.h
deleted file mode 100644
index 0ecb83e..0000000
--- a/sys/include/sys/machdep.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_MACHDEP_H_
-#define _SYS_MACHDEP_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/proc.h>
-
-#if defined(_KERNEL)
-
-#define MAXCPUS 32
-
-int processor_init_pcb(struct proc *proc);
-int processor_free_pcb(struct proc *proc);
-void processor_switch_to(struct proc *old_td, struct proc *new_td);
-void processor_init(void);
-void processor_halt(void);
-void intr_mask(void);
-void intr_unmask(void);
-void machine_panic(void);
-__weak void chips_init(void);
-__weak void pre_init(void);
-__weak void serial_dbgch(char c);
-__weak void cpu_halt_others(void);
-__weak void cpu_reset(void);
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SYS_MACHDEP_H_ */
diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h
deleted file mode 100644
index 69d8fd2..0000000
--- a/sys/include/sys/mmio.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/*
- * For documentation: See mmio(9)
- */
-
-#ifndef _SYS_MMIO_H_
-#define _SYS_MMIO_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <vm/vm.h>
-
-/*
- * mmio_write<n> - Writes to MMIO address with specific size
- *
- * @addr: Address to write to.
- * @val: Value to write.
- *
- * These functions will add the higher half
- * offset (VM_HIGHER_HALF) if the MMIO address
- * is less than VM_HIGHER_HALF as it'll be safe
- * to assume it's a physical address. Page faults
- * from writes could be due to the resulting virtual
- * address not being mapped.
- */
-#define _MMIO_WRITE_TYPE(TYPE, SUFFIX) \
- static inline void \
- mmio_write##SUFFIX(volatile void *addr, TYPE val) \
- { \
- uintptr_t tmp; \
- \
- tmp = (uintptr_t)addr; \
- if (tmp < VM_HIGHER_HALF) { \
- tmp += VM_HIGHER_HALF; \
- } \
- *(volatile TYPE *)tmp = val; \
- __mem_barrier(); \
- }
-
-/*
- * mmio_read<n> - Does the same as mmio_write<n> but for reading
- *
- * @addr: Address to read from.
- */
-#define _MMIO_READ_TYPE(TYPE, SUFFIX) \
- static inline TYPE \
- mmio_read##SUFFIX(volatile void *addr) \
- { \
- uintptr_t tmp; \
- \
- tmp = (uintptr_t)addr; \
- if (tmp < VM_HIGHER_HALF) { \
- tmp += VM_HIGHER_HALF; \
- } \
- \
- __mem_barrier(); /* Ensure writes complete */ \
- return *(volatile TYPE *)tmp; \
- }
-
-/*
- * To write to an MMIO address of, for example,
- * 8 bits, use mmio_write8(addr, val)
- */
-_MMIO_WRITE_TYPE(uint8_t, 8)
-_MMIO_WRITE_TYPE(uint16_t, 16)
-_MMIO_WRITE_TYPE(uint32_t, 32)
-#if __SIZEOF_SIZE_T__ == 8
-_MMIO_WRITE_TYPE(uint64_t, 64)
-#endif
-__extension__
-
-/*
- * To read from an MMIO address of, for example,
- * 8 bits, use mmio_read8(addr)
- */
-_MMIO_READ_TYPE(uint8_t, 8)
-_MMIO_READ_TYPE(uint16_t, 16)
-_MMIO_READ_TYPE(uint32_t, 32)
-#if __SIZEOF_SIZE_T__ == 8
-_MMIO_READ_TYPE(uint64_t, 64)
-#endif
-__extension__
-
-#endif /* !_SYS_MMIO_H_ */
diff --git a/sys/include/sys/mount.h b/sys/include/sys/mount.h
deleted file mode 100644
index b208bf7..0000000
--- a/sys/include/sys/mount.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_MOUNT_H_
-#define _SYS_MOUNT_H_
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/vnode.h>
-#include <sys/cdefs.h>
-
-#define FS_NAME_MAX 16 /* Max length of FS type name including nul */
-
-struct fs_info;
-struct mount;
-struct vnode;
-
-struct vfsops {
- int(*init)(struct fs_info *info, struct vnode *source);
-};
-
-struct mount {
- int flags;
- size_t phash; /* Path hash */
- struct fs_info *fs;
- TAILQ_ENTRY(mount) link;
-};
-
-struct fs_info {
- char name[FS_NAME_MAX]; /* Filesystem type name */
- struct vfsops *vfsops; /* Filesystem operations */
- struct vops *vops; /* Vops for our vnode */
- struct vnode *vnode; /* Vnode for this filesystem */
- struct mount *mp_root;
- uint16_t caps;
-};
-
-/*
- * Filesystem capabilities
- */
-#define FSCAP_FULLPATH __BIT(0) /* Requires full path per lookup */
-
-/*
- * Mount flags
- */
-#define MNT_RDONLY 0x00000001
-
-#if defined(_KERNEL)
-int vfs_mount(const char *path, int mntflags, struct fs_info *fs);
-int vfs_get_mp(const char *path, struct mount **mp);
-void vfs_mount_init(void);
-#endif /* defined(_KERNEL) */
-
-#endif /* !_SYS_MOUNT_H_ */
diff --git a/sys/include/sys/mutex.h b/sys/include/sys/mutex.h
deleted file mode 100644
index dfd2dec..0000000
--- a/sys/include/sys/mutex.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-
-#ifndef _SYS_MUTEX_H_
-#define _SYS_MUTEX_H_
-
-struct mutex {
- volatile _Atomic bool lock;
-};
-
-void mutex_acquire(struct mutex *mutex);
-void mutex_release(struct mutex *mutex);
-
-#endif /* !_SYS_MUTEX_H_ */
diff --git a/sys/include/sys/panic.h b/sys/include/sys/panic.h
deleted file mode 100644
index 961e5d5..0000000
--- a/sys/include/sys/panic.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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/proc.h b/sys/include/sys/proc.h
deleted file mode 100644
index e3416f9..0000000
--- a/sys/include/sys/proc.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_PROC_H_
-#define _SYS_PROC_H_
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/filedesc.h>
-#include <sys/spinlock.h>
-#include <sys/loader.h>
-#include <machine/cpu.h>
-#include <machine/frame.h>
-#include <machine/pcb.h>
-#include <vm/vm.h>
-#include <vm/map.h>
-
-#define PROC_MAX_FDS 256
-#define PROC_MAX_ADDR_RANGE 4
-
-#define PROC_STACK_PAGES 8
-#define PROC_STACK_SIZE (PROC_STACK_PAGES*vm_get_page_size())
-
-/*
- * The PHYS_TO_VIRT/VIRT_TO_PHYS macros convert
- * addresses to lower and higher half addresses.
- * Userspace addresses are on the lower half,
- * therefore, we can just wrap over these to
- * keep things simple.
- *
- * XXX: TODO: This won't work when not identity mapping
- * lowerhalf addresses. Once that is updated,
- * get rid of this.
- */
-#define USER_TO_KERN(user) PHYS_TO_VIRT(user)
-#define KERN_TO_USER(kern) VIRT_TO_PHYS(kern)
-
-enum {
- ADDR_RANGE_EXEC = 0, /* Program address range */
- ADDR_RANGE_STACK /* Stack address range */
-};
-
-/*
- * A task running on the CPU e.g., a process or
- * a thread.
- */
-struct proc {
- pid_t pid;
- struct cpu_info *cpu;
- struct trapframe *tf;
- struct pcb pcb;
- struct vas addrsp;
- struct vm_range addr_range[PROC_MAX_ADDR_RANGE];
- struct spinlock lock;
- uint8_t is_user;
- uint8_t rested;
- uint32_t signal;
- uint32_t priority;
- struct filedesc *fds[PROC_MAX_FDS];
- struct spinlock mapspace_lock;
- struct vm_mapspace mapspace;
- TAILQ_ENTRY(proc) link;
-};
-
-#endif /* !_SYS_PROC_H_ */
diff --git a/sys/include/sys/queue.h b/sys/include/sys/queue.h
deleted file mode 100644
index 60231f4..0000000
--- a/sys/include/sys/queue.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-
-#ifndef _QUEUE_H_
-#define _QUEUE_H_
-
-#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 */ \
- size_t nelem; /* Number of elements */ \
-}
-
-#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_NELEM(head) ((head)->nelem)
-#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; \
- (head)->nelem = 0; \
-} 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; \
- ++(head)->nelem; \
-} 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; \
- ++(head)->nelem; \
-} 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; \
- ++(head)->nelem; \
-} 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; \
- ++(head)->nelem; \
-} 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); \
- --(head)->nelem; \
-} 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)
-#endif /* _QUEUE_H_ */
diff --git a/sys/include/sys/reboot.h b/sys/include/sys/reboot.h
deleted file mode 100644
index e09bd4f..0000000
--- a/sys/include/sys/reboot.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_REBOOT_H_
-#define _SYS_REBOOT_H_
-
-#if defined(_KERNEL)
-#include <sys/syscall.h>
-#endif
-
-#define REBOOT_DEFAULT 0x0000
-
-int reboot(int type);
-
-#if defined(_KERNEL)
-uint64_t sys_reboot(struct syscall_args *args);
-#endif /* defined(_KERNEL) */
-
-#endif /* !_SYS_REBOOT_H_ */
diff --git a/sys/include/sys/sched.h b/sys/include/sys/sched.h
deleted file mode 100644
index 06cf860..0000000
--- a/sys/include/sys/sched.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SCHED_H_
-#define _SYS_SCHED_H_
-
-#include <sys/proc.h>
-#include <sys/queue.h>
-#include <sys/types.h>
-#include <sys/spinlock.h>
-#include <sys/syscall.h>
-#include <machine/cpu.h>
-#include <machine/frame.h>
-
-struct proc *this_td(void);
-void sched_init(void);
-void sched_exit(void);
-void sched_context_switch(struct trapframe *tf);
-void sched_rest(void);
-
-__noreturn
-void sched_enter(void);
-
-__noreturn
-uint64_t sys_exit(struct syscall_args *args);
-
-#endif /* !_SYS_SCHED_H_ */
diff --git a/sys/include/sys/sched_state.h b/sys/include/sys/sched_state.h
deleted file mode 100644
index 52d6c56..0000000
--- a/sys/include/sys/sched_state.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SCHED_STATE_H_
-#define _SYS_SCHED_STATE_H_
-
-#include <sys/proc.h>
-
-/*
- * Scheduler state, per CPU.
- */
-struct sched_state {
- struct proc *td; /* Current_thread */
-};
-
-#endif /* !_SYS_SCHED_STATE_H_ */
diff --git a/sys/include/sys/schedvar.h b/sys/include/sys/schedvar.h
deleted file mode 100644
index 2a0a1fc..0000000
--- a/sys/include/sys/schedvar.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SCHEDVAR_H_
-#define _SYS_SCHEDVAR_H_
-
-#include <sys/cdefs.h>
-#include <sys/proc.h>
-#include <sys/queue.h>
-
-#define DEFAULT_TIMESLICE_USEC 3000
-#define SHORT_TIMESLICE_USEC 10
-
-#define SCHED_POLICY_MLFQ 0x0000U /* Multilevel feedback queue */
-#define SCHED_POLICY_RR 0x0001U /* Round robin */
-
-typedef uint8_t schedpolicy_t;
-
-/* Might be set by kconf(1) */
-#if defined(__SCHED_NQUEUE)
-#define SCHED_NQUEUE __SCHED_NQUEUE
-#else
-#define SCHED_NQUEUE 4
-#endif
-
-/* Ensure SCHED_NQUEUE is an acceptable value */
-__STATIC_ASSERT(SCHED_NQUEUE <= 8, "SCHED_NQUEUE exceeds max");
-__STATIC_ASSERT(SCHED_NQUEUE > 0, "SCHED_NQUEUE cannot be zero");
-
-struct sched_queue {
- TAILQ_HEAD(, proc) q;
- size_t nthread;
-};
-
-#endif /* !_SYS_SCHEDVAR_H_ */
diff --git a/sys/include/sys/signal.h b/sys/include/sys/signal.h
deleted file mode 100644
index 640773d..0000000
--- a/sys/include/sys/signal.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SIGNAL_H_
-#define _SYS_SIGNAL_H_
-
-#if defined(_KERNEL)
-#include <sys/proc.h>
-#endif
-
-#define SIGFPE 8 /* Floating point exception */
-#define SIGKILL 9 /* Kill */
-#define SIGSEGV 11 /* Segmentation violation */
-
-#if defined(_KERNEL)
-void signal_handle(struct proc *curtd);
-void signal_raise(struct proc *to, int signal);
-#endif /* defined(_KERNEL) */
-
-#endif /* !_SYS_SIGNAL_H_ */
diff --git a/sys/include/sys/sio.h b/sys/include/sys/sio.h
deleted file mode 100644
index 6f13a09..0000000
--- a/sys/include/sys/sio.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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 _SIO_H_
-#define _SIO_H_
-
-#include <sys/types.h>
-
-#if defined(_KERNEL)
-enum sio_type {
- SIO_NONE, /* None specified */
- SIO_USER, /* Userspace related transaction */
- SIO_KERN, /* Kernel transaction */
-};
-
-/*
- * System I/O transaction
- *
- * This structure describes a system I/O transaction
- * and contains common fields that are used
- * with system I/O.
- */
-struct sio_txn {
- void *buf; /* Source/dest buffer */
- off_t offset; /* Transfer offset */
- size_t len; /* Length in bytes */
- enum sio_type type; /* Transaction type */
-};
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SIO_H_ */
diff --git a/sys/include/sys/spinlock.h b/sys/include/sys/spinlock.h
deleted file mode 100644
index 98bc342..0000000
--- a/sys/include/sys/spinlock.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SPINLOCK_H_
-#define _SYS_SPINLOCK_H_
-
-#include <sys/types.h>
-
-struct spinlock {
- volatile _Atomic bool lock;
-};
-
-static inline void
-spinlock_acquire(struct spinlock *lock)
-{
- while (__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/syscall.h b/sys/include/sys/syscall.h
deleted file mode 100644
index 4ef3666..0000000
--- a/sys/include/sys/syscall.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SYSCALL_H_
-#define _SYS_SYSCALL_H_
-
-#include <sys/types.h>
-#if defined(_KERNEL)
-#include <machine/frame.h>
-#endif
-
-/* Do not reorder */
-enum {
- SYS_exit = 1,
- SYS_write,
- SYS_open,
- SYS_close,
- SYS_read,
- SYS_lseek,
- SYS_mmap,
- SYS_munmap,
- SYS_ioctl,
- SYS_execv,
- SYS_mount,
- SYS_reboot,
- __MAX_SYSCALLS
-};
-
-struct syscall_args {
- uint64_t code;
- uint64_t arg0, arg1, arg2;
- uint64_t arg3, arg4, arg5, arg6;
- uint64_t ip;
- uint64_t sp;
-};
-
-#if defined(_KERNEL)
-extern uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args);
-void __syscall(struct trapframe *tf);
-#endif
-
-#endif
diff --git a/sys/include/sys/syslog.h b/sys/include/sys/syslog.h
deleted file mode 100644
index 18948ee..0000000
--- a/sys/include/sys/syslog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/*
- * For documentation: See syslog(9)
- */
-
-#ifndef _SYS_SYSLOG_H_
-#define _SYS_SYSLOG_H_
-
-#include <sys/types.h>
-#include <stdarg.h>
-#include <dev/vcons/vcons.h>
-
-#if defined(_KERNEL)
-
-#define OMIT_TIMESTAMP "\x01"
-
-void syslog_init(void);
-void syslog_init_proc(void);
-void kprintf(const char *fmt, ...);
-void vkprintf(const char *fmt, va_list *ap);
-
-extern struct vcons_screen g_syslog_screen;
-extern bool g_syslog_use_tty;
-
-#endif /* defined(_KERNEL) */
-
-#endif /* !_SYS_SYSLOG_H_ */
diff --git a/sys/include/sys/system.h b/sys/include/sys/system.h
deleted file mode 100644
index 03ac710..0000000
--- a/sys/include/sys/system.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_SYSTEM_H_
-#define _SYS_SYSTEM_H_
-
-#include <sys/types.h>
-#include <sys/syscall.h>
-
-#if defined(_KERNEL)
-int copyin(uintptr_t uaddr, void *kaddr, size_t len);
-int copyout(const void *kaddr, uintptr_t uaddr, size_t len);
-int copyinstr(uintptr_t uaddr, char *kaddr, size_t len);
-uint64_t sys_ioctl(struct syscall_args *args);
-#endif
-
-#endif /* !_SYS_SYSTEM_H_ */
diff --git a/sys/include/sys/termios.h b/sys/include/sys/termios.h
deleted file mode 100644
index 1fda67e..0000000
--- a/sys/include/sys/termios.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_TERMIOS_H_
-#define _SYS_TERMIOS_H_
-
-#if defined(_KERNEL)
-#include <sys/types.h>
-#else
-#include <stdint.h>
-#endif
-
-#define NCCS 20
-
-/*
- * Output flags - software output processing
- */
-#define OPOST 0x00000001U /* Enable output processing */
-#if defined(_KERNEL) || defined(_HYRA_SOURCE)
-#define OCRNL 0x00000002U /* Map NL to CR-NL */
-#endif /* defined(_KERNEL) || defined(_HYRA_SOURCE) */
-
-/*
- * Local flags
- */
-#define ICANON 0x00000001U
-#define ECHO 0x00000002U
-
-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/timer.h b/sys/include/sys/timer.h
deleted file mode 100644
index e33b2d3..0000000
--- a/sys/include/sys/timer.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/*
- * For documentation: See timer(9)
- */
-
-#ifndef _SYS_TIMER_H_
-#define _SYS_TIMER_H_
-
-#include <sys/types.h>
-
-/* Timer IDs */
-#define TIMER_SCHED 0x00000000U /* Scheduler reserved timer */
-#define TIMER_GP 0x00000001U /* General purpose timer */
-
-/* Number of timer IDs, adjust when adding timer IDs */
-#define TIMER_ID_COUNT 2
-
-/* Timer registry status */
-#define TMRR_SUCCESS 0x00000000U /* Successful */
-#define TMRR_HAS_ENTRY 0x00000001U /* Already has an entry */
-#define TMRR_INVALID_TYPE 0x00000002U /* Invalid timer id */
-#define TMRR_EMPTY_ENTRY 0x00000003U /* Entry is empty */
-#define TMRR_INVALID_ARG 0x00000004U /* Invalid iface arg */
-
-/* See timer ID defines */
-typedef uint8_t timer_id_t;
-
-/* See timer registry status */
-typedef int tmrr_status_t;
-
-/*
- * Represents a timer, pointer fields
- * are optional and may be set to NULL, therefore
- * it is paramount to verify any function or general
- * pointer field within this struct is checked for
- * a NULL value. Fields should be NULL if the timer
- * driver implementation doesn't implement support
- * for a functionality.
- *
- * XXX: The msleep, usleep, ... functions must return
- * either EXIT_SUCCESS and EXIT_FAILURE from sys/errno.h
- * ONLY.
- */
-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_sec)(void); /* Time since init (seconds) */
- int(*msleep)(size_t ms);
- int(*usleep)(size_t us);
- int(*nsleep)(size_t ns);
- void(*periodic_ms)(size_t ms);
- void(*periodic_us)(size_t ms);
- void(*oneshot_ms)(size_t ms);
- void(*oneshot_us)(size_t ms);
- void(*stop)(void);
-};
-
-tmrr_status_t register_timer(timer_id_t id, const struct timer *tmr);
-tmrr_status_t tmr_registry_overwrite(timer_id_t, const struct timer *tmr);
-tmrr_status_t req_timer(timer_id_t id, struct timer *tmr_out);
-
-#endif /* !_SYS_TIMER_H_ */
diff --git a/sys/include/sys/tty.h b/sys/include/sys/tty.h
deleted file mode 100644
index 18583a5..0000000
--- a/sys/include/sys/tty.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_TTY_H_
-#define _SYS_TTY_H_
-
-#include <sys/termios.h>
-#if defined(_KERNEL)
-#include <sys/types.h>
-#include <sys/spinlock.h>
-#include <sys/device.h>
-#include <dev/vcons/vcons.h>
-#endif
-
-/* TTY ioctl commands */
-#define TCSETS 0x00000000U
-#define TCGETS 0x00000001U
-
-#if defined(_KERNEL)
-#define TTY_RING_SIZE 32
-#define TTY_SOURCE_RAW 0x0001U /* Raw text */
-#define TTY_SOURCE_DEV 0x0002U /* Input from device (e.g keyboard) */
-
-struct tty_ring {
- char data[TTY_RING_SIZE]; /* Ring data */
- off_t enq_index; /* Enqueue index */
- off_t deq_index; /* Dequeue index */
-};
-
-struct tty {
- dev_t id;
- struct vcons_screen *scr; /* Console screen */
- struct tty_ring ring; /* Input ring */
- struct tty_ring outring; /* Output ring */
- struct spinlock rlock; /* Ring lock */
- struct termios termios; /* Termios structure */
- struct device *dev; /* Device pointer */
-};
-
-extern struct tty g_root_tty;
-
-dev_t tty_attach(struct tty *tty);
-int tty_putc(struct tty *tty, int c, int flags);
-int tty_putstr(struct tty *tty, const char *s, size_t count);
-ssize_t tty_flush(struct tty *tty);
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SYS_TTY_H_ */
diff --git a/sys/include/sys/types.h b/sys/include/sys/types.h
deleted file mode 100644
index 8636d4b..0000000
--- a/sys/include/sys/types.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_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;
-typedef int pid_t;
-typedef int dev_t;
-
-#if defined(_KERNEL)
-typedef uintptr_t vaddr_t; /* Virtual address */
-typedef uintptr_t paddr_t; /* Physical address */
-typedef uint32_t vm_prot_t; /* Access flags */
-#endif /* defined(_KERNEL) */
-
-#endif /* !_SYS_TYPES_H_ */
diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h
deleted file mode 100644
index 1f7e423..0000000
--- a/sys/include/sys/vfs.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_VFS_H_
-#define _SYS_VFS_H_
-
-#include <sys/mount.h>
-#include <sys/vnode.h>
-#include <sys/types.h>
-#include <sys/sio.h>
-
-/* Max path length */
-#define PATH_MAX 1024
-
-#if defined(_KERNEL)
-
-extern struct vnode *g_root_vnode;
-
-void vfs_init(void);
-struct fs_info *vfs_byname(const char *name);
-
-int vfs_vget(struct vnode *parent, const char *name, struct vnode **vp);
-int vfs_path_to_node(const char *path, struct vnode **vp);
-
-char *vfs_get_fname_at(const char *path, size_t idx);
-int vfs_rootname(const char *path, char **new_path);
-
-bool vfs_is_valid_path(const char *path);
-ssize_t vfs_hash_path(const char *path);
-
-ssize_t vfs_read(struct vnode *vp, struct sio_txn *sio);
-ssize_t vfs_write(struct vnode *vp, struct sio_txn *sio);
-
-int vfs_getattr(struct vnode *vp, struct vattr *vattr);
-int vfs_open(struct vnode *vp);
-
-int vfs_close(struct vnode *vp);
-uint64_t sys_mount(struct syscall_args *args);
-
-#endif /* defined(_KERNEL) */
-#endif /* !_SYS_VFS_H_ */
diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h
deleted file mode 100644
index 8201f94..0000000
--- a/sys/include/sys/vnode.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_VNODE_H_
-#define _SYS_VNODE_H_
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/mount.h>
-#include <vm/obj.h>
-#include <sys/sio.h>
-
-struct vnode;
-struct vattr;
-
-struct vops {
- int(*vget)(struct vnode *parent, const char *name, struct vnode **vp);
- int(*read)(struct vnode *vp, struct sio_txn *sio);
- int(*write)(struct vnode *vp, struct sio_txn *sio);
- int(*getattr)(struct vnode *vp, struct vattr *vattr);
- int(*open)(struct vnode *vp);
- int(*close)(struct vnode *vp);
-};
-
-struct vattr {
- size_t size; /* File size in bytes */
- int type; /* Vnode type */
-};
-
-struct vnode {
- int type;
- int flags;
- struct vm_object *vmobj;
- struct mount *mp; /* Ptr to vfs vnode is in */
- struct vops *vops;
- struct vnode *parent;
- struct fs_info *fs; /* Filesystem this vnode belongs to, can be NULL */
- void *data; /* Filesystem specific data */
-};
-
-/*
- * Vnode type flags
- */
-#define VREG 0x01 /* Regular file */
-#define VDIR 0x02 /* Directory */
-#define VCHR 0x03 /* Character device */
-#define VBLK 0x04 /* Block device */
-
-#if defined(_KERNEL)
-int vfs_alloc_vnode(struct vnode **vnode, struct mount *mp, int type);
-#endif
-
-#endif
diff --git a/sys/include/vm/dynalloc.h b/sys/include/vm/dynalloc.h
deleted file mode 100644
index 44d2f5a..0000000
--- a/sys/include/vm/dynalloc.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/*
- * For documentation: See dynalloc(9)
- */
-
-#ifndef _VM_DYNALLOC_H_
-#define _VM_DYNALLOC_H_
-
-#include <sys/types.h>
-
-void *dynalloc(size_t sz);
-void *dynalloc_memalign(size_t sz, size_t align);
-void *dynrealloc(void *old_ptr, size_t newsize);
-void dynfree(void *ptr);
-
-#endif /* !_VM_DYNALLOC_H_ */
diff --git a/sys/include/vm/fault.h b/sys/include/vm/fault.h
deleted file mode 100644
index f0e308c..0000000
--- a/sys/include/vm/fault.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_FAULT_H_
-#define _VM_FAULT_H_
-
-#include <sys/types.h>
-#include <vm/pmap.h>
-
-int vm_fault(vaddr_t va, vm_prot_t access_type);
-
-#endif /* !_VM_FAULT_H_ */
diff --git a/sys/include/vm/map.h b/sys/include/vm/map.h
deleted file mode 100644
index a1e74d9..0000000
--- a/sys/include/vm/map.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_MMAP_H_
-#define _VM_MMAP_H_
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/queue.h>
-#include <sys/syscall.h>
-#include <sys/spinlock.h>
-#include <vm/pmap.h>
-#include <vm/vm.h>
-
-#define MAP_SHARED 0x0001
-#define MAP_PRIVATE 0x0002
-#define MAP_ANONYMOUS 0x0010
-#define MAP_FAILED ((void *)-1)
-
-/* Memory map table entry count */
-#define MTAB_ENTRIES 32
-
-struct vm_object;
-
-struct vm_mapping {
- TAILQ_ENTRY(vm_mapping) link;
- struct vm_range range;
- struct vm_object *vmobj;
- paddr_t physmem_base;
- vm_prot_t prot;
-
- /* Private */
- size_t vhash; /* Virtual address hash */
-};
-
-typedef TAILQ_HEAD(, vm_mapping) vm_mapq_t;
-
-struct vm_mapspace {
- vm_mapq_t mtab[MTAB_ENTRIES]; /* Map table */
- size_t map_count;
-};
-
-/* Mapping operations */
-int vm_map_destroy(struct vas vas, vaddr_t va, size_t bytes);
-int vm_map_create(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot,
- size_t bytes);
-
-/* Syscalls */
-uint64_t sys_mmap(struct syscall_args *args);
-uint64_t sys_munmap(struct syscall_args *args);
-
-/* Mapespace operations */
-void vm_mapspace_insert(struct vm_mapspace *ms, struct vm_mapping *mapping);
-void vm_mapspace_remove(struct vm_mapspace *ms, struct vm_mapping *mapping);
-struct vm_mapping *vm_mapping_fetch(struct vm_mapspace *ms, vaddr_t va);
-void vm_free_mapq(vm_mapq_t *mapq);
-
-#endif /* !_VM_MMAP_H_ */
diff --git a/sys/include/vm/obj.h b/sys/include/vm/obj.h
deleted file mode 100644
index 6e24516..0000000
--- a/sys/include/vm/obj.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_OBJ_H_
-#define _VM_OBJ_H_
-
-#include <sys/spinlock.h>
-#include <sys/types.h>
-#include <sys/vnode.h>
-#include <vm/map.h>
-#include <vm/pager.h>
-
-struct vm_object {
- struct spinlock lock; /* Protects this object */
- struct vm_mapspace mapspace; /* Mapspace this object points to */
- struct vm_pagerops *pgops; /* Pager operations */
-
- uint8_t is_anon : 1; /* Is an anonymous mapping */
- uint8_t demand : 1; /* Only mapped upon access */
- int ref; /* Ref count */
- struct vnode *vnode; /* Only used if `is_anon` is 0 */
-};
-
-#define vm_object_ref(OBJPTR) (++(OBJPTR)->ref)
-#define vm_object_unref(OBJPTR) do { \
- if ((OBJPTR)->ref > 0) { \
- --(OBJPTR)->ref; \
- } \
- } while (0);
-
-size_t vm_obj_count(void);
-int vm_obj_init(struct vm_object **res, struct vnode *vnode);
-int vm_obj_destroy(struct vm_object *obj);
-
-#endif /* !_VM_OBJ_H_ */
diff --git a/sys/include/vm/page.h b/sys/include/vm/page.h
deleted file mode 100644
index 80fa74f..0000000
--- a/sys/include/vm/page.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_PAGE_H_
-#define _VM_PAGE_H_
-
-#include <sys/types.h>
-
-struct vm_page {
- paddr_t physaddr;
-};
-
-void vm_zero_page(void *page, size_t page_count);
-
-#endif /* !_VM_PAGE_H_ */
diff --git a/sys/include/vm/pager.h b/sys/include/vm/pager.h
deleted file mode 100644
index e57afe1..0000000
--- a/sys/include/vm/pager.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_PAGER_H_
-#define _VM_PAGER_H_
-
-#include <sys/types.h>
-#include <vm/page.h>
-
-struct vm_object;
-
-struct vm_pagerops {
- int(*get)(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg);
- int(*store)(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg);
- /* TODO: Remove this and add demand paging */
- int(*get_paddr)(struct vm_object *obj, paddr_t *paddr, vm_prot_t prot);
-};
-
-extern struct vm_pagerops g_vnode_pagerops;
-extern struct vm_pagerops g_dev_pagerops;
-
-int vm_pager_get(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg);
-int vm_pager_paddr(struct vm_object *obj, paddr_t *paddr, vm_prot_t prot);
-
-#endif /* !_VM_PAGER_H_ */
diff --git a/sys/include/vm/physseg.h b/sys/include/vm/physseg.h
deleted file mode 100644
index 956f82f..0000000
--- a/sys/include/vm/physseg.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_VM_PHYSSEG_H_
-#define _VM_VM_PHYSSEG_H_
-
-#include <sys/types.h>
-
-struct physmem_stat {
- size_t reserved_kib; /* Reserved memory */
- size_t total_kib; /* Total memory */
- size_t avl_kib; /* Available memory */
- size_t alloc_kib; /* Allocated physical memory */
-};
-
-void vm_physseg_init(void);
-uintptr_t vm_alloc_pageframe(size_t count);
-
-void vm_free_pageframe(uintptr_t base, size_t count);
-struct physmem_stat vm_phys_memstat(void);
-
-#endif /* !_VM_VM_PHYSSEG_H_ */
diff --git a/sys/include/vm/pmap.h b/sys/include/vm/pmap.h
deleted file mode 100644
index cb18885..0000000
--- a/sys/include/vm/pmap.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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_PMAP_H_
-#define _VM_PMAP_H_
-
-/*
- * Each architecture is expected to implement
- * this header. It should contain a `struct vas'
- * which will contain information about a VAS
- * (virtual address space)
- *
- * On AMD64 this struct contains: PML4, etc
- *
- * XXX: Compiler errors pointing to this include means you
- * forgot to implement it!!!
- *
- * `struct vas' MUST have a `struct spinlock lock' field!!!
- */
-#include <machine/vas.h>
-
-#include <vm/tlsf.h>
-#include <sys/types.h>
-#include <sys/spinlock.h>
-
-/* prot flags for mappings */
-#define PROT_WRITE __BIT(0) /* Writable */
-#define PROT_EXEC __BIT(1) /* Executable */
-#define PROT_USER __BIT(2) /* User accessible */
-
-/* Caching types */
-#define VM_CACHE_UC 0x00000U /* Uncachable */
-#define VM_CACHE_WT 0x00001U /* Write-through */
-
-#define is_vas_valid(vas) (vas.top_level != 0)
-
-/*
- * vm_ctx - Per core virtual memory context
- */
-struct vm_ctx {
- uintptr_t dynalloc_pool_phys;
- size_t dynalloc_pool_sz; /* In bytes */
- tlsf_t tlsf_ctx;
- struct spinlock dynalloc_lock;
-};
-
-/*
- * Mark a virtual address with a specific caching
- * type.
- */
-int pmap_set_cache(struct vm_ctx *, struct vas, vaddr_t, int);
-
-/*
- * Create a virtual address space
- * and return the descriptor.
- */
-int pmap_create_vas(struct vm_ctx *, struct vas *);
-
-/*
- * Switch the current virtual address space
- * to another.
- */
-void pmap_switch_vas(struct vm_ctx *, struct vas);
-
-/*
- * Read virtual address space descriptor
- * and return it.
- */
-struct vas pmap_read_vas(void);
-
-/*
- * Map a physical address to a virtual address.
- */
-int pmap_map(struct vm_ctx *, struct vas, vaddr_t, paddr_t, vm_prot_t);
-
-/*
- * Get rid of a virtual address space and free
- * resources.
- */
-int pmap_free_vas(struct vm_ctx *, struct vas);
-
-/*
- * Unmap a page.
- */
-int pmap_unmap(struct vm_ctx *, struct vas, vaddr_t);
-
-/*
- * Architecture specific init code for pmap
- */
-int pmap_init(struct vm_ctx *);
-#endif /* _VM_PMAP_H_ */
diff --git a/sys/include/vm/tlsf.h b/sys/include/vm/tlsf.h
deleted file mode 100644
index e9b5a91..0000000
--- a/sys/include/vm/tlsf.h
+++ /dev/null
@@ -1,90 +0,0 @@
-#ifndef INCLUDED_tlsf
-#define INCLUDED_tlsf
-
-/*
-** Two Level Segregated Fit memory allocator, version 3.1.
-** Written by Matthew Conte
-** http://tlsf.baisoku.org
-**
-** Based on the original documentation by Miguel Masmano:
-** http://www.gii.upv.es/tlsf/main/docs
-**
-** This implementation was written to the specification
-** of the document, therefore no GPL restrictions apply.
-**
-** Copyright (c) 2006-2016, Matthew Conte
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * 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.
-** * Neither the name of the copyright holder 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 MATTHEW CONTE BE LIABLE FOR ANY
-** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stddef.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
-/* pool_t: a block of memory that TLSF can manage. */
-typedef void* tlsf_t;
-typedef void* pool_t;
-
-/* Create/destroy a memory pool. */
-tlsf_t tlsf_create(void* mem);
-tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
-void tlsf_destroy(tlsf_t tlsf);
-pool_t tlsf_get_pool(tlsf_t tlsf);
-
-/* Add/remove memory pools. */
-pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
-void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
-
-/* malloc/memalign/realloc/free replacements. */
-void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
-void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
-void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
-void tlsf_free(tlsf_t tlsf, void* ptr);
-
-/* Returns internal block size, not original request size */
-size_t tlsf_block_size(void* ptr);
-
-/* Overheads/limits of internal structures. */
-size_t tlsf_size(void);
-size_t tlsf_align_size(void);
-size_t tlsf_block_size_min(void);
-size_t tlsf_block_size_max(void);
-size_t tlsf_pool_overhead(void);
-size_t tlsf_alloc_overhead(void);
-
-/* Debugging. */
-typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
-void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
-/* Returns nonzero if any internal consistency check fails. */
-int tlsf_check(tlsf_t tlsf);
-int tlsf_check_pool(pool_t pool);
-
-#if defined(__cplusplus)
-};
-#endif
-
-#endif
diff --git a/sys/include/vm/vm.h b/sys/include/vm/vm.h
deleted file mode 100644
index 1c23b8a..0000000
--- a/sys/include/vm/vm.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-
-/*
- * For documentation: See vm(9)
- */
-
-#ifndef _VM_H_
-#define _VM_H_
-
-#include <sys/types.h>
-#include <sys/limine.h>
-#include <sys/cdefs.h>
-#include <vm/page.h>
-#include <vm/pmap.h>
-#include <vm/physseg.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 *)((uintptr_t)phys + VM_HIGHER_HALF)
-#define VIRT_TO_PHYS(virt) ((uintptr_t)virt - VM_HIGHER_HALF)
-
-struct vm_range {
- uintptr_t start;
- uintptr_t end;
-};
-
-struct vm_memstat {
- struct physmem_stat pmem_stat;
- size_t vmobj_cnt;
-};
-
-/*
- * Returns the machine's pagesize:
- *
- * XXX TODO: This needs to be moved to vmm_init.c
- * while returning a non-constant value.
- */
-static inline size_t
-vm_get_page_size(void)
-{
- return 4096;
-}
-
-void vm_init(void);
-struct vm_ctx *vm_get_ctx(void);
-struct vas vm_get_kvas(void);
-struct vm_memstat vm_memstat(void);
-
-#endif /* !_VM_H_ */
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
deleted file mode 100644
index 847f4a6..0000000
--- a/sys/kern/init_main.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-#include <sys/machdep.h>
-#include <sys/timer.h>
-#include <sys/sched.h>
-#include <sys/tty.h>
-#include <sys/vfs.h>
-#include <sys/driver.h>
-#include <machine/cpu_mp.h>
-#include <firmware/acpi/acpi.h>
-#include <vm/physseg.h>
-#include <logo.h>
-
-__MODULE_NAME("init_main");
-__KERNEL_META("$Hyra$: init_main.c, Ian Marco Moffett, "
- "Where the Hyra kernel first starts up");
-
-static inline void
-log_timer(const char *purpose, tmrr_status_t s, const struct timer *tmr)
-{
- if (s == TMRR_EMPTY_ENTRY) {
- kprintf("init_main: %s not yet registered\n", purpose);
- } else if (tmr->name == NULL) {
- kprintf("init_main: Nameless %s registered; unknown\n", purpose);
- } else {
- kprintf("init_main: %s registered: %s\n", purpose, tmr->name);
- }
-}
-
-/*
- * Logs what timers are registered
- * on the system.
- */
-static void
-list_timers(void)
-{
- struct timer timer_tmp;
- tmrr_status_t status;
-
- status = req_timer(TIMER_SCHED, &timer_tmp);
- log_timer("SCHED_TMR", status, &timer_tmp);
-
- status = req_timer(TIMER_GP, &timer_tmp);
- log_timer("GENERAL_PURPOSE_TMR", status, &timer_tmp);
-}
-
-void
-main(void)
-{
- struct cpu_info *ci;
- int status;
-
- __TRY_CALL(pre_init);
- syslog_init();
- PRINT_LOGO();
-
- kprintf("Hyra/%s v%s: %s (%s)\n",
- HYRA_ARCH, HYRA_VERSION, HYRA_BUILDDATE,
- HYRA_BUILDBRANCH);
-
- acpi_init();
- __TRY_CALL(chips_init);
-
- processor_init();
- list_timers();
- vfs_init();
-
- /* Attach the root TTY */
- if ((status = tty_attach(&g_root_tty)) < 0)
- kprintf("Failed to attach root TTY (got %d)\n", status);
-
- DRIVERS_INIT();
- sched_init();
- ci = this_cpu();
-
- /* Stop writing kernel messages to TTY */
- g_syslog_use_tty = false;
-
- __TRY_CALL(ap_bootstrap, ci);
- sched_enter();
-
- while (1);
- __builtin_unreachable();
-}
diff --git a/sys/kern/kern_cpu.c b/sys/kern/kern_cpu.c
deleted file mode 100644
index 1779244..0000000
--- a/sys/kern/kern_cpu.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cpu.h>
-#include <sys/types.h>
-#include <sys/panic.h>
-#include <sys/machdep.h>
-#include <vm/dynalloc.h>
-#include <assert.h>
-
-__MODULE_NAME("kern_cpu");
-__KERNEL_META("$Hyra$: kern_cpu.c, Ian Marco Moffett, "
- "Machine independent CPU interface");
-
-#define CI_LIST_SZ \
- sizeof(struct cpu_info *) * (MAXCPUS + 1)
-
-static size_t ncpu = 0;
-static struct cpu_info **ci_list = NULL;
-
-void
-cpu_attach(struct cpu_info *ci)
-{
- if ((ci->idx = ncpu++) >= (MAXCPUS + 1)) {
- panic("Machine core count exceeds MAXCPUS!\n");
- }
-
- if (ci_list == NULL) {
- ci_list = dynalloc(CI_LIST_SZ);
- __assert(ci_list != NULL);
- }
-
- ci_list[cpu_index(ci)] = ci;
-}
-
-struct cpu_info *
-cpu_get(size_t i)
-{
- if (i >= ncpu || ci_list == NULL) {
- return NULL;
- }
-
- return ci_list[i];
-}
-
-size_t
-cpu_count(void)
-{
- return ncpu;
-}
diff --git a/sys/kern/kern_device.c b/sys/kern/kern_device.c
deleted file mode 100644
index cbba965..0000000
--- a/sys/kern/kern_device.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/device.h>
-#include <sys/queue.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/spinlock.h>
-
-static TAILQ_HEAD(, device) devices;
-static struct spinlock devices_lock = {0};
-static bool device_list_init = false;
-
-dev_t
-device_alloc_major(void)
-{
- static dev_t major = 1;
- return major++;
-}
-
-struct device *
-device_fetch(dev_t major, dev_t minor)
-{
- struct device *dev;
-
- TAILQ_FOREACH(dev, &devices, link) {
- if (dev->major == major && dev->minor == minor) {
- return dev;
- }
- }
-
- return NULL;
-}
-
-dev_t
-device_create(struct device *dev, dev_t major, dev_t minor)
-{
- if (dev == NULL || minor == 0) {
- return -EINVAL;
- }
-
- if (major == 0) {
- return -EINVAL;
- }
-
- if (!device_list_init) {
- TAILQ_INIT(&devices);
- device_list_init = true;
- }
-
- dev->major = major;
- dev->minor = minor;
-
- spinlock_acquire(&devices_lock);
- TAILQ_INSERT_HEAD(&devices, dev, link);
- spinlock_release(&devices_lock);
- return dev->major;
-}
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
deleted file mode 100644
index 202da23..0000000
--- a/sys/kern/kern_exec.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/sched.h>
-#include <sys/system.h>
-#include <sys/errno.h>
-#include <sys/vfs.h>
-#include <sys/exec.h>
-#include <sys/filedesc.h>
-#include <sys/signal.h>
-#include <sys/loader.h>
-#include <sys/cdefs.h>
-#include <vm/dynalloc.h>
-#include <sys/syslog.h>
-#include <string.h>
-
-__MODULE_NAME("exec");
-__KERNEL_META("$Hyra$: kern_exec.c, Ian Marco Moffett, "
- "exec() implementation");
-
-#define ARG_MAX 1024
-
-/*
- * Allocates a buffer in in `res' and fetches
- * the args from `argv'
- *
- * @argv: User argv
- * @res: Exec args result.
- *
- * XXX: res->argp is dynamically allocated, remember
- * to free it!
- */
-static int
-exec_get_args(char **argv, struct exec_args *res)
-{
- static char *dmmy_envp[] = {NULL};
- const size_t ARG_LEN = sizeof(char) * ARG_MAX;
- char *argp = NULL;
- void *tmp;
-
- struct proc *td;
- size_t argp_len = 0;
-
- if (res == NULL)
- return -EINVAL;
-
- /* Allocate argp */
- res->argp = dynalloc(ARG_LEN);
- if (res->argp == NULL)
- return -ENOMEM;
-
- td = this_td();
- res->vas = td->addrsp;
- res->envp = dmmy_envp;
-
- /* Read argv */
- copyin((uintptr_t)argv, &argp, sizeof(char *));
- for (;;) {
- if (argp == NULL) {
- res->argp[argp_len] = NULL;
- break;
- }
-
- /* Fetch this arg and get next argp */
- copyinstr((uintptr_t)argp, res->argp[argp_len++], ARG_MAX);
- copyin((uintptr_t)++argv, &argp, sizeof(char *));
-
- /* Try to resize the argp buffer */
- tmp = dynrealloc(res->argp, ARG_LEN * (argp_len + 1));
- if (tmp == NULL) {
- dynfree(res->argp);
- return -ENOMEM;
- }
- res->argp = tmp;
- }
-
- return 0;
-}
-
-/*
- * Reset the stack of the process.
- *
- * @td: Target thread.
- * @args: Exec args.
- *
- * Returns the new stack pointer.
- */
-static uintptr_t
-exec_set_stack(struct proc *td, struct exec_args args)
-{
- struct vm_range *stack_range;
- uintptr_t stack_top, sp;
-
- stack_range = &td->addr_range[ADDR_RANGE_STACK];
- stack_top = stack_range->start + (PROC_STACK_SIZE);
-
- sp = loader_init_stack((void *)stack_top, args);
- return sp;
-}
-
-/*
- * execv() implementation.
- *
- * @pathname: Path of file to execute.
- * @argv: Args.
- * @sp_res: Pointer to new stack pointer
- */
-static int
-execv(char *pathname, char **argv, uintptr_t *sp_res)
-{
- char *bin = NULL;
- struct filedesc *filedes;
- struct vm_range *exec_range;
- struct exec_args args;
-
- struct proc *td = this_td();
- int fd, ret = 0;
- int status;
- size_t bin_size;
-
- if ((status = exec_get_args(argv, &args)) != 0)
- return status;
-
- spinlock_acquire(&td->lock);
- fd = open(pathname, O_RDONLY);
-
- if (fd < 0) {
- ret = -ENOENT;
- goto done;
- }
-
- filedes = fd_from_fdnum(td, fd);
- if (__unlikely(filedes == NULL)) {
- /*
- * Should not happen. The kernel might be in some
- * erroneous state.
- */
- ret = -EIO;
- goto done;
- }
-
- lseek(fd, 0, SEEK_END);
- bin_size = filedes->offset;
- lseek(fd, 0, SEEK_SET);
-
- /* Allocate memory for the binary */
- bin = dynalloc(bin_size);
- if (bin == NULL) {
- ret = -ENOMEM;
- goto done;
- }
-
- /* Read-in the binary */
- if ((status = read(fd, bin, bin_size)) < 0) {
- ret = status;
- goto done;
- }
-
- /*
- * Unload the current process image. After we do this,
- * we cannot return in this state until we replace it.
- *
- * XXX: This is one of the last things we do in case of
- * errors.
- */
- exec_range = &td->addr_range[ADDR_RANGE_EXEC];
- loader_unload(td->addrsp, exec_range);
-
- /*
- * Now we try to load the new program and hope everything
- * works... If something goes wrong here then we'll be forced
- * to send a SIGSEGV to the thread.
- */
- status = loader_load(td->addrsp, bin, &args.auxv, 0, NULL, exec_range);
- if (status != 0) {
- /* Well shit */
- kprintf("exec: Failed to load new process image\n");
- signal_raise(td, SIGSEGV);
- for (;;);
- }
-
- *sp_res = exec_set_stack(td, args);
- set_frame_ip(td->tf, args.auxv.at_entry);
-done:
- /* We are done, cleanup and release the thread */
- if (bin != NULL) dynfree(bin);
- fd_close_fdnum(td, fd);
- dynfree(args.argp);
- spinlock_release(&td->lock);
- return ret;
-}
-
-/*
- * Arg0: Pathname
- * Arg1: Argv
- */
-uint64_t
-sys_execv(struct syscall_args *args)
-{
- uintptr_t sp;
- char pathname[PATH_MAX];
- char **argv = (char **)args->arg1;
-
- int status;
- struct proc *td = this_td();
-
- copyinstr(args->arg0, pathname, PATH_MAX);
- if ((status = execv(pathname, argv, &sp)) != 0)
- return status;
-
- args->ip = get_frame_ip(td->tf);
- args->sp = sp;
- return 0;
-}
diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c
deleted file mode 100644
index 17a3d84..0000000
--- a/sys/kern/kern_filedesc.c
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/filedesc.h>
-#include <sys/proc.h>
-#include <sys/sio.h>
-#include <sys/sched.h>
-#include <sys/errno.h>
-#include <sys/system.h>
-#include <sys/syslog.h>
-#include <sys/vfs.h>
-#include <sys/signal.h>
-#include <sys/vnode.h>
-#include <vm/dynalloc.h>
-#include <dev/vcons/vcons.h>
-#include <assert.h>
-#include <string.h>
-
-#define MAX_RW_SIZE 0x7FFFF000
-
-/*
- * This function is a helper for write(). It creates
- * a buffer and copies write data to it.
- *
- * @td: Current thread.
- * @data: Data to copy.
- * @buf_out: Pointer to buffer that will store data.
- * @count: Number of bytes.
- */
-static int
-make_write_buf(struct proc *td, const void *data, char **buf_out, size_t count)
-{
- char *buf = NULL;
-
- /* Count cannot be 0 or exceed the max size */
- if (count > MAX_RW_SIZE || count == 0) {
- return -EINVAL;
- }
-
- buf = dynalloc(count);
-
- if (buf == NULL) {
- return -ENOMEM;
- }
-
- __assert(buf_out != NULL);
- *buf_out = buf;
-
- memset(buf, 0, count);
-
- if (td->is_user) {
- /*
- * A user process called us, so we want to be careful
- * and use copyin()
- */
- if (copyin((uintptr_t)data, buf, count) != 0) {
- signal_raise(NULL, SIGSEGV);
- }
- } else {
- /* Can just memcpy() here */
- memcpy(buf, (char *)data, count);
- }
-
- return 0;
-}
-
-/*
- * Helper function for write()
- */
-static ssize_t
-do_write(struct vnode *vp, char *buf, size_t count)
-{
- struct sio_txn sio = { .buf = buf, .len = count };
- struct vops *vops = vp->vops;
- int status;
-
- __assert(vops != NULL);
-
- /* Can we call the write operation? */
- if (vops->write == NULL) {
- return -EACCES;
- }
-
- /* Attempt a write */
- if ((status = vops->write(vp, &sio)) < 0) {
- return status;
- }
-
- return count;
-}
-
-/*
- * Allocate a file descriptor.
- *
- * @td: Thread to allocate from, NULL for current thread.
- * @fd_out: Pointer to allocated file descriptor output.
- *
- * This routine will create a new file descriptor
- * table entry.
- *
- * Returns 0 on success.
- */
-int
-fd_alloc(struct proc *td, struct filedesc **fd_out)
-{
- struct filedesc *fd;
-
- if (td == NULL) {
- td = this_td();
- __assert(td != NULL);
- }
-
- /* Find free fd table entry */
- for (size_t i = 0; i < PROC_MAX_FDS; ++i) {
- if (td->fds[i] != NULL) {
- /* In use */
- continue;
- }
-
- fd = dynalloc(sizeof(struct filedesc));
- memset(fd, 0, sizeof(struct filedesc));
-
- if (fd == NULL) {
- return -ENOMEM;
- }
-
- fd->fdno = i;
- td->fds[i] = fd;
-
- if (fd_out != NULL)
- *fd_out = fd;
-
- return 0;
- }
-
- return -EMFILE;
-}
-
-/*
- * Fetch a file descriptor from a file descriptor
- * number.
- *
- * @td: Thread to fetch from, NULL for current thread.
- * @fdno: File descriptor to fetch
- */
-struct filedesc *
-fd_from_fdnum(const struct proc *td, int fdno)
-{
- if (td == NULL) {
- td = this_td();
- __assert(td != NULL);
- }
-
- if (fdno < 0 || fdno > PROC_MAX_FDS) {
- return NULL;
- }
-
- return td->fds[fdno];
-}
-
-/*
- * Close a file descriptor from its fd number.
- *
- * @td: Thread to fetch from, NULL for current thread.
- * @fdno: File descriptor number to close.
- */
-void
-fd_close_fdnum(struct proc *td, int fdno)
-{
- struct filedesc *fd;
-
- if (td == NULL) {
- td = this_td();
- __assert(td != NULL);
- }
-
- fd = fd_from_fdnum(td, fdno);
- if (fd == NULL) {
- return;
- }
-
- if (fd->vnode != NULL) {
- vfs_close(fd->vnode);
- }
-
- dynfree(fd);
- td->fds[fdno] = NULL;
-}
-
-ssize_t
-write(int fd, const void *buf, size_t count)
-{
- struct proc *td = this_td();
- struct filedesc *desc = NULL;
- struct vnode *vp = NULL;
- char *in_buf = NULL;
-
- ssize_t ret = count;
- int status;
-
- /*
- * Create our write buffer... Memory will be allocated
- * and data copied.
- */
- if ((status = make_write_buf(td, buf, &in_buf, count)) != 0) {
- return status;
- }
-
- /* Is this stdout/stderr? */
- if (fd == 1 || fd == 2) {
- /* TODO: Update this when we have PTYs */
- vcons_putstr(&g_syslog_screen, in_buf, count);
- return count;
- }
-
- desc = fd_from_fdnum(td, fd);
- if (desc == NULL) {
- return -EBADF;
- }
-
- mutex_acquire(&desc->lock);
- if (desc->oflag != O_WRONLY && desc->oflag != O_WRONLY) {
- ret = -EACCES;
- goto cleanup;
- }
-
- /* Does this file descriptor exist? */
- if (desc == NULL) {
- ret = -EBADF;
- goto cleanup;
- }
-
- /* Do we have a vnode? */
- if (desc->vnode == NULL) {
- ret = -EACCES;
- goto cleanup;
- }
-
- vp = desc->vnode;
- status = do_write(vp, in_buf, count);
-
- if (status < 0) {
- ret = status;
- goto cleanup;
- }
-cleanup:
- mutex_release(&desc->lock);
- dynfree(in_buf);
- return ret;
-}
-
-/*
- * Open a file and return a file descriptor.
- *
- * @pathname: File path.
- * @oflag: Flags.
- */
-int
-open(const char *pathname, int oflag)
-{
- struct vnode *vp;
- struct filedesc *fd;
- int status;
-
- /*
- * Attempt to create a vnode, call the open hook then
- * allocate a file descriptor
- */
- if ((status = vfs_path_to_node(pathname, &vp)) != 0) {
- return status;
- }
- if ((status = vfs_open(vp)) != 0) {
- return status;
- }
- if ((status = fd_alloc(this_td(), &fd)) != 0) {
- return status;
- }
-
- fd->oflag = oflag;
- fd->vnode = vp;
- fd->is_dir = (vp->type == VDIR);
- return fd->fdno;
-}
-
-/*
- * Read file into a buffer.
- *
- * @fd: File descriptor number.
- * @buf: Buffer to read to.
- * @count: Number of bytes to read.
- */
-int
-read(int fd, void *buf, size_t count)
-{
- ssize_t bytes_read;
- struct vnode *vnode;
- struct filedesc *fd_desc;
- struct sio_txn sio = {
- .buf = buf,
- .len = count,
- .type = SIO_NONE
- };
-
- fd_desc = fd_from_fdnum(this_td(), fd);
- if (fd_desc == NULL) {
- return -EBADF;
- }
-
- mutex_acquire(&fd_desc->lock);
- if (fd_desc->oflag == O_WRONLY) {
- bytes_read = -EACCES;
- goto done;
- }
-
- sio.offset = fd_desc->offset;
- vnode = fd_desc->vnode;
-
- if (count > MAX_RW_SIZE) {
- bytes_read = -EACCES;
- goto done;
- }
-
- bytes_read = vfs_read(vnode, &sio);
- fd_desc->offset += bytes_read;
-done:
- mutex_release(&fd_desc->lock);
- return bytes_read;
-}
-
-/*
- * Reposition the file offset
- *
- * @fd: File descriptor.
- * @offset: Offset for the reposition
- * @whence: SEEK_SET, SEEK_CUR, or SEEK_END
- *
- * TODO: Implement SEEK_END
- */
-off_t
-lseek(int fd, off_t offset, int whence)
-{
- struct filedesc *fd_desc;
- struct vattr vattr;
-
- fd_desc = fd_from_fdnum(this_td(), fd);
-
- if (fd_desc == NULL) {
- return -EBADF;
- }
-
- if (vfs_getattr(fd_desc->vnode, &vattr) != 0) {
- return -1;
- }
-
- switch (whence) {
- case SEEK_SET:
- if (offset > vattr.size)
- return -ESPIPE;
-
- fd_desc->offset = offset;
- break;
- case SEEK_CUR:
- if ((fd_desc->offset + offset) > vattr.size)
- return -ESPIPE;
-
- fd_desc->offset += offset;
- break;
- case SEEK_END:
- fd_desc->offset = vattr.size;
- break;
- default:
- return -EINVAL;
- }
-
- return fd_desc->offset;
-}
-
-/*
- * arg0: int fd
- * arg1: const void *buf
- * arg2: count
- */
-uint64_t
-sys_write(struct syscall_args *args)
-{
- return write(args->arg0, (void *)args->arg1, args->arg2);
-}
-
-/*
- * arg0: const char *pathname
- * arg1: int oflag
- */
-uint64_t
-sys_open(struct syscall_args *args)
-{
- char *pathbuf = dynalloc(sizeof(char) * PATH_MAX);
- int ret;
-
- if (pathbuf == NULL) {
- return -ENOMEM;
- }
-
- if (copyinstr(args->arg0, pathbuf, PATH_MAX) != 0) {
- signal_raise(NULL, SIGSEGV);
- }
-
- ret = open(pathbuf, args->arg1);
- dynfree(pathbuf);
- return ret;
-}
-
-/*
- * arg0: fd
- */
-uint64_t
-sys_close(struct syscall_args *args)
-{
- fd_close_fdnum(this_td(), args->arg0);
- return 0;
-}
-
-/*
- * arg0: fd
- * arg1: char *buf
- * arg2: size_t count
- */
-uint64_t
-sys_read(struct syscall_args *args)
-{
- char *kbuf;
- ssize_t bytes_read;
-
- if (args->arg2 > MAX_RW_SIZE || args->arg2 == 0) {
- return -EINVAL;
- }
-
- kbuf = dynalloc(args->arg2);
- if (kbuf == NULL) {
- return -ENOMEM;
- }
-
- /*
- * Try to read into our kernel buffer then copy out
- * to userspace.
- */
- if ((bytes_read = read(args->arg0, kbuf, args->arg2)) < 0) {
- /* Failure */
- dynfree(kbuf);
- return bytes_read;
- }
- if (copyout(kbuf, args->arg1, bytes_read) != 0) {
- signal_raise(NULL, SIGSEGV);
- }
-
- dynfree(kbuf);
- return bytes_read;
-}
-
-/*
- * arg0: fd
- * arg1: offset:
- * arg2: whence
- */
-uint64_t
-sys_lseek(struct syscall_args *args)
-{
- return lseek(args->arg0, args->arg1, args->arg2);
-}
diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c
deleted file mode 100644
index 0c80334..0000000
--- a/sys/kern/kern_intr.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/intr.h>
-#include <sys/queue.h>
-#include <sys/mutex.h>
-#include <vm/dynalloc.h>
-#include <fs/procfs.h>
-#include <string.h>
-#include <assert.h>
-
-#define PROC_BUF_SIZE 4096
-
-static TAILQ_HEAD(, intr_info) intrlist;
-static struct mutex intrlist_lock = {0};
-static struct proc_entry *proc;
-
-static int
-proc_read(struct proc_entry *entry, struct sio_txn *sio)
-{
- struct intr_info *info;
- char buf[PROC_BUF_SIZE];
- char *p = &buf[0];
- size_t idx = 0, len;
- int res;
-
- mutex_acquire(&intrlist_lock);
- TAILQ_FOREACH(info, &intrlist, link) {
- __assert((sizeof(buf) - idx) > 0);
- res = snprintf(p, sizeof(buf) - idx,
- "CPU%d\t\t%d\t\t%s\t\t%s\n",
- info->affinity,
- info->count,
- info->source,
- info->device
- );
-
- if (res > 0) {
- idx += res;
- p += res;
- }
-
- if (idx >= (PROC_BUF_SIZE - 1)) {
- break;
- }
- }
-
- len = idx + 1;
- buf[idx] = '\0';
-
- if (sio->len > PROC_BUF_SIZE)
- sio->len = PROC_BUF_SIZE;
- if (len > sio->len)
- len = sio->len;
-
- memcpy(sio->buf, buf, len);
- mutex_release(&intrlist_lock);
- return len;
-}
-
-/*
- * Register an interrupt stat
- *
- * @source: Source of interrupt (e.g IOAPIC)
- * @dev: Device (e.g i8042)
- */
-struct intr_info *
-intr_info_alloc(const char *source, const char *dev)
-{
- struct intr_info *intr;
-
- intr = dynalloc(sizeof(*intr));
- if (intr == NULL)
- return NULL;
-
- memset(intr, 0, sizeof(*intr));
- intr->source = source;
- intr->device = dev;
- return intr;
-}
-
-void
-intr_register(struct intr_info *info)
-{
- if (info == NULL)
- return;
-
- TAILQ_INSERT_TAIL(&intrlist, info, link);
-}
-
-void
-intr_init_proc(void)
-{
- /* Init the interrupt list */
- TAILQ_INIT(&intrlist);
-
- /* Setup /proc/interrupts */
- proc = procfs_alloc_entry();
- proc->read = proc_read;
- procfs_add_entry("interrupts", proc);
-}
diff --git a/sys/kern/kern_ioctl.c b/sys/kern/kern_ioctl.c
deleted file mode 100644
index 4b81983..0000000
--- a/sys/kern/kern_ioctl.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/system.h>
-#include <sys/vnode.h>
-#include <sys/filedesc.h>
-#include <sys/syscall.h>
-#include <sys/errno.h>
-#include <sys/sched.h>
-#include <fs/devfs.h>
-
-static int
-do_ioctl(int fd, uint32_t cmd, uintptr_t arg)
-{
- struct proc *td = this_td();
- struct filedesc *filedes;
- struct vnode *vp;
- struct device *dev;
- int status;
-
- filedes = fd_from_fdnum(td, fd);
-
- /* Fetch the vnode */
- if (filedes == NULL)
- return -EBADF;
- if ((vp = filedes->vnode) == NULL)
- return -EIO;
-
- if ((status = devfs_get_dev(vp, &dev)) != 0)
- return status;
- if (dev->ioctl == NULL)
- return -EIO;
-
- return dev->ioctl(dev, cmd, arg);
-}
-
-/*
- * Arg0: Fd.
- * Arg1: Cmd.
- * Arg2: Arg.
- */
-uint64_t
-sys_ioctl(struct syscall_args *args)
-{
- return do_ioctl(args->arg0, args->arg1, args->arg2);
-}
diff --git a/sys/kern/kern_loader.c b/sys/kern/kern_loader.c
deleted file mode 100644
index 8edc160..0000000
--- a/sys/kern/kern_loader.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/loader.h>
-#include <sys/cdefs.h>
-#include <sys/elf.h>
-#include <sys/types.h>
-#include <sys/syslog.h>
-#include <sys/errno.h>
-#include <sys/proc.h>
-#include <vm/vm.h>
-#include <vm/map.h>
-#include <vm/physseg.h>
-#include <vm/dynalloc.h>
-#include <string.h>
-#include <assert.h>
-
-__MODULE_NAME("kern_loader");
-__KERNEL_META("$Hyra$: kern_loader.c, Ian Marco Moffett, "
- "Kernel ELF loader");
-
-#define pr_trace(fmt, ...) kprintf("loader: " fmt, ##__VA_ARGS__)
-#define pr_error(...) pr_trace(__VA_ARGS__)
-
-#define PHDR(hdrptr, IDX) \
- (void *)((uintptr_t)hdr + (hdrptr)->e_phoff + (hdrptr->e_phentsize*IDX))
-
-int
-loader_unload(struct vas vas, struct vm_range *exec_range)
-{
- size_t start, end;
-
- start = exec_range->start;
- end = exec_range->end;
-
- /* FIXME: Figure out how to free physical memory too */
- return vm_map_destroy(vas, start, (end - start));
-}
-
-uintptr_t
-loader_init_stack(void *stack_top, struct exec_args args)
-{
- uintptr_t *sp = stack_top;
- uintptr_t old_sp = 0;
- size_t argc, envc, len;
- char **argvp = args.argp;
- char **envp = args.envp;
- struct auxval auxv = args.auxv;
-
- /* Copy strings */
- old_sp = (uintptr_t)sp;
- for (argc = 0; argvp[argc] != NULL; ++argc) {
- len = strlen(argvp[argc]) + 1;
- sp = (void *)((char *)sp - len);
- memcpy((char *)sp, argvp[argc], len);
- }
- for (envc = 0; envp[envc] != NULL; ++envc) {
- len = strlen(envp[envc]) + 1;
- sp = (void *)((char *)sp - len);
- memcpy((char *)sp, envp[envc], len);
- }
-
- /* Ensure the stack is aligned */
- sp = (void *)__ALIGN_DOWN((uintptr_t)sp, 16);
- if (((argc + envc + 1) & 1) != 0)
- --sp;
-
- AUXVAL(sp, AT_NULL, 0x0);
- AUXVAL(sp, AT_SECURE, 0x0);
- AUXVAL(sp, AT_ENTRY, auxv.at_entry);
- AUXVAL(sp, AT_PHDR, auxv.at_phdr);
- AUXVAL(sp, AT_PHNUM, auxv.at_phnum);
- AUXVAL(sp, AT_PAGESIZE, vm_get_page_size());
- STACK_PUSH(sp, 0);
-
- /* Copy envp pointers */
- sp -= envc;
- for (int i = 0; i < envc; ++i) {
- len = strlen(envp[i]) + 1;
- old_sp -= len;
- sp[i] = KERN_TO_USER(old_sp);
- }
-
- /* Copy argvp pointers */
- STACK_PUSH(sp, 0);
- sp -= argc;
- for (int i = 0; i < argc; ++i) {
- len = strlen(argvp[i]) + 1;
- old_sp -= len;
- sp[i] = KERN_TO_USER(old_sp);
- }
-
- STACK_PUSH(sp, argc);
- return (uintptr_t)sp;
-}
-
-int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv,
- size_t load_base, char **ld_path, struct vm_range *prog_range)
-{
- const Elf64_Ehdr *hdr = dataptr;
- Elf64_Phdr *phdr;
- vm_prot_t prot = PROT_USER;
-
- uintptr_t physmem;
- size_t misalign, page_count, map_len;
- int status;
-
- uintptr_t start_addr = (uintptr_t)-1;
- uintptr_t end_addr = 0;
-
- const size_t GRANULE = vm_get_page_size();
- void *tmp_ptr;
-
- if (auxv == NULL) {
- pr_error("Auxval argument NULL\n");
- return -1;
- }
-
- if (memcmp(hdr->e_ident, ELFMAG, 4) != 0) {
- /* Bad ELF header */
- pr_error("ELF header bad! (Magic incorrect)\n");
- return -1;
- }
-
- /* Parse program headers */
- for (size_t i = 0; i < hdr->e_phnum; ++i) {
- phdr = PHDR(hdr, i);
- switch (phdr->p_type) {
- case PT_LOAD:
- if (__TEST(phdr->p_flags, PF_W))
- prot |= PROT_WRITE;
- if (__TEST(phdr->p_flags, PF_X)) {
- prot |= PROT_EXEC;
- }
-
- misalign = phdr->p_vaddr & (GRANULE - 1);
- page_count = __DIV_ROUNDUP(phdr->p_memsz + misalign, GRANULE);
- physmem = vm_alloc_pageframe(page_count);
- map_len = page_count * GRANULE;
-
- /*
- * Now we want to compute the start address of the
- * program and the end address.
- */
- if (start_addr == (uintptr_t)-1) {
- start_addr = phdr->p_vaddr;
- }
-
- end_addr = __MAX(end_addr, phdr->p_vaddr + page_count*GRANULE);
-
- /* Do we not have enough page frames? */
- if (physmem == 0) {
- pr_error("Failed to allocate physical memory\n");
- vm_free_pageframe(physmem, page_count);
- return -ENOMEM;
- }
-
- status = vm_map_create(vas, phdr->p_vaddr + load_base, physmem, prot, map_len);
-
- if (status != 0) {
- return status;
- }
-
- /* Now we want to copy the data */
- tmp_ptr = (void *)((uintptr_t)hdr + phdr->p_offset);
- memcpy(PHYS_TO_VIRT(physmem), tmp_ptr, phdr->p_filesz);
- break;
- case PT_INTERP:
- if (ld_path == NULL) {
- break;
- }
-
- *ld_path = dynalloc(phdr->p_filesz);
-
- if (ld_path == NULL) {
- pr_error("Failed to allocate memory for PT_INTERP path\n");
- return -ENOMEM;
- }
-
- memcpy(*ld_path, (char *)hdr + phdr->p_offset, phdr->p_filesz);
- break;
- case PT_PHDR:
- auxv->at_phdr = phdr->p_vaddr + load_base;
- break;
- }
- }
-
- auxv->at_entry = hdr->e_entry + load_base;
- auxv->at_phent = hdr->e_phentsize;
- auxv->at_phnum = hdr->e_phnum;
- prog_range->start = start_addr;
- prog_range->end = end_addr;
- return 0;
-}
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
deleted file mode 100644
index ea770b1..0000000
--- a/sys/kern/kern_mutex.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/mutex.h>
-#include <sys/sched.h>
-#include <sys/proc.h>
-
-void
-mutex_acquire(struct mutex *mutex)
-{
- struct proc *td = this_td();
- register bool rest = (td != NULL);
-
- while (__atomic_test_and_set(&mutex->lock, __ATOMIC_ACQUIRE)) {
- if (!rest)
- continue;
-
- sched_rest();
- }
-}
-
-void
-mutex_release(struct mutex *mutex)
-{
- __atomic_clear(&mutex->lock, __ATOMIC_RELEASE);
-}
diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c
deleted file mode 100644
index 71744af..0000000
--- a/sys/kern/kern_panic.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/panic.h>
-#include <sys/syslog.h>
-#include <sys/machdep.h>
-#include <sys/spinlock.h>
-
-/*
- * Tells the user something terribly
- * wrong happened then halting the system
- * as soon as possible.
- *
- * XXX: There is no need to cleanup stuff here (e.g `va_list ap`)
- * as we won't be returning from here anyways and the source
- * of the panic could be *anywhere* so it's best not to mess with
- * things.
- */
-void
-panic(const char *fmt, ...)
-{
- va_list ap;
- static struct spinlock lock = {0};
-
- intr_mask();
- spinlock_acquire(&lock); /* Never released */
- __TRY_CALL(cpu_halt_others);
-
- g_syslog_use_tty = true;
- va_start(ap, fmt);
-
- kprintf(OMIT_TIMESTAMP "panic: ");
- vkprintf(fmt, &ap);
-
- machine_panic();
- __builtin_unreachable();
-}
diff --git a/sys/kern/kern_reboot.c b/sys/kern/kern_reboot.c
deleted file mode 100644
index 8f7c400..0000000
--- a/sys/kern/kern_reboot.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/reboot.h>
-#include <sys/panic.h>
-#include <sys/cdefs.h>
-#include <sys/machdep.h>
-
-int
-reboot(int type)
-{
- __TRY_CALL(cpu_reset);
-
- /* Should be unreachable if the reboot works */
- return -1;
-}
-
-/*
- * Arg0: Type
- */
-uint64_t
-sys_reboot(struct syscall_args *args)
-{
- return reboot(args->arg0);
-}
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
deleted file mode 100644
index ddc99ca..0000000
--- a/sys/kern/kern_sched.c
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/sched.h>
-#include <sys/schedvar.h>
-#include <sys/machdep.h>
-#include <sys/loader.h>
-#include <sys/errno.h>
-#include <sys/cdefs.h>
-#include <sys/filedesc.h>
-#include <sys/timer.h>
-#include <sys/panic.h>
-#include <sys/signal.h>
-#include <fs/initramfs.h>
-#include <vm/dynalloc.h>
-#include <vm/physseg.h>
-#include <vm/map.h>
-#include <vm/pmap.h>
-#include <string.h>
-#include <assert.h>
-
-/*
- * Thread ready queues - all threads ready to be
- * scheduled should be added to the toplevel queue.
- */
-static struct sched_queue qlist[SCHED_NQUEUE];
-
-/*
- * Global scheduler state.
- */
-static size_t nthread = 0;
-static schedpolicy_t policy = SCHED_POLICY_MLFQ;
-
-/*
- * Thread queue lock - all operations to `qlist'
- * must be done with this lock acquired.
- *
- * This lock is aligned on a cache line boundary to ensure
- * it has its own cache line to reduce contention. This is
- * because it is constantly acquired and released on every
- * processor.
- */
-__cacheline_aligned
-static struct spinlock tdq_lock = {0};
-
-/*
- * Lower thread priority.
- */
-static inline void
-td_pri_lower(struct proc *td)
-{
- if (td->priority < (SCHED_NQUEUE - 1))
- ++td->priority;
-}
-
-/*
- * Raise thread priority.
- */
-static inline void
-td_pri_raise(struct proc *td)
-{
- if (td->priority > 0)
- --td->priority;
-}
-
-/*
- * Called during preemption. We raise the priority
- * if the thread has been rested. If the thread has not
- * been rested, we lower its priority.
- */
-static void
-td_pri_update(struct proc *td)
-{
- if (td->rested) {
- td->rested = 0;
- td_pri_raise(td);
- return;
- }
-
- td_pri_lower(td);
-}
-
-/*
- * Enqueue a thread into the scheduler.
- */
-static void
-sched_enqueue_td(struct proc *td)
-{
- struct sched_queue *queue;
-
- spinlock_acquire(&tdq_lock);
- queue = &qlist[td->priority];
-
- TAILQ_INSERT_TAIL(&queue->q, td, link);
- spinlock_release(&tdq_lock);
-}
-
-/*
- * Dequeue a thread from a queue.
- */
-static struct proc *
-sched_dequeue_td(void)
-{
- struct sched_queue *queue;
- struct proc *td = NULL;
-
- spinlock_acquire(&tdq_lock);
-
- /*
- * Try to pop a thread from a queue. We start at the
- * highest priority which is 0.
- */
- for (size_t i = 0; i < SCHED_NQUEUE; ++i) {
- queue = &qlist[i];
-
- if (!TAILQ_EMPTY(&queue->q)) {
- td = TAILQ_FIRST(&queue->q);
- TAILQ_REMOVE(&queue->q, td, link);
- break;
- }
- }
-
- spinlock_release(&tdq_lock);
- return td;
-}
-
-/*
- * Create a new thread stack.
- * sched_new_td() helper.
- */
-static uintptr_t
-sched_create_stack(bool is_user, struct exec_args args, struct proc *td)
-{
- int status;
- uintptr_t stack;
- struct vm_range *stack_range;
- const vm_prot_t USERSTACK_PROT = PROT_WRITE | PROT_USER;
-
- stack_range = &td->addr_range[ADDR_RANGE_STACK];
-
- /*
- * Kernel stacks can be allocated with dynalloc() as they
- * are on the higher half.
- */
- if (!is_user) {
- stack = (uintptr_t)dynalloc(PROC_STACK_SIZE);
- stack_range->start = stack;
- stack_range->end = stack + PROC_STACK_SIZE;
- return loader_init_stack((void *)(stack + PROC_STACK_SIZE), args);
- }
-
- stack = vm_alloc_pageframe(PROC_STACK_PAGES);
- if (stack == 0) {
- return 0;
- }
-
- status = vm_map_create(args.vas, stack, stack, USERSTACK_PROT, PROC_STACK_SIZE);
- if (status != 0) {
- vm_free_pageframe(stack, PROC_STACK_PAGES);
- return 0;
- }
-
- stack_range->start = stack;
- stack_range->end = stack + PROC_STACK_SIZE;
-
- memset(USER_TO_KERN(stack), 0, PROC_STACK_SIZE);
- stack = loader_init_stack((void *)USER_TO_KERN(stack + PROC_STACK_SIZE), args);
- return stack;
-}
-
-/*
- * Create a new thread.
- *
- * @ip: Instruction pointer to start at.
- * @is_user: True for user program.
- * @exec_args: Common exec args.
- */
-static int
-sched_new_td(uintptr_t ip, bool is_user, struct exec_args args, struct vm_range *prog_range,
- struct proc **res)
-{
- struct vm_range *exec_range;
- struct proc *td;
- struct trapframe *tf;
- uintptr_t stack;
- int retval = 0;
-
- td = dynalloc(sizeof(struct proc));
- tf = dynalloc(sizeof(struct trapframe));
- if (td == NULL || tf == NULL) {
- retval = -ENOMEM;
- goto done;
- }
-
- /* Keep them in a known state */
- memset(td, 0, sizeof(*td));
- memset(tf, 0, sizeof(*tf));
-
- /* Try to create a stack */
- stack = sched_create_stack(is_user, args, td);
- if (stack == 0) {
- retval = -ENOMEM;
- goto done;
- }
-
- /* Setup initial thread state */
- td->pid = ++nthread;
- td->tf = tf;
- td->addrsp = args.vas;
- td->is_user = is_user;
- processor_init_pcb(td);
-
- /* Setup each mapping table */
- for (size_t i = 0; i < MTAB_ENTRIES; ++i) {
- TAILQ_INIT(&td->mapspace.mtab[i]);
- }
-
- /* Setup standard file descriptors */
- __assert(fd_alloc(td, NULL) == 0); /* STDIN */
- __assert(fd_alloc(td, NULL) == 0); /* STDOUT */
- __assert(fd_alloc(td, NULL) == 0); /* STDERR */
-
- exec_range = &td->addr_range[ADDR_RANGE_EXEC];
- memcpy(exec_range, prog_range, sizeof(struct vm_range));
-
- /* Init the trapframe */
- if (!is_user) {
- init_frame(tf, ip, stack);
- } else {
- init_frame_user(tf, ip, KERN_TO_USER(stack));
- }
-done:
- if (retval != 0 && td != NULL)
- dynfree(td);
- if (retval != 0 && tf != NULL)
- dynfree(td);
- if (retval == 0 && res != NULL)
- *res = td;
-
- return retval;
-}
-
-/*
- * Perform timer oneshot
- *
- * @now: True for shortest timeslice.
- */
-static inline void
-sched_oneshot(bool now)
-{
- struct timer timer;
- size_t usec = (now) ? SHORT_TIMESLICE_USEC : DEFAULT_TIMESLICE_USEC;
- tmrr_status_t tmr_status;
-
- tmr_status = req_timer(TIMER_SCHED, &timer);
- __assert(tmr_status == TMRR_SUCCESS);
-
- timer.oneshot_us(usec);
-}
-
-/*
- * Enter the schedulera and wait until
- * preemption.
- */
-void
-sched_enter(void)
-{
- sched_oneshot(false);
-
- for (;;) {
- hint_spinwait();
- }
-}
-
-/*
- * Initialize all of the queues.
- */
-static void
-sched_init_queues(void)
-{
- for (size_t i = 0; i < SCHED_NQUEUE; ++i) {
- TAILQ_INIT(&qlist[i].q);
- }
-}
-
-/*
- * Load the first thread (init)
- */
-static void
-sched_load_init(void)
-{
- struct exec_args args;
- struct proc *init;
- struct auxval *auxvp = &args.auxv;
- struct vm_range init_range;
- int tmp;
-
- char *argv[] = {"/usr/sbin/init", NULL};
- char *envp[] = {NULL};
- const char *init_bin;
-
- if ((init_bin = initramfs_open("/usr/sbin/init")) == NULL)
- panic("Could not open /usr/sbin/init\n");
-
- pmap_create_vas(vm_get_ctx(), &args.vas);
- args.argp = argv;
- args.envp = envp;
-
- tmp = loader_load(args.vas, init_bin, auxvp, 0, NULL, &init_range);
- if (tmp != 0)
- panic("Failed to load init\n");
-
- if (sched_new_td(auxvp->at_entry, true, args, &init_range, &init) != 0)
- panic("Failed to create init thread\n");
-
- sched_enqueue_td(init);
-}
-
-static void
-sched_destroy_td(struct proc *td)
-{
- struct vm_range *stack_range;
- struct vm_range *exec_range;
- vm_mapq_t *mapq;
-
- processor_free_pcb(td);
- stack_range = &td->addr_range[ADDR_RANGE_STACK];
- exec_range = &td->addr_range[ADDR_RANGE_EXEC];
-
- /*
- * User thread's have their stack allocated
- * with vm_alloc_pageframe() and kernel thread's
- * have their stacks allocated with dynalloc()
- */
- if (td->is_user) {
- vm_free_pageframe(stack_range->start, PROC_STACK_PAGES);
- } else {
- dynfree((void *)stack_range->start);
- }
-
- for (size_t i = 0; i < MTAB_ENTRIES; ++i) {
- mapq = &td->mapspace.mtab[i];
- vm_free_mapq(mapq);
- }
-
- for (size_t i = 0; i < PROC_MAX_FDS; ++i) {
- fd_close_fdnum(td, i);
- }
-
- loader_unload(td->addrsp, exec_range);
- pmap_free_vas(vm_get_ctx(), td->addrsp);
- dynfree(td);
-}
-
-/*
- * Cause an early preemption and lets
- * the next thread run.
- */
-void
-sched_rest(void)
-{
- struct proc *td = this_td();
-
- if (td == NULL)
- return;
-
- td->rested = 1;
- sched_oneshot(true);
-}
-
-void
-sched_exit(void)
-{
- struct proc *td = this_td();
- struct vas kvas = vm_get_kvas();
-
- spinlock_acquire(&tdq_lock);
- intr_mask();
-
- /* Switch to kernel VAS and destroy td */
- pmap_switch_vas(vm_get_ctx(), kvas);
- sched_destroy_td(td);
-
- spinlock_release(&tdq_lock);
- intr_unmask();
- sched_enter();
-}
-
-/*
- * Get the current running thread.
- */
-struct proc *
-this_td(void)
-{
- struct sched_state *state;
- struct cpu_info *ci;
-
- ci = this_cpu();
- state = &ci->sched_state;
- return state->td;
-}
-
-/*
- * Thread context switch routine
- *
- * Handles the transition from the currently running
- * thread to the next thread.
- */
-void
-sched_context_switch(struct trapframe *tf)
-{
- struct cpu_info *ci = this_cpu();
- struct sched_state *state = &ci->sched_state;
- struct proc *next_td, *td = state->td;
-
- if (td != NULL) {
- signal_handle(state->td);
- }
-
- /*
- * If a thread is currently running and our policy is
- * MLFQ, then we should update the thread's priority.
- */
- if (td != NULL && policy == SCHED_POLICY_MLFQ) {
- td_pri_update(td);
- }
-
- /* Don't preempt if we have no threads */
- if ((next_td = sched_dequeue_td()) == NULL) {
- sched_oneshot(false);
- return;
- }
-
- /*
- * If we have a thread currently running, then we should save
- * its current register state and re-enqueue it.
- */
- if (td != NULL) {
- memcpy(td->tf, tf, sizeof(struct trapframe));
- sched_enqueue_td(td);
- }
-
- /* Perform the switch */
- memcpy(tf, next_td->tf, sizeof(struct trapframe));
- processor_switch_to(td, next_td);
-
- state->td = next_td;
- pmap_switch_vas(vm_get_ctx(), next_td->addrsp);
- sched_oneshot(false);
-}
-
-uint64_t
-sys_exit(struct syscall_args *args)
-{
- sched_exit();
- __builtin_unreachable();
-}
-
-void
-sched_init(void)
-{
- sched_init_queues();
- sched_load_init();
-}
diff --git a/sys/kern/kern_signal.c b/sys/kern/kern_signal.c
deleted file mode 100644
index 7c31c86..0000000
--- a/sys/kern/kern_signal.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/proc.h>
-#include <sys/sched.h>
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-#include <sys/signal.h>
-#include <dev/vcons/vcons.h>
-#include <string.h>
-
-__MODULE_NAME("kern_signal");
-__KERNEL_META("$Hyra$: kern_signal.c, Ian Marco Moffett, "
- "Signal handling code");
-
-static void
-signal_log(const char *s)
-{
- vcons_putstr(&g_syslog_screen, s, strlen(s));
-}
-
-/*
- * Handle any signals within the current thread
- *
- * TODO: Add sigaction support, default action
- * for all currently is killing the process.
- */
-void
-signal_handle(struct proc *curtd)
-{
- int signo = curtd->signal;
-
- if (signo == 0) {
- return;
- }
-
- spinlock_acquire(&curtd->lock);
- curtd->signal = 0;
-
- switch (signo) {
- case SIGFPE:
- signal_log("Arithmetic error\n");
- break;
- case SIGSEGV:
- signal_log("Segmentation fault\n");
- break;
- case SIGKILL:
- signal_log("Killed\n");
- break;
- }
-
- spinlock_release(&curtd->lock);
- sched_exit();
-}
-
-/*
- * Raise a signal for a process
- *
- * @to: Can be NULL to mean the current process
- * @signal: Signal to send
- *
- * TODO: Add more functionality.
- */
-void
-signal_raise(struct proc *to, int signal)
-{
- if (to == NULL) {
- to = this_td();
- }
-
- to->signal = signal;
- if (to == this_td()) {
- /* Current process, just preempt */
- sched_context_switch(to->tf);
- }
-}
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
deleted file mode 100644
index d9b1b3a..0000000
--- a/sys/kern/kern_subr.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/system.h>
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <sys/sched.h>
-#include <vm/vm.h>
-#include <string.h>
-
-/*
- * Check if a user address is valid.
- *
- * @uaddr: User address to check.
- *
- * Returns true if valid, otherwise false.
- */
-static bool
-check_uaddr(uintptr_t uaddr)
-{
- struct proc *td = this_td();
- struct vm_range exec_range = td->addr_range[ADDR_RANGE_EXEC];
- struct vm_range stack_range = td->addr_range[ADDR_RANGE_STACK];
-
- if (uaddr >= exec_range.start && uaddr <= exec_range.end) {
- return true;
- }
- if (uaddr >= stack_range.start && uaddr <= stack_range.end) {
- return true;
- }
-
- return false;
-}
-
-/*
- * Copy from userspace to the kernel.
- *
- * @uaddr: Userspace address.
- * @kaddr: Kernelspace address.
- * @len: Length of data.
- */
-int
-copyin(uintptr_t uaddr, void *kaddr, size_t len)
-{
- if (!check_uaddr(uaddr) || !check_uaddr(uaddr + len)) {
- return -EFAULT;
- }
-
- memcpy(kaddr, (void *)uaddr, len);
- return 0;
-}
-
-/*
- * Copy from the kernel to userspace.
- *
- * @kaddr: Kernelspace address.
- * @uaddr: Userspace address.
- * @len: Length of data.
- */
-int
-copyout(const void *kaddr, uintptr_t uaddr, size_t len)
-{
- if (!check_uaddr(uaddr) || !check_uaddr(uaddr + len)) {
- return -EFAULT;
- }
-
- memcpy((void *)uaddr, kaddr, len);
- return 0;
-}
-
-/*
- * Copy in a string from userspace
- *
- * Unlike the typical copyin(), this routine will
- * copy until we've hit NUL ('\0')
- *
- * @uaddr: Userspace address.
- * @kaddr: Kernelspace address.
- * @len: Length of string.
- *
- * XXX: Please note that if `len' is less than the actual
- * string length, the returned value will not be
- * NUL terminated.
- */
-int
-copyinstr(uintptr_t uaddr, char *kaddr, size_t len)
-{
- char *dest = (char *)kaddr;
- char *src = (char *)uaddr;
-
- if (!check_uaddr(uaddr)) {
- return -EFAULT;
- }
-
- for (size_t i = 0; i < len; ++i) {
- if (!check_uaddr(uaddr + i)) {
- return -EFAULT;
- }
-
- dest[i] = src[i];
-
- if (src[i] == '\0') {
- break;
- }
- }
-
- return 0;
-}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
deleted file mode 100644
index 35185ea..0000000
--- a/sys/kern/kern_syscall.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/syscall.h>
-#include <sys/sched.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/filedesc.h>
-#include <sys/system.h>
-#include <sys/exec.h>
-#include <sys/reboot.h>
-#include <sys/vfs.h>
-#include <vm/map.h>
-
-uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args) = {
- sys_exit,
- sys_write,
- sys_open,
- sys_close,
- sys_read,
- sys_lseek,
- sys_mmap,
- sys_munmap,
- sys_ioctl,
- sys_execv,
- sys_mount,
- sys_reboot
-};
diff --git a/sys/kern/kern_syslog.c b/sys/kern/kern_syslog.c
deleted file mode 100644
index 86877e0..0000000
--- a/sys/kern/kern_syslog.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/syslog.h>
-#include <sys/machdep.h>
-#include <sys/tty.h>
-#include <sys/cdefs.h>
-#include <sys/timer.h>
-#include <sys/spinlock.h>
-#include <dev/vcons/vcons.h>
-#include <fs/procfs.h>
-#include <string.h>
-
-#if defined(__KMSG_BUF_SHIFT)
-#define KMSG_BUF_SHIFT __KMSG_BUF_SHIFT
-#else
-#define KMSG_BUF_SHIFT 12
-#endif
-
-#define KMSG_BUF_SIZE (1 << KMSG_BUF_SHIFT)
-
-__STATIC_ASSERT(KMSG_BUF_SHIFT <= 16, "Log buffer shift too large!\n");
-
-static char kmsg_buf[KMSG_BUF_SIZE];
-static size_t kmsg_buf_idx = 0;
-static struct proc_entry *kmsg_proc;
-static struct spinlock lock = {0};
-
-struct vcons_screen g_syslog_screen = {0};
-bool g_syslog_use_tty = true;
-
-static inline void
-kmsg_buf_putc(char c)
-{
- kmsg_buf[kmsg_buf_idx++] = c;
- kmsg_buf[kmsg_buf_idx] = '\0';
- if (kmsg_buf_idx >= (KMSG_BUF_SIZE - 1))
- kmsg_buf_idx = 0;
-}
-
-static int
-proc_kmsg_read(struct proc_entry *p, struct sio_txn *sio)
-{
- if (sio->len > KMSG_BUF_SIZE)
- sio->len = KMSG_BUF_SIZE;
-
- memcpy(sio->buf, kmsg_buf, sio->len);
- return sio->len;
-}
-
-static void
-syslog_write(const char *s, size_t len)
-{
- size_t tmp_len = len;
- const char *tmp_s = s;
-
- while (tmp_len--) {
-#if defined(__SERIAL_DEBUG)
- serial_dbgch(*tmp_s);
-#endif /* defined(__SERIAL_DEBUG) */
- kmsg_buf_putc(*tmp_s);
- if (g_syslog_use_tty)
- tty_putc(&g_root_tty, *tmp_s, TTY_SOURCE_RAW);
-
- ++tmp_s;
- }
-
- tty_flush(&g_root_tty);
-}
-
-/*
- * XXX: Not serialized
- */
-void
-vkprintf(const char *fmt, va_list *ap)
-{
- char buffer[1024] = {0};
-
- vsnprintf(buffer, sizeof(buffer), fmt, *ap);
- syslog_write(buffer, strlen(buffer));
-}
-
-void
-kprintf(const char *fmt, ...)
-{
- va_list ap;
- char timestamp[64] = "[ 0.000000] ";
- bool has_counter = true;
- bool use_timestamp = true;
- const char *fmt_p = fmt;
- struct timer tmr = {0};
-
- spinlock_acquire(&lock);
-
- /*
- * If the first char is OMIT_TIMESTAMP, then we won't
- * print out the timestamp.
- */
- if (*fmt_p == OMIT_TIMESTAMP[0]) {
- ++fmt_p;
- use_timestamp = false;
- }
-
- /* See if we can use the counter */
- if (req_timer(TIMER_GP, &tmr) != 0)
- has_counter = false;
-
- /* If we can use the counter, format the timestamp */
- if (has_counter) {
- if (tmr.get_time_sec != NULL && tmr.get_time_usec != NULL)
- snprintf(timestamp, sizeof(timestamp), "[ %d.%06d] ",
- tmr.get_time_sec(), tmr.get_time_usec());
-
- }
-
- if (use_timestamp) {
- syslog_write(timestamp, strlen(timestamp));
- }
-
- va_start(ap, fmt);
- vkprintf(fmt_p, &ap);
- va_end(ap);
-
- spinlock_release(&lock);
-}
-
-void
-syslog_init_proc(void)
-{
- kmsg_proc = procfs_alloc_entry();
- kmsg_proc->read = proc_kmsg_read;
- procfs_add_entry("kmsg", kmsg_proc);
-}
-
-void
-syslog_init(void)
-{
- g_syslog_screen.bg = 0x000000;
- g_syslog_screen.fg = 0x808080;
-
- vcons_attach(&g_syslog_screen);
-}
diff --git a/sys/kern/kern_timer.c b/sys/kern/kern_timer.c
deleted file mode 100644
index 5cc808f..0000000
--- a/sys/kern/kern_timer.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/timer.h>
-
-/*
- * When a timer on the machine has been registered
- * to the Hyra kernel, they'll be added to the Hyra timer
- * registry.
- */
-static const struct timer *tmr_registry[TIMER_ID_COUNT] = { 0 };
-
-/*
- * Returns true if the timer ID given
- * is valid.
- *
- * @id: ID to verify.
- */
-static inline bool
-is_timer_id_valid(timer_id_t id)
-{
- return id < TIMER_ID_COUNT;
-}
-
-/*
- * Adds timer on the machine to the timer registry. To be specific,
- * this function writes information about the specific timer to the
- * timer registry. However, it will not overwrite an entry. To do this
- * you must use tmr_registry_overwrite(), of course with caution.
- *
- * @id: ID of timer to register.
- * @tmr: Timer descriptor to register.
- */
-tmrr_status_t
-register_timer(timer_id_t id, const struct timer *tmr)
-{
- if (!is_timer_id_valid(id))
- return TMRR_INVALID_TYPE;
-
- if (tmr_registry[id] != NULL)
- return TMRR_HAS_ENTRY;
-
- tmr_registry[id] = tmr;
- return TMRR_SUCCESS;
-}
-
-/*
- * Overwrites an entry within the timer registery.
- * Use with caution.
- *
- * @id: ID of entry to overwrite.
- * @tmr: Timer descriptor to write.
- */
-tmrr_status_t
-tmr_registry_overwrite(timer_id_t id, const struct timer *tmr)
-{
- if (!is_timer_id_valid(id))
- return TMRR_INVALID_TYPE;
-
- tmr_registry[id] = tmr;
- return TMRR_SUCCESS;
-}
-
-/*
- * Requests a specific timer descriptor
- * with a specific ID.
- *
- * @id: ID to request.
- * @tmr_out: Pointer to memory that'll hold the
- * requested descriptor.
- */
-tmrr_status_t
-req_timer(timer_id_t id, struct timer *tmr_out)
-{
- if (!is_timer_id_valid(id))
- return TMRR_INVALID_TYPE;
-
- if (tmr_registry[id] == NULL)
- return TMRR_EMPTY_ENTRY;
-
- if (tmr_out == NULL)
- return TMRR_INVALID_ARG;
-
- *tmr_out = *tmr_registry[id];
- return TMRR_SUCCESS;
-}
diff --git a/sys/kern/kern_tty.c b/sys/kern/kern_tty.c
deleted file mode 100644
index e47c2e2..0000000
--- a/sys/kern/kern_tty.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/tty.h>
-#include <sys/system.h>
-#include <sys/cdefs.h>
-#include <sys/errno.h>
-#include <sys/syslog.h>
-#include <sys/ascii.h>
-#include <dev/vcons/vcons_io.h>
-#include <fs/devfs.h>
-#include <string.h>
-
-static dev_t tty_major = 0;
-struct tty g_root_tty = {
- .scr = &g_syslog_screen,
- .ring = {
- .enq_index = 0,
- .deq_index = 0,
- },
- .termios = {
- .c_lflag = ICANON | ECHO
- }
-};
-
-static inline dev_t
-tty_alloc_id(void)
-{
- static dev_t id = 1;
-
- return id++;
-}
-
-static inline bool
-tty_is_special(char c)
-{
- return c < 0x1F;
-}
-
-static inline void
-tty_reset_ring(struct tty_ring *ring)
-{
- ring->enq_index = 0;
- ring->deq_index = 0;
-}
-
-static void
-tty_process(struct tty *tty, char c, bool echo)
-{
- const struct termios *termios;
- bool canon, special;
-
- termios = &tty->termios;
- canon = __TEST(termios->c_lflag, ICANON);
- special = tty_is_special(c);
-
- if (canon && special)
- vcons_process_output(tty->scr, c);
- if (echo && !special)
- vcons_putch(tty->scr, c);
-}
-
-/*
- * Flushes the TTY ring buffer.
- *
- * @tty: TTY to flush.
- *
- * Returns number of bytes flushed.
- */
-static ssize_t
-__tty_flush(struct tty *tty)
-{
- struct tty_ring *ring = &tty->ring;
- struct tty_ring *outring = &tty->outring;
- size_t count = 0;
- char tmp;
-
- /* Do we have any data left? */
- if (ring->deq_index >= ring->enq_index)
- return -EAGAIN;
-
- /*
- * Flush the input ring to the output ring
- * to allow user programs to fetch from it
- * with /dev/ttyN.
- */
- while (ring->deq_index < ring->enq_index) {
- tmp = ring->data[ring->deq_index++];
- outring->data[outring->enq_index++] = tmp;
-
- if (outring->enq_index > TTY_RING_SIZE)
- tty_reset_ring(outring);
-
- ++count;
- }
-
- tty_reset_ring(ring);
- return count;
-}
-
-static int
-tty_dev_read(struct device *dev, struct sio_txn *sio)
-{
- struct tty_ring *ring = &g_root_tty.outring;
- size_t len, max_len;
-
- spinlock_acquire(&g_root_tty.rlock);
- max_len = (ring->enq_index - ring->deq_index);
- len = sio->len;
-
- if (len > max_len)
- len = max_len;
-
- /*
- * Transfer data from the TTY ring with SIO then
- * ensure the ring is clean by resetting it.
- *
- * TODO: As of now we are just reading the root
- * TTY, add support for multiple TTYs.
- */
- memcpy(sio->buf, ring->data, len);
- tty_reset_ring(ring);
- spinlock_release(&g_root_tty.rlock);
- return len;
-}
-
-static int
-tty_dev_ioctl(struct device *dev, uint32_t cmd, uintptr_t arg)
-{
- /* TODO: Support multiple TTYs */
- struct termios *tp = &g_root_tty.termios;
-
- switch (cmd) {
- case TCGETS:
- copyout(tp, arg, sizeof(struct termios));
- break;
- case TCSETS:
- copyin(arg, tp, sizeof(struct termios));
- break;
- default:
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int
-tty_dev_open(struct device *dev)
-{
- /* TODO: Support multiple TTYs */
- struct tty *tty = &g_root_tty;
- struct tty_ring *ring = &tty->outring;
-
- /* Ensure the ring is clean */
- spinlock_acquire(&tty->rlock);
- tty_reset_ring(ring);
- spinlock_release(&tty->rlock);
- return 0;
-}
-
-/*
- * Serialized wrapper over __tty_flush()
- */
-ssize_t
-tty_flush(struct tty *tty)
-{
- ssize_t ret;
-
- spinlock_acquire(&tty->rlock);
- ret = __tty_flush(tty);
- spinlock_release(&tty->rlock);
- return ret;
-}
-
-/*
- * Write a character to a TTY
- *
- * @tty: TTY to write to.
- * @c: Character to write.
- */
-int
-tty_putc(struct tty *tty, int c, int flags)
-{
- struct tty_ring *ring;
- const struct termios *termios;
- bool canon, echo;
-
- ring = &tty->ring;
- termios = &tty->termios;
-
- canon = __TEST(termios->c_lflag, ICANON);
- echo = __TEST(termios->c_lflag, ECHO);
-
- spinlock_acquire(&tty->rlock);
- ring->data[ring->enq_index++] = c;
-
- /*
- * Process the characters for both device input
- * and raw input. Device input will only be echoed
- * if the ECHO bit is set within c_lflag
- */
- if (__TEST(flags, TTY_SOURCE_DEV) && echo)
- tty_process(tty, c, echo);
- if (__TEST(flags, TTY_SOURCE_RAW))
- tty_process(tty, c, true);
-
- /*
- * If we are in canonical mode and we have a linefeed ('\n')
- * character, we should flush the ring.
- */
- if (canon && c == ASCII_LF) {
- __tty_flush(tty);
- }
-
- /*
- * Just flush the ring if we aren't in canonical
- * mode.
- */
- if (!canon) {
- __tty_flush(tty);
- }
-
- /* Reset the ring if it is full */
- if (ring->enq_index >= TTY_RING_SIZE) {
- tty_reset_ring(ring);
- }
-
- spinlock_release(&tty->rlock);
- return 0;
-}
-
-/*
- * Write a string to a TTY
- *
- * @tty: TTY to write to.
- * @s: String to write.
- * @count: Number of bytes to write.
- */
-int
-tty_putstr(struct tty *tty, const char *s, size_t count)
-{
- for (size_t i = 0; i < count; ++i) {
- tty_putc(tty, *s++, TTY_SOURCE_RAW);
- }
-
- return 0;
-}
-
-dev_t
-tty_attach(struct tty *tty)
-{
- int tmp;
- char devname[128];
- struct device *dev = device_alloc();
-
- if (dev == NULL)
- return -ENOMEM;
-
- /*
- * Allocate a major for the driver if we don't
- * have one yet.
- */
- if (tty_major == 0)
- tty_major = device_alloc_major();
-
- /* Now try to create the device */
- tty->id = tty_alloc_id();
- if ((tmp = device_create(dev, tty_major, tty->id)) < 0)
- return tmp;
-
- dev->read = tty_dev_read;
- dev->ioctl = tty_dev_ioctl;
- dev->open = tty_dev_open;
- dev->blocksize = 1;
-
- snprintf(devname, sizeof(devname), "tty%d", tty->id);
- return devfs_add_dev(devname, dev);
-}
diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c
deleted file mode 100644
index 6754b1f..0000000
--- a/sys/kern/vfs_init.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/vfs.h>
-#include <sys/cdefs.h>
-#include <sys/mount.h>
-#include <sys/types.h>
-#include <sys/vnode.h>
-#include <fs/initramfs.h>
-#include <fs/devfs.h>
-#include <fs/procfs.h>
-#include <assert.h>
-#include <string.h>
-
-__MODULE_NAME("vfs");
-__KERNEL_META("$Hyra$: vfs.c, Ian Marco Moffett, "
- "Hyra Virtual File System");
-
-#define INITRAMFS_ID 0
-#define DEVFS_ID 1
-#define PROCFS_ID 2
-
-static struct fs_info filesystems[] = {
- [INITRAMFS_ID] = { "initramfs", &g_initramfs_ops, NULL},
- [DEVFS_ID] = { "dev", &g_devfs_ops, &g_devfs_vops },
- [PROCFS_ID] = { "proc", &g_procfs_ops, &g_procfs_vops }
-};
-
-struct vnode *g_root_vnode = NULL;
-
-struct fs_info *
-vfs_byname(const char *name)
-{
- for (int i = 0; i < __ARRAY_COUNT(filesystems); ++i) {
- if (strcmp(filesystems[i].name, name) == 0) {
- return &filesystems[i];
- }
- }
-
- return NULL;
-}
-
-void
-vfs_init(void)
-{
- struct fs_info *info;
- struct vfsops *vfsops;
-
- vfs_mount_init();
- __assert(vfs_alloc_vnode(&g_root_vnode, NULL, VDIR) == 0);
-
- for (int i = 0; i < __ARRAY_COUNT(filesystems); ++i) {
- info = &filesystems[i];
- vfsops = info->vfsops;
-
- __assert(vfsops->init != NULL);
- __assert(vfs_mount(info->name, 0, info) == 0);
- vfsops->init(info, NULL);
- }
-
- g_root_vnode->vops = &g_initramfs_vops;
- g_root_vnode->fs = &filesystems[INITRAMFS_ID];
-}
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
deleted file mode 100644
index ea73d1a..0000000
--- a/sys/kern/vfs_lookup.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/vfs.h>
-#include <sys/mount.h>
-#include <sys/errno.h>
-#include <vm/dynalloc.h>
-#include <string.h>
-
-/*
- * Fetches the filename within a path at
- * the nth index denoted by `idx'
- *
- * Returns memory allocated by dynalloc()
- * containing the filename.
- *
- * XXX: MUST FREE RETURN VALUE WITH dynfree() WHEN
- * DONE!
- */
-char *
-vfs_get_fname_at(const char *path, size_t idx)
-{
- size_t pathlen = strlen(path);
- size_t fname_len;
-
- char *path_tmp = dynalloc(pathlen + 2);
- char *ret = NULL;
- char *start_ptr, *ptr;
-
- /* Make one-based */
- ++idx;
-
- if (path_tmp == NULL) {
- return NULL;
- }
-
- ptr = path_tmp;
- memcpy(path_tmp, path, pathlen + 1);
-
- /*
- * We want to by default have a '/' at the end
- * to keep the parsing logic from getting more
- * complicated than it needs to be.
- */
- path_tmp[pathlen] = '/';
- path_tmp[pathlen + 1] = '\0';
-
- /* Skip any leading slashes */
- while (*ptr == '/')
- ++ptr;
-
- start_ptr = ptr;
-
- /* Get each filename */
- while (*ptr != '\0') {
- /* Handle duplicate delimiter */
- if (*ptr == '/' && *(ptr + 1) == '/') {
- /*
- * Snip this delimiter and skip, the next
- * will be read and filename returned (if of course
- * the index is reached).
- */
- *(ptr++) = '\0';
- continue;
- }
-
- if (*ptr == '/') {
- *(ptr++) = '\0';
-
- /* Continue if index not reached */
- if ((--idx) != 0) {
- start_ptr = ptr;
- continue;
- }
-
- /* Index has been reached, start_ptr contains name */
- fname_len = strlen(start_ptr);
- ret = dynalloc(fname_len + 1);
-
- if (ret != NULL) {
- memcpy(ret, start_ptr, fname_len + 1);
- }
- break;
- }
-
- ++ptr;
- }
-
- dynfree(path_tmp);
- return ret;
-}
-
-/*
- * Fetches a vnode from a path.
- *
- * @path: Path to fetch vnode from.
- * @vp: Output var for fetched vnode.
- *
- * Returns 0 on success.
- */
-int
-vfs_path_to_node(const char *path, struct vnode **vp)
-{
- struct vnode *vnode = g_root_vnode;
- struct mount *mp;
- struct fs_info *fs;
- char *name;
- int s = 0, fs_caps = 0;
-
- if (strcmp(path, "/") == 0 || !vfs_is_valid_path(path)) {
- return -EINVAL;
- } else if (*path != '/') {
- return -EINVAL;
- }
-
- /* See if we have a mountpoint with this name */
- name = vfs_get_fname_at(path, 0);
- if (vfs_get_mp(name, &mp) == 0) {
- fs = mp->fs;
- vnode = fs->vnode;
- }
-
- /* Fetch filesystem capabilities if we can */
- if (vnode->fs != NULL) {
- fs = vnode->fs;
- fs_caps = fs->caps;
- }
-
- /*
- * If the filesystem requires full-path lookups, we can try
- * throwing the full path at the filesystem to see if
- * it'll give us a vnode.
- */
- if (__TEST(fs_caps, FSCAP_FULLPATH)) {
- s = vfs_vget(vnode, path, &vnode);
- goto done;
- }
-
- for (size_t i = 1;; ++i) {
- name = vfs_get_fname_at(path, i);
- if (name == NULL) break;
-
- s = vfs_vget(vnode, name, &vnode);
- dynfree(name);
-
- if (s != 0) break;
- }
-
-done:
- if (vp != NULL && s == 0) {
- *vp = vnode;
- }
-
- return s;
-}
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
deleted file mode 100644
index 27d0ec3..0000000
--- a/sys/kern/vfs_mount.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/mount.h>
-#include <sys/vfs.h>
-#include <sys/errno.h>
-#include <vm/dynalloc.h>
-#include <assert.h>
-#include <string.h>
-
-/* TODO: Make this more flexible */
-#define MOUNTLIST_SIZE 8
-
-/* Mountlist entry */
-struct mountlist_entry {
- TAILQ_HEAD(, mount) buckets;
-};
-
-static struct mountlist_entry *mountlist = NULL;
-
-static int
-vfs_create_mp(const char *path, int mntflags, struct mount **mp_out)
-{
- struct mount *mp;
-
- mp = dynalloc(sizeof(struct mount));
- if (mp == NULL) {
- return -ENOMEM;
- }
-
- mp->flags = mntflags;
- *mp_out = mp;
- return 0;
-}
-
-static int
-mount(const char *source, const char *target, const char *filesystemtype,
- unsigned long mountflags, const void *data)
-{
- struct vnode *source_vnode;
- struct fs_info *info;
- int status;
-
- if (source == NULL || target == NULL || filesystemtype == NULL)
- return -EFAULT;
-
- /*
- * Check mount flags.
- *
- * XXX: No flags implemented yet.
- */
- if (mountflags != 0)
- return -EINVAL;
-
- /* Locate source, if any */
- if (strcmp(source, "none") == 0) {
- source_vnode = NULL;
- } else {
- status = vfs_path_to_node(source, &source_vnode);
- if (status != 0)
- return status;
- }
-
- /* Locate filesystem */
- info = vfs_byname(filesystemtype);
- if (info == NULL)
- return -ENODEV;
-
- /* Create mount point */
- status = vfs_mount(target, 0, info);
- if (status != 0)
- return status;
-
- /* Initialize filesystem if needed */
- if (info->vfsops->init != NULL)
- return info->vfsops->init(info, source_vnode);
-
- return 0;
-}
-
-/*
- * Mount a mountpoint
- *
- * @path: Path this mountpoint belongs to
- * @mntflags: Flags to mount with
- * @fs: Filesystem to mount
- *
- * If this mount entry already exists, -EEXIST
- * will be returned.
- */
-int
-vfs_mount(const char *path, int mntflags, struct fs_info *fs)
-{
- size_t hash;
- int status;
- struct mountlist_entry *entry;
- struct mount *mp;
-
- /* Exclude leading slash */
- if (*path == '/') {
- ++path;
- }
-
- hash = vfs_hash_path(path);
-
- if ((status = vfs_create_mp(path, mntflags, &mp)) != 0) {
- return status;
- }
-
- if (hash == -1) {
- /* Something is wrong with the path */
- return -EINVAL;
- }
-
- if (vfs_get_mp(path, NULL) == 0) {
- /* mount hit, do not duplicate this entry */
- return -EEXIST;
- }
-
- if ((status = vfs_alloc_vnode(&fs->vnode, mp, VDIR)) != 0) {
- return status;
- }
-
- mp->phash = hash;
- mp->fs = fs;
- fs->vnode->vops = fs->vops;
-
- entry = &mountlist[hash % MOUNTLIST_SIZE];
- TAILQ_INSERT_TAIL(&entry->buckets, mp, link);
- return 0;
-}
-
-/*
- * Fetch mountpoint
- *
- * @path: Path of target mountpoint
- * @mp: Pointer of variable where mountpoint fetched will
- * be stored
- *
- * Returns 0 upon a mplist hit, on a mplist miss this
- * function returns -ENOENT.
- */
-int
-vfs_get_mp(const char *path, struct mount **mp)
-{
- size_t hash;
- struct mountlist_entry *entry;
- struct mount *mount_iter;
-
- /* Exclude leading slash */
- if (*path == '/') {
- ++path;
- }
-
- hash = vfs_hash_path(path);
-
- if (hash == 0) {
- /* Something is wrong with the path */
- return -EINVAL;
- }
-
- entry = &mountlist[hash % MOUNTLIST_SIZE];
- TAILQ_FOREACH(mount_iter, &entry->buckets, link) {
- if (mount_iter->phash == hash) {
- if (mp != NULL) *mp = mount_iter;
- return 0;
- }
- }
-
- return -ENOENT;
-}
-
-void
-vfs_mount_init(void)
-{
- mountlist = dynalloc(sizeof(struct mountlist_entry) * MOUNTLIST_SIZE);
- __assert(mountlist != NULL);
-
- for (size_t i = 0; i < MOUNTLIST_SIZE; ++i) {
- TAILQ_INIT(&mountlist[i].buckets);
- }
-}
-
-uint64_t
-sys_mount(struct syscall_args *args)
-{
- return mount((void *)args->arg0, (void *)args->arg1, (void *)args->arg2,
- (unsigned long)args->arg3, (void *)args->arg4);
-}
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
deleted file mode 100644
index 60afa31..0000000
--- a/sys/kern/vfs_subr.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/vfs.h>
-#include <sys/errno.h>
-#include <sys/mount.h>
-#include <vm/dynalloc.h>
-#include <string.h>
-
-/* FNV-1a defines */
-#define FNV_OFFSET 14695981039346656037ULL
-#define FNV_PRIME 1099511628211ULL
-
-/*
- * FNV-1a hash function
- * https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function
- */
-static size_t
-vfs_hash(const char *data)
-{
- size_t hash = FNV_OFFSET;
- const char *p = data;
-
- while (*p) {
- hash ^= (size_t)(uint8_t)(*p);
- hash *= FNV_PRIME;
- ++p;
- }
-
- return hash;
-}
-
-/*
- * Hashes a path
- *
- * @path: Path to hash.
- *
- * Returns -1 on failure, >= 0 return values
- * are valid.
- */
-ssize_t
-vfs_hash_path(const char *path)
-{
- char *name = NULL;
- size_t i = 0, hash = 0;
-
- if (strcmp(path, "/") == 0 || !vfs_is_valid_path(path)) {
- return -1;
- }
-
- do {
- name = vfs_get_fname_at(path, i++);
- if (name != NULL) {
- hash += vfs_hash(name);
- dynfree(name);
- }
- } while (name != NULL);
-
- return hash;
-}
-
-
-/*
- * This function checks if a path is valid.
- *
- * @path: Path to check.
- *
- * Returns true if valid, otherwise false.
- */
-bool
-vfs_is_valid_path(const char *path)
-{
- const char *ptr = path;
- char c;
-
- while (*ptr != '\0') {
- c = *(ptr++);
- switch (c) {
- case '/':
- case '-':
- case '_':
- case '.':
- /* Valid char, can continue */
- continue;
- default:
- /*
- * This could be an alphabetical or "numeric" char which
- * is valid. We want to handle this too. To make things
- * easier we'll OR the char by 0x20 to convert it to
- * lowercase if it is alphabetical.
- */
- c |= 0x20;
- if (c >= 'a' && c <= 'z')
- continue;
- else if (c >= '0' && c <= '9')
- continue;
-
- /* We got an invalid char */
- return false;
- }
- }
-
- return true;
-}
-
-/*
- * Allocates a vnode
- *
- * @vnode: Pointer to vnode pointer where newly allocated
- * vnode will be stored.
- *
- * @mp: Mountpoint this vnode is associated with.
- * @type: Vnode type.
- *
- * This function will return 0 upon success and < 0 on failure.
- */
-int
-vfs_alloc_vnode(struct vnode **vnode, struct mount *mp, int type)
-{
- struct vnode *new_vnode = dynalloc(sizeof(struct vnode));
-
- if (new_vnode == NULL) {
- return -ENOMEM;
- }
-
- memset(new_vnode, 0, sizeof(struct vnode));
- new_vnode->type = type;
- new_vnode->mp = mp;
-
- *vnode = new_vnode;
- return 0;
-}
-
-/*
- * Returns the rootname of a path
- * For example, "/foo/bar/" will be "foo" and
- * "/foo/bar/baz" will also be "foo"
- *
- * There will be no slashes in the returned string
- * unless "/" is passed.
- *
- * XXX: Returns memory allocated by dynalloc,
- * remember to free the memory with dynfree()
- *
- * @path: Path to get rootname of
- * @new_path: New path will be placed here.
- */
-int
-vfs_rootname(const char *path, char **new_path)
-{
- char *tmp = NULL;
- const char *ptr = path;
- size_t len = 0;
-
- if (!vfs_is_valid_path(path)) {
- *new_path = NULL;
- return -EINVAL;
- }
-
- if (*path == '/') {
- /* Skip first '/' */
- ++ptr;
- ++path;
- }
-
- for (; *ptr != '\0' && *ptr != '/'; ++ptr) {
- if (*ptr == '/') {
- break;
- }
- ++len;
- }
-
- tmp = dynalloc(sizeof(char) * len + 1);
- if (tmp == NULL) {
- *new_path = NULL;
- return -ENOMEM;
- }
-
- if (len == 0) {
- /* Handle input that is just "/" */
- tmp[0] = '/';
- tmp[1] = '\0';
- } else {
- memcpy(tmp, path, len + 2);
- }
-
- *new_path = tmp;
- return 0;
-}
-
-
-int
-vfs_vget(struct vnode *parent, const char *name, struct vnode **vp)
-{
- return parent->vops->vget(parent, name, vp);
-}
-
-ssize_t
-vfs_read(struct vnode *vp, struct sio_txn *sio)
-{
- return vp->vops->read(vp, sio);
-}
-
-ssize_t
-vfs_write(struct vnode *vp, struct sio_txn *sio)
-{
- return vp->vops->write(vp, sio);
-}
-
-int
-vfs_getattr(struct vnode *vp, struct vattr *vattr)
-{
- return vp->vops->getattr(vp, vattr);
-}
-
-int vfs_open(struct vnode *vp)
-{
- if (vp->vops->open == NULL)
- return -EIO;
-
- return vp->vops->open(vp);
-}
-
-int
-vfs_close(struct vnode *vp)
-{
- if (vp->vops->close == NULL)
- return -EIO;
-
- return vp->vops->close(vp);
-}
diff --git a/sys/lib/logo.c b/sys/lib/logo.c
deleted file mode 100644
index 051d597..0000000
--- a/sys/lib/logo.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <lib/logo.h>
-
-/*
- * Ascii art logo.
- */
-
-uint8_t g_logo[] = {
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x60, 0x38, 0x2E, 0x60,
- 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2C, 0x38, 0x27, 0x20, 0x38,
- 0x20, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x6F, 0x2E, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x20, 0x60, 0x38, 0x2E, 0x60, 0x38, 0x38, 0x38,
- 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x2C, 0x38, 0x27, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38,
- 0x38, 0x20, 0x20, 0x20, 0x20, 0x60, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x2E, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x60, 0x38, 0x2E, 0x60, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20,
- 0x20, 0x2C, 0x38, 0x27, 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x60, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3A, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20,
- 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20,
- 0x20, 0x20, 0x20, 0x60, 0x38, 0x2E, 0x60, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x2C, 0x38, 0x27, 0x20,
- 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2C, 0x38,
- 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x60, 0x38, 0x2E, 0x60, 0x38, 0x38, 0x38, 0x38, 0x38, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38,
- 0x20, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x2C, 0x38, 0x38, 0x27, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x2E, 0x38, 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x38, 0x2E,
- 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x50, 0x27, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E,
- 0x38, 0x60, 0x38, 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x38, 0x20, 0x38, 0x38, 0x38,
- 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x60, 0x38, 0x62,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E, 0x38, 0x27, 0x20, 0x60, 0x38,
- 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20,
- 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x60, 0x38, 0x62, 0x2E, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E, 0x38, 0x27, 0x20, 0x20, 0x20, 0x60, 0x38, 0x2E, 0x20, 0x60,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38,
- 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x60, 0x38, 0x62, 0x2E, 0x20, 0x20, 0x20, 0x20,
- 0x2E, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x2E, 0x20, 0x20, 0x0A, 0x38, 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38,
- 0x20, 0x38, 0x38, 0x38, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x20, 0x38, 0x38, 0x38,
- 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x38, 0x38, 0x2E, 0x20, 0x2E, 0x38, 0x27, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0x38, 0x2E, 0x20, 0x60, 0x38, 0x38, 0x38, 0x38, 0x38, 0x2E,
- 0x20, 0x00
-};
diff --git a/sys/lib/string/itoa.c b/sys/lib/string/itoa.c
deleted file mode 100644
index 01e2fef..0000000
--- a/sys/lib/string/itoa.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-static char *itoa_base10_convert(int64_t value, char *buf);
-
-static char *
-itoa_base10_convert(int64_t value, char *buf)
-{
- size_t i;
- uint8_t tmp;
- bool is_negative;
-
- i = 0;
- is_negative = false;
-
- if (value == 0) {
- buf[i++] = '0';
- buf[i++] = '\0';
- return buf;
- }
-
- if (value < 0) {
- /* Easier to handle positive numbers */
- value *= -1;
- is_negative = true;
- }
-
- while (value > 0) {
- buf[i++] = '0' + (value % 10);
- value /= 10;
- }
-
- if (is_negative) {
- buf[i++] = '-';
- }
-
- buf[i--] = '\0';
-
- /* Result is in reverse */
- for (int j = 0; j < i; ++j, --i) {
- tmp = buf[j];
- buf[j] = buf[i];
- buf[i] = tmp;
- }
-
- return buf;
-}
-
-static char *
-itoa_convert_base16(uint64_t n, char *buffer)
-{
- bool pad;
- uint8_t nibble;
- uint8_t i, j, tmp;
- const char *ascii_nums = "0123456789ABCDEF";
-
- i = 0;
- pad = false;
-
- if (n == 0) {
- /* Zero, no need to parse */
- memcpy(buffer, "0x00\0", 5);
- return buffer;
- }
- /* If one digit, pad out 2 later */
- if (n < 0x10) {
- pad = true;
- }
-
- while (n > 0) {
- nibble = (uint8_t)n & 0x0F;
- nibble = ascii_nums[nibble];
- buffer[i++] = nibble;
- n >>= 4; /* Fetch next nibble */
- }
-
- if (pad) {
- buffer[i++] = '0';
- }
-
- /* Add "0x" prefix */
- buffer[i++] = 'x';
- buffer[i++] = '0';
- buffer[i--] = '\0';
-
- /* Unreverse the result */
- for (j = 0; j < i; ++j, --i) {
- tmp = buffer[j];
- buffer[j] = buffer[i];
- buffer[i] = tmp;
- }
- return buffer;
-}
-
-char *
-itoa(int64_t value, char *buf, int base)
-{
- switch (base) {
- case 10:
- return itoa_base10_convert(value, buf);
- case 16:
- return itoa_convert_base16(value, buf);
- default:
- return NULL;
- }
-}
diff --git a/sys/lib/string/memcmp.c b/sys/lib/string/memcmp.c
deleted file mode 100644
index 6e95aa8..0000000
--- a/sys/lib/string/memcmp.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2023-2024 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.
- */
-/* $Id */
-
-#include <string.h>
-
-int
-memcmp(const void *s1, const void *s2, size_t n)
-{
- if (n != 0) {
- const unsigned char *p1 = s1, *p2 = s2;
-
- do {
- if (*p1++ != *p2++) {
- return (*--p1 - *--p2);
- }
- } while (--n != 0);
- }
- return 0;
-}
diff --git a/sys/lib/string/memcpy.c b/sys/lib/string/memcpy.c
deleted file mode 100644
index 09cb90e..0000000
--- a/sys/lib/string/memcpy.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-void *
-memcpy(void *dest, const void *src, size_t n)
-{
- for (size_t i = 0; i < n; ++i) {
- ((char *)dest)[i] = ((char *)src)[i];
- }
-
- return dest;
-}
-
-void *
-memcpy32(void *dest, const void *src, size_t n)
-{
- for (size_t i = 0; i < n; ++i) {
- ((uint32_t *)dest)[i] = ((uint32_t *)src)[i];
- }
-
- return dest;
-}
diff --git a/sys/lib/string/memmove.c b/sys/lib/string/memmove.c
deleted file mode 100644
index ea5cad2..0000000
--- a/sys/lib/string/memmove.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-void *
-memmove(void *s1, const void *s2, size_t n)
-{
- const char *f = s2;
- char *t = s1;
-
- if (f < t) {
- f += n;
- t += n;
- while (n-- > 0)
- *--t = *--f;
- } else {
- while (n-- > 0)
- *t++ = *f++;
- }
-
- return s1;
-}
diff --git a/sys/lib/string/memset.c b/sys/lib/string/memset.c
deleted file mode 100644
index 4e92cc6..0000000
--- a/sys/lib/string/memset.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-void *
-memset(void *s, int c, size_t n)
-{
- for (size_t i = 0; i < n; ++i) {
- ((char *)s)[i] = c;
- }
-
- return s;
-}
-
-void *
-memset64(void *s, int c, size_t n)
-{
- for (size_t i = 0; i < n; ++i) {
- ((uint32_t *)s)[i] = c;
- }
-
- return s;
-}
diff --git a/sys/lib/string/strcmp.c b/sys/lib/string/strcmp.c
deleted file mode 100644
index 4648f32..0000000
--- a/sys/lib/string/strcmp.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-int
-strcmp(const char *s1, const char *s2)
-{
- while (*s1 == *s2++)
- if (*s1++ == 0)
- return (0);
- return (*(unsigned char *)s1 - *(unsigned char *)--s2);
-}
diff --git a/sys/lib/string/strlen.c b/sys/lib/string/strlen.c
deleted file mode 100644
index 85ccf23..0000000
--- a/sys/lib/string/strlen.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-
-size_t
-strlen(const char *s)
-{
- size_t len;
-
- len = 0;
- while (s[len++]);
- return len - 1;
-}
diff --git a/sys/lib/string/vsnprintf.c b/sys/lib/string/vsnprintf.c
deleted file mode 100644
index b8a4faa..0000000
--- a/sys/lib/string/vsnprintf.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-
-static inline void
-printc(char *buf, size_t size, size_t *off, char c)
-{
- if (*off < size - 1) {
- buf[(*off)++] = c;
- }
- buf[*off] = 0;
-}
-
-static void
-printstr(char *buf, size_t size, size_t *off, const char *s)
-{
- while (*off < size - 1 && *s != '\0') {
- buf[(*off)++] = *(s)++;
- }
- buf[*off] = 0;
-}
-
-int
-snprintf(char *s, size_t size, const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = vsnprintf(s, size, fmt, ap);
- va_end(ap);
- return ret;
-}
-
-int
-vsnprintf(char *s, size_t size, const char *fmt, va_list ap)
-{
- size_t tmp_len, num_len, off = 0;
- ssize_t num = 0;
- char c, c1, num_buf[256] = {0};
- const char *tmp_str;
- uint8_t pad_width = 0;
-
- while (off < (size - 1)) {
- while (*fmt && *fmt != '%') {
- printc(s, size, &off, *fmt++);
- }
- if (*(fmt)++ == '\0' || off == size - 1) {
- return off;
- }
-
- /*
- * Handle a case where we have "%0N". For example:
- * "%04d"
- */
- if (*fmt == '0') {
- ++fmt;
- while (*fmt >= '0' && *fmt <= '9') {
- pad_width = pad_width * 10 + (*fmt - '0');
- ++fmt;
- }
- }
-
- c = *fmt++;
- switch (c) {
- case 'c':
- c1 = (char )va_arg(ap, int);
- printc(s, size, &off, c1);
- break;
- case 'd':
- num = va_arg(ap, int);
- itoa(num, num_buf, 10);
-
- if (pad_width > 0) {
- num_len = strlen(num_buf);
- for (size_t i = num_len; i < pad_width; ++i)
- printc(s, size, &off, '0');
- }
- printstr(s, size, &off, num_buf);
- break;
- case 'p':
- num = va_arg(ap, uint64_t);
- itoa(num, num_buf, 16);
- tmp_len = strlen(num_buf);
- /*
- * Now we pad this.
- *
- * XXX TODO: This assumes 64-bits, should be
- * cleaned up.
- */
- for (size_t i = 0; i < 18 - tmp_len; ++i) {
- printc(s, size, &off, '0');
- }
- printstr(s, size, &off, num_buf + 2);
- break;
- case 'x':
- num = va_arg(ap, uint64_t);
- itoa(num, num_buf, 16);
- tmp_len = strlen(num_buf);
- printstr(s, size, &off, num_buf + 2);
- break;
- case 's':
- tmp_str = va_arg(ap, const char *);
- printstr(s, size, &off, tmp_str);
- break;
- }
- }
-
- return 0;
-}
diff --git a/sys/lib/sysfont.c b/sys/lib/sysfont.c
deleted file mode 100644
index e5ae2aa..0000000
--- a/sys/lib/sysfont.c
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <lib/sysfont.h>
-
-
-const uint8_t DEFAULT_FONT_DATA[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x81, 0x81, 0xa5, 0xa5, 0x81,
- 0x81, 0xa5, 0x99, 0x81, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0xff,
- 0xff, 0xdb, 0xdb, 0xff, 0xff, 0xdb, 0xe7, 0xff, 0x7e, 0x3c, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe,
- 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
- 0x3c, 0x3c, 0xdb, 0xff, 0xff, 0xdb, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0x66, 0x18, 0x18,
- 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
- 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x84, 0x84, 0xcc, 0x78, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd,
- 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1e,
- 0x0e, 0x1e, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x18, 0x1c, 0x1e, 0x16, 0x12,
- 0x10, 0x10, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x38, 0x2c,
- 0x26, 0x32, 0x3a, 0x2e, 0x26, 0x22, 0x62, 0xe2, 0xc6, 0x0e, 0x0c, 0x00,
- 0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe,
- 0xf8, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
- 0x06, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78,
- 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
- 0xcc, 0xcc, 0x00, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb,
- 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c,
- 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78,
- 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x78, 0x30, 0xfc, 0x00, 0x00,
- 0x00, 0x00, 0x30, 0x78, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x30, 0x30, 0xfc, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x18, 0x0c, 0xfe, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0xfe, 0x60, 0x30, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
- 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x24, 0x66, 0xff, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c,
- 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x30, 0x30, 0x00, 0x30,
- 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
- 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
- 0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc0, 0xc0, 0x7c, 0x06, 0x06, 0xc6, 0x7c,
- 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x0c, 0x0c, 0x18, 0x38,
- 0x30, 0x60, 0x60, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
- 0x6c, 0x38, 0x30, 0x76, 0xde, 0xcc, 0xcc, 0xde, 0x76, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60, 0x60, 0x60,
- 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x38, 0xfe, 0x38, 0x6c, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e,
- 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06,
- 0x0c, 0x0c, 0x18, 0x38, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
- 0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0x06, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc,
- 0xfe, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0,
- 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x3c, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18,
- 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
- 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c,
- 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
- 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00,
- 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x0c,
- 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
- 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x60,
- 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x00, 0x30,
- 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xde, 0xde,
- 0xde, 0xde, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
- 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0,
- 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
- 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xf8, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
- 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0,
- 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
- 0xc0, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6,
- 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c,
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc6, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6,
- 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
- 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
- 0xee, 0xfe, 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc6, 0xc6, 0xe6, 0xe6, 0xf6, 0xde, 0xce, 0xce, 0xc6, 0xc6,
- 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xf6, 0xda,
- 0x6c, 0x06, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc,
- 0xd8, 0xcc, 0xcc, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
- 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c,
- 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x38,
- 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc,
- 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfe, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc0, 0xc0,
- 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60,
- 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
- 0x60, 0x60, 0x30, 0x38, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0x18, 0x18, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x06, 0x06,
- 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
- 0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xe6, 0xdc, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x76, 0xce, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xce, 0xc6,
- 0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
- 0xc0, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x18, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1e, 0x06, 0x06,
- 0x06, 0x06, 0x06, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0xc0, 0xc0,
- 0xc0, 0xc6, 0xcc, 0xd8, 0xf0, 0xf0, 0xd8, 0xcc, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6,
- 0xd6, 0xd6, 0xd6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc6,
- 0xc6, 0xc6, 0xe6, 0xdc, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x76, 0xce, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0x06, 0x06, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xe6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
- 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0,
- 0x70, 0x1c, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
- 0x30, 0xfe, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x38, 0x38, 0x6c, 0xc6,
- 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xfe, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xfe, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x30, 0x30,
- 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00,
- 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x30,
- 0x30, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x30, 0x30, 0xe0, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x38, 0x38, 0x6c,
- 0x6c, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66,
- 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x18, 0xcc, 0x78, 0x00,
- 0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6,
- 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
- 0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6,
- 0x7e, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0x06, 0x06,
- 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38,
- 0x00, 0x7c, 0x06, 0x06, 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6,
- 0x7c, 0x18, 0x0c, 0x38, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
- 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
- 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0, 0x7e, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc0, 0xc0, 0xc0,
- 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x38, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
- 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x3c, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6,
- 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00,
- 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x18, 0x30, 0x60, 0x00, 0xfe, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0,
- 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x36, 0x36,
- 0x76, 0xde, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3c,
- 0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00,
- 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18,
- 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
- 0x00, 0x10, 0x38, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c,
- 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xce, 0x76, 0x06, 0xc6, 0x7c, 0x00,
- 0x6c, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
- 0x30, 0x78, 0xcc, 0xc0, 0xc0, 0xcc, 0x78, 0x30, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x38, 0x6c, 0x60, 0x60, 0x60, 0xf8, 0x60, 0x60, 0x60, 0xe6,
- 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0xfc,
- 0x30, 0xfc, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc,
- 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0xd8, 0x70, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0x06, 0x06,
- 0x7e, 0xc6, 0xc6, 0xc6, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30,
- 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
- 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0xc6, 0xc6, 0xc6,
- 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
- 0x00, 0xdc, 0xe6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x76, 0xdc, 0x00, 0xc6, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6,
- 0xc6, 0x00, 0x00, 0x00, 0x00, 0x78, 0xd8, 0xd8, 0x6c, 0x00, 0xfc, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
- 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xc6,
- 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xfe, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30, 0x60, 0xdc, 0x86, 0x0c,
- 0x18, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc2, 0xc6, 0xcc, 0xd8, 0x30,
- 0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
- 0x00, 0x30, 0x30, 0x30, 0x78, 0x78, 0x78, 0x78, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36,
- 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88,
- 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88,
- 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
- 0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77,
- 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
- 0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18,
- 0x18, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0xf6, 0xf6, 0x06, 0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x06,
- 0x06, 0xf6, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0xf6, 0xf6, 0x06, 0x06, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0xfe, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0xf8, 0x18,
- 0x18, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37,
- 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x37, 0x37, 0x30, 0x30, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x30, 0x30, 0x37, 0x37, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0xf7, 0x00,
- 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0xff, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x37, 0x30, 0x30, 0x37, 0x37, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
- 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0xf7, 0xf7, 0x00, 0x00, 0xf7, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f,
- 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x1f, 0x1f, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
- 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0xff, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0x18, 0x18, 0xff, 0xff, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8,
- 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
- 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x76, 0xd6, 0xdc, 0xc8, 0xc8, 0xdc, 0xd6, 0x76, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
- 0xd8, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0,
- 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x7e, 0xfe, 0x24, 0x24, 0x24, 0x24, 0x66, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfe, 0xfe, 0xc2, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc2, 0xfe,
- 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xc8, 0xcc,
- 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x76, 0x6c, 0x60, 0xc0, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0xfc, 0x98, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x30, 0x30, 0x78, 0xcc, 0xcc,
- 0xcc, 0x78, 0x30, 0x30, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
- 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c,
- 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x60, 0x30, 0x78, 0xcc,
- 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x76, 0xbb, 0x99, 0x99, 0xdd, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x02, 0x06, 0x3c, 0x6c, 0xce, 0xd6, 0xd6, 0xe6, 0x6c, 0x78,
- 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x60, 0xc0, 0xc0, 0xfe,
- 0xc0, 0xc0, 0x60, 0x30, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
- 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc,
- 0x30, 0x30, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00,
- 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x36, 0x30, 0x30, 0x30,
- 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x18, 0x18, 0x18,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0xfc, 0x00, 0x30, 0x30, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
- 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc,
- 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c,
- 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0x6c, 0x3c, 0x1c, 0x0c, 0x00, 0x00,
- 0x00, 0xd8, 0xec, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x0c, 0x18, 0x30, 0x60, 0x7c,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
-};
diff --git a/sys/vm/tlsf.c b/sys/vm/tlsf.c
deleted file mode 100644
index d4a6ddf..0000000
--- a/sys/vm/tlsf.c
+++ /dev/null
@@ -1,1264 +0,0 @@
-#include <sys/syslog.h>
-#include <sys/types.h>
-#include <assert.h>
-#include <limits.h>
-#include <string.h>
-#include <vm/tlsf.h>
-
-#define printf kprintf
-
-#if defined(__cplusplus)
-#define tlsf_decl inline
-#else
-#define tlsf_decl static
-#endif
-
-/*
-** Architecture-specific bit manipulation routines.
-**
-** TLSF achieves O(1) cost for malloc and free operations by limiting
-** the search for a free block to a free list of guaranteed size
-** adequate to fulfill the request, combined with efficient free list
-** queries using bitmasks and architecture-specific bit-manipulation
-** routines.
-**
-** Most modern processors provide instructions to count leading zeroes
-** in a word, find the lowest and highest set bit, etc. These
-** specific implementations will be used when available, falling back
-** to a reasonably efficient generic implementation.
-**
-** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
-** ffs/fls return 1-32 by default, returning 0 for error.
-*/
-
-/*
-** Detect whether or not we are building for a 32- or 64-bit (LP/LLP)
-** architecture. There is no reliable portable method at compile-time.
-*/
-#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \
- || defined (_WIN64) || defined (__LP64__) || defined (__LLP64__)
-#define TLSF_64BIT
-#endif
-
-/*
-** gcc 3.4 and above have builtin support, specialized for architecture.
-** Some compilers masquerade as gcc; patchlevel test filters them out.
-*/
-#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
- && defined (__GNUC_PATCHLEVEL__)
-
-#if defined (__SNC__)
-/* SNC for Playstation 3. */
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- const unsigned int reverse = word & (~word + 1);
- const int bit = 32 - __builtin_clz(reverse);
- return bit - 1;
-}
-
-#else
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- return __builtin_ffs(word) - 1;
-}
-
-#endif
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- const int bit = word ? 32 - __builtin_clz(word) : 0;
- return bit - 1;
-}
-
-#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64))
-/* Microsoft Visual C++ support on x86/X64 architectures. */
-
-#include <intrin.h>
-
-#pragma intrinsic(_BitScanReverse)
-#pragma intrinsic(_BitScanForward)
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- unsigned long index;
- return _BitScanReverse(&index, word) ? index : -1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- unsigned long index;
- return _BitScanForward(&index, word) ? index : -1;
-}
-
-#elif defined (_MSC_VER) && defined (_M_PPC)
-/* Microsoft Visual C++ support on PowerPC architectures. */
-
-#include <ppcintrinsics.h>
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- const int bit = 32 - _CountLeadingZeros(word);
- return bit - 1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- const unsigned int reverse = word & (~word + 1);
- const int bit = 32 - _CountLeadingZeros(reverse);
- return bit - 1;
-}
-
-#elif defined (__ARMCC_VERSION)
-/* RealView Compilation Tools for ARM */
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- const unsigned int reverse = word & (~word + 1);
- const int bit = 32 - __clz(reverse);
- return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- const int bit = word ? 32 - __clz(word) : 0;
- return bit - 1;
-}
-
-#elif defined (__ghs__)
-/* Green Hills support for PowerPC */
-
-#include <ppc_ghs.h>
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- const unsigned int reverse = word & (~word + 1);
- const int bit = 32 - __CLZ32(reverse);
- return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- const int bit = word ? 32 - __CLZ32(word) : 0;
- return bit - 1;
-}
-
-#else
-/* Fall back to generic implementation. */
-
-tlsf_decl int tlsf_fls_generic(unsigned int word)
-{
- int bit = 32;
-
- if (!word) bit -= 1;
- if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; }
- if (!(word & 0xff000000)) { word <<= 8; bit -= 8; }
- if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; }
- if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; }
- if (!(word & 0x80000000)) { word <<= 1; bit -= 1; }
-
- return bit;
-}
-
-/* Implement ffs in terms of fls. */
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
- return tlsf_fls_generic(word & (~word + 1)) - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
- return tlsf_fls_generic(word) - 1;
-}
-
-#endif
-
-/* Possibly 64-bit version of tlsf_fls. */
-#if defined (TLSF_64BIT)
-tlsf_decl int tlsf_fls_sizet(size_t size)
-{
- int high = (int)(size >> 32);
- int bits = 0;
- if (high)
- {
- bits = 32 + tlsf_fls(high);
- }
- else
- {
- bits = tlsf_fls((int)size & 0xffffffff);
-
- }
- return bits;
-}
-#else
-#define tlsf_fls_sizet tlsf_fls
-#endif
-
-#undef tlsf_decl
-
-/*
-** Constants.
-*/
-
-/* Public constants: may be modified. */
-enum tlsf_public
-{
- /* log2 of number of linear subdivisions of block sizes. Larger
- ** values require more memory in the control structure. Values of
- ** 4 or 5 are typical.
- */
- SL_INDEX_COUNT_LOG2 = 5,
-};
-
-/* Private constants: do not modify. */
-enum tlsf_private
-{
-#if defined (TLSF_64BIT)
- /* All allocation sizes and addresses are aligned to 8 bytes. */
- ALIGN_SIZE_LOG2 = 3,
-#else
- /* All allocation sizes and addresses are aligned to 4 bytes. */
- ALIGN_SIZE_LOG2 = 2,
-#endif
- ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
-
- /*
- ** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits.
- ** However, because we linearly subdivide the second-level lists, and
- ** our minimum size granularity is 4 bytes, it doesn't make sense to
- ** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4,
- ** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
- ** trying to split size ranges into more slots than we have available.
- ** Instead, we calculate the minimum threshold size, and place all
- ** blocks below that size into the 0th first-level list.
- */
-
-#if defined (TLSF_64BIT)
- /*
- ** TODO: We can increase this to support larger sizes, at the expense
- ** of more overhead in the TLSF structure.
- */
- FL_INDEX_MAX = 32,
-#else
- FL_INDEX_MAX = 30,
-#endif
- SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2),
- FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2),
- FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1),
-
- SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT),
-};
-
-/*
-** Cast and min/max macros.
-*/
-
-#define tlsf_cast(t, exp) ((t) (exp))
-#define tlsf_min(a, b) ((a) < (b) ? (a) : (b))
-#define tlsf_max(a, b) ((a) > (b) ? (a) : (b))
-
-/*
-** Set assert macro, if it has not been provided by the user.
-*/
-#if !defined (tlsf_assert)
-#define tlsf_assert __assert
-#endif
-
-/*
-** Static assertion mechanism.
-*/
-
-#define _tlsf_glue2(x, y) x ## y
-#define _tlsf_glue(x, y) _tlsf_glue2(x, y)
-#define tlsf_static_assert(exp) \
- typedef char _tlsf_glue(static_assert, __LINE__) [(exp) ? 1 : -1]
-
-/* This code has been tested on 32- and 64-bit (LP/LLP) architectures. */
-tlsf_static_assert(sizeof(int) * CHAR_BIT == 32);
-tlsf_static_assert(sizeof(size_t) * CHAR_BIT >= 32);
-tlsf_static_assert(sizeof(size_t) * CHAR_BIT <= 64);
-
-/* SL_INDEX_COUNT must be <= number of bits in sl_bitmap's storage type. */
-tlsf_static_assert(sizeof(unsigned int) * CHAR_BIT >= SL_INDEX_COUNT);
-
-/* Ensure we've properly tuned our sizes. */
-tlsf_static_assert(ALIGN_SIZE == SMALL_BLOCK_SIZE / SL_INDEX_COUNT);
-
-/*
-** Data structures and associated constants.
-*/
-
-/*
-** Block header structure.
-**
-** There are several implementation subtleties involved:
-** - The prev_phys_block field is only valid if the previous block is free.
-** - The prev_phys_block field is actually stored at the end of the
-** previous block. It appears at the beginning of this structure only to
-** simplify the implementation.
-** - The next_free / prev_free fields are only valid if the block is free.
-*/
-typedef struct block_header_t
-{
- /* Points to the previous physical block. */
- struct block_header_t* prev_phys_block;
-
- /* The size of this block, excluding the block header. */
- size_t size;
-
- /* Next and previous free blocks. */
- struct block_header_t* next_free;
- struct block_header_t* prev_free;
-} block_header_t;
-
-/*
-** Since block sizes are always at least a multiple of 4, the two least
-** significant bits of the size field are used to store the block status:
-** - bit 0: whether block is busy or free
-** - bit 1: whether previous block is busy or free
-*/
-static const size_t block_header_free_bit = 1 << 0;
-static const size_t block_header_prev_free_bit = 1 << 1;
-
-/*
-** The size of the block header exposed to used blocks is the size field.
-** The prev_phys_block field is stored *inside* the previous free block.
-*/
-static const size_t block_header_overhead = sizeof(size_t);
-
-/* User data starts directly after the size field in a used block. */
-static const size_t block_start_offset =
- offsetof(block_header_t, size) + sizeof(size_t);
-
-/*
-** A free block must be large enough to store its header minus the size of
-** the prev_phys_block field, and no larger than the number of addressable
-** bits for FL_INDEX.
-*/
-static const size_t block_size_min =
- sizeof(block_header_t) - sizeof(block_header_t*);
-static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX;
-
-
-/* The TLSF control structure. */
-typedef struct control_t
-{
- /* Empty lists point at this block to indicate they are free. */
- block_header_t block_null;
-
- /* Bitmaps for free lists. */
- unsigned int fl_bitmap;
- unsigned int sl_bitmap[FL_INDEX_COUNT];
-
- /* Head of free lists. */
- block_header_t* blocks[FL_INDEX_COUNT][SL_INDEX_COUNT];
-} control_t;
-
-/* A type used for casting when doing pointer arithmetic. */
-typedef ptrdiff_t tlsfptr_t;
-
-/*
-** block_header_t member functions.
-*/
-
-static size_t block_size(const block_header_t* block)
-{
- return block->size & ~(block_header_free_bit | block_header_prev_free_bit);
-}
-
-static void block_set_size(block_header_t* block, size_t size)
-{
- const size_t oldsize = block->size;
- block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit));
-}
-
-static int block_is_last(const block_header_t* block)
-{
- return block_size(block) == 0;
-}
-
-static int block_is_free(const block_header_t* block)
-{
- return tlsf_cast(int, block->size & block_header_free_bit);
-}
-
-static void block_set_free(block_header_t* block)
-{
- block->size |= block_header_free_bit;
-}
-
-static void block_set_used(block_header_t* block)
-{
- block->size &= ~block_header_free_bit;
-}
-
-static int block_is_prev_free(const block_header_t* block)
-{
- return tlsf_cast(int, block->size & block_header_prev_free_bit);
-}
-
-static void block_set_prev_free(block_header_t* block)
-{
- block->size |= block_header_prev_free_bit;
-}
-
-static void block_set_prev_used(block_header_t* block)
-{
- block->size &= ~block_header_prev_free_bit;
-}
-
-static block_header_t* block_from_ptr(const void* ptr)
-{
- return tlsf_cast(block_header_t*,
- tlsf_cast(unsigned char*, ptr) - block_start_offset);
-}
-
-static void* block_to_ptr(const block_header_t* block)
-{
- return tlsf_cast(void*,
- tlsf_cast(unsigned char*, block) + block_start_offset);
-}
-
-/* Return location of next block after block of given size. */
-static block_header_t* offset_to_block(const void* ptr, size_t size)
-{
- return tlsf_cast(block_header_t*, tlsf_cast(tlsfptr_t, ptr) + size);
-}
-
-/* Return location of previous block. */
-static block_header_t* block_prev(const block_header_t* block)
-{
- tlsf_assert(block_is_prev_free(block) && "previous block must be free");
- return block->prev_phys_block;
-}
-
-/* Return location of next existing block. */
-static block_header_t* block_next(const block_header_t* block)
-{
- block_header_t* next = offset_to_block(block_to_ptr(block),
- block_size(block) - block_header_overhead);
- tlsf_assert(!block_is_last(block));
- return next;
-}
-
-/* Link a new block with its physical neighbor, return the neighbor. */
-static block_header_t* block_link_next(block_header_t* block)
-{
- block_header_t* next = block_next(block);
- next->prev_phys_block = block;
- return next;
-}
-
-static void block_mark_as_free(block_header_t* block)
-{
- /* Link the block to the next block, first. */
- block_header_t* next = block_link_next(block);
- block_set_prev_free(next);
- block_set_free(block);
-}
-
-static void block_mark_as_used(block_header_t* block)
-{
- block_header_t* next = block_next(block);
- block_set_prev_used(next);
- block_set_used(block);
-}
-
-static size_t align_up(size_t x, size_t align)
-{
- tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
- return (x + (align - 1)) & ~(align - 1);
-}
-
-static size_t align_down(size_t x, size_t align)
-{
- tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
- return x - (x & (align - 1));
-}
-
-static void* align_ptr(const void* ptr, size_t align)
-{
- const tlsfptr_t aligned =
- (tlsf_cast(tlsfptr_t, ptr) + (align - 1)) & ~(align - 1);
- tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
- return tlsf_cast(void*, aligned);
-}
-
-/*
-** Adjust an allocation size to be aligned to word size, and no smaller
-** than internal minimum.
-*/
-static size_t adjust_request_size(size_t size, size_t align)
-{
- size_t adjust = 0;
- if (size)
- {
- const size_t aligned = align_up(size, align);
-
- /* aligned sized must not exceed block_size_max or we'll go out of bounds on sl_bitmap */
- if (aligned < block_size_max)
- {
- adjust = tlsf_max(aligned, block_size_min);
- }
- }
- return adjust;
-}
-
-/*
-** TLSF utility functions. In most cases, these are direct translations of
-** the documentation found in the white paper.
-*/
-
-static void mapping_insert(size_t size, int* fli, int* sli)
-{
- int fl, sl;
- if (size < SMALL_BLOCK_SIZE)
- {
- /* Store small blocks in first list. */
- fl = 0;
- sl = tlsf_cast(int, size) / (SMALL_BLOCK_SIZE / SL_INDEX_COUNT);
- }
- else
- {
- fl = tlsf_fls_sizet(size);
- sl = tlsf_cast(int, size >> (fl - SL_INDEX_COUNT_LOG2)) ^ (1 << SL_INDEX_COUNT_LOG2);
- fl -= (FL_INDEX_SHIFT - 1);
- }
- *fli = fl;
- *sli = sl;
-}
-
-/* This version rounds up to the next block size (for allocations) */
-static void mapping_search(size_t size, int* fli, int* sli)
-{
- if (size >= SMALL_BLOCK_SIZE)
- {
- const size_t round = (1 << (tlsf_fls_sizet(size) - SL_INDEX_COUNT_LOG2)) - 1;
- size += round;
- }
- mapping_insert(size, fli, sli);
-}
-
-static block_header_t* search_suitable_block(control_t* control, int* fli, int* sli)
-{
- int fl = *fli;
- int sl = *sli;
-
- /*
- ** First, search for a block in the list associated with the given
- ** fl/sl index.
- */
- unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl);
- if (!sl_map)
- {
- /* No block exists. Search in the next largest first-level list. */
- const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1));
- if (!fl_map)
- {
- /* No free blocks available, memory has been exhausted. */
- return 0;
- }
-
- fl = tlsf_ffs(fl_map);
- *fli = fl;
- sl_map = control->sl_bitmap[fl];
- }
- tlsf_assert(sl_map && "internal error - second level bitmap is null");
- sl = tlsf_ffs(sl_map);
- *sli = sl;
-
- /* Return the first block in the free list. */
- return control->blocks[fl][sl];
-}
-
-/* Remove a free block from the free list.*/
-static void remove_free_block(control_t* control, block_header_t* block, int fl, int sl)
-{
- block_header_t* prev = block->prev_free;
- block_header_t* next = block->next_free;
- tlsf_assert(prev && "prev_free field can not be null");
- tlsf_assert(next && "next_free field can not be null");
- next->prev_free = prev;
- prev->next_free = next;
-
- /* If this block is the head of the free list, set new head. */
- if (control->blocks[fl][sl] == block)
- {
- control->blocks[fl][sl] = next;
-
- /* If the new head is null, clear the bitmap. */
- if (next == &control->block_null)
- {
- control->sl_bitmap[fl] &= ~(1U << sl);
-
- /* If the second bitmap is now empty, clear the fl bitmap. */
- if (!control->sl_bitmap[fl])
- {
- control->fl_bitmap &= ~(1U << fl);
- }
- }
- }
-}
-
-/* Insert a free block into the free block list. */
-static void insert_free_block(control_t* control, block_header_t* block, int fl, int sl)
-{
- block_header_t* current = control->blocks[fl][sl];
- tlsf_assert(current && "free list cannot have a null entry");
- tlsf_assert(block && "cannot insert a null entry into the free list");
- block->next_free = current;
- block->prev_free = &control->block_null;
- current->prev_free = block;
-
- tlsf_assert((uintptr_t)block_to_ptr(block) == (uintptr_t)align_ptr(block_to_ptr(block), ALIGN_SIZE)
- && "block not aligned properly");
- /*
- ** Insert the new block at the head of the list, and mark the first-
- ** and second-level bitmaps appropriately.
- */
- control->blocks[fl][sl] = block;
- control->fl_bitmap |= (1U << fl);
- control->sl_bitmap[fl] |= (1U << sl);
-}
-
-/* Remove a given block from the free list. */
-static void block_remove(control_t* control, block_header_t* block)
-{
- int fl, sl;
- mapping_insert(block_size(block), &fl, &sl);
- remove_free_block(control, block, fl, sl);
-}
-
-/* Insert a given block into the free list. */
-static void block_insert(control_t* control, block_header_t* block)
-{
- int fl, sl;
- mapping_insert(block_size(block), &fl, &sl);
- insert_free_block(control, block, fl, sl);
-}
-
-static int block_can_split(block_header_t* block, size_t size)
-{
- return block_size(block) >= sizeof(block_header_t) + size;
-}
-
-/* Split a block into two, the second of which is free. */
-static block_header_t* block_split(block_header_t* block, size_t size)
-{
- /* Calculate the amount of space left in the remaining block. */
- block_header_t* remaining =
- offset_to_block(block_to_ptr(block), size - block_header_overhead);
-
- const size_t remain_size = block_size(block) - (size + block_header_overhead);
-
- tlsf_assert((uintptr_t)block_to_ptr(remaining) == (uintptr_t)align_ptr(block_to_ptr(remaining), ALIGN_SIZE)
- && "remaining block not aligned properly");
-
- tlsf_assert(block_size(block) == remain_size + size + block_header_overhead);
- block_set_size(remaining, remain_size);
- tlsf_assert(block_size(remaining) >= block_size_min && "block split with invalid size");
-
- block_set_size(block, size);
- block_mark_as_free(remaining);
-
- return remaining;
-}
-
-/* Absorb a free block's storage into an adjacent previous free block. */
-static block_header_t* block_absorb(block_header_t* prev, block_header_t* block)
-{
- tlsf_assert(!block_is_last(prev) && "previous block can't be last");
- /* Note: Leaves flags untouched. */
- prev->size += block_size(block) + block_header_overhead;
- block_link_next(prev);
- return prev;
-}
-
-/* Merge a just-freed block with an adjacent previous free block. */
-static block_header_t* block_merge_prev(control_t* control, block_header_t* block)
-{
- if (block_is_prev_free(block))
- {
- block_header_t* prev = block_prev(block);
- tlsf_assert(prev && "prev physical block can't be null");
- tlsf_assert(block_is_free(prev) && "prev block is not free though marked as such");
- block_remove(control, prev);
- block = block_absorb(prev, block);
- }
-
- return block;
-}
-
-/* Merge a just-freed block with an adjacent free block. */
-static block_header_t* block_merge_next(control_t* control, block_header_t* block)
-{
- block_header_t* next = block_next(block);
- tlsf_assert(next && "next physical block can't be null");
-
- if (block_is_free(next))
- {
- tlsf_assert(!block_is_last(block) && "previous block can't be last");
- block_remove(control, next);
- block = block_absorb(block, next);
- }
-
- return block;
-}
-
-/* Trim any trailing block space off the end of a block, return to pool. */
-static void block_trim_free(control_t* control, block_header_t* block, size_t size)
-{
- tlsf_assert(block_is_free(block) && "block must be free");
- if (block_can_split(block, size))
- {
- block_header_t* remaining_block = block_split(block, size);
- block_link_next(block);
- block_set_prev_free(remaining_block);
- block_insert(control, remaining_block);
- }
-}
-
-/* Trim any trailing block space off the end of a used block, return to pool. */
-static void block_trim_used(control_t* control, block_header_t* block, size_t size)
-{
- tlsf_assert(!block_is_free(block) && "block must be used");
- if (block_can_split(block, size))
- {
- /* If the next block is free, we must coalesce. */
- block_header_t* remaining_block = block_split(block, size);
- block_set_prev_used(remaining_block);
-
- remaining_block = block_merge_next(control, remaining_block);
- block_insert(control, remaining_block);
- }
-}
-
-static block_header_t* block_trim_free_leading(control_t* control, block_header_t* block, size_t size)
-{
- block_header_t* remaining_block = block;
- if (block_can_split(block, size))
- {
- /* We want the 2nd block. */
- remaining_block = block_split(block, size - block_header_overhead);
- block_set_prev_free(remaining_block);
-
- block_link_next(block);
- block_insert(control, block);
- }
-
- return remaining_block;
-}
-
-static block_header_t* block_locate_free(control_t* control, size_t size)
-{
- int fl = 0, sl = 0;
- block_header_t* block = 0;
-
- if (size)
- {
- mapping_search(size, &fl, &sl);
-
- /*
- ** mapping_search can futz with the size, so for excessively large sizes it can sometimes wind up
- ** with indices that are off the end of the block array.
- ** So, we protect against that here, since this is the only callsite of mapping_search.
- ** Note that we don't need to check sl, since it comes from a modulo operation that guarantees it's always in range.
- */
- if (fl < FL_INDEX_COUNT)
- {
- block = search_suitable_block(control, &fl, &sl);
- }
- }
-
- if (block)
- {
- tlsf_assert(block_size(block) >= size);
- remove_free_block(control, block, fl, sl);
- }
-
- return block;
-}
-
-static void* block_prepare_used(control_t* control, block_header_t* block, size_t size)
-{
- void* p = 0;
- if (block)
- {
- tlsf_assert(size && "size must be non-zero");
- block_trim_free(control, block, size);
- block_mark_as_used(block);
- p = block_to_ptr(block);
- }
- return p;
-}
-
-/* Clear structure and point all empty lists at the null block. */
-static void control_construct(control_t* control)
-{
- int i, j;
-
- control->block_null.next_free = &control->block_null;
- control->block_null.prev_free = &control->block_null;
-
- control->fl_bitmap = 0;
- for (i = 0; i < FL_INDEX_COUNT; ++i)
- {
- control->sl_bitmap[i] = 0;
- for (j = 0; j < SL_INDEX_COUNT; ++j)
- {
- control->blocks[i][j] = &control->block_null;
- }
- }
-}
-
-/*
-** Debugging utilities.
-*/
-
-typedef struct integrity_t
-{
- int prev_status;
- int status;
-} integrity_t;
-
-#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } }
-
-static void integrity_walker(void* ptr, size_t size, int used, void* user)
-{
- block_header_t* block = block_from_ptr(ptr);
- integrity_t* integ = tlsf_cast(integrity_t*, user);
- const int this_prev_status = block_is_prev_free(block) ? 1 : 0;
- const int this_status = block_is_free(block) ? 1 : 0;
- const size_t this_block_size = block_size(block);
-
- int status = 0;
- (void)used;
- tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect");
- tlsf_insist(size == this_block_size && "block size incorrect");
-
- integ->prev_status = this_status;
- integ->status += status;
-}
-
-int tlsf_check(tlsf_t tlsf)
-{
- int i, j;
-
- control_t* control = tlsf_cast(control_t*, tlsf);
- int status = 0;
-
- /* Check that the free lists and bitmaps are accurate. */
- for (i = 0; i < FL_INDEX_COUNT; ++i)
- {
- for (j = 0; j < SL_INDEX_COUNT; ++j)
- {
- const int fl_map = control->fl_bitmap & (1U << i);
- const int sl_list = control->sl_bitmap[i];
- const int sl_map = sl_list & (1U << j);
- const block_header_t* block = control->blocks[i][j];
-
- /* Check that first- and second-level lists agree. */
- if (!fl_map)
- {
- tlsf_insist(!sl_map && "second-level map must be null");
- }
-
- if (!sl_map)
- {
- tlsf_insist((uint64_t)block == (uint64_t)&control->block_null && "block list must be null");
- continue;
- }
-
- /* Check that there is at least one free block. */
- tlsf_insist(sl_list && "no free blocks in second-level map");
- tlsf_insist((uintptr_t)block != (uintptr_t)&control->block_null && "block should not be null");
-
- while (block != &control->block_null)
- {
- int fli, sli;
- tlsf_insist(block_is_free(block) && "block should be free");
- tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced");
- tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced");
- tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free");
- tlsf_insist(block_size(block) >= block_size_min && "block not minimum size");
-
- mapping_insert(block_size(block), &fli, &sli);
- tlsf_insist(fli == i && sli == j && "block size indexed in wrong list");
- block = block->next_free;
- }
- }
- }
-
- return status;
-}
-
-#undef tlsf_insist
-
-static void default_walker(void* ptr, size_t size, int used, void* user)
-{
- (void)user;
- printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));
-}
-
-void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
-{
- tlsf_walker pool_walker = walker ? walker : default_walker;
- block_header_t* block =
- offset_to_block(pool, -(int)block_header_overhead);
-
- while (block && !block_is_last(block))
- {
- pool_walker(
- block_to_ptr(block),
- block_size(block),
- !block_is_free(block),
- user);
- block = block_next(block);
- }
-}
-
-size_t tlsf_block_size(void* ptr)
-{
- size_t size = 0;
- if (ptr)
- {
- const block_header_t* block = block_from_ptr(ptr);
- size = block_size(block);
- }
- return size;
-}
-
-int tlsf_check_pool(pool_t pool)
-{
- /* Check that the blocks are physically correct. */
- integrity_t integ = { 0, 0 };
- tlsf_walk_pool(pool, integrity_walker, &integ);
-
- return integ.status;
-}
-
-/*
-** Size of the TLSF structures in a given memory block passed to
-** tlsf_create, equal to the size of a control_t
-*/
-size_t tlsf_size(void)
-{
- return sizeof(control_t);
-}
-
-size_t tlsf_align_size(void)
-{
- return ALIGN_SIZE;
-}
-
-size_t tlsf_block_size_min(void)
-{
- return block_size_min;
-}
-
-size_t tlsf_block_size_max(void)
-{
- return block_size_max;
-}
-
-/*
-** Overhead of the TLSF structures in a given memory block passed to
-** tlsf_add_pool, equal to the overhead of a free block and the
-** sentinel block.
-*/
-size_t tlsf_pool_overhead(void)
-{
- return 2 * block_header_overhead;
-}
-
-size_t tlsf_alloc_overhead(void)
-{
- return block_header_overhead;
-}
-
-pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
-{
- block_header_t* block;
- block_header_t* next;
-
- const size_t pool_overhead = tlsf_pool_overhead();
- const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE);
-
- if (((ptrdiff_t)mem % ALIGN_SIZE) != 0)
- {
- printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n",
- (unsigned int)ALIGN_SIZE);
- return 0;
- }
-
- if (pool_bytes < block_size_min || pool_bytes > block_size_max)
- {
-#if defined (TLSF_64BIT)
- printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n",
- (unsigned int)(pool_overhead + block_size_min),
- (unsigned int)((pool_overhead + block_size_max) / 256));
-#else
- printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n",
- (unsigned int)(pool_overhead + block_size_min),
- (unsigned int)(pool_overhead + block_size_max));
-#endif
- return 0;
- }
-
- /*
- ** Create the main free block. Offset the start of the block slightly
- ** so that the prev_phys_block field falls outside of the pool -
- ** it will never be used.
- */
- block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead);
- block_set_size(block, pool_bytes);
- block_set_free(block);
- block_set_prev_used(block);
- block_insert(tlsf_cast(control_t*, tlsf), block);
-
- /* Split the block to create a zero-size sentinel block. */
- next = block_link_next(block);
- block_set_size(next, 0);
- block_set_used(next);
- block_set_prev_free(next);
-
- return mem;
-}
-
-void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
-{
- control_t* control = tlsf_cast(control_t*, tlsf);
- block_header_t* block = offset_to_block(pool, -(int)block_header_overhead);
-
- int fl = 0, sl = 0;
-
- tlsf_assert(block_is_free(block) && "block should be free");
- tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free");
- tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero");
-
- mapping_insert(block_size(block), &fl, &sl);
- remove_free_block(control, block, fl, sl);
-}
-
-/*
-** TLSF main interface.
-*/
-
-#if _DEBUG
-int test_ffs_fls()
-{
- /* Verify ffs/fls work properly. */
- int rv = 0;
- rv += (tlsf_ffs(0) == -1) ? 0 : 0x1;
- rv += (tlsf_fls(0) == -1) ? 0 : 0x2;
- rv += (tlsf_ffs(1) == 0) ? 0 : 0x4;
- rv += (tlsf_fls(1) == 0) ? 0 : 0x8;
- rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10;
- rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20;
- rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40;
- rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80;
-
-#if defined (TLSF_64BIT)
- rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100;
- rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200;
- rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400;
-#endif
-
- if (rv)
- {
- printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv);
- }
- return rv;
-}
-#endif
-
-tlsf_t tlsf_create(void* mem)
-{
-#if _DEBUG
- if (test_ffs_fls())
- {
- return 0;
- }
-#endif
-
- if (((tlsfptr_t)mem % ALIGN_SIZE) != 0)
- {
- printf("tlsf_create: Memory must be aligned to %u bytes.\n",
- (unsigned int)ALIGN_SIZE);
- return 0;
- }
-
- control_construct(tlsf_cast(control_t*, mem));
-
- return tlsf_cast(tlsf_t, mem);
-}
-
-tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
-{
- tlsf_t tlsf = tlsf_create(mem);
- tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
- return tlsf;
-}
-
-void tlsf_destroy(tlsf_t tlsf)
-{
- /* Nothing to do. */
- (void)tlsf;
-}
-
-pool_t tlsf_get_pool(tlsf_t tlsf)
-{
- return tlsf_cast(pool_t, (char*)tlsf + tlsf_size());
-}
-
-void* tlsf_malloc(tlsf_t tlsf, size_t size)
-{
- control_t* control = tlsf_cast(control_t*, tlsf);
- const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
- block_header_t* block = block_locate_free(control, adjust);
- return block_prepare_used(control, block, adjust);
-}
-
-void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
-{
- control_t* control = tlsf_cast(control_t*, tlsf);
- const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
-
- /*
- ** We must allocate an additional minimum block size bytes so that if
- ** our free block will leave an alignment gap which is smaller, we can
- ** trim a leading free block and release it back to the pool. We must
- ** do this because the previous physical block is in use, therefore
- ** the prev_phys_block field is not valid, and we can't simply adjust
- ** the size of that block.
- */
- const size_t gap_minimum = sizeof(block_header_t);
- const size_t size_with_gap = adjust_request_size(adjust + align + gap_minimum, align);
-
- /*
- ** If alignment is less than or equals base alignment, we're done.
- ** If we requested 0 bytes, return null, as tlsf_malloc(0) does.
- */
- const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust;
-
- block_header_t* block = block_locate_free(control, aligned_size);
-
- /* This can't be a static assert. */
- tlsf_assert(sizeof(block_header_t) == block_size_min + block_header_overhead);
-
- if (block)
- {
- void* ptr = block_to_ptr(block);
- void* aligned = align_ptr(ptr, align);
- size_t gap = tlsf_cast(size_t,
- tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr));
-
- /* If gap size is too small, offset to next aligned boundary. */
- if (gap && gap < gap_minimum)
- {
- const size_t gap_remain = gap_minimum - gap;
- const size_t offset = tlsf_max(gap_remain, align);
- const void* next_aligned = tlsf_cast(void*,
- tlsf_cast(tlsfptr_t, aligned) + offset);
-
- aligned = align_ptr(next_aligned, align);
- gap = tlsf_cast(size_t,
- tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr));
- }
-
- if (gap)
- {
- tlsf_assert(gap >= gap_minimum && "gap size too small");
- block = block_trim_free_leading(control, block, gap);
- }
- }
-
- return block_prepare_used(control, block, adjust);
-}
-
-void tlsf_free(tlsf_t tlsf, void* ptr)
-{
- /* Don't attempt to free a NULL pointer. */
- if (ptr)
- {
- control_t* control = tlsf_cast(control_t*, tlsf);
- block_header_t* block = block_from_ptr(ptr);
- tlsf_assert(!block_is_free(block) && "block already marked as free");
- block_mark_as_free(block);
- block = block_merge_prev(control, block);
- block = block_merge_next(control, block);
- block_insert(control, block);
- }
-}
-
-/*
-** The TLSF block information provides us with enough information to
-** provide a reasonably intelligent implementation of realloc, growing or
-** shrinking the currently allocated block as required.
-**
-** This routine handles the somewhat esoteric edge cases of realloc:
-** - a non-zero size with a null pointer will behave like malloc
-** - a zero size with a non-null pointer will behave like free
-** - a request that cannot be satisfied will leave the original buffer
-** untouched
-** - an extended buffer size will leave the newly-allocated area with
-** contents undefined
-*/
-void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
-{
- control_t* control = tlsf_cast(control_t*, tlsf);
- void* p = 0;
-
- /* Zero-size requests are treated as free. */
- if (ptr && size == 0)
- {
- tlsf_free(tlsf, ptr);
- }
- /* Requests with NULL pointers are treated as malloc. */
- else if (!ptr)
- {
- p = tlsf_malloc(tlsf, size);
- }
- else
- {
- block_header_t* block = block_from_ptr(ptr);
- block_header_t* next = block_next(block);
-
- const size_t cursize = block_size(block);
- const size_t combined = cursize + block_size(next) + block_header_overhead;
- const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
-
- tlsf_assert(!block_is_free(block) && "block already marked as free");
-
- /*
- ** If the next block is used, or when combined with the current
- ** block, does not offer enough space, we must reallocate and copy.
- */
- if (adjust > cursize && (!block_is_free(next) || adjust > combined))
- {
- p = tlsf_malloc(tlsf, size);
- if (p)
- {
- const size_t minsize = tlsf_min(cursize, size);
- memcpy(p, ptr, minsize);
- tlsf_free(tlsf, ptr);
- }
- }
- else
- {
- /* Do we need to expand to the next block? */
- if (adjust > cursize)
- {
- block_merge_next(control, block);
- block_mark_as_used(block);
- }
-
- /* Trim the resulting block and return the original pointer. */
- block_trim_used(control, block, adjust);
- p = ptr;
- }
- }
-
- return p;
-}
diff --git a/sys/vm/vm_device.c b/sys/vm/vm_device.c
deleted file mode 100644
index 976dec7..0000000
--- a/sys/vm/vm_device.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <sys/sio.h>
-#include <sys/vfs.h>
-#include <sys/cdefs.h>
-#include <fs/devfs.h>
-#include <vm/obj.h>
-#include <vm/vm.h>
-#include <vm/pager.h>
-
-static int dv_pager_get(struct vm_object *obj, off_t off, size_t len,
- struct vm_page *pg);
-
-static int dv_pager_store(struct vm_object *obj, off_t off, size_t len,
- struct vm_page *pg);
-
-static int dv_pager_paddr(struct vm_object *obj, paddr_t *paddr,
- vm_prot_t prot);
-
-/* Pager operations */
-struct vm_pagerops g_dev_pagerops = {
- .get = dv_pager_get,
- .store = dv_pager_store,
- .get_paddr = dv_pager_paddr
-};
-
-/*
- * Fetch a device descriptor from a memory
- * object.
- *
- * Returns 0 on success.
- */
-static int
-dv_get_dev(struct vm_object *obj, struct device **res)
-{
- struct device *dev;
- struct vnode *vp;
- int status;
-
- if ((vp = obj->vnode) == NULL)
- return -EIO;
-
- /* Now try to fetch the device */
- if ((status = devfs_get_dev(vp, &dev)) != 0)
- return status;
-
- *res = dev;
- return 0;
-}
-
-static int
-dv_pager_paddr(struct vm_object *obj, paddr_t *paddr, vm_prot_t prot)
-{
- struct device *dev;
- int status;
-
- if (paddr == NULL) {
- return -EINVAL;
- }
-
- /* Try to fetch the device */
- if ((status = dv_get_dev(obj, &dev)) != 0) {
- return status;
- }
-
- if (dev->mmap == NULL) {
- /*
- * mmap() is not supported, this is not an object
- * we can handle so try switching its operations
- * to the vnode pager ops...
- */
- obj->pgops = &g_vnode_pagerops;
- return -ENOTSUP;
- }
-
- *paddr = dev->mmap(dev, 0, prot);
- return 0;
-}
-
-static int
-dv_pager_store(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg)
-{
- return -1;
-}
-
-static int
-dv_pager_get(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg)
-{
- return -1;
-}
diff --git a/sys/vm/vm_dynalloc.c b/sys/vm/vm_dynalloc.c
deleted file mode 100644
index dea4460..0000000
--- a/sys/vm/vm_dynalloc.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/dynalloc.h>
-#include <vm/vm.h>
-
-/*
- * Dynamically allocates memory
- *
- * @sz: The amount of bytes to allocate
- */
-void *
-dynalloc(size_t sz)
-{
- struct vm_ctx *vm_ctx = vm_get_ctx();
- void *tmp;
-
- spinlock_acquire(&vm_ctx->dynalloc_lock);
- tmp = tlsf_malloc(vm_ctx->tlsf_ctx, sz);
- spinlock_release(&vm_ctx->dynalloc_lock);
- return tmp;
-}
-
-void *
-dynalloc_memalign(size_t sz, size_t align)
-{
- struct vm_ctx *vm_ctx = vm_get_ctx();
- void *tmp;
-
- spinlock_acquire(&vm_ctx->dynalloc_lock);
- tmp = tlsf_memalign(vm_ctx->tlsf_ctx, align, sz);
- spinlock_release(&vm_ctx->dynalloc_lock);
- return tmp;
-}
-
-/*
- * Reallocates memory pool created by `dynalloc()'
- *
- * @old_ptr: Pointer to old pool.
- * @newsize: Size of new pool.
- */
-void *
-dynrealloc(void *old_ptr, size_t newsize)
-{
- struct vm_ctx *vm_ctx = vm_get_ctx();
- void *tmp;
-
- spinlock_acquire(&vm_ctx->dynalloc_lock);
- tmp = tlsf_realloc(vm_ctx->tlsf_ctx, old_ptr, newsize);
- spinlock_release(&vm_ctx->dynalloc_lock);
- return tmp;
-}
-
-/*
- * Free dynamically allocated memory
- *
- * @ptr: Pointer to base of memory.
- */
-void
-dynfree(void *ptr)
-{
- struct vm_ctx *vm_ctx = vm_get_ctx();
-
- spinlock_acquire(&vm_ctx->dynalloc_lock);
- tlsf_free(vm_ctx->tlsf_ctx, ptr);
- spinlock_release(&vm_ctx->dynalloc_lock);
-}
diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c
deleted file mode 100644
index 45def7f..0000000
--- a/sys/vm/vm_fault.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/sched.h>
-#include <vm/fault.h>
-#include <vm/map.h>
-#include <vm/pmap.h>
-#include <vm/vm.h>
-#include <vm/physseg.h>
-
-static struct vm_mapping *
-vm_mapq_search(vm_mapq_t *mq, vaddr_t addr)
-{
- struct vm_mapping *mapping;
- const struct vm_range *range;
-
- TAILQ_FOREACH(mapping, mq, link) {
- range = &mapping->range;
- if (addr >= range->start && addr <= range->end) {
- return mapping;
- }
- }
-
- return NULL;
-}
-
-static struct vm_mapping *
-vm_find_mapping(vaddr_t addr)
-{
- struct vm_mapping *mapping;
- struct proc *td = this_td();
- vm_mapq_t *mapq;
-
- mapping = vm_mapping_fetch(&td->mapspace, addr);
- if (mapping != NULL)
- return mapping;
-
- /* Need to search other maps */
- for (size_t i = 0; i < MTAB_ENTRIES; ++i) {
- mapq = &td->mapspace.mtab[i];
- mapping = vm_mapq_search(mapq, addr);
- if (mapping != NULL)
- return mapping;
- }
-
- return NULL;
-}
-
-static int
-vm_demand_page(struct vm_mapping *mapping, vaddr_t va, vm_prot_t access_type)
-{
- struct proc *td;
- paddr_t pa_base;
-
- int s;
- size_t granule = vm_get_page_size();
-
- /* Allocate physical memory if needed */
- if (mapping->physmem_base == 0) {
- pa_base = vm_alloc_pageframe(1);
- mapping->physmem_base = pa_base;
- } else {
- pa_base = mapping->physmem_base;
- }
-
- td = this_td();
- s = vm_map_create(td->addrsp, va, pa_base, access_type, granule);
- return s;
-}
-
-int
-vm_fault(vaddr_t va, vm_prot_t access_type)
-{
- struct vm_mapping *mapping;
- struct vm_object *vmobj;
-
- int s = 0;
- size_t granule = vm_get_page_size();
- vaddr_t va_base = va & ~(granule - 1);
-
- mapping = vm_find_mapping(va_base);
- if (mapping == NULL)
- return -1;
-
- if ((vmobj = mapping->vmobj) == NULL)
- /* Virtual memory object non-existent */
- return -1;
- if ((access_type & ~mapping->prot) != 0)
- /* Invalid access type */
- return -1;
-
- vm_object_ref(vmobj);
-
- /* Can we perform demand paging? */
- if (vmobj->demand) {
- s = vm_demand_page(mapping, va_base, access_type);
- if (s != 0)
- goto done;
- }
-
-done:
- /* Drop the vmobj ref */
- vm_object_unref(vmobj);
- return s;
-}
diff --git a/sys/vm/vm_init.c b/sys/vm/vm_init.c
deleted file mode 100644
index 3087e6e..0000000
--- a/sys/vm/vm_init.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/vm.h>
-#include <vm/physseg.h>
-#include <vm/pmap.h>
-#include <sys/panic.h>
-#include <assert.h>
-
-/*
- * XXX: As of now, these are constant... It would be nice if we could
- * have this value expanded upon request so we can keep it small
- * to not hog up resources. Would make it more flexible too :^)
- */
-#define DYNALLOC_POOL_SZ 0x400000 /* 4 MiB */
-#define DYNALLOC_POOL_PAGES (DYNALLOC_POOL_SZ / vm_get_page_size())
-
-static volatile struct vas kernel_vas;
-
-/*
- * TODO: Move this to a per CPU structure, this kinda sucks
- * how it is right now...
- */
-static struct vm_ctx bsp_vm_ctx = {0};
-
-volatile struct limine_hhdm_request g_hhdm_request = {
- .id = LIMINE_HHDM_REQUEST,
- .revision = 0
-};
-
-struct vm_ctx *
-vm_get_ctx(void)
-{
- return &bsp_vm_ctx;
-}
-
-/*
- * Return the kernel VAS.
- */
-struct vas
-vm_get_kvas(void)
-{
- return kernel_vas;
-}
-
-void
-vm_init(void)
-{
- void *pool_va;
-
- kernel_vas = pmap_read_vas();
- if (pmap_init(vm_get_ctx()) != 0) {
- panic("Failed to init pmap layer\n");
- }
-
- /* Setup virtual memory context */
- bsp_vm_ctx.dynalloc_pool_sz = DYNALLOC_POOL_SZ;
- bsp_vm_ctx.dynalloc_pool_phys = vm_alloc_pageframe(DYNALLOC_POOL_PAGES);
- if (bsp_vm_ctx.dynalloc_pool_phys == 0) {
- panic("Failed to allocate dynamic pool\n");
- }
- pool_va = PHYS_TO_VIRT(bsp_vm_ctx.dynalloc_pool_phys);
- bsp_vm_ctx.tlsf_ctx = tlsf_create_with_pool(pool_va, DYNALLOC_POOL_SZ);
- __assert(bsp_vm_ctx.tlsf_ctx != 0);
-}
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
deleted file mode 100644
index ca1d18a..0000000
--- a/sys/vm/vm_map.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/map.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/physseg.h>
-#include <vm/dynalloc.h>
-#include <vm/pager.h>
-#include <sys/types.h>
-#include <sys/filedesc.h>
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <sys/sched.h>
-#include <lib/assert.h>
-
-#define ALLOC_MAPPING() dynalloc(sizeof(struct vm_mapping))
-#define DESTROY_MAPPING(MAPPING) dynfree(MAPPING)
-#define MMAP_DEFAULT_OFF 0x3000000
-
-static size_t
-vm_hash_vaddr(vaddr_t va) {
- va = (va ^ (va >> 30)) * (size_t)0xBF58476D1CE4E5B9;
- va = (va ^ (va >> 27)) * (size_t)0x94D049BB133111EB;
- va = va ^ (va >> 31);
- return va;
-}
-
-/*
- * Fetches a suitable offset to be added to an
- * address that will be mapped with mmap() to
- * avoid clobbering the address space.
- */
-static uintptr_t
-vm_get_mapoff(struct proc *td)
-{
- /*
- * FIXME: For now we are adding a fixed offset to the
- * address to be mapped.
- *
- * It would be best to ensure that it isn't in
- * range of the process *just in case*.
- */
- (void)td;
- return MMAP_DEFAULT_OFF;
-}
-
-/*
- * Destroy a map queue.
- */
-void
-vm_free_mapq(vm_mapq_t *mapq)
-{
- struct vm_mapping *map;
- size_t map_pages, granule;
-
- granule = vm_get_page_size();
- TAILQ_FOREACH(map, mapq, link) {
- map_pages = (map->range.end - map->range.start) / granule;
- vm_free_pageframe(map->range.start, map_pages);
- }
- dynfree(map);
-}
-
-/*
- * Remove a mapping from a mapspace.
- *
- * @ms: Mapspace.
- * @mapping: Mapping to remove.
- */
-void
-vm_mapspace_remove(struct vm_mapspace *ms, struct vm_mapping *mapping)
-{
- size_t vhash;
- vm_mapq_t *mapq;
-
- if (ms == NULL)
- return;
-
- vhash = vm_hash_vaddr(mapping->range.start);
- mapq = &ms->mtab[vhash % MTAB_ENTRIES];
- TAILQ_REMOVE(mapq, mapping, link);
- --ms->map_count;
-}
-
-/*
- * Fetch a mapping from a mapspace.
- *
- * @ms: Mapspace.
- * @va: Virtual address.
- */
-struct vm_mapping *
-vm_mapping_fetch(struct vm_mapspace *ms, vaddr_t va)
-{
- size_t vhash;
- const vm_mapq_t *mapq;
- struct vm_mapping *map;
-
- if (ms == NULL)
- return NULL;
-
- vhash = vm_hash_vaddr(va);
- mapq = &ms->mtab[vhash % MTAB_ENTRIES];
-
- TAILQ_FOREACH(map, mapq, link) {
- if (map->vhash == vhash) {
- return map;
- }
- }
-
- return NULL;
-}
-
-/*
- * Insert a mapping into a mapspace.
- *
- * @ms: Target mapspace.
- * @mapping: Mapping to insert.
- */
-void
-vm_mapspace_insert(struct vm_mapspace *ms, struct vm_mapping *mapping)
-{
- size_t vhash;
- vm_mapq_t *q;
-
- if (mapping == NULL || ms == NULL)
- return;
-
- vhash = vm_hash_vaddr(mapping->range.start);
- mapping->vhash = vhash;
-
- q = &ms->mtab[vhash % MTAB_ENTRIES];
- TAILQ_INSERT_HEAD(q, mapping, link);
- ++ms->map_count;
-}
-
-/*
- * Create a mapping (internal helper)
- *
- * @addr: Address to map.
- * @physmem: Physical address, set to 0 to alloc one here
- * @prot: Protection flags.
- *
- * Returns zero on failure.
- */
-static paddr_t
-vm_map(void *addr, paddr_t physmem, vm_prot_t prot, size_t len)
-{
- struct proc *td = this_td();
- const size_t GRANULE = vm_get_page_size();
-
- int status;
-
- /* Allocate the physical memory if needed */
- if (physmem == 0)
- physmem = vm_alloc_pageframe(len / GRANULE);
-
- if (physmem == 0)
- return 0;
-
- /*
- * XXX: There is no need to worry about alignment yet
- * as vm_map_create() handles that internally.
- */
- prot |= PROT_USER;
- status = vm_map_create(td->addrsp, (vaddr_t)addr, physmem, prot, len);
- if (status != 0) {
- vm_free_pageframe(physmem, len / GRANULE);
- return 0;
- }
-
- return physmem;
-}
-
-/*
- * Create a mapping backed by a file.
- *
- * @addr: Address to map.
- * @prot: Protection flags.
- * @len: Length of mapping.
- * @off: Offset.
- * @fd: File descriptor.
- */
-static paddr_t
-vm_fd_map(void *addr, vm_prot_t prot, size_t len, off_t off, int fd,
- struct vm_mapping *mapping)
-{
- paddr_t physmem = 0;
-
- int oflag;
- struct filedesc *filedes;
- struct vnode *vp;
-
- struct proc *td = this_td();
- struct vm_page pg = {0};
-
- /* Attempt to get the vnode */
- filedes = fd_from_fdnum(td, fd);
- if (filedes == NULL)
- return 0;
- if ((vp = filedes->vnode) == NULL)
- return 0;
-
- /* Check the perms of the filedes */
- oflag = filedes->oflag;
- if (__TEST(prot, PROT_WRITE) && oflag == O_RDONLY)
- return 0;
- if (!__TEST(prot, PROT_WRITE) && oflag == O_WRONLY)
- return 0;
-
- /* Try to create the virtual memory object */
- if (vm_obj_init(&vp->vmobj, vp) != 0)
- return 0;
-
- mapping->vmobj = vp->vmobj;
- vm_object_ref(vp->vmobj);
-
- /* Try to fetch a physical address */
- if (vm_pager_paddr(vp->vmobj, &physmem, prot) != 0) {
- vm_obj_destroy(vp->vmobj);
- return 0;
- }
-
- /*
- * If the pager found a physical address for the object to
- * be mapped to, then we start off with an anonymous mapping
- * then connect it to the physical address (creates a shared mapping)
- */
- if (physmem != 0) {
- vm_map(addr, physmem, prot, len);
- return physmem;
- }
-
- /*
- * If the pager could not find a physical address for
- * the object to be mapped to, start of with just a plain
- * anonymous mapping then page-in from whatever filesystem
- * (creates a shared mapping)
- */
- physmem = vm_map(addr, 0, prot, len);
- pg.physaddr = physmem;
-
- if (vm_pager_get(vp->vmobj, off, len, &pg) != 0) {
- vm_obj_destroy(vp->vmobj);
- return 0;
- }
-
- return physmem;
-}
-
-static int
-munmap(void *addr, size_t len)
-{
- struct proc *td = this_td();
- struct vm_mapping *mapping;
- struct vm_object *obj;
-
- struct vm_mapspace *ms;
- size_t map_len, granule;
- vaddr_t map_start, map_end;
-
- ms = &td->mapspace;
-
- granule = vm_get_page_size();
- mapping = vm_mapping_fetch(ms, (vaddr_t)addr);
- if (mapping == NULL) {
- return -1;
- }
-
- spinlock_acquire(&td->mapspace_lock);
- map_start = mapping->range.start;
- map_end = mapping->range.end;
- map_len = map_end - map_start;
-
- /* Try to release any virtual memory objects */
- if ((obj = mapping->vmobj) != NULL) {
- /*
- * Drop our ref and try to cleanup. If the refcount
- * is > 0, something is still holding it and we can't
- * do much.
- */
- vm_object_unref(obj);
- if (obj->ref == 0) {
- vm_obj_destroy(obj);
- }
- }
-
- /* Release the mapping */
- vm_map_destroy(td->addrsp, map_start, map_len);
- vm_free_pageframe(mapping->range.start, map_len / granule);
-
- /* Destroy the mapping descriptor */
- vm_mapspace_remove(ms, mapping);
- dynfree(mapping);
- spinlock_release(&td->mapspace_lock);
- return 0;
-}
-
-static void *
-mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
-{
- const int PROT_MASK = PROT_WRITE | PROT_EXEC;
- const size_t GRANULE = vm_get_page_size();
- uintptr_t map_end, map_start;
-
- struct proc *td = this_td();
- struct vm_mapping *mapping;
- struct vm_object *vmobj;
-
- size_t misalign = ((vaddr_t)addr) & (GRANULE - 1);
- off_t mapoff = vm_get_mapoff(td);
-
- paddr_t physmem = 0;
- vaddr_t va = (vaddr_t)addr + mapoff;
-
- /* Ensure of valid prot flags */
- if ((prot & ~PROT_MASK) != 0)
- return MAP_FAILED;
-
- /* Try to allocate a mapping */
- mapping = ALLOC_MAPPING();
- if (mapping == NULL)
- return MAP_FAILED;
-
- /* Setup prot and mapping start */
- mapping->prot = prot | PROT_USER;
- map_start = __ALIGN_DOWN(va, GRANULE);
-
- /* Ensure the length is aligned */
- len = __ALIGN_UP(len + misalign, GRANULE);
-
- /*
- * Now we check what type of map request
- * this is.
- */
- if (__TEST(flags, MAP_ANONYMOUS)) {
- /* Try to create a virtual memory object */
- if (vm_obj_init(&vmobj, NULL) != 0)
- goto fail;
-
- /*
- * If 'addr' is NULL, we'll just allocate physical
- * memory right away.
- */
- if (addr == NULL)
- physmem = vm_alloc_pageframe(len / GRANULE);
-
- /*
- * Enable demand paging for this object if
- * `addr` is not NULL.
- */
- if (addr != NULL) {
- vmobj->is_anon = 1;
- vmobj->demand = 1;
-
- mapping->vmobj = vmobj;
- mapping->physmem_base = 0;
- } else if (addr == NULL && physmem != 0) {
- map_start = physmem + mapoff;
- vm_map((void *)map_start, physmem, prot, len);
- addr = (void *)physmem;
-
- vmobj->is_anon = 1;
- vmobj->demand = 0;
- mapping->vmobj = vmobj;
- mapping->physmem_base = physmem;
- }
-
- /* Did this work? */
- if (physmem == 0 && addr == NULL) {
- goto fail;
- }
- } else if (__TEST(flags, MAP_SHARED)) {
- physmem = vm_fd_map((void *)map_start, prot, len, off, fildes, mapping);
- if (physmem == 0) {
- goto fail;
- }
- }
-
- /* Setup map_end and map ranges */
- map_end = map_start + len;
- mapping->range.start = map_start;
- mapping->range.end = map_end;
- mapping->physmem_base = physmem;
-
- /* Add to mapspace */
- spinlock_acquire(&td->mapspace_lock);
- vm_mapspace_insert(&td->mapspace, mapping);
- spinlock_release(&td->mapspace_lock);
- return (void *)map_start;
-fail:
- DESTROY_MAPPING(mapping);
- return MAP_FAILED;
-}
-
-/*
- * Internal routine for cleaning up.
- *
- * @va: VA to start unmapping at.
- * @bytes_aligned: Amount of bytes to unmap.
- *
- * XXX DANGER!!: `bytes_aligned' is expected to be aligned by the
- * machine's page granule. If this is not so,
- * undefined behaviour will occur. This will
- * be enforced via a panic.
- */
-static void
-vm_map_cleanup(struct vas vas, struct vm_ctx *ctx, vaddr_t va,
- size_t bytes_aligned, size_t granule)
-{
- __assert(bytes_aligned != 0);
- __assert((bytes_aligned & (granule - 1)) == 0);
-
- for (size_t i = 0; i < bytes_aligned; i += 0x1000) {
- if (pmap_unmap(ctx, vas, va + i) != 0) {
- /*
- * XXX: This shouldn't happen... If it somehow does,
- * then this should be handled.
- */
- panic("Could not cleanup!!!\n");
- }
- }
-}
-
-/*
- * Create a virtual memory mappings in the current
- * address space.
- *
- * @va: Virtual address.
- * @pa: Physical address.
- * @prot: Protection flags.
- * @bytes: Amount of bytes to be mapped. This is aligned by the
- * machine's page granule, typically a 4k boundary.
- */
-int
-vm_map_create(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot, size_t bytes)
-{
- size_t granule = vm_get_page_size();
- size_t misalign = va & (granule - 1);
- int s;
-
- struct vm_ctx *ctx = vm_get_ctx();
-
- /*
- * The amount of bytes to be mapped should fully span pages,
- * so we ensure it is aligned by the page granularity.
- */
- bytes = __ALIGN_UP(bytes + misalign, granule);
-
- /* Align VA/PA by granule */
- va = __ALIGN_DOWN(va, granule);
- pa = __ALIGN_DOWN(pa, granule);
-
- if (bytes == 0) {
- /* You can't map 0 pages, silly! */
- return -1;
- }
-
- for (uintptr_t i = 0; i < bytes; i += granule) {
- s = pmap_map(ctx, vas, va + i, pa + i, prot);
- if (s != 0) {
- /* Something went a bit wrong here, cleanup */
- vm_map_cleanup(vas, ctx, va, i, bytes);
- return -1;
- }
- }
-
- return 0;
-}
-
-/*
- * Destroy a virtual memory mapping in the current
- * address space.
- */
-int
-vm_map_destroy(struct vas vas, vaddr_t va, size_t bytes)
-{
- struct vm_ctx *ctx = vm_get_ctx();
- size_t granule = vm_get_page_size();
- size_t misalign = va & (granule - 1);
- int s;
-
- /* We want bytes to be aligned by the granule */
- bytes = __ALIGN_UP(bytes + misalign, granule);
-
- /* Align VA by granule */
- va = __ALIGN_DOWN(va, granule);
-
- if (bytes == 0) {
- return -1;
- }
-
- for (uintptr_t i = 0; i < bytes; i += granule) {
- s = pmap_unmap(ctx, vas, va + i);
- if (s != 0) {
- return -1;
- }
- }
-
- return 0;
-}
-
-uint64_t
-sys_mmap(struct syscall_args *args)
-{
- return (uintptr_t)mmap((void *)args->arg0, args->arg1, args->arg2,
- args->arg3, args->arg4, args->arg5);
-}
-
-uint64_t
-sys_munmap(struct syscall_args *args)
-{
- return munmap((void *)args->arg0, args->arg1);
-}
diff --git a/sys/vm/vm_obj.c b/sys/vm/vm_obj.c
deleted file mode 100644
index b501c6b..0000000
--- a/sys/vm/vm_obj.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/obj.h>
-#include <vm/dynalloc.h>
-#include <sys/errno.h>
-#include <string.h>
-
-static size_t obj_count = 0;
-
-static void
-vm_set_pgops(struct vm_object *obj, struct vnode *vnode)
-{
- if (vnode == NULL) {
- obj->vnode = NULL;
- return;
- }
-
- /* Is this a device? */
- if (vnode->type == VCHR || vnode->type == VBLK) {
- obj->pgops = &g_dev_pagerops;
- } else {
- obj->pgops = &g_vnode_pagerops;
- }
-}
-
-int
-vm_obj_init(struct vm_object **res, struct vnode *vnode)
-{
- struct vm_object *obj = dynalloc(sizeof(struct vm_object));
-
- if (obj == NULL) {
- return -ENOMEM;
- }
-
- memset(obj, 0, sizeof(struct vm_object));
- obj->vnode = vnode;
- obj->ref = 0;
-
- vm_set_pgops(obj, vnode);
- *res = obj;
- ++obj_count;
- return 0;
-}
-
-int
-vm_obj_destroy(struct vm_object *obj)
-{
- struct vnode *vp = obj->vnode;
-
- /* Check the ref count */
- if (obj->ref > 0)
- return -EBUSY;
-
- if (vp != NULL)
- vp->vmobj = NULL;
-
- dynfree(obj);
- --obj_count;
- return 0;
-}
-
-size_t
-vm_obj_count(void)
-{
- return obj_count;
-}
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
deleted file mode 100644
index f496fee..0000000
--- a/sys/vm/vm_page.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#include <sys/panic.h>
-#include <vm/page.h>
-#include <vm/vm.h>
-#include <string.h>
-
-__MODULE_NAME("vm_page");
-__KERNEL_META("$Hyra$: vm_page.c, Ian Marco Moffett, "
- "Virtual memory page specific operations");
-
-/*
- * Zero `page_count' pages.
- *
- * @page: First page to start zeroing at
- * @page_count: Number of pages to zero.
- */
-void
-vm_zero_page(void *page, size_t page_count)
-{
- const size_t PAGE_SIZE = vm_get_page_size();
- size_t bytes = page_count * PAGE_SIZE;
-
- /*
- * This *should not* happen. Page sizes
- * are usually 2^n but if this runs, something
- * *very* weird is happening and either something
- * broke badly. Or it's that damn technological
- * degeneration that is getting out of hand within
- * our world!! But really, page sizes *should* be a
- * power of 2 and it would be pretty worrying if
- * this branches causing a panic stating something
- * that shouldn't happen, happened.
- *
- * The reason why it is wise for pages to be a power of
- * 2 is so we can efficiently read/write to the page in
- * fixed-sized power of 2 blocks cleanly without the risk
- * of clobbering other pages we didn't intend to mess with.
- */
- if ((PAGE_SIZE & 1) != 0) {
- panic("Unexpected page size, not power of 2!\n");
- }
-
- memset64(page, 0, bytes/8);
-}
diff --git a/sys/vm/vm_pager.c b/sys/vm/vm_pager.c
deleted file mode 100644
index 0046e9c..0000000
--- a/sys/vm/vm_pager.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/pager.h>
-#include <vm/obj.h>
-#include <sys/types.h>
-
-/*
- * Get pages from backing store.
- */
-int
-vm_pager_get(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg)
-{
- struct vm_pagerops *pgops = obj->pgops;
-
- if (obj->is_anon) {
- return -1;
- }
-
- return pgops->get(obj, off, len, pg);
-}
-
-/*
- * Get physical address.
- *
- * TODO: Remove this and add demanding paging.
- */
-int
-vm_pager_paddr(struct vm_object *obj, paddr_t *paddr, vm_prot_t prot)
-{
- struct vm_pagerops *pgops = obj->pgops;
-
- if (obj->is_anon) {
- return -1;
- }
-
- if (pgops->get_paddr == NULL) {
- return 0;
- }
-
- return pgops->get_paddr(obj, paddr, prot);
-}
diff --git a/sys/vm/vm_physseg.c b/sys/vm/vm_physseg.c
deleted file mode 100644
index 88560e5..0000000
--- a/sys/vm/vm_physseg.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/limine.h>
-#include <sys/cdefs.h>
-#include <sys/syslog.h>
-#include <vm/physseg.h>
-#include <vm/vm.h>
-#include <bitmap.h>
-#include <string.h>
-
-__MODULE_NAME("vm_physseg");
-__KERNEL_META("$Hyra$: vm_physseg.c, Ian Marco Moffett, "
- "The Hyra physical memory manager");
-
-#if defined(VM_PHYSSEG_DEBUG)
-#define DPRINTF(...) KDEBUG(__VA_ARGS__)
-#else
-#define DPRINTF(...) __nothing
-#endif /* defined(VM_PHYSSEG_DEBUG) */
-
-static struct limine_memmap_request mmap_req = {
- .id = LIMINE_MEMMAP_REQUEST,
- .revision = 0
-};
-
-static struct limine_memmap_response *resp = NULL;
-
-__used static const char *segment_name[] = {
- [LIMINE_MEMMAP_USABLE] = "usable",
- [LIMINE_MEMMAP_RESERVED] = "reserved",
- [LIMINE_MEMMAP_ACPI_RECLAIMABLE] = "ACPI reclaimable",
- [LIMINE_MEMMAP_ACPI_NVS] = "ACPI NVS",
- [LIMINE_MEMMAP_BAD_MEMORY] = "bad",
- [LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE] = "bootloader reclaimable",
- [LIMINE_MEMMAP_KERNEL_AND_MODULES] = "kernel and modules",
- [LIMINE_MEMMAP_FRAMEBUFFER] = "framebuffer"
-};
-
-static const int MAX_SEGMENTS = __ARRAY_COUNT(segment_name);
-
-
-static bitmap_t bitmap = NULL;
-static size_t pages_total = 0;
-static size_t pages_reserved = 0;
-static size_t last_used_idx = 0;
-static size_t pages_allocated = 0;
-static size_t bitmap_size = 0;
-static size_t highest_frame_idx;
-static size_t bitmap_free_start; /* Beginning bit of free region */
-
-static void
-vm_physseg_getstat(void)
-{
- struct limine_memmap_entry *entry;
- size_t entry_pages = 0;
-
- pages_total = 0;
- pages_reserved = 0;
-
- for (size_t i = 0; i < resp->entry_count; ++i) {
- entry = resp->entries[i];
- entry_pages = entry->length / vm_get_page_size();
-
- /* Drop invalid entries */
- if (entry->type >= MAX_SEGMENTS) {
- continue;
- }
-
- pages_total += entry_pages;
-
- if (entry->type != LIMINE_MEMMAP_USABLE) {
- pages_reserved += entry_pages;
- continue;
- }
- }
-}
-
-static void
-vm_physseg_bitmap_alloc(void)
-{
- struct limine_memmap_entry *entry;
- uintptr_t highest_addr = 0;
-
- for (size_t i = 0; i < resp->entry_count; ++i) {
- entry = resp->entries[i];
-
- /* Drop any entries with an invalid type */
- if (entry->type >= MAX_SEGMENTS) {
- continue;
- }
-
- if (entry->type != LIMINE_MEMMAP_USABLE) {
- /* This memory is not usable */
- continue;
- }
-
- if (entry->length >= bitmap_size) {
- bitmap = PHYS_TO_VIRT(entry->base);
- memset(bitmap, 0xFF, bitmap_size);
- entry->length -= bitmap_size;
- entry->base += bitmap_size;
- return;
- }
-
- highest_addr = __MAX(highest_addr, entry->base + entry->length);
- }
-}
-
-static void
-vm_physseg_bitmap_populate(void)
-{
- struct limine_memmap_entry *entry;
-#if defined(VM_PHYSSEG_DEBUG)
- size_t start, end;
-#endif /* defined(VM_PHYSSEG_DEBUG) */
-
- for (size_t i = 0; i < resp->entry_count; ++i) {
- entry = resp->entries[i];
-
- /* Drop any entries with an invalid type */
- if (entry->type >= MAX_SEGMENTS) {
- continue;
- }
-
-#if defined(VM_PHYSSEG_DEBUG)
- /* Dump the memory map if we are debugging */
- start = entry->base;
- end = entry->base + entry->length;
- DPRINTF("0x%x - 0x%x, size: 0x%x, type: %s\n",
- start, end, entry->length,
- segment_name[entry->type]);
-#endif /* defined(VM_PHYSSEG_DEBUG) */
-
- /* Don't set non-usable entries as free */
- if (entry->type != LIMINE_MEMMAP_USABLE) {
- continue;
- }
-
- /* Populate */
- if (bitmap_free_start == 0) {
- bitmap_free_start = entry->base/0x1000;
- }
- for (size_t j = 0; j < entry->length; j += 0x1000) {
- bitmap_unset_bit(bitmap, (entry->base + j) / 0x1000);
- }
- }
-}
-
-static void
-vm_physseg_bitmap_init(void)
-{
- uintptr_t highest_addr;
- struct limine_memmap_entry *entry;
-
- highest_addr = 0;
- highest_frame_idx = 0;
-
- /* Find the highest entry */
- for (size_t i = 0; i < resp->entry_count; ++i) {
- entry = resp->entries[i];
-
- if (entry->type != LIMINE_MEMMAP_USABLE) {
- /* Memeory not usable */
- continue;
- }
-
- highest_addr = __MAX(highest_addr, entry->base + entry->length);
- }
-
- highest_frame_idx = highest_addr / 0x1000;
- bitmap_size = __ALIGN_UP(highest_frame_idx / 8, 0x1000);
-
- DPRINTF("Bitmap size: %d bytes\n", bitmap_size);
- DPRINTF("Allocating and populating bitmap now...\n");
-
- vm_physseg_bitmap_alloc();
- vm_physseg_bitmap_populate();
-}
-
-uintptr_t
-vm_alloc_pageframe(size_t count)
-{
- size_t pages = 0;
- size_t tmp;
-
- while (last_used_idx < highest_frame_idx) {
- if (!bitmap_test_bit(bitmap, last_used_idx++)) {
- /* We have a free page */
- if (++pages != count)
- continue;
-
- tmp = last_used_idx - count;
-
- for (size_t i = tmp; i < last_used_idx; ++i)
- bitmap_set_bit(bitmap, i);
-
- pages_allocated += count;
- return tmp * vm_get_page_size();
- } else {
- pages = 0;
- }
- }
-
- return 0;
-}
-
-/*
- * Frees physical pageframes.
- *
- * @base: Base to start freeing at.
- * @count: Number of pageframes to free.
- */
-void
-vm_free_pageframe(uintptr_t base, size_t count)
-{
- const size_t PAGE_SIZE = vm_get_page_size();
-
- for (uintptr_t p = base; p < base + (count*PAGE_SIZE); p += PAGE_SIZE) {
- bitmap_unset_bit(bitmap, p/0x1000);
- }
-
- pages_allocated -= count;
-}
-
-void
-vm_physseg_init(void)
-{
- resp = mmap_req.response;
-
- vm_physseg_bitmap_init();
-}
-
-struct physmem_stat
-vm_phys_memstat(void)
-{
- size_t pagesize = vm_get_page_size();
- struct physmem_stat stat;
-
- vm_physseg_getstat();
- stat.total_kib = (pages_total * pagesize) / 1024;
- stat.reserved_kib = (pages_reserved * pagesize) / 1024;
- stat.alloc_kib = (pages_allocated * pagesize) / 1024;
- stat.avl_kib = stat.total_kib - stat.alloc_kib;
- return stat;
-}
diff --git a/sys/vm/vm_stat.c b/sys/vm/vm_stat.c
deleted file mode 100644
index 6374699..0000000
--- a/sys/vm/vm_stat.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vm/physseg.h>
-#include <vm/vm.h>
-#include <vm/obj.h>
-
-struct vm_memstat
-vm_memstat(void)
-{
- struct vm_memstat stat;
-
- stat.pmem_stat = vm_phys_memstat();
- stat.vmobj_cnt = vm_obj_count();
- return stat;
-}
diff --git a/sys/vm/vm_vnode.c b/sys/vm/vm_vnode.c
deleted file mode 100644
index e3d95ac..0000000
--- a/sys/vm/vm_vnode.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Hyra nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <sys/sio.h>
-#include <sys/vfs.h>
-#include <sys/cdefs.h>
-#include <vm/obj.h>
-#include <vm/vm.h>
-#include <vm/pager.h>
-
-static int vn_pager_get(struct vm_object *obj, off_t off, size_t len,
- struct vm_page *pg);
-
-static int vn_pager_store(struct vm_object *obj, off_t off, size_t len,
- struct vm_page *pg);
-
-/* Pager operations */
-struct vm_pagerops g_vnode_pagerops = {
- .get = vn_pager_get,
- .store = vn_pager_store
-};
-
-static inline void
-vn_prep_sio(struct sio_txn *sio, char *pg, off_t off, size_t len)
-{
- sio->len = __ALIGN_DOWN(len, vm_get_page_size());
- sio->buf = pg;
- sio->offset = off;
- sio->len = len;
-}
-
-static int
-vn_pager_io(struct vm_object *obj, off_t off, size_t len,
- struct vm_page *pg, bool out)
-{
- struct sio_txn sio;
- struct vnode *vp;
- ssize_t paged_bytes;
- char *dest;
- int res = 0;
-
- if (obj == NULL || pg == NULL) {
- return -EIO;
- }
-
- spinlock_acquire(&obj->lock);
- vm_object_ref(obj);
- dest = PHYS_TO_VIRT(pg->physaddr);
-
- /* Attempt to fetch the vnode */
- if ((vp = obj->vnode) == NULL) {
- res = -EIO;
- goto done;
- }
-
- /* Prepare the SIO transaction */
- vn_prep_sio(&sio, dest, off, len);
- if (sio.len == 0) {
- res = -EIO;
- goto done;
- }
-
- /* Perform I/O on the backing store */
- paged_bytes = out ? vfs_write(vp, &sio) : vfs_read(vp, &sio);
- if (paged_bytes < 0) {
- /* Failure */
- res = paged_bytes;
- goto done;
- }
-done:
- vm_object_unref(obj);
- spinlock_release(&obj->lock);
- return res;
-}
-
-static int
-vn_pager_store(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg)
-{
- return vn_pager_io(obj, off, len, pg, true);
-}
-
-static int
-vn_pager_get(struct vm_object *obj, off_t off, size_t len, struct vm_page *pg)
-{
- return vn_pager_io(obj, off, len, pg, false);
-}