1 |
6 |
kfleming |
//----------------------------------------------------------------------//
|
2 |
|
|
// The MIT License
|
3 |
|
|
//
|
4 |
|
|
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu
|
5 |
|
|
//
|
6 |
|
|
// Permission is hereby granted, free of charge, to any person
|
7 |
|
|
// obtaining a copy of this software and associated documentation
|
8 |
|
|
// files (the "Software"), to deal in the Software without
|
9 |
|
|
// restriction, including without limitation the rights to use,
|
10 |
|
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
|
|
// copies of the Software, and to permit persons to whom the
|
12 |
|
|
// Software is furnished to do so, subject to the following conditions:
|
13 |
|
|
//
|
14 |
|
|
// The above copyright notice and this permission notice shall be
|
15 |
|
|
// included in all copies or substantial portions of the Software.
|
16 |
|
|
//
|
17 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18 |
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19 |
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20 |
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21 |
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22 |
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23 |
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24 |
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
25 |
|
|
//----------------------------------------------------------------------//
|
26 |
2 |
kfleming |
//BSV includes
|
27 |
|
|
import RegFile::*;
|
28 |
|
|
import Connectable::*;
|
29 |
|
|
import GetPut::*;
|
30 |
|
|
import StmtFSM::*;
|
31 |
|
|
|
32 |
|
|
//CSG Lib includes
|
33 |
|
|
import PLBMaster::*;
|
34 |
|
|
import PLBMasterDefaultParameters::*;
|
35 |
|
|
import PLBMasterEmulator::*;
|
36 |
|
|
|
37 |
|
|
//Local includes
|
38 |
|
|
import MD6Parameters::*;
|
39 |
|
|
import MD6Types::*;
|
40 |
|
|
import MD6Control::*;
|
41 |
|
|
import CompressionFunctionTypes::*;
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
module mkMD6ControlTest ();
|
47 |
|
|
RegFile#(Bit#(26),BusWord) memory <- mkRegFileFullLoad("md6Input.hex");
|
48 |
|
|
PLBMasterEmulator#(TExp#(26)) plbmaster <- mkPLBMasterEmulator(memory);
|
49 |
|
|
MD6Control#(1,32) control <- mkMD6Control;
|
50 |
|
|
// Hook up the system
|
51 |
|
|
mkConnection(plbmaster.plbmaster.wordInput.put,control.wordOutput);
|
52 |
|
|
mkConnection(control.wordInput,plbmaster.plbmaster.wordOutput.get);
|
53 |
|
|
mkConnection(plbmaster.plbmaster.plbMasterCommandInput.put,control.outputCommand);
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
Reg#(Bit#(32)) memPtr <- mkReg(0);
|
57 |
|
|
|
58 |
|
|
RegFile#(Bit#(1), Bit#(32)) rfileSize <- mkRegFileFullLoad("inputSize.hex");
|
59 |
|
|
RegFile#(Bit#(TLog#(MD6_c)), BusWord) rfileRes <- mkRegFileFullLoad("md6Result.hex");
|
60 |
|
|
Reg#(Bit#(TAdd#(TLog#(MD6_c),1))) resPtr <- mkReg(0);
|
61 |
|
|
|
62 |
|
|
let inputSize = (((rfileSize.sub(0))/fromInteger(8*valueof(MD6_b))) + 1)*fromInteger(valueof(MD6_b));
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
Stmt s = seq
|
66 |
|
|
control.keyRegister <= unpack(0);
|
67 |
|
|
control.digestLength <= 512;
|
68 |
|
|
control.sourceAddress <= 0;
|
69 |
|
|
$display("Offset is: %d", inputSize);
|
70 |
|
|
control.destinationAddress <= 2*truncate(inputSize);
|
71 |
|
|
control.bufferAddress <= 4*truncate(inputSize);
|
72 |
|
|
$display("Bits input: %d", rfileSize.sub(0));
|
73 |
|
|
control.bitSize <= zeroExtend(rfileSize.sub(0));
|
74 |
|
|
control.bigEndian <= True;
|
75 |
|
|
control.startDecode();
|
76 |
|
|
await(!control.running);
|
77 |
|
|
delay(100);
|
78 |
|
|
for(resPtr <= 0;
|
79 |
|
|
resPtr < fromInteger(valueof(MD6_c)) - 8; //result is 512 bits I suppose
|
80 |
|
|
resPtr <= resPtr+1)
|
81 |
|
|
seq
|
82 |
|
|
if(rfileRes.sub(truncate(resPtr)) != memory.sub(truncate(zeroExtend(resPtr) + inputSize + 8)))
|
83 |
|
|
seq
|
84 |
|
|
$display("Offset: %d rfile: %d",zeroExtend(resPtr), rfileSize.sub(0));
|
85 |
|
|
$display("FAILED at %d, %h != %h", inputSize+zeroExtend(resPtr),rfileRes.sub(truncate(resPtr)),memory.sub(truncate(zeroExtend(resPtr) + inputSize + 8)));
|
86 |
|
|
$finish;
|
87 |
|
|
endseq
|
88 |
|
|
else
|
89 |
|
|
seq
|
90 |
|
|
$display("Match at %d", zeroExtend(resPtr) + inputSize);
|
91 |
|
|
endseq
|
92 |
|
|
endseq
|
93 |
|
|
$display("PASS");
|
94 |
|
|
$finish;
|
95 |
|
|
endseq;
|
96 |
|
|
|
97 |
|
|
FSM fsm <- mkFSM(s);
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
rule startFSM;
|
101 |
|
|
fsm.start;
|
102 |
|
|
endrule
|
103 |
|
|
|
104 |
|
|
endmodule
|