From 21b2d1de6506e6103f2be498972dcb1d0c9c25cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Thu, 4 Jan 2024 18:45:16 +0100 Subject: [PATCH] Kernel/riscv64: Add AK::Formatter for SBI errors This allows us to print errors returned to us via the SBI. The error messages are taken from the SBI spec. --- Kernel/Arch/riscv64/SBI.h | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Kernel/Arch/riscv64/SBI.h b/Kernel/Arch/riscv64/SBI.h index 98c5776fd3..e08c0d933e 100644 --- a/Kernel/Arch/riscv64/SBI.h +++ b/Kernel/Arch/riscv64/SBI.h @@ -203,6 +203,50 @@ void initialize(); } +template<> +struct AK::Formatter : Formatter { + ErrorOr format(FormatBuilder& builder, Kernel::SBI::SBIError error) + { + auto string = "Unknown error"sv; + + using enum Kernel::SBI::SBIError; + switch (error) { + case Success: + string = "Completed successfully"sv; + break; + case Failed: + string = "Failed"sv; + break; + case NotSupported: + string = "Not supported"sv; + break; + case InvalidParam: + string = "Invalid parameter(s)"sv; + break; + case Denied: + string = "Denied or not allowed"sv; + break; + case InvalidAddress: + string = "Invalid address(s)"sv; + break; + case AlreadyAvailable: + string = "Already available"sv; + break; + case AlreadyStarted: + string = "Already started"sv; + break; + case AlreadyStopped: + string = "Already stopped"sv; + break; + case NoSHMEM: + string = "Shared memory not available"sv; + break; + } + + return builder.put_string(string); + } +}; + template<> struct AK::Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Kernel::SBI::Base::SpecificationVersion const& version)