Skip to content

Commit

Permalink
update kvm
Browse files Browse the repository at this point in the history
  • Loading branch information
0vercl0k committed Feb 8, 2024
1 parent 6f344d2 commit 8c48d63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
41 changes: 21 additions & 20 deletions src/wtf/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,27 @@ union Rflags_t {
};

struct Fptw_t {
//
// The FXSAVE instruction saves an abridged version of the x87 FPU tag word
// in
// the FTW field (unlike the FSAVE instruction, which saves the complete tag
// word). The tag information is saved in physical register order (R0
// through R7), rather than in top-of-stack (TOS) order. With the FXSAVE
// instruction, however, only a single bit (1 for valid or 0 for empty) is
// saved for each tag. For example, assume that the tag word is currently
// set as follows:
//
// R7 R6 R5 R4 R3 R2 R1 R0
// 11 xx xx xx 11 11 11 11
//
// Here, 11B indicates empty stack elements and "xx" indicates valid (00B),
// zero (01B), or special (10B). For this example, the FXSAVE instruction
// saves only the following 8 bits of information:
//
// R7 R6 R5 R4 R3 R2 R1 R0
// 0 1 1 1 0 0 0 0
//

uint16_t Value = 0;

Fptw_t() = default;
Expand All @@ -1039,26 +1060,6 @@ struct Fptw_t {
}

uint8_t Abridged() const {
// The FXSAVE instruction saves an abridged version of the x87 FPU tag word
// in
// the FTW field (unlike the FSAVE instruction, which saves the complete tag
// word). The tag information is saved in physical register order (R0
// through R7), rather than in top-of-stack (TOS) order. With the FXSAVE
// instruction, however, only a single bit (1 for valid or 0 for empty) is
// saved for each tag. For example, assume that the tag word is currently
// set as follows:
//
// R7 R6 R5 R4 R3 R2 R1 R0
// 11 xx xx xx 11 11 11 11
//
// Here, 11B indicates empty stack elements and "xx" indicates valid (00B),
// zero (01B), or special (10B). For this example, the FXSAVE instruction
// saves only the following 8 bits of information:
//
// R7 R6 R5 R4 R3 R2 R1 R0
// 0 1 1 1 0 0 0 0
//

uint8_t Abridged = 0;
for (size_t Idx = 0; Idx < 8; Idx++) {
const uint16_t Bits = (Value >> (Idx * 2)) & 0b11;
Expand Down
6 changes: 3 additions & 3 deletions src/wtf/kvm_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,10 @@ bool KvmBackend_t::LoadFpu(const CpuState_t &CpuState) {

Fregs.fcw = CpuState.Fpcw;
Fregs.fsw = CpuState.Fpsw;
// Fregs.ftwx = ??
Fregs.ftwx = CpuState.Fptw.Abridged();
Fregs.last_opcode = CpuState.Fpop;
// Fregs.last_ip = ??
// Fregs.last_dp = ??
Fregs.last_ip = 0;
Fregs.last_dp = 0;
Fregs.mxcsr = CpuState.Mxcsr;
for (uint64_t Idx = 0; Idx < 16; Idx++) {
memcpy(Fregs.xmm[Idx], &CpuState.Zmm[Idx].Q[0], 16);
Expand Down

0 comments on commit 8c48d63

Please sign in to comment.