|
|
far jump in 64-bit mode
Hi, all
I am doing a work which is mixing up 32-bit code and 64-bit code in a
process.
I use LLVM JIT, and try to compile some 32-bit code. I have to do "far
jump" to other code segment, to make 32-bit code can be decoded. At
this part, I inline asm into the C program, and i execute it. But I
got a segmentation fault. The follows are source code, any help and
suggestion are good for me. Thanks very much.
#include <string>
#include <memory>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <llvm/LLVMContext.h>
#include <llvm/Target/TargetSelect.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/JIT.h>
using namespace std;
using namespace llvm;
typedef unsigned long long W64;
typedef unsigned int W32;
typedef unsigned short W16;
typedef W64 Waddr;
struct FarJumpDescriptor {
W32 offset;
W16 seg;
};
#define LO32(x) (W32)((x) & 0xffffffffLL)
#define USER_CS "0x33"
#define USER32_CS "0x23"
#define USER_DS "0x2b"
int main()
{
InitializeNativeTarget();
llvm_start_multithreaded();
LLVMContext context;
string error;
MemoryBuffer *buffer = MemoryBuffer::getFile("tst.bc");
Module *m = ParseBitcodeFile( buffer, context, &error);
//setting jit builder
EngineBuilder builder = EngineBuilder(m);
builder.setMArch("x86");
builder.setEngineKind(EngineKind::JIT);
//create JIT
ExecutionEngine* execution_engine = builder.create();
Function* func = execution_engine->FindFunctionNamed("main");
void (*entry_point)();
entry_point = reinterpret_cast<void(*)()>(execution_engine-
>getPointerToFunction(func));
printf("entry_point:%p\n", entry_point);
FarJumpDescriptor desc;
desc.offset = LO32((Waddr)entry_point);
desc.seg = 0x33;
printf("offset:%p\n", desc.offset);
asm volatile(
"lea %[desc],%%eax \n"
"ljmp *(%%eax) \n"
: : [desc] "m" (desc)
);
return 0;
}
|
|
0
|
|
|
|
Reply
|
joannechiou
|
11/25/2010 8:15:43 AM |
|
|
0 Replies
587 Views
(page loaded in 0.027 seconds)
Similiar Articles: far jump in 64-bit mode - comp.lang.asm.x86Hi, all I am doing a work which is mixing up 32-bit code and 64-bit code in a process. I use LLVM JIT, and try to compile some 32-bit code. I have to do "far jump" to ... Far jump - comp.lang.asm.x86far jump in 64-bit mode - comp.lang.asm.x86 Hi, all I am doing a work which is mixing up 32-bit code and 64-bit code in a process. I use LLVM JIT, and try to compile some ... How to encode an unconditional jump in 64-bit mode? - comp.lang ...far jump in 64-bit mode - comp.lang.asm.x86 Intel's manual says: "REX.W + FF /5 JMP m16:64 Jump far, absolute indirect ... Re: How to encode an unconditional jump in 64 ... x86 instruction size length - comp.lang.asm.x86far jump in 64-bit mode - comp.lang.asm.x86 x86 instruction size length - comp.lang.asm.x86 What I understood so far, in full 64-bit mode (not compatible long mode): the ... FAR CALL/JMP to an absolute address - comp.lang.asm.x86Far jump - comp.lang.asm.x86 FAR CALL/JMP to an absolute address - comp.lang.asm.x86 far jump in 64-bit mode - comp.lang.asm.x86 Far Cry 64 bit and Windows 7: It works ... Variadic Macros - comp.lang.c++.moderatedfar jump in 64-bit mode - comp.lang.asm.x86 Variadic Macros - comp.lang.c++.moderated far jump in 64-bit mode - comp.lang.asm.x86 Variadic Macros - comp.lang.c++.moderated ... Segmentation source code - comp.soft-sys.matlabfar jump in 64-bit mode - comp.lang.asm.x86 Segmentation source code - comp.soft-sys.matlab far jump in 64-bit mode - comp.lang.asm.x86 got a segmentation fault. [bochs][nasm][video memory] - comp.lang.asm.x86far jump in 64-bit mode - comp.lang.asm.x86 #include <string> #include <memory> #include <iostream> #include <stdio.h> #include ... Far jump - comp.lang.asm.x86 NASM 64 ... Segmentation fault on trying to deliver to bighotpay.com - comp ...far jump in 64-bit mode - comp.lang.asm.x86 I use LLVM JIT, and try to compile some 32-bit code. I have to... ... comp.soft-sys.matlab far jump in 64-bit mode - comp.lang ... 64-bit byteswapping and legacy programs - comp.lang.fortran ...Far jump - comp.lang.asm.x86 64-bit byteswapping and legacy programs - comp.lang.fortran ... Intel Thermal sensor - comp.lang.asm.x86 far jump in 64-bit mode - comp.lang ... far jump in 64-bit mode - comp.lang.asm.x86 | Computer GroupHi, all I am doing a work which is mixing up 32-bit code and 64-bit code in a process. I use LLVM JIT, and try to compile some 32-bit code. I have to do "far jump" to ... Re: How to encode an unconditional jump in 64-bit mode?Intel's manual says: "REX.W + FF /5 JMP m16:64 Jump far, absolute indirect ... Re: How to encode an unconditional jump in 64-bit mode?... that emits 48h... 7/26/2012 3:15:55 PM
|
|
|
|
|
|
|
|
|