📄 mpu.s
字号:
@ ____________________________________________________________________
@
@ Copyright (c) 2002, Andrew N. Sloss, Chris Wright and Dominic Symes
@ All rights reserved.
@ ____________________________________________________________________
@
@ NON-COMMERCIAL USE License
@
@ Redistribution and use in source and binary forms, with or without
@ modification, are permitted provided that the following conditions
@ are met:
@
@ 1. For NON-COMMERCIAL USE only.
@
@ 2. Redistributions of source code must retain the above copyright
@ notice, this list of conditions and the following disclaimer.
@
@ 3. Redistributions in binary form must reproduce the above
@ copyright notice, this list of conditions and the following
@ disclaimer in the documentation and/or other materials provided
@ with the distribution.
@
@ 4. All advertising materials mentioning features or use of this
@ software must display the following acknowledgement:
@
@ This product includes software developed by Andrew N. Sloss,
@ Chris Wright and Dominic Symes.
@
@ THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY
@ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE
@ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES@ LOSS OF USE, DATA,
@ OR PROFITS@ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
@ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
@ OF SUCH DAMAGE.
@
@ If you have questions about this license or would like a different
@ license please email :
@
@ andrew@sloss.net
@
@
@ ****************************************************************************
@ * Simple Little Operating System - mpuSLOS
@ ****************************************************************************
@ ****************************************************************************
@ *
@ * Module : mpu.s
@ * Description : provides a set of simple MPU routines
@ * Platform : CM940IAP
@ * History :
@ *
@ * 4 July 2002 (Independence Day) Andrew N. Sloss
@ * - taken from Chris Wright MPU example
@ *
@ ****************************************************************************
@ ****************************************************************************
@ * IMPORT/EXPORT
@ ****************************************************************************
.extern MpuPCB_Table
.global mpuInitFlush
.global mpuRegionDefine
.global mpuRegionStdAccess
.global mpuRegionExtAccess
.global mpuRegionCB
.global mpuRegionEnable
.global mpuChangeControl
.global mpuScheduleRegion2
@ ****************************************************************************
@ * ROUTINES
@ ****************************************************************************
mpuInitFlush:
MOV r0, #0x78
MCR p15, 0x0, r0, c1, c0, 0x0 @ ;
MOV r0, #0x0
MCR p15, 0x0, r0, c7, c5, 0x0 @ ; invalidate instruction cache
MCR p15, 0x0, r0, c7, c6, 0x0 @ ; invalidate data cache
MOV pc,lr
@ ;-----------------
@ ; Change Control Register Values
@ ; int changeControl(unsigned value, unsigned mask)
@ ;-----------------
mpuChangeControl:
MVN r2, r1 @ ; invert mask
BIC r3, r0, r2 @ ; clear values that are not masked
CMP r3, r0
BNE ErrorControl @ ; values outside of mask set
MRC p15, 0, r3, c1, c0, 0 @ ; get control register values
BIC r3, r3, r1 @ ; mask off bit that change
ORR r3, r3, r0 @ ; set value of bits that change
MCR p15, 0, r3, c1, c0, 0 @ ; set control register values
MOV r0, #0
MOV pc, lr
@ ;-----------------
@ ; Define Data Region Base and Size
@ ; int mpuRegionDefine(unsigned region, unsigned base, unsigned size)
@ ;-----------------
mpuRegionDefine:
mpuRegionDefineErrorCheck:
CMP r2, #11 @ ; check if size value too small (<11)
BLO ErrorSize @ ; ERROR: region size to small
CMPHI r2, #31 @ ; check if size value too large (>31)
BHI ErrorSize @ ; ERROR: region size too large
ADD r12, r2, #1 @ ; adjust multiple of size (off by one)
MOV r3, r1, lsr r12 @ ; clear trailing zeros part1
MOV r3, r3, lsl r12 @ ; clear trailing zeros part2
CMP r1, r3 @ ; check if Address is aligned on size
BHI ErrorAddress @ ; ERROR: address is not aligned
ORR r3, r3, r2, lsl #1 @ ; combine size and base address
MOV r12, r0 @ ; clear r0 for return value
MOV r0 , #0 @ ; set return value to zero
CMP r12, #8 @ check if region is in range
ADDLO pc, pc, r12, lsl #4 @ branch to base and size routine
@ lsl value (940T=#4 740/946=#3)
B ErrorRegion @ ERROR: Region to large, pad for jump
defineRegion0: @ defining region disables region
MCR p15, 0, r3, c6, c0, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c0, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion1: @ defining region disables region
MCR p15, 0, r3, c6, c1, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c1, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion2: @ defining region disables region
MCR p15, 0, r3, c6, c2, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c2, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion3: @ defining region disables region
MCR p15, 0, r3, c6, c3, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c3, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion4: @ defining region disables region
MCR p15, 0, r3, c6, c4, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c4, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion5: @ defining region disables region
MCR p15, 0, r3, c6, c5, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c5, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion6: @ defining region disables region
MCR p15, 0, r3, c6, c6, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c6, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
NOP @ pad for jump, remove in 740T/946ES
defineRegion7: @ defining region disables region
MCR p15, 0, r3, c6, c7, 0 @ set Dregion base and size
MCR p15, 0, r3, c6, c7, 1 @ set Iregion base and size, 940T only
MOV pc, lr @ region set return
@ ;-----------------
@ ; Define Access Permissions
@ ; int mpuRegionStdAccess(unsigned region, unsigned ap)
@ ;-----------------
mpuRegionStdAccess:
CMP r0, #0x7 @ check if region is in range
BHI ErrorRegion @ ERROR: Region out of Range
TST r1, #0xCC @ check extended permission use
BNE ErrorPermission @ ERROR: Use of Extended Permissions
MOV r0, r0, lsl #1 @ double region number ap is 2bits
MOV r2, #3 @ set mask 2 bits wide
setStdDAP:
MRC p15, 0, r3, c5, c0, 0 @ get D access permissions
BIC r3, r3, r2, lsl r0 @ clear D ap bits
AND r12, r1, #0x3 @ clear all except std D AP bits
ORR r3, r3, r12, lsl r0 @ set std D AP bits
MCR p15, 0, r3, c5, c0, 0 @ set std access permissions
setStdIAP:
MRC p15, 0, r3, c5, c0, 1 @ get I access permissions
BIC r3, r3, r2, lsl r0 @ clear I ap bits
MOV r1, r1, lsr #4 @ shift I AP bits in position
AND r12, r1, #0x3 @ clear all except std I AP bits
ORR r3, r3, r12, lsl r0 @ set std D AP bits
MCR p15, 0, r3, c5, c0, 1 @ set std access permissions
MOV r0, #0 @ success
MOV pc, lr @ region set return
@ ;-----------------
@ ; Define Access Permissions
@ ; int mpuRegionExtAccess(unsigned region, unsigned ap)
@ ;-----------------
mpuRegionExtAccess:
CMP r0, #0x7 @ check if region is in range
BHI ErrorRegion @ ERROR: Region out of Range
TST r1, #0x88 @ check unpredictable ext permission
BNE ErrorPermission @ ERROR: unpredicable use Ext Permissions
MOV r12, #4
TEQ r12, r1, lsr #4 @ check inst permission 0x100 unpredicable
MOV r12, #7
TEQNE r12, r1, lsr #4 @ check inst permission 0x111 unpredicable
BEQ ErrorPermission @ ERROR: unpredicable use Ext Permissions
AND r12, r1, #0xf
TEQ r12, #4 @ check data permission 0x100 unpredicable
TEQNE r12, #7 @ check data permission 0x111 unpredicable
BEQ ErrorPermission @ ERROR: unpredicable use Ext Permissions
@
MOV r0, r0, lsl #1 @ double region number ap is 2bits
MOV r2, #3 @ set mask 2 bits wide
setExtDAP:
MRC p15, 0, r3, c5, c0, 2 @ get D access permissions
BIC r3, r3, r2, lsl r0 @ clear D ap bits
AND r12, r1, #0xf @ clear all except ext D AP bits
ORR r3, r3, r12, lsl r0 @ set ext D AP bits
MCR p15, 0, r3, c5, c0, 2 @ set ext access permissions
setExtIAP:
MRC p15, 0, r3, c5, c0, 3 @ get I access permissions
BIC r3, r3, r2, lsl r0 @ clear I ap bits
MOV r1, r1, lsr #4 @ shift I AP bits in position
ORR r3, r3, r12, lsl r0 @ set ext D AP bits
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -