PCSX2 Documentation/PCSX2 EE Recompiler: Difference between revisions

Line 22: Line 22:
== Internal detail of the EE recompiler ==
== Internal detail of the EE recompiler ==


An important part of the recompiler is the management of block. You can see below a nice schematic.
An important part of the recompiler is the management of various blocks (x86/EE etc...). You can see below a nice schematic with the links between them.


[[File:Recompiler_block.png]]
[[File:Recompiler_block.png]]


=== PS2 Virtual space ===


The PS2 virtual space is composed of EE instructions. An instruction is always 4B. An instruction can be anywhere in the 4GB address space of the PS2 (yes 4GB). Of course those 4GB are mapped physically into a 32MB RAM or 4MB ROM. The address of the current instruction is stored inside an HW register. It is named PC (which stand for Program Counter).




=== Recompiler lookup table ===


The recLUT (recompiler lookup table) will allow to get the related BASEBLOCK related to the PC. The LUT maps the virtual address space as 64kB page. There is an easy macro to retrieve the current BASEBLOCK from a PC.


* '''<code>C++ macro: PC_GETBLOCK(PC)</code>'''
* '''<code>C++ array: __aligned16 uptr recLUT[_64kb]</code>'''


The hwLUT (hardware lookup table) will allow to get the physical PS2 address from a PS2 virtual address. Again a nice macro is available.
* '''<code>C++ macro: HWADDR(mem_address)</code>'''
* '''<code>C++ array: __aligned16 uptr hwLUT[_64kb]</code>'''
=== Base Block ===
The recompiler will map the EE memory into 3 differents BASEBLOCK array.
* '''<code>C++ array: BASEBLOCK *recRAM/code>'''
* '''<code>C++ array: BASEBLOCK *recROM/code>'''
* '''<code>C++ array: BASEBLOCK *recROM1/code>'''
The BASEBLOCK is barely a function pointer. It could be either
* a pointer to the X86 instruction buffer
* a pointer to a JITCompile dispatcher. The function will do
# Call recRecompile(cpuRegs.pc) to recompile the current block
# Jump to the recompiled block PC_GETBLOCK(cpuRegs.pc)->m_pFnptr()
* a pointer to a JITCompileInBlock dispatcher.




Line 42: Line 69:




[code]
static R5900LutReserve_RAM* recLutReserve_RAM = NULL;
[/code]
Main BASEBLOCK array buffer. Each BASEBLOCK contains a function pointer to a x86 generated code.
(around 36MB is allocated for recLutReserve_RAM , note there is a waste of ~4MB for the ROM)


The buffer is indirectly accessed through a Lookup table called recLUT
[code]
[code]
static __aligned16 uptr recLUT[_64kb];
static __aligned16 uptr recLUT[_64kb];
ninja
56

edits