Skip to content

Commit

Permalink
[cheshire/sw] Add basic software support for Cheshire
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-17 committed Jul 5, 2024
1 parent ca32c65 commit 43bc4d2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cheshire/sw/Makefile
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
9 changes: 9 additions & 0 deletions cheshire/sw/README.md
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.
1 change: 1 addition & 0 deletions cheshire/sw/encoding.h
38 changes: 38 additions & 0 deletions cheshire/sw/vector_helloworld.c
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;
}
19 changes: 19 additions & 0 deletions cheshire/sw/vector_util.h
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

0 comments on commit 43bc4d2

Please sign in to comment.