1 / 23

x86 Memory Management

x86 Memory Management. Reviewing Some Terms New Terms Translating Addresses Converting Logical to Linear Address Page Translation. Reviewing Some Terms.

Télécharger la présentation

x86 Memory Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. x86 Memory Management • Reviewing Some Terms • New Terms • Translating Addresses • Converting Logical to Linear Address • Page Translation Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  2. Reviewing Some Terms • Multitasking permits multiple programs (or tasks) to run at the same time. The processor divides up its time between all of the running programs. • Segments are variable-sized areas of memory used by a program containing either code or data. • Segmentation provides a way to isolate memory segments from each other. This permits multiple programs to run simultaneously without interfering with each other. • A segment descriptor is a 64-bit value that identifies and describes a single memory segment: it contains information about the segment’s base address, access rights, size limit, type, and usage. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  3. New Terms • A segment selector is a 16-bit value stored in a segment register (CS, DS, SS, ES, FS, or GS). • provides an indirect reference to a memory segment • A logical address is a combination of a segment selector and a 32-bit offset. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  4. Translating Addresses • The x86 processor uses a one- or two-step process to convert a variable's logical address into a unique memory location. • The first step combines a segment value with a variable’s offset to create a linear address. • The second optional step, called page translation, converts a linear address to a physical address. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  5. Converting Logical to Linear Address The segment selector points to a segment descriptor, which contains the base address of a memory segment. The 32-bit offset from the logical address is added to the segment’s base address, generating a 32-bit linear address. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  6. Indexing into a Descriptor Table Each segment descriptor indexes into the program's local descriptor table (LDT). Each table entry is mapped to a linear address: Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  7. Paging (1 of 2) • Paging makes it possible for a computer to run a combination of programs that would not otherwise fit into memory. • Only part of a program must be kept in memory, while the remaining parts are kept on disk. • The memory used by the program is divided into small units called pages. • As the program runs, the processor selectively unloads inactive pages from memory and loads other pages that are immediately required. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  8. Paging (2 of 2) • OS maintains page directory and page tables • Page translation: CPU converts the linear address into a physical address • Page fault: occurs when a needed page is not in memory, and the CPU interrupts the program • OS copies the page into memory, program resumes execution Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  9. MS-DOS and the IBM-PC • Real-Address Mode • MS-DOS Memory Organization • MS-DOS Memory Map • Redirecting Input-Output • Software Interrupts • INT Instruction • Interrupt Vectoring Process • Common Interrupts Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  10. Real-Address Mode • Real-address mode (16-bit mode) programs have the following characteristics: • Max 1 megabyte addressable RAM • Single tasking • No memory boundary protection • Offsets are 16 bits • IBM PC-DOS: first Real-address OS for IBM-PC • Has roots in Gary Kildall's highly successful Digital Research CP/M • Later renamed to MS-DOS, owned by Microsoft Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  11. MS-DOS Memory Organization • Interrupt Vector Table • BIOS & DOS data • Software BIOS • MS-DOS kernel • Resident command processor • Transient programs • Video graphics & text • Reserved (device controllers) • ROM BIOS Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  12. MS-DOS Memory Map Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  13. Redirecting Input-Output (1 of 2) • Input-output devices and files are interchangeable • Three primary types of I/O: • Standard input (console, keyboard) • Standard output (console, display) • Standard error (console, display) • Symbols borrowed from Unix: • < symbol: get input from • > symbol: send output to • | symbol: pipe output from one process to another • Predefined device names: • PRN, CON, LPT1, LPT2, NUL, COM1, COM2 Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  14. Redirecting Input-Output (2 of 2) • Standard input, standard output can both be redirected • Standard error cannot be redirected • Suppose we have created a program named myprog.exe that reads from standard input and writes to standard output. Following are MS-DOS commands that demonstrate various types of redirection: myprog < infile.txt myprog > outfile.txt myprog < infile.txt > outfile.txt Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  15. INT Instruction • The INT instruction executes a software interrupt. • The code that handles the interrupt is called an interrupt handler. • Syntax: INT number (number = 0..FFh) The Interrupt Vector Table (IVT) holds a 32-bit segment-offset address for each possible interrupt handler. Interrupt Service Routine (ISR) is another name for interrupt handler. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  16. Interrupt Vectoring Process Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  17. Common Interrupts • INT 10h Video Services • INT 16h Keyboard Services • INT 17h Printer Services • INT 1Ah Time of Day • INT 1Ch User Timer Interrupt • INT 21h MS-DOS Services Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  18. What's Next • MS-DOS and the IBM-PC • MS-DOS Function Calls (INT 21h) • Standard MS-DOS File I/O Services Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  19. MS-DOS Function Calls (INT 21h) • ASCII Control Characters • Selected Output Functions • Selected Input Functions • Example: String Encryption • Date/Time Functions Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  20. INT 4Ch: Terminate Process • Ends the current process (program), returns an optional 8-bit return code to the calling process. • A return code of 0 usually indicates successful completion. mov ah,4Ch ; terminate process mov al,0 ; return code int 21h ; Same as: .EXIT 0 Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  21. Selected Output Functions • ASCII control characters • 02h, 06h - Write character to standard output • 05h - Write character to default printer • 09h - Write string to standard output • 40h - Write string to file or device Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  22. ASCII Control Characters • 08h - Backspace (moves one column to the left) • 09h - Horizontal tab (skips forward n columns) • 0Ah - Line feed (moves to next output line) • 0Ch - Form feed (moves to next printer page) • 0Dh - Carriage return (moves to leftmost output column) • 1Bh - Escape character Many INT 21h functions act upon the following control characters: Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

  23. Write a backspace to standard output: mov ah,06h mov dl,08h int 21h INT 21h Functions 02h and 06h: Write Character to Standard Output Write the letter 'A' to standard output: mov ah,02h mov dl,’A’ int 21h or: mov ah,2 Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

More Related