-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU.h
More file actions
80 lines (65 loc) · 2.81 KB
/
Copy pathCPU.h
File metadata and controls
80 lines (65 loc) · 2.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "../Request.h"
#include <cstdint>
#include <systemc>
#include <vector>
SC_MODULE(CPU) {
public:
// ====================================== External Ports ======================================
// Global Clock
sc_core::sc_in<bool> SC_NAMED(clock);
// CPU -> Cache
sc_core::sc_out<std::uint32_t> SC_NAMED(addressBus);
sc_core::sc_out<std::uint32_t> SC_NAMED(dataOutBus);
sc_core::sc_out<bool> SC_NAMED(weBus);
sc_core::sc_out<bool> SC_NAMED(validDataRequestBus);
// Cache -> CPU
sc_core::sc_in<std::uint32_t> SC_NAMED(dataInBus);
sc_core::sc_in<bool> SC_NAMED(dataReadyBus);
// Instr Cache -> CPU
sc_core::sc_in<Request> SC_NAMED(instrBus);
sc_core::sc_in<bool> SC_NAMED(instrReadyBus);
// CPU -> Instr Cache
sc_core::sc_out<bool> SC_NAMED(validInstrRequestBus);
sc_core::sc_out<std::uint32_t> SC_NAMED(pcBus);
private:
Request* instructions;
std::uint64_t program_counter = 0;
std::uint64_t lastCycleWhereWorkWasDone = 0;
std::size_t numRequests = 0;
// needed to handle a parallel instruction read and instruction processing
bool instructionReady = false;
sc_core::sc_event triggerNextInstructionRead;
// this is for when we have just waited for an instruction to be done so we don't need to wait any longer
bool skipAhead = false;
public:
CPU(sc_core::sc_module_name name, Request * instructions, std::size_t numRequests);
/**
* Returns the cycle in which the last instruction was completed
* @return cycle in which the last instruction was completed
*/
constexpr std::uint64_t getElapsedCycleCount() const noexcept { return lastCycleWhereWorkWasDone; }
private:
SC_CTOR(CPU); // private since this is never to be called, just to get systemc typedef
// ======================================= Main Handling =======================================
/**
* The main point of the CPU, which sleeps until we received a instruction and then sets all signals needed
* for the data cache to process the request. In case of a read the data returned from the cache is set to the data
* field of the instruction.
*/
void handleInstruction() noexcept;
/**
* For the first instruction this sets all needed signals for the instruction cache to read the next instruction.
* Afterwards the event triggerNextInstructionRead has to be notified to read the next instruction.
*/
void readInstruction() noexcept;
// ====================================== Waiting Helpers ======================================
/**
* Sleeps until we get a ready signal from instruction cache
*/
void waitForInstruction() noexcept;
/**
* Sleeps until we get a ready signal from data cache
*/
void waitForInstructionProcessing() noexcept;
};