160 likes | 271 Views
[2011-2] 시스템 프로그래밍 Class 2 : Introduction. 담당교수 : 최 윤 정 2011. 8.31 . Introduction. Compilation Process Preprocessing Phase Modifies the original C program according to the directives (#) Compilation Phase Translates the C program into Assembly-language program Assembly Phase
E N D
[2011-2] 시스템 프로그래밍Class 2: Introduction 담당교수 : 최 윤 정 2011. 8.31
Introduction • Compilation Process • Preprocessing Phase • Modifies the original C program according to the directives (#) • Compilation Phase • Translates the C program into Assembly-language program • Assembly Phase • Transforms the Assembly-language program into Machine language programs • Linking Phase • Merge all the necessary object files to generate executables.
printf.o Pre- processor (cpp) Compiler (cc1) Assembler (as) Linker (ld) hello.c hello.i hello.s hello.o hello Source program (text) Assembly program (text) Modified source program (text) Relocatable object programs (binary) Executable object program (binary)
Hardware Organization • Buses • Carry bytes of information back and forth between components • I/O Devices • The system’s connection to the external world • In the example, keyboards, mouse, display, disk drive • Main Memory • Temporary storage device holding both a program and the data while the processor executes the program • Processor • CPU interprets instructions stored in main memory • PC (program counter) points at some machine language instructions in main memory • Register File and ALU • CPU executes very simple operations • Load (from MM to Register), Store (from Register to MM), Update (Copy bytes to ALU, stores the result in a register), I/O Read (from I/O device to Register), I/O Write (from Register to I/O device), Jump (change PC value using a word extracted from the instruction), etc.
Hardware Organization CPU Register file ALU PC System bus Memory bus Main memory Bus interface I/O bridge I/O bus Expansion slots for other devices such as network adapters USB controller Graphics adapter Disk controller Mouse Keyboard Display Disk hello executable stored on disk
Running “hello, world” – reading k/b CPU Register file ALU PC System bus Memory bus Main memory "hello" Bus interface I/O bridge I/O bus Expansion slots for other devices such as network adapters USB controller Graphics adapter Disk controller Mouse Keyboard Display Disk User types "hello"
Running “hello, world” - loading CPU Register file ALU PC System bus Memory bus Main memory "hello,world\n" Bus interface I/O bridge hello code I/O bus Expansion slots for other devices such as network adapters USB controller Graphics adapter Disk controller Mouse Keyboard Display Disk hello executable stored on disk
Running “hello, world” - writing CPU Register file ALU PC System bus Memory bus Main memory "hello,world\n" Bus interface I/O bridge hello code I/O bus Expansion slots for other devices such as network adapters USB controller Graphics adapter Disk controller Mouse Keyboard Display Disk hello executable stored on disk "hello,world\n"
L1 cache holds cache lines retrieved from the L2 cache L2 cache holds cache lines retrieved from memory Main memory holds disk blocks retrieved from local disks Local disks hold files retrieved from disks on remote network servers Caches and Memory Hierarchy L0: Smaller, faster, and costlier (per byte) storage devices Registers CPU registers hold words retrieved from cache memory On-chip L1 cache (SRAM) L1: Off-chip L2 cache (SRAM) L2: Main memory (DRAM) L3: Larger, slower, and cheaper (per byte) storage devices Local secondary storage (local disks) L4: Remote secondary storage (distributed file systems, Web servers) L5:
Operating System Application programs Software Operating system Processor Main memory I/O devices Hardware System Layers Processes Virtual memory Files Processor Main memory I/O devices Abstractions by O/S
Operating System hello process shell process Time Application code Context switch OS code Application code Context switch OS code Application code • Processes • Operating system’s abstraction for a running program • Multiple programs can run concurrently on the same system • Concurrency provided by context switch • Context: State information that the process needs to run including values in PC, registers, and main memory
Operating System • Threads • Execution units in a process • Each thread runs in the context of the process and shares the same code and global data • Easier to share data between multiple threads than processes • Typically more efficient than processes
Operating System • Virtual Memory • Abstraction that provides each process with the illusion that it has exclusive use of the main memory • Process’s uniform view of memory
Operating System Memory invisible to user code Shared Libraries: Holds code and data for shared libraries such as C standard library and math library. Related to dynamic linking (CH 7). 0xffffffff Kernel virtual memory 0xc0000000 User stack (created at runtime) Stack: Top of the user’s address space. Used to implement function calls. Expands and contracts dynamically during the execution by function calls. Kernel is the part of the operating system that is always resident in memory. Top ¼ of the virtual memory reserved for the kernel. Applications are not allowed access. Memory mapped region for shared libraries Heap: Expands and contracts dynamically at run time as a result of calls to C standard library routines such as malloc and free. printf() function 0x40000000 Program Code and Data: Initialized directly from the contents of an executable object file Run-time heap (created at runtime by malloc) Read/write data Loaded from the hello executable file Read-only code and data 0x08048000 Unused 0
Operating System • Files • A sequence of bytes. • Every I/O device is modeled as a file. • A network is another I/O device to O/S.
Conclusion A Computer system consists of hardware and system software. Processors read and interpret binary instructions stored in main memory. Storage devices that are higher in the hierarchy are faster. Can help performance optimization. Operating system kernel serves an intermediary between the application and hardware. O/S provides three fundamental abstractions: Files for I/O devices, VM for MM and disks, Processes for Processor, MM and I/O devices. Network is just another I/O device.