Skip to content

Commit

Permalink
Added Linux support, Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziang95 committed Dec 12, 2019
1 parent 1d0ec55 commit 13746c3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Tomasulo_simulator
A pthread implementation of an MIPS CPU simulator using Tomasulo algorithm.
# A pthread-win32 implementation
- This program simulates the behaviour of an MIPS CPU running `Tomasulo algorithm`, and outputs a table recording the start-time of stages in each instruction's lifetime (i.e. `issue`, `execution`, `write_back`...).
- The code is written in a `parallel` way, which means, every virtual-component is functioning in an independent thread, and all threads comply a universal clock, which is also a thread.
- The code is written in a "Quasi-VHDL" style, so you can use function *`at_rising_edge`* and *`at_falling_edge`* to sync each component with the universal clock, but don't forget to register the component in *`clk_wait_list`* first <br>

## How to use it
For now, this program can run on Windows and can possibly be compiled on Linux (not tested yet). Simply download the zip file in [release](https://github.com/Ziang95/Tomasulo_simulator/releases), and use any shell on Windows like `cmd.exe` or `powershell.exe` to run the mips.exe. Here is the procedure:<br>
1. Prepare an input file containing the CPU configuration, initial registor/memory values and assembly code. here is a [template](https://github.com/Ziang95/Tomasulo_simulator/blob/master/InputTest.txt). As for the instruction type, currently only `ADD`, `ADDI`, `ADD.D`, `SUB`, `SUB.D`, `MUL.D`, `LD`, `SD`, `BNE`, `BEQ` and `NOP` are supported.<br>
2. Put your file into the same folder with `mips.exe`, then open `cmd.exe` and cd to the folder, or **press shift**->**right click** your mouse at blank region in the folder->Open `PowerShell` Window here.
3. In the shell window, for example, type:<br>".\mips.exe .\test_case\case1.txt 3"<br>Here, the program takes in 2 arguments, the first is the path of input file, the second is a number *debug_level (optional)*, which control how many debug outputs you want to see on screen.<br>

If you've done everything correctly, you can get output like this:<br>
![example](example.gif)

Enjoy~❤️
8 changes: 8 additions & 0 deletions clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ bool clk_tick::clk_automat(int freq)
for (auto a : clk_wait_list)
outp += to_string(*a) + ",";
msg_log("In waiting for vdd = 1, " + outp, 4);
#ifdef _WIN32
Sleep(500/freq);
#else
usleep(500/freq);
#endif
}
pthread_mutex_lock(&boradcast_lock);
vdd = 1;
Expand All @@ -110,7 +114,11 @@ bool clk_tick::clk_automat(int freq)
for (auto a : clk_wait_list)
outp += to_string(*a) + ",";
msg_log("In waiting for vdd = 0, " + outp, 4);
#ifdef _WIN32
Sleep(500/freq);
#else
usleep(500/freq);
#endif
}
pthread_mutex_lock(&boradcast_lock);
vdd = 0;
Expand Down
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion headers/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
#define CLOCK_H

#include <string>
#include <windows.h>
#include <pthread.h>
#include <string>
#include <vector>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

typedef pthread_cond_t cond_t;
typedef pthread_mutex_t mutex_t;
Expand Down

0 comments on commit 13746c3

Please sign in to comment.