PCSX2 Documentation/PCSX2 EE Recompiler: Difference between revisions
PCSX2 Documentation/PCSX2 EE Recompiler (view source)
Revision as of 17:47, 3 November 2015
, 3 November 2015→Memory Protection
Line 68: | Line 68: | ||
=== Memory Protection === | === Memory Protection === | ||
The instruction cache buffer is a cache of the EE program inside the EE memory. Therefore it is required to ensure some coherencies between the cache and the EE memory. It means that a write in the EE memory must be translated to a discard of the cache content, likely followed by a recompilation. | |||
The situation can occurred because of self-modifying code or due to a library linking (change memory pointer in RAM). | |||
A naive implementation would be to instrument all write to detect corresponding block. However it will cost a big penalty for each memory write. Another one will be to check the content of the instruction block at each execution. Again slow. A more complex implementation will use the page fault signal handler mechanism to detect invalid write. Guess what, we choose the later. | |||
==== The Automatic Protection ==== | |||
The EE memory is memory mapped as 4K Read/Write pages. A protection status is attached for each page. | |||
If the protection is manual, you need to handle it manually (easy isn't it). This case will be discussed below. Otherwise you will mark the page as Read-Only. | |||
==== The Write Interception ==== | |||
Now that EE memory page is Read-Only, any write on it will trigger an error. On Linux it will be a SIGSEGV (segmentation fault) signal. PCSX2 remaps the default handler to handle it. It will dispatch the signal to the correct buffer. Buffer will | |||
* Remount the page as Read/Write | |||
* Mark the memory protection as manual | |||
* Clear the recLUT cache | |||
==== The Manual Protection ==== | |||
After a write in a page, all the block will be recompiled with a manual protection status. The purpose is to add a small check at the start of the block that will check the content of it. In case of failure the block will be cleared with the help of the dyna_block_discard function. | |||
==== The Automatic Re-Protection ==== | |||
==== Limitation ==== | |||
== Code Generation == | == Code Generation == |