Some prettier init code
This commit is contained in:
parent
a9f7cb8cf7
commit
5948d6c8e8
2 changed files with 18 additions and 5 deletions
2
Makefile
2
Makefile
|
@ -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 $@ $^
|
||||||
|
|
||||||
|
|
21
start.c
21
start.c
|
@ -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,17 +22,28 @@ 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_putc(a + '0');
|
|
||||||
uart_putc('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uart_puts("Hart number: ");
|
||||||
|
uart_putc(a + '0');
|
||||||
|
uart_putc('\n');
|
||||||
|
|
||||||
|
release(&sl);
|
||||||
|
|
||||||
/* Here we will do a bunch of initialization steps */
|
/* Here we will do a bunch of initialization steps */
|
||||||
|
|
||||||
// We should not arrive here, but if we do, hang in a while on wfi.
|
// We should not arrive here, but if we do, hang in a while on wfi.
|
||||||
|
|
Loading…
Add table
Reference in a new issue