@@ -765,6 +765,59 @@ Instruction &Instruction::operator=(const Instruction &c) {
765765 return *this ;
766766}
767767
768+ int32_t extend (uint32_t value, uint32_t used_bits) {
769+ return value | ~((value & (1 << (used_bits - 1 ))) - 1 );
770+ }
771+
772+ QString field_to_string (int32_t field, const ArgumentDesc* arg_desc, Address inst_addr, bool symbolic_registers_enabled) {
773+ QString res = " " ;
774+ if (arg_desc->min < 0 ) {
775+ field = extend (field, [&]() {
776+ int sum = (int )arg_desc->arg .shift ;
777+ for (auto chunk : arg_desc->arg ) {
778+ sum += chunk.count ;
779+ }
780+ return sum;
781+ }());
782+ }
783+ switch (arg_desc->kind ) {
784+ case ' g' : {
785+ if (symbolic_registers_enabled) {
786+ res += QString (Rv_regnames[field]);
787+ } else {
788+ res += " x" + QString::number (field);
789+ }
790+ break ;
791+ }
792+ case ' p' :
793+ case ' a' : {
794+ field += (int32_t )inst_addr.get_raw ();
795+ res.append (str::asHex (field));
796+ break ;
797+ }
798+ case ' o' :
799+ case ' n' : {
800+ if (arg_desc->min < 0 ) {
801+ res += QString::number ((int32_t )field, 10 );
802+ } else {
803+ res.append (str::asHex (uint32_t (field)));
804+ }
805+ break ;
806+ }
807+ case ' E' : {
808+ if (symbolic_registers_enabled) {
809+ try {
810+ res += CSR::REGISTERS[CSR::REGISTER_MAP.at (CSR::Address (field))].name ;
811+ } catch (std::out_of_range &e) { res.append (str::asHex (field)); }
812+ } else {
813+ res.append (str::asHex (field));
814+ }
815+ break ;
816+ }
817+ }
818+ return res;
819+ }
820+
768821QString Instruction::to_str (Address inst_addr) const {
769822 const InstructionMap &im = InstructionMapFind (dt);
770823 // TODO there are exception where some fields are zero and such so we should
@@ -787,50 +840,7 @@ QString Instruction::to_str(Address inst_addr) const {
787840 continue ;
788841 }
789842 auto field = (int32_t )arg_desc->arg .decode (this ->dt );
790- if (arg_desc->min < 0 ) {
791- field = extend (field, [&]() {
792- int sum = (int )arg_desc->arg .shift ;
793- for (auto chunk : arg_desc->arg ) {
794- sum += chunk.count ;
795- }
796- return sum;
797- }());
798- }
799- switch (arg_desc->kind ) {
800- case ' g' : {
801- if (symbolic_registers_enabled) {
802- res += QString (Rv_regnames[field]);
803- } else {
804- res += " x" + QString::number (field);
805- }
806- break ;
807- }
808- case ' p' :
809- case ' a' : {
810- field += (int32_t )inst_addr.get_raw ();
811- res.append (str::asHex (field));
812- break ;
813- }
814- case ' o' :
815- case ' n' : {
816- if (arg_desc->min < 0 ) {
817- res += QString::number ((int32_t )field, 10 );
818- } else {
819- res.append (str::asHex (uint32_t (field)));
820- }
821- break ;
822- }
823- case ' E' : {
824- if (symbolic_registers_enabled) {
825- try {
826- res += CSR::REGISTERS[CSR::REGISTER_MAP.at (CSR::Address (field))].name ;
827- } catch (std::out_of_range &e) { res.append (str::asHex (field)); }
828- } else {
829- res.append (str::asHex (field));
830- }
831- break ;
832- }
833- }
843+ res += field_to_string (field, arg_desc, inst_addr, symbolic_registers_enabled);
834844 }
835845 }
836846 return res;
@@ -1312,6 +1322,17 @@ uint32_t Instruction::parse_field(
13121322 if (effective_mod != Modifier::NONE) {
13131323 val = modify_pseudoinst_imm (effective_mod, val);
13141324 } else if (!adesc->is_value_in_field_range (val)) {
1325+ if (adesc->min < 0 ) {
1326+ printf (" val(-): %ld\n " , val);
1327+ printf (" val(-): 0x%lx\n " , val);
1328+ // return val.as_i64() <= max && val.as_i64() >= min;
1329+
1330+ printf (" val(-) <= max(%ld): %d\n " , adesc->max , (int64_t )val <= adesc->max );
1331+ printf (" val(-) >= min(%ld): %d\n " , adesc->min , (int64_t )val >= adesc->min );
1332+
1333+ } else {
1334+ printf (" val(+): 0x%lx\n " , val);
1335+ }
13151336 throw ParseError (" argument range exceed" );
13161337 }
13171338
0 commit comments