MPU(Memory Protection Units) 《ARM System Developer's Guide》Chapter-13

一些嵌入式系统都具有多任务的能力,在这些系统上会涉及到多个任务对于系统资源的使用,对这些系统资源的保护,也就是本章的主题。

有两种方法控制对系统资源的访问。第一种是unprotected:这种系统依赖于软件层面对于资源的保护,没有专用的硬件监管内存和外设的使用。第二种是protected system:通过软件和硬件对系统资源进行保护,具有专用的硬件确认和限制对资源的访问。在这种系统中,任务行为需要符合运行环境定义的一系列规则也要接受硬件的制约,硬件层面给程序监控资源提供了特权。因此第二种方法比第一种方法具有更好的保护能力。

ARM提供了一系列具有硬件层面保护系统资源的处理器。分为2类,第一类是配备了MPU(memory protection units)的处理器, hardware protection over several software-designated regions.第二类是配备MMU的处理器,提供了硬件保护并且增加了虚拟内存的能力。

本章就是讲述MPU的处理器,下一章再讲解MMU。

本章内容如下
1. Protected Regions
2. Initializing the MPU, Caches , and Write buffer
3. Demonstration of an MPU System

在开始本章之前先大致讲解一下region是什么,才能进一步讲解MPU是如何在regions的基础上提供硬件保护能力的。

Region

A region is a set of attributes associated with an area of memory.The processor core holds these attributes in several CP15 registers and identifies each region by a number, which ranges between 0 and 7.

A region’s memory boundaries are configured using two attributes,

attributes
the starting address
its lengthwhich can be any power of two between 4 KB and 4 GB

the operation system assigns additional attributes to these regions

additional attributes
access rightsThe access to a region in memory is set as read-write, read-only, or no access and is subject to additional rights based on the current processor mode, which is either privileged or user.
the cache and write buffer policieswhich controls cache and write buffer attributes.

For example, one region can be set to access memory using a writethrough policy, while another operates as noncached and nonbuffered.

访问region过程:

When the processor accesses a region in main memory, the MPU compares the region’s access permission attributes with the current processor mode to determine what action it will take. If the request satisfies the region access criteria, the core is allowed to read or write to main memory. However, if the memory request results in a memory access violation, the MPU will generate an abort signal.
abort handler会决定abort类型是prefetch or data abort。

region生命周期

region可以被创建并且持续整个嵌入式系统的生命周期,又或者临时创建用来满足某一特殊的操作然后就移除。

如何安排和创建regions就是接下来一节的内容。

Protected Regions

当前的ARM产品中包含MPU的有如下几个:

the ARM740T, ARM940T, ARM946E-S, and the ARM1026EJ-S.
The ARM740T, ARM946E-S, and ARM1026EJ-S each contain 8 protection regions;
The ARM940T contains 16 protection regions

Regions是独立于冯诺依曼和哈弗架构的。每个region都有region number范围0~7.
第一类包含8个regions的芯片使用了统一的指令和数据regions。第二类芯片使用了独立的指令和数据regions,每个region number具有一对regions,所以有16个regions。

There are several rules that govern regions
1. Regions can overlap other regions.
2. Regions are assigned a priority number that is independent of the privilege assigned to the region.
3. When regions overlap, the attributes of the region with the highest priority number take precedence over the other regions. The priority only applies over the addresses within the areas that overlap.
4. A region’s starting address must be a multiple of its size.
5. A region’s size can be any power of two between 4 KB and 4 GB—in other words, any of the following values: 4 KB, 8 KB, 16 KB, 32 KB, 64 KB, … , 2 GB, 4 GB.
6. Accessing an area of main memory outside of a defined region results in an abort. The MPU generates a prefetch abort if the core was fetching an instruction or a data abort if the memory request was for data.

13.1.1-Overlapping Regions

overlapping regions
picture

13.1.2-Background Regions

example
figure 13.2
explanation

13.2 Initializing the MPU,Caches , and Write buffer

在控制系统开启protection unit之前必须最少定义一个data region和一个instruction region。The protection unit必须在caches and write buffer使能的同时或者之前使能(enable)。
控制系统使用CP15 register c1,c2,c3,c5 and c6来配置MPU。如下图所示:
 13.2

初始化 the MPU, caches, and write buffer 的步骤如下:
1. Define the size and location of the instruction and data regions using CP15:c6.
2. Set the access permission for each region using CP15:c5.
3. Set the cache and write buffer attributes for each region using CP15:c2 for cache and CP15:c3 for the write buffer.
4. Enable the caches and the MPU using CP15:c1.

13.2.1-Defining Region Size and Location

为了定义每个region的尺寸和位置,嵌入式系统需要写入到八个secondary registers之一,CP5:c6:c0:0 to CP5:c6:c7:0. Each secondary coprocessor register number maps to the corresponding region number identifier.

