Skip to content

Commit bdec8a3

Browse files
committed
update README.md & Makefile
1 parent d811ace commit bdec8a3

File tree

2 files changed

+128
-25
lines changed

2 files changed

+128
-25
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ itrace:
4848
ftrace:
4949
@$(MAKE) run MODEL=iss T=$(T) ARGS="--ftrace"
5050

51+
TESTS := ackermann add div dummy if-else load-store matrix-mul quicksort shift unalign
52+
53+
.PHONY: test-all $(TESTS:%=run-%)
54+
55+
test-all: $(TESTS:%=run-%)
56+
57+
$(TESTS:%=run-%): run-%:
58+
@echo ""
59+
@echo "=============================="
60+
@echo " Running test: $*"
61+
@echo " MODEL: $(MODEL)"
62+
@echo "=============================="
63+
@$(MAKE) run T=$* MODEL=$(MODEL) ARGS="$(ARGS)"
64+
5165
.PHONY: clean
5266

5367
clean:

README.md

Lines changed: 114 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you prefer to build locally, you will need to install the RISC-V GNU toolchai
5656
2. **Build the project and run all test:**
5757

5858
```bash
59-
docker-compose exec dev make test_all
59+
docker-compose exec dev make test-all MODEL=[iss|mc|pl]
6060
```
6161

6262
### Build and Run (Local)
@@ -68,50 +68,139 @@ If you prefer to build locally, you will need to install the RISC-V GNU toolchai
6868
Run the `make` command in the project root directory.
6969

7070
```bash
71-
make test_all
71+
make test-all
7272
```
7373

74-
## 🎮 Usage
74+
## 🧩 Simulator Usage Guide
7575

76-
### Running Test Programs
76+
This document explains how to build and run the RISC-V simulator and test programs using the provided **Makefile**.
77+
It describes all available commands, parameters, and typical usage examples.
7778

78-
You can run any test program located in the project's root directory. All test programs are compiled into the `test/build` directory.
79+
---
80+
81+
### ⚙️ Build Commands
82+
83+
| Command | Description |
84+
| ----------------- | -------------------------------------------------------------- |
85+
| `make build` | Build both the simulator (`sim`) and the test program (`test`) |
86+
| `make build-sim` | Build the simulator only |
87+
| `make build-test` | Build the test program only |
88+
89+
---
90+
91+
### 🚀 Running the Simulator
92+
93+
#### Basic Command Format
7994

80-
For example, to run the `quicksort` test:
8195
```bash
82-
docker-compose exec dev make T=quicksort
96+
make run T=<test_name> MODEL=<model_name> [ARGS="optional arguments"]
8397
```
8498

85-
### Debug Mode
99+
#### Parameters
100+
101+
| Parameter | Description | Example |
102+
| --------- | -------------------------------------------------- | ------------------------------------- |
103+
| `T` | The test program name (without `.bin` extension) | `T=dummy` |
104+
| `MODEL` | The simulator model to run | `MODEL=iss` or `MODEL=mc` or `MODEL=pl` |
105+
| `ARGS` | Optional runtime arguments passed to the simulator | `ARGS="--itrace"` or `ARGS="--debug"` |
106+
107+
#### Execution Process
108+
109+
When you run `make run`, the following happens automatically:
110+
111+
1. The simulator and test program are built (via `build-sim` and `build-test`).
112+
2. The command below is executed:
113+
114+
```
115+
sim/build/Simulator <MODEL> <T> <ARGS>
116+
```
117+
118+
* `<MODEL>` specifies which simulator model to run.
119+
* `<T>` is the test program name.
120+
* `<ARGS>` are additional runtime options.
121+
122+
---
123+
124+
### 🧠 Predefined Shortcuts
125+
126+
To simplify common use cases, the Makefile defines several shortcut targets:
127+
128+
| Command | Equivalent to | Description |
129+
| --------------------- | -------------------------------------------- | ----------------------------------------------------- |
130+
| `make iss T=dummy` | `make run MODEL=iss T=dummy ARGS="--batch"` | Run the ISS (instruction set simulator) in batch mode |
131+
| `make mc T=dummy` | `make run MODEL=mc T=dummy ARGS=""` | Run the multi-cycle CPU model |
132+
| `make debug T=dummy` | `make run MODEL=iss T=dummy ARGS="--debug"` | Run the ISS in debug mode |
133+
| `make itrace T=dummy` | `make run MODEL=iss T=dummy ARGS="--itrace"` | Enable instruction tracing |
134+
| `make ftrace T=dummy` | `make run MODEL=iss T=dummy ARGS="--ftrace"` | Enable function call tracing |
135+
136+
---
137+
138+
### 🧪 Examples
139+
140+
#### Example 1 — Run the Multi-Cycle Model
86141

87-
Start the simulator in debug mode by the make command below:
88142
```bash
89-
docker-compose exec dev make debug T=XXX
143+
make run T=dummy MODEL=mc
90144
```
91145

92-
In debug mode, you can use the following commands:
146+
➡️ Builds and runs `test/build/dummy.bin` using the multi-cycle CPU model.
93147

94-
- `help`: Print the help message of debug commands
148+
---
95149

96-
* `si [N]`: Execute a single instruction if `arg N` not provided, or execute N instructions.
97-
* `c`: Continue execution until the program finishes.
98-
* `info r`: Print the status of all general-purpose registers (include PC).
99-
* `x <N> <EXPR>`: Scan `N` 4-byte words of memory starting at address `EXPR`.
150+
#### Example 2 — Run the ISS Model
100151

101-
### Other Commands
152+
```bash
153+
make run T=dummy MODEL=iss
154+
```
155+
156+
➡️ Builds and runs the instruction set simulator.
157+
158+
---
159+
160+
#### Example 3 — Enable Instruction Tracing
161+
162+
```bash
163+
make run T=dummy MODEL=iss ARGS="--itrace"
164+
```
165+
166+
or simply:
167+
168+
```bash
169+
make itrace T=dummy
170+
```
171+
172+
➡️ Runs the simulator with instruction-level trace output.
173+
174+
---
102175

103-
To run the Simulator in `itrace`/`ftrace` mode:
176+
#### Example 4 — Debug Mode
104177

105-
```sh
106-
docker-compose exec dev make itrace T=XXX
107-
docker-compose exec dev make ftrace T=XXX
178+
```bash
179+
make debug T=dummy
108180
```
109181

110-
## ✅ Testing
182+
➡️ Runs the ISS with detailed debug output enabled.
183+
184+
---
111185

112-
If you want to add your own test cases, place your test source file (`.c` file) in the **`/test/src`** directory.
113-
For example, if your test is named **`sample`**, you can run it with the following command:
186+
#### Example 5 — Clean the Build
114187

115188
```bash
116-
docker-compose exec dev make T=sample
189+
make clean
117190
```
191+
192+
➡️ Removes all generated files under `sim/build/` and `test/build/`.
193+
194+
---
195+
196+
### 📘 Summary
197+
198+
| Use Case | Recommended Command |
199+
| ----------------- | ---------------------------- |
200+
| First run | `make run T=dummy MODEL=iss` |
201+
| Multi-cycle model | `make run T=dummy MODEL=mc` |
202+
| Batch mode | `make iss T=dummy` |
203+
| Instruction trace | `make itrace T=dummy` |
204+
| Debug mode | `make debug T=dummy` |
205+
| Clean build files | `make clean` |
206+

0 commit comments

Comments
 (0)