diff options
| -rw-r--r-- | Makefile | 17 | ||||
| -rw-r--r-- | TODO.txt | 2 | ||||
| -rw-r--r-- | a.out | 0 | ||||
| l--------- | arch/riscv32 | 1 | ||||
| -rw-r--r-- | arch/riscv64/config.h | 26 | ||||
| -rw-r--r-- | arch/riscv64/include/types.h | 4 | ||||
| -rw-r--r-- | arch/riscv64/include/vmem.h | 6 | ||||
| -rw-r--r-- | arch/riscv64/init/init.c | 20 | ||||
| -rw-r--r-- | arch/riscv64/source.mk | 3 | ||||
| -rw-r--r-- | include/apos/types.h | 10 | ||||
| -rw-r--r-- | include/apos/utils.h | 14 | ||||
| -rw-r--r-- | lib/fdt_dbg.c | 4 | ||||
| -rw-r--r-- | lib/ubsan.c | 4 |
13 files changed, 70 insertions, 41 deletions
@@ -9,7 +9,7 @@ CFLAGS = -ffreestanding -nostdlib -std=c17 -Wall -Wextra -Wvla DEPFLAGS = -MT $@ -MMD -MP -MF $@.d LINTFLAGS = -fsyntax-only PREPROCESS = -E -LINKFLAGS = +LDFLAGS = -static-libgcc -lgcc all: apos.bin @@ -33,6 +33,9 @@ INIT_SOURCES := include arch/$(ARCH)/source.mk +COMPILE_FLAGS := $(CFLAGS) $(ARCH_CFLAGS) +LINK_FLAGS := $(LDFLAGS) $(ARCH_LDFLAGS) + INCLUDE_FLAGS := -I include -I arch/$(ARCH)/include\ -include config.h -include arch/$(ARCH)/config.h @@ -40,15 +43,15 @@ INCLUDE_FLAGS := -I include -I arch/$(ARCH)/include\ OBJCOPY_FLAGS ?= -Obinary --set-section-flags .bss=alloc,load,contents COMPILE = $(COMPILER) $(DEBUGFLAGS)\ - $(CFLAGS) $(ARCH_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS) + $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS) LINT = $(COMPILER) $(DEBUGFLAGS)\ - $(CFLAGS) $(ARCH_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS) + $(COMPILE_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS) GENELF = $(COMPILER) $(DEBUGFLAGS)\ - $(CFLAGS) $(ARCH_FLAGS) $(LINKFLAGS) $(INCLUDE_FLAGS) + $(COMPILE_FLAGS) $(INCLUDE_FLAGS) -GENLINK = $(COMPILER) $(PREPROCESS) $(DEPFLAGS) $(INCLUDE_FLAGS) +GENLINK = $(COMPILER) $(COMPILE_FLAGS) $(PREPROCESS) $(DEPFLAGS) $(INCLUDE_FLAGS) STRIPLINK = sed -n '/^[^\#]/p' KERN_SIZE = wc -c kernel.bin | cut -d ' ' -f 1 KERN_INFO = sed "s/<KERNEL_SIZE>/$$($(KERN_SIZE))/" @@ -71,10 +74,10 @@ $(INIT_LD): kernel.bin lint: $(INIT_OBJECTS:.o=.o.l) $(KERNEL_OBJECTS:.o=.o.l) init.elf: $(INIT_OBJECTS) $(INIT_LD) - $(GENELF) -T $(INIT_LD) $(INIT_OBJECTS) -o $@ + $(GENELF) -T $(INIT_LD) $(INIT_OBJECTS) -o $@ $(LINK_FLAGS) kernel.elf: $(KERNEL_OBJECTS) $(KERNEL_LD) - $(GENELF) -T $(KERNEL_LD) $(KERNEL_OBJECTS) -o $@ + $(GENELF) -T $(KERNEL_LD) $(KERNEL_OBJECTS) -o $@ $(LINK_FLAGS) init.bin: init.elf $(OBJCOPY) $(OBJCOPY_FLAGS) $< $@ @@ -1,5 +1,7 @@ + Investigate GCC/Clang builtin atomic operations? ++ Implement more type operators in dbg, mainly intmax/uintmax and size_t + + Add in mapping the same memory to two different processes + Create sensible thread handling + Add in init process loading diff --git a/arch/riscv32 b/arch/riscv32 new file mode 120000 index 0000000..11677ef --- /dev/null +++ b/arch/riscv32 @@ -0,0 +1 @@ +riscv64
\ No newline at end of file diff --git a/arch/riscv64/config.h b/arch/riscv64/config.h index 957f848..b52585b 100644 --- a/arch/riscv64/config.h +++ b/arch/riscv64/config.h @@ -14,11 +14,10 @@ #define PM_STACK_SIZE (SZ_256K) #define PM_STACK_TOP (PM_STACK_BASE + PM_STACK_SIZE) +#if __riscv_xlen == 64 +/* 64bit */ #define VM_DMAP (0xffffffc000000000) /* testing for now */ #define VM_KERN (VM_DMAP + SZ_256K) -#define TMP_PTE (-SZ_2G) -#define ROOT_PTE (0UL) -#define ROOT_REGION (SZ_4K) #define IO_PAGE 511UL #define KSTART_PAGE 256UL @@ -32,3 +31,24 @@ #define PROC_STACK_TOP (SZ_256G) #define PROC_STACK_BASE (SZ_256G - SZ_1G) +#else +/* 32bit */ +/* TODO: figure this stuff out */ +#define VM_DMAP (0x000000000) +#define VM_KERN (VM_DMAP + SZ_256K) +#define ROOT_PTE (0UL) +#define ROOT_REGION (SZ_4K) + +#define IO_PAGE 1023UL +#define KSTART_PAGE 512UL +#define CSTACK_PAGE 511UL + +/* assume Sv39, probably wouldn't be too difficult to use runtime parameters + * instead. First 4K is reserved for NULL, but I suppose it could be mapped + * later if *absolutely* necessary. */ +#define UVMEM_START (SZ_4K) +#define UVMEM_END (SZ_4G - SZ_8M) + +#define PROC_STACK_TOP (SZ_4G) +#define PROC_STACK_BASE (SZ_4G - SZ_8M) +#endif diff --git a/arch/riscv64/include/types.h b/arch/riscv64/include/types.h index 3e1c08b..59a2762 100644 --- a/arch/riscv64/include/types.h +++ b/arch/riscv64/include/types.h @@ -3,7 +3,7 @@ #include <apos/types.h> -typedef size_t vm_t; -typedef size_t pm_t; +typedef uintptr_t vm_t; +typedef uintptr_t pm_t; #endif /* APOS_RISCV_TYPES_H */ diff --git a/arch/riscv64/include/vmem.h b/arch/riscv64/include/vmem.h index 115f2b0..4446aef 100644 --- a/arch/riscv64/include/vmem.h +++ b/arch/riscv64/include/vmem.h @@ -4,6 +4,8 @@ #include <apos/types.h> #include <apos/attrs.h> +#define RISCV_NUM_LEAVES (4096 / sizeof(void *)) + #define VM_V (1 << 0) #define VM_R (1 << 1) #define VM_W (1 << 2) @@ -19,8 +21,8 @@ enum mm_mode { Sv32, }; -struct __packed vm_branch { - struct vm_branch *leaf[512]; +struct vm_branch { + struct vm_branch *leaf[RISCV_NUM_LEAVES]; }; #endif /* APOS_RISCV_VMAP_H */ diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c index f844dbb..b28c581 100644 --- a/arch/riscv64/init/init.c +++ b/arch/riscv64/init/init.c @@ -6,11 +6,7 @@ #include <csr.h> /* assume 64 bit for now */ -struct __packed init_vmem { - int *leaf[512]; -}; - -struct init_vmem *root_branch; +struct vm_branch *root_branch; #define to_pte(a, f) (((a) >> 12) << 10 | (f)) @@ -20,23 +16,23 @@ void init_bootmem() size_t flags = VM_V | VM_X | VM_R | VM_W; extern char *__init_start; - root_branch = (struct init_vmem *)align_down( - (size_t)&__init_start - SZ_4K, SZ_4K); + root_branch = (struct vm_branch *)align_down( + (uintptr_t)&__init_start - SZ_4K, SZ_4K); /* direct mapping (temp) */ for (size_t i = 0; i < CSTACK_PAGE; ++i) - root_branch->leaf[i] = (int *)to_pte(SZ_1G * i, flags); + root_branch->leaf[i] = (struct vm_branch *)to_pte(SZ_1G * i, flags); /* kernel (also sort of direct mapping) */ flags |= VM_G; for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i) root_branch->leaf[i] = - (int *)to_pte(RAM_BASE + SZ_1G * (i - 256), flags); + (struct vm_branch *)to_pte(RAM_BASE + SZ_1G * (i - 256), flags); /* kernel IO, map to 0 for now, will be updated in the future */ - root_branch->leaf[IO_PAGE] = (int *)to_pte(0, flags); + root_branch->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags); - csr_write(CSR_SATP, SATP_MODE_Sv39 | ((size_t)root_branch >> 12)); + csr_write(CSR_SATP, SATP_MODE_Sv39 | ((uintptr_t)root_branch >> 12)); } void move_kernel() @@ -44,7 +40,7 @@ void move_kernel() extern char *__init_end; extern char *__kernel_size; - size_t sz = (size_t)&__kernel_size; + unsigned long sz = (unsigned long)&__kernel_size; char *src = (char *)&__init_end; char *dst = (char *)VM_KERN; for (size_t i = 0; i < sz; ++i) diff --git a/arch/riscv64/source.mk b/arch/riscv64/source.mk index d1986d4..ce229a4 100644 --- a/arch/riscv64/source.mk +++ b/arch/riscv64/source.mk @@ -4,7 +4,8 @@ INIT_SOURCES += arch/riscv64/init/*.[cS] CLEANUP_CMD := ./arch/riscv64/conf/rmimage.sh -ARCH_FLAGS := -mcmodel=medany +ARCH_CFLAGS := -mcmodel=medany -fno-strict-aliasing +ARCH_LDFLAGS := # llvm compilation doesn't seem to work, either bfd reads the object files wrong # and outputs incorrect symbols or lld handles relocations in a dumb way. Only diff --git a/include/apos/types.h b/include/apos/types.h index 01c5317..d413957 100644 --- a/include/apos/types.h +++ b/include/apos/types.h @@ -37,9 +37,13 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t; typedef __INTPTR_TYPE__ intptr_t; typedef __UINTPTR_TYPE__ uintptr_t; -/* sort of unconventional, but should be fine */ -typedef uintmax_t size_t; -typedef intmax_t ssize_t; +#if __SIZE_WIDTH__ == 64 +typedef uint64_t size_t; +typedef int64_t ssize_t; +#else +typedef uint32_t size_t; +typedef int32_t ssize_t; +#endif #define INT8_C __INT8_C #define INT16_C __INT16_C diff --git a/include/apos/utils.h b/include/apos/utils.h index af0534a..1d1d6dd 100644 --- a/include/apos/utils.h +++ b/include/apos/utils.h @@ -28,7 +28,7 @@ #if __has_builtin(__builtin_offsetof) #define offsetof(type, member) __builtin_offsetof(type, member) #else -#define offsetof(type, member) ((size_t) & ((type *)0)->member) +#define offsetof(type, member) ((uintptr_t) & ((type *)0)->member) #endif #if __has_builtin(__builtin_expect) @@ -49,12 +49,12 @@ #include <apos/types.h> -static inline size_t align_up(size_t val, size_t a) +static inline uintptr_t align_up(uintptr_t val, uintptr_t a) { if (!a) return val; - size_t rem = val % a; + uintptr_t rem = val % a; if (rem == 0) return val; @@ -62,7 +62,7 @@ static inline size_t align_up(size_t val, size_t a) return val + a - rem; } -static inline size_t align_down(size_t val, size_t a) +static inline uintptr_t align_down(uintptr_t val, uintptr_t a) { if (!a) return val; @@ -70,7 +70,7 @@ static inline size_t align_down(size_t val, size_t a) return val - (val % a); } -static inline bool aligned(size_t val, size_t a) +static inline bool aligned(uintmax_t val, uintmax_t a) { if (!a) return true; @@ -78,7 +78,7 @@ static inline bool aligned(size_t val, size_t a) return val % a == 0; } -static inline size_t asciinum(char c) +static inline int asciinum(char c) { if (c >= '0' && c <= '9') return c - '0'; @@ -90,7 +90,7 @@ static inline size_t asciinum(char c) return 0; } -static inline size_t convnum(const char *c, size_t len, size_t base) +static inline uintmax_t convnum(const char *c, size_t len, size_t base) { size_t multiplier = 1; size_t sum = 0; diff --git a/lib/fdt_dbg.c b/lib/fdt_dbg.c index 296a8de..bf8e2d9 100644 --- a/lib/fdt_dbg.c +++ b/lib/fdt_dbg.c @@ -76,7 +76,7 @@ static void __print_prop_value(const void *data, int len) const int32_t *p = (const int32_t *)data; dbg("<"); for (int i = 0; i < len / 4; ++i) - dbg("%#08x%s", fdt32_to_cpu(p[i]), + dbg("%#08x%s", (unsigned int)fdt32_to_cpu(p[i]), i < (len / 4 - 1) ? " " : ""); dbg(">"); @@ -84,7 +84,7 @@ static void __print_prop_value(const void *data, int len) const int32_t *p = (const int32_t *)data; dbg("["); for (int i = 0; i < len / 4; ++i) - dbg("%#02x%s", fdt32_to_cpu(p[i]), + dbg("%#02x%s", (unsigned int)fdt32_to_cpu(p[i]), i < (len / 4 - 1) ? " " : ""); dbg("]"); diff --git a/lib/ubsan.c b/lib/ubsan.c index 906ba46..7f4df2a 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -71,8 +71,8 @@ struct tu_invalid_builtin_data { static void tu_print_location(const char *message, struct tu_source_location loc) { - bug("ubsan: %s at file %s, line %d, column %d\n", message, loc.file, - loc.line, loc.column); + bug("ubsan: %s at file %s, line %ju, column %ju\n", message, loc.file, + (uintmax_t)loc.line, (uintmax_t)loc.column); } void __ubsan_handle_add_overflow(struct tu_overflow_data *data) |
