Skip to content

Commit ba8eb1e

Browse files
author
Stuart Cording
committed
First functional version of ihStat
First version providing basic statistic reporting.
1 parent a3ebbb6 commit ba8eb1e

File tree

1 file changed

+82
-87
lines changed

1 file changed

+82
-87
lines changed

utilities/ihStat/ihStat.cpp

Lines changed: 82 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,13 @@ int main(int argc, char *argv[])
112112
/* Decode file */
113113
intelHexInput >> ihStat;
114114

115-
#error Got here
116-
117-
/* Check for errors or warnings */
118-
if (intelHexInput.getNoWarnings() != 0)
115+
/* Check for errors or warnings */
116+
if (ihStat.getNoWarnings() != 0)
119117
{
120118
std::cerr << "File " << argv[1] << " contained warnings." << std::endl;
121119
decodingIssues = true;
122120
}
123-
if (intelHexInput.getNoErrors() != 0)
121+
if (ihStat.getNoErrors() != 0)
124122
{
125123
std::cerr << "File " << argv[1] << " contained errors." << std::endl;
126124
decodingIssues = true;
@@ -132,91 +130,88 @@ int main(int argc, char *argv[])
132130
}
133131

134132
/* Determine start and end addresses */
135-
intelHexInput.begin();
136-
startAddress = intelHexInput.currentAddress();
137-
intelHexInput.end();
138-
endAddress = intelHexInput.currentAddress();
133+
ihStat.begin();
134+
startAddress = ihStat.currentAddress();
135+
ihStat.end();
136+
endAddress = ihStat.currentAddress();
139137

140-
cout << "Start address: 0x" << hex << setw(8) << startAddress << endl;
141-
cout << "End address : 0x" << hex << setw(8) << endAddress << endl;
142-
cout << "Address range: " << dec << ((endAddress - startAddress) +1) << \
143-
" bytes" << endl;
138+
cout << "Start address: 0x" << hex << setw(8) << setfill('0') \
139+
<< uppercase << startAddress << endl;
140+
cout << "End address : 0x" << hex << setw(8) << setfill('0') \
141+
<< uppercase << endAddress << endl;
142+
cout << "Address range: " << dec << ((endAddress - startAddress) +1UL) \
143+
<< " bytes" << endl;
144144

145145
/* Determine number of bytes in file */
146-
cout << "Data bytes : " << dec << intelHexInput.size() << endl;
146+
cout << "Data bytes : " << dec << ihStat.size() << endl;
147147

148-
/* Two local var's to store data at the locations being analysed */
149-
unsigned char diffAData = 0;
150-
unsigned char diffBData = 0;
151-
152-
bool aFinished = false;
153-
bool bFinished = false;
154-
155-
bool complete = false;
156-
157-
do
158-
{
159-
/* Get address of data we are pointing to */
160-
diffAAddress = ihDiffA.currentAddress();
161-
diffBAddress = ihDiffB.currentAddress();
162-
163-
/* Get the data at two current addresses */
164-
ihDiffA.getData(&diffAData);
165-
ihDiffB.getData(&diffBData);
166-
167-
/* If addresses are the same, compare data values */
168-
if (diffAAddress == diffBAddress)
169-
{
170-
if (diffAData != diffBData)
171-
{
172-
cout << uppercase << "0x" \
173-
<< hex << setw(8) << setfill('0') << diffAAddress \
174-
<< " 0x" << hex << setw(2) \
175-
<< static_cast<unsigned short>(diffAData) \
176-
<< " 0x" << hex << setw(2) \
177-
<< static_cast<unsigned short>(diffBData) << endl;
178-
}
179-
/* Increment both addresses */
180-
++ihDiffA;
181-
++ihDiffB;
182-
}
183-
184-
/* If addresses are different, find out which one is lower and output */
185-
/* that this address has data where the other does not have data */
186-
else if (diffAAddress < diffBAddress)
187-
{
188-
/* Output A address as reference address since this exists and */
189-
/* the B address doesn't */
190-
cout << uppercase << "0x" \
191-
<< hex << setw(8) << setfill('0') << diffAAddress \
192-
<< " 0x" << hex << setw(2) \
193-
<< static_cast<unsigned short>(diffAData) \
194-
<< " ----" << endl;
195-
++ihDiffA;
196-
}
197-
else
198-
{
199-
/* Here we output the B address as reference address since data */
200-
/* appears at this address in file B, but not in file A */
201-
cout << uppercase << "0x" \
202-
<< hex << setw(8) << setfill('0') << diffBAddress \
203-
<< " ----" \
204-
<< " 0x" << hex << setw(2) \
205-
<< static_cast<unsigned short>(diffBData) << endl;
206-
++ihDiffB;
207-
}
208-
209-
/* Check if we got to the end of the two files */
210-
if (ihDiffA.endOfData() == true)
211-
{
212-
break;
213-
}
214-
else if (ihDiffB.endOfData() == true)
215-
{
216-
break;
217-
}
218-
219-
} while (complete != true);
220-
148+
/* If EIP register was found, output value */
149+
unsigned long eipRegister;
150+
151+
if (ihStat.getStartLinearAddress(&eipRegister))
152+
{
153+
cout << "EIP : 0x" << hex << setw(8) << setfill('0') \
154+
<< uppercase << eipRegister << endl;
155+
}
156+
157+
/* If IP & CS registers were found, output values */
158+
unsigned short ipRegister;
159+
unsigned short csRegister;
160+
161+
if (ihStat.getStartSegmentAddress(&ipRegister, &csRegister))
162+
{
163+
cout << "IP : 0x" << hex << setw(4) << setfill('0') \
164+
<< uppercase << ipRegister << endl;
165+
cout << "CS : 0x" << hex << setw(4) << setfill('0') \
166+
<< uppercase << csRegister << endl;
167+
}
168+
169+
/* Find empty regions */
170+
bool foundEmptyRegion = false;
171+
unsigned long emptyAddressCount = 0;
172+
unsigned long emptyRegionStart = 0;
173+
unsigned long emptyRegionEnd = 0;
174+
unsigned long previousAddress = 0;
175+
unsigned long currentAddress = 0;
176+
unsigned char data = 0x00;
177+
bool inEmptyRegion = false;
178+
179+
cout << "Finding empty regions..." << endl;
180+
181+
//for (unsigned long address = startAddress; address <= endAddress;
182+
// address ++)
183+
ihStat.begin();
184+
previousAddress = ihStat.currentAddress();
185+
186+
do
187+
{
188+
++ihStat;
189+
190+
currentAddress = ihStat.currentAddress();
191+
192+
if (currentAddress != (previousAddress + 1UL))
193+
{
194+
foundEmptyRegion = true;
195+
emptyRegionStart = previousAddress;
196+
emptyRegionEnd = currentAddress;
197+
emptyAddressCount = (currentAddress - previousAddress) + 1UL;
198+
cout << "Between 0x" << hex << uppercase << setw(8) \
199+
<< emptyRegionStart \
200+
<< " and 0x" << hex << uppercase << setw(8) \
201+
<< emptyRegionEnd \
202+
<< " are " << dec << emptyAddressCount \
203+
<< " free bytes." << endl;
204+
}
205+
206+
previousAddress = currentAddress;
207+
} while (!ihStat.endOfData());
208+
209+
if (foundEmptyRegion == false)
210+
{
211+
cout << " ...no empty regions in file." << endl;
212+
}
213+
214+
215+
221216
return(0);
222217
}

0 commit comments

Comments
 (0)