// The OS/K Team licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #include //----------------------------------------------------------------------------// IMPL_START(jmp) { R(RIP) = p1->val; return 0; } IMPL_START(loop) { if (R(RCX) > 0) { R(RCX)--; R(RIP) = p1->val; } return 0; } IMPL_START(b) { SRCP(p1); SRCP(p2); COMPARE_SUB(p1->val, p2->val); if (eval_cond(ctx->cond)) R(RIP) = p3->val; return 0; } IMPL_START(cmp) { SRCP(p1); COMPARE_SUB(p1->val, p2->val); return 0; } //----------------------------------------------------------------------------// IMPL_START(lea) { *r1 = p2->addr; return 1; } IMPL_START(mov) { XSRCP(*r1, p2, sx); return 1; } IMPL_START(movzx) { XSRCP(*r1, p2, zx); return 1; } IMPL_START(movsxb) { SRCP(p2); *r1 = (ulong)(long)(char)p2->val; return 1; } IMPL_START(movsxw) { SRCP(p2); *r1 = (ulong)(long)(short)p2->val; return 1; } IMPL_START(movsxd) { SRCP(p2); *r1 = (ulong)(long)(int)p2->val; return 1; } IMPL_START(xchg) { SRCP(p1); SRCP(p2); *r2 = p1->val; *r1 = p2->val; return 2; } //----------------------------------------------------------------------------// // // Stack manipulation instructions // IMPL_START(push) { XSRCP(p1->val, p1, zx); R(RSP) -= 8; writemem(p1->val, R(RSP), 8); return 0; } IMPL_START(pop) { *r1 = readmemzx(R(RSP), 8); R(RSP) += 8; return 1; } IMPL_START(call) { SRCP(p1); R(RSP) -= 8; writemem(R(RIP), R(RSP), 8); R(RIP) = p1->val; return 0; } IMPL_START(xcall2) { SRCP(p1); SRCP(p2); R(RSP) -= 8; writemem(R(RIP), R(RSP), 8); R(RIP) = p1->val; R(AX0) = p2->val; return 0; } IMPL_START(xcall3) { SRCP(p1); SRCP(p2); SRCP(p3); R(RSP) -= 8; writemem(R(RIP), R(RSP), 8); R(RIP) = p1->val; R(AX0) = p2->val; R(AX1) = p3->val; return 0; } IMPL_START(ret) { R(RIP) = readmemzx(R(RSP), 8); R(RSP) += 8; return 0; } IMPL_START(enter) { writemem(R(RBP), R(RSP) - 8, 8); R(RBP) = R(RSP) - 8; R(RSP) -= (p1->val + 1) * 8; return 0; } IMPL_START(leave) { R(RSP) = R(RBP) + 8; R(RBP) = readmemzx(R(RBP), 8); return 0; } //----------------------------------------------------------------------------//