diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/fdt/fdt.c | 24 | ||||
-rw-r--r-- | sys/include/cpu.h | 10 | ||||
-rw-r--r-- | sys/include/sbi.h | 42 | ||||
-rw-r--r-- | sys/sys/init.c | 22 | ||||
-rw-r--r-- | sys/sys/mm/kalloc.c | 26 | ||||
-rw-r--r-- | sys/sys/printf.c | 98 |
6 files changed, 106 insertions, 116 deletions
diff --git a/sys/dev/fdt/fdt.c b/sys/dev/fdt/fdt.c index 0bd0a52..9a8f1af 100644 --- a/sys/dev/fdt/fdt.c +++ b/sys/dev/fdt/fdt.c @@ -7,18 +7,18 @@ void fdt_walk(struct fdt_header *header) { if (fdt_uint32(header->magic) != FDT_HEADER_MAGIC) { - printf("corrupted or invalid fdt"); - } - printf("parsing fdt @%p...\n", header); - printf("header->totalsize: %d\n", fdt_uint32(header->totalsize)); - printf("header->off_dt_struct: %d\n", fdt_uint32(header->off_dt_struct)); - printf("header->off_dt_strings: %d\n", fdt_uint32(header->off_dt_strings)); - printf("header->off_mem_rsvmap: %d\n", fdt_uint32(header->off_mem_rsvmap)); - printf("header->version: %d\n", fdt_uint32(header->version)); - printf("header->last_comp_version: %d\n", fdt_uint32(header->last_comp_version)); - printf("header->boot_cpuid_phys: %d\n", fdt_uint32(header->boot_cpuid_phys)); - printf("header->size_dt_strings: %d\n", fdt_uint32(header->size_dt_strings)); - printf("header->size_dt_struct: %d\n", fdt_uint32(header->size_dt_struct)); + printf("corrupted or invalid fdt"); + } + printf("parsing fdt @%p...\n", header); + printf("header->totalsize: %d\n", fdt_uint32(header->totalsize)); + printf("header->off_dt_struct: %d\n", fdt_uint32(header->off_dt_struct)); + printf("header->off_dt_strings: %d\n", fdt_uint32(header->off_dt_strings)); + printf("header->off_mem_rsvmap: %d\n", fdt_uint32(header->off_mem_rsvmap)); + printf("header->version: %d\n", fdt_uint32(header->version)); + printf("header->last_comp_version: %d\n", fdt_uint32(header->last_comp_version)); + printf("header->boot_cpuid_phys: %d\n", fdt_uint32(header->boot_cpuid_phys)); + printf("header->size_dt_strings: %d\n", fdt_uint32(header->size_dt_strings)); + printf("header->size_dt_struct: %d\n", fdt_uint32(header->size_dt_struct)); printf("walking the memory reservation block...\n"); struct fdt_reserve_entry *p = header + fdt_uint32(header->off_mem_rsvmap); diff --git a/sys/include/cpu.h b/sys/include/cpu.h deleted file mode 100644 index 9567496..0000000 --- a/sys/include/cpu.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _CPU_H -#define _CPU_H - -struct hart { - int intr_stack; -}; - -struct hart harts[NPROC] = {0}; - -#endif /* _CPU_H */ diff --git a/sys/include/sbi.h b/sys/include/sbi.h index 1c0fc7f..94c3749 100644 --- a/sys/include/sbi.h +++ b/sys/include/sbi.h @@ -2,8 +2,8 @@ #define _SBI_H struct sbiret { - long err; - long val; + long err; + long val; }; #define SBI_SUCCESS 0 @@ -28,28 +28,28 @@ enum HART_STATUS { static inline struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, - unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, - unsigned long arg5) + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) { - struct sbiret ret; + struct sbiret ret; - register unsigned long a0 asm ("a0") = (unsigned long)(arg0); - register unsigned long a1 asm ("a1") = (unsigned long)(arg1); - register unsigned long a2 asm ("a2") = (unsigned long)(arg2); - register unsigned long a3 asm ("a3") = (unsigned long)(arg3); - register unsigned long a4 asm ("a4") = (unsigned long)(arg4); - register unsigned long a5 asm ("a5") = (unsigned long)(arg5); - register unsigned long a6 asm ("a6") = (unsigned long)(fid); - register unsigned long a7 asm ("a7") = (unsigned long)(ext); - asm volatile ("ecall" - : "+r" (a0), "+r" (a1) - : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) - : "memory"); - ret.err = a0; - ret.val = a1; + register unsigned long a0 asm ("a0") = (unsigned long)(arg0); + register unsigned long a1 asm ("a1") = (unsigned long)(arg1); + register unsigned long a2 asm ("a2") = (unsigned long)(arg2); + register unsigned long a3 asm ("a3") = (unsigned long)(arg3); + register unsigned long a4 asm ("a4") = (unsigned long)(arg4); + register unsigned long a5 asm ("a5") = (unsigned long)(arg5); + register unsigned long a6 asm ("a6") = (unsigned long)(fid); + register unsigned long a7 asm ("a7") = (unsigned long)(ext); + asm volatile ("ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) + : "memory"); + ret.err = a0; + ret.val = a1; - return ret; + return ret; } static inline void diff --git a/sys/sys/init.c b/sys/sys/init.c index e5cb4e4..4867be6 100644 --- a/sys/sys/init.c +++ b/sys/sys/init.c @@ -17,19 +17,19 @@ init(unsigned long hartid, struct fdt_header *fdt) printf("booting from hart #%d\n", 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("found flattened device tree at %p!\n", (uint64_t)fdt); - printf("setting up the heap at %p\n", HEAP_START); - kalloc_init(); + printf("parsing device tree!\n"); + fdt_walk(fdt); + + printf("setting up the heap at %p\n", HEAP_START); + kalloc_init(); printf_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 + printf("done!\n"); + // printf("printing free pages:\n"); + ///walkfree(); + printf("bringing up other harts...\n"); + // todo: detect harts and reserved mem from device tree for optimal memory usage. for (int i = 0; i < NPROC; ++i) { if (i == hartid) { printf("skipping hart #%d\n", i); diff --git a/sys/sys/mm/kalloc.c b/sys/sys/mm/kalloc.c index a574c41..b2c19d9 100644 --- a/sys/sys/mm/kalloc.c +++ b/sys/sys/mm/kalloc.c @@ -20,7 +20,7 @@ kalloc(void) { acquire(&mutex); freenode_t *p = head; - + if (p == NULL) return NULL; @@ -54,21 +54,21 @@ void kalloc_init(void) { initlock(&mutex); - freenode_t *p = (freenode_t*)HEAP_START; - for (;(unsigned long)p + PAGE_SIZE <= (HEAP_START + 0x100000); p += PAGE_SIZE) { - kfree(p); - } + freenode_t *p = (freenode_t*)HEAP_START; + for (;(unsigned long)p + PAGE_SIZE <= (HEAP_START + 0x100000); p += PAGE_SIZE) { + kfree(p); + } } void walkfree(void) { - freenode_t *node = head; - int nfree = 0; - while (node) { - printf("freenode at %p\n", node); - node = node->next; - nfree++; - } - printf("found and printed %d free pages!\n", nfree); + freenode_t *node = head; + int nfree = 0; + while (node) { + printf("freenode at %p\n", node); + node = node->next; + nfree++; + } + printf("found and printed %d free pages!\n", nfree); } diff --git a/sys/sys/printf.c b/sys/sys/printf.c index 19b2315..03bf8cc 100644 --- a/sys/sys/printf.c +++ b/sys/sys/printf.c @@ -21,72 +21,72 @@ puts(const char *str) static void printint(int xx, int base, int sign) { - char buf[16]; - int i; - unsigned int x; + char buf[16]; + int i; + unsigned int x; - if (sign && (sign = xx < 0)) - x = -xx; - else - x = xx; + if (sign && (sign = xx < 0)) + x = -xx; + else + x = xx; - i = 0; - do { - buf[i++] = digits[x % base]; - } while ((x /= base) != 0); + i = 0; + do { + buf[i++] = digits[x % base]; + } while ((x /= base) != 0); - if (sign) - buf[i++] = '-'; - while (--i >= 0) - PUTCHAR(buf[i]); + if (sign) + buf[i++] = '-'; + while (--i >= 0) + PUTCHAR(buf[i]); } static void printptr(uint64_t x) { - int i; - puts("0x"); - for (i = 0; i < (sizeof(uint64_t) * 2); i++, x <<= 4) - PUTCHAR(digits[x >> (sizeof(int64_t) * 8 - 4)]); + int i; + puts("0x"); + for (i = 0; i < (sizeof(uint64_t) * 2); i++, x <<= 4) + PUTCHAR(digits[x >> (sizeof(int64_t) * 8 - 4)]); } void printf(const char *fmt, ...) { - va_list ap; - int i, c, _locked; - char *s; + va_list ap; + int i, c, _locked; + char *s; acquire(&mutex); - va_start(ap, fmt); - - for (i = 0; (c = fmt[i] & 0xff) != 0; i++) { - if (c != '%') { - PUTCHAR(c); - continue; - } - c = fmt[++i] & 0xff; - if (!c) - break; - - switch (c) { - case 'd': - case 'i': - printint(va_arg(ap, int), 10, 1); - break; - case 'x': - printint(va_arg(ap, int), 16, 1); - break; - case 'p': - printptr(va_arg(ap, uint64_t)); - break; - case '%': - PUTCHAR('%'); - break; - } - } + va_start(ap, fmt); + + for (i = 0; (c = fmt[i] & 0xff) != 0; i++) { + if (c != '%') { + PUTCHAR(c); + continue; + } + c = fmt[++i] & 0xff; + if (!c) + break; + + switch (c) { + case 'd': + case 'i': + printint(va_arg(ap, int), 10, 1); + break; + case 'x': + printint(va_arg(ap, int), 16, 1); + break; + case 'p': + printptr(va_arg(ap, uint64_t)); + break; + case '%': + PUTCHAR('%'); + break; + } + } release(&mutex); } |