diff --git a/src/include/j6/flags.h b/src/include/j6/flags.h new file mode 100644 index 0000000..6cc89dd --- /dev/null +++ b/src/include/j6/flags.h @@ -0,0 +1,10 @@ +#pragma once +/// \file flags.h +/// Enums used as flags for syscalls + +enum j6_vm_flags { +#define VM_FLAG(name, v) j6_vm_flag_ ## name = v, +#include "j6/tables/vm_flags.inc" +#undef VM_FLAG + j6_vm_flags_MAX +}; diff --git a/src/include/j6/tables/syscalls.inc b/src/include/j6/tables/syscalls.inc index 26314b0..8fa78fb 100644 --- a/src/include/j6/tables/syscalls.inc +++ b/src/include/j6/tables/syscalls.inc @@ -2,6 +2,7 @@ SYSCALL(0x00, system_log, const char *) SYSCALL(0x01, system_noop, void) SYSCALL(0x02, system_get_log, j6_handle_t, char *, size_t *) SYSCALL(0x03, system_bind_irq, j6_handle_t, j6_handle_t, unsigned) +SYSCALL(0x04, system_map_mmio, j6_handle_t, j6_handle_t *, uintptr_t, size_t, uint32_t) SYSCALL(0x08, object_koid, j6_handle_t, j6_koid_t *) SYSCALL(0x09, object_wait, j6_handle_t, j6_signal_t, j6_signal_t *) diff --git a/src/include/j6/tables/vm_flags.inc b/src/include/j6/tables/vm_flags.inc new file mode 100644 index 0000000..3621f36 --- /dev/null +++ b/src/include/j6/tables/vm_flags.inc @@ -0,0 +1,9 @@ +VM_FLAG( none, 0x00000000) +VM_FLAG( write, 0x00000001) +VM_FLAG( exec, 0x00000002) +VM_FLAG( zero, 0x00000010) +VM_FLAG( contiguous, 0x00000020) +VM_FLAG( large_pages, 0x00000100) +VM_FLAG( huge_pages, 0x00000200) +VM_FLAG( write_combine, 0x00001000) +VM_FLAG( mmio, 0x00010000) diff --git a/src/kernel/objects/vm_area.h b/src/kernel/objects/vm_area.h index 4ece993..87ff0ac 100644 --- a/src/kernel/objects/vm_area.h +++ b/src/kernel/objects/vm_area.h @@ -17,20 +17,9 @@ class vm_space; enum class vm_flags : uint32_t { - none = 0x00000000, - - write = 0x00000001, - exec = 0x00000002, - - zero = 0x00000010, - contiguous = 0x00000020, - - large_pages = 0x00000100, - huge_pages = 0x00000200, - - mmio = 0x00010000, - write_combine = 0x00020000, - +#define VM_FLAG(name, v) name = v, +#include "j6/tables/vm_flags.inc" +#undef VM_FLAG user_mask = 0x0000ffff ///< flags allowed via syscall }; diff --git a/src/kernel/syscalls/system.cpp b/src/kernel/syscalls/system.cpp index 8a5acb0..e47bfdf 100644 --- a/src/kernel/syscalls/system.cpp +++ b/src/kernel/syscalls/system.cpp @@ -6,6 +6,7 @@ #include "objects/endpoint.h" #include "objects/thread.h" #include "objects/system.h" +#include "objects/vm_area.h" #include "syscalls/helpers.h" extern log::logger &g_logger; @@ -58,4 +59,16 @@ system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq) return j6_err_invalid_arg; } +j6_status_t +system_map_mmio(j6_handle_t sys, j6_handle_t *vma_handle, uintptr_t phys_addr, size_t size, uint32_t flags) +{ + // TODO: check capabilities on sys handle + if (!vma_handle) return j6_err_invalid_arg; + + vm_flags vmf = vm_flags::mmio | (static_cast(flags) & vm_flags::user_mask); + construct_handle(vma_handle, phys_addr, size, vmf); + + return j6_status_ok; +} + } // namespace syscalls