Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk

pptx
Số trang Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk 49 Cỡ tệp Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk 1 MB Lượt tải Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk 0 Lượt đọc Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk 0
Đánh giá Lecture Computer organization and assembly language: Chapter 5 - Dr. Safdar Hussain Bouk
4.1 ( 4 lượt)
Nhấn vào bên dưới để tải tài liệu
Để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

CSC 221 Computer Organization and Assembly Language Lecture 05: Memory Access Lecture 4: Review • The programming model of the 8086 through 80286 contain 8- and 16-bit registers. • The programming model of the 80386 and above contains 8-, 16-, and 32-bit extended registers as well as two additional 16-bit segment registers: FS and GS. Lecture 4: Review (cont.) • The 64-bit registers in a Pentium 4 with 64-bit extensions are RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI, and R8 through R15. • In addition, the microprocessor contains an instruction pointer (IP/EIP/RIP) and flag register (FLAGS, EFLAGS, or RFLAGS). Lecture Outline • Memory Access: – Real Mode memory-addressing techniques. – Protected Mode memory-addressing techniques. • Memory Access: – 64-bit Flat Memory model. • Program-invisible registers in the 80286~Core2 microprocessors. REAL MODE MEMORY ADDRESSING • The only mode available on the 8086-8088. 20 bit address bus  1 MB, 16 bit data bus, 16 bit registers • 80286 and above operate in either the real or protected mode. • Real mode operation allows addressing of only the first 1M byte of memory space—even in Pentium 4 or Core2 microprocessor. – the first 1M byte of memory is called the real memory, conventional memory, or DOS memory system Segments and Offsets • All real mode memory addresses must consist of a segment address plus an offset address. – segment address defines the beginning address of any 64K-byte memory segment – offset address selects any location within the 64K byte memory segment • Figure in Next Slide: shows how the segment plus offset addressing scheme selects a memory location. Segments and Offsets – this shows a memory segment beginning at 10000H, ending at location IFFFFH • 64K bytes in length – also shows how an offset address, called a displacement, of F000H selects location 1F000H in the memory Figure: The real mode memory-addressing scheme, using a segment address plus an offset. Segments and Offsets Then the Effective memory Address (EA) = 20-bit segment start address + 16-bit offset address 16-bit each 0 Appended 4 bits (0H) Segment Start Address in Segment Register Figure: The real mode memory-addressing scheme, using a segment address plus an offset. Effective Address Calculations • EA = segment register (SR) x 10H + offset (a) SR: 1000H 10000 + 0023 = 10023 (b) SR: AAF0H AAF00 + 0134 = AB034 (c) SR: 1200H 12000 + FFF0 = 21FF0 Segments and Offsets • Once the beginning/starting address is known, the ending address is found by adding FFFFH. – because a real mode segment of memory is 64K in length • The offset address is always added to the segment starting address to locate the data. • Segment and offset address is sometimes written as 1000:2000. – a segment address of 1000H; an offset of 2000H Default Segment and Offset Registers • The microprocessor has rules that apply to segments whenever memory is addressed. – these define the segment and offset register combination • The code segment register defines the start of the code segment. • The instruction pointer locates the next instruction within the code segment. Default Segment and Offset Registers • Another of the default combinations is the stack. – stack data are referenced through the stack segment at the memory location addressed by either the stack pointer (SP/ESP) or the base pointer (BP/EBP) • Figure in Next Slide: shows a system that contains four memory segments. – a memory segment can touch or overlap if 64K bytes of memory are not required for a segment Default Segment and Offset Registers Memory FFFFF 59000 58FFF Extra 49000 48FFF 4900 ES 44000 43FFF 34000 33FFF Stack 3400 SS 30000 2FFFF – a program can have more than four or six segments, • but only access four or six segments at a time Code 20000 1FFFF – think of segments as Windows that can be moved over any area of memory to access data or code 2000 CS 1000 DS Data 10000 0FFFF 00000 Figure: A memory system showing the placement of four memory segments. Default Segment and Offset Registers Code should be limited to only this portion of the code segment, to avoid effects of segment overlap. Figure: An application program containing a code, data, and stack segment loaded into a DOS system memory. Default Segment and Offset Registers Convention Example: EA = CS:[IP] • • Default segment numbers in: – CS for program (code) Segment Start – SS for stack in Segment register – DS for data – ES for string (destination) data Default offset addresses that go with them: Segment Offset (16-bit) 8080, 8086, 80286 Offset: Literal or in a CPU register Offset (32-bit) 80386 and above Purpose CS SS DS IP EIP Program SP, BP ESP, EBP Stack BX, DI, SI, 8-bit or 16-bit # EBX, EDI, ESI, EAX ECX, EDX, 8-bit or 32-bit # Data ES DI, with string instructions EDI, with string instructions String destination TPA • The Transient Program Area (TPA) holds the DOS (disk operating system) operating system; other programs that control the computer system. • TPA is the first available area of memory above drivers and other TPA programs • Area is indicated by a free-pointer maintained by DOS • program loading is handled automatically by the program loader within DOS Real Mode Addressing Scheme Allows Relocation • Segment plus offset addressing allows DOS programs to be relocated in memory. • A relocatable program is one that can be placed into any area of memory and executed without change. • Relocatable data are data that can be placed in any area of memory and used without any change to the program. Real Mode Addressing Scheme Allows Relocation • Because memory is addressed within a segment by an offset address, the memory segment can be moved to any place in the memory system without changing any of the offset addresses. • Only the contents of the segment register must be changed to address the program in the new area of memory. • Windows programs are written assuming that the first 2G of memory are available for code and data. Real Mode : Pros and Cons Advantages: • Allows easy and efficient relocation of code and data • To relocate code or data, only the number in the relevant segment register needs to be changed Consequences: A program can be located anywhere in memory without making any changes to it (addresses are not absolute, but offsets relative to start of segments) Program writer needs not worry about actual memory structure (map) of the computer used to execute it Disadvantages: • Complex hardware and for address generation • Address computation delay for every memory access • Software limitation: Program size limited by segment size (64KB with the 8086) Limitations of the Real Mode Segmentation Scheme • Segment size is fixed at and limited to 64 KB • Segment can not begin at an arbitrary memory address… With 20-bit memory addressing, can only begin at addresses starting with 0H, i.e. at 16 byte intervals  Principle is difficult to apply with 80286 and above, with segment registers remaining at 16-bits! Append: 00H 0000H 80286 and above use 24, 32 bit addresses but still 16-bit segment registers • No protection mechanisms: Programs can overwrite operating system code segments and corrupt them!  Use memory segmentation in the protected mode PROTECTED MODE MEMORY ADDRESSING • Operating systems operate in a 16- or 32-bit environment. • DOS uses a 16-bit environment. • Most Windows applications use a 32-bit environment called WIN32. • MSDOS/PCDOS & Windows 3.1 operating systems require 16-bit instruction mode. • Instruction mode is accessible only in a protected mode system such as Windows Vista. PROTECTED MODE MEMORY ADDRESSING: 80286 and above • Allows access to data and programs located within and above the first 1M byte of memory. • Protected mode is where Windows operates. • In place of a segment address, the segment register contains a selector that selects a descriptor from a descriptor table. • The descriptor describes the memory segment’s location, length, and access rights. • Descriptors are placed in descriptor tables in main memory • Protection is provided by restricting access to memory segments through: - Privilege levels, - and Access rights Selectors and Descriptors • The descriptor is located in the segment register and describes the location, length, and access rights of the segment of memory. – it selects one of 8192 descriptors from one of two tables of descriptors • In protected mode, this segment number can address any memory location in the system for the code segment. • Indirectly, the register still selects a memory segment, but not directly as in real mode. Selectors and Descriptors • Global descriptors contain segment definitions that apply to all programs. • Local descriptors are usually unique to an application. – a global descriptor might be called a system descriptor, and local descriptor an application descriptor • Figure 2–6 shows the format of a descriptor for the 80286 through the Core2. – each descriptor is 8 bytes in length – global and local descriptor tables are a maximum of 64K bytes in length Figure: The 80286 through Core2 64-bit descriptors. Base: 3-byte Limit: 2-byte (16 bit)  Seg. Size: 1B-64 KB Note provision for upward compatibility (286 software run on higher processors) Instruction Mode: 16/32 bits Base: 4-byte  32 bit addressing Limit: 2-1/2-byte (20 bit)  Size: 1B-1MB With G (4 K multiplier) bit = 1: 4KB-4GB Segment Availability Descriptors • The base address of the descriptor indicates the starting location of the memory segment. – the paragraph boundary limitation is removed in protected mode – segments may begin at any address • The G, or granularity bit allows a segment length of 4K to 4G bytes in steps of 4K bytes. – 32-bit offset address allows segment lengths of 4G bytes – 16-bit offset address allows segment lengths of 64K bytes. Descriptors • The G, or granularity bit allows a segment length of 4K to 4G bytes in steps of 4K bytes. • If G=0: no change • If G=1, append limit with FFFH, i.e. segment size is multiplied by 4K • With limit specifying 1 MB segments and G=1 (i.e. 4K multiplier): Max Segment size = 4K x 1 MB = 4 GB • With 16K segments like this, the system can address 16K x 4 GB = 64 TB (not necessarily all will be in physical memory) 80386 and above Example • Descriptor has: base = 23000000H limit = 012FFH With G = 0 Segment start = 23000000H Segment end = 23000000H + 012FFH=230012FFH Segment size = 12FFH+1H = 1300H (= 19 x 256 bytes) With G = 1 ( so actual limit = 012FFFFFH) (append limit in descriptor by FFFH) Segment start = 23000000H Segment end = 23000000H + 012FFFFFH = 242FFFFFH Segment size = 12FFFFF+1H = 1300000H = 212 x 1300H = 4K x 1300H Access Rights Byte • The access rights byte controls access to the protected mode segment. – describes segment function in the system and allows complete control over the segment – if the segment is a data segment, the direction of growth is specified • If the segment grows beyond its limit, the operating system is interrupted, indicating a general protection fault. • You can specify whether a data segment can be written or is write-protected. Figure: The access rights byte for the 80286 through Core2 descriptor. DPL will be compared with the request privilege level (RPL) in the segment register specifying this segment. Allow access to the segment only if RPL has higher or equal privilege to the DPL, subject to the state of C bit if applicable Descriptor Table • Descriptors are chosen from the descriptor table by the segment register. – register contains a 13-bit selector field, a table selector bit, and requested privilege level field • The TI bit selects either the global or the local descriptor table. • Requested Privilege Level (RPL) requests the access privilege level of a memory segment. – If privilege levels are violated, system normally indicates an application or privilege level violation Descriptors specify memory segments Segment number (still in a 16-bit segment register) defines the segment through a selector/descriptor (not directly as in real mode  but more flexibility) 16 bits segment register = 13 bit descriptor selector + 1 bit descriptor table selector + 2-bit requested privilege Segment Register, e.g. DS Figure: The contents of a segment register during protected mode operation of the 80286 through Core2 microprocessors. Privilege Levels 00: Highest Privilege 01 10 11: Lowest Privilege Highest RPL (In Seg Reg) DPL (in descriptor) Lowest Hardware Privilege Comparator RPL  DPL Allow Access to segment Discussion • Figure in “Next Slide” in shows how the segment register, containing a selector, chooses a descriptor from the global descriptor table. • The entry in the global descriptor table selects a segment in the memory system. • Descriptor zero is called the null descriptor, must contain all zeros, and may not be used for accessing memory. Processor: 80286 Protected Mode: Segmentation Example (in main memory) Because each descriptor in the table is 8 bytes wide, Selector:000b is used as an offset from GDT (or LDT) base address to point to the start of the required segment descriptor Always 0’s for upward compatibility 8-byte Segment Descriptor # 1 Access Rights byte MSB 16-bit Segment Register H 24-bit Address 000b Base Limit Descriptor # 0 GDT Base Address (= segment #) Offset Segment size = Limit+1 = FF+1 = 100H bytes Program-Invisible Registers • Global and local descriptor tables are found in the memory system. • To access and specify the table addresses, 80286– Core2 contain program-invisible registers. – not directly addressed by software • Each segment register contains a program-invisible portion used in the protected mode. – often called cache memory because cache is any memory that stores information Figure: The program-invisible register within the 80286–Core2 microprocessors. Discussion • When a new segment number is placed in a segment register, the microprocessor accesses a descriptor table and loads the descriptor into the program-invisible portion of the segment register. –held there and used to access the memory segment until the segment number is changed • This allows the microprocessor to repeatedly access a memory segment without referring to the descriptor table. –hence the term cache Global Descriptor Table Register • The GDTR (global descriptor table register) and IDTR (interrupt descriptor table register) contain the base address of the descriptor table and its limit. – when protected mode operation desired, address of the global descriptor table and its limit are loaded into the GDTR • The location of the local descriptor table is selected from the global descriptor table. – one of the global descriptors is set up to address the local descriptor table Local Descriptor Table Register • To access the local descriptor table, the LDTR (local descriptor table register) is loaded with a selector. – selector accesses global descriptor table, & loads local descriptor table address, limit, & access rights into the cache portion of the LDTR • The TR (task register) holds a selector, which accesses a descriptor that defines a task. – a task is most often a procedure or application • Allows multitasking systems to switch tasks to another in a simple and orderly fashion. Flat Mode Memory • A flat mode memory system is one in which there is no segmentation. – does not use a segment register to address a location in the memory • First byte address is at 00 0000 0000H; the last location is at FF FFFF FFFFH. – address is 40-bits • The segment register still selects the privilege level of the software. Flat Mode Memory • Real mode system is not available if the processor operates in the 64-bit mode. • Protection and paging are allowed in the 64-bit mode. • The CS register is still used in the protected mode operation in the 64-bit mode. • Most programs today are operated in the IA32 compatible mode. – current software operates properly, but this will change in a few years as memory becomes larger and most people have 64-bit computers Figure The 64-bit flat mode memory model. SUMMARY • All real mode memory addresses are a combination of a segment address plus an offset address. • The starting location of a segment is defined by the 16-bit number in the segment register that is appended with a hexadecimal zero at its rightmost end. • The offset address is a 16-bit number added to the 20-bit segment address to form the real mode memory address. • All instructions (code) are accessed by the combination of CS (segment ad-dress) plus IP or EIP (offset address). SUMMARY (cont.) • Data are normally referenced through a combination of the DS (data segment) and either an offset address or the contents of a register that contains the offset address. • The 8086-Core2 use BX, DI, and SI as default offset registers for data if 16-bit registers are selected. • The 80386 and above can use the 32-bit registers EAX, EBX, ECX, EDX, EDI, and ESI as default offset registers for data. SUMMARY (cont.) • The 80286 microprocessor allows a memory segment to start at any of its 16M bytes of memory using a 24-bit base address. • The 80386 and above allow a memory segment to begin at any of its 4G bytes of memory using a 32-bit base address. • This allows an 80286 memory segment limit of 64K bytes, and an 80386 and above memory segment limit of either 1M bytes. SUMMARY (cont.) • The segment register contains three fields of information in the protected mode. • The leftmost 13 bits of the segment register address one of 8192 descriptors from a descriptor table. • The program-invisible registers are used by the 80286 and above to access the descriptor tables. SUMMARY (cont.) • Each segment register contains a cache portion that is used in protected mode to hold the base address, limit, and access rights acquired from a descriptor. • The cache allows the microprocessor to access the memory segment without again referring to the descriptor table until the segment register's contents are changed. SUMMARY (cont.) • The flat mode memory contains 1T byte of memory using a 40-bit address. • In the future, Intel plans to increase the address width to 52 bits to access 4P bytes of memory. • The flat mode is only available in the Pentium 4 and Core2 that have their 64-bit extensions enabled.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.