aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-21 23:25:57 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-21 23:25:57 +0300
commit42451ed4718af3f93770feb201bd023625d69b3a (patch)
tree7f69bc86e0fc0591f176ca086db377e1cb99a718 /arch/riscv64
parent1a5248bb177242a34fd51efadb4af941853d5e35 (diff)
downloadkmi-42451ed4718af3f93770feb201bd023625d69b3a.tar.gz
kmi-42451ed4718af3f93770feb201bd023625d69b3a.zip
fix warnings on 32bit riscv
+ Will most probably not work on 32bit, but nice to make 'portable' code.
Diffstat (limited to 'arch/riscv64')
-rw-r--r--arch/riscv64/config.h26
-rw-r--r--arch/riscv64/include/types.h4
-rw-r--r--arch/riscv64/include/vmem.h6
-rw-r--r--arch/riscv64/init/init.c20
-rw-r--r--arch/riscv64/source.mk3
5 files changed, 39 insertions, 20 deletions
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