The bit fields and the format of the eight secondary registers CP15:c6:c0 to CP15:c6:c7 are shown in Figure 13.3 and Table 13.3.
13.3
为了设置region的大小,N的值可以参考Table 13.4
N的取值被硬件设计所限制,范围11~31,相应大小范围为4KB~4GB。Base address需要大于4KB并且是[5:1]bits 所表示size的整数倍。
table 13.4

在The ARM740T, ARM946E-S, and ARM1026EJ-S processors each have eight regions中.为了设置size和location需要写入到secondary register in CP5 : c6 : cX.
如下面的例子,就是设置region 3的大小和位置。

Example
 MOV r1, #0x300000      // set starting address
 MOV r1, r1, #0x11 << 1 // set size to 256KB
 MCR p15, 0, r1, c6, c3, 0

ARM940T data and intsurction各有8个regions,所以有着不同的设置方法,具体参考p468.

此外设置起始地址,region大小和enable位的具体代码,参照p469~470.

13.2.2-Access Permission

There are two sets of access permission schemes avaliable, a standard set and a extended set.
所有核心都支持标准级-包含了4层访问权限。较新的ARM946E-S和ARM1026EJ-S支持扩展集-其中增加了2层访问级(如table 13.5,0101,0110两种情况,其余的是不可预知的)
access permission table13.5
AP13.6
支持扩展集的处理器也支持软件运行在标准集上。其实际运行的 permission类型取决于最后一次向CP15 AP register的写入操作。如果最后一次是写入标准AP寄存器,则核心使用标准集;如果最后一次写入扩展AP寄存器,则核心使用扩展集。之所以有这样的效果,是因为向标准AP寄存器写入也会更新扩展AP寄存器,意味着扩展AP region entry的high bits[2:3]会被清除。

当使用标准AP的时候,每个region使用CP15:c5:c0:0 sets the AP for data, and CP15:c5:c0:1 sets the instruction region.

    MRC p15, 0, r1, c5, c0, 0;   Std AP Data Regions
    MRC p15, 0, r2, c5, c0, 1;   Std AP Inst Regions 

此外使用扩展AP代码如下:

    MRC p15, 0, r3, c5, c0, 2;   Extended AP Data Regions
    MRC p15, 0, r4, c5, c0, 3;   Extended AP Inst Regions 

(具体的很多内容请参照p472~474)

13.2.3-Setting Region Cache and Write buffer Attributes

三个 CP15 寄存器控制着cache and write buffer attributes。
如图:
figure 13.5
table 13.7
The cache bit determines if the cache is enabled for a given address within the region. In the ARM740T and ARM940T, the cache is always searched, regardless of the state of the cache bit. If the controller finds a valid cache entry, it will use the cached data over data in external memory.

Because of this cache behavior, the MPU control system must do operations when changing cache policy(see following table).

operationswhen changing cache policy
flush the cachefrom writethrough to noncached
clean and flush the cachefrom writeback to noncached
clean the cachefrom writeback to writethrough

The eight region write buffer bits in the register CP15:c3:c0:0 enable or disable the write
buffer for each region (again see Figure 13.5).

When configuring data regions, the region cache and write buffer bits together determine the policy of the region. The write buffer bit has two uses; it enables or disables the write buffer for a region and sets the region cache write policy.Table 13.8 gives a tabular view of thevarious states of the cache and write buffer bits and their meanings.
table 13.8

书上使用代码例子现实了如何设置cache and write buffer attributes。具体参照p476~477

13.2.4-Enabling Regions and the MPU

1
2

13.3 Demonstration of an MPU System

We have provided a set of routines to use as building blocks to initialize and control a protected system. This section uses the routines described to initialize and control a simple protected system using a fixed memory map.

Here is a demonstration that uses the examples presented in the previous sections of this chapter to create a functional protection system. It provides an infrastructure that enables the running of three tasks in a simple protected multi-tasking system. We believe it provides a suitable demonstration of the concepts underlying the ARM MPU hardware. It is written in C and uses standard access permission.
具体内容暂时不学习了,以后有功夫再继续学习,参照p478~487

13.3.1-System Requirements

13.3.2-Assigning Regions using a Memory map

13.3.3-Initializing the MPU

13.3.4-Initializing and configure the a region

13.3.5-Putting it all together , initializing the MPU

13.3.6-A protected Context Switch

13.3.7-MPUSLOS

Summary

There are two methods to handle memory protection. The first method is known as unprotected and uses voluntarily enforced software control routines to manage rules for task interaction. The second method is known as protected and uses hardware and software to enforce rules for task interaction. In a protected system the hardware protects areas of memory by generating an abort when access permission is violated and software responds to handle the abort routines and manage control to memory-based resources.

An ARM MPU uses regions as the primary construct for system protection. A region is a set of attributes associated with an area of memory. Regions can overlap, allowing the use of a background region to shield a dormant task’s memory areas from unwanted access by the current running task.

