Skip to content

Commit

Permalink
LLVMify pulp sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Scheremo committed Dec 1, 2023
1 parent 5e17eee commit b064312
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[submodule "tools/gvsoc"]
path = tools/gvsoc
url = https://github.com/gvsoc/gvsoc.git
url = git@github.com:Scheremo/gvsoc.git
6 changes: 3 additions & 3 deletions rtos/pmsis/pmsis_bsp/rules/pulp_sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export VEGA_SRC
all:
ifdef PULPOS
make -f rules/pulpos.mk build install
endif
endif

clean:
ifdef PULPOS
Expand All @@ -21,5 +21,5 @@ ifdef PULPOS
endif
ifdef SRC
mkdir -p $(TARGET_INSTALL_DIR)/src/pmsis_bsp
cp -r bsp camera display flash ram fs include zephyr $(TARGET_INSTALL_DIR)/src/pmsis_bsp
endif
cp -r bsp partition camera display flash ram fs include zephyr $(TARGET_INSTALL_DIR)/src/pmsis_bsp
endif
1 change: 1 addition & 0 deletions rtos/pmsis/pmsis_bsp/rules/pulpos/src.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CONFIG_HYPER = 1
endif

ifeq '$(CONFIG_READFS)' '1'
PULP_SRCS += $(BSP_FLASH_SRC)
PULP_SRCS += $(BSP_READFS_SRC)
CONFIG_FS = 1
endif
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/kernel/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "archi/pulp.h"

.section .text_l2
.section .text_l2, "ax", %progbits
.global pos_init_entry
pos_init_entry:

Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/kernel/irq_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#


.section .text_l2
.section .text_l2, "ax", %progbits

.global pos_irq_call_external_c_function
pos_irq_call_external_c_function:
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/kernel/soc_event_v2_itc.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <archi/pulp.h>


.section .text_l2
.section .text_l2, "ax", %progbits

#
# SOC event handler entry
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/kernel/task_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <pos/data/data.h>

.section .text_l2
.section .text_l2, "ax", %progbits

.global pos_task_push_asm
pos_task_push_asm:
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/common/kernel/time_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <pos/data/data.h>

.section .text_l2
.section .text_l2, "ax", %progbits

.global pos_time_timer_handler_asm
pos_time_timer_handler_asm:
Expand Down
30 changes: 25 additions & 5 deletions rtos/pulpos/common/rules/pulpos/default_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,40 @@ override config_args += $(foreach file, $(HOSTFS_FILES), --config-opt=flash/cont

define declare_app

$(eval PULP_APP_SRCS_$(1) += $(PULP_APP_SRCS) $(PULP_APP_FC_SRCS) $(PULP_SRCS) $(PULP_APP_CL_SRCS) $(PULP_CL_SRCS))
$(eval PULP_APP_ASM_SRCS_$(1) += $(PULP_APP_ASM_SRCS) $(PULP_ASM_SRCS) $(PULP_APP_CL_ASM_SRCS) $(PULP_CL_ASM_SRCS))
$(eval PULP_SDK_SRCS_SDK = $(PULP_CL_SRCS) $(PULP_SRCS))
$(eval PULP_SDK_ASM_SRCS_SDK = $(PULP_ASM_SRCS) $(PULP_CL_ASM_SRCS))
$(eval PULP_SDK_OBJS_SDK += $(patsubst %.c,$(TARGET_BUILD_DIR)/SDK/%.o,$(PULP_SDK_SRCS_SDK)))
$(eval PULP_SDK_OBJS_SDK += $(patsubst %.S,$(TARGET_BUILD_DIR)/SDK/%.o,$(PULP_SDK_ASM_SRCS_SDK)))
$(eval PULP_APP_CFLAGS_SDK += $(PULP_ARCH_CFLAGS) $(PULP_CFLAGS) $(PULP_APP_CFLAGS) -fno-inline-functions)

$(eval PULP_APP_SRCS_$(1) += $(PULP_APP_SRCS) $(PULP_APP_FC_SRCS) $(PULP_APP_CL_SRCS))
$(eval PULP_APP_ASM_SRCS_$(1) += $(PULP_APP_ASM_SRCS) $(PULP_APP_CL_ASM_SRCS))
$(eval PULP_APP_OBJS_$(1) += $(patsubst %.c,$(TARGET_BUILD_DIR)/$(1)/%.o,$(PULP_APP_SRCS_$(1))))
$(eval PULP_APP_OBJS_$(1) += $(patsubst %.S,$(TARGET_BUILD_DIR)/$(1)/%.o,$(PULP_APP_ASM_SRCS_$(1))))

$(eval PULP_APP_CFLAGS_$(1) += $(PULP_ARCH_CFLAGS) $(PULP_CFLAGS) $(PULP_APP_CFLAGS))
$(eval PULP_APP_LDFLAGS_$(1) += $(PULP_ARCH_LDFLAGS) $(PULP_LDFLAGS) $(PULP_APP_LDFLAGS))

-include $(PULP_APP_OBJS_$(1):.o=.d)

$(TARGET_BUILD_DIR)/SDK/%.o: %.c
@echo "CC $$<"
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_CC) -c $$< -o $$@ -MMD -MP -fno-inline-functions $(PULP_APP_CFLAGS_SDK)

$(TARGET_BUILD_DIR)/SDK/%.o: %.cpp
@echo "CXX $$<"
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_CC) -c $< -o $@ -MMD -MP $(PULP_APP_CFLAGS_SDK)

