Skip to content

Commit

Permalink
Reworked 0F 01 opcode ([ARM64_DYNAREC] too)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jan 26, 2024
1 parent aab6bc0 commit 1d0d7e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 46 deletions.
39 changes: 30 additions & 9 deletions src/dynarec/arm64/dynarec_arm64_0f.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
case 0x01:
// TODO:, /0 is SGDT. While 0F 01 D0 is XGETBV, etc...
nextop = F8;
if(MODREG)
switch(nextop) {
case 0xD0:
INST_NAME("FAKE xgetbv");
Expand All @@ -78,15 +79,35 @@ uintptr_t dynarec64_0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
*ok = 0;
break;
default:
switch((nextop>>3)&7) {
case 0: // SGDT
INST_NAME("FAKE sgdt Ed");
addr = fakeed(dyn, addr, ninst, nextop);
// do nothing for now...
break;
default:
DEFAULT;
}
DEFAULT;
} else
switch((nextop>>3)&7) {
case 0: // SGDT
INST_NAME("SGDT Ed");
addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, NULL, 0, 0, rex, NULL, 0, 0);
MOV32w(x1, 0x7f);
STURH_I9(x1, wback, 0);
MOV32w(x1, 0x000c);
STURH_I9(x1, wback, 2);
MOV32w(x1, 0xd000);
STURH_I9(x1, wback, 4);
break;
case 1:
INST_NAME("SIDT Ed");
addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, NULL, 0, 0, rex, NULL, 0, 0);
MOV32w(x1, 0xfff);
STURH_I9(x1, wback, 0);
STURw_I9(xZR, wback, 2);
break;
case 4:
INST_NAME("SMSW Ew");
addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, NULL, 0, 0, rex, NULL, 0, 0);
// dummy for now... Do I need to track CR0 state?
MOV32w(x1, (1<<0) | (1<<4)); // only PE and ET set...
STURH_I9(x1, wback, 0);
break;
default:
DEFAULT;
}
break;

Expand Down
61 changes: 24 additions & 37 deletions src/emu/x64run0f.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,48 +86,35 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
return 0;
break;
case 0x01: /* XGETBV, SGDT, etc... */
// this is a privilege opcode...
nextop = F8;
GETED(0);
if(MODREG)
switch(nextop) {
case 0xD0:
#ifndef TEST_INTERPRETER
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
#endif
break;
#ifndef TEST_INTERPRETER
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
#endif
break;
default:
if(rex.is32bits) {
switch((nextop>>3)&7) {
case 0: /* SGDT Ed */
GETED(0);
ED->word[0] = 0x7f; // dummy return...
ED->word[1] = 0x000c;
ED->word[2] = 0xd000;
break;
case 1: /* SIDT Ed */
GETED(0);
ED->word[0] = 0xfff; // dummy return, like "disabled"
ED->word[1] = 0;
ED->word[2] = 0;
break;
case 4: /* SMSW Ew */
GETED(0);
// dummy for now... Do I need to track CR0 state?
ED->word[0] = (1<<0) | (1<<4); // only PE and ET set...
break;
default:
return 0;
}

} else {
switch((nextop>>3)&7) {
case 0: // SGDT
// do nothing for now...
break;
default:
return 0;
}
}
return 0;
} else
switch((nextop>>3)&7) {
case 0: /* SGDT Ed */
ED->word[0] = 0x7f; // dummy return...
ED->word[1] = 0x000c;
ED->word[2] = 0xd000;
break;
case 1: /* SIDT Ed */
ED->word[0] = 0xfff; // dummy return, like "disabled"
ED->word[1] = 0;
ED->word[2] = 0;
break;
case 4: /* SMSW Ew */
// dummy for now... Do I need to track CR0 state?
ED->word[0] = (1<<0) | (1<<4); // only PE and ET set...
break;
default:
return 0;
}
break;

Expand Down

0 comments on commit 1d0d7e9

Please sign in to comment.