Several steps are required to initialize the MPU, included are routines to set various region attributes. The first step sets the size and location of the instruction and data regions using CP15:c6. The second step sets the access permission for each region using CP15:c5. The third step sets the cache and write buffer attributes for each region using CP15:c2 for

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: ARM Cortex-M3和Cortex-M4处理器权威指南是一本针对ARM架构的核心处理器的详细手册。该指南提供了有关这两款处理器的全面信息,使得读者能够充分了解它们的功能和特点。 首先,该指南介绍了Cortex-M3和Cortex-M4处理器的基本架构。它解释了处理器的不同功能模块,例如中央处理单元(CPU)、内存保护单元(MPU)和系统控制单元(SCU)。此外,该指南还描述了这些处理器所支持的指令集架构和编程模型。 其次,该指南深入探讨了Cortex-M3和Cortex-M4处理器的性能特点。它详细介绍了这两款处理器的时钟频率、Cache大小、浮点运算能力和并行处理能力等关键参数。此外,该指南还讨论了这些处理器在功耗管理、中断处理和异常处理等方面的出色表现。 此外,该指南还提供了丰富的编程指南和示例代码,帮助读者使用Cortex-M3和Cortex-M4处理器进行软件开发。它介绍了处理器的开发工具链、调试和仿真工具,以及软件开发的最佳实践。此外,该指南还解释了处理器的专有指令和寄存器,以及如何充分利用这些功能。 最后,该指南还介绍了Cortex-M3和Cortex-M4处理器的实际应用案例。它列举了一些使用这些处理器开发的典型应用,例如物联网设备、嵌入式系统和工控系统等。此外,该指南还提供了设计和优化这些应用的一些建议和技巧,帮助读者充分利用这些处理器的潜力。 综上所述,ARM Cortex-M3和Cortex-M4处理器权威指南是一本全面的技术手册,为读者提供了关于这些处理器的详尽信息。它涵盖了处理器的架构、性能特点、编程指南和实际应用等方面,是开发人员和研究人员的重要参考资料。 ### 回答2: 《ARM Cortex-M3和Cortex-M4处理器权威指南》是一本深入介绍ARM Cortex-M3和Cortex-M4处理器的权威指南。这本书详细介绍了这两款处理器的架构、特性和应用,对于工程师、开发者和学习者来说,都是一本非常重要和实用的参考书。 首先,该书详细解释了ARM Cortex-M3和Cortex-M4处理器的架构设计和功能,包括处理器的可靠性、性能优化和功耗管理等方面。读者可以深入了解这两款处理器的内部结构和工作原理,有助于在实际应用中充分发挥其优势。 另外,该书还介绍了使用Cortex-M3和Cortex-M4处理器进行嵌入式系统设计的一些最佳实践和技巧。这包括了基本的编程模型、中断处理、低功耗设计和调试方法等方面。读者可以学习到如何有效地开发和优化嵌入式系统,提高系统性能和稳定性。 此外,该书还提供了丰富的实际应用案例和示例代码,以帮助读者更好地理解和掌握Cortex-M3和Cortex-M4处理器的使用。这些案例涵盖了多个应用领域,如物联网、工业控制、医疗设备等,读者可以从中学习到如何将这两款处理器应用到实际项目中。 总之,《ARM Cortex-M3和Cortex-M4处理器权威指南》是一本涵盖了ARM Cortex-M3和Cortex-M4处理器的全面指南。无论是初学者还是有经验的开发者,都可以从中获得宝贵的知识和经验,提高在嵌入式系统设计和开发领域的能力。 ### 回答3: 《ARM Cortex-M3和Cortex-M4处理器权威指南》是一本讲述ARM Cortex-M3和Cortex-M4处理器的权威性指南。ARM Cortex-M系列处理器是一种低功耗、高性能处理器架构,被广泛应用于嵌入式系统。 该指南首先介绍了ARM Cortex-M系列处理器的基本架构和特点。它详细解释了这两个处理器的指令集、寄存器和内存管理单元的功能。读者可以了解不同寄存器的作用和寄存器级别的操作。 在介绍基本架构之后,指南详细描述了Cortex-M3和Cortex-M4处理器的核心特性和性能差异。读者将了解到Cortex-M4相较于Cortex-M3的新增功能,比如浮点运算单元(FPU)和DSP指令集扩展。这些功能使Cortex-M4更适合用于数字信号处理(DSP)和浮点运算密集型应用。 此外,指南还讨论了Cortex-M3和Cortex-M4的系统设计和软件开发。读者将了解到处理器的时钟和功耗管理、中断控制器的配置、外设接口和调试技术等方面的知识。同时,本指南还提供了开发工具和软件编程模型的指导,帮助读者更好地利用Cortex-M系列处理器进行嵌入式开发。 总之,《ARM Cortex-M3和Cortex-M4处理器权威指南》是一本全面指导读者了解和使用ARM Cortex-M3和Cortex-M4处理器的权威性参考书。无论是硬件工程师还是嵌入式开发人员,都可以从中获得宝贵的知识和指导,提升他们在嵌入式系统开发领域的技术水平。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猎羽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值