mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
Kernel/riscv64: Add support for SRST "System Reset" SBI extension
This extension will be used for rebooting and shutting down.
This commit is contained in:
parent
cac7dc8d71
commit
27087318bc
2 changed files with 58 additions and 0 deletions
|
@ -44,6 +44,22 @@ static SBIErrorOr<long> sbi_ecall1(EID extension_id, u32 function_id, unsigned l
|
|||
return static_cast<SBIError>(a0);
|
||||
}
|
||||
|
||||
static SBIErrorOr<long> sbi_ecall2(EID extension_id, u32 function_id, unsigned long arg0, unsigned long arg1)
|
||||
{
|
||||
register unsigned long a0 asm("a0") = arg0;
|
||||
register unsigned long a1 asm("a1") = arg1;
|
||||
register unsigned long a6 asm("a6") = function_id;
|
||||
register unsigned long a7 asm("a7") = to_underlying(extension_id);
|
||||
asm volatile("ecall"
|
||||
: "+r"(a0), "+r"(a1)
|
||||
: "r"(a0), "r"(a1), "r"(a6), "r"(a7)
|
||||
: "memory");
|
||||
if (a0 == to_underlying(SBIError::Success))
|
||||
return static_cast<long>(a1);
|
||||
|
||||
return static_cast<SBIError>(a0);
|
||||
}
|
||||
|
||||
namespace Base {
|
||||
|
||||
SBIErrorOr<SpecificationVersion> get_spec_version()
|
||||
|
@ -145,6 +161,20 @@ SBIErrorOr<void> set_timer(u64 stime_value)
|
|||
|
||||
}
|
||||
|
||||
namespace SystemReset {
|
||||
|
||||
SBIError system_reset(ResetType reset_type, ResetReason reset_reason)
|
||||
{
|
||||
auto const res = SBI::sbi_ecall2(EID::SystemReset, to_underlying(FID::SystemReset), to_underlying(reset_type), to_underlying(reset_reason));
|
||||
|
||||
// This SBI call shold only return if it didn't succeed
|
||||
VERIFY(res.is_error());
|
||||
|
||||
return res.error();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace DBCN {
|
||||
|
||||
SBIErrorOr<void> debug_console_write_byte(u8 byte)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue