An X86 emulator written using Java A dissertation submitted to the University of Manchester for the degree of Master of Science in the Faculty of Engineering and Physical Sciences. 2005 Jonathan Kenneth William Burcham School of Computer Science 1 Contents Abstract ..................................................................................................................6 Declaration .............................................................................................................7 Copyright ...............................................................................................................8 Acknowledgements................................................................................................9 The Author ...........................................................................................................10 1 Emulation with Pearcolator...............................................................................11 1.1 Emulation...................................................................................................11 1.2 Pearcolator..................................................................................................12 2 Emulating x86 Linux ........................................................................................13 2.1 Evaluation of the x86 Linux Environment.................................................13 2.2 X86 Architecture........................................................................................14 2.2.1 Overview.............................................................................................14 2.2.2 Registers..............................................................................................14 2.2.3 Addressing Modes...................................................................................18 3 Environment......................................................................................................19 3.1 Introduction................................................................................................19 3.2 Process Space.............................................................................................19 3.2.1 Overview.............................................................................................19 3.2.2 Registers..............................................................................................20 3.2.3 Memory...............................................................................................21 3.2.4 System Calls........................................................................................23 3.3 Binary Loader.............................................................................................25 3.3.1 Introduction.........................................................................................25 3.3.2 Purpose of Binary Formats .................................................................26 3.3.3 The ELF Binary Format......................................................................26 3.3.4 A problem with the Old Binary Loader ..............................................27 3.3.5 Determination of Binary Format.........................................................28 3.3.6 Reading ELF Header...........................................................................29 3.3.7 Creating ELF Program Header Table .................................................29 3.3.8 Reading ELF Program Headers ..........................................................29 3.3.9 Copy Executable Code........................................................................29 2 3.3.10 Copy Initialised Data ........................................................................30 3.3.11 Configure Uninitialised Data ............................................................30 3.3.12 Environment Variables .....................................................................30 3.3.13 Aux Vector........................................................................................31 3.3.14 Stack Initialisation.............................................................................31 4 Register Handling..............................................................................................33 4.1 Introduction................................................................................................33 4.2 Register handling in PowerPC Pearcolator................................................33 4.3 Register Handling in x86 Pearcolator ........................................................34 4.3.1 Introduction.........................................................................................34 4.3.2 Sub Register Synchronisation Laziness ..............................................35 4.3.3 Removing Unnecessary Fills and Spills..............................................37 4.3.4 First Version........................................................................................37 4.3.5 Second Version ...................................................................................37 4.3.6 Third Version ......................................................................................38 4.3.7 Fourth Version ....................................................................................38 4.3.8 Alternative Implementation ................................................................39 4.4 Flag Handling.............................................................................................41 4.4.1 Introduction.........................................................................................41 4.4.2 Flag Laziness.......................................................................................41 5 Instruction Decoder...........................................................................................42 5.1 Introduction................................................................................................42 5.2 Instruction Format......................................................................................42 5.2.1 Instruction Prefix Field .......................................................................43 5.2.2 Opcode Field.......................................................................................43 5.2.3 ModR/M Field.....................................................................................43 5.2.4 SIB Field .............................................................................................44 5.2.5 Displacement Field .............................................................................45 5.2.6 Immediate Data ...................................................................................45 5.3 Decoder Implementations ..........................................................................45 5.3.1 QEMU.................................................................................................46 5.3.2 Bochs...................................................................................................46 5.3.3 libdisasm .............................................................................................46 5.3.4 libopcodes ...........................................................................................47 3 5.3.5 Jikes RVM...........................................................................................47 5.3.6 ndisasm................................................................................................47 5.3.7 Sled......................................................................................................48 5.3.8 Chosen Implementation ......................................................................48 5.4 Decoder Components.................................................................................48 5.4.1 X86_BaseInstructionDecoder Class ...................................................49 5.4.2 Instruction Class..................................................................................49 5.4.3 OpcodeFunction Class ........................................................................49 5.4.4 Opcode Decoder..................................................................................49 5.4.5 Operands .............................................................................................50 5.5 Improving the Decoder ..............................................................................51 6 Emulation Modes ..............................................................................................53 6.1 Introduction................................................................................................53 6.2 Code Translation ........................................................................................53 6.2.1 Introduction.........................................................................................53 6.2.2 Single Instruction Translation.............................................................54 6.2.3 Trace Translation Mode......................................................................55 6.2.4 Structure ..................................................................................................56 6.2.5 Branch Handling .....................................................................................56 6.2.6 Reusing HIR........................................................................................57 6.2.7 Planting Method Calls.........................................................................57 6.2.8 Compilation.........................................................................................58
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages66 Page
-
File Size-