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.
This commit is contained in:
Sönke Holz 2024-01-04 18:45:16 +01:00 committed by Andrew Kaster
parent 27087318bc
commit 21b2d1de65
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00

View file

@ -203,6 +203,50 @@ void initialize();
}
template<>
struct AK::Formatter<Kernel::SBI::SBIError> : Formatter<StringView> {
ErrorOr<void> 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<Kernel::SBI::Base::SpecificationVersion> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, Kernel::SBI::Base::SpecificationVersion const& version)