Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cag-uconn committed Oct 4, 2023
1 parent 20a8d07 commit b5cb1e8
Show file tree
Hide file tree
Showing 28 changed files with 1,475 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pa2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SRCS = $(wildcard src/*.c)
HEADERS = $(wildcard src/*.h)
CC = gcc
CFLAGS = -g -std=c99
LDFLAGS = -lm

default: simulator

simulator: $(SRCS) $(HEADERS)
@echo "Building $@..."
@#gcc simulator.o -o simulator -ggdb -std=c99
@echo "Sources: $(SRCS)"
@echo "Headers: $(HEADERS)"
$(CC) $(CFLAGS) -o $@ $(SRCS) $(LDFLAGS)

clean:
-rm -r assembled_tests
-rm -f simulator
-rm -f pipe_trace.txt *.out mdump.txt
27 changes: 27 additions & 0 deletions pa2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Programming Assignment 2: Pipelined riscv-uconn Simulator

A 5-stage pipelined CPU simulator for the RISC-V based riscv-uconn instruction set architecture. The
simulator translates machine code created by the riscv-uconn assembler, and executes instructions
one at a time. Each instruction goes through a Fetch, Decode, Execute, Memory and Writeback stage of
processing.

## Build Instructions
$ make

## Unit Tests
Several unit tests are provided in the `unittests` directory. These unit tests must be assembled
before use with the simulator. Ensure that the assembler is compiled (this should be done after completing PA0).
The unit tests can all be assembled by executing the following command in the `pa2` directory:

$ ../assembler/assembler unittests/unit_test_file.asm <path>/unit_test_file.out

where `unit_test_file` is any of the unit test files (written in riscv-uconn assembly) in the
`unittests` directory. You may also use the provided `assemble_all.sh' script:

$ bash assemble_all.sh

## Usage
$ ./simulator assembled_program_file.out FORWARDING_ENABLED

where `assembled_program_file.out` may be any assembled program file generated by the riscv-uconn
assembler, and `FORWARDING_ENABLED` may be 0 (disabled) or 1 (enabled).
24 changes: 24 additions & 0 deletions pa2/assemble_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# This script is privided to you to assemble all unit tests for you.
# 1) First ensure that that your assembler is compiled
# 2) Then, run "$ bash assemble_all.sh".
# A new directory "assembled tests will be generated, populated with all the binary tests.
# Note: "$ make clean" will remove these tests

if [ ! -d assembled_tests ]; then
echo "Creating \"assembled_tests\" directory..."
mkdir assembled_tests
fi

if [ ! -f ../assembler/assembler ]; then
echo "Error: Assembler is not compiled."
exit
fi

for test in unittests/*.asm; do
echo "Assembling test \"$test\"..."
testname=$(basename $test .asm)
../assembler/assembler $test assembled_tests/$testname.out > /dev/null 2>&1
done
echo "Done!"
61 changes: 61 additions & 0 deletions pa2/src/instruction_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* University of Connecticut
* CSE 4302 / CSE 5302 / ECE 5402: Computer Architecture
* Fall 2023
*
* Programming Assignment 2: Pipelined 5-Stage Simulator
*
* riscy-uconn: instruction_map.h
*
* DO NOT MODIFY THIS FILE
*
*/

#pragma once

/* Some helpful defines for decoding instructions */
#define bit_7 0x00000080
#define bit_20 0x00100000
#define bit_31 0x80000000
#define bit_2_downto_0 0x00000007
#define bit_4_downto_0 0x0000001F
#define bit_6_downto_0 0x0000007F
#define bit_10_downto_7 0x00000780
#define bit_11_downto_8 0x00000F00
#define bit_19_downto_12 0x000FF000
#define bit_30_downto_21 0x7FE00000
#define bit_30_downto_25 0x7E000000
#define bit_31_downto_12 0xFFFFF000
#define bit_31_downto_20 0xFFF00000
#define bit_31_downto_25 0xFE000000

/* Opcode Bits */
#define RTYPE 0x33
#define ITYPE_ARITH 0x13
#define ITYPE_LOAD 0x3
#define STYPE 0x23
#define BTYPE 0x63
#define LUI 0x37
#define JAL 0x6F
#define JALR 0x67

/* Funct3 Bits */
/* R and I-Type Arithmetic */
#define ADD_SUB 0b000
#define SUB 0b000
#define SLT 0b010
#define SLL 0b001
#define SRL 0b101
#define AND 0b111
#define OR 0b110
#define XOR 0b100
/* I-type JALR and Load, S-type, and B-type */
#define LW_SW 0b010
#define BEQ 0b000
#define BNE 0b001
#define BLT 0b100
#define BGE 0b101

/* R-type Funct7s */
#define ADD_F7 0x0
#define SUB_F7 0x20
49 changes: 49 additions & 0 deletions pa2/src/register_map.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* University of Connecticut
* CSE 4302 / CSE 5302 / ECE 5402: Computer Architecture
* Fall 2023
*
* Programming Assignment 2: Pipelined 5-Stage Simulator
*
* riscy-uconn: register_map.c
*
* DO NOT MODIFY THIS FILE
*
*/

#include "register_map.h"

const char* register_map[] = {
[0] = "zero",
[1] = "ra",
[2] = "sp",
[3] = "gp",
[4] = "tp",
[5] = "t0",
[6] = "t1",
[7] = "t2",
[8] = "s0",
[9] = "s1",
[10] = "a0",
[11] = "a1",
[12] = "a2",
[13] = "a3",
[14] = "a4",
[15] = "a5",
[16] = "a6",
[17] = "a7",
[18] = "s2",
[19] = "s3",
[20] = "s4",
[21] = "s5",
[22] = "s6",
[23] = "s7",
[24] = "s8",
[25] = "s9",
[26] = "s10",
[27] = "s11",
[28] = "t3",
[29] = "t4",
[30] = "t5",
[31] = "t6",
};
16 changes: 16 additions & 0 deletions pa2/src/register_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* University of Connecticut
* CSE 4302 / CSE 5302 / ECE 5402: Computer Architecture
* Fall 2023
*
* Programming Assignment 2: Pipelined 5-Stage Simulator
*
* riscy-uconn: register_map.h
*
* DO NOT MODIFY THIS FILE
*
*/

#pragma once

extern const char* register_map[];
Loading

0 comments on commit b5cb1e8

Please sign in to comment.