From 2eead36f97faf5bdad1abd60a220c0af72a5526c Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 3 Dec 2024 14:34:43 +0100 Subject: Run a hart lottery on SMP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On systems with SMP multiple harts will try to run the kernel, and they will appear at random. But in this kernel, in order to keep things simple, we want to make sure that *only one* hart is running the show, as it greatly simplifies things on these kinds of systems. The solution is similar to what Linux does, which is to allow the first hart to initialize things, but then (and different to what Linux does), it will infinitely stall all the other harts that arrive at a random later point in time. In order to make this more apparent, I have also added a print message showing which hart is being used to run the whole thing. Signed-off-by: Miquel Sabaté Solà --- kernel/printk.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'kernel/printk.c') diff --git a/kernel/printk.c b/kernel/printk.c index bd2bcab..1cc68db 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -3,7 +3,7 @@ #include #include -void __noreturn __kernel die(const char *const message) +__kernel __noreturn void die(const char *const message) { if (message) { printk(message); @@ -13,6 +13,19 @@ void __noreturn __kernel die(const char *const message) ; } +__kernel void print_digit(uint32_t digit) +{ + char buffer[2]; + + if (digit > 9) { + die("We cannot print numbers with two or more digits :D\n"); + } + + buffer[0] = '0' + digit; + buffer[1] = '\0'; + write(buffer, 2); +} + __kernel void write(const char *const message, size_t n) { struct sbi_ret ret = sbi_ecall2(DBCN_EXT, DBCN_WRITE, n, (unsigned long)message); -- cgit v1.2.3