blob: a58d3bce979b3ae39bd3351e2cadc7bb3490d490 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <fdt.h>
#include <mm/kalloc.h>
#include <printf.h>
#include <spinlock.h>
#include <sbi.h>
#include <stdint.h>
extern uint64_t HEAP_START;
#define HLT()\
for (;;)\
asm("wfi")
void
init(unsigned long hartid, struct fdt_header *fdt)
{
printf("booting from hart #%d\n", hartid);
asm volatile ("mv tp, %0" : : "r"(hartid));
if (fdt_uint32(fdt->magic) == FDT_HEADER_MAGIC)
printf("found flattened device tree at %p!\n", (uint64_t)fdt);
printf("parsing device tree!\n");
fdt_walk(fdt);
printf("setting up the heap at %p\n", HEAP_START);
kalloc_init();
printf("done!\n");
// printf("printing free pages:\n");
///walkfree();
printf("bringing up other harts...\n");
// todo: detect harts from device tree can also be used for more conservative stack allocation
for (int i = 0; i < NPROC; ++i) {
if (i == hartid) {
printf("skipping hart #%d\n", i);
continue;
}
printf("starting hart #%d\n", i);
struct sbiret r = _start_hart(i, (unsigned long)LOAD_ADDR);
if (r.err != SBI_SUCCESS)
printf("ERROR");
}
}
void
mpinit(unsigned long hartid)
{
printf("mpinit: %d", hartid);
HLT();
}
|