Some prettier init code

This commit is contained in:
Imbus 2025-06-26 05:57:35 +02:00
parent a9f7cb8cf7
commit 5948d6c8e8
2 changed files with 18 additions and 5 deletions

View file

@ -27,7 +27,7 @@ CFLAGS += -fno-omit-frame-pointer # More reliable backtraces in GDB
all: kernel.elf all: kernel.elf
kernel.elf: entry.o start.o lib/string.o kernel.elf: entry.o start.o lib/string.o lib/proc.o lib/spinlock.o lib/proc.o
@echo LD $@ @echo LD $@
@$(LD) $(LDFLAGS) -o $@ $^ @$(LD) $(LDFLAGS) -o $@ $^

19
start.c
View file

@ -1,4 +1,6 @@
#include <config.h>
#include <riscv.h> #include <riscv.h>
#include <spinlock.h>
#include <types.h> #include <types.h>
/* QEMU memory maps a UART device here. */ /* QEMU memory maps a UART device here. */
@ -20,16 +22,27 @@ void uart_puts(const char *s) {
*/ */
char stack0[4096 * NCPU] __attribute__((aligned(16))); 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;
/* This is where entry.S drops us of. All cores land here */ /* This is where entry.S drops us of. All cores land here */
void start() { void start() {
u64 a = r_mhartid(); u64 a = r_mhartid();
if(a == 0) {
acquire(&sl);
if (!greeted) {
uart_puts("Hello Neptune!\n"); uart_puts("Hello Neptune!\n");
uart_puts("Core number: "); greeted = 1;
}
uart_puts("Hart number: ");
uart_putc(a + '0'); uart_putc(a + '0');
uart_putc('\n'); uart_putc('\n');
}
release(&sl);
/* Here we will do a bunch of initialization steps */ /* Here we will do a bunch of initialization steps */