Skip to content

Commit

Permalink
Corrected wrong validation of spectre attack
Browse files Browse the repository at this point in the history
Project accomplished
  • Loading branch information
Ziang95 committed Dec 12, 2019
1 parent 96bb66e commit 1d0ec55
Show file tree
Hide file tree
Showing 66 changed files with 138 additions and 3,426 deletions.
19 changes: 15 additions & 4 deletions FU.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "FU.h"
#include ".\headers\FU.h"

extern config *CPU_cfg;
extern instr_queue *instr_Q;
Expand Down Expand Up @@ -239,8 +239,19 @@ A: at_rising_edge(next_vdd);
{
if (branch == tmp->taken)
{
at_falling_edge(next_vdd);
R->finished = true;
if (tmp->taken && tmp->target != R->instr_i + 1 + task.offset)
{
tmp->target = R->instr_i + 1 +task.offset;
brcUnit.to_target(R->instr_i + 1 + task.offset);
msg_log("Begin Squash", 3);
brcUnit.to_squash(task.dest);
at_falling_edge(next_vdd);
}
else
{
at_falling_edge(next_vdd);
R->finished = true;
}
}
else
{
Expand All @@ -258,7 +269,7 @@ A: at_rising_edge(next_vdd);
{
if (branch)
{
CPU_BTB.addEntry(R->instr_i, (R->instr_i + 1 + task.offset)%8);
CPU_BTB.addEntry(R->instr_i, R->instr_i + 1 + task.offset);
brcUnit.to_target(R->instr_i + 1 + task.offset);
msg_log("Begin Squash", 3);
brcUnit.to_squash(task.dest);
Expand Down
2 changes: 1 addition & 1 deletion ROB.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ROB.h"
#include ".\headers\ROB.h"

extern config *CPU_cfg;
extern instr_queue *instr_Q;
Expand Down
4 changes: 2 additions & 2 deletions branch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "branch.h"
#include "clock.h"
#include ".\headers\branch.h"
#include ".\headers\clock.h"

extern unordered_map <string, int> RAT;
extern vector<int*> clk_wait_list;
Expand Down
2 changes: 1 addition & 1 deletion branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef struct squash_param
bool flag = false; //Whether the squash has begun
}squash_param;

#include "mips.h"
#include ".\headers\mips.h"

class BTB
{
Expand Down
2 changes: 1 addition & 1 deletion clock.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "clock.h"
#include ".\headers\clock.h"

extern vector<int*> clk_wait_list;
extern int debug_level;
Expand Down
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions headers/branch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef BRANCH_H
#define BRANCH_H

typedef struct BTBEntry
{
int target;
bool predicted;
bool taken;
}BTBEntry;

typedef struct squash_param
{
int R_f; //The front pointer of ROB
int R_r; //The rear pointer of ROB
int ROB_i; //The affected ROB index
bool flag = false; //Whether the squash has begun
}squash_param;

#include "mips.h"

class BTB
{
private:
BTBEntry buf[BTB_LEN];
public:
BTB();
void addEntry(int _instr_i, int _target);
BTBEntry *getEntry(int instr_i);
};

class branchCtrl
{
private:
int ROB_i;
int target;
public:
pthread_t handle;
int next_vdd;
branchCtrl();
void to_squash(int _ROB_i);
void to_target(int _target);
int squash_ROB_i();
void branch_automat();
};

void init_brcUnit();

#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion import.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "import.h"
#include ".\headers\import.h"

extern config *CPU_cfg;
extern clk_tick sys_clk;
Expand Down
2 changes: 1 addition & 1 deletion instruction.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "instruction.h"
#include ".\headers\instruction.h"

instr_queue::instr_queue(vector<instr> a):
Q(a),size(a.size())
Expand Down
4 changes: 2 additions & 2 deletions issue.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "issue.h"
#include ".\headers\issue.h"

extern pthread_t iss_unit;
extern clk_tick sys_clk;
Expand Down Expand Up @@ -264,7 +264,7 @@ void *issue_automat(void *arg)
if (BTBEntry* predctr = CPU_BTB.getEntry(R->instr_i))
{
if (predctr->taken)
instr_Q->move_ptr(((R->instr_i)/8)*8 + predctr->target);
instr_Q->move_ptr(((R->instr_i)/8)*8 + (predctr->target)%8);
else
instr_Q->ptr_advance();
}
Expand Down
2 changes: 1 addition & 1 deletion memory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "memory.h"
#include ".\headers\memory.h"

extern clk_tick sys_clk;
extern memory main_mem;
Expand Down
2 changes: 1 addition & 1 deletion mips.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mips.h"
#include ".\headers\mips.h"

config *CPU_cfg = nullptr;
instr_queue *instr_Q = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion output.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "output.h"
#include ".\headers\output.h"

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion registor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "registor.h"
#include ".\headers\registor.h"

extern clk_tick sys_clk;

Expand Down
4 changes: 2 additions & 2 deletions reserv_station.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "reserv_station.h"
#include "mips.h"
#include ".\headers\reserv_station.h"
#include ".\headers\mips.h"

extern config *CPU_cfg;
extern clk_tick sys_clk;
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions test_case/case10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# of rs Cycles in EX Cycles in Mem # of FUs
Integer adder 2 1 1
FP adder 3 3 1
FP multiplier 2 20 1
Load/store unit 3 1 4 1
ROB entries = 128
CDB buffer entries = 1
R1=10,R2=16,R3=30,F1=111.111,F2=222.222
Mem[4]=1,Mem[8]=2,Mem[12]=3.4

ADD R1,R0,R0
SD F1, 0(R1)
ADDI R1,R1,4
BNE R1,R2,-3
SD F2, 0(R1)
LD F3, 0(R1)
LD F4, -8(R1)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions test_case/the_test_case.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# of rs Cycles in EX Cycles in Mem # of FUs
Integer adder 4 1 1
FP adder 3 4 1
FP multiplier 2 15 1
Load/store unit 10 1 5 1
ROB entries = 64
CDB buffer entries = 1

R1=12, R2=32, F20=3.0
Mem[4]=3.0, Mem[8]=2.0, Mem[12]=1.0, Mem[24]=6.0, Mem[28]=5.0, Mem[32]=4.0

ld F2, 0(R1)
mult.d F4, F2, F20
ld F6, 0(R2)
add.d F6, F4, F6
sd F6, 0(R2)
addi R1, R1, -4
addi R2, R2, -4
bne R1, R0, -8
NOP
23 changes: 23 additions & 0 deletions test_case/victim_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# of rs Cycles in EX Cycles in Mem # of FUs
Integer adder 4 1 1
FP adder 3 4 1
FP multiplier 2 15 1
Load/store unit 3 1 5 1
ROB entries = 64
CDB buffer entries = 1

R0=0
Mem[4]=3.0

Addi R2, R0, -2
Addi R3, R0, 4
Addi R2, R2, 2
Ld F1, 0(R1)
Beq R2, R0, 5
Addi R3, R3, 4
Addi R2, R2, 8
Mult.d F3, F2, F1
Add R2, R2, R2
Add R1, R1, R1
Add R1, R1, R1
Add R1, R1, R1
40 changes: 0 additions & 40 deletions tumasulu/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions tumasulu/ExeTable.h

This file was deleted.

Loading

0 comments on commit 1d0ec55

Please sign in to comment.