Skip to content

Support LLVM Toolchain #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions arch/riscv/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,49 @@ DEFINES := -DF_CPU=$(F_CLK) \
-DF_TIMER=$(F_TICK) \
-include config.h

ASFLAGS = -march=rv32imzicsr -mabi=ilp32
CFLAGS += -Wall -Wextra -Wshadow -Wno-unused-parameter -Werror
CROSS_COMPILE ?= riscv32-unknown-elf-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default value to riscv-none-elf- as xPack GNU RISC-V Embedded GCC is suggested.

CC_DEFAULT := $(CROSS_COMPILE)gcc
CC_IS_CLANG := $(shell $(CC_DEFAULT) --version 2>/dev/null | grep -qi clang && echo 1)
# Architecture flags
ARCH_FLAGS = -march=rv32imzicsr -mabi=ilp32

# Common compiler flags
CFLAGS += -Wall -Wextra -Werror -Wshadow -Wno-unused-parameter
CFLAGS += -O2 -std=gnu99
CFLAGS += -march=rv32imzicsr -mabi=ilp32
CFLAGS += $(ARCH_FLAGS)
CFLAGS += -mstrict-align -ffreestanding -nostdlib -fomit-frame-pointer
CFLAGS += $(INC_DIRS) $(DEFINES) -fdata-sections -ffunction-sections
ARFLAGS = r

# Linker flags
LDFLAGS = -melf32lriscv --gc-sections
LDSCRIPT = $(ARCH_DIR)/riscv32-qemu.ld
ifeq ($(CC_IS_CLANG),1)
CC = $(CROSS_COMPILE)clang
AS = $(CROSS_COMPILE)clang
LD = $(CROSS_COMPILE)ld.lld
DUMP = $(CROSS_COMPILE)llvm-objdump -M no-aliases
READ = $(CROSS_COMPILE)llvm-readelf
OBJ = $(CROSS_COMPILE)llvm-objcopy
SIZE = $(CROSS_COMPILE)llvm-size

CFLAGS += --target=riscv32-unknown-elf
CFLAGS += -Wno-unused-command-line-argument
ASFLAGS = --target=riscv32-unknown-elf
LDFLAGS = -m elf32lriscv
else
CC = $(CC_DEFAULT)
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
DUMP = $(CROSS_COMPILE)objdump -Mno-aliases
READ = $(CROSS_COMPILE)readelf
OBJ = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
LDFLAGS = -melf32lriscv
endif

CROSS_COMPILE ?= riscv-none-elf-
CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
DUMP = $(CROSS_COMPILE)objdump -Mno-aliases
READ = $(CROSS_COMPILE)readelf
OBJ = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
AR = $(CROSS_COMPILE)ar
ASFLAGS += $(ARCH_FLAGS)
LDFLAGS += --gc-sections

ARFLAGS = r
LDSCRIPT = $(ARCH_DIR)/riscv32-qemu.ld

HAL_OBJS := boot.o hal.o muldiv.o
HAL_OBJS := $(addprefix $(BUILD_KERNEL_DIR)/,$(HAL_OBJS))
Expand Down
4 changes: 2 additions & 2 deletions kernel/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ static inline uint16_t pipe_free_space_internal(const pipe_t *p)
return (p->mask + 1) - p->used;
}

static inline char pipe_get_byte(pipe_t *p)
static inline __attribute__((__unused__)) char pipe_get_byte(pipe_t *p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply do #include "private/utils.h" and use pre-defined UNUSED macro.

{
char val = p->buf[p->head];
p->head = (p->head + 1) & p->mask;
p->used--;
return val;
}

static inline void pipe_put_byte(pipe_t *p, char c)
static inline __attribute__((__unused__)) void pipe_put_byte(pipe_t *p, char c)
{
p->buf[p->tail] = c;
p->tail = (p->tail + 1) & p->mask;
Expand Down
2 changes: 0 additions & 2 deletions lib/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ void free(void *ptr)
static void selective_coalesce(void)
{
memblock_t *p = first_free;
uint32_t coalesced = 0;

while (p && p->next) {
/* Merge only when blocks are FREE *and* adjacent in memory */
uint8_t *pend = (uint8_t *) p + sizeof(memblock_t) + GET_SIZE(p);
if (!IS_USED(p) && !IS_USED(p->next) && pend == (uint8_t *) p->next) {
p->size = GET_SIZE(p) + sizeof(memblock_t) + GET_SIZE(p->next);
p->next = p->next->next;
coalesced++;
free_blocks_count--;
} else {
p = p->next;
Expand Down