forked from chipsalliance/VeeR-ISS
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWhisperMessage.h
96 lines (81 loc) · 3.46 KB
/
WhisperMessage.h
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
// Copyright 2020 Western Digital Corporation or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <array>
#include <span>
#include <cstdint>
enum WhisperMessageType
{
Peek, Poke, Step, Until, Change, ChangeCount, Quit, Invalid, Reset, Nmi, ClearNmi,
EnterDebug, ExitDebug, LoadFinished, CancelDiv, CancelLr, DumpMemory, McmRead,
McmInsert, McmWrite, McmEnd, PageTableWalk, Translate, CheckInterrupt, McmBypass,
SeiPin, McmIFetch, McmIEvict, McmSkipReadChk, PmpEntry, PmaEntry, InjectException
};
/// Resource identifiers for peek special.
enum WhisperSpecialResource { PrivMode, PrevPrivMode, FpFlags, IncrementalVec, Trap,
DeferredInterrupts, Seipin, EffMemAttr, LastLdStAddress};
/// Structure used to communicate with the whisper program using
/// sockets. When a ChangeCount message is returned by whisper (as a
/// reply to a Step or a ChangeCount request), the address is set to
/// the program-counter of the last executed instruction, the resource
/// is set to the opcode of that instruction and the value is set to
/// the number of change records generated by that instruction.
struct WhisperMessage
{
WhisperMessage(uint32_t hart = 0, WhisperMessageType type = Invalid,
uint32_t resource = 0, uint64_t address = 0,
uint64_t value = 0, uint32_t size = 0, uint64_t instrTag = 0,
uint64_t time = 0)
: hart(hart), type(type), resource(resource), size(size),
instrTag(instrTag), time(time), address(address), value(value)
{
buffer.fill(0);
tag.fill(0);
}
/// Unpack socket message into the returned WhisperMessage object.
static WhisperMessage deserializeFrom(std::span<char> buffer);
/// Serialize the current WhisperMessage into the given buffer.
/// Return the number of bytes written into buffer.
size_t serializeTo(std::span<char> buffer) const;
uint32_t hart;
uint32_t type;
uint32_t resource; // Also used for vector element index and element size.
uint32_t size;
uint32_t flags = 0;
uint64_t instrTag; // Instruction tag.
uint64_t time; // Time stamp.
uint64_t address;
uint64_t value;
std::array<char, 128> buffer;
std::array<char, 20> tag;
};
/// Union to pack/unpack flags we send in reply to a step request.
union WhisperFlags
{
WhisperFlags(uint32_t val = 0)
: value(val)
{ }
uint32_t value; // First variant of union.
struct // Second variant of union.
{
unsigned privMode : 2; // privilege mode
unsigned fpFlags : 5; // floating point flags from last instruction
bool trap : 1; // true if last instruction trapped
bool stop : 1; // true if target program stopped
bool interrupt : 1; // true if last instruction interrupted
bool virt : 1; // virtual mode before last instruction
bool debug : 1; // true if hart is in debug mode
bool load : 1; // true if last instructions reads data memory
} bits;
};