From 386ad4f82955d389ae347bc50f7efca5edb9d9a8 Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 21 Apr 2023 21:56:45 -0400 Subject: actually got libfdt working --- sys/Makefile | 3 +++ sys/dev/dev_init.c | 22 ++++++++++++++++++++++ sys/include/dev.h | 8 ++++++++ sys/sys/init.c | 4 ++++ sys/sys/printf.c | 4 ++++ 5 files changed, 41 insertions(+) create mode 100644 sys/dev/dev_init.c create mode 100644 sys/include/dev.h (limited to 'sys') 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 +#include +#include +#include +#include +#include + +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 + +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 #include +#include #include #include #include @@ -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); -- cgit v1.2.3