summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/Makefile3
-rw-r--r--sys/dev/dev_init.c22
-rw-r--r--sys/include/dev.h8
-rw-r--r--sys/sys/init.c4
-rw-r--r--sys/sys/printf.c4
5 files changed, 41 insertions, 0 deletions
diff --git a/sys/Makefile b/sys/Makefile
index 385cf7a..970809f 100644
--- a/sys/Makefile
+++ b/sys/Makefile
@@ -13,6 +13,7 @@ SRC=\
sys/printf.c\
sys/mm/kalloc.c\
sys/smp/spinlock.c\
+ dev/dev_init.c\
${BUILDDIR}/kernel.elf: ${SRC}
@@ -28,6 +29,8 @@ ${BUILDDIR}/kernel.elf: ${SRC}
-I ./include\
${CFLAGS} -T sys/kernel.lds ${LDFLAGS}\
-L../lib/libc/${BUILDDIR}/\
+ -L../lib/libfdt/${BUILDDIR}/\
+ -l:libfdt.a\
-l:libc.a\
-o $@
diff --git a/sys/dev/dev_init.c b/sys/dev/dev_init.c
new file mode 100644
index 0000000..fc70853
--- /dev/null
+++ b/sys/dev/dev_init.c
@@ -0,0 +1,22 @@
+#include <dev.h>
+#include <libfdt.h>
+#include <sbi.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+
+void
+dev_init(struct fdt_header *fdt)
+{
+ if (fdt_check_header(fdt) == 0)
+ printf("[dev_init] valid fdt at %p\n", fdt);
+ else
+ printf("[dev_init] error: fdt_check_header()\n");
+
+ int offset = fdt_next_node(fdt, offset, 0);
+ do {
+ printf("[dev_init] found %s\n", fdt_get_name(fdt, offset, NULL));
+ offset = fdt_next_node(fdt, offset, 0);
+ } while (offset != -FDT_ERR_NOTFOUND);
+}
+
diff --git a/sys/include/dev.h b/sys/include/dev.h
new file mode 100644
index 0000000..b8bfef8
--- /dev/null
+++ b/sys/include/dev.h
@@ -0,0 +1,8 @@
+#ifndef _DEV_H
+#define _DEV_H
+
+#include <libfdt.h>
+
+void dev_init(struct fdt_header* fdt);
+
+#endif /* _DEV_H */
diff --git a/sys/sys/init.c b/sys/sys/init.c
index b21ac84..48aeb97 100644
--- a/sys/sys/init.c
+++ b/sys/sys/init.c
@@ -1,4 +1,6 @@
+#include <dev.h>
#include <libfdt.h>
+#include <string.h>
#include <kalloc.h>
#include <spinlock.h>
#include <stdio.h>
@@ -23,6 +25,8 @@ init(unsigned long hartid, struct fdt_header *fdt)
printf_init();
printf("done!\n");
+ dev_init(fdt);
+
printf("bringing up other harts...\n");
for (int i = 0; i < NPROC; ++i) {
if (i == hartid) {
diff --git a/sys/sys/printf.c b/sys/sys/printf.c
index e8cc468..bff20bf 100644
--- a/sys/sys/printf.c
+++ b/sys/sys/printf.c
@@ -56,6 +56,7 @@ printptr(uint64_t x)
putchar(digits[x >> (sizeof(int64_t) * 8 - 4)]);
}
+/* literally zero overflow checking (i am the best programmer of all time) */
void
printf(const char *fmt, ...)
{
@@ -90,6 +91,9 @@ printf(const char *fmt, ...)
case '%':
putchar('%');
break;
+ case 's':
+ puts(va_arg(ap, const char *));
+ break;
}
}
release(&mutex);