Restructure, use ispinlock

This commit is contained in:
Imbus 2025-08-16 15:01:01 +02:00
parent 608968668b
commit 39ef34d41e

30
start.c
View file

@ -1,9 +1,9 @@
#include <config.h>
#include <ispinlock.h>
#include <kalloc.h>
#include <memory.h>
#include <proc.h>
#include <riscv.h>
#include <spinlock.h>
#include <types.h>
#include <uart.h>
@ -16,8 +16,8 @@
char stack0[4096 * NCPU] __attribute__((aligned(16)));
/* Keep this here and sync on it until we have synchronized printf */
struct Spinlock sl = {0};
volatile int greeted = 0;
spinlock_t sl = {0};
volatile int hold = 1;
/* This is where entry.S drops us of. All cores land here */
void start() {
@ -29,24 +29,22 @@ void start() {
// cpu (struct Cpu).
write_tp(id);
acquire(&sl);
if (!greeted) {
uart_puts("Hello Neptune!\n");
greeted = 1;
}
uart_puts("Hart number: ");
uart_putc(id + '0');
uart_putc('\n');
release(&sl);
if (id == 0) {
/* Here we will do a bunch of initialization steps */
kalloc_init();
uart_puts("Hello Neptune!\n");
spinlock_init(&sl);
hold = 0;
}
while (hold);
spin_lock(&sl);
uart_puts("Hart number: ");
uart_putc(id + '0');
uart_putc('\n');
spin_unlock(&sl);
// We should not arrive here, but if we do, hang in a while on wfi.
while (1) __asm__ volatile("wfi"); // (Wait For Interrupt)
}