From 9ff6bf983a40ae30472962343036a5b6d9d00e25 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 3 Sep 2026 21:02:08 +0200 Subject: x86_64/cpu: fix GDT size calculation The GDT pointer already receives the size in bytes when the GDT constructs it to activate the new GDT. Previously, the size in bytes got multiplied by the size of a single segment_descriptor before performing the mandatory subtraction of one. This means that the CPU lived in the believe that the GDT had a size of 448 bytes, instead of the true 56. Additionally, the calculation was flawed in another way, revealing the reason for why the size in bytes was passed to global_descriptor_table_pointer in the first place: it assumes that all entries in the GDT are of the same size. However, system descriptors are larger than basic segment descriptors. --- arch/x86_64/arch/cpu/global_descriptor_table.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/global_descriptor_table.hpp b/arch/x86_64/arch/cpu/global_descriptor_table.hpp index e485d65c..986dd566 100644 --- a/arch/x86_64/arch/cpu/global_descriptor_table.hpp +++ b/arch/x86_64/arch/cpu/global_descriptor_table.hpp @@ -23,7 +23,7 @@ namespace arch::cpu { template global_descriptor_table_pointer(global_descriptor_table const & gdt) - : size{GdtSize * sizeof(segment_descriptor) - 1} + : size{GdtSize - 1} , address{kapi::memory::physical_address{std::bit_cast(&gdt)}.raw()} {} -- cgit v1.2.3 From 041ae23d5d952f134533443b508b1287af2357d3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 3 Sep 2026 21:05:48 +0200 Subject: x86_64/cpu: reload the task register When execution enters the kernel, no specific task register state has been established, leaving the power-on state of the CPU itself active. We have no control over that state, ergo we need to reload the task register to point to descriptor under our control. The earliest point when we can do that is after the new global descriptor table has been loaded. Thus this is the exact point where we do that. Additionally, reloading the TR has unveiled another latent bug that was present since the early days of the CPU initialization code: The TSS descriptor was actually incorrect. The reason for this not having been revealed earlier, is that the CPU was quietly using the TR set up by by its own power-on bootstrap. Once a load with the existing, non-TSS, descriptor was issued, A #GP was triggered because the CPU detected that the referenced TSS descriptor is not in fact a TSS descriptor (subtype 0x9): ----- BEGIN EXCEPTION DUMP ----- check_exception old: 0xffffffff new 0xd 0: v=0d e=0028 i=0 cpl=0 IP=0008:ffffffff80281b12 pc=ffffffff80281b12 SP=0010:ffffffff80216390 env->regs[R_EAX]=0000000000000028 RAX=0000000000000028 RBX=0000000000000000 RCX=ffffffff80216100 RDX=ffffffff8010fca0 RSI=0000000000000050 RDI=ffffffff80216260 RBP=ffffffff802163d0 RSP=ffffffff80216390 R8 =ffffffff802160f7 R9 =ffffffff80115328 R10=ffffffff8021626c R11=0000000000000000 R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000 RIP=ffffffff80281b12 RFL=00000092 [--S-A--] CPL=0 II=0 A20=1 SMM=0 HLT=0 ES =0010 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA] CS =0008 0000000000000000 ffffffff 00af9800 DPL=0 CS64 [---] SS =0010 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA] DS =0010 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA] FS =0010 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA] GS =0010 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA] LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy GDT= ffffffff801154e0 000001bf IDT= 0000000000000000 00000000 CR0=80000013 CR2=0000000000000000 CR3=0000000000102000 CR4=00000620 DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 DR6=00000000ffff0ff0 DR7=0000000000000400 CCS=0000000000000090 CCD=ffffffff802161f8 CCO=EFLAGS EFER=0000000000000500 ----- END EXCEPTION DUMP ----- Decoding the e= value of the exception shows that the #GP occurred while the CPU was trying to process index 5 of the GDT (bits 3-15 define the index, with e=0028 being 0000'0000'0010'1000 => index 5). The layout of a system segment descriptor differs from a normal segment descriptor in that the accessed, read/write, conforming, and executable bits change their meaning into a 4-bit subtype number. For a TSS descriptor, this subtype number must be 9. In the future, the data structures of the GDT implementation should be revised to ensure this kind of misconfiguration can not happen again. --- arch/x86_64/arch/cpu/initialization.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/initialization.cpp b/arch/x86_64/arch/cpu/initialization.cpp index 83493fe3..67bc2a4d 100644 --- a/arch/x86_64/arch/cpu/initialization.cpp +++ b/arch/x86_64/arch/cpu/initialization.cpp @@ -95,10 +95,10 @@ namespace arch::cpu { .limit_low = limit & 0xffff, // NOLINT(readability-magic-numbers) .base_low = address & 0xffffff, // NOLINT(readability-magic-numbers) - .accessed = false, + .accessed = true, .read_write = false, .direction_or_conforming = false, - .executable = false, + .executable = true, .type = segment_type::system, .privilege_level = 0, .present = true, @@ -126,6 +126,10 @@ namespace arch::cpu kstd::println("[ARCH:SYS] Reloading Global Descriptor Table."); gdt.load(1, 2); + kstd::println("[ARCH:SYS] Loading the Task Register."); + auto const tss_selector_offset = static_cast(5 * sizeof(segment_descriptor)); + asm volatile("ltr %0" : : "r"(tss_selector_offset)); + kstd::println("[ARCH:SYS] Initializing Interrupt Descriptor Table."); auto static idt = interrupt_descriptor_table{}; idt.load(); -- cgit v1.2.3 From aee4582fb5144e1dd493041a8d1fc0c08146a622 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 18:14:16 +0200 Subject: x86_64/cpu: isolate kernel and IST1 stack Previously, the kernel stack was allocated inside the .kernel_bss section, along other uninitialized data. While this works, it assumes that the section will always be laid out with the kernel stack at the top. If that is not the case, the allocated guard page before .kernel_bss would not trigger a #PF since out-of-bounds (overflow) access would quietly overwrite other data in the section, thus potentially corrupting global kernel data. At the same time, there was no separate section (and guard page) for the future #DF exception stack (IST1 in our case). Thus we allocate a section, and a guard page, while we are already modifying the linker script. --- arch/x86_64/scripts/kernel.ld | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld index e6ae3425..8cd6c1c3 100644 --- a/arch/x86_64/scripts/kernel.ld +++ b/arch/x86_64/scripts/kernel.ld @@ -98,9 +98,21 @@ SECTIONS . += 4K; + .kernel_stack ALIGN(4K) : AT (ADDR (.kernel_stack) - TEACHOS_VMA) + { + *(.stack) + } :kernel_data + + . += 4K; + + .kernel_ist1_stack ALIGN(4K) : AT (ADDR (.kernel_ist1_stack) - TEACHOS_VMA) + { + *(.ist1_stack) + } :kernel_data + .kernel_bss ALIGN(4K) : AT (ADDR (.kernel_bss) - TEACHOS_VMA) { - *(.stack .bss*) + *(.bss*) } :kernel_data .kernel_text ALIGN(4K) : AT(ADDR (.kernel_text) - TEACHOS_VMA) -- cgit v1.2.3 From a5848c037e6e681d586312ddddddd200b9f7a5b0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 20:24:06 +0200 Subject: x86_64/cpu: use IST1 as the stack for #DF --- arch/x86_64/arch/cpu/initialization.cpp | 20 +++++++++++++++++++- arch/x86_64/arch/cpu/interrupts.cpp | 4 +++- arch/x86_64/arch/cpu/task_state_segment.hpp | 21 +++++++++++---------- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/initialization.cpp b/arch/x86_64/arch/cpu/initialization.cpp index 67bc2a4d..be1cc9f8 100644 --- a/arch/x86_64/arch/cpu/initialization.cpp +++ b/arch/x86_64/arch/cpu/initialization.cpp @@ -8,7 +8,9 @@ #include +#include #include +#include #include namespace arch::cpu @@ -111,11 +113,27 @@ namespace arch::cpu (address >> 32) & 0xffff'ffff, // NOLINT(readability-magic-numbers) }; } + + [[gnu::section(".ist1_stack")]] auto constinit ist1_stack = std::array{}; + + auto constinit tss = task_state_segment{ + .rsp0 = nullptr, + .rsp1 = nullptr, + .rsp2 = nullptr, + .ist1 = ist1_stack.data() + ist1_stack.size(), + .ist2 = nullptr, + .ist3 = nullptr, + .ist4 = nullptr, + .ist5 = nullptr, + .ist6 = nullptr, + .ist7 = nullptr, + .io_map_base_address = 0, + }; + } // namespace auto initialize_descriptors() -> void { - auto static tss = task_state_segment{}; auto static tss_descriptor = make_tss_descriptor(&tss); auto static gdt = global_descriptor_table{ diff --git a/arch/x86_64/arch/cpu/interrupts.cpp b/arch/x86_64/arch/cpu/interrupts.cpp index 2fdc4671..cf225a90 100644 --- a/arch/x86_64/arch/cpu/interrupts.cpp +++ b/arch/x86_64/arch/cpu/interrupts.cpp @@ -167,10 +167,12 @@ namespace arch::cpu { for (auto i = 0uz; i < 256; ++i) { + auto ist_selector = static_cast(i == 8 ? 1 : 0); + m_descriptors[i] = gate_descriptor{ .offset_low = static_cast(isr_stub_table[i] & 0xffff), // NOLINT(readability-magic-numbers) .m_code_segment = segment_selector{0, false, 1}, - .interrupt_stack_table_selector = 0, + .interrupt_stack_table_selector = ist_selector, .gate_type = (i < 32 && i != 2) ? gate_type::trap_gate : gate_type::interrupt_gate, .descriptor_privilege_level = 0, .present = true, diff --git a/arch/x86_64/arch/cpu/task_state_segment.hpp b/arch/x86_64/arch/cpu/task_state_segment.hpp index ab141f4c..f8b257d4 100644 --- a/arch/x86_64/arch/cpu/task_state_segment.hpp +++ b/arch/x86_64/arch/cpu/task_state_segment.hpp @@ -1,6 +1,7 @@ #ifndef TEACHOS_ARCH_X86_64_TASK_STATE_SEGMENT_HPP #define TEACHOS_ARCH_X86_64_TASK_STATE_SEGMENT_HPP +#include #include namespace arch::cpu @@ -9,17 +10,17 @@ namespace arch::cpu struct [[gnu::packed]] task_state_segment { std::uint32_t : 32; - std::uint64_t rsp0 = {}; - std::uint64_t rsp1 = {}; - std::uint64_t rsp2 = {}; + std::byte * rsp0 = {}; + std::byte * rsp1 = {}; + std::byte * rsp2 = {}; std::uint64_t : 64; - std::uint64_t ist1 = {}; - std::uint64_t ist2 = {}; - std::uint64_t ist3 = {}; - std::uint64_t ist4 = {}; - std::uint64_t ist5 = {}; - std::uint64_t ist6 = {}; - std::uint64_t ist7 = {}; + std::byte * ist1 = {}; + std::byte * ist2 = {}; + std::byte * ist3 = {}; + std::byte * ist4 = {}; + std::byte * ist5 = {}; + std::byte * ist6 = {}; + std::byte * ist7 = {}; std::uint64_t : 64; std::uint16_t : 16; std::uint16_t io_map_base_address = {}; -- cgit v1.2.3 From f00223b5cc99a8f3f1b6a15658d8c854c177932a Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 20:25:14 +0200 Subject: x86_64/cpu: handle #DF inside the arch code A double fault is a very x86-64 specific type of exception and not recoverable in a generalized way. Thus we should handle it internally, with handling currently being triggering a panic, and not forward it to the architecture-independent kernel layer. --- arch/x86_64/arch/cpu/interrupts.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/interrupts.cpp b/arch/x86_64/arch/cpu/interrupts.cpp index cf225a90..94806621 100644 --- a/arch/x86_64/arch/cpu/interrupts.cpp +++ b/arch/x86_64/arch/cpu/interrupts.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -124,6 +125,12 @@ namespace arch::cpu } pic_master_control_port::write(pic_end_of_interrupt); } + + auto handle_double_fault(interrupt_frame * frame) -> void + { + kapi::system::panic("[ARCH:CPU] Double fault! Possible kernel stack corruption! rsp was {}", + frame->cpu_saved.rsp); + } } // namespace extern "C" @@ -134,7 +141,11 @@ namespace arch::cpu { auto [number, code] = frame->interrupt; - if (number < number_of_exception_vectors) + if (number == static_cast(exception::double_fault)) + { + handle_double_fault(frame); + } + else if (number < number_of_exception_vectors) { if (!dispatch_exception(frame)) { -- cgit v1.2.3 From c6d5c461ff8ec1d8361c477a4318491755a24235 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 21:04:24 +0200 Subject: x86_64/boot: reduce kernel stack size to 8 KiB --- arch/x86_64/arch/boot/entry64.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/x86_64/arch/boot/entry64.s b/arch/x86_64/arch/boot/entry64.s index 29fb778d..d08276c0 100644 --- a/arch/x86_64/arch/boot/entry64.s +++ b/arch/x86_64/arch/boot/entry64.s @@ -2,7 +2,7 @@ .align 16 .global stack_top -stack_bottom: .skip 1 << 20 +stack_bottom: .skip 1 << 13 stack_top: stack_size = stack_top - stack_bottom -- cgit v1.2.3 From ccd0a1ca865d3b640f902945df84bb2be388a755 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 4 Sep 2026 22:10:44 +0200 Subject: x86_64/cpu: fix asm input constraint The "X" constraint tells GCC that any operand whatsoever is valid to be placed in the assembler template. This makes no sense in this case, since that would allow for the exact expression to be inserted. If that happens, which it does when `-Og` is active, GCC is unable to assemble that template. The correct constraint is forcing the value into a register. --- arch/x86_64/arch/cpu/global_descriptor_table.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/global_descriptor_table.hpp b/arch/x86_64/arch/cpu/global_descriptor_table.hpp index 986dd566..0bd7677d 100644 --- a/arch/x86_64/arch/cpu/global_descriptor_table.hpp +++ b/arch/x86_64/arch/cpu/global_descriptor_table.hpp @@ -73,8 +73,8 @@ namespace arch::cpu "mov %%rax, %%fs\n" "mov %%rax, %%gs\n" : - : "X"(code_segment_index * sizeof(segment_descriptor)), - "X"(data_segment_index * sizeof(segment_descriptor)) + : "r"(code_segment_index * sizeof(segment_descriptor)), + "r"(data_segment_index * sizeof(segment_descriptor)) : "rax"); } -- cgit v1.2.3 From 3eb72bb6bc7446df3e34bd990cb84a0b8178b9cd Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 5 Sep 2026 11:18:38 +0200 Subject: x86_64/cpu: improve stack overflow detection --- arch/x86_64/arch/cpu/interrupts.cpp | 29 +++++++++++++++++++++++++++-- arch/x86_64/scripts/kernel.ld | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/arch/cpu/interrupts.cpp b/arch/x86_64/arch/cpu/interrupts.cpp index 94806621..f27c3a2e 100644 --- a/arch/x86_64/arch/cpu/interrupts.cpp +++ b/arch/x86_64/arch/cpu/interrupts.cpp @@ -9,7 +9,9 @@ #include #include +#include +#include #include namespace arch::cpu @@ -17,6 +19,9 @@ namespace arch::cpu namespace { + extern "C" std::byte __kernel_stack_bottom[]; // NOLINT(readability-identifier-naming) + extern "C" std::byte __ist1_stack_bottom[]; // NOLINT(readability-identifier-naming) + enum struct exception { divide_error, @@ -128,8 +133,28 @@ namespace arch::cpu auto handle_double_fault(interrupt_frame * frame) -> void { - kapi::system::panic("[ARCH:CPU] Double fault! Possible kernel stack corruption! rsp was {}", - frame->cpu_saved.rsp); + auto const rsp = frame->cpu_saved.rsp; + auto const rip = frame->cpu_saved.rip; + auto const kernel_stack_bottom = kapi::memory::linear_address{__kernel_stack_bottom}; + auto const ist1_stack_bottom = kapi::memory::linear_address{__ist1_stack_bottom}; + + auto const overflowed_kernel = rsp < kernel_stack_bottom && rsp >= kernel_stack_bottom - kapi::memory::page::size; + auto const overflowed_ist1 = rsp < ist1_stack_bottom && rsp >= ist1_stack_bottom - kapi::memory::page::size; + + if (overflowed_kernel || overflowed_ist1) + { + auto const overflowed_what = overflowed_kernel ? "kernel" : "ist1"; + auto const overflowed_by = + kstd::bytes{static_cast((overflowed_kernel ? kernel_stack_bottom : ist1_stack_bottom) - rsp)}; + + kapi::system::panic("[ARCH:CPU] Suspected {} stack overflow: \n" // + "\toverflowed by: {:#}\n" // + "\trsp: {}\n" // + "\trip: {}\n", // + overflowed_what, overflowed_by, rsp, rip); + } + + kapi::system::panic("[ARCH:CPU] Double fault at {}", rip); } } // namespace diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld index 8cd6c1c3..f96152d7 100644 --- a/arch/x86_64/scripts/kernel.ld +++ b/arch/x86_64/scripts/kernel.ld @@ -100,6 +100,7 @@ SECTIONS .kernel_stack ALIGN(4K) : AT (ADDR (.kernel_stack) - TEACHOS_VMA) { + PROVIDE_HIDDEN(__kernel_stack_bottom = .); *(.stack) } :kernel_data @@ -107,6 +108,7 @@ SECTIONS .kernel_ist1_stack ALIGN(4K) : AT (ADDR (.kernel_ist1_stack) - TEACHOS_VMA) { + PROVIDE_HIDDEN(__ist1_stack_bottom = .); *(.ist1_stack) } :kernel_data -- cgit v1.2.3 From c0b2173d6b6c4587d1df3e8ea992ee19c9ff4418 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 5 Sep 2026 11:27:44 +0200 Subject: x86_64: stop loading uninitialized data --- arch/x86_64/scripts/kernel.ld | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld index f96152d7..3b2fd898 100644 --- a/arch/x86_64/scripts/kernel.ld +++ b/arch/x86_64/scripts/kernel.ld @@ -52,7 +52,7 @@ SECTIONS PROVIDE_HIDDEN(__init_array_end = .); } :boot_data - .boot_bss ALIGN(4K) : + .boot_bss ALIGN(4K) (NOLOAD) : { KEEP(*(.boot_stack .boot_bss*)) } :boot_data @@ -98,7 +98,7 @@ SECTIONS . += 4K; - .kernel_stack ALIGN(4K) : AT (ADDR (.kernel_stack) - TEACHOS_VMA) + .kernel_stack ALIGN(4K) (NOLOAD) : AT (ADDR (.kernel_stack) - TEACHOS_VMA) { PROVIDE_HIDDEN(__kernel_stack_bottom = .); *(.stack) @@ -106,13 +106,13 @@ SECTIONS . += 4K; - .kernel_ist1_stack ALIGN(4K) : AT (ADDR (.kernel_ist1_stack) - TEACHOS_VMA) + .kernel_ist1_stack ALIGN(4K) (NOLOAD) : AT (ADDR (.kernel_ist1_stack) - TEACHOS_VMA) { PROVIDE_HIDDEN(__ist1_stack_bottom = .); *(.ist1_stack) } :kernel_data - .kernel_bss ALIGN(4K) : AT (ADDR (.kernel_bss) - TEACHOS_VMA) + .kernel_bss ALIGN(4K) (NOLOAD) : AT (ADDR (.kernel_bss) - TEACHOS_VMA) { *(.bss*) } :kernel_data @@ -138,7 +138,7 @@ SECTIONS . += 4K; - .user_bss ALIGN(4K) : AT(ADDR (.user_bss) - TEACHOS_VMA) + .user_bss ALIGN(4K) (NOLOAD) : AT(ADDR (.user_bss) - TEACHOS_VMA) { KEEP(*(.user_bss*)) } :user_data -- cgit v1.2.3 From 9f544dea5dbcdb92f614c6092a60e81d3398b8da Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 5 Sep 2026 13:19:25 +0200 Subject: build: enable strong stack protector --- arch/x86_64/arch/boot/initialize_runtime.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'arch') diff --git a/arch/x86_64/arch/boot/initialize_runtime.cpp b/arch/x86_64/arch/boot/initialize_runtime.cpp index e548f4a1..ad2fa205 100644 --- a/arch/x86_64/arch/boot/initialize_runtime.cpp +++ b/arch/x86_64/arch/boot/initialize_runtime.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -12,6 +14,15 @@ namespace arch::boot // NOLINTBEGIN(readability-identifier-naming) extern global_initializer __init_array_start; extern global_initializer __init_array_end; + + [[gnu::used]] + constinit auto __stack_chk_guard = 0xcafe'face'1ee7'8ee7; // NOLINT(readability-magic-numbers) + + [[noreturn]] + auto __stack_chk_fail() -> void + { + kapi::system::panic("Stack smashing detected!"); + } // NOLINTEND(readability-identifier-naming) auto invoke_global_constructors() -> void -- cgit v1.2.3 From b99b79d8080cc1491f96069677d9ce0b7775a4f0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 9 Sep 2026 23:02:20 +0200 Subject: chore: replace some naked pointers The coding guidelines explicitly prohibit the use of "naked"/C-style pointers. However, there were some prominent examples in the kapi and the core kernel source. This changeset replaces them with the appropriate smart pointer types. --- arch/x86_64/arch/devices/cpu/core.cpp | 5 +++-- arch/x86_64/arch/devices/cpu/core.hpp | 4 +++- arch/x86_64/arch/devices/cpu/lapic.cpp | 5 +++-- arch/x86_64/arch/devices/cpu/lapic.hpp | 4 +++- arch/x86_64/arch/devices/pit.cpp | 6 ++++-- arch/x86_64/arch/devices/pit.hpp | 4 +++- arch/x86_64/arch/drivers/cpu/lapic.cpp | 10 +++++----- arch/x86_64/arch/drivers/cpu/lapic.hpp | 3 ++- arch/x86_64/arch/drivers/pit.cpp | 4 ++-- arch/x86_64/arch/drivers/pit.hpp | 2 +- 10 files changed, 29 insertions(+), 18 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/arch/devices/cpu/core.cpp b/arch/x86_64/arch/devices/cpu/core.cpp index ac06850e..13d4652d 100644 --- a/arch/x86_64/arch/devices/cpu/core.cpp +++ b/arch/x86_64/arch/devices/cpu/core.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -29,11 +30,11 @@ namespace arch::devices::cpu return m_id; } - auto core::query_facet(kapi::capabilities::facet_id facet) -> void * + auto core::query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr { if (facet == bus::core_signature::id) { - return static_cast(this); + return kstd::make_observer(this); } return device::query_facet(facet); diff --git a/arch/x86_64/arch/devices/cpu/core.hpp b/arch/x86_64/arch/devices/cpu/core.hpp index cd5ac65c..ad965da1 100644 --- a/arch/x86_64/arch/devices/cpu/core.hpp +++ b/arch/x86_64/arch/devices/cpu/core.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include #include @@ -20,7 +22,7 @@ namespace arch::devices::cpu [[nodiscard]] auto hardware_id() const noexcept -> std::uint64_t override; protected: - auto query_facet(kapi::capabilities::facet_id facet) -> void * override; + auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr override; private: std::uint64_t m_id; diff --git a/arch/x86_64/arch/devices/cpu/lapic.cpp b/arch/x86_64/arch/devices/cpu/lapic.cpp index 280ebbca..d8571a8f 100644 --- a/arch/x86_64/arch/devices/cpu/lapic.cpp +++ b/arch/x86_64/arch/devices/cpu/lapic.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -29,11 +30,11 @@ namespace arch::devices::cpu return m_is_bsp; } - auto lapic::query_facet(kapi::capabilities::facet_id facet) -> void * + auto lapic::query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr { if (facet == bus::lapic_signature::id) { - return static_cast(this); + return kstd::make_observer(this); } return device::query_facet(facet); diff --git a/arch/x86_64/arch/devices/cpu/lapic.hpp b/arch/x86_64/arch/devices/cpu/lapic.hpp index 52ae40ae..3f91968e 100644 --- a/arch/x86_64/arch/devices/cpu/lapic.hpp +++ b/arch/x86_64/arch/devices/cpu/lapic.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include #include @@ -20,7 +22,7 @@ namespace arch::devices::cpu [[nodiscard]] auto is_bsp() const noexcept -> bool override; protected: - auto query_facet(kapi::capabilities::facet_id facet) -> void * override; + auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr override; private: std::uint64_t m_id; diff --git a/arch/x86_64/arch/devices/pit.cpp b/arch/x86_64/arch/devices/pit.cpp index 83443c93..6de23865 100644 --- a/arch/x86_64/arch/devices/pit.cpp +++ b/arch/x86_64/arch/devices/pit.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include namespace arch::devices @@ -19,11 +21,11 @@ namespace arch::devices return "pit"; } - auto pit::query_facet(kapi::capabilities::facet_id facet) -> void * + auto pit::query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr { if (facet == arch::bus::isa_signature::id) { - return static_cast(this); + return kstd::make_observer(this); } return kapi::devices::device::query_facet(facet); diff --git a/arch/x86_64/arch/devices/pit.hpp b/arch/x86_64/arch/devices/pit.hpp index 08bf423a..ddd6d8a3 100644 --- a/arch/x86_64/arch/devices/pit.hpp +++ b/arch/x86_64/arch/devices/pit.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include namespace arch::devices @@ -25,7 +27,7 @@ namespace arch::devices [[nodiscard]] auto isa_name() const -> std::string_view override; protected: - auto query_facet(kapi::capabilities::facet_id facet) -> void * override; + auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr override; }; } // namespace arch::devices diff --git a/arch/x86_64/arch/drivers/cpu/lapic.cpp b/arch/x86_64/arch/drivers/cpu/lapic.cpp index c02c3df6..3b7c2d45 100644 --- a/arch/x86_64/arch/drivers/cpu/lapic.cpp +++ b/arch/x86_64/arch/drivers/cpu/lapic.cpp @@ -104,7 +104,7 @@ namespace arch::drivers::cpu auto lapic::probe(kapi::devices::device & device) -> kstd::result { - auto * signature = device.facet(); + auto const signature = device.facet(); if (!signature) { return kstd::failure(make_error_code(kstd::errc::invalid_argument)); @@ -142,8 +142,8 @@ namespace arch::drivers::cpu write_register(registers::spurious_interrupt_vector, lapic_enable_bit | spurious_interrupt_vector); - kstd::println("[ARCH:DRV] LAPIC initialized. version: {#x} | max_lvt_entry: {} | eoi_suppression: {:s}", - version, highest_lvt_entry_index, supports_eoi_broadcast_suppression); + kstd::println("[ARCH:DRV] LAPIC initialized. version: {#x} | max_lvt_entry: {} | eoi_suppression: {:s}", version, + highest_lvt_entry_index, supports_eoi_broadcast_suppression); } else { @@ -172,11 +172,11 @@ namespace arch::drivers::cpu *reg = value; } - auto lapic::query_facet(kapi::capabilities::facet_id facet) -> void * + auto lapic::query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr { if (facet == arch::bus::lapic_claim::id) { - return static_cast(this); + return kstd::make_observer(this); } return kapi::devices::driver::query_facet(facet); diff --git a/arch/x86_64/arch/drivers/cpu/lapic.hpp b/arch/x86_64/arch/drivers/cpu/lapic.hpp index 678d364a..52533d9a 100644 --- a/arch/x86_64/arch/drivers/cpu/lapic.hpp +++ b/arch/x86_64/arch/drivers/cpu/lapic.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -27,7 +28,7 @@ namespace arch::drivers::cpu [[nodiscard]] auto name() const noexcept -> std::string_view override; protected: - auto query_facet(kapi::capabilities::facet_id facet) -> void * override; + auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr override; private: enum struct registers : std::ptrdiff_t; diff --git a/arch/x86_64/arch/drivers/pit.cpp b/arch/x86_64/arch/drivers/pit.cpp index e6e98796..6a768fc9 100644 --- a/arch/x86_64/arch/drivers/pit.cpp +++ b/arch/x86_64/arch/drivers/pit.cpp @@ -124,11 +124,11 @@ namespace arch::drivers return kapi::interrupts::status::handled; } - auto pit::query_facet(kapi::capabilities::facet_id facet) -> void * + auto pit::query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr { if (facet == arch::bus::isa_claim::id) { - return static_cast(this); + return kstd::make_observer(this); } return kapi::devices::driver::query_facet(facet); diff --git a/arch/x86_64/arch/drivers/pit.hpp b/arch/x86_64/arch/drivers/pit.hpp index ad8add4b..f5be5a17 100644 --- a/arch/x86_64/arch/drivers/pit.hpp +++ b/arch/x86_64/arch/drivers/pit.hpp @@ -33,7 +33,7 @@ namespace arch::drivers [[nodiscard]] auto name() const noexcept -> std::string_view override; protected: - auto query_facet(kapi::capabilities::facet_id facet) -> void * override; + auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr override; private: struct data -- cgit v1.2.3