Embedded Systems Notes
Embedded Systems Notes
&
MEMORY MANAGEMENT
UNIT
Paging
• Provide Protection
• One process can’t interfere with another.
• because they operate in different address spaces.
• User process cannot access privileged information
• different sections of address spaces have different permissions.
MEMORY MANAGEMENT UNIT
• Used in many modern microcontroller targeted for embedded applications
• Memory Management Unit provides the key service of managing tasks as independent programs
running in their own private space
• MMU simplifies programming of application tasks by providing resources for managing virtual memory
• MMU acts as a translator which converts addresses of programs and data to actual physical addresses to map that
on to actual DRAM.
• It also Enables relocation of programs with virtual address to any part of main memory
• Memory management unit (MMU) translates addresses.
logical physical
address memory address main
CPU management
memory
unit
SEGMENTATION BASED MEMORY MANAGEMENT
• Segmentation provided by simple MMU
• Program views its memory as set of segments. Code segment, Data Segment, Stack segment, etc.
• Each program has its own set of private segments.
• Each access to memory is via a segment selector and offset within the segment.
• It allows a program to have its own private view of memory and to coexist transparently with other programs
in the same memory space.
base bound
Segment Descriptor Table (SDT)
Base: The base address of the segment
Logical address: an offset within a segment
Bound: Segment limit
SDT: Holds Access and other information about + >?
the segment
physical address access fault
PAGING
• Logical Memory area can be bigger than the physical memory
• Logical memory can be accommodated in the secondary memory
• Divide physical memory into equal sized chunks called pages
• Any chunk of Virtual Memory assigned to any chuck of Physical Memory (“page”)
Memory
0:
Page Table 1:
Virtual Physical
Addresses 0: Addresses
1:
CPU
P-1:
N-1:
Disk
Disk
SERVICING A PAGE FAULT
• Processor Signals the I/O controller
• Which provide read block of length P starting at disk address X (1) Initiate Block Read
and store starting at memory address Y
Processor
• Read Occurs
Reg
• Direct Memory Access (DMA) (3) Read
• Under control of I/O controller Done
• I / O Controller Signals Completion
Cache
• Interrupt the processor
• OS resumes suspended process
Memory-I/O bus
I/O
Memory controller
(2) DMA
disk
Disk disk
Disk
Transfer
MANAGING MULTIPLE PROCESSES
• Each process has its own virtual address space
• operating system controls how virtual pages are assigned to physical memory
• A page table for each process
• every program can start at the same address (virtual address)!
• A process should not access pages not allocated to it.
Page Tables Memory
Read? Write? Physical Addr 0:
Protection: VP 0: Yes No PP 9 1:
Page table entry contains access rights Process i: VP 1: Yes Yes PP 4
information VP 2: No No XXXXXXX
• • •
• • •
• • •
Hardware enforces this protection
(trap into OS if violation occurs) Read? Write? Physical Addr
VP 0: Yes Yes PP 6
Process j: VP 1: Yes No PP 9 N-1:
VP 2: No No XXXXXXX
• • •
• • •
• • •
PAGE ADDRESS TRANSLATION
concatenate
page offset
if valid=0
then page
not in memory m–1 p p–1 0
physical page number (PPN) page offset
physical address
PAGE TABLE OPERATIONS
• Translation
• Separate (set of) page table(s) per process
• Virtual page number (VPN) forms index into page table (points to a page table entry)
• Computing Physical Address
Page Table Entry (PTE) provides information about page
• if (valid bit = 1) then the page is in memory.
• Use physical page number (PPN) to construct address
• if (valid bit = 0) then the page is on disk
• Page fault (Exception is raised)
• Must load page from disk into main memory before continuing
• Checking Protection
• Access rights field indicate allowable access
• e.g., read-only, read-write, execute-only
• typically support multiple protection modes (e.g., kernel vs. user)
• Protection violation fault occurs if process doesn’t have necessary permission to access a location which is
not allowed.
INTEGRATING VM AND CACHE
• Most Caches “Physically Addressed”
• Accessed by physical addresses VA PA miss
• Allows multiple processes to have blocks in cache at same time Trans- Main
CPU Cache
• Allows multiple processes to share pages lation Memory
• Cache doesn’t need to be concerned with protection issues hit
• Access rights checked as part of address translation data
TLB hit
physical address
hit
Demand Paging
• Use flash memory as non-volatile store
• Disks or file system implemented in flash memory in appliances like PDA’s etc.
• copy programs to RAM during system operation for faster access
• Under these conditions Dynamic Paging with loading pages on demand
• Adopt Write-back policy for the pages because access time to flash MCU MMU
is much more compared to RAM