diff options
author | Ian Moffett <ian@osmora.org> | 2025-04-02 09:38:22 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-04-02 09:38:22 -0400 |
commit | 753666a333bb9ff0b8410cd729b9d06df85e0013 (patch) | |
tree | 169aa8b4307c65430e0da1b062cce858cfc2d7e7 | |
parent | d81f6b1d2cfcae0f90f2394b44cbdf03dcc0c69b (diff) |
kernel/aarch64: Add initial AARCH64 portaarch64
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | configure.ac | 36 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/acpi_machdep.c | 37 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/machdep.c | 75 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/mp.c | 39 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/pmap.c | 68 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/proc_machdep.c | 70 | ||||
-rw-r--r-- | sys/arch/aarch64/aarch64/reboot.c | 38 | ||||
-rw-r--r-- | sys/arch/aarch64/conf/GENERIC | 5 | ||||
-rw-r--r-- | sys/arch/aarch64/conf/link.ld | 75 | ||||
-rw-r--r-- | sys/arch/aarch64/pci/pci_machdep.c | 79 | ||||
-rw-r--r-- | sys/include/arch/aarch64/cpu.h | 48 | ||||
-rw-r--r-- | sys/include/arch/aarch64/frame.h | 96 | ||||
-rw-r--r-- | sys/include/arch/aarch64/pcb.h | 40 | ||||
-rw-r--r-- | sys/include/arch/aarch64/syscall.h | 85 | ||||
-rw-r--r-- | sys/include/arch/aarch64/vas.h | 45 |
16 files changed, 835 insertions, 4 deletions
diff --git a/Makefile.in b/Makefile.in index edf7193..95a419f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,6 +4,7 @@ override PROMPT := printf "%s\t\t%s\n" ############################### # CFLAGS, QEMU flags + misc ############################### +override BOOT_FW = @BOOT_FW@ override ARCH = @ARCH@ override HYRA_VERSION = @PACKAGE_VERSION@ override PROMPT := printf "%s\t\t%s\n" @@ -110,7 +111,7 @@ clean: iso: mkdir -p iso_root/boot/ mkdir -p iso_root/EFI/BOOT/ - cp stand/limine/BOOTX64.EFI iso_root/EFI/BOOT/ + cp stand/limine/$(BOOT_FW) iso_root/EFI/BOOT/ mv ramfs.cpio iso_root/boot/ cp builddeps/limine.cfg stand/limine/limine-bios.sys \ stand/limine/limine-bios-cd.bin stand/limine/limine-uefi-cd.bin iso_root/ diff --git a/configure.ac b/configure.ac index 08cf4dd..18398a4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,13 @@ -AC_INIT([Hyra], [1.5], [ian@osmora.org]) +AC_INIT([Hyra], [1.6], [ian@osmora.org]) + +TARGET="amd64" +BOOT_FW="BOOTX64.EFI" +AC_ARG_ENABLE([aarch64], + [AS_HELP_STRING([--enable-aarch64], [Enable AARCH64 Support])], + [TARGET="aarch64"], + [] +) + KERN_CFLAGS_AMD64="-fexceptions --std=gnu11 -ffreestanding -fno-stack-protector -fno-pic \\ -Werror=implicit -Werror=implicit-function-declaration \\ @@ -10,20 +19,41 @@ KERN_CFLAGS_AMD64="-fexceptions --std=gnu11 -ffreestanding -fno-stack-protector -I sys/include/ -I sys/include/lib/ -D_KERNEL -Wno-pointer-sign -MMD \\ -Wno-gnu-zero-variadic-macro-arguments -Wno-language-extension-token -Wno-tautological-constant-out-of-range-compare -Wno-c23-extensions" + +KERN_CFLAGS_AARCH64="-fexceptions --std=gnu11 -ffreestanding -fno-stack-protector -fno-pic \\ + -Werror=implicit -Werror=implicit-function-declaration \\ + -Werror=implicit-int -Werror=int-conversion \\ + -Werror=missing-prototypes \\ + -Werror=incompatible-pointer-types -Werror=int-to-pointer-cast \\ + -Werror=return-type -Wunused -pedantic \\ + -I sys/include/ -I sys/include/lib/ -D_KERNEL -Wno-pointer-sign -MMD \\ + -Wno-gnu-zero-variadic-macro-arguments -Wno-language-extension-token -Wno-tautological-constant-out-of-range-compare -Wno-c23-extensions" + + QEMU_FLAGS_AMD64="--enable-kvm -monitor stdio \\ -M q35 -m 1G -smp 4 -cpu host \\ -cdrom Hyra.iso" +KERN_CFLAGS="$KERN_CFLAGS_AMD64" + +if test "x$TARGET" = "xaarch64" +then + KERN_CFLAGS="$KERN_CFLAGS_AARCH64" + BOOT_FW="BOOTAA64.EFI" +fi + + HYRA_BUILDDATE=`export LANG=en_US.UTF-8 ; date` HYRA_BUILDBRANCH="`basename $PWD`" AC_SUBST(HYRA_BUILDDATE, [$HYRA_BUILDDATE]) AC_SUBST(HYRA_BUILDBRANCH, [$HYRA_BUILDBRANCH]) -AC_SUBST(KERNEL_CFLAGS, [$KERN_CFLAGS_AMD64]) +AC_SUBST(KERNEL_CFLAGS, [$KERN_CFLAGS]) AC_SUBST(QEMU_FLAGS, [$QEMU_FLAGS_AMD64]) AC_SUBST(QEMU, [qemu-system-x86_64]) -AC_SUBST(ARCH, [amd64]) +AC_SUBST(BOOT_FW, [$BOOT_FW]) +AC_SUBST(ARCH, [$TARGET]) AC_SUBST(TOOLCHAIN, [clang]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/sys/arch/aarch64/aarch64/acpi_machdep.c b/sys/arch/aarch64/aarch64/acpi_machdep.c new file mode 100644 index 0000000..f077de3 --- /dev/null +++ b/sys/arch/aarch64/aarch64/acpi_machdep.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <dev/acpi/acpi.h> +#include <dev/acpi/acpivar.h> + +int +acpi_init_madt(void) +{ + return 0; +} diff --git a/sys/arch/aarch64/aarch64/machdep.c b/sys/arch/aarch64/aarch64/machdep.c new file mode 100644 index 0000000..1d34e56 --- /dev/null +++ b/sys/arch/aarch64/aarch64/machdep.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/syslog.h> +#include <sys/panic.h> +#include <machine/cpu.h> + +struct cpu_info g_bsp_ci = {0}; + +void +cpu_startup(struct cpu_info *ci) +{ + /* TODO: STUB */ + return; +} + +void +serial_init(void) +{ + /* TODO: STUB */ + return; +} + +void +md_backtrace(void) +{ + /* TODO: STUB */ + return; +} + +void +serial_putc(char c) +{ + /* TODO: STUB */ + return; +} + +/* + * Get the descriptor for the currently + * running processor. + */ +struct cpu_info * +this_cpu(void) +{ + struct cpu_info *ci; + + __ASMV("mrs %0, tpidr_el0" : "=r" (ci)); + return ci; +} diff --git a/sys/arch/aarch64/aarch64/mp.c b/sys/arch/aarch64/aarch64/mp.c new file mode 100644 index 0000000..4e07566 --- /dev/null +++ b/sys/arch/aarch64/aarch64/mp.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <machine/cpu.h> + +#define pr_trace(fmt, ...) kprintf("cpu_mp: " fmt, ##__VA_ARGS__) + +void +mp_bootstrap_aps(struct cpu_info *ci) +{ + for (;;); +} diff --git a/sys/arch/aarch64/aarch64/pmap.c b/sys/arch/aarch64/aarch64/pmap.c new file mode 100644 index 0000000..b5ebda9 --- /dev/null +++ b/sys/arch/aarch64/aarch64/pmap.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <machine/vas.h> +#include <vm/pmap.h> + +struct vas +pmap_read_vas(void) +{ + /* TODO: STUB */ + struct vas vas = {0}; + return vas; +} + +void +pmap_switch_vas(struct vas vas) +{ + /* TODO: STUB */ + return; +} + +int +pmap_map(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot) +{ + /* TODO: STUB */ + return 0; +} + +int +pmap_unmap(struct vas vas, vaddr_t va) +{ + /* TODO: STUB */ + return 0; +} + +void +pmap_destroy_vas(struct vas vas) +{ + /* TODO: STUB */ + return; +} diff --git a/sys/arch/aarch64/aarch64/proc_machdep.c b/sys/arch/aarch64/aarch64/proc_machdep.c new file mode 100644 index 0000000..97902e5 --- /dev/null +++ b/sys/arch/aarch64/aarch64/proc_machdep.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/proc.h> + +/* + * MD thread init code + * + * @p: New process. + * @parent: Parent of new process. + * @ip: Instruction pointer. + */ +int +md_fork(struct proc *p, struct proc *parent, uintptr_t ip) +{ + /* TODO: STUB */ + return 0; +} + +void +md_td_stackinit(struct proc *td, void *stack_top, struct exec_prog *prog) +{ + /* TODO: STUB */ + return; +} + +void +setregs(struct proc *td, struct exec_prog *prog, uintptr_t stack) +{ + /* TODO: STUB */ + return; +} + +/* + * Startup a user thread. + * + * @td: Thread to start up. + */ +void +md_td_kick(struct proc *td) +{ + /* TODO: STUB */ + for (;;); +} diff --git a/sys/arch/aarch64/aarch64/reboot.c b/sys/arch/aarch64/aarch64/reboot.c new file mode 100644 index 0000000..6d82133 --- /dev/null +++ b/sys/arch/aarch64/aarch64/reboot.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/reboot.h> +#include <sys/param.h> + +void +cpu_reboot(int method) +{ + /* TODO: STUB */ + for (;;); +} diff --git a/sys/arch/aarch64/conf/GENERIC b/sys/arch/aarch64/conf/GENERIC new file mode 100644 index 0000000..5691685 --- /dev/null +++ b/sys/arch/aarch64/conf/GENERIC @@ -0,0 +1,5 @@ +// Kernel options +option SERIAL_DEBUG yes + +// Kernel constants +setval SCHED_NQUEUE 4 diff --git a/sys/arch/aarch64/conf/link.ld b/sys/arch/aarch64/conf/link.ld new file mode 100644 index 0000000..c64cec3 --- /dev/null +++ b/sys/arch/aarch64/conf/link.ld @@ -0,0 +1,75 @@ +/* Tell the linker that we want an aarch64 ELF64 output file */ +OUTPUT_FORMAT(elf64-littleaarch64) +OUTPUT_ARCH(aarch64) + +/* We want the symbol main to be our entry point */ +ENTRY(main) + +/* Define the program headers we want so the bootloader gives us the right */ +/* MMU permissions */ +PHDRS +{ + text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ + rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ + data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ + dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic PHDR for relocations */ +} + +SECTIONS +{ + /* We wanna be placed in the topmost 2GiB of the address space, for optimisations */ + /* and because that is what the Limine spec mandates. */ + /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */ + /* that is the beginning of the region. */ + . = 0xffffffff80000000; + + .text : { + *(.text .text.*) + } :text + + /* Move to the next memory page for .rodata */ + . += CONSTANT(MAXPAGESIZE); + + .rodata : { + *(.rodata .rodata.*) + } :rodata + + .drivers : { + __drivers_init_start = .; + *(.drivers .drivers) + __drivers_init_end = .; + } :rodata + + /* Move to the next memory page for .data */ + . += CONSTANT(MAXPAGESIZE); + + .data : { + *(.data .data.*) + } :data + + /* Dynamic section for relocations, both in its own PHDR and inside data PHDR */ + .dynamic : { + *(.dynamic) + } :data :dynamic + + /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ + /* unnecessary zeros will be written to the binary. */ + /* If you need, for example, .init_array and .fini_array, those should be placed */ + /* above this. */ + .bss : { + *(.bss .bss.*) + *(COMMON) + } :data + + /* -- Cache line alignment -- */ + . = ALIGN(64); + .data.cacheline_aligned : { + *(.data.cacheline_aligned) + } + + /* Discard .note.* and .eh_frame since they may cause issues on some hosts. */ + /DISCARD/ : { + *(.eh_frame) + *(.note .note.*) + } +} diff --git a/sys/arch/aarch64/pci/pci_machdep.c b/sys/arch/aarch64/pci/pci_machdep.c new file mode 100644 index 0000000..fa92165 --- /dev/null +++ b/sys/arch/aarch64/pci/pci_machdep.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <dev/pci/pci.h> + +pcireg_t +pci_readl(struct pci_device *dev, uint32_t offset) +{ + /* TODO: STUB */ + return 0; +} + +void +pci_writel(struct pci_device *dev, uint32_t offset, pcireg_t val) +{ + /* TODO: STUB */ + return; +} + +/* + * Map a BAR into kernel memory. + * + * @dev: Device of BAR to map. + * @barno: BAR number to map. + * @vap: Resulting virtual address. + */ +int +pci_map_bar(struct pci_device *dev, uint8_t barno, void **vap) +{ + /* TODO: STUB */ + return 0; +} + +void +pci_msix_eoi(void) +{ + return; +} + +/* + * Enable MSI-X for a device and allocate an + * interrupt vector. + * + * @dev: Device to enable MSI-X for. + * @intr: MSI-X interrupt descriptor. + */ +int +pci_enable_msix(struct pci_device *dev, const struct msi_intr *intr) +{ + /* TODO: STUB */ + return 0; +} diff --git a/sys/include/arch/aarch64/cpu.h b/sys/include/arch/aarch64/cpu.h new file mode 100644 index 0000000..a6ccdec --- /dev/null +++ b/sys/include/arch/aarch64/cpu.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +#include <sys/types.h> +#include <sys/cdefs.h> +#include <sys/proc.h> + +struct cpu_info { + struct proc *curtd; + struct cpu_info *self; +}; + +void cpu_startup(struct cpu_info *ci); +void mp_bootstrap_aps(struct cpu_info *ci); +struct cpu_info *this_cpu(void); + +extern struct cpu_info g_bsp_ci; + +#endif /* !_MACHINE_CPU_H_ */ diff --git a/sys/include/arch/aarch64/frame.h b/sys/include/arch/aarch64/frame.h new file mode 100644 index 0000000..ec11533 --- /dev/null +++ b/sys/include/arch/aarch64/frame.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#include <sys/types.h> + +typedef uint64_t lreg_t; + +/* General purpose registers */ +struct gpregs { + lreg_t x0; + lreg_t x1; + lreg_t x2; + lreg_t x3; + lreg_t x4; + lreg_t x5; + lreg_t x6; + lreg_t x7; + lreg_t x8; + lreg_t x9; + lreg_t x10; + lreg_t x11; + lreg_t x12; + lreg_t x13; + lreg_t x14; + lreg_t x15; + lreg_t x16; + lreg_t x17; + lreg_t x18; + lreg_t x19; + lreg_t x20; + lreg_t x21; + lreg_t x22; + lreg_t x23; + lreg_t x24; + lreg_t x25; + lreg_t x26; + lreg_t x27; + lreg_t x28; + lreg_t x29; + lreg_t x30; +}; + +/* Stack regs */ +struct sregs { + lreg_t sp_el0; + lreg_t sp_el1; + lreg_t sp_el2; +}; + +/* Program status */ +struct pstat { + lreg_t spsr_el1; + lreg_t spsr_el2; + lreg_t spsr_el3; +}; + +struct trapframe { + struct gpregs gp; + struct sregs stack; + struct pstat status; + lreg_t elr_el1; + lreg_t elr_el2; + lreg_t elr_el3; + lreg_t pc; +}; + +#endif /* !_MACHINE_FRAME_H_ */ diff --git a/sys/include/arch/aarch64/pcb.h b/sys/include/arch/aarch64/pcb.h new file mode 100644 index 0000000..f9a0b1a --- /dev/null +++ b/sys/include/arch/aarch64/pcb.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include <sys/types.h> +#include <vm/pmap.h> + +struct pcb { + struct vas addrsp; +}; + +#endif /* !_MACHINE_PCB_H_ */ diff --git a/sys/include/arch/aarch64/syscall.h b/sys/include/arch/aarch64/syscall.h new file mode 100644 index 0000000..84a51e0 --- /dev/null +++ b/sys/include/arch/aarch64/syscall.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_SYSCALL_H_ +#define _MACHINE_SYSCALL_H_ + +#if !defined(__ASSEMBLER__) +__always_inline static inline long +syscall0(uint64_t code) +{ + return 0; +} + +__always_inline static inline long +syscall1(uint64_t code, uint64_t arg0) +{ + return 0; +} + +__always_inline static long inline +syscall2(uint64_t code, uint64_t arg0, uint64_t arg1) +{ + return 0; +} + +__always_inline static inline long +syscall3(uint64_t code, uint64_t arg0, uint64_t arg1, uint64_t arg2) +{ + return 0; +} + +__always_inline static inline long +syscall4(uint64_t code, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3) +{ + return 0; +} + +__always_inline static inline long +syscall5(uint64_t code, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) +{ + return 0; +} + +__always_inline static inline long +syscall6(uint64_t code, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) +{ + return 0; +} + +#define _SYSCALL_N(a0, a1, a2, a3, a4, a5, a6, name, ...) \ + name + +#define syscall(...) \ +_SYSCALL_N(__VA_ARGS__, syscall6, syscall5, \ + syscall4, syscall3, syscall2, syscall1, \ + syscall0)(__VA_ARGS__) + +#endif /* !__ASSEMBLER__ */ +#endif /* !_MACHINE_SYSCALL_H_ */ diff --git a/sys/include/arch/aarch64/vas.h b/sys/include/arch/aarch64/vas.h new file mode 100644 index 0000000..07cd576 --- /dev/null +++ b/sys/include/arch/aarch64/vas.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_VAS_H_ +#define _MACHINE_VAS_H_ + +#include <sys/types.h> +#include <sys/spinlock.h> + +/* + * VAS structure - describes a virtual address space + */ +struct vas { + paddr_t ttbr0_el1; /* Lower half */ + paddr_t ttbr1_el1; /* Higher half */ + struct spinlock *lock; +}; + +#endif /* !_MACHINE_VAS_H_ */ |