diff options
Diffstat (limited to 'sys/include')
-rw-r--r-- | sys/include/arch/amd64/cdefs.h | 9 | ||||
-rw-r--r-- | sys/include/arch/amd64/cpu.h | 8 | ||||
-rw-r--r-- | sys/include/dev/video/fbdev.h | 1 | ||||
-rw-r--r-- | sys/include/sys/device.h | 5 | ||||
-rw-r--r-- | sys/include/sys/driver.h | 2 | ||||
-rw-r--r-- | sys/include/sys/fbdev.h | 40 | ||||
-rw-r--r-- | sys/include/sys/limits.h | 4 | ||||
-rw-r--r-- | sys/include/sys/mman.h | 22 | ||||
-rw-r--r-- | sys/include/sys/proc.h | 5 | ||||
-rw-r--r-- | sys/include/sys/sched.h | 2 | ||||
-rw-r--r-- | sys/include/sys/spawn.h | 3 | ||||
-rw-r--r-- | sys/include/sys/syscall.h | 2 | ||||
-rw-r--r-- | sys/include/sys/vnode.h | 3 | ||||
-rw-r--r-- | sys/include/vm/pmap.h | 11 | ||||
-rw-r--r-- | sys/include/vm/vm_device.h | 43 |
15 files changed, 147 insertions, 13 deletions
diff --git a/sys/include/arch/amd64/cdefs.h b/sys/include/arch/amd64/cdefs.h index bab0c89..0a20324 100644 --- a/sys/include/arch/amd64/cdefs.h +++ b/sys/include/arch/amd64/cdefs.h @@ -43,4 +43,13 @@ #define md_inton() __ASMV("sti") /* Enable interrupts */ #define md_hlt() __ASMV("hlt") /* Halt the processor */ +/* + * AMD64 specific defines + */ +#define __invlpg(VA) \ + __ASMV("invlpg %0" \ + : \ + : "m" ((VA)) \ + : "memory") + #endif /* !_AMD64_CDEFS_H_ */ diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h index dd753b7..2d08d6e 100644 --- a/sys/include/arch/amd64/cpu.h +++ b/sys/include/arch/amd64/cpu.h @@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/cdefs.h> #include <sys/proc.h> +#include <sys/spinlock.h> #include <machine/tss.h> #define CPU_IRQ(IRQ_N) (BIT((IRQ_N)) & 0xFF) @@ -40,11 +41,14 @@ struct cpu_info { uint32_t apicid; uint8_t has_x2apic : 1; + uint8_t tlb_shootdown : 1; uint8_t ipl; size_t lapic_tmr_freq; uint8_t irq_mask; + vaddr_t shootdown_va; struct tss_entry *tss; struct proc *curtd; + struct spinlock lock; struct cpu_info *self; }; @@ -52,6 +56,10 @@ __dead void cpu_halt_all(void); void cpu_halt_others(void); void cpu_startup(struct cpu_info *ci); +struct cpu_info *cpu_get(uint32_t index); +uint32_t cpu_count(void); +void cpu_shootdown_tlb(vaddr_t va); + struct cpu_info *this_cpu(void); void mp_bootstrap_aps(struct cpu_info *ci); diff --git a/sys/include/dev/video/fbdev.h b/sys/include/dev/video/fbdev.h index c80fd92..c9fec94 100644 --- a/sys/include/dev/video/fbdev.h +++ b/sys/include/dev/video/fbdev.h @@ -52,5 +52,6 @@ fbdev_get_index(const struct fbdev *fbdev, uint32_t x, uint32_t y) } struct fbdev fbdev_get(void); +void fbdev_init_dev(void); #endif /* !_DEV_FBDEV_H_ */ diff --git a/sys/include/sys/device.h b/sys/include/sys/device.h index fcafdab..04b66fc 100644 --- a/sys/include/sys/device.h +++ b/sys/include/sys/device.h @@ -36,6 +36,7 @@ #include <sys/queue.h> #include <sys/proc.h> #include <sys/sio.h> +#include <vm/vm_obj.h> typedef uint8_t devmajor_t; @@ -47,6 +48,10 @@ typedef int(*dev_bsize_t)(dev_t); struct cdevsw { int(*read)(dev_t dev, struct sio_txn *sio, int flags); int(*write)(dev_t dev, struct sio_txn *sio, int flags); + paddr_t(*mmap)(dev_t dev, size_t size, off_t off, int flags); + + /* Private */ + struct vm_object vmobj; }; struct bdevsw { diff --git a/sys/include/sys/driver.h b/sys/include/sys/driver.h index 6e4a267..8ab9521 100644 --- a/sys/include/sys/driver.h +++ b/sys/include/sys/driver.h @@ -110,7 +110,7 @@ extern char __driversd_init_end[]; } #define DRIVERS_SCHED() \ - spawn(&g_proc0,__driver_init_td, NULL, 0, NULL) + spawn(&g_proc0, __driver_init_td, NULL, 0, NULL) void __driver_init_td(void); diff --git a/sys/include/sys/fbdev.h b/sys/include/sys/fbdev.h new file mode 100644 index 0000000..e206889 --- /dev/null +++ b/sys/include/sys/fbdev.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_FBDEV_H_ +#define _SYS_FBDEV_H_ + +struct fbattr { + uint32_t width; + uint32_t height; + uint32_t pitch; + uint32_t bpp; +}; + +#endif /* !_SYS_FBDEV_H_ */ diff --git a/sys/include/sys/limits.h b/sys/include/sys/limits.h index 6185719..198c963 100644 --- a/sys/include/sys/limits.h +++ b/sys/include/sys/limits.h @@ -33,5 +33,7 @@ #define PATH_MAX 1024 #define SSIZE_MAX 32767 #define CHAR_BIT 8 - +#if defined(_KERNEL) +#define CPU_MAX 256 +#endif /* _KERNEL */ #endif /* !_SYS_LIMITS_H_ */ diff --git a/sys/include/sys/mman.h b/sys/include/sys/mman.h index 4ead9ba..08f506d 100644 --- a/sys/include/sys/mman.h +++ b/sys/include/sys/mman.h @@ -35,6 +35,8 @@ #if defined(_KERNEL) #include <sys/tree.h> #include <vm/vm_obj.h> +#else +#include <stddef.h> #endif /* _KERNEL */ /* @@ -80,19 +82,19 @@ struct mmap_lgdr { size_t nbytes; }; -/* Kernel munmap() routine */ -int munmap_at(void *addr, size_t len); - -/* Kernel mmap() routine */ -void *mmap_at(void *addr, size_t len, int prot, int flags, - int fildes, off_t off); - int mmap_entrycmp(const struct mmap_entry *a, const struct mmap_entry *b); RBT_PROTOTYPE(lgdr_entries, mmap_entry, hd, mmap_entrycmp) -#endif /* _KERNEL */ /* Syscall layer */ -scret_t mmap(struct syscall_args *scargs); -scret_t munmap(struct syscall_args *scargs); +scret_t sys_mmap(struct syscall_args *scargs); +scret_t sys_munmap(struct syscall_args *scargs); +#endif /* _KERNEL */ + +/* Kernel munmap() routine */ +int munmap(void *addr, size_t len); + +/* Kernel mmap() routine */ +void *mmap(void *addr, size_t len, int prot, int flags, + int fildes, off_t off); #endif /* !_SYS_MMAN_H_ */ diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h index 0a7d133..25f5fd3 100644 --- a/sys/include/sys/proc.h +++ b/sys/include/sys/proc.h @@ -64,7 +64,7 @@ struct proc { struct trapframe tf; struct pcb pcb; struct proc *parent; - void *spawn_data; + void *data; size_t priority; int exit_status; bool rested; @@ -84,9 +84,12 @@ struct proc { #define PROC_LEAFQ BIT(3) /* Leaf queue is active */ #define PROC_WAITED BIT(4) /* Being waited on by parent */ #define PROC_KTD BIT(5) /* Kernel thread */ +#define PROC_SLEEP BIT(6) /* Thread execution paused */ struct proc *this_td(void); struct proc *get_child(struct proc *cur, pid_t pid); +void proc_reap(struct proc *td); + int md_spawn(struct proc *p, struct proc *parent, uintptr_t ip); scret_t sys_spawn(struct syscall_args *scargs); diff --git a/sys/include/sys/sched.h b/sys/include/sys/sched.h index 80f4d1c..7d17607 100644 --- a/sys/include/sys/sched.h +++ b/sys/include/sys/sched.h @@ -37,6 +37,8 @@ void sched_init(void); void sched_yield(void); + +void sched_switch_to(struct trapframe *tf, struct proc *td); void sched_detach(struct proc *td); __dead void sched_enter(void); diff --git a/sys/include/sys/spawn.h b/sys/include/sys/spawn.h index 3828d5c..9d823db 100644 --- a/sys/include/sys/spawn.h +++ b/sys/include/sys/spawn.h @@ -31,6 +31,9 @@ #define _SYS_SPAWN_H_ #include <sys/types.h> +#include <sys/param.h> + +#define SPAWN_WAIT BIT(0) #if !defined(_KERNEL) pid_t spawn(const char *pathname, int flags); diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h index 2223a96..dad2e00 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -48,6 +48,8 @@ #define SYS_write 7 #define SYS_spawn 8 #define SYS_reboot 9 +#define SYS_mmap 10 +#define SYS_munmap 11 #if defined(_KERNEL) /* Syscall return value and arg type */ diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h index 33092f9..cd71817 100644 --- a/sys/include/sys/vnode.h +++ b/sys/include/sys/vnode.h @@ -32,6 +32,7 @@ #include <sys/types.h> #include <sys/queue.h> +#include <sys/vnode.h> #include <sys/atomic.h> #include <sys/sio.h> #include <vm/vm_obj.h> @@ -47,6 +48,8 @@ struct vnode { const struct vops *vops; struct vm_object vobj; uint32_t refcount; + dev_t major; + dev_t dev; TAILQ_ENTRY(vnode) vcache_link; }; diff --git a/sys/include/vm/pmap.h b/sys/include/vm/pmap.h index 9eed184..e1f3f89 100644 --- a/sys/include/vm/pmap.h +++ b/sys/include/vm/pmap.h @@ -76,6 +76,17 @@ int pmap_map(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot); int pmap_unmap(struct vas vas, vaddr_t va); /* + * Returns true if the page is clean (modified), otherwise + * returns false. + */ +bool pmap_is_clean(struct vas vas, vaddr_t va); + +/* + * Marks a page as clean (unmodified) + */ +void pmap_mark_clean(struct vas vas, vaddr_t va); + +/* * Mark a virtual address with a specific * caching type. */ diff --git a/sys/include/vm/vm_device.h b/sys/include/vm/vm_device.h new file mode 100644 index 0000000..da476e2 --- /dev/null +++ b/sys/include/vm/vm_device.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _VM_DEVICE_H_ +#define _VM_DEVICE_H_ + +#include <sys/types.h> +#include <sys/vnode.h> +#include <sys/device.h> +#include <vm/vm_pager.h> +#include <vm/vm_obj.h> + +extern const struct vm_pagerops vm_vnops; + +struct vm_object *dv_attach(devmajor_t major, dev_t dev, vm_prot_t prot); + +#endif /* !_VM_DEVICE_H_ */ |