A memory map refers to the layout and organization of memory in a computing system. In ARM processors, the memory map defines different memory regions and what they are used for. Understanding the ARM memory map is important for programmers to properly utilize memory and avoid conflicts.
Overview of ARM Memory Map
The ARM memory map divides the processor’s physical address space into regions for different purposes. Some key things to know about the ARM memory map:
- Memory regions are defined by starting and ending addresses.
- Each region serves a specific function like code, data, peripherals, etc.
- Memory access is controlled through settings like access permissions.
- The memory map is standardized so software knows what to expect.
On ARMv7 architectures, the processor operates in a 32-bit address space, meaning up to 4GB of memory can be addressed. ARMv8 extends this to a 64-bit address space.
Overview of Main Memory Regions
Here are some of the major standard memory regions defined in the ARM memory map:
Code Region
The code region stores program code and read-only data. It is typically mapped to non-volatile memory like flash or ROM. Code memory needs execute permissions but not write.
RAM Region
The RAM region provides memory for storing runtime data like the stack, heap, global variables, etc. It is mapped to volatile RAM and requires read/write permissions.
Peripheral Region
This region provides access to the processor’s peripherals like timers, UARTs, GPIO, etc. Peripherals have control registers that can be read/written to manipulate the peripheral.
Reserved Regions
Parts of the memory map are reserved for specific hardware functions or future use. These regions should not be used by software.
System Region
The system region gives access to system control registers, interrupts, cache, MMU configuration, etc. This is for low-level functions.
ARMv7 Memory Map Regions
Here is a more detailed overview of the memory map on 32-bit ARMv7 architectures:
- 0x00000000 – 0x001FFFFF: Internal memory. Used for core functions.
- 0x00200000 – 0x003FFFFF: Bit-band alias. Provides bit-level access to SRAM.
- 0x00400000 – 0x00FFFFFF: Reserved. Do not use.
- 0x01000000 – 0x01FFFFFF: Code region. Stores program code and read-only data.
- 0x02000000 – 0x021FFFFF: RAM region. Used for read/write data.
- 0x02200000 – 0xDFFFFFFF: Reserved. Do not use.
- 0xE0000000 – 0xE00FFFFF: CCM RAM. Fast access RAM for some Cortex-M cores.
- 0xE0100000 – 0xFFFFFFFF: Device region. Maps to peripherals.
This covers the most commonly used parts of the memory map. There are additional implementation-specific regions as well.
ARMv8 Memory Map Changes
ARMv8 builds on ARMv7 and expands the address space to 64-bit. Some key differences in ARMv8:
- 48-bit virtual address space and 64-bit physical address space.
- New Extending regions for peripherals, RAM, and ROM added in upper half.
- Address space layout randomization security feature supported.
- More address space reserved for future use.
The overall layout remains similar to ARMv7 with code, data, peripherals, and system regions. But the expanded address space allows much larger physical memory.
Memory Endianness
Endianness refers to how data is stored in memory – either “big endian” or “little endian”. This impacts how multibyte values are interpreted at specific addresses.
ARM supports both big and little endian formats. The ARM memory map itself does not mandate endianness. But endianness can be set differently for different regions. So one region could be little endian and another big endian.
Memory Attributes
Each memory region in the ARM memory map has associated attributes that control access permissions and cache policies for that region. This allows greater control of memory usage.
Some memory attributes that can be configured:
- Read/Write permissions
- Execute permissions
- Memory access ordering
- Cacheable vs non-cacheable
- Allocation strategies like write-through, write-back, read-allocate
Attributes are commonly set during boot by the Memory Protection Unit (MPU). Cortex-M cores have a simplified MPU compared to Cortex-A application processors.
Memory Mapping in ARM Cores
The ARM memory map is an abstraction – the physical memory chips are mapped into the appropriate regions by the Memory Management Unit (MMU).
In Cortex-M microcontrollers, the MMU is simple or non-existent. Memory mapping is done via fixed address decoding logic. Memory chips can just be connected to the appropriate regions.
In Cortex-A application processors, the MMU does advanced virtual-to-physical address translation. Virtual addresses used by software are dynamically translated to physical addresses with configurable mappings.
Using the ARM Memory Map in Software
Here are some ways software utilizes the ARM memory map:
- Knowing code is executed from the code region, constants can be placed in read-only regions.
- Globally accessible data can be placed in the RAM region.
- Peripheral registers are accessed by reading/writing to the peripheral region addresses.
- Interrupts and exceptions can be handled using defined vectors in the system region.
- Access violations can be debugged by checking region permissions.
Software like operating systems will initialize memory protection and map virtual address spaces onto the physical map regions. Following the standards allows predictable memory access.
Typical ARM Memory Map Configurations
The ARM memory map provides a lot of flexibility. Here are some typical configurations:
Simple System
A simple microcontroller may have:
- Flash memory stores code in the code region.
- On-chip SRAM used for data RAM region.
- Peripherals directly accessed in their defined regions.
MMU System
A complex application processor may have:
- External DRAM is mapped to data RAM and code regions.
- Flash is a cacheable executable region.
- OS uses virtual addresses mapped by MMU.
- Advanced caching and access controls.
Custom System
For a custom hardware design:
- Memory map is modified for custom peripherals.
- Specialized memory attributes tailored to use case.
- Extended regions added for large external memories.
The memory map provides a guideline while allowing customization as needed.
Summary
In summary, the ARM memory map organizes memory into different regions with defined purposes. Understanding how it partitions and manages memory access is key for ARM programmers. The memory map enables efficient use of available memory resources on ARM processors.
Key takeaways include:
- Standard regions for code, data, peripherals.
- Configurable memory attributes for each region.
- MMU handles advanced address mapping.
- Follows a standard layout for software compatibility.
By properly utilizing the ARM memory map, developers can build robust systems that make the best use of available memory.