diff --git a/Makefile b/Makefile index 9a024a6..8d0e4a2 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ CFLAGS += -fno-omit-frame-pointer # More reliable backtraces in GDB 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 $@ @$(LD) $(LDFLAGS) -o $@ $^ diff --git a/start.c b/start.c index 27ef439..0a9ca9b 100644 --- a/start.c +++ b/start.c @@ -1,4 +1,6 @@ +#include #include +#include #include /* QEMU memory maps a UART device here. */ @@ -20,17 +22,28 @@ void uart_puts(const char *s) { */ 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 */ void start() { u64 a = r_mhartid(); - if(a == 0) { + + acquire(&sl); + + if (!greeted) { uart_puts("Hello Neptune!\n"); - uart_puts("Core number: "); - uart_putc(a + '0'); - uart_putc('\n'); + greeted = 1; } + uart_puts("Hart number: "); + uart_putc(a + '0'); + uart_putc('\n'); + + release(&sl); + /* Here we will do a bunch of initialization steps */ // We should not arrive here, but if we do, hang in a while on wfi.