$(TARGET_BUILD_DIR)/SDK/%.o: %.S
@echo "CC $$<"
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_CC) -c $$< -o $$@ -MMD -MP -DLANGUAGE_ASSEMBLY $(PULP_APP_CFLAGS_SDK)

$(TARGET_BUILD_DIR)/$(1)/%.o: %.c
@echo "CC $$<"
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_CC) -c $$< -o $$@ -MMD -MP $(PULP_APP_CFLAGS_$(1))
$(V)$(PULP_CC) -c $$< -o $$@ -MMD -MP -fno-inline-functions $(PULP_APP_CFLAGS_$(1))

$(TARGET_BUILD_DIR)/$(1)/%.o: %.cpp
@echo "CXX $$<"
Expand All @@ -214,7 +234,7 @@ $(TARGET_BUILD_DIR)/$(1)/%.o: %.S
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_CC) -c $$< -o $$@ -MMD -MP -DLANGUAGE_ASSEMBLY $(PULP_APP_CFLAGS_$(1))

$(TARGET_BUILD_DIR)/$(1)/$(1): $(PULP_APP_OBJS_$(1))
$(TARGET_BUILD_DIR)/$(1)/$(1): $(PULP_APP_OBJS_$(1)) $(PULP_SDK_OBJS_SDK)
@echo "LD $$@"
$(V)mkdir -p `dirname $$@`
$(V)$(PULP_LD) -o $$@ $$^ -MMD -MP $(PULP_APP_LDFLAGS_$(1))
Expand Down
2 changes: 1 addition & 1 deletion rtos/pulpos/pulp/kernel/chips/pulp/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ SECTIONS
*(.data_tiny_l1.*)
*(.data_alias_l1)
*(.data_alias_l1.*)
} > L1_aliased AT> L2
} > L2_aliased AT> L2

.l1cluster_g (ORIGIN(L1) + SIZEOF(.data_tiny_l1)): {
. = ALIGN(4);
Expand Down
7 changes: 5 additions & 2 deletions rtos/pulpos/pulp/rules/pulpos/targets/pulp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ 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
PULP_LDFLAGS += -nostartfiles -nostdlib -Wl,--gc-sections -L$(PULP_EXT_LIBS) -L$(PULPOS_PULP_HOME)/kernel -Tchips/pulp/link.ld -lgcc
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_CFLAGS ?= -target riscv32-unknown-elf -march=rv32imcxpulpv2 --sysroot=${PULP_RISCV_LLVM_TOOLCHAIN}/picolibc/riscv -ffreestanding -ffunction-sections -fdata-sections -mno-relax
PULP_ARCH_LDFLAGS ?= -march=rv32imcxpulpv2
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imcxpulpv2
PULP_LDFLAGS += -z norelro -target riscv32-unknown-elf -march=rv32imcxpulpv2 --sysroot=${PULP_RISCV_LLVM_TOOLCHAIN}/picolibc/riscv -fuse-ld=lld -nostartfiles -L$(PULP_EXT_LIBS) -L$(PULPOS_PULP_HOME)/kernel -T$(PULPOS_PULP_HOME)/kernel/chips/pulp/link.ld
PULP_LD ?= clang
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
endif
PULP_LDFLAGS += -nostartfiles -nostdlib -Wl,--gc-sections -L$(PULP_EXT_LIBS) -L$(PULPOS_PULP_HOME)/kernel -Tchips/pulp/link.ld -lgcc


PULP_CC = riscv32-unknown-elf-gcc
PULP_AR ?= riscv32-unknown-elf-ar
Expand Down
1 change: 0 additions & 1 deletion tools/dpi-models/models/jtag/proxy/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <thread>
#include <sys/prctl.h>
#include <netinet/in.h>
#include <stdint.h>
#include <unistd.h>
Expand Down
6 changes: 4 additions & 2 deletions tools/dpi-models/src/dpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "dpi/tb_driver.h"




// NOTE for DPI models integration with Questasim.
//
// As vsim does not export symbols to dynamically loaded modules, we need
Expand Down Expand Up @@ -334,7 +332,11 @@ void *dpi_model_load(void *config, void *handle)

if (periph_api == NULL)
{
#if !(__APPLE__)
void *libperiph = dlopen("libpulpperiph.so", RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND);
#else
void *libperiph = dlopen("libpulpperiph.dylib", RTLD_NOW | RTLD_GLOBAL);
#endif
if (libperiph == NULL)
{
dpi_print(NULL, "ERROR, Failed to open Pulp periph models library with error:");
Expand Down
4 changes: 4 additions & 0 deletions tools/dpi-models/src/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ extern "C" void *model_load(void *_config, void *handle)

std::string module_name = module_config->get_str();

#if (!__APPLE__)
void *module = dlopen(module_name.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND);
#else
void *module = dlopen(module_name.c_str(), RTLD_NOW | RTLD_GLOBAL);
#endif
if (module == NULL)
{
dpi_fatal_stub(handle, "ERROR, Failed to open periph model (%s) with error: %s", module_name.c_str(), dlerror());
Expand Down
1 change: 0 additions & 1 deletion tools/dpi-models/src/telnet_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <mutex>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/prctl.h>
#include <netinet/in.h>
#include <poll.h>
#include <signal.h>
Expand Down
2 changes: 1 addition & 1 deletion tools/gvsoc
Submodule gvsoc updated 179 files

0 comments on commit b064312

Please sign in to comment.