Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support (partially) far calls #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion remill/Arch/Runtime/HyperCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class AsyncHyperCall {
kX86SysEnter,
kX86SysExit,

// Far jumps: CS should be updated.
// Far jumps/calls: CS should be updated.
kX86JmpFar,
kX86CallFar,

kAArch64SupervisorCall,

Expand Down
20 changes: 20 additions & 0 deletions remill/Arch/X86/Semantics/CALL_RET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ DEF_SEM(CALL, T target_pc, PC return_pc) {
return memory;
}

template <typename S1, typename S2>
DEF_SEM(CALL_FAR_PTR, S1 target_pc, S2 target_seg, PC return_pc) {
HYPER_CALL = AsyncHyperCall::kX86CallFar;

addr_t next_sp = USub(REG_XSP, ADDRESS_SIZE_BYTES * 2);

// stack update
WriteZExt(WritePtr<addr_t>(next_sp + ADDRESS_SIZE_BYTES), Read(REG_CS.flat));
Write(WritePtr<addr_t>(next_sp _IF_32BIT(REG_SS_BASE)), Read(return_pc));

// register update
Write(REG_XSP, Read(next_sp));
WriteZExt(REG_PC, Read(target_pc));
Write(REG_CS.flat, Read(target_seg));

return memory;
}

DEF_SEM(RET_IMM, I16 bytes) {
Write(REG_PC, Read(ReadPtr<addr_t>(REG_XSP _IF_32BIT(REG_SS_BASE))));
Write(REG_XSP,
Expand All @@ -53,6 +71,8 @@ IF_32BIT( DEF_ISEL(CALL_NEAR_GPRv_16) = CALL<R16>; )
IF_32BIT( DEF_ISEL(CALL_NEAR_GPRv_32) = CALL<R32>; )
IF_64BIT( DEF_ISEL(CALL_NEAR_GPRv_64) = CALL<R64>; )

IF_32BIT( DEF_ISEL(CALL_FAR_PTRp_IMMw_32) = CALL_FAR_PTR<PC, I16>; )

/*
352 CALL_FAR CALL_FAR_MEMp2 CALL BASE I86 ATTRIBUTES: FAR_XFER FIXED_BASE1 NOTSX SCALABLE STACKPUSH1
353 CALL_FAR CALL_FAR_PTRp_IMMw CALL BASE I86 ATTRIBUTES: FAR_XFER FIXED_BASE0 NOTSX SCALABLE STACKPUSH0
Expand Down