Skip to content

Commit

Permalink
Porting coremark to FRISCV
Browse files Browse the repository at this point in the history
  • Loading branch information
dpretet committed Nov 30, 2023
1 parent 8c878e7 commit 269524b
Show file tree
Hide file tree
Showing 14 changed files with 3,321 additions and 474 deletions.
2 changes: 1 addition & 1 deletion doc/project_mgt_hw.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DOING

- [ ] v1.6.0: Kernel-capable Hart
- [ ] Kernel-capable Hart
- [X] Supporter des set de config du core en test bench.
- [X] Support U-mode
- [X] Support PMP/PMA
Expand Down
1 change: 1 addition & 0 deletions test/apps/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TRACE_BLOCKS=0
TRACE_FETCHER=0
TRACE_PUSHER=0
TRACE_TB_RAM=0
TRACE_REGISTERS=0

# Disable external IRQ generation
GEN_EIRQ=0
Expand Down
3,159 changes: 3,159 additions & 0 deletions test/apps/tests/coremark.v

Large diffs are not rendered by default.

77 changes: 39 additions & 38 deletions test/apps/tests/coremark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Original Author: Shay Gal-on

# Make sure the default target is to simply build and run the benchmark.
Expand All @@ -22,35 +22,18 @@ run: $(OUTFILE) rerun score

score:
@echo "Check run1.log and run2.log for results."
@echo "See README.md for run and reporting rules."

ifndef PORT_DIR
# Ports for a couple of common self hosted platforms
UNAME=$(shell if command -v uname 2> /dev/null; then uname ; fi)
ifneq (,$(findstring CYGWIN,$(UNAME)))
PORT_DIR=cygwin
endif
ifneq (,$(findstring Darwin,$(UNAME)))
PORT_DIR=macos
endif
ifneq (,$(findstring FreeBSD,$(UNAME)))
PORT_DIR=freebsd
endif
ifneq (,$(findstring Linux,$(UNAME)))
PORT_DIR=linux
endif
endif
ifndef PORT_DIR
$(error PLEASE define PORT_DIR! (e.g. make PORT_DIR=simple))
endif
@echo "See README.md for run and reporting rules."

PORT_DIR=barebones

vpath %.c $(PORT_DIR)
vpath %.S $(PORT_DIR)
vpath %.h $(PORT_DIR)
vpath %.mak $(PORT_DIR)
include $(PORT_DIR)/core_portme.mak

ifndef ITERATIONS
ITERATIONS=0
endif
ITERATIONS=10

ifdef REBUILD
FORCE_REBUILD=force_rebuild
endif
Expand All @@ -65,8 +48,9 @@ OUTNAME = coremark$(EXE)
OUTFILE = $(OPATH)$(OUTNAME)
LOUTCMD = $(OFLAG) $(OUTFILE) $(LFLAGS_END)
OUTCMD = $(OUTFLAG) $(OUTFILE) $(LFLAGS_END)
CRT = ./crt0.S

HEADERS = coremark.h
HEADERS = coremark.h
CHECK_FILES = $(ORIG_SRCS) $(HEADERS)

$(OPATH):
Expand All @@ -77,26 +61,42 @@ ifdef SEPARATE_COMPILE
$(OPATH)$(PORT_DIR):
$(MKDIR) $(OPATH)$(PORT_DIR)

compile: $(OPATH) $(OPATH)$(PORT_DIR) $(OBJS) $(HEADERS)
link: compile
compile: $(OPATH) $(OPATH)$(PORT_DIR) $(OBJS) $(HEADERS)
link: compile
$(LD) $(LFLAGS) $(XLFLAGS) $(OBJS) $(LOUTCMD)

@echo "Link NOT performed along with compile"

else

compile: $(OPATH) $(SRCS) $(HEADERS)
$(CC) $(CFLAGS) $(XCFLAGS) $(SRCS) $(OUTCMD)
link: compile
#$(PROJ_NAME).elf: compile

compile: $(OPATH) $(SRCS) $(HEADERS)
$(RISCV_CC) -c $(CFLAGS) -o ctr0.o $(CRT) -D__ASSEMBLY__=1
$(CC) $(CFLAGS) $(XCFLAGS) $(SRCS) ctr0.o $(OUTCMD) $(LDFLAGS)
link: compile
@echo "Link performed along with compile"

endif

