Skip to content

Commit f3ddaec

Browse files
committedJul 3, 2019
Instructions update and encoding enhanced.
Be permissive when signed argument is defined as unsigned value near 2^32 because it is usual way how the negative arguments are encoded on 32-bit system. Signed-off-by: Pavel Pisa <[email protected]>
1 parent ea607be commit f3ddaec

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed
 

‎qtmips_machine/instruction.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,13 @@ void instruction_from_string_build_base(const InstructionMap *im = nullptr,
10511051
}
10521052
if (!(im->flags & IMF_SUPPORTED))
10531053
continue;
1054-
str_to_instruction_code_map.insert(im->name, code);
1055-
#if 0
10561054
if (im->code != code) {
1055+
#if 0
10571056
printf("code mitchmatch %s computed 0x%08x found 0x%08x\n", im->name, code, im->code);
1057+
#endif
1058+
continue;
10581059
}
1059-
#endif
1060+
str_to_instruction_code_map.insert(im->name, code);
10601061
}
10611062
#if 0
10621063
for (auto i = str_to_instruction_code_map.begin();
@@ -1074,11 +1075,17 @@ static int parse_reg_from_string(QString str, uint *chars_taken = nullptr)
10741075
return -1;
10751076

10761077
if (str.at(1).isLetter()) {
1077-
str = str.mid(1);
1078+
int k = 1;
1079+
while(k < str.count()) {
1080+
if (!str.at(k).isLetterOrNumber())
1081+
break;
1082+
k++;
1083+
}
1084+
str = str.mid(1, k-1);
10781085
for (i = 0 ; i < REGISTER_CODES; i++) {
10791086
if (str == regbycode[i].name) {
10801087
if (chars_taken != nullptr)
1081-
*chars_taken = str.count() + 1;
1088+
*chars_taken = k;
10821089
return regbycode[i].number;
10831090
}
10841091
}
@@ -1235,7 +1242,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize,
12351242
break;
12361243
case 'a':
12371244
shift_right += options & 0xff;
1238-
val -= (inst_addr + 4) & 0xf0000000;
1245+
val -= (inst_addr + 4) & ~(std::int64_t)0x0fffffff;
12391246
if(fl.at(0).isDigit() || (reloc == nullptr)) {
12401247
std::uint64_t num_val;
12411248
int i;
@@ -1256,7 +1263,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize,
12561263
need_reloc = true;
12571264
}
12581265
if (need_reloc && (reloc != nullptr)) {
1259-
reloc_append(reloc, fl, val, inst_addr, adesc, &chars_taken, line, options);
1266+
reloc_append(reloc, fl, inst_addr, val, adesc, &chars_taken, line, options);
12601267
val = 0;
12611268
}
12621269
break;
@@ -1326,7 +1333,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize,
13261333
error = QString("error in LUI element of " + inst_base);
13271334
return -1;
13281335
}
1329-
inst_fields.insert(1, "$0");
1336+
inst_fields.insert(1, inst_fields.at(0));
13301337
if (code_from_string(code + 1, buffsize - 4, "ORI", inst_fields, error,
13311338
inst_addr + 4, reloc, line, false,
13321339
CFS_OPTION_SILENT_MASK + 0) < 0) {
@@ -1378,6 +1385,8 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize,
13781385
bool Instruction::update(std::int64_t val, RelocExpression *relocexp) {
13791386
std::int64_t mask = (((std::int64_t)1 << relocexp->bits) - 1) << relocexp->lsb_bit;
13801387
dt &= ~ mask;
1388+
if (relocexp->shift)
1389+
printf("reloc shift\n");
13811390
val += relocexp->offset;
13821391
if ((val & ((1 << relocexp->shift) - 1)) &&
13831392
!(relocexp->options & CFS_OPTION_SILENT_MASK)) {
@@ -1392,7 +1401,9 @@ bool Instruction::update(std::int64_t val, RelocExpression *relocexp) {
13921401
if (relocexp->min < 0) {
13931402
if (((std::int64_t)val < relocexp->min) ||
13941403
((std::int64_t)val > relocexp->max)) {
1395-
return false;
1404+
if (((std::int64_t)val - 0x100000000 < relocexp->min) ||
1405+
((std::int64_t)val - 0x100000000 > relocexp->max))
1406+
return false;
13961407
}
13971408
} else {
13981409
if (((std::uint64_t)val < (std::uint64_t)relocexp->min) ||

0 commit comments

Comments
 (0)
Please sign in to comment.