# Protection Units (Overview)

## Introduction

Protection units are used for setting the usage status of the memory read/write and the cache / write-back attributes, and for protecting the memory. Eight regions can be mapped in the memory space, and different attributes can be configured for each.

Protection units are a feature of the ARM9 processor. They do not exist on ARM7.

### Enabling and Disabling Protection Units

The protection units themselves can be enabled or disabled using the functions listed below.

`OS_EnableProtectionUnit()`
`OS_DisableProtectionUnit()`

### Settings for Each Region

The functions that perform each of the protection region settings are:
`OS_SetProtectionRegion()`
`OS_SetProtectionRegionParam()`

The functions that get the settings are:
`OS_GetProtectionRegionAddress()`
`OS_GetProtectionRegionSize()
OS_GetProtectionRegionParam()`

### Default Mapping

By default, each region is mapped as indicated below.
When the regions overlap, the larger region number has priority.

Region Number | Usage | Base Address | Size | Cache | Write Buffer | User Attribute (Command) | User Attribute (Data)
--- | --- | --- | --- | --- | --- | --- | ---
`-` | Background | `0x00000000` | 4GByte ( `0x100000000` ) | X | X | NA | NA
`0` (zero) | I/O register , VRAM, etc. | `HW_IOREG` ( `0x04000000` ) | 64MByte ( `0x400000` ) | X | X | R/W | R/W
`1` | Main Memory | `HW_MAIN_MEM_MAIN` ( `0x02000000` ) | 4M / 8MByte (CAUTION 1) ( `0x400000` / `0x800000` ) | O | O | R/W | R/W
`2` | ARM7-Exclusive | `HW_MAIN_MEM_SUB` ( `0x27C0000` / ...)(CAUTION 2) | 256KByte / ... (CAUTION 3) ( `0x40000` / ...) | X | X | NA | NA
`3` | GamePak | `HW_CTRDG_ROM` ( `0x08000000` ) | 128MByte ( `0x800000` ) | X | X | NA | R/W
`4` | DTCM | `HW_DTCM` ( `0x027C0000` / ... ) (CAUTION 4) | 16KByte ( `0x4000` ) | X | X | NA | R/W
`5` | ITCM | `HW_ITCM_IMAGE` ( `0x01000000` ) (CAUTION 5) | 16MByte ( `0x100000` ) | X | X | R/W | R/W
`6` | BIOS Reserved | `HW_BIOS` ( `0xFFFF0000` ) | 32KByte ( `0x8000` ) | O | X | R | R
`7` | Shared Main Memory | `HW_MAIN_MEM_SHARED` ( `0x027FF000` ) | 4KByte ( `0x1000` ) | X | X | NA | R/W

(CAUTION 1)
The size of protection region 1, used to protect the main memory, is either designated as `NITRO_4M` and compiled, or it is 4MByte on the actual device and everything else is 8MByte.

(CAUTION 2) (CAUTION 3)
The `HW_MAIN_MEM_SUB` starting address of protection region 2, used to protect the ARM7-exclusive region, is `0x2780000` on the TEG. It is `0x27C0000` on the TS. The size of protection region 2 is determined by the starting address. The value that takes the starting address from the upper address in the main memory expanded region becomes the size. For the TS, this is 256KByte, while it is 512KByte on the TEG.

(CAUTION 4)
The starting position of the DTCM is taken from the `lsf` file. By default, it is `0x27C0000` on the TS, and `0x2780000` on the TEG.

(CAUTION 5)
Since accessing a NULL pointer will cause an exception, do not start from `0x00000000`.

The following is a graphical representation of this mapping:

Furthermore, an enlarged representation of the main memory and expanded memory regions is shown below:

## See Also

An Overview of OS Functions (Protection Units)

## Revision History

11/17/2004 Initial version