3. # who am i Saumil Shah CEO Net-square. Hacker, Speaker, Trainer, Author. M.S. Computer Science Purdue University. Google: "saumil" LinkedIn: saumilshah
6. The CPU We shall discuss the Intel x86 32-bit CPU.
7. The CPU We shall discuss the Intel x86 32-bit CPU. The CPU has REGISTERS.
8. The CPU We shall discuss the Intel x86 32-bit CPU. The CPU has REGISTERS. "Variables" on the CPU, hard-wired. Size is equal to the "machine word". (32 bits)
11. What do Registers do? Registers hold data. They may be numbers... ...or memory addresses (pointers)
12. What do Registers do? Registers hold data. They may be numbers... ...or memory addresses (pointers) Using registers, the CPU can perform computations, read and write memory, and execute instructions.
13. x86 Registers - the basics EAX ESI EBX EDI ECX ESP EDX EBP EIP EFLAGS there are more, but this is good enough for now.
14. x86 Registers - General Purpose EAX Accumulator EBX Base ECX Count EDX Data
15. x86 Registers - General Purpose EAX Accumulator EBX Base ECX Count EDX Data Used for Integer operations (arithmetic), returning values (EAX), loops (ECX), or anything the compiler wishes to use them for.
16. x86 Registers - Pointers ESI Source Index EDI Destination Index
17. x86 Registers - Pointers ESI Source Index EDI Destination Index These are POINTERS, used for block copy operations. ESI = address of source, EDI = address of destination, ECX = count of bytes/words to be copied.
18. x86 Registers - Stack Related Stack Pointer ESP Frame Pointer (Base Pointer) EBP
19. x86 Registers - Stack Related Stack Pointer points to the top of the process stack. Stack Pointer ESP Frame Pointer (Base Pointer) EBP
20. x86 Registers - Stack Related Stack Pointer points to the top of the process stack. Stack Pointer ESP Frame Pointer (Base Pointer) EBP Frame pointer points to FRAMES within the stack. Frames store data for functions.
21. x86 Registers - EIP EIP Instruction Pointer (program counter)
22. x86 Registers - EIP A very important register. Points to a memory address from where the CPU fetches and executes the next instruction. EIP autoincrements after every instruction. EIP Instruction Pointer (program counter)
24. x86 Registers - Flags Individual bits indicate status of operations. Boolean values. Never treated as a full register, just individual bit flags. EFLAGS Bit Flags
26. The Operating System Modern Operating Systems are very complex and do many things. We shall discuss only the basic concepts and functions of an OS.
27. The Operating System Modern Operating Systems are very complex and do many things. We shall discuss only the basic concepts and functions of an OS. Multitasking and Multiprogramming Processes The Virtual Machine
30. What is Multiprogramming? The ability to store and execute multiple programs in the memory ...and what is Multitasking?
31. What is Multiprogramming? The ability to store and execute multiple programs in the memory ...and what is Multitasking? Running multiple PROCESSES at the SAME TIME.
33. So what is a "Process"? A PROCESS is termed as a program that is EXECUTING. A running program.
34. So what is a "Process"? A PROCESS is termed as a program that is EXECUTING. A running program. A process is an instance of a program. Processes "live" in memory. Programs live on disk. (secondary storage) A program may have multiple processes of its own self.
36. How do multiple processes run simultaneously? By TIME SLICING and CONTEXT-SWITCHING
37. How do multiple processes run simultaneously? By TIME SLICING and CONTEXT-SWITCHING Each process runs for a short time and is then PRE-EMPTED to let another process run. This happens so fast, it appears as if all processes are running simultaneously. This is called MULTITASKING
39. Multitasking Process Queue P2 P3 P4 P1 CPU Process P1 is running. It shall continue to run for a small period of time, called a QUANTUM.
40. Multitasking P2 P3 P4 P1 Time Slice Interrupt CPU An INTERRUPT is triggered at the end of the quantum. A snapshot of P1's registers (P1's CONTEXT) is saved.
41. Multitasking P2 P3 P4 P1 CPU P1 is then PRE-EMPTED. It is brought back into the process queue.
42. Multitasking P2 P3 P4 P1 CPU It is P2's turn now. P2's context is loaded into the CPU's registers. This is called CONTEXT SWITCHING.
49. What is a Virtual Machine? A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS.
50. What is a Virtual Machine? A view of ABSTRACTED HARDWARE as presented to a PROCESS by the OS. A process sees its OWN view of the CPU, Memory, Storage, and other devices. Every process runs in its own "virtual" machine. This is how the OS ensures process memory and resource segregation.
51. Do processes have their OWN view of the memory? Yes. Processes see "Virtual Memory"
52. Do processes have their OWN view of the memory? Yes. Processes see "Virtual Memory" Physical memory is divided into PAGES. A process is assigned pages as needed. This is done by the Memory Management Unit (MMU) From the process' point of view, it seems to have all the memory to itself.
53. Pages from P1's memory are mapped from physical memory. P1 sees a "virtual address space". Physical Memory P1's memory Physical and Virtual Memory
54. Physical and Virtual Memory Similarly for P2. Physical Memory P1's memory P2's memory
55. Can one process access another's memory? No. A process can only access its own virtual memory space.
56. Can one process access another's memory? No. A process can only access its own virtual memory space. A process CANNOT access physical memory.
57. The Process' view of memory Process Memory has its own VIRTUAL ADDRESS SPACE. Typically 2 to 3 GB. Binary Heap It is called a PROCESS MEMORY MAP. Lib 3GB (Linux) 2GB (Win32) Lib Lower addresses represented at the top of the map. Higher addresses at the bottom. Lib Stack Process' Virtual Memory
58. Linux Process Memory Map 0x08000000 Binary Heap Lib 3GB Lib Lib Stack 0xbfffffff Linux Process Memory Map
59. An example Here's how to view a process' memory map in Linux. The process here is PID 1110. saumil@localhost:$ pmap 1110 1110: /home/nweb/nweb 8181 /home/nweb 08048000 8K read/exec /home/nweb/nweb 0804a000 4K read/write /home/nweb/nweb 0804b000 8K read/write/exec [ anon ] 40000000 72K read/exec /lib/ld-2.3.1.so 40012000 4K read/write /lib/ld-2.3.1.so 40013000 4K read/write [ anon ] 40019000 1204K read/exec /lib/i686/libc-2.3.1.so 40146000 16K read/write /lib/i686/libc-2.3.1.so 4014a000 8K read/write [ anon ] bfffe000 8K read/write/exec [ anon ] total 1336K
62. File System Network Stack Scheduler MMU Driver Driver CPU NIC Storage Physical Memory
63. kernel space System Calls File System Network Stack Loader Scheduler MMU Driver Driver CPU NIC Storage Physical Memory
64. user space Virtual Memory PROCESS Virtual Memory PROCESS Virtual Memory PROCESS CPU FS N/W CPU FS N/W CPU FS N/W kernel space System Calls File System Network Stack Loader Scheduler MMU Driver Driver CPU NIC Storage Physical Memory
65. user space Virtual Memory PROCESS Virtual Memory PROCESS Virtual Memory PROCESS CPU FS N/W CPU FS N/W CPU FS N/W kernel space System Calls File System Network Stack Loader Scheduler MMU Driver Driver CPU NIC Storage Physical Memory