Skip to content

Commit

Permalink
riscv: fix riscv64 build
Browse files Browse the repository at this point in the history
  • Loading branch information
Supercip971 committed Nov 20, 2021
1 parent 8d8c256 commit e31aeee
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
4 changes: 3 additions & 1 deletion build/toolchain/archs/riscv64.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

ARCH_CFLAGS = \
-march=rv64imafdc \
-D__$(CONFIG_BOARD)=1
-D__$(CONFIG_BOARD)=1 \
-mno-relax

USER_AS=$(CONFIG_ARCH)-elf-as
USER_ASFLAGS=

Expand Down
2 changes: 1 addition & 1 deletion build/toolchain/gnu/.build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ USER_KLDFLAGS= \
build/toolchain/gnu/local/lib/gcc/$(CONFIG_ARCH)-elf/11.1.0/libgcc.a

USER_ULDFLAGS= \
-Tsources/embed/brutal/$(CONFIG_ARCH)/link.ld \
-Tsources/embed/brutal/$(CONFIG_ARCH)/$(CONFIG_BOARD)/link.ld \
-z max-page-size=0x1000 \
$(ARCH_LDFLAGS) \
build/toolchain/gnu/local/lib/gcc/$(CONFIG_ARCH)-elf/11.1.0/libgcc.a
Expand Down
6 changes: 3 additions & 3 deletions build/toolchain/llvm/.build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ USER_CFLAGS= \
$(CFLAGS_STD) \
$(CFLAGS_OPT) \
$(CFLAGS_WARN) \
$(ARCH_CFLAGS) \
$(USER_CFLAGS_INC) \
-ffreestanding

Expand All @@ -59,12 +60,12 @@ USER_UCFLAGS= \

USER_LD=ld.lld
USER_KLDFLAGS= \
-Tsources/embed/kernel/$(CONFIG_ARCH)/link.ld \
-Tsources/embed/kernel/$(CONFIG_ARCH)/$(CONFIG_BOARD)/link.ld \
-z max-page-size=0x1000 \
$(ARCH_LDFLAGS)

USER_ULDFLAGS= \
-Tsources/embed/brutal/$(CONFIG_ARCH)/link.ld \
-Tsources/embed/brutal/$(CONFIG_ARCH)/$(CONFIG_BOARD)/link.ld \
-z max-page-size=0x1000 \
$(ARCH_LDFLAGS)

Expand All @@ -75,7 +76,6 @@ endif

USER_ARFLAGS=rcs


ifeq ($(GEN_COVERAGE), yes)
HOST_CFLAGS += \
-fprofile-instr-generate -fcoverage-mapping
Expand Down
8 changes: 1 addition & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,13 @@ include sources/loader/.build.mk
.PHONY: all
all: $(ALL)

ifeq ($(QEMU_BOOT_METHOD), kernel)

run: $(ISO)
run-riscv: $(KERNEL)
qemu-system-$(CONFIG_ARCH) \
$(QEMU_ARGS) \
-serial mon:stdio \
-no-reboot \
-no-shutdown \
-kernel $(KERNEL)
-hda $(ISO)

else ifeq ($(QEMU_BOOT_METHOD), iso)

run: $(ISO)
qemu-system-$(CONFIG_ARCH) \
Expand All @@ -83,7 +78,6 @@ run: $(ISO)
-no-shutdown \
-cdrom $(ISO)

endif

.PHONY: clean
clean:
Expand Down
8 changes: 4 additions & 4 deletions sources/embed/kernel/riscv64/unleashed/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ ENTRY(_kstart)

MEMORY
{
lim (airwx) : ORIGIN = 0x8000000, LENGTH = 0x1e0000
ram (airwx) : ORIGIN = 0x8000000, LENGTH = 0x1e0000
rom (irx!wa) : ORIGIN = 0x20000000, LENGTH = 0x10000000
lim (arwx) : ORIGIN = 0x8000000, LENGTH = 0x1e0000
ram (arwx) : ORIGIN = 0x8000000, LENGTH = 0x1e0000
rom (rx!wa) : ORIGIN = 0x20000000, LENGTH = 0x10000000
}

PHDRS
Expand Down Expand Up @@ -296,7 +296,7 @@ SECTIONS
PROVIDE( metal_segment_heap_target_start = . );
/* If __heap_max is defined, grow the heap to use the rest of RAM,
* otherwise set the heap size to __heap_size */
. = DEFINED(__heap_max) ? MIN( LENGTH(ram) - ( . - ORIGIN(ram)) , 0x10000000) : __heap_size;
. = DEFINED(__heap_max) ? MIN( LENGTH(ram) - ( . - ORIGIN(ram)) , 0x10000000) : . + __heap_size;
PROVIDE( metal_segment_heap_target_end = . );
PROVIDE( _heap_end = . );
PROVIDE( __heap_end = . );
Expand Down
7 changes: 7 additions & 0 deletions sources/embed/riscv64/backtrace.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "embed/arch.h"

size_t arch_backtrace(MAYBE_UNUSED uintptr_t *buf, MAYBE_UNUSED size_t cap)
{
return 0;
}

16 changes: 16 additions & 0 deletions sources/embed/riscv64/copy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <embed/arch.h>

void *arch_mem_copy(void *to, void const *from, size_t size)
{

uint8_t *dest = (uint8_t *)to;
uint8_t const *src = (uint8_t const *)from;

for (size_t i = 0; i < size; i++)
{
dest[i] = src[i];
}

return to;
}

14 changes: 14 additions & 0 deletions sources/embed/riscv64/set.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <embed/arch.h>

void *arch_mem_set(void *d, uint8_t s, size_t c)
{
uint8_t *dest = (uint8_t *)d;

for (size_t i = 0; i < c; i++)
{
dest[i] = s;
}

return d;
}

2 changes: 1 addition & 1 deletion sources/kernel/riscv64/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void pmm_initialize(MAYBE_UNUSED Handover const *handover)
{
}

PmmResult pmm_alloc(MAYBE_UNUSED size_t size)
PmmResult pmm_alloc(MAYBE_UNUSED size_t size, MAYBE_UNUSED bool upper)
{
return OK(PmmResult, (PmmRange){});
}
Expand Down

0 comments on commit e31aeee

Please sign in to comment.