-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_single_hart.cpp
More file actions
50 lines (46 loc) · 1.31 KB
/
cpu_single_hart.cpp
File metadata and controls
50 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//******************************************************************
// Ryon Cook
// z1863954
// CSCI 463 Section 1
// Assignment 5
//
// I certify that this is my own work and where appropriate an extension
// of the starter code provided for the assignment
//
//******************************************************************
#include <iostream>
#include <iomanip>
#include "cpu_single_hart.h"
#include "rv32i_hart.h"
#include "memory.h"
#include "registerfile.h"
/**
* Controls execution of the cpu simulator.
*
* @param exec_limit Number of maximum executions
*
********************************************************************************/
void cpu_single_hart::run(uint64_t exec_limit)
{
//set register x2 to the memory size
regs.set(2,mem.get_size());
if(exec_limit == 0)
{
while(is_halted() == false)
{
tick();//call tick while is_halted is false
}
}
if(exec_limit != 0)
{
while(is_halted() == false && get_insn_counter() != exec_limit)
{
tick();
}
}
if(is_halted() == true)
{
std::cout <<"Execution terminated. Reason: " << get_halt_reason() << std::endl;
}
std::cout << get_insn_counter() << " instructions executed" << std::endl;
}