-
Notifications
You must be signed in to change notification settings - Fork 3
/
SCR1Device.wl
140 lines (113 loc) · 3.96 KB
/
SCR1Device.wl
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
(* ::Package:: *)
BeginPackage["SCR1Device`"];
Begin["`Private`"];
Needs["CCompilerDriver`"];
$libscr1=Null;
DeviceFramework`DeviceClassRegister["SCR1",
"Singleton" -> True,
"DriverVersion" -> 1.0,
"OpenFunction" -> open,
"CloseFunction" -> close,
"ReadFunction" -> read,
"WriteFunction" -> write,
"ExecuteFunction" -> exec,
"GetPropertyFunction" -> readProp,
"DeviceIconFunction" -> logo,
"Properties" -> {
"State" -> Null,
"Clock" -> Null,
"IPC" -> Null,
"MAX_MEM" -> Null
}
];
logo[{ih_,dh_}, ___]:=Import["logo.png"];
readProp[dev_,"State"]:=Which[#==0,"IDLE",#==1,"WORK",#==2,"FINISHED"]&@funcGETSTATE[][[1]];
readProp[dev_,"IPC"]:=funcGETSTATE[][[4]];
readProp[dev_,"Clock"]:=funcGETSTATE[][[3]];
readProp[dev_,"MAX_MEM"]:=funcGETMAXMEM[];
exec[{ih_,dh_}, "HARD_RESET"] := funcHARDRESET[];
exec[{ih_,dh_}, "RESET"] := funcRESET[];
exec[{ih_,dh_}, "RUN"] := funcRUN[];
exec[{ih_,dh_}, "RUN_UNTIL_IPC",ipc_] := funcRUNUNITL[ipc];
exec[{ih_,dh_}, "STEP"] := funcSTEP[];
exec[{ih_,dh_}, "NEXT_IPC"] := funcNEXTIPC[];
exec[{ih_,dh_}, "TRACE_IPC"] := funcTRACEIPC[];
exec[{ih_,dh_}, "LOAD", program_] := funcLOAD[program];
read[{ih_,dh_}, "REGS"] := funcGETREGS[];
read[{ih_,dh_}, "STATE"] :=
Inner[
#1->#2&,
{"State","Finished","Clock","IPC"},
MapAt[
Which[#==0,"IDLE",#==1,"WORK",#==2,"FINISHED"]&,
funcGETSTATE[],
1
],
Association
];
read[{ih_,dh_}, "BRANCH"] :=
Inner[
#1->#2&,
{"IPC","Jump","Branch_taken","Branch_not_taken", "JB_addr"},
funcGETBRANCH[],
Association
];
read[{ih_,dh_}, "DBUS"] :=
Inner[
#1->#2&,
{"Address","Bytes"},
funcREADDMEMBUS[],
Association
];
read[{ih_,dh_}, "MEM", addr_, num_] := funcREADMEM[addr,num];
write[{ih_,dh_},"MEM", addr_, value_] := funcWRITEMEM[addr,value];
write[{ih_,dh_},"REGS",num_,value_] := funcSETREG[num,value];
open[___] := Module[
{
h = CreateUUID[],
fileList =
{
"cpp_bridge/cpp_bridge.cpp",
"cpp_bridge/scr1_wrapper.cpp",
"scr1_generated/Vscr1_top_tb_axi.cpp",
"scr1_generated/Vscr1_top_tb_axi__ALLsup.cpp",
"scr1_generated/verilator_system/verilated.cpp",
"scr1_generated/verilator_system/verilated_cov.cpp",
"scr1_generated/verilator_system/verilated_save.cpp",
"scr1_generated/verilator_system/verilated_vcd_c.cpp",
"scr1_generated/verilator_system/verilated_vpi.cpp"
},
incList =
{
NotebookDirectory[]<>"scr1_generated/verilator_system/",
NotebookDirectory[]<>"scr1_generated/"
}
},
$libscr1 = CreateLibrary[
fileList,
"cpp_bridge",
Language -> "C++",
"IncludeDirectories" -> incList
(*This generates a build command. Check an output if the library does not be built.*)
(*,"ShellCommandFunction" -> Print*)
];
funcHARDRESET = LibraryFunctionLoad[$libscr1, "scr1_hard_reset", {}, Integer];
funcRESET = LibraryFunctionLoad[$libscr1, "scr1_reset", {}, Integer];
funcLOAD = LibraryFunctionLoad[$libscr1, "scr1_load", {String}, Integer];
funcRUN = LibraryFunctionLoad[$libscr1, "scr1_run", {}, Integer];
funcRUNUNITL = LibraryFunctionLoad[$libscr1, "scr1_run_until_ipc", {Integer}, Integer];
funcSTEP = LibraryFunctionLoad[$libscr1, "scr1_step", {}, Integer];
funcGETSTATE = LibraryFunctionLoad[$libscr1, "scr1_get_state", {},{Integer,1}];
funcGETREGS = LibraryFunctionLoad[$libscr1, "scr1_get_register_list", {},{Integer,1}];
funcNEXTIPC = LibraryFunctionLoad[$libscr1, "scr1_next_ipc", {}, Integer];
funcTRACEIPC = LibraryFunctionLoad[$libscr1, "scr1_trace_ipc", {},{Integer,1}];
funcGETBRANCH = LibraryFunctionLoad[$libscr1, "scr1_get_branch_state", {},{Integer,1}];
funcREADMEM = LibraryFunctionLoad[$libscr1, "scr1_read_memory", {Integer,Integer},{Integer,1}];
funcREADDMEMBUS = LibraryFunctionLoad[$libscr1, "scr1_get_dmem_bus_state", {}, {Integer,1}];
funcWRITEMEM = LibraryFunctionLoad[$libscr1, "scr1_write_memory", {Integer,Integer}, Integer];
funcSETREG = LibraryFunctionLoad[$libscr1, "scr1_set_register", {Integer,Integer}, Integer];
funcGETMAXMEM = LibraryFunctionLoad[$libscr1, "scr1_get_max_memory", {}, Integer];
h];
close[{ih_,dh_}] := LibraryUnload[$libscr1];
End[];
EndPackage[];