diff --git a/cheshire/sw/Makefile b/cheshire/sw/Makefile new file mode 100644 index 000000000..4daa16dd8 --- /dev/null +++ b/cheshire/sw/Makefile @@ -0,0 +1,25 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Matteo Perotti +# +# Copy and compile vector software on Cheshire + +CHS_ROOT ?= $(realpath ../../../../../..) +ARA_SW := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +CHS_SW := $(CHS_ROOT)/sw +SRC := $(wildcard $(ARA_SW)/*.c) $(wildcard $(ARA_SW)/*.h) + +# Get the original compiler options and add the support for vector extension +CHS_SW_FLAGS ?= $(shell grep "^CHS_SW_FLAGS\s\+?=\s\+" -- $(CHS_SW)/sw.mk | sed 's/^.*?= //' | sed s/rv64gc/rv64gcv/) + +.PHONY: chs-sw-all copy_vector_sw + +# Forward build command to the main Cheshire makefile and attach the correct -march +chs-sw-all: copy-vector-sw + make -C $(CHS_ROOT) $@ CHS_SW_FLAGS="$(CHS_SW_FLAGS)" + +# Copy the vector programs to cheshire +copy-vector-sw: + cp $(SRC) $(CHS_SW)/tests diff --git a/cheshire/sw/README.md b/cheshire/sw/README.md new file mode 100644 index 000000000..e4be744d2 --- /dev/null +++ b/cheshire/sw/README.md @@ -0,0 +1,9 @@ +# Build software for Cheshire Ara + +Compile the `.c` programs in this folder with: + +```bash +make chs-sw-all +``` + +This command will copy the necessary source files into Cheshire's `sw/tests` directory and compile them with the support for vector extension. \ No newline at end of file diff --git a/cheshire/sw/encoding.h b/cheshire/sw/encoding.h new file mode 120000 index 000000000..d2d456631 --- /dev/null +++ b/cheshire/sw/encoding.h @@ -0,0 +1 @@ +../../apps/common/encoding.h \ No newline at end of file diff --git a/cheshire/sw/vector_helloworld.c b/cheshire/sw/vector_helloworld.c new file mode 100644 index 000000000..7bcd4d27a --- /dev/null +++ b/cheshire/sw/vector_helloworld.c @@ -0,0 +1,38 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Matteo Perotti +// +// Simple vector memcpy for Hello World! + +#include "regs/cheshire.h" +#include "dif/clint.h" +#include "dif/uart.h" +#include "params.h" +#include "util.h" + +#include "vector_util.h" +#include + +unsigned char buf[64]; + +int main(void) { + enable_rvv(); + + const unsigned char str[] = "Hello World!\r\n"; + vuint8m1_t str_v; + + // Copy the hello world string to buf + str_v = __riscv_vle8_v_u8m1(str, sizeof(str)); + __riscv_vse8_v_u8m1(buf, str_v, sizeof(str)); + + // Print buf + uint32_t rtc_freq = *reg32(&__base_regs, CHESHIRE_RTC_FREQ_REG_OFFSET); + uint64_t reset_freq = clint_get_core_freq(rtc_freq, 2500); + uart_init(&__base_uart, reset_freq, __BOOT_BAUDRATE); + uart_write_str(&__base_uart, buf, sizeof(buf)); + uart_write_flush(&__base_uart); + + return 0; +} diff --git a/cheshire/sw/vector_util.h b/cheshire/sw/vector_util.h new file mode 100644 index 000000000..29e8cb166 --- /dev/null +++ b/cheshire/sw/vector_util.h @@ -0,0 +1,19 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Matteo Perotti +// +// Custom vector util + +#ifndef __VECTOR_UTIL_H__ +#define __VECTOR_UTIL_H__ + +#include "encoding.h" + +inline void enable_rvv() { + asm volatile ("li t0, %0" :: "i"(MSTATUS_VS)); + asm volatile ("csrs mstatus, t0" ); +} + +#endif