Kernel/riscv64: Add support for legacy "System Shutdown" SBI extension

This commit is contained in:
Sönke Holz 2024-01-04 18:16:55 +01:00 committed by Andrew Kaster
parent fbdb1a3d61
commit cac7dc8d71
Notes: sideshowbarker 2024-07-17 08:35:21 +09:00
2 changed files with 23 additions and 0 deletions

View File

@ -86,6 +86,17 @@ SBIErrorOr<long> get_mimpid()
namespace Legacy {
static long sbi_legacy_ecall0(LegacyEID extension_id)
{
register unsigned long a0 asm("a0");
register unsigned long a7 asm("a7") = to_underlying(extension_id);
asm volatile("ecall"
: "=r"(a0)
: "r"(a7)
: "memory");
return static_cast<long>(a0);
}
static long sbi_legacy_ecall1(LegacyEID extension_id, unsigned long arg0)
{
register unsigned long a0 asm("a0") = arg0;
@ -115,6 +126,13 @@ LegacySBIErrorOr<void> console_putchar(int ch)
return err;
}
void shutdown()
{
sbi_legacy_ecall0(LegacyEID::SystemShutdown);
VERIFY_NOT_REACHED();
}
}
namespace Timer {

View File

@ -133,6 +133,11 @@ LegacySBIErrorOr<void> set_timer(u64 stime_value);
// Write data present in ch to debug console.
LegacySBIErrorOr<void> console_putchar(int ch);
// System Shutdown (EID #0x08)
// Puts all the harts to shutdown state from supervisor point of view.
// This SBI call doesnt return irrespective whether it succeeds or fails.
[[noreturn]] void shutdown();
}
// Chapter 6. Timer Extension (EID #0x54494D45 "TIME")