Lecture04 PDF - Embedded Systems Memory
Document Details
Uploaded by SmoothestSunstone
UMass Boston
Tags
Summary
These lecture notes provide a basic overview of memory architecture, types, and storage methods in embedded systems. The document explains Von Neumann and Harvard architectures and discusses concepts like Big Endian and Little Endian memory organization.
Full Transcript
Homework • Reading – PAL pp 119-125, 161-172 – http://www.barrgroup.com/EmbeddedSystems/How-To/Memory-Types-RAM-ROMFlash 1 Memory Architectures • Von Neumann Architecture – Code and data are accessed in one address space – The I/O ports may be in: • The same address space (Memory Mapped I/O) • A...
Homework • Reading – PAL pp 119-125, 161-172 – http://www.barrgroup.com/EmbeddedSystems/How-To/Memory-Types-RAM-ROMFlash 1 Memory Architectures • Von Neumann Architecture – Code and data are accessed in one address space – The I/O ports may be in: • The same address space (Memory Mapped I/O) • A separate I/O address space (Intel) • Harvard Architecture – Code is accessed in one address space – Data and I/O ports are in another address space 2 Memory Architectures • Comparison of Vendor Implementations Program Code Intel 386 Atmega Data I/O Ports Address space Address space Motorola 68xxx Von Neumann Architecture Address space Address space Harvard Architecture 3 Intel Memory Architecture • We’ll discuss various aspects of memory use: – – – – – – Storage of bytes Storage of words and long words Storage of strings The stack and the stack pointer RAM and ROM Addressing - real mode and protected mode 4 Storage of Bytes • Memory is byte addressable (8 bits/byte) • A memory address “points” to the location of a specific byte in memory • As we know from C data types, a “pointer” can be “cast” to point to a type or structure in memory that is larger than one byte • In that case, the memory address “points” to the lowest address of the storage area used 5 Storage of Words and Long Words • Word Sizes – A Word usually means 16 bits or 2 bytes – A Long Word usually means 32 bits or 4 bytes • Many processors (Motorola 68000/PPC and Sun) store words and long words in memory in “Big Endian” fashion • Intel and Atmega Processors store words and long words in memory in “Little Endian” fashion 6 “Big Endian” • Mapping a long word from register to memory: %eax 0x12 0x34 0x56 0x78 *** 0x12 0x34 0x56 0x78 0x1000e0 0x1000e1 0x1000e2 Memory Address *** 0x1000e3 7 “Big Endian” Appearance • Hex value as seen in register: %eax: 12 34 56 78 • Hex value(s) as seen in memory bytes (md): 0x1000e0: 12 34 56 78 • Irrelevant to the end user – self consistent! • Has a logical appearance to a programmer using a debugger! 8 “Little Endian” • Mapping a long word from register to memory: %eax 0x12 0x34 0x56 0x78 *** 0x78 0x56 0x34 0x12 0x1000e0 0x1000e1 0x1000e2 Memory Address *** 0x1000e3 9 “Little Endian” Appearance • Hex value as seen in register: %eax: 12 34 56 78 • Hex value(s) as seen in memory bytes (md): 0x1000e0: 78 56 34 12 • Irrelevant to the end user – self consistent! • A bit confusing to programmers using a debugger! 10 Debugging with “Little Endian” • Mostly learn to live with it! • To help with displays, the “real” Tutor monitor has an "mdd" command (memory-display-doubleword) • This command reorders the bytes and displays four bytes at a time as a double word value: Tutor> mdd 1000e0 1000e0 12345678 ... 11 Storage of Strings • How are strings stored? – Look at string “help” stored at location 0x200000 – Since memory is “byte addressable” each character (i.e., each byte) has its own address – The address of the entire string is the address of the first byte of the string (the lowest address) – The null terminator shows the end ‘h’ 0x200000 ‘e’ 0x200001 ‘l’ ‘p’ ‘\0’ 0x200002 0x200003 0x200004 Memory Address *** 12 The Stack • One register is called the “extended stack pointer (%esp)” and is used to implement a stack • There are various times when data is pushed on the stack and/or popped off the stack that we will study later – Function calls and returns – Interrupts and returns – System calls and returns 13 The Stack • For now, we will just understand how the esp register is used to push and pop data on and off the stack • Why is a specific register used? Can’t the software use any register for a stack pointer? • Not for system stack! Both hardware and software push and pop data on and off the system stack • Hardware is designed to use a specific register (%esp) so software must be consistent and use same register 14 The Stack - Initialization • Software initializes system stack pointer to point just after the end of available area in memory (i.e., not used for another purpose than stack) • Contents of the stack area are not initialized movl $0x01000000, %esp high memory address 0x01000000 ?? 0x00FFFFFF ?? 0x00FFFFFE ?? 0x00FFFFFD ?? 0x00FFFFFC ?? 0x00FFFFFB ?? 0x00FFFFFA ?? 0x00FFFFF9 ?? 0x00FFFFF8 ?? %esp low memory address 15 The Stack – Push Operation • When data is pushed onto the stack 1. The %esp register is first decremented 2. The value being pushed is stored to memory at the address value (“pointer”) stored in the %esp register movl $0x12345678, %eax pushl %eax high memory address 0x01000000 ?? 0x00FFFFFF 0x12 0x00FFFFFE 0x34 0x00FFFFFD 0x56 0x00FFFFFC 0x78 0x00FFFFFB ?? 0x00FFFFFA ?? 0x00FFFFF9 ?? 0x00FFFFF8 ?? %esp before %esp after low memory address 16 The Stack – Pop Operation popl %eax (%eax contains 0x12345678 again) • When data is popped off the stack 1. The value of the data is read from memory at the address value (“pointer”) stored in the %esp register 2. The %esp register is incremented high memory address 0x01000000 ?? 0x00FFFFFF 0x12 0x00FFFFFE 0x34 0x00FFFFFD 0x56 0x00FFFFFC 0x78 0x00FFFFFB ?? 0x00FFFFFA ?? 0x00FFFFF9 ?? 0x00FFFFF8 ?? %esp after %esp before low memory address 17 The Stack – Manually using esp • You can manually place data on the stack by utilizing the esp register as a memory pointer • (%esp) is indirect addressing. It means the memory location points to by the esp register subl $0x04, %esp movl $0x89abcdef, (%esp) high memory address 0x01000000 ?? 0x00FFFFFF 0x89 0x00FFFFFE 0xab 0x00FFFFFD 0xcd 0x00FFFFFC 0xef 0x00FFFFFB ?? 0x00FFFFFA ?? 0x00FFFFF9 ?? 0x00FFFFF8 ?? %esp before %esp after low memory address18 Memory Types • A good reference article: http://www.barrgroup.com/Embedded-Systems/HowTo/Memory-Types-RAM-ROM-Flash • Random Access Memory (RAM) – Contents are “volatile” (lost when power is off) – Can be loaded with code from a non-volatile media/source such as a disk or a network server – Can be used for reading and writing data via normal reads and writes to the memory address – Can be overwritten unintentionally, e.g. using a “bad” pointer when storing data in memory 19 – Faster access Memory Types (cont’d) • 2 types of RAM (depending on the lifetime of data stored): – Dynamic RAM (DRAM) • If power is turn off, its contents will be lost forever. • Even if power is applied, memory is only retained for 4 milliseconds, and it is gone. • Need to be refreshed periodically to keep memory. – Static RAM (SRAM) • If power is turn off, its contents will be lost forever. • Memory is retained as long as the power is on. 20 Memory Types (cont’d) • Read Only Memory (ROM) – – – – Contents are “non-volatile” (saved with power off) Contains code needed to “boot” the processor Can be used for reading (but not writing) data Erasable and Programmable ROM(EPROM): • Low Volume/High Cost (for Development and Testing) • Use ultraviolet light to erase memory – Programmable ROM (PROM): • High Volume/Low Cost (for Production) 21 Software in Embedded System Memory (Low volume / High Cost) Inventory of Blank Memory Chips Dev’t Host File Prototype Board(s) Prom Programmer Manual Process To “Burn” PROMs 22 Software in Embedded System Memory (High Volume / Low Cost) Order Production Quantities Dev’t Host File Memory Chip Vendor Transfer file to Memory Chip Vendor Inventory of Programmed Chips *** Production Boards 23 Hybrid Between RAM and ROM • Electrically Erasable and Programmable ROM(EEPROM) – Erase byte by byte electrically – Once written, the data is stored forever – Higher cost and write cycle is much longer • Flash memory – High density, low cost, non-volatile and fast to read – Electrically erasable a sector (256 to 16 Kbyte) at a time 24 BIOS Memory • For some computer systems (e.g. PC’s) and embedded devices, the BIOS is stored in nonvolatile memory e.g. flash memory. • More details at: http://www.howtogeek.com/180798/where-is-the-bios-stored/ • These parts can be reloaded using a special procedure, e.g. BIOS update for a PC • Risk: If anything goes wrong, the device may become unusable and the part need replacing 25 Difference between Memory Address and Memory Content Memory chip Address (ptr) e.g., 0xffff 0000 Content (*ptr) e.g., 0xff char *ptr; int *ptr1; *ptr= 0xff; *ptr1= 0x???? ??ff Content (*ptr1) e.g., 0x???? ??ff 26 Initialize a string in C char a[]=“I am great”; char *ptr=“You are great too”; How many bytes are allocated to a? How many bytes are allocated to ptr? 27