Not all experts agree on the same definition of a basic block, but most think that such a block should be terminated by an instruction which has the possibility to interrupt the sequential execution, ie. In compiler theory such a code sequence is called a basic block. Sequence and the next branch as its terminator. The branch target thus acts as the start of the new code If it wasn't performed before, a new translation task is started when the code sequence to be executed is changed, meaning when a branch/jump/call occurs. The question now is how the binary translator knows which parts to translate if it doesn't translate the whole code. Only those parts of the application which are really executed will be translated, as can be seen in the following part of the loop where the called code is translated if it hasn't been done already: * handle interrupts and other events here */ The simplified main loop of the DynaRec (often called dispatcher) might be written as: We also need to pass the current context (register values, status flags, and the like) to the translated code, thus the function pointer could look like this: The function should return some state so that we know if the code block terminated correctly, if an error occured, or if the code sequence was interrupted. First of all we need to define a function pointer to call the translated code. Let's take a closer look at how a DynaRec works in a simplified form. How does Dynamic Recompilation work in principle? The difference is that a DynaRec has to deal with low level machine code, probably full of dirty programming tricks, rather than more high-level bytecode produced by a compiler. Given the definition above it becomes obvious that a DynaRec is indeed similar to the just-in-time (JIT) compilers used in some Java runtime environments. But most people use these terms synonymously and don't imply whether self-modifying code is handled or not. Some people even distinguish between dynamic compilation and recompilation, where the latter handles self-modifying code and the former does not. Therefore I prefer the term Dynamic Binary Translation, but DynaRec is already well-established. But dynamic recompilation means that you take the binary code (the executable file, eg.) and translate this into native machine code on another machine during runtime. The problem is that you can take some source code and "recompile" it on a differnt platform. The term recompilation is a bit confusing since it is a bit ambigious and doesn't exactly name the process performed. So what does this term mean? First of all, DynaRec is an an abreviation of Dynamic Recompilation or Dynamic Recompiler. More and more of the newer emulators replace their interpretive cores with a DynaRec. Maybe I should rename it to "Everything you have always wanted to know about Dynamic Recompilation but were afraid to ask" someday. The name DRFAQ isn't quite correct since I deviated from the typical question-answer structure, but as long as no real FAQ is compiled this page shall answer most of the questions about Dynamic Recompilation. DRFAQ Dynamic Recompilation - Freqently Asked Questions by Michael König (aka M.I.K.e)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |