From 76169cd214e4830a523c8c2ee7bbddc04b4253df Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 5 Dec 2024 15:34:33 +0100 Subject: supervisor: Add an example on the HSM extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HSM extension from SBI v2.0 allows a supervisor to manage the state of harts on the system. Moreover, it also guarantees that only one hart makes it into the booting stages of the supervisor, and it's up to the supervisor to wake up the rest through the HSM extension. I have added an example which showcases this extension in different ways, and it finally shuts down the machine. Signed-off-by: Miquel Sabaté Solà --- arch/riscv/supervisor/hsm/head.S | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 arch/riscv/supervisor/hsm/head.S (limited to 'arch/riscv/supervisor/hsm/head.S') diff --git a/arch/riscv/supervisor/hsm/head.S b/arch/riscv/supervisor/hsm/head.S new file mode 100644 index 0000000..e912b18 --- /dev/null +++ b/arch/riscv/supervisor/hsm/head.S @@ -0,0 +1,44 @@ +.global _start +.section .head.text + +_start: + // Start by simply disabling interrupts. + csrw sie, zero + csrw sip, zero + fence.i + + // Initialize the 'a4' register, which is going to be used for printing out + // the end message by the main hart. + li a4, 0 + + // Hart lottery! The main hart will win it, the rest will simply jump into + // .Lhalt. See hsm.c for more details. + la a3, hart_lottery + li a2, 1 + amoadd.w a3, a2, (a3) + bnez a3, .Lhalt + + // Setup a dummy stack and call the kernel. + la sp, _STACK_PTR + call start_kernel + + // We actually expect the main kernel routine to quit. Here we make the + // .Lhalt part of the code to print special messages for that case. + addi a4, a4, 1 + +.Lhalt: + // Increase the number of hart that lost the lottery. + la a3, hart_failed_lottery + li a2, 1 + amoadd.w zero, a2, (a3) + + // If it's the main hart that is bailing out, first print some final + // messages. + beqz a4, .Lend + call print_lottery + call end + + // Die Bart, die! +.Lend: + wfi + j .Lend -- cgit v1.2.3