-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTC_ShadowStack-M.c
158 lines (121 loc) · 3.04 KB
/
TC_ShadowStack-M.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <stdio.h>
#include <stdlib.h>
#include "rocc.h"
#include "spin_lock.h"
#include "ght.h"
#include "ghe.h"
#include "tasks.h"
#include "malloc.h"
int uart_lock;
char* shadow;
/* Core_0 thread */
int main(void)
{
int sum_temp = 0;
int sum = 0;
//================== Initialisation ==================//
// shadow memory
shadow = shadow_malloc(32*1024*1024*sizeof(char));
if(shadow == NULL) {
printf("C0: Error! memory not allocated.");
exit(0);
}
// Insepct JAL
// inst_index: 0x03
// Func: 0x00 - 0x07
// Opcode: 0x6F
// Data path: ALU + JALR
ght_cfg_filter(0x03, 0x00, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x01, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x02, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x03, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x04, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x05, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x06, 0x6F, 0x01);
ght_cfg_filter(0x03, 0x07, 0x6F, 0x01);
// Insepct JALR
// inst_index: 0x03
// Func: 0x00
// Opcode: 0x67
// Data path: ALU + JALR
ght_cfg_filter(0x03, 0x00, 0x67, 0x01);
// Insepct Special RET
// inst_index: 0x03
// Func: 0x00
// Opcode: 0x02
// Data path: ALU + JALR
ght_cfg_filter_rvc(0x03, 0x00, 0x02, 0x01);
// Insepct Special JALR
// inst_index: 0x03
// Func: 0x01
// Opcode: 0x02
// Data path: ALU + JALR
ght_cfg_filter_rvc(0x03, 0x01, 0x02, 0x01);
ghm_cfg_agg(0x01);
// se: 0x03, end_id: 0x03, scheduling: fp, start_id: 0x02
ght_cfg_se (0x03, 0x03, 0x03, 0x02);
// inst_index: 0x03 se: 0x03
ght_cfg_mapper (0x03, 0b1000);
lock_acquire(&uart_lock);
printf("C0: Test is now started: \r\n");
lock_release(&uart_lock);
ght_set_satp_priv();
ght_set_status (0x01); // ght: start
//===================== Execution =====================//
for (int i = 0; i < 170; i++) {
task_synthetic();
printf("");
printf("");
printf("");
}
for (int i = 0; i < 170; i++ ){
sum_temp = task_synthetic_malloc(i);
task_synthetic();
sum = sum + sum_temp;
printf("");
}
//=================== Post execution ===================//
ght_set_status (0x02);
uint64_t status;
while ((status = ght_get_status()) < 0x1FFFF)
{
ght_set_status (0x02);
}
lock_acquire(&uart_lock);
printf("All tests are done! Status: %x, sum = %x \r\n", status, sum);
lock_release(&uart_lock);
return 0;
}
/* Core_1 & 2 thread */
int __main(void)
{
uint64_t Hart_id = 0;
asm volatile ("csrr %0, mhartid" : "=r"(Hart_id));
switch (Hart_id){
case 0x01:
task_ShadowStack_M_Agg(Hart_id, 0x2, 0x3);
break;
case 0x02:
task_ShadowStack_M_Pre(Hart_id);
break;
case 0x03:
task_ShadowStack_M_Pre(Hart_id);
break;
case 0x04:
task_ShadowStack_M_Pre(Hart_id);
break;
case 0x05:
task_ShadowStack_M_Pre(Hart_id);
break;
case 0x06:
task_ShadowStack_M_Pre(Hart_id);
break;
case 0x07:
task_ShadowStack_M_Pre(Hart_id);
break;
default:
break;
}
idle();
return 0;
}