R01UH0823EJ0100 Rev.1.00
Page 336 of 1823
Jul 31, 2019
RX23W Group
17. Memory-Protection Unit (MPU)
17.4
Procedures for Using Memory Protection
17.4.1
Setting Access-Control Information
Access-control information for the various regions is set in supervisor mode.
Settings for up to eight access-control regions are made in the region-n start page number registers (RSPAGEn) and
region-n end page number registers (REPAGEn), where n = 0 to 7.
Settings for the background access-control region are made in the background access-control register (MPBAC).
17.4.2
Enabling Memory Protection
Setting the memory-protection enable (MPEN) bit in the memory-protection enable (MPEN) register to 1 while
operation is in supervisor mode enables memory protection.
17.4.3
Transition to User Mode
After updating the registers related to the memory-protection unit, read any of these registers and check that the settings
have been made before the transition to user mode.
Either of the methods below can be used for the transition from supervisor mode to user mode.
•
Set the processor mode setting (PM) bit in the copy of the processor status word (PSW) saved in the stack area to 1
(the setting for user mode) and then execute an RTE instruction.
•
Set the PM bit in the backup processor status word (BPSW) to 1 and then execute an RTFI instruction.
Note:
Using an MVTC or POPC instruction to write to the PSW.PM bit is invalid. Use an RTE or RTFI instruction to
update the value of the PSW.PM bit.
The memory-protection unit starts checking instruction-execution access and operand access by the CPU on the
transition to user mode.
17.4.4
Processing in Response to Memory-Protection Errors
The CPU starts access-exception processing on detection of a violation of protection set up by the access-control
information (i.e. a memory-protection error). For details on CPU operations in access-exception processing, refer to
section 14, Exception Handling
To determine whether an instruction memory-protection error or data memory-protection error has been generated, check
the values of the instruction memory-protection error generation (IMPER) and data memory-protection error generation
(DMPER) bits in the memory-protection error status register (MPESTS) from within the exception-processing routine.
After confirming the type of error, clear the memory-protection error status register (MPESTS) by writing 1 to the status
clearing (MPE) bit in the memory-protection error status clearing register (MPECLR).