Skip to content

Commit

Permalink
Merge pull request #120 from pulp-platform/llvm-support
Browse files Browse the repository at this point in the history
This commit adds support for compiling with the PULP LLVM toolchain.
  • Loading branch information
NBruschi committed Nov 2, 2022
2 parents b1f7381 + 68e8c94 commit e30d78e
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 114 deletions.
8 changes: 7 additions & 1 deletion configs/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ if [ -n "$PULP_RISCV_GCC_TOOLCHAIN_BASE" ]; then
export PULP_RISCV_GCC_TOOLCHAIN=$PULP_RISCV_GCC_TOOLCHAIN_BASE/1.3
fi

export PATH="$PULP_RISCV_GCC_TOOLCHAIN/bin":"$PULP_SDK_HOME/tools/bin":$PATH
if [ -n "$PULP_RISCV_GCC_TOOLCHAIN" ]; then
export PATH="$PULP_RISCV_GCC_TOOLCHAIN/bin":"$PULP_SDK_HOME/tools/bin":$PATH
fi

if [ -n "$PULP_RISCV_LLVM_TOOLCHAIN" ]; then
export PATH="$PULP_RISCV_LLVM_TOOLCHAIN/bin":"$PULP_SDK_HOME/tools/bin":$PATH
fi

# keep compatibility with gap_sdk
export GAP_SDK_HOME=$PULP_SDK_HOME
Expand Down
2 changes: 1 addition & 1 deletion rtos/pmsis/pmsis_bsp/fs/read_fs/read_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void __pi_fs_free(pi_read_fs_t *fs)
static void __pi_fs_mount_step(void *arg)
{
pi_read_fs_t *fs = (pi_read_fs_t *) arg;
const pi_partition_table_t partition_table = NULL;
pi_partition_table_t partition_table = NULL;
const pi_partition_t *readfs_partition = NULL;
pi_err_t rc;

Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/include/pos/data/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#ifndef LANGUAGE_ASSEMBLY

// We cannot use tiny attribute if we use a generic riscv toolchain or LLVM or we there is fc specific memeory (TCDM or L2)
#if (defined(ARCHI_HAS_FC_TCDM) || defined(ARCHI_HAS_L2_ALIAS)) && !defined(__LLVM__) && !defined(__RISCV_GENERIC__) && defined(CONFIG_NO_STD_RELOC)
#if (defined(ARCHI_HAS_FC_TCDM) || defined(ARCHI_HAS_L2_ALIAS)) && !defined(__RISCV_GENERIC__) && defined(CONFIG_NO_STD_RELOC)
#define POS_FC_TINY_ATTRIBUTE __attribute__ ((tiny))
#else
#define POS_FC_TINY_ATTRIBUTE
Expand Down
5 changes: 4 additions & 1 deletion rtos/pulpos/common/kernel/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pos_init_entry:
andi a1, a0, 0x1f
srli a0, a0, 5
li a2, ARCHI_FC_CID
bne a0, a2, pos_pe_start
# bne a0, a2, pos_pe_start
beq a0, a2, label0
j pos_pe_start
label0:

#endif

Expand Down
2 changes: 2 additions & 0 deletions rtos/pulpos/common/kernel/soc_event_v2_itc.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
sw x10, 8(sp)
sw x11, 12(sp)
sw x12, 16(sp)
sw t0, 20(sp)



Expand Down Expand Up @@ -125,5 +126,6 @@ pos_soc_event_handler_end_asm:
lw x10, 8(sp)
lw x11, 12(sp)
lw x12, 16(sp)
lw t0, 20(sp)
add sp, sp, 128
mret
2 changes: 2 additions & 0 deletions rtos/pulpos/common/kernel/task_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pos_task_remote_enqueue:
sw a0, -12(sp)
sw a1, -16(sp)
sw a2, -20(sp)
sw t0, -24(sp)

li x8, ARCHI_NB_CLUSTER
la x9, pos_cluster
Expand Down Expand Up @@ -129,6 +130,7 @@ pos_task_remote_enqueue_event_loop_cluster_continue:
lw a0, -12(sp)
lw a1, -16(sp)
lw a2, -20(sp)
lw t0, -24(sp)

mret

Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/lib/omp/omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void __rt_omp_init(int exec_main)

initTeam(_this, &_this->plainTeam);

#ifdef __LLVM__
#ifdef __clang__
_this->numThreads = 0;
#endif

Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/lib/omp/ompRt.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct {
typedef struct {
//ompTask_t *taskPool;
omp_team_t plainTeam;
#ifdef __LLVM__
#ifdef __clang__
int numThreads;
#endif
unsigned short coreMask;
Expand Down
7 changes: 6 additions & 1 deletion rtos/pulpos/common/rules/pulpos/default_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ifdef PULP_RISCV_GCC_TOOLCHAIN
PULP_CC := $(PULP_RISCV_GCC_TOOLCHAIN)/bin/$(PULP_CC)
PULP_LD := $(PULP_RISCV_GCC_TOOLCHAIN)/bin/$(PULP_LD)
PULP_AR := $(PULP_RISCV_GCC_TOOLCHAIN)/bin/$(PULP_AR)
PULP_CFLAGS += -fno-jump-tables -fno-tree-loop-distribute-patterns
endif
ifdef PULP_RISCV_LLVM_TOOLCHAIN
PULP_CC := $(PULP_RISCV_LLVM_TOOLCHAIN)/bin/clang
PULP_LD := $(PULP_RISCV_LLVM_TOOLCHAIN)/bin/$(PULP_LD)
PULP_AR := $(PULP_RISCV_LLVM_TOOLCHAIN)/bin/$(PULP_AR)
endif
endif
endif
Expand All @@ -37,7 +43,6 @@ VPATH = $(PULPOS_HOME) $(PULPOS_MODULES)

include $(PULPOS_HOME)/rules/pulpos/src.mk

PULP_CFLAGS += -fno-jump-tables -fno-tree-loop-distribute-patterns

ifeq '$(CONFIG_LIBC_MINIMAL)' '1'
PULP_APP_CFLAGS += -I$(PULPOS_HOME)/lib/libc/minimal/include
Expand Down
14 changes: 14 additions & 0 deletions rtos/pulpos/pulp/rules/pulpos/targets/pulp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ CONFIG_NB_CLUSTER_PE ?= 8

PULP_LDFLAGS +=
PULP_CFLAGS += -D__riscv__

ifneq ($(and $(PULP_RISCV_GCC_TOOLCHAIN),$(PULP_RISCV_LLVM_TOOLCHAIN)),)
$(error PULP_RISCV_GCC_TOOLCHAIN and PULP_RISCV_LLVM_TOOLCHAIN cannot be set both at the same time)
endif

ifdef PULP_RISCV_GCC_TOOLCHAIN
PULP_ARCH_CFLAGS ?= -march=rv32imcxgap9 -mPE=$(CONFIG_NB_CLUSTER_PE) -mFC=1
PULP_ARCH_LDFLAGS ?= -march=rv32imcxgap9 -mPE=$(CONFIG_NB_CLUSTER_PE) -mFC=1
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imcxgap9
endif

ifdef PULP_RISCV_LLVM_TOOLCHAIN
PULP_ARCH_CFLAGS ?= -target riscv32-unknown-elf -march=rv32imcxpulpv2 --sysroot=${PULP_RISCV_LLVM_TOOLCHAIN}/riscv32-unknown-elf -ffreestanding
PULP_ARCH_LDFLAGS ?= -march=rv32imcxpulpv2
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imcxpulpv2
endif

PULP_CFLAGS += -fdata-sections -ffunction-sections -include pos/chips/pulp/config.h -I$(PULPOS_PULP_HOME)/include/pos/chips/pulp -I$(PULP_EXT_LIBS)/include
ifeq '$(CONFIG_OPENMP)' '1'
PULP_CFLAGS += -fopenmp -mnativeomp
Expand Down
4 changes: 2 additions & 2 deletions rtos/pulpos/pulp_archi/include/archi/gap_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
static inline unsigned int __attribute__ ((always_inline)) ExtInsMaskFast_archi(unsigned int Size, unsigned int Offset) { return ((((Size-1))<<5)|(Offset)); }
static inline unsigned int __attribute__ ((always_inline)) ExtInsMaskSafe_archi(unsigned int Size, unsigned int Offset) { return ((((Size-1)&0x1F)<<5)|(Offset&0x1F)); }

#if defined(__riscv__) && !defined(__LLVM__) && !defined(RV_ISA_RV32)
#if defined(__riscv__) && !defined(RV_ISA_RV32)
#define GAP_WRITE_VOL(base, offset, value) __builtin_pulp_write_base_off_v((value), (base), (offset))
#define GAP_WRITE(base, offset, value) __builtin_pulp_OffsetedWrite((value), (int *)(base), (offset))
#define GAP_READ(base, offset) __builtin_pulp_OffsetedRead((int *)(base), (offset))
Expand All @@ -36,4 +36,4 @@ static inline unsigned int __attribute__ ((always_inline)) ExtInsMaskSafe_archi(
#define GAP_BEXTRACTU(src,size,off) __builtin_pulp_bextractu((src), (size), (off))
#define GAP_BEXTRACT(src,size,off) __builtin_pulp_bextract((src), (size), (off))

#endif
#endif
2 changes: 1 addition & 1 deletion rtos/pulpos/pulp_archi/include/archi/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define archi_read(add) (*(volatile unsigned int *)(long)(add))


#if defined(__riscv__) && !defined(__LLVM__) && !defined(RV_ISA_RV32)
#if defined(__riscv__) && !defined(RV_ISA_RV32)
#define ARCHI_WRITE_VOL(base, offset, value) __builtin_pulp_write_base_off_v((value), (base), (offset))
#define ARCHI_WRITE(base, offset, value) __builtin_pulp_OffsetedWrite((value), (int *)(base), (offset))
#define ARCHI_READ(base, offset) __builtin_pulp_OffsetedRead((int *)(base), (offset))
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/pulp_hal/include/hal/dma/mchan_v6.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static inline unsigned int plp_dma_status();

/// @cond IMPLEM

#if defined(__riscv__) && !defined(RV_ISA_RV32) && !defined(__LLVM__)
#if defined(__riscv__) && !defined(RV_ISA_RV32)
#define DMA_WRITE(value, offset) __builtin_pulp_OffsetedWrite((value), (int *)ARCHI_DEMUX_PERIPHERALS_ADDR, ARCHI_MCHAN_DEMUX_OFFSET + (offset))
#define DMA_READ(offset) __builtin_pulp_OffsetedRead((int *)ARCHI_DEMUX_PERIPHERALS_ADDR, ARCHI_MCHAN_DEMUX_OFFSET + (offset))
#else
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/pulp_hal/include/hal/dma/mchan_v7.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static inline unsigned int plp_dma_status();

/// @cond IMPLEM

#if defined(__riscv__) && !defined(RV_ISA_RV32) && !defined(__LLVM__)
#if defined(__riscv__) && !defined(RV_ISA_RV32)
#define DMA_WRITE(value, offset) __builtin_pulp_OffsetedWrite((value), (int *)ARCHI_MCHAN_EXT_ADDR, (offset))
#define DMA_READ(offset) __builtin_pulp_OffsetedRead((int *)ARCHI_MCHAN_EXT_ADDR, (offset))
#else
Expand Down
21 changes: 4 additions & 17 deletions rtos/pulpos/pulp_hal/include/hal/eu/eu_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,20 @@
\param offset The offset in the event unit where to load from. Depending on this offset, this will trigger different behaviors (barrier, wait, wait&clear, etc).
\return The loaded value, after the core has been waken-up. This value depends on the feature which is accessed.
*/
#if defined(__OPTIMIZE__)
static inline unsigned int evt_read32(unsigned int base, unsigned int offset)
{
unsigned int value;
#if !defined(__LLVM__) && ((defined(OR1K_VERSION) && OR1K_VERSION >= 5) || (defined(RISCV_VERSION) && RISCV_VERSION >= 4)) && !defined(CONFIG_PULP)
value = __builtin_pulp_event_unit_read_fenced((int *)base, offset);
#if ((defined(OR1K_VERSION) && OR1K_VERSION >= 5) || (defined(RISCV_VERSION) && RISCV_VERSION >= 4)) && !defined(CONFIG_PULP)
__asm__ __volatile__ ("" : : : "memory");
value = __builtin_pulp_event_unit_read((int *)base, offset);
__asm__ __volatile__ ("" : : : "memory");
#else
__asm__ __volatile__ ("" : : : "memory");
value = pulp_read32(base + offset);
__asm__ __volatile__ ("" : : : "memory");
#endif
return value;
}
#else
#define evt_read32(base,offset) \
({ \
unsigned int value; \
#if !defined(CONFIG_PULP)
value = __builtin_pulp_event_unit_read_fenced((int *)base, offset); \
#else
__asm__ __volatile__ ("" : : : "memory"); \
value = pulp_read32(base + offset); \
__asm__ __volatile__ ("" : : : "memory"); \
#endif
value; \
})
#endif

/** Get event status.
Return the value of the event status register. This register contains one bit per event, 1 means the event is set. Note that this register is actually used
Expand Down
8 changes: 2 additions & 6 deletions rtos/pulpos/pulp_hal/include/hal/pulp_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define pulp_write32(add, val_) (*(volatile unsigned int *)(long)(add) = val_)
#define pulp_write(add, val_) (*(volatile unsigned int *)(long)(add) = val_)

#if 1
#if !defined(__clang__)

#define pulp_read8(add) (*(volatile unsigned char *)(long)(add))
#define pulp_read16(add) (*(volatile unsigned short *)(long)(add))
Expand All @@ -37,7 +37,6 @@ static inline uint8_t pulp_read8(uint32_t add)
{
__asm__ __volatile__ ("" : : : "memory");
uint8_t result = *(volatile uint8_t *)add;
asm volatile("l.nop;");
__asm__ __volatile__ ("" : : : "memory");
return result;
}
Expand All @@ -46,7 +45,6 @@ static inline uint16_t pulp_read16(uint32_t add)
{
__asm__ __volatile__ ("" : : : "memory");
uint16_t result = *(volatile uint16_t *)add;
asm volatile("nop;");
__asm__ __volatile__ ("" : : : "memory");
return result;
}
Expand All @@ -55,7 +53,6 @@ static inline uint32_t pulp_read32(uint32_t add)
{
__asm__ __volatile__ ("" : : : "memory");
uint32_t result = *(volatile uint32_t *)add;
asm volatile("nop;");
__asm__ __volatile__ ("" : : : "memory");
return result;
}
Expand All @@ -64,14 +61,13 @@ static inline uint32_t pulp_read(uint32_t add)
{
__asm__ __volatile__ ("" : : : "memory");
uint32_t result = *(volatile uint32_t *)add;
asm volatile("nop;");
__asm__ __volatile__ ("" : : : "memory");
return result;
}

#endif

#if defined(__riscv__) && !defined(RV_ISA_RV32) && !defined(__LLVM__)
#if defined(__riscv__) && !defined(RV_ISA_RV32)
#define IP_WRITE_VOL(base, offset, value) __builtin_pulp_write_base_off_v((value), (base), (offset))
#define IP_WRITE(base, offset, value) __builtin_pulp_OffsetedWrite((value), (int *)(base), (offset))
#if !defined(CONFIG_PULP)
Expand Down
42 changes: 1 addition & 41 deletions rtos/pulpos/pulp_hal/include/hal/riscv/riscv_v4.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@



#if defined(__OPTIMIZE__) && defined(CORE_PULP_BUILTINS) && !defined(__LLVM__)
#if defined(__OPTIMIZE__) && defined(CORE_PULP_BUILTINS)

static inline unsigned int hal_spr_read_then_clr(unsigned int reg, unsigned int val)
{
Expand All @@ -56,10 +56,6 @@ static inline unsigned int hal_spr_read(unsigned int reg)

#else

#if defined(__LLVM__)

#else

#define hal_spr_read_then_clr(reg,val) \
({ \
int state; \
Expand All @@ -86,29 +82,11 @@ do { \
result; \
})

#endif

#endif





#if defined(__LLVM__)

#define csr_read(csr) \
({ \
register unsigned int __v; \
__asm__ __volatile__ ("csrr %0, " #csr \
: "=r" (__v)); \
__v; \
})

#define hal_mepc_read() csr_read(0x341)

#else
#define hal_mepc_read() hal_spr_read(RV_CSR_MEPC)
#endif

static inline unsigned int core_id() {
int hart_id;
Expand Down Expand Up @@ -222,23 +200,6 @@ static inline __attribute__((always_inline)) unsigned int hal_is_fc() {



#if defined(__LLVM__)

static inline int hal_irq_disable()
{
return 0;
}

static inline void hal_irq_restore(int state)
{
}

static inline void hal_irq_enable()
{
}

#else

static inline int hal_irq_disable()
{
int irq = hal_spr_read_then_clr(0x300, 0x1<<3);
Expand All @@ -261,7 +222,6 @@ static inline void hal_irq_enable()
hal_spr_read_then_set(0x300, 0x1<<3);
}

#endif

/*
* PERFORMANCE COUNTERS
Expand Down
Loading

0 comments on commit e30d78e

Please sign in to comment.