1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 18:47:44 +00:00

Kernel/riscv64: Make the kernel compile

This commits inserts TODOs into all necessary places to make the kernel
compile on riscv64!
This commit is contained in:
Sönke Holz 2023-11-02 23:21:09 +01:00 committed by Andrew Kaster
parent b6ac2ed34d
commit da88d766b2
37 changed files with 633 additions and 5 deletions

10
Kernel/Arch/riscv64/CPU.h Normal file
View file

@ -0,0 +1,10 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Platform.h>
VALIDATE_IS_RISCV64()

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Library/Assertions.h>
namespace Kernel {
void debug_output(char)
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Arch/Delay.h>
namespace Kernel {
void microseconds_delay(u32)
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Firmware/ACPI/StaticParsing.h>
namespace Kernel::ACPI::StaticParsing {
ErrorOr<Optional<PhysicalAddress>> find_rsdp_in_platform_specific_memory_locations()
{
// FIXME: Implement finding RSDP for riscv64.
return Optional<PhysicalAddress> {};
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <AK/Platform.h>
VALIDATE_IS_RISCV64()
namespace Kernel {
class IRQController : public AtomicRefCounted<IRQController> {
public:
virtual ~IRQController() = default;
virtual void enable(GenericInterruptHandler const&) = 0;
virtual void disable(GenericInterruptHandler const&) = 0;
virtual void eoi(GenericInterruptHandler const&) const = 0;
virtual u64 pending_interrupts() const = 0;
virtual StringView model() const = 0;
protected:
IRQController() = default;
};
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/StringView.h>
#include <AK/Types.h>
#include <Kernel/Arch/riscv64/IRQController.h>
#include <AK/Platform.h>
VALIDATE_IS_RISCV64()
namespace Kernel::RISCV64 {
class InterruptController : public IRQController {
public:
InterruptController();
private:
virtual void enable(GenericInterruptHandler const&) override;
virtual void disable(GenericInterruptHandler const&) override;
virtual void eoi(GenericInterruptHandler const&) const override;
virtual u64 pending_interrupts() const override;
virtual StringView model() const override
{
return "cpu-intc"sv;
}
};
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Arch/Interrupts.h>
#include <Kernel/Arch/riscv64/IRQController.h>
#include <Kernel/Arch/riscv64/InterruptManagement.h>
#include <Kernel/Interrupts/SharedIRQHandler.h>
namespace Kernel {
static InterruptManagement* s_interrupt_management;
bool InterruptManagement::initialized()
{
return s_interrupt_management != nullptr;
}
InterruptManagement& InterruptManagement::the()
{
VERIFY(InterruptManagement::initialized());
return *s_interrupt_management;
}
void InterruptManagement::initialize()
{
VERIFY(!InterruptManagement::initialized());
s_interrupt_management = new InterruptManagement;
the().find_controllers();
}
void InterruptManagement::find_controllers()
{
TODO_RISCV64();
}
u8 InterruptManagement::acquire_mapped_interrupt_number(u8)
{
TODO_RISCV64();
}
Vector<NonnullLockRefPtr<IRQController>> const& InterruptManagement::controllers()
{
return m_interrupt_controllers;
}
NonnullLockRefPtr<IRQController> InterruptManagement::get_responsible_irq_controller(size_t)
{
TODO_RISCV64();
}
void InterruptManagement::enumerate_interrupt_handlers(Function<void(GenericInterruptHandler&)>)
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <Kernel/Arch/riscv64/IRQController.h>
#include <AK/Platform.h>
VALIDATE_IS_RISCV64()
namespace Kernel {
class InterruptManagement {
public:
static InterruptManagement& the();
static void initialize();
static bool initialized();
static u8 acquire_mapped_interrupt_number(u8 original_irq);
Vector<NonnullLockRefPtr<IRQController>> const& controllers();
NonnullLockRefPtr<IRQController> get_responsible_irq_controller(size_t irq_number);
void enumerate_interrupt_handlers(Function<void(GenericInterruptHandler&)>);
private:
InterruptManagement() = default;
void find_controllers();
Vector<NonnullLockRefPtr<IRQController>> m_interrupt_controllers;
};
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Error.h>
#include <AK/Types.h>
#include <Kernel/Arch/TrapFrame.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
namespace Kernel {
void dump_registers(RegisterState const&)
{
}
// FIXME: Share the code below with Arch/x86_64/Interrupts.cpp
// While refactoring, the interrupt handlers can also be moved into the InterruptManagement class.
GenericInterruptHandler& get_interrupt_handler(u8)
{
TODO_RISCV64();
}
// Sets the reserved flag on `number_of_irqs` if it finds unused interrupt handler on
// a contiguous range.
ErrorOr<u8> reserve_interrupt_handlers(u8)
{
TODO_RISCV64();
}
void register_generic_interrupt_handler(u8, GenericInterruptHandler&)
{
TODO_RISCV64();
}
void unregister_generic_interrupt_handler(u8, GenericInterruptHandler&)
{
}
void initialize_interrupts()
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Library/Assertions.h>
namespace Kernel::PCI {
bool g_pci_access_io_probe_failed { false };
bool g_pci_access_is_disabled_from_commandline { true };
void initialize()
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Format.h>
#include <AK/Singleton.h>
#include <Kernel/Arch/PageDirectory.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
namespace Kernel::Memory {
void PageDirectory::register_page_directory(PageDirectory*)
{
TODO_RISCV64();
}
void PageDirectory::deregister_page_directory(PageDirectory*)
{
TODO_RISCV64();
}
ErrorOr<NonnullLockRefPtr<PageDirectory>> PageDirectory::try_create_for_userspace(Process&)
{
TODO_RISCV64();
}
LockRefPtr<PageDirectory> PageDirectory::find_current()
{
TODO_RISCV64();
}
void activate_kernel_page_directory(PageDirectory const&)
{
TODO_RISCV64();
}
void activate_page_directory(PageDirectory const&, Thread*)
{
TODO_RISCV64();
}
UNMAP_AFTER_INIT NonnullLockRefPtr<PageDirectory> PageDirectory::must_create_kernel_page_directory()
{
return adopt_lock_ref_if_nonnull(new (nothrow) PageDirectory).release_nonnull();
}
PageDirectory::PageDirectory() = default;
UNMAP_AFTER_INIT void PageDirectory::allocate_kernel_directory()
{
TODO_RISCV64();
}
PageDirectory::~PageDirectory()
{
if (is_root_table_initialized()) {
deregister_page_directory(this);
}
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Arch/Processor.h>
#include <Kernel/KSyms.h>
#include <Kernel/Library/Panic.h>
// FIXME: Merge the code in this file with Kernel/Library/Panic.cpp once the proper abstractions are in place.
// Note: This is required here, since __assertion_failed should be out of the Kernel namespace,
// but the PANIC macro uses functions that require the Kernel namespace.
using namespace Kernel;
[[noreturn]] void __assertion_failed(char const* msg, char const* file, unsigned line, char const* func)
{
critical_dmesgln("ASSERTION FAILED: {}", msg);
critical_dmesgln("{}:{} in {}", file, line, func);
// Used for printing a nice backtrace!
PANIC("Aborted");
}

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Arch/PowerState.h>
namespace Kernel {
void arch_specific_reboot()
{
TODO_RISCV64();
}
void arch_specific_poweroff()
{
TODO_RISCV64();
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com>
* Copyright (c) 2023, Daniel Bertalan <dani@danielbertalan.dev>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Arch/RegisterState.h>
#include <Kernel/Arch/SafeMem.h>
#include <Kernel/Library/StdLib.h>
#define CODE_SECTION(section_name) __attribute__((section(section_name)))
extern "C" u8 start_of_safemem_text[];
extern "C" u8 end_of_safemem_text[];
extern "C" u8 start_of_safemem_atomic_text[];
extern "C" u8 end_of_safemem_atomic_text[];
namespace Kernel {
CODE_SECTION(".text.safemem")
NEVER_INLINE FLATTEN bool safe_memset(void* dest_ptr, int c, size_t n, void*& fault_at)
{
// FIXME: Actually implement a safe memset.
auto* dest = static_cast<u8*>(dest_ptr);
for (; n--;)
*dest++ = c;
fault_at = nullptr;
return true;
}
CODE_SECTION(".text.safemem")
NEVER_INLINE FLATTEN ssize_t safe_strnlen(char const* str, unsigned long max_n, void*& fault_at)
{
// FIXME: Actually implement a safe strnlen.
size_t len = 0;
for (; len < max_n && *str; str++)
len++;
fault_at = nullptr;
return len;
}
CODE_SECTION(".text.safemem")
NEVER_INLINE FLATTEN bool safe_memcpy(void* dest_ptr, void const* src_ptr, unsigned long n, void*& fault_at)
{
// FIXME: Actually implement a safe memcpy.
auto* pd = static_cast<u8*>(dest_ptr);
auto const* ps = static_cast<u8 const*>(src_ptr);
for (; n--;)
*pd++ = *ps++;
fault_at = nullptr;
return true;
}
CODE_SECTION(".text.safemem.atomic")
NEVER_INLINE FLATTEN Optional<bool> safe_atomic_compare_exchange_relaxed(u32 volatile* var, u32& expected, u32 val)
{
// FIXME: Handle access faults.
return AK::atomic_compare_exchange_strong(var, expected, val, AK::memory_order_relaxed);
}
CODE_SECTION(".text.safemem.atomic")
NEVER_INLINE FLATTEN Optional<u32> safe_atomic_load_relaxed(u32 volatile* var)
{
// FIXME: Handle access faults.
return AK::atomic_load(var, AK::memory_order_relaxed);
}
CODE_SECTION(".text.safemem.atomic")
NEVER_INLINE FLATTEN Optional<u32> safe_atomic_fetch_add_relaxed(u32 volatile* var, u32 val)
{
// FIXME: Handle access faults.
return AK::atomic_fetch_add(var, val, AK::memory_order_relaxed);
}
CODE_SECTION(".text.safemem.atomic")
NEVER_INLINE FLATTEN Optional<u32> safe_atomic_exchange_relaxed(u32 volatile* var, u32 val)
{
// FIXME: Handle access faults.
return AK::atomic_exchange(var, val, AK::memory_order_relaxed);
}
CODE_SECTION(".text.safemem.atomic")
NEVER_INLINE FLATTEN bool safe_atomic_store_relaxed(u32 volatile* var, u32 val)
{
// FIXME: Handle access faults.
AK::atomic_store(var, val);
return true;
}
bool handle_safe_access_fault(RegisterState& regs, FlatPtr fault_address)
{
FlatPtr ip = regs.ip();
if (ip >= (FlatPtr)&start_of_safemem_text && ip < (FlatPtr)&end_of_safemem_text) {
dbgln("FIXME: Faulted while accessing userspace address {:p}.", fault_address);
dbgln(" We need to jump back into the appropriate SafeMem function, set fault_at and return failure.");
TODO_RISCV64();
} else if (ip >= (FlatPtr)&start_of_safemem_atomic_text && ip < (FlatPtr)&end_of_safemem_atomic_text) {
dbgln("FIXME: Faulted while accessing userspace address {:p}.", fault_address);
dbgln(" We need to jump back into the appropriate atomic SafeMem function and return failure.");
TODO_RISCV64();
}
return false;
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Types.h>
#include <Kernel/Arch/Processor.h>
#include <Kernel/Memory/PhysicalAddress.h>
namespace Kernel {
extern "C" [[noreturn]] void pre_init(FlatPtr mhartid, PhysicalPtr fdt_phys_addr);
extern "C" [[noreturn]] void pre_init(FlatPtr mhartid, PhysicalPtr fdt_phys_addr)
{
(void)mhartid;
(void)fdt_phys_addr;
// FIXME: Implement this
Processor::halt();
}
}