I'm using Michael's riscv-qemu (07146abe22e5ea5) and the Linux
riscv-next branch (418457520fbb). I have a small C program called
‘poweroff’ which simply calls ‘reboot (LINUX_REBOOT_CMD_POWER_OFF);’
but this isn't powering off (exiting) qemu.
So I was interested to find out what actually happens (or at least is
supposed to happen) during power off, since I'd never looked in any
detail before.
The kernel calls the riscv-specific code arch/riscv/kernel/reset.c:
static inline void sbi_shutdown(void)
{
SBI_CALL_0(SBI_SHUTDOWN);
}
void machine_power_off(void)
{
sbi_shutdown();
while (1);
}
which ends up as:
sbi_shutdown();
ffffffe0000183ac: 4501 li a0,0
ffffffe0000183ae: 4581 li a1,0
ffffffe0000183b0: 4601 li a2,0
ffffffe0000183b2: 48a1 li a7,8 // SBI_SHUTDOWN
ffffffe0000183b4: 00000073 ecall
while (1);
ffffffe0000183b8: a001 j ffffffe0000183b8 <machine_power_off+0x12>
ecall calls from S-mode into M-mode, and I believe from there we end
up in riscv-pk machine/mtrap.c:
void poweroff(uint16_t code)
{
printm("Power off\n");
finisher_exit(code);
if (htif) {
htif_poweroff();
} else {
while (1);
}
}
This is a problem because this version of qemu isn't emulating HTIF.
Now at this point I've no idea. Is there some other way planned to do
power off? (I guess without ACPI and friends, for now)
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/