aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--arch/riscv64/conf/init-link.S5
-rw-r--r--arch/riscv64/conf/kernel-link.S5
-rw-r--r--arch/riscv64/config.h4
-rw-r--r--arch/riscv64/init/init.c15
5 files changed, 28 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a647267..3c29758 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ DEBUGFLAGS != [ $(RELEASE) ] \
&& echo "-flto -O2 -g -DNDEBUG" \
|| echo "-O0 -g -DDEBUG"
-CFLAGS = -ffreestanding -nostdlib -std=c17 -Wall -Wextra -Wvla -D$(ARCH)
+CFLAGS = -ffreestanding -nostdlib -static -fno-pie -std=c17 -Wall -Wextra -Wvla -D$(ARCH)
DEPFLAGS = -MT $@ -MMD -MP -MF $@.d
LINTFLAGS = -fsyntax-only
PREPROCESS = -E
@@ -47,7 +47,8 @@ LINK_FLAGS := $(LDFLAGS) $(ARCH_LDFLAGS)
INCLUDE_FLAGS := -I include -include config.h -include arch/$(ARCH)/config.h
# This makes sure .bss is loaded into the binary
-OBJCOPY_FLAGS ?= -Obinary --set-section-flags .bss=alloc,load,contents
+OBJCOPY_FLAGS ?= -Obinary -R .garbage \
+ --set-section-flags .bss=alloc,load,contents
COMPILE = $(COMPILER) $(DEBUGFLAGS)\
$(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS)
diff --git a/arch/riscv64/conf/init-link.S b/arch/riscv64/conf/init-link.S
index ac7f858..f827245 100644
--- a/arch/riscv64/conf/init-link.S
+++ b/arch/riscv64/conf/init-link.S
@@ -31,4 +31,9 @@ SECTIONS {
__init_end = . ;
__kernel_size = <KERNEL_SIZE>;
+
+ .garbage : {
+ *(.note*)
+ *(.riscv.attributes)
+ }
}
diff --git a/arch/riscv64/conf/kernel-link.S b/arch/riscv64/conf/kernel-link.S
index 5673a64..2f000c9 100644
--- a/arch/riscv64/conf/kernel-link.S
+++ b/arch/riscv64/conf/kernel-link.S
@@ -26,4 +26,9 @@ SECTIONS {
}
__kernel_end = .;
+
+ .garbage : {
+ *(.note*)
+ *(.riscv.attributes)
+ }
}
diff --git a/arch/riscv64/config.h b/arch/riscv64/config.h
index 5ea5482..7606e38 100644
--- a/arch/riscv64/config.h
+++ b/arch/riscv64/config.h
@@ -98,7 +98,7 @@
#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)
+#define RPC_STACK_TOP (SZ_4G)
+#define RPC_STACK_BASE (SZ_4G - SZ_8M)
#endif
#endif /* APOS_RISCV_CONFIG_H */
diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c
index c91d192..0ea1f37 100644
--- a/arch/riscv64/init/init.c
+++ b/arch/riscv64/init/init.c
@@ -42,19 +42,30 @@ static void init_bootmem()
* @todo Allocate root_branch statically? */
root_branch = (struct vmem *)align_up(top, SZ_4K);
+#if defined(riscv64)
+ const size_t top_size = SZ_1G;
+#else
+ const size_t top_size = SZ_4M;
+#endif
+
/* direct mapping (temp) */
for (size_t i = 0; i < CSTACK_PAGE; ++i)
- root_branch->leaf[i] = (struct vmem *)to_pte(SZ_1G * i, flags);
+ root_branch->leaf[i] = (struct vmem *)to_pte(top_size * 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] = (struct vmem *)to_pte(
- RAM_BASE + SZ_1G * (i - 256), flags);
+ RAM_BASE + top_size * (i - KSTART_PAGE), flags);
/* kernel IO, map to 0 for now, will be updated in the future */
root_branch->leaf[IO_PAGE] = (struct vmem *)to_pte(0, flags);
+#if defined(riscv64)
+ const uintmax_t mode = SATP_MODE_Sv39;
+#else
+ const uintmax_t mode = SATP_MODE_Sv32;
+#endif
csr_write(CSR_SATP, SATP_MODE_Sv39 | ((uintptr_t)root_branch >> 12));
}