diff --git a/src/boot/allocator.cpp b/src/boot/allocator.cpp index 8d5f47e..c4cb878 100644 --- a/src/boot/allocator.cpp +++ b/src/boot/allocator.cpp @@ -1,7 +1,7 @@ #include #include +#include -#include "kutil/no_construct.h" #include "allocator.h" #include "error.h" #include "init_args.h" @@ -10,7 +10,7 @@ namespace boot { -kutil::no_construct __g_alloc_storage; +util::no_construct __g_alloc_storage; memory::allocator &g_alloc = __g_alloc_storage.value; namespace memory { diff --git a/src/boot/boot.module b/src/boot/boot.module index e9cdf57..13b71da 100644 --- a/src/boot/boot.module +++ b/src/boot/boot.module @@ -4,7 +4,7 @@ module("boot", kind = "exe", output = "boot.efi", targets = [ "boot" ], - deps = [ "cpu", "elf", "kutil" ], + deps = [ "cpu", "elf", "util" ], sources = [ "allocator.cpp", "console.cpp", diff --git a/src/boot/memory.cpp b/src/boot/memory.cpp index 03a28cd..f3042c3 100644 --- a/src/boot/memory.cpp +++ b/src/boot/memory.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "console.h" #include "error.h" diff --git a/src/include/j6/flags.h b/src/include/j6/flags.h index d4afee5..c840bee 100644 --- a/src/include/j6/flags.h +++ b/src/include/j6/flags.h @@ -4,7 +4,7 @@ enum j6_vm_flags { #define VM_FLAG(name, v) j6_vm_flag_ ## name = v, -#include "j6/tables/vm_flags.inc" +#include #undef VM_FLAG j6_vm_flag_MAX }; diff --git a/src/include/j6/init.h b/src/include/j6/init.h index a8afe20..c65827c 100644 --- a/src/include/j6/init.h +++ b/src/include/j6/init.h @@ -3,7 +3,7 @@ /// Types used in process and thread initialization #include -#include "j6/types.h" +#include enum j6_init_type { // `value` is a: j6_init_handle_self, // Handle to the system diff --git a/src/include/j6/types.h b/src/include/j6/types.h index 2eeffe3..e9bfb0f 100644 --- a/src/include/j6/types.h +++ b/src/include/j6/types.h @@ -38,7 +38,7 @@ typedef uint64_t j6_handle_t; enum j6_object_type { #define OBJECT_TYPE( name, val ) j6_object_type_ ## name = val, -#include "j6/tables/object_types.inc" +#include #undef OBJECT_TYPE j6_object_type_max diff --git a/src/kernel/acpi_tables.h b/src/kernel/acpi_tables.h index 74fc894..a9665fb 100644 --- a/src/kernel/acpi_tables.h +++ b/src/kernel/acpi_tables.h @@ -3,8 +3,8 @@ #include #include -#include "enum_bitfields.h" -#include "kutil/misc.h" +#include +#include struct acpi_table_header { @@ -22,7 +22,7 @@ struct acpi_table_header } __attribute__ ((packed)); #define TABLE_HEADER(signature) \ - static constexpr uint32_t type_id = kutil::byteswap(signature); \ + static constexpr uint32_t type_id = util::byteswap(signature); \ acpi_table_header header; diff --git a/src/kernel/console.cpp b/src/kernel/console.cpp index 4353700..64590ff 100644 --- a/src/kernel/console.cpp +++ b/src/kernel/console.cpp @@ -1,13 +1,13 @@ -#include "kutil/no_construct.h" -#include "printf/printf.h" +#include #include "console.h" +#include "printf/printf.h" #include "serial.h" const char digits[] = "0123456789abcdef"; -static kutil::no_construct __g_console_storage; +static util::no_construct __g_console_storage; console &g_console = __g_console_storage.value; diff --git a/src/kernel/device_manager.h b/src/kernel/device_manager.h index d328e72..a658eb1 100644 --- a/src/kernel/device_manager.h +++ b/src/kernel/device_manager.h @@ -1,7 +1,9 @@ #pragma once /// \file device_manager.h /// The device manager definition -#include "kutil/vector.h" + +#include + #include "apic.h" #include "hpet.h" #include "pci.h" @@ -79,7 +81,7 @@ public: }; /// Get the list of APIC ids for other CPUs - inline const kutil::vector & get_apic_ids() const { return m_apic_ids; } + inline const util::vector & get_apic_ids() const { return m_apic_ids; } /// Get the LAPIC base address /// \returns The physical base address of the local apic registers @@ -150,18 +152,18 @@ private: uintptr_t m_lapic_base; - kutil::vector m_ioapics; - kutil::vector m_hpets; - kutil::vector m_apic_ids; - kutil::vector m_nmis; - kutil::vector m_overrides; + util::vector m_ioapics; + util::vector m_hpets; + util::vector m_apic_ids; + util::vector m_nmis; + util::vector m_overrides; - kutil::vector m_pci; - kutil::vector m_devices; + util::vector m_pci; + util::vector m_devices; - kutil::vector m_irqs; + util::vector m_irqs; - kutil::vector m_blockdevs; + util::vector m_blockdevs; static device_manager s_instance; diff --git a/src/kernel/frame_allocator.cpp b/src/kernel/frame_allocator.cpp index b117ea0..8228e42 100644 --- a/src/kernel/frame_allocator.cpp +++ b/src/kernel/frame_allocator.cpp @@ -30,7 +30,7 @@ bsf(uint64_t v) size_t frame_allocator::allocate(size_t count, uintptr_t *address) { - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; for (long i = m_count - 1; i >= 0; --i) { frame_block &block = m_blocks[i]; @@ -80,7 +80,7 @@ frame_allocator::allocate(size_t count, uintptr_t *address) void frame_allocator::free(uintptr_t address, size_t count) { - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; kassert(address % frame_size == 0, "Trying to free a non page-aligned frame!"); @@ -118,7 +118,7 @@ frame_allocator::free(uintptr_t address, size_t count) void frame_allocator::used(uintptr_t address, size_t count) { - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; kassert(address % frame_size == 0, "Trying to mark a non page-aligned frame!"); diff --git a/src/kernel/frame_allocator.h b/src/kernel/frame_allocator.h index b0056ce..f276e27 100644 --- a/src/kernel/frame_allocator.h +++ b/src/kernel/frame_allocator.h @@ -3,7 +3,7 @@ /// Allocator for physical memory frames #include -#include "kutil/spinlock.h" +#include namespace kernel { namespace init { @@ -46,7 +46,7 @@ private: frame_block *m_blocks; size_t m_count; - kutil::spinlock m_lock; + util::spinlock m_lock; frame_allocator() = delete; frame_allocator(const frame_allocator &) = delete; diff --git a/src/kernel/gdt.cpp b/src/kernel/gdt.cpp index 39beaf6..88d9bae 100644 --- a/src/kernel/gdt.cpp +++ b/src/kernel/gdt.cpp @@ -1,7 +1,7 @@ #include #include -#include "kutil/no_construct.h" +#include #include "assert.h" #include "console.h" @@ -22,7 +22,7 @@ static constexpr uint8_t tss_index = 6; // Note that this takes TWO GDT en // The BSP's GDT is initialized _before_ global constructors are called, // so we don't want it to have a global constructor, lest it overwrite // the previous initialization. -static kutil::no_construct __g_bsp_gdt_storage; +static util::no_construct __g_bsp_gdt_storage; GDT &g_bsp_gdt = __g_bsp_gdt_storage.value; diff --git a/src/kernel/heap_allocator.cpp b/src/kernel/heap_allocator.cpp index 1cc4bd0..2195816 100644 --- a/src/kernel/heap_allocator.cpp +++ b/src/kernel/heap_allocator.cpp @@ -1,6 +1,7 @@ #include #include -#include "kutil/util.h" + +#include #include "assert.h" #include "heap_allocator.h" @@ -81,7 +82,7 @@ heap_allocator::allocate(size_t length) if (length == 0) return nullptr; - unsigned order = kutil::log2(total); + unsigned order = util::log2(total); if (order < min_order) order = min_order; @@ -89,7 +90,7 @@ heap_allocator::allocate(size_t length) if (order > max_order) return nullptr; - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; mem_header *header = pop_free(order); header->set_used(true); @@ -106,7 +107,7 @@ heap_allocator::free(void *p) kassert(addr >= m_start && addr < m_end, "Attempt to free non-heap pointer"); - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; mem_header *header = reinterpret_cast(p); header -= 1; // p points after the header diff --git a/src/kernel/heap_allocator.h b/src/kernel/heap_allocator.h index 457aada..6837a6e 100644 --- a/src/kernel/heap_allocator.h +++ b/src/kernel/heap_allocator.h @@ -3,7 +3,8 @@ /// A buddy allocator for a memory heap #include -#include "kutil/spinlock.h" + +#include /// Allocator for a given heap range @@ -56,7 +57,7 @@ protected: mem_header *m_free[max_order - min_order + 1]; size_t m_allocated_size; - kutil::spinlock m_lock; + util::spinlock m_lock; heap_allocator(const heap_allocator &) = delete; }; diff --git a/src/kernel/idt.cpp b/src/kernel/idt.cpp index 96e33ff..39a6206 100644 --- a/src/kernel/idt.cpp +++ b/src/kernel/idt.cpp @@ -1,6 +1,6 @@ #include -#include "kutil/no_construct.h" +#include #include "cpu.h" #include "idt.h" @@ -23,7 +23,7 @@ extern "C" { // The BSP's IDT is initialized _before_ global constructors are called, // so we don't want it to have a global constructor, lest it overwrite // the previous initialization. -static kutil::no_construct __g_bsp_idt_storage; +static util::no_construct __g_bsp_idt_storage; IDT &g_bsp_idt = __g_bsp_idt_storage.value; void (*__nmi_handler)(); diff --git a/src/kernel/kernel.module b/src/kernel/kernel.module index da01947..9d2ad01 100644 --- a/src/kernel/kernel.module +++ b/src/kernel/kernel.module @@ -5,7 +5,7 @@ kernel = module("kernel", default = True, output = "jsix.elf", targets = [ "kernel" ], - deps = [ "kutil", "cpu" ], + deps = [ "util", "cpu" ], includes = [ "." ], sources = [ "apic.cpp", diff --git a/src/kernel/log.cpp b/src/kernel/log.cpp index 34b3960..3be1583 100644 --- a/src/kernel/log.cpp +++ b/src/kernel/log.cpp @@ -1,5 +1,5 @@ -#include "j6/signals.h" -#include "kutil/no_construct.h" +#include +#include #include "assert.h" #include "console.h" @@ -13,7 +13,7 @@ static uint8_t log_buffer[0x10000]; // The logger is initialized _before_ global constructors are called, // so that we can start log output immediately. Keep its constructor // from being called here so as to not overwrite the previous initialization. -static kutil::no_construct __g_logger_storage; +static util::no_construct __g_logger_storage; log::logger &g_logger = __g_logger_storage.value; static const uint8_t level_colors[] = {0x07, 0x07, 0x0f, 0x0b, 0x09}; diff --git a/src/kernel/logger.cpp b/src/kernel/logger.cpp index 3cf2a7d..83e4f04 100644 --- a/src/kernel/logger.cpp +++ b/src/kernel/logger.cpp @@ -1,16 +1,16 @@ #include -#include "kutil/constexpr_hash.h" -#include "printf/printf.h" +#include #include "assert.h" #include "logger.h" +#include "printf/printf.h" namespace logs { #define LOG(name, lvl) \ const log::area_t name = #name ## _h; \ const char * name ## _name = #name; -#include "j6/tables/log_areas.inc" +#include #undef LOG } @@ -42,7 +42,7 @@ logger::logger(uint8_t *buffer, size_t size, logger::immediate_cb output) : #define LOG(name, lvl) \ register_area(logs::name, logs::name ## _name, log::level::lvl); -#include "j6/tables/log_areas.inc" +#include #undef LOG } @@ -89,7 +89,7 @@ logger::output(level severity, area_t area, const char *fmt, va_list args) header->bytes += vsnprintf(header->message, sizeof(buffer) - sizeof(entry), fmt, args); - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; if (m_immediate) { buffer[header->bytes] = 0; @@ -117,7 +117,7 @@ logger::output(level severity, area_t area, const char *fmt, va_list args) size_t logger::get_entry(void *buffer, size_t size) { - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; void *out; size_t out_size = m_buffer.get_block(&out); diff --git a/src/kernel/logger.h b/src/kernel/logger.h index e5e4150..9123f71 100644 --- a/src/kernel/logger.h +++ b/src/kernel/logger.h @@ -5,8 +5,8 @@ #include #include -#include "kutil/bip_buffer.h" -#include "kutil/spinlock.h" +#include +#include namespace log { @@ -110,8 +110,8 @@ private: uint8_t m_sequence; - kutil::bip_buffer m_buffer; - kutil::spinlock m_lock; + util::bip_buffer m_buffer; + util::spinlock m_lock; static logger *s_log; static const char *s_level_names[static_cast(level::max)]; @@ -129,6 +129,6 @@ extern log::logger &g_logger; namespace logs { #define LOG(name, lvl) extern const log::area_t name; -#include "j6/tables/log_areas.inc" +#include #undef LOG } // namespace logs diff --git a/src/kernel/main.cpp b/src/kernel/main.cpp index 65d5b77..2cf60b1 100644 --- a/src/kernel/main.cpp +++ b/src/kernel/main.cpp @@ -2,9 +2,10 @@ #include #include -#include "j6/signals.h" -#include "kernel_args.h" -#include "kernel_memory.h" +#include +#include +#include +#include #include "apic.h" #include "assert.h" @@ -54,7 +55,7 @@ void memory_initialize_pre_ctors(init::args &kargs); void memory_initialize_post_ctors(init::args &kargs); void load_init_server(init::program &program, uintptr_t modules_address); -unsigned start_aps(lapic &apic, const kutil::vector &ids, void *kpml4); +unsigned start_aps(lapic &apic, const util::vector &ids, void *kpml4); void init_console() @@ -190,7 +191,7 @@ kernel_main(init::args *args) } unsigned -start_aps(lapic &apic, const kutil::vector &ids, void *kpml4) +start_aps(lapic &apic, const util::vector &ids, void *kpml4) { using memory::frame_size; using memory::kernel_stack_pages; diff --git a/src/kernel/memory_bootstrap.cpp b/src/kernel/memory_bootstrap.cpp index f613b2c..4d17c16 100644 --- a/src/kernel/memory_bootstrap.cpp +++ b/src/kernel/memory_bootstrap.cpp @@ -1,10 +1,9 @@ #include -#include "kernel_args.h" -#include "j6/init.h" - -#include "enum_bitfields.h" -#include "kutil/no_construct.h" +#include +#include +#include +#include #include "assert.h" #include "device_manager.h" @@ -39,16 +38,16 @@ extern "C" uintptr_t initialize_main_user_stack(); // These objects are initialized _before_ global constructors are called, // so we don't want them to have global constructors at all, lest they // overwrite the previous initialization. -static kutil::no_construct __g_kernel_heap_storage; +static util::no_construct __g_kernel_heap_storage; heap_allocator &g_kernel_heap = __g_kernel_heap_storage.value; -static kutil::no_construct __g_frame_allocator_storage; +static util::no_construct __g_frame_allocator_storage; frame_allocator &g_frame_allocator = __g_frame_allocator_storage.value; -static kutil::no_construct __g_kernel_heap_area_storage; +static util::no_construct __g_kernel_heap_area_storage; vm_area_untracked &g_kernel_heap_area = __g_kernel_heap_area_storage.value; -static kutil::no_construct __g_kernel_stacks_storage; +static util::no_construct __g_kernel_stacks_storage; vm_area_guarded &g_kernel_stacks = __g_kernel_stacks_storage.value; vm_area_guarded g_kernel_buffers { diff --git a/src/kernel/objects/channel.h b/src/kernel/objects/channel.h index 40cb7b0..8c4001d 100644 --- a/src/kernel/objects/channel.h +++ b/src/kernel/objects/channel.h @@ -2,8 +2,9 @@ /// \file channel.h /// Definition of channel objects and related functions -#include "j6/signals.h" -#include "kutil/bip_buffer.h" +#include +#include + #include "objects/kobject.h" /// Channels are bi-directional means of sending messages @@ -45,5 +46,5 @@ protected: private: size_t m_len; uintptr_t m_data; - kutil::bip_buffer m_buffer; + util::bip_buffer m_buffer; }; diff --git a/src/kernel/objects/endpoint.h b/src/kernel/objects/endpoint.h index 16d8183..51cff5d 100644 --- a/src/kernel/objects/endpoint.h +++ b/src/kernel/objects/endpoint.h @@ -2,7 +2,9 @@ /// \file endpoint.h /// Definition of endpoint kobject types -#include "j6/signals.h" +#include +#include + #include "objects/kobject.h" /// Endpoints are objects that enable synchronous message-passing IPC @@ -64,5 +66,5 @@ private: j6_status_t do_message_copy(const thread_data &sender, thread_data &receiver); - kutil::vector m_blocked; + util::vector m_blocked; }; diff --git a/src/kernel/objects/kobject.cpp b/src/kernel/objects/kobject.cpp index d9ee5c6..fc111f8 100644 --- a/src/kernel/objects/kobject.cpp +++ b/src/kernel/objects/kobject.cpp @@ -1,6 +1,6 @@ -#include "j6/errors.h" -#include "j6/signals.h" -#include "j6/types.h" +#include +#include +#include #include "assert.h" #include "objects/kobject.h" diff --git a/src/kernel/objects/kobject.h b/src/kernel/objects/kobject.h index e9d3379..6dc4eed 100644 --- a/src/kernel/objects/kobject.h +++ b/src/kernel/objects/kobject.h @@ -2,10 +2,10 @@ /// \file kobject.h /// Definition of base type for user-interactable kernel objects -#include "j6/errors.h" -#include "j6/signals.h" -#include "j6/types.h" -#include "kutil/vector.h" +#include +#include +#include +#include class thread; @@ -17,7 +17,7 @@ public: enum class type : uint16_t { #define OBJECT_TYPE( name, val ) name = val, -#include "j6/tables/object_types.inc" +#include #undef OBJECT_TYPE max @@ -96,5 +96,5 @@ private: uint16_t m_handle_count; protected: - kutil::vector m_blocked_threads; + util::vector m_blocked_threads; }; diff --git a/src/kernel/objects/process.cpp b/src/kernel/objects/process.cpp index 37660a4..5203103 100644 --- a/src/kernel/objects/process.cpp +++ b/src/kernel/objects/process.cpp @@ -1,4 +1,4 @@ -#include "kutil/no_construct.h" +#include #include "assert.h" #include "cpu.h" @@ -10,7 +10,7 @@ // This object is initialized _before_ global constructors are called, // so we don't want it to have a global constructor at all, lest it // overwrite the previous initialization. -static kutil::no_construct __g_kernel_process_storage; +static util::no_construct __g_kernel_process_storage; process &g_kernel_process = __g_kernel_process_storage.value; diff --git a/src/kernel/objects/process.h b/src/kernel/objects/process.h index 7fcdf0c..406f4e1 100644 --- a/src/kernel/objects/process.h +++ b/src/kernel/objects/process.h @@ -2,8 +2,9 @@ /// \file process.h /// Definition of process kobject types -#include "kutil/map.h" -#include "kutil/vector.h" +#include +#include + #include "objects/kobject.h" #include "page_table.h" #include "vm_space.h" @@ -88,8 +89,8 @@ private: vm_space m_space; - kutil::vector m_threads; - kutil::map m_handles; + util::vector m_threads; + util::map m_handles; j6_handle_t m_next_handle; enum class state : uint8_t { running, exited }; diff --git a/src/kernel/objects/thread.cpp b/src/kernel/objects/thread.cpp index 7c5dac0..4e26dc2 100644 --- a/src/kernel/objects/thread.cpp +++ b/src/kernel/objects/thread.cpp @@ -1,4 +1,4 @@ -#include "j6/signals.h" +#include #include "cpu.h" #include "log.h" diff --git a/src/kernel/objects/thread.h b/src/kernel/objects/thread.h index 66910ea..39fbcc1 100644 --- a/src/kernel/objects/thread.h +++ b/src/kernel/objects/thread.h @@ -2,7 +2,8 @@ /// \file thread.h /// Definition of thread kobject types -#include "kutil/linked_list.h" +#include + #include "objects/kobject.h" struct page_table; @@ -29,7 +30,7 @@ struct TCB uint64_t last_ran; }; -using tcb_list = kutil::linked_list; +using tcb_list = util::linked_list; using tcb_node = tcb_list::item_type; class thread : diff --git a/src/kernel/objects/vm_area.h b/src/kernel/objects/vm_area.h index 43399aa..9a95100 100644 --- a/src/kernel/objects/vm_area.h +++ b/src/kernel/objects/vm_area.h @@ -5,9 +5,9 @@ #include #include -#include "enum_bitfields.h" -#include "j6/signals.h" -#include "kutil/vector.h" +#include +#include +#include #include "kernel_memory.h" #include "objects/kobject.h" @@ -18,7 +18,7 @@ class vm_space; enum class vm_flags : uint32_t { #define VM_FLAG(name, v) name = v, -#include "j6/tables/vm_flags.inc" +#include #undef VM_FLAG driver_mask = 0x000fffff, ///< flags allowed via syscall for drivers user_mask = 0x0000ffff, ///< flags allowed via syscall for non-drivers @@ -74,7 +74,7 @@ protected: size_t m_size; vm_flags m_flags; - kutil::vector m_spaces; + util::vector m_spaces; // Initial static space for m_spaces - most areas will never grow // beyond this size, so avoid allocations @@ -165,7 +165,7 @@ public: virtual bool get_page(uintptr_t offset, uintptr_t &phys) override; private: - kutil::vector m_cache; + util::vector m_cache; uintptr_t m_start; size_t m_pages; uintptr_t m_next; diff --git a/src/kernel/page_table.cpp b/src/kernel/page_table.cpp index 34c4825..96d963b 100644 --- a/src/kernel/page_table.cpp +++ b/src/kernel/page_table.cpp @@ -12,7 +12,7 @@ using level = page_table::level; free_page_header * page_table::s_page_cache = nullptr; size_t page_table::s_cache_count = 0; -kutil::spinlock page_table::s_lock; +util::spinlock page_table::s_lock; constexpr size_t page_table::entry_sizes[4]; @@ -180,7 +180,7 @@ page_table::get_table_page() free_page_header *page = nullptr; { - kutil::scoped_lock lock(s_lock); + util::scoped_lock lock(s_lock); if (!s_cache_count) fill_table_page_cache(); @@ -199,7 +199,7 @@ page_table::get_table_page() void page_table::free_table_page(page_table *pt) { - kutil::scoped_lock lock(s_lock); + util::scoped_lock lock(s_lock); free_page_header *page = reinterpret_cast(pt); page->next = s_page_cache; diff --git a/src/kernel/page_table.h b/src/kernel/page_table.h index 632e712..fec0077 100644 --- a/src/kernel/page_table.h +++ b/src/kernel/page_table.h @@ -3,9 +3,9 @@ /// Helper structures for dealing with page tables. #include -#include "enum_bitfields.h" -#include "kernel_memory.h" -#include "kutil/spinlock.h" +#include +#include +#include struct free_page_header; @@ -142,7 +142,7 @@ struct page_table static free_page_header *s_page_cache; ///< Cache of free pages to use for tables static size_t s_cache_count; ///< Number of pages in s_page_cache - static kutil::spinlock s_lock; ///< Lock for shared page cache + static util::spinlock s_lock; ///< Lock for shared page cache /// Get an entry in the page table as a page_table pointer /// \arg i Index of the entry in this page table diff --git a/src/kernel/panic.serial/serial.module b/src/kernel/panic.serial/serial.module index f15b0ac..4880e8f 100644 --- a/src/kernel/panic.serial/serial.module +++ b/src/kernel/panic.serial/serial.module @@ -4,7 +4,7 @@ panic = module("panic.serial", kind = "exe", output = "panic.serial.elf", targets = [ "kernel" ], - deps = [ "kutil", "elf", "kernel" ], + deps = [ "util", "elf", "kernel" ], sources = [ "display.cpp", "entry.s", diff --git a/src/kernel/scheduler.cpp b/src/kernel/scheduler.cpp index 46b032f..b900f27 100644 --- a/src/kernel/scheduler.cpp +++ b/src/kernel/scheduler.cpp @@ -1,6 +1,7 @@ #include #include +#include #include "apic.h" #include "assert.h" @@ -34,7 +35,7 @@ struct run_queue uint64_t last_promotion = 0; uint64_t last_steal = 0; - kutil::spinlock lock; + util::spinlock lock; }; scheduler::scheduler(unsigned cpus) : @@ -97,7 +98,7 @@ scheduler::start() run_queue &queue = m_run_queues[cpu.index]; { - kutil::scoped_lock lock {queue.lock}; + util::scoped_lock lock {queue.lock}; process *kp = &process::kernel_process(); thread *idle = thread::create_idle_thread(*kp, max_priority, cpu.rsp0); @@ -119,7 +120,7 @@ scheduler::add_thread(TCB *t) { cpu_data &cpu = current_cpu(); run_queue &queue = m_run_queues[cpu.index]; - kutil::scoped_lock lock {queue.lock}; + util::scoped_lock lock {queue.lock}; queue.blocked.push_back(static_cast(t)); t->time_left = quantum(t->priority); @@ -221,14 +222,14 @@ scheduler::steal_work(cpu_data &cpu) { // Lock this cpu's queue for the whole time while we modify it run_queue &my_queue = m_run_queues[cpu.index]; - kutil::scoped_lock my_queue_lock {my_queue.lock}; + util::scoped_lock my_queue_lock {my_queue.lock}; const unsigned count = m_run_queues.count(); for (unsigned i = 0; i < count; ++i) { if (i == cpu.index) continue; run_queue &other_queue = m_run_queues[i]; - kutil::scoped_lock other_queue_lock {other_queue.lock}; + util::scoped_lock other_queue_lock {other_queue.lock}; size_t stolen = 0; @@ -263,7 +264,7 @@ scheduler::schedule() // We need to explicitly lock/unlock here instead of // using a scoped lock, because the scope doesn't "end" // for the current thread until it gets scheduled again - kutil::spinlock::waiter waiter; + util::spinlock::waiter waiter; queue.lock.acquire(&waiter); queue.current->time_left = remaining; diff --git a/src/kernel/scheduler.h b/src/kernel/scheduler.h index 02674a1..1aeb5cb 100644 --- a/src/kernel/scheduler.h +++ b/src/kernel/scheduler.h @@ -3,8 +3,7 @@ /// The task scheduler and related definitions #include -#include "kutil/spinlock.h" -#include "kutil/vector.h" +#include namespace kernel { namespace args { @@ -92,7 +91,7 @@ private: process *m_kernel_process; - kutil::vector m_run_queues; + util::vector m_run_queues; // TODO: lol a real clock uint64_t m_clock = 0; diff --git a/src/kernel/serial.cpp b/src/kernel/serial.cpp index 2cf24ca..b1b5bfe 100644 --- a/src/kernel/serial.cpp +++ b/src/kernel/serial.cpp @@ -1,5 +1,5 @@ #include -#include "kutil/no_construct.h" +#include #include "assert.h" #include "interrupts.h" @@ -9,7 +9,7 @@ // This object is initialized _before_ global constructors are called, // so we don't want it to have global constructors at all, lest it // overwrite the previous initialization. -static kutil::no_construct __g_com1_storage; +static util::no_construct __g_com1_storage; serial_port &g_com1 = __g_com1_storage.value; constexpr size_t fifo_size = 64; diff --git a/src/kernel/serial.h b/src/kernel/serial.h index 03c80ed..99e6f27 100644 --- a/src/kernel/serial.h +++ b/src/kernel/serial.h @@ -3,7 +3,7 @@ /// Declarations related to serial ports. #include -#include "kutil/bip_buffer.h" +#include class serial_port { @@ -22,8 +22,8 @@ public: private: bool m_writing; uint16_t m_port; - kutil::bip_buffer m_out_buffer; - kutil::bip_buffer m_in_buffer; + util::bip_buffer m_out_buffer; + util::bip_buffer m_in_buffer; void do_read(); void do_write(); diff --git a/src/kernel/syscall.h.cog b/src/kernel/syscall.h.cog index 2169025..1506df9 100644 --- a/src/kernel/syscall.h.cog +++ b/src/kernel/syscall.h.cog @@ -2,7 +2,7 @@ // vim: ft=cpp #include -#include "j6/types.h" +#include struct cpu_state; diff --git a/src/kernel/syscalls/channel.cpp b/src/kernel/syscalls/channel.cpp index c98b7bf..44bcc5a 100644 --- a/src/kernel/syscalls/channel.cpp +++ b/src/kernel/syscalls/channel.cpp @@ -1,5 +1,5 @@ -#include "j6/errors.h" -#include "j6/types.h" +#include +#include #include "objects/channel.h" #include "syscalls/helpers.h" diff --git a/src/kernel/syscalls/endpoint.cpp b/src/kernel/syscalls/endpoint.cpp index 0dd0787..ee1b253 100644 --- a/src/kernel/syscalls/endpoint.cpp +++ b/src/kernel/syscalls/endpoint.cpp @@ -1,5 +1,5 @@ -#include "j6/errors.h" -#include "j6/types.h" +#include +#include #include "log.h" #include "objects/endpoint.h" diff --git a/src/kernel/syscalls/helpers.h b/src/kernel/syscalls/helpers.h index d96936a..59b2868 100644 --- a/src/kernel/syscalls/helpers.h +++ b/src/kernel/syscalls/helpers.h @@ -2,7 +2,8 @@ /// \file syscalls/helpers.h /// Utility functions for use in syscall handler implementations -#include "j6/types.h" +#include + #include "objects/kobject.h" #include "objects/process.h" diff --git a/src/kernel/syscalls/object.cpp b/src/kernel/syscalls/object.cpp index bfe51fe..42c5e36 100644 --- a/src/kernel/syscalls/object.cpp +++ b/src/kernel/syscalls/object.cpp @@ -1,6 +1,7 @@ -#include "j6/errors.h" -#include "j6/signals.h" -#include "j6/types.h" +#include +#include +#include +#include #include "assert.h" #include "log.h" @@ -50,7 +51,7 @@ kobject_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs) j6_status_t kobject_wait_many(j6_handle_t * handles, size_t handles_count, uint64_t mask, j6_handle_t * handle, uint64_t * signals) { - kutil::vector objects {uint32_t(handles_count)}; + util::vector objects {uint32_t(handles_count)}; for (unsigned i = 0; i < handles_count; ++i) { j6_handle_t h = handles[i]; diff --git a/src/kernel/syscalls/process.cpp b/src/kernel/syscalls/process.cpp index 4b498cb..bdc2437 100644 --- a/src/kernel/syscalls/process.cpp +++ b/src/kernel/syscalls/process.cpp @@ -1,5 +1,5 @@ -#include "j6/errors.h" -#include "j6/types.h" +#include +#include #include "log.h" #include "objects/process.h" diff --git a/src/kernel/syscalls/system.cpp b/src/kernel/syscalls/system.cpp index 5cdb730..ded323d 100644 --- a/src/kernel/syscalls/system.cpp +++ b/src/kernel/syscalls/system.cpp @@ -1,5 +1,5 @@ -#include "j6/errors.h" -#include "j6/types.h" +#include +#include #include "cpu.h" #include "device_manager.h" diff --git a/src/kernel/syscalls/thread.cpp b/src/kernel/syscalls/thread.cpp index 242c393..a844e26 100644 --- a/src/kernel/syscalls/thread.cpp +++ b/src/kernel/syscalls/thread.cpp @@ -1,5 +1,5 @@ -#include "j6/errors.h" -#include "j6/types.h" +#include +#include #include "log.h" #include "objects/process.h" diff --git a/src/kernel/syscalls/vm_area.cpp b/src/kernel/syscalls/vm_area.cpp index e75ee42..8c56cbd 100644 --- a/src/kernel/syscalls/vm_area.cpp +++ b/src/kernel/syscalls/vm_area.cpp @@ -1,6 +1,6 @@ -#include "j6/errors.h" -#include "j6/signals.h" -#include "j6/types.h" +#include +#include +#include #include "log.h" #include "objects/process.h" diff --git a/src/kernel/tss.cpp b/src/kernel/tss.cpp index 45e0897..bc711b4 100644 --- a/src/kernel/tss.cpp +++ b/src/kernel/tss.cpp @@ -1,5 +1,5 @@ #include -#include "kutil/no_construct.h" +#include #include "assert.h" #include "cpu.h" @@ -11,7 +11,7 @@ // The BSP's TSS is initialized _before_ global constructors are called, // so we don't want it to have a global constructor, lest it overwrite // the previous initialization. -static kutil::no_construct __g_bsp_tss_storage; +static util::no_construct __g_bsp_tss_storage; TSS &g_bsp_tss = __g_bsp_tss_storage.value; diff --git a/src/kernel/vm_space.cpp b/src/kernel/vm_space.cpp index e9166f4..a1908a3 100644 --- a/src/kernel/vm_space.cpp +++ b/src/kernel/vm_space.cpp @@ -170,7 +170,7 @@ void vm_space::page_in(const vm_area &vma, uintptr_t offset, uintptr_t phys, size_t count) { using memory::frame_size; - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; uintptr_t base = 0; if (!find_vma(vma, base)) @@ -198,7 +198,7 @@ void vm_space::clear(const vm_area &vma, uintptr_t offset, size_t count, bool free) { using memory::frame_size; - kutil::scoped_lock lock {m_lock}; + util::scoped_lock lock {m_lock}; uintptr_t base = 0; if (!find_vma(vma, base)) diff --git a/src/kernel/vm_space.h b/src/kernel/vm_space.h index c61ac8d..7c95812 100644 --- a/src/kernel/vm_space.h +++ b/src/kernel/vm_space.h @@ -3,9 +3,11 @@ /// Structure for tracking a range of virtual memory addresses #include -#include "enum_bitfields.h" -#include "kutil/spinlock.h" -#include "kutil/vector.h" + +#include +#include +#include + #include "page_table.h" class process; @@ -129,9 +131,9 @@ private: int compare(const struct area &o) const; bool operator==(const struct area &o) const; }; - kutil::vector m_areas; + util::vector m_areas; - kutil::spinlock m_lock; + util::spinlock m_lock; }; is_bitfield(vm_space::fault_type); diff --git a/src/libraries/kutil/bip_buffer.cpp b/src/libraries/util/bip_buffer.cpp similarity index 92% rename from src/libraries/kutil/bip_buffer.cpp rename to src/libraries/util/bip_buffer.cpp index 7e09d9c..5133252 100644 --- a/src/libraries/kutil/bip_buffer.cpp +++ b/src/libraries/util/bip_buffer.cpp @@ -4,9 +4,9 @@ #define assert(x) ((void)0) #endif -#include "kutil/bip_buffer.h" +#include -namespace kutil { +namespace util { bip_buffer::bip_buffer() : m_start_a(0), @@ -30,6 +30,8 @@ bip_buffer::bip_buffer(uint8_t *buffer, size_t size) : size_t bip_buffer::reserve(size_t size, void **area) { + scoped_lock lock {m_lock}; + if (m_size_r) { *area = nullptr; return 0; @@ -66,6 +68,8 @@ size_t bip_buffer::reserve(size_t size, void **area) void bip_buffer::commit(size_t size) { + scoped_lock lock {m_lock}; + assert(size <= m_size_r && "Tried to commit more than reserved"); if (m_start_r == m_start_a + m_size_a) { @@ -82,12 +86,16 @@ void bip_buffer::commit(size_t size) size_t bip_buffer::get_block(void **area) const { + scoped_lock lock {m_lock}; + *area = m_size_a ? &m_buffer[m_start_a] : nullptr; return m_size_a; } void bip_buffer::consume(size_t size) { + scoped_lock lock {m_lock}; + assert(size <= m_size_a && "Consumed more bytes than exist in A"); if (size >= m_size_a) { m_size_a = m_size_b; @@ -99,4 +107,4 @@ void bip_buffer::consume(size_t size) } } -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/bip_buffer.h b/src/libraries/util/include/util/bip_buffer.h similarity index 94% rename from src/libraries/kutil/include/kutil/bip_buffer.h rename to src/libraries/util/include/util/bip_buffer.h index c178cea..b5f3f26 100644 --- a/src/libraries/kutil/include/kutil/bip_buffer.h +++ b/src/libraries/util/include/util/bip_buffer.h @@ -6,7 +6,9 @@ #include #include -namespace kutil { +#include + +namespace util { class bip_buffer { @@ -52,8 +54,10 @@ private: size_t m_size_b; size_t m_size_r; + mutable spinlock m_lock; + const size_t m_buffer_size; uint8_t * const m_buffer; }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/constexpr_hash.h b/src/libraries/util/include/util/constexpr_hash.h similarity index 94% rename from src/libraries/kutil/include/kutil/constexpr_hash.h rename to src/libraries/util/include/util/constexpr_hash.h index 54caac7..12f99a7 100644 --- a/src/libraries/kutil/include/kutil/constexpr_hash.h +++ b/src/libraries/util/include/util/constexpr_hash.h @@ -5,7 +5,7 @@ #include #include -namespace kutil { +namespace util { constexpr static const uint8_t pearson_hash_table[256] = { 0x76,0x07,0xbe,0x47,0xcf,0x41,0x0a,0xe8,0x01,0x5c,0x9f,0xc5,0x24,0x63,0x9a,0x85, @@ -34,9 +34,9 @@ constexpr inline uint32_t djb_hash_32(const char *s, int off = 0) { return !s[off] ? 5381 : (djb_hash_32(s, off+1)*33) ^ s[off]; } -} // namespace kutil +} // namespace util constexpr inline uint8_t operator "" _h (const char *s, size_t len) { - return kutil::pearson_hash_8(s, static_cast(len & 0xff)); + return util::pearson_hash_8(s, static_cast(len & 0xff)); } diff --git a/src/libraries/kutil/include/kutil/hash.h b/src/libraries/util/include/util/hash.h similarity index 96% rename from src/libraries/kutil/include/kutil/hash.h rename to src/libraries/util/include/util/hash.h index 308e583..537401c 100644 --- a/src/libraries/kutil/include/kutil/hash.h +++ b/src/libraries/util/include/util/hash.h @@ -5,7 +5,7 @@ #include #include -namespace kutil { +namespace util { constexpr uint64_t fnv_64_prime = 0x100000001b3ull; constexpr uint64_t fnv1a_64_init = 0xcbf29ce484222325ull; @@ -40,4 +40,4 @@ inline uint64_t hash(const T &v) { template <> inline uint64_t hash(const uint64_t &i) { return i; } template <> inline uint64_t hash(const char * const &s) { return hash_string(s); } -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/linked_list.h b/src/libraries/util/include/util/linked_list.h similarity index 99% rename from src/libraries/kutil/include/kutil/linked_list.h rename to src/libraries/util/include/util/linked_list.h index 42425a1..e9ec0de 100644 --- a/src/libraries/kutil/include/kutil/linked_list.h +++ b/src/libraries/util/include/util/linked_list.h @@ -3,7 +3,7 @@ /// A generic templatized linked list. #include -namespace kutil { +namespace util { template class linked_list; @@ -346,4 +346,4 @@ private: }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/map.h b/src/libraries/util/include/util/map.h similarity index 98% rename from src/libraries/kutil/include/kutil/map.h rename to src/libraries/util/include/util/map.h index 170db54..8d49914 100644 --- a/src/libraries/kutil/include/kutil/map.h +++ b/src/libraries/util/include/util/map.h @@ -14,11 +14,12 @@ #include #include #include -#include "kutil/hash.h" -#include "kutil/vector.h" -#include "kutil/util.h" -namespace kutil { +#include +#include +#include + +namespace util { /// Templated equality check to allow overriding template @@ -290,4 +291,4 @@ public: } }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/misc.h b/src/libraries/util/include/util/misc.h similarity index 91% rename from src/libraries/kutil/include/kutil/misc.h rename to src/libraries/util/include/util/misc.h index e455e13..3e2fe63 100644 --- a/src/libraries/kutil/include/kutil/misc.h +++ b/src/libraries/util/include/util/misc.h @@ -1,6 +1,6 @@ #pragma once -namespace kutil { +namespace util { constexpr uint32_t byteswap(uint32_t x) diff --git a/src/libraries/kutil/include/kutil/no_construct.h b/src/libraries/util/include/util/no_construct.h similarity index 87% rename from src/libraries/kutil/include/kutil/no_construct.h rename to src/libraries/util/include/util/no_construct.h index 0c42595..b8f1988 100644 --- a/src/libraries/kutil/include/kutil/no_construct.h +++ b/src/libraries/util/include/util/no_construct.h @@ -2,7 +2,7 @@ /// \file no_construct.h /// Tools for creating objects witout running constructors -namespace kutil { +namespace util { /// Helper template for creating objects witout running constructors template @@ -13,4 +13,4 @@ union no_construct ~no_construct() {} }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/spinlock.h b/src/libraries/util/include/util/spinlock.h similarity index 94% rename from src/libraries/kutil/include/kutil/spinlock.h rename to src/libraries/util/include/util/spinlock.h index f174805..d9fc2d4 100644 --- a/src/libraries/kutil/include/kutil/spinlock.h +++ b/src/libraries/util/include/util/spinlock.h @@ -3,7 +3,7 @@ #pragma once -namespace kutil { +namespace util { /// An MCS based spinlock class spinlock @@ -43,4 +43,4 @@ private: spinlock::waiter m_waiter; }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/include/kutil/util.h b/src/libraries/util/include/util/util.h similarity index 77% rename from src/libraries/kutil/include/kutil/util.h rename to src/libraries/util/include/util/util.h index e1ecba8..f46c91a 100644 --- a/src/libraries/kutil/include/kutil/util.h +++ b/src/libraries/util/include/util/util.h @@ -1,10 +1,10 @@ #pragma once /// \file util.h -/// Utility functions used in other kutil code +/// Utility functions used in other util code #include -namespace kutil { +namespace util { // Get the base-2 logarithm of i inline unsigned log2(uint64_t i) { diff --git a/src/libraries/kutil/include/kutil/vector.h b/src/libraries/util/include/util/vector.h similarity index 99% rename from src/libraries/kutil/include/kutil/vector.h rename to src/libraries/util/include/util/vector.h index 866516e..c38f0af 100644 --- a/src/libraries/kutil/include/kutil/vector.h +++ b/src/libraries/util/include/util/vector.h @@ -5,9 +5,10 @@ #include #include #include -#include "kutil/util.h" -namespace kutil { +#include + +namespace util { /// A dynamic array. template @@ -292,4 +293,4 @@ private: T *m_elements; }; -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/spinlock.cpp b/src/libraries/util/spinlock.cpp similarity index 93% rename from src/libraries/kutil/spinlock.cpp rename to src/libraries/util/spinlock.cpp index c31b086..4b62c25 100644 --- a/src/libraries/kutil/spinlock.cpp +++ b/src/libraries/util/spinlock.cpp @@ -1,6 +1,6 @@ -#include "kutil/spinlock.h" +#include -namespace kutil { +namespace util { static constexpr int memorder = __ATOMIC_SEQ_CST; @@ -43,4 +43,4 @@ spinlock::release(waiter *w) } -} // namespace kutil +} // namespace util diff --git a/src/libraries/kutil/kutil.module b/src/libraries/util/util.module similarity index 89% rename from src/libraries/kutil/kutil.module rename to src/libraries/util/util.module index 67d816f..3979ff6 100644 --- a/src/libraries/kutil/kutil.module +++ b/src/libraries/util/util.module @@ -1,6 +1,6 @@ # vim: ft=python -module("kutil", +module("util", kind = "lib", includes = [ "include" ], sources = [ diff --git a/src/user/drv.uefi_fb/main.cpp b/src/user/drv.uefi_fb/main.cpp index 33f4e7b..409f902 100644 --- a/src/user/drv.uefi_fb/main.cpp +++ b/src/user/drv.uefi_fb/main.cpp @@ -2,12 +2,12 @@ #include #include -#include "j6/init.h" -#include "j6/errors.h" -#include "j6/flags.h" -#include "j6/signals.h" -#include "j6/syscalls.h" -#include "j6/types.h" +#include +#include +#include +#include +#include +#include #include "font.h" #include "screen.h" diff --git a/src/user/srv.init/loader.cpp b/src/user/srv.init/loader.cpp index 34193fd..e5d40dc 100644 --- a/src/user/srv.init/loader.cpp +++ b/src/user/srv.init/loader.cpp @@ -1,12 +1,13 @@ #include #include -#include "enum_bitfields.h" -#include "elf/file.h" -#include "elf/headers.h" -#include "j6/errors.h" -#include "j6/flags.h" -#include "j6/syscalls.h" -#include "init_args.h" + +#include +#include +#include +#include +#include +#include +#include using kernel::init::module_flags; using kernel::init::module_program; diff --git a/src/user/srv.init/main.cpp b/src/user/srv.init/main.cpp index adf74d7..7cb1635 100644 --- a/src/user/srv.init/main.cpp +++ b/src/user/srv.init/main.cpp @@ -1,6 +1,7 @@ #include -#include "init_args.h" -#include "j6/syscalls.h" + +#include +#include #include "loader.h" #include "modules.h" diff --git a/src/user/srv.init/modules.cpp b/src/user/srv.init/modules.cpp index 349e67b..e5c8873 100644 --- a/src/user/srv.init/modules.cpp +++ b/src/user/srv.init/modules.cpp @@ -1,8 +1,8 @@ #include #include -#include "j6/errors.h" -#include "j6/syscalls.h" +#include +#include #include "modules.h" diff --git a/src/user/srv.init/modules.h b/src/user/srv.init/modules.h index e3bfa0b..62c4ea0 100644 --- a/src/user/srv.init/modules.h +++ b/src/user/srv.init/modules.h @@ -2,9 +2,9 @@ /// \file modules.h /// Routines for loading initial argument modules -#include "j6/types.h" -#include "init_args.h" -#include "pointer_manipulation.h" +#include +#include +#include class module_iterator diff --git a/src/user/testapp/main.cpp b/src/user/testapp/main.cpp index 4cfd24b..65a05c4 100644 --- a/src/user/testapp/main.cpp +++ b/src/user/testapp/main.cpp @@ -1,11 +1,11 @@ #include #include -#include "j6/types.h" -#include "j6/errors.h" -#include "j6/flags.h" -#include "j6/signals.h" -#include "j6/syscalls.h" +#include +#include +#include +#include +#include #include "io.h" #include "serial.h"