########################################################
all: $(OUTFILE)
$(RISCV_OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
$(RISCV_OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
$(RISCV_OBJCOPY) -O verilog $(PROJ_NAME).elf $(PROJ_NAME).v
$(RISCV_OBJDUMP) -S -d $(PROJ_NAME).elf > $(PROJ_NAME).asm
@cp *.v ../
$(RISCV_NM) *.elf > $(PROJ_NAME).symbols
@cp *.symbols ../
@echo "done"
########################################################

$(OUTFILE): $(SRCS) $(HEADERS) Makefile core_portme.mak $(EXTRA_DEPENDS) $(FORCE_REBUILD)
$(MAKE) port_prebuild
$(MAKE) link
$(MAKE) port_postbuild

.PHONY: rerun
rerun:
rerun:
$(MAKE) XCFLAGS="$(XCFLAGS) -DPERFORMANCE_RUN=1" load run1.log
$(MAKE) XCFLAGS="$(XCFLAGS) -DVALIDATION_RUN=1" load run2.log

Expand All @@ -105,14 +105,14 @@ PARAM2=$(PORT_PARAMS) 0x3415 0x3415 0x66 $(ITERATIONS)
PARAM3=$(PORT_PARAMS) 8 8 8 $(ITERATIONS)

run1.log-PARAM=$(PARAM1) 7 1 2000
run2.log-PARAM=$(PARAM2) 7 1 2000
run2.log-PARAM=$(PARAM2) 7 1 2000
run3.log-PARAM=$(PARAM3) 7 1 1200

run1.log run2.log run3.log: load
$(MAKE) port_prerun
$(RUN) $(OUTFILE) $($(@)-PARAM) > $(OPATH)$@
$(MAKE) port_postrun

.PHONY: gen_pgo_data
gen_pgo_data: run3.log

Expand All @@ -125,16 +125,17 @@ load: $(OUTFILE)
.PHONY: clean
clean:
rm -f $(OUTFILE) $(OBJS) $(OPATH)*.log *.info $(OPATH)index.html $(PORT_CLEAN)
rm -f *.elf $(PROJ_NAME) *.map *.bin *.md5 *.hex *.v *.asm *.symbols

.PHONY: force_rebuild
force_rebuild:
echo "Forcing Rebuild"

.PHONY: check
check:
md5sum -c coremark.md5
md5sum -c coremark.md5

ifdef ETC
# Targets related to testing and releasing CoreMark. Not part of the general release!
include Makefile.internal
endif
endif
12 changes: 8 additions & 4 deletions test/apps/tests/coremark/barebones/core_portme.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ volatile ee_s32 seed5_volatile = 0;
CORETIMETYPE
barebones_clock()
{
#error \
"You must implement a method to measure time in barebones_clock()! This function should return current time.\n"
int cycle;
asm volatile("csrr %0, 0xC00" : "=r"(cycle));

// #error \
// "You must implement a method to measure time in barebones_clock()! This function should return current time.\n"
}
/* Define : TIMER_RES_DIVIDER
Divider to trade off timer resolution and total time that can be
Expand All @@ -59,6 +62,7 @@ barebones_clock()
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
#define TIMER_RES_DIVIDER 1
#define SAMPLE_TIME_IMPLEMENTATION 1
#define CLOCKS_PER_SEC 1000000000
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)

/** Define Host specific (POSIX), or target specific global time variables. */
Expand Down Expand Up @@ -129,8 +133,8 @@ ee_u32 default_num_contexts = 1;
void
portable_init(core_portable *p, int *argc, char *argv[])
{
#error \
"Call board initialization routines in portable init (if needed), in particular initialize UART!\n"
// #error \
// "Call board initialization routines in portable init (if needed), in particular initialize UART!\n"

(void)argc; // prevent unused warning
(void)argv; // prevent unused warning
Expand Down
3 changes: 3 additions & 0 deletions test/apps/tests/coremark/barebones/core_portme.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Original Author: Shay Gal-on
This file contains configuration constants required to execute on
different platforms
*/

#include "stdlib.h"

#ifndef CORE_PORTME_H
#define CORE_PORTME_H
/************************/
Expand Down
51 changes: 44 additions & 7 deletions test/apps/tests/coremark/barebones/core_portme.mak
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,56 @@
#
# Original Author: Shay Gal-on

##########################################################################
# RISCV toolchain
##########################################################################

PROJ_NAME=$(shell basename $(CURDIR))

OPATH = ./

RISCV_NAME = riscv64-unknown-elf
RISCV_CC = $(RISCV_NAME)-gcc
RISCV_OBJCOPY = $(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_NAME)-objdump
RISCV_NM = $(RISCV_NAME)-nm

RISCV_CLIB="/opt/homebrew/Cellar/riscv-gnu-toolchain/main/riscv64-unknown-elf/include/"

# Select architecure and ABI
CFLAGS += -march=rv32im \
-mabi=ilp32 \
-O0 \
-g \
-I./ \
-I$(RISCV_CLIB) \
-mcmodel=medany \
-static \
-std=gnu99 \

LDFLAGS += -nostartfiles \
-e _start \
-T linker.ld \
-Wl,-Map,$(OPATH)/$(PROJ_NAME).map \
-Wl,--print-memory-usage

##########################################################################

#File : core_portme.mak

# Flag : OUTFLAG
# Use this flag to define how to to get an executable (e.g -o)
OUTFLAG= -o
# Flag : CC
# Use this flag to define compiler to use
CC = gcc
# CC = gcc
CC = $(RISCV_CC)
# Flag : LD
# Use this flag to define compiler to use
LD = gld
# Flag : AS
# Use this flag to define compiler to use
AS = gas
AS = $(RISCV_CC)
# Flag : CFLAGS
# Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -O0 -g
Expand All @@ -36,12 +72,12 @@ CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
#Flag : LFLAGS_END
# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
# Note : On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
SEPARATE_COMPILE=1
#SEPARATE_COMPILE=1
# Flag : SEPARATE_COMPILE
# You must also define below how to create an object file, and how to link.
OBJOUT = -o
LFLAGS =
ASFLAGS =
ASFLAGS = -D__ASSEMBLY__=1
OFLAG = -o
COUT = -c

Expand All @@ -63,16 +99,17 @@ LOAD = echo "Please set LOAD to the process of loading the executable to the fla
RUN = echo "Please set LOAD to the process of running the executable (e.g. via jtag, or board reset)"

OEXT = .o
EXE = .bin
EXE = .elf

$(OPATH)$(PORT_DIR)/%$(OEXT) : %.c
$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@

$(OPATH)%$(OEXT) : %.c
$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@

$(OPATH)$(PORT_DIR)/%$(OEXT) : %.s
$(AS) $(ASFLAGS) $< $(OBJOUT) $@
$(OPATH)$(PORT_DIR)/%$(OEXT) : %.S
#$(AS) $(ASFLAGS) $< $(OBJOUT) $@
$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1

# Target : port_pre% and port_post%
# For the purpose of this simple port, no pre or post steps needed.
Expand Down
1 change: 1 addition & 0 deletions test/apps/tests/coremark/barebones/crt0.S
10 changes: 9 additions & 1 deletion test/apps/tests/coremark/barebones/ee_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ limitations under the License.

#define is_digit(c) ((c) >= '0' && (c) <= '9')

#define UART_ADDRESS 0x100008
#define UART_STATUS (UART_ADDRESS + 0x0)
#define UART_CLKDIV (UART_STATUS + 0x4)
#define UART_TX (UART_STATUS + 0x8)
#define UART_RX (UART_STATUS + 0xC)

static char * digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static char * upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static ee_size_t strnlen(const char *s, ee_size_t count);
Expand Down Expand Up @@ -662,7 +668,9 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
void
uart_send_char(char c)
{
#error "You must implement the method uart_send_char to use this file!\n";
*((volatile int*) UART_TX) = c;

// #error "You must implement the method uart_send_char to use this file!\n";
/* Output of a char to a UART usually follows the following model:
Wait until UART is ready
Write char to UART
Expand Down
6 changes: 0 additions & 6 deletions test/apps/tests/coremark/coremark.md5

This file was deleted.

54 changes: 54 additions & 0 deletions test/apps/tests/coremark/crt0.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# distributed under the mit license
# https://opensource.org/licenses/mit-license.php

.section .text.init
.global _start

_start:

# First init all the registers to 0
li x1, 0
li x2, 0
li x3, 0
li x4, 0
li x5, 0
li x6, 0
li x7, 0
li x8, 0
li x8, 0
li x9, 0
li x10, 0
li x11, 0
li x12, 0
li x13, 0
li x14, 0
li x15, 0
li x16, 0
li x17, 0
li x19, 0
li x20, 0
li x21, 0
li x22, 0
li x23, 0
li x24, 0
li x25, 0
li x26, 0
li x27, 0
li x28, 0
li x29, 0
li x30, 0
li x31, 0

# Setup system call function address
la t0, trap_entry
csrw mtvec,t0

# Init the max boundary of the stack section
# _estack will be linked later with the linker file symbols
la sp, _estack

# Jump to the main
call main

trap_entry:
ebreak
1 change: 1 addition & 0 deletions test/apps/tests/coremark/linker.ld
Loading

0 comments on commit 269524b

Please sign in to comment.