@@ -34,8 +34,11 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
34
34
if (first_word == " Registers" ) {
35
35
vector<string> registers;
36
36
StringSplit (' ' , line, ®isters);
37
- for (int i = 1 ; i < registers.size (); i++) {
38
- registers_.push_back (make_pair (registers[i], m->AllocateSegment (registers[i], 4 )));
37
+ int size = stoi (registers[1 ])/8 ;
38
+ for (int i = 2 ; i < registers.size (); i++) {
39
+ Address* this_address = m->AllocateSegment (registers[i], size);
40
+ this_address->set_size (size);
41
+ registers_.push_back (make_pair (registers[i], this_address));
39
42
}
40
43
} else if (first_word == " DefaultChange" ) {
41
44
// 0 is Change, 1 is bits, 2 is target, 3... is change
@@ -62,19 +65,39 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
62
65
}
63
66
if (current != NULL ) instructioncomprehensions_.push_back (current);
64
67
LOG (INFO) << " read " << current_line_ << " lines of comprehension" ;
68
+
69
+ map<char , uint32_t > psuedo_local_scope;
70
+ program_counter_ = memory_->ResolveToAddress (0 , EvalulateStringInScope (global_scope_, psuedo_local_scope, " {ProgramCounter}" ));
71
+ link_register_ = memory_->ResolveToAddress (0 , EvalulateStringInScope (global_scope_, psuedo_local_scope, " {LinkRegister}" ));
72
+ stack_pointer_ = memory_->ResolveToAddress (0 , EvalulateStringInScope (global_scope_, psuedo_local_scope, " {StackPointer}" ));
73
+ program_counter_offset_ = memory_->ResolveToNumber (0 , EvalulateStringInScope (global_scope_, psuedo_local_scope, " {ProgramCounterOffset}" ));
65
74
}
66
75
67
- Address* InstructionFactoryISDF::Process (Address* start) {
68
- uint32_t opcode;
69
- Address* ret = start->get32 (0 , &opcode); // hmm, bad size
76
+ void InstructionFactoryISDF::StateToXML (std::ostringstream& out) {
77
+ out << std::hex;
78
+ out << " <Core>" ;
79
+ out << " <ProgramCounter>" << GetProgramCounter () << " </ProgramCounter>" ;
80
+ out << " <StackPointer>" << GetStackPointer () << " </StackPointer>" ;
81
+ out << " <registers>" ;
82
+
83
+ for (vector<pair<string, Address*> >::iterator it = registers_.begin (); it!=registers_.end (); ++it) {
84
+ uint32_t data;
85
+ it->second ->get (0 , &data);
86
+ out << " <" << it->first << " >" << data << " </" << it->first << " >" ;
87
+ }
88
+
89
+ out << " </registers>" ;
90
+ out << " </Core>" ;
91
+ }
70
92
93
+ Address* InstructionFactoryISDF::Process (Address* start) {
71
94
map<string, string> global_scope_copy = global_scope_;
72
95
73
96
StatelessChangelist* change = new StatelessChangelist;
74
- ParsedInstruction* parsed = new ParsedInstruction;
97
+ ParsedInstruction* parsed = new ParsedInstruction (start) ;
75
98
76
99
for (vector<InstructionComprehension*>::iterator it = instructioncomprehensions_.begin (); it != instructioncomprehensions_.end (); ++it) {
77
- if ((*it)->Execute (opcode , &global_scope_copy, change, parsed) == true ) break ;
100
+ if ((*it)->Execute (start , &global_scope_copy, change, parsed) == true ) break ;
78
101
}
79
102
80
103
for (map<string, pair<int , string> >::iterator it = default_changes_.begin (); it != default_changes_.end (); ++it) {
@@ -100,7 +123,8 @@ Address* InstructionFactoryISDF::Process(Address* start) {
100
123
LOG (DEBUG) << " Parsed -- " << parsed->GetConsoleString ();
101
124
102
125
start->set_instruction (new Instruction (parsed, change, start, 4 ));
103
- return ret;
126
+ uint32_t data;
127
+ return start->get (0 , &data);
104
128
}
105
129
106
130
// Okay, I know I'm not supposed to work in the constructor...
@@ -190,9 +214,12 @@ void InstructionComprehension::AddLine(const string& linein) {
190
214
}
191
215
}
192
216
193
- bool InstructionComprehension::Execute (uint32_t data, map<string, string>* global_scope, StatelessChangelist* change, ParsedInstruction* parsed) {
217
+ bool InstructionComprehension::Execute (Address* opcode, map<string, string>* global_scope, StatelessChangelist* change, ParsedInstruction* parsed) {
218
+ opcode->set_size (bitsize_/8 );
219
+ uint32_t data;
220
+ opcode->get (0 , &data);
194
221
if ( (data & mask_) != data_) {
195
- // LOG(DEBUG) << std::hex << "No match on data " << data << " with data " << data_ << " and mask " << mask_;
222
+ // LOG(DEBUG) << std::hex << "No match on data " << data << " with data " << data_ << " and mask " << mask_ << " and bitsize " << bitsize_ ;
196
223
return false ;
197
224
}
198
225
@@ -206,7 +233,13 @@ bool InstructionComprehension::Execute(uint32_t data, map<string, string>* globa
206
233
}
207
234
// Evaluate global scope
208
235
for (map<string, string>::iterator it = global_scope_additions_.begin (); it != global_scope_additions_.end (); ++it) {
209
- (*global_scope)[it->first ] = parent_->EvalulateStringInScope (*global_scope, local_scope, it->second );
236
+ string varname = it->first ;
237
+ if (varname[varname.length ()-1 ] == ' +' ) {
238
+ (*global_scope)[varname.substr (0 ,varname.length ()-1 )] += parent_->EvalulateStringInScope (*global_scope, local_scope, it->second );
239
+ } else {
240
+ (*global_scope)[varname] += parent_->EvalulateStringInScope (*global_scope, local_scope, it->second );
241
+ }
242
+
210
243
LOG (DEBUG) << " added " << it->first << " to the global scope: " << (*global_scope)[it->first ];
211
244
}
212
245
// Add Parsed
@@ -251,7 +284,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
251
284
// Find {...} shit and replace it
252
285
// {{...}} is registers
253
286
// {|...|} is eval to hex number
254
- LOG (DEBUG) << " eval start: " << evalme;
287
+ // LOG(DEBUG) << "eval start: " << evalme;
255
288
string out = " " ;
256
289
int p = 0 ;
257
290
int last = 0 ;
@@ -274,7 +307,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
274
307
}
275
308
} else if (parsethis[1 ] == ' |' ) { // Hex
276
309
string dataeval = EvalulateStringInScope (global_scope, local_scope, parsethis.substr (2 , parsethis.length ()-4 ) );
277
- LOG (DEBUG) << " resolving: " << dataeval;
310
+ // LOG(DEBUG) << " resolving: " << dataeval;
278
311
replace = immed (memory_->ResolveToNumber (0 , dataeval));
279
312
} else {
280
313
string variable = parsethis.substr (1 , parsethis.length ()-2 );
@@ -291,14 +324,14 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
291
324
}
292
325
}
293
326
}
294
- LOG (DEBUG) << " parsing \" " << parsethis << " \" to \" " << replace << " \" " ;
327
+ // LOG(DEBUG) << " parsing \"" << parsethis << "\" to \"" << replace << "\"";
295
328
out += evalme.substr (last, p-last) + replace;
296
329
297
330
p = close +1 ;
298
331
last = p;
299
332
}
300
333
301
334
out += evalme.substr (last);
302
- LOG (DEBUG) << " eval done: \" " << evalme << " \" to \" " << out << " \" " ;
335
+ // LOG(DEBUG) << "eval done: \"" << evalme << "\" to \"" << out << "\"";
303
336
return out;
304
337
}
0 commit comments