-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cheshire/sw] Add basic software support for Cheshire
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
# | ||
# Copy and compile vector software on Cheshire | ||
|
||
CHS_ROOT ?= ../../../../../.. | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../apps/common/encoding.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
// | ||
// 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 <riscv_vector.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
// | ||
// 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 |