This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
BitfieldTargetLocation.cs
91 lines (76 loc) · 2.14 KB
/
BitfieldTargetLocation.cs
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
using System;
using System.Text;
using Mono.Debugger.Backend;
namespace Mono.Debugger.Languages
{
internal class BitfieldTargetLocation : TargetLocation
{
TargetLocation relative_to;
int bit_offset, bit_size;
public BitfieldTargetLocation (TargetLocation relative_to, int offset, int size)
{
this.relative_to = relative_to;
this.bit_offset = offset;
this.bit_size = size;
}
internal override bool HasAddress {
get { return false; }
}
internal override TargetAddress GetAddress (TargetMemoryAccess target)
{
throw new InvalidOperationException ();
}
private string Print (bool[] data)
{
StringBuilder sb = new StringBuilder ("[");
for (int i = 0; i < data.Length; i++) {
if ((i > 0) && ((i % 8) == 0))
sb.Append (" ");
sb.Append (data [i] ? "1" : "0");
}
return sb.ToString ();
}
internal override TargetBlob ReadMemory (TargetMemoryAccess target, int size)
{
byte[] data = relative_to.ReadBuffer (target, size);
int total_size = 8 * data.Length;
bool[] bit_data = new bool [total_size];
bool[] target_bits = new bool [total_size];
// FIXME
bool is_bigendian = false;
int bit_pos = 0;
for (int i = 0; i < data.Length; i++) {
byte current = data [i];
for (int j = 0; j < 8; j++)
bit_data [bit_pos++] = (current & (1 << j)) != 0;
}
bit_pos = 0;
if (!is_bigendian)
bit_offset = total_size - bit_offset - bit_size;
for (int i = bit_offset; i < bit_offset + bit_size; i++)
target_bits [bit_pos++] = bit_data [i];
byte[] blob = new byte [data.Length];
bit_pos = 0;
for (int i = 0; i < blob.Length; i++) {
int current = 0;
for (int j = 0; j < 8; j++) {
if (target_bits [bit_pos++])
current |= 1 << j;
}
blob [i] = (byte) current;
}
return new TargetBlob (blob, target.TargetMemoryInfo);
}
public override string Print ()
{
return String.Format ("Bitfield [{0}..{1}] in {2}",
bit_offset, bit_offset + bit_size,
relative_to.Print ());
}
protected override string MyToString ()
{
return String.Format (":{0}:{1}:{2}", relative_to,
bit_offset, bit_size);
}
}
}