diff --git a/target/sim/sw/device/Makefile b/target/sim/sw/device/Makefile index 1bab68e71..913514b75 100644 --- a/target/sim/sw/device/Makefile +++ b/target/sim/sw/device/Makefile @@ -7,6 +7,7 @@ # Add user applications to APPS variable APPS = blas/axpy APPS += blas/gemm +APPS += libomptarget_device TARGET ?= all diff --git a/target/sim/sw/device/apps/common.mk b/target/sim/sw/device/apps/common.mk index eff90e921..c29aa94d8 100644 --- a/target/sim/sw/device/apps/common.mk +++ b/target/sim/sw/device/apps/common.mk @@ -99,6 +99,9 @@ $(BUILDDIR): $(DEP): $(SRCS) | $(BUILDDIR) $(RISCV_CC) $(RISCV_CFLAGS) -MM -MT '$(ELF)' $< > $@ +$(BUILDDIR)/%.o: $(SRC_DIR)/%.c | $(BUILDDIR) + $(RISCV_CC) $(RISCV_CFLAGS) -c $< -o $@ + $(ELF): $(DEP) $(LD_SRCS) | $(BUILDDIR) $(RISCV_CC) $(RISCV_CFLAGS) $(RISCV_LDFLAGS) $(SRCS) -o $@ diff --git a/target/sim/sw/device/apps/libomptarget_device/Makefile b/target/sim/sw/device/apps/libomptarget_device/Makefile new file mode 100644 index 000000000..f08716972 --- /dev/null +++ b/target/sim/sw/device/apps/libomptarget_device/Makefile @@ -0,0 +1,30 @@ +# Copyright 2023 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Cyril Koenig + +# Usage of absolute paths is required to externally include this Makefile +MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +SRC_DIR := $(realpath $(MK_DIR)/src) + +APP ?= omptarget_device +SRCS ?= $(SRC_DIR)/main.c +INCDIRS += $(SRC_DIR) + +.PHONY: clean +clean: + +include ../common.mk + +OBJS := $(subst $(SRC_DIR), $(BUILDDIR), $(SRCS:.c=.o)) +LIB := $(BUILDDIR)/libomptarget_device.a + +$(BUILDDIR)/origin.ld: | $(BUILDDIR) + echo "L3_ORIGIN = 0x80000000;" > $(BUILDDIR)/origin.ld + +$(LIB): $(OBJS) | $(BUILDDIR) + $(RISCV_AR) $(RISCV_ARFLAGS) $@ $^ + +# For this target, only build the library +all: $(LIB) diff --git a/target/sim/sw/device/apps/libomptarget_device/link.ld b/target/sim/sw/device/apps/libomptarget_device/link.ld new file mode 100644 index 000000000..df1730b69 --- /dev/null +++ b/target/sim/sw/device/apps/libomptarget_device/link.ld @@ -0,0 +1,181 @@ +OUTPUT_ARCH(riscv) +ENTRY( _start ) +MEMORY +{ + LOCAL : ORIGIN = 0x70010000, LENGTH = 0x70000 + L2 : ORIGIN = 0x80000000, LENGTH = 0x0fffffff +} + + + +SECTIONS +{ + .init : + { + . = ALIGN(4); + KEEP( *(.init) ) + } > LOCAL + + + .fini : + { + . = ALIGN(4); + KEEP( *(.fini) ) + } > LOCAL + + .preinit_array : { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > LOCAL + + .init_array : { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + __CTOR_LIST__ = .; + LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) + KEEP(*(.ctors.start)) + KEEP(*(.ctors)) + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array )) + LONG(0) + __CTOR_END__ = .; + PROVIDE_HIDDEN (__init_array_end = .); + } > LOCAL + + .fini_array : { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + __DTOR_LIST__ = .; + LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) + KEEP(*(.dtors.start)) + KEEP(*(.dtors)) + LONG(0) + __DTOR_END__ = .; + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array )) + PROVIDE_HIDDEN (__fini_array_end = .); + } > LOCAL + + .boot : { + . = ALIGN(4); + *(.boot) + *(.boot.data) + } > LOCAL + + .rodata : { + . = ALIGN(4); + *(.rodata); + *(.rodata.*) + *(.srodata); + *(.srodata.*) + *(.eh_frame*) + } > LOCAL + + .shbss : { + . = ALIGN(4); + *(.shbss) + } > LOCAL + + .talias : { + } > LOCAL + + .gnu.offload_funcs : { + . = ALIGN(4); + KEEP(*(.gnu.offload_funcs)) + } > LOCAL + + .gnu.offload_vars : { + . = ALIGN(4); + KEEP(*(.gnu.offload_vars)) + } > LOCAL + + .stack : { + . = ALIGN(4); + . = ALIGN(16); + stack_start = .; + . = . + 0x1000; + stack = .; + } > LOCAL + + .data : { + . = ALIGN(4); + sdata = .; + _sdata = .; + *(.data_fc) + *(.data_fc.*) + *(.data); + *(.data.*) + *(.sdata); + *(.sdata.*) + *(.heapl2ram) + *(.fcTcdm) + *(.fcTcdm.*) + *(.fcTcdm_g) + *(.fcTcdm_g.*) + . = ALIGN(4); + edata = .; + _edata = .; + } > LOCAL + + .bss : { + . = ALIGN(8); + _bss_start = .; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(COMMON) + . = ALIGN(4); + _bss_end = .; + } > LOCAL + + __l2_priv0_end = ALIGN(4); + + /* + * LOCAL PRIVATE BANK1 + * + * Contains FC code + */ + + .vectors MAX(0x60010000,ALIGN(256)) : + { + __irq_vector_base = .; + KEEP(*(.vectors)) + } > LOCAL + + .text : + { + . = ALIGN(4); + _stext = .; + *(.text) + *(.text.*) + _etext = .; + *(.lit) + *(.shdata) + _endtext = .; + . = ALIGN(4); + } > LOCAL + + __l2_priv1_end = ALIGN(4); + + /* + * L2 SHARED BANKS + * + * Contains other data such as peripheral data and cluster code and data + */ + + .l2_data : + { + . = ALIGN(4); + *(.l2_data) + *(.l2_data.*) + *(.data_fc_shared) + *(.data_fc_shared.*) + . = ALIGN(4); + } > L2 + + __l2_shared_end = ALIGN(4); + +} diff --git a/target/sim/sw/device/apps/libomptarget_device/src/main.c b/target/sim/sw/device/apps/libomptarget_device/src/main.c new file mode 100644 index 000000000..379d14a6e --- /dev/null +++ b/target/sim/sw/device/apps/libomptarget_device/src/main.c @@ -0,0 +1,4 @@ + +int main() { + return 0; +} \ No newline at end of file diff --git a/target/sim/sw/device/apps/libomptarget_device/src/main.o b/target/sim/sw/device/apps/libomptarget_device/src/main.o new file mode 100644 index 000000000..f7685fc0f Binary files /dev/null and b/target/sim/sw/device/apps/libomptarget_device/src/main.o differ