/*---------------------------------------------------------------------------* Project: TwlSDK - OS File: os_protectionRegion.c Copyright 2003-2008 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Date:: 2008-09-18#$ $Rev: 8573 $ $Author: okubata_ryoma $ *---------------------------------------------------------------------------*/ #include #include //================================================================================ // Instruction Cache for each protection region //================================================================================ /*---------------------------------------------------------------------------* Name: OS_EnableICacheForProtectionRegion OS_DisableICacheForProtectionRegion Description: enable/disable instruction cache for each protection region Arguments: flags : Each bit shows the region to be enable/disable. bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 Returns: None *---------------------------------------------------------------------------*/ asm void OS_EnableICacheForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c2, c0, 1 orr r1, r1, r0 mcr p15, 0, r1, c2, c0, 1 bx lr } //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - asm void OS_DisableICacheForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c2, c0, 1 bic r1, r1, r0 mcr p15, 0, r1, c2, c0, 1 bx lr } /*---------------------------------------------------------------------------* Name: OS_GetICacheEnableFlagsForProtectionRegion Description: get instruction cache status for each protection region Arguments: None Returns: instruction cache status. bit for each protection region, means 1... enable, 0... disable bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 *---------------------------------------------------------------------------*/ asm u32 OS_GetICacheEnableFlagsForProtectionRegion( void ) { mrc p15, 0, r0, c2, c0, 1 bx lr } /*---------------------------------------------------------------------------* Name: OS_SetIPermissionsForProtectionRegion Description: set instruction access limitation for each protection region Arguments: setMask : set mask bit, which is or-ed by mask. flags : flag bit, which is or-ed by access limitation. (mask) OS_PRn_ACCESS_MASK (n=0-7) (access limitation) OS_PRn_ACCESS_NA no permission to access OS_PRn_ACCESS_RW read and write permission OS_PRn_ACCESS_RO read only permission (n=0-7) ex. In case to set region3 readonly and region6 no permission, call OS_SetIPermissionsForProtectionRegion( OS_PR3_ACCESS_MASK | OS_PR6_ACCESS_MASK, OS_PR3_ACCESS_RO | OS_PR6_ACCESS_NA ); Returns: None *---------------------------------------------------------------------------*/ asm void OS_SetIPermissionsForProtectionRegion( register u32 setMask, register u32 flags ) { mrc p15, 0, r2, c5, c0, 3 bic r2, r2, r0 orr r2, r2, r1 mcr p15, 0, r2, c5, c0, 3 bx lr } /*---------------------------------------------------------------------------* Name: OS_GetIPermissionsForProtectionRegion Description: get instruction access limitation for each protection region Arguments: None Returns: Return value & OS_PRn_ACCESS_MASK (n=0-7) shows access limitation. (access limitation) OS_PRn_ACCESS_NA no permission to access OS_PRn_ACCESS_RW read and write permission OS_PRn_ACCESS_RO read only permission (n=0-7) *---------------------------------------------------------------------------*/ asm u32 OS_GetIPermissionsForProtectionRegion( void ) { mrc p15, 0, r0, c5, c0, 3 bx lr } //================================================================================ // Data Cache for each protection region //================================================================================ /*---------------------------------------------------------------------------* Name: OS_EnableDCacheForProtectionRegion OS_DisableDCacheForProtectionRegion Description: enable/disable data cache for each protection region Arguments: flags : Each bit shows the region to be enable/disable. bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 Returns: None *---------------------------------------------------------------------------*/ asm void OS_EnableDCacheForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c2, c0, 0 orr r1, r1, r0 mcr p15, 0, r1, c2, c0, 0 bx lr } //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - asm void OS_DisableDCacheForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c2, c0, 0 bic r1, r1, r0 mcr p15, 0, r1, c2, c0, 0 bx lr } /*---------------------------------------------------------------------------* Name: OS_GetDCacheEnableFlagsForProtectionRegion Description: get data cache status for each protection region Arguments: None Returns: data cache status. bit for each protection region, means 1... enable, 0... disable bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 *---------------------------------------------------------------------------*/ asm u32 OS_GetDCacheEnableFlagsForProtectionRegion( void ) { mrc p15, 0, r0, c2, c0, 0 bx lr } /*---------------------------------------------------------------------------* Name: OS_SetDPermissionsForProtectionRegion Description: set data access limitation for each protection region Arguments: setMask : set mask bit, which is or-ed by mask. flags : flag bit, which is or-ed by access limitation. (mask) OS_PRn_ACCESS_MASK (n=0-7) (access limitation) OS_PRn_ACCESS_NA no permission to access OS_PRn_ACCESS_RW read and write permission OS_PRn_ACCESS_RO read only permission (n=0-7) ex. In case to set region3 readonly and region6 no permission, call OS_SetDPermissionsForProtectionRegion( OS_PR3_ACCESS_MASK | OS_PR6_ACCESS_MASK, OS_PR3_ACCESS_RO | OS_PR6_ACCESS_NA ); Returns: None *---------------------------------------------------------------------------*/ asm void OS_SetDPermissionsForProtectionRegion( register u32 setMask, register u32 flags ) { mrc p15, 0, r2, c5, c0, 2 bic r2, r2, r0 orr r2, r2, r1 mcr p15, 0, r2, c5, c0, 2 bx lr } /*---------------------------------------------------------------------------* Name: OS_GetDPermissionsForProtectionRegion Description: get data access limitation for each protection region Arguments: None Returns: Return value & OS_PRn_ACCESS_MASK (n=0-7) shows access limitation. (access limitation) OS_PRn_ACCESS_NA no permission to access OS_PRn_ACCESS_RW read and write permission OS_PRn_ACCESS_RO read only permission (n=0-7) *---------------------------------------------------------------------------*/ asm u32 OS_GetDPermissionsForProtectionRegion( void ) { mrc p15, 0, r0, c5, c0, 2 bx lr } //================================================================================ // Write buffer for each protection region //================================================================================ /*---------------------------------------------------------------------------* Name: OS_EnableWriteBufferForProtectionRegion OS_DisableWriteBufferForProtectionRegion Description: enable/disable write buffer for each protection region Arguments: flags : Each bit shows the region to be enable/disable. bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 Returns: None *---------------------------------------------------------------------------*/ asm void OS_EnableWriteBufferForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c3, c0, 0 orr r1, r1, r0 mcr p15, 0, r1, c3, c0, 0 bx lr } //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - asm void OS_DisableWriteBufferForProtectionRegion( register u32 flags ) { mrc p15, 0, r1, c3, c0, 0 bic r1, r1, r0 mcr p15, 0, r1, c3, c0, 0 bx lr } /*---------------------------------------------------------------------------* Name: OS_GetWriteBufferEnableFlagsForProtectionRegion Description: get write buffer status for each protection region Arguments: None Returns: write buffer status. bit for each protection region, means 1... enable, 0... disable bit0(LSB) ... protection region 0 bit1 ... protection region 1 : : bit7 ... protection region 7 *---------------------------------------------------------------------------*/ asm u32 OS_GetWriteBufferEnableFlagsForProtectionRegion( register u32 flags ) { mrc p15, 0, r0, c3, c0, 0 bx lr } //================================================================================ // protection region //================================================================================ /*---------------------------------------------------------------------------* Name: OS_SetProtectionRegionParam Description: set up parameter of protection region Arguments: regionNo : region number param : parameter ( created from base address and size ) Returns: None *---------------------------------------------------------------------------*/ void OS_SetProtectionRegionParam( int regionNo, u32 param ) { static void (*f[])(u32) = { OS_SetProtectionRegion0, OS_SetProtectionRegion1, OS_SetProtectionRegion2, OS_SetProtectionRegion3, OS_SetProtectionRegion4, OS_SetProtectionRegion5, OS_SetProtectionRegion6, OS_SetProtectionRegion7 }; SDK_ASSERT( regionNo>=0 && regionNo=0 && regionNo> (n<<2)) & HW_C5_PERMIT_MASK ) { case HW_C5_PERMIT_NA: ipermit = "--"; break; case HW_C5_PERMIT_RW: ipermit = "RW"; break; case HW_C5_PERMIT_RO: ipermit = "R-"; break; default: ipermit = "??"; break; } switch( (d_permit >> (n<<2)) & HW_C5_PERMIT_MASK ) { case HW_C5_PERMIT_NA: dpermit = "--"; break; case HW_C5_PERMIT_RW: dpermit = "RW"; break; case HW_C5_PERMIT_RO: dpermit = "R-"; break; default: dpermit = "??"; break; } OS_Printf(" %d %c %c %s %s 0x%08x 0x%x\n", n, (i_cache & (1<