A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Similar documents
Computer Systems Organization

Introduction to Computer Systems

Introduction to Computer Systems

Chris Riesbeck, Fall Introduction to Computer Systems

Introduction to Computer Systems

Bilgisayar Sistemlerine Genel Bakış

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

Introduction Presentation A

CSCI2467: Systems Programming Concepts

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

COS 318: Operating Systems

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

M2 Instruction Set Architecture

(Extract from the slides by Terrance E. Boult

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

18-447: Computer Architecture Lecture 16: Virtual Memory

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Lectures 5-6: Introduction to C

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

The Memory Hierarchy 10/25/16

Virtual Memory Nov 9, 2009"

Compilation, Disassembly, and Profiling (in Linux)

LC-3 Assembly Language

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Compiler Drivers = GCC

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Memory Management. Goals of this Lecture. Motivation for Memory Hierarchy

A Tour of Computer Systems

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Chapter 1 A Tour of Computer Systems

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

Main Memory. ICS332 Operating Systems

CSE 153 Design of Operating Systems

Page 1. Goals for Today" Virtualizing Resources" Important Aspects of Memory Multiplexing" CS162 Operating Systems and Systems Programming Lecture 20

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Virtual Memory Oct. 29, 2002

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Memory Management! Goals of this Lecture!

Abstractions and Reality

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

CISC 360. Virtual Memory Dec. 4, 2008

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

CSC 2405: Computer Systems II

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Lectures 5-6: Introduction to C

StackVsHeap SPL/2010 SPL/20

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

Introduction to Computer Systems

Introduction to Computer Systems

virtual memory Page 1 CSE 361S Disk Disk

Processes and Virtual Memory Concepts

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

Memory Management. Kevin Webb Swarthmore College February 27, 2018

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Chapter 3: Operating-System Structures

Page 1. Goals for Today" Important Aspects of Memory Multiplexing" Virtualizing Resources" CS162 Operating Systems and Systems Programming Lecture 9

Compila(on, Disassembly, and Profiling

12: Memory Management

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

Principles of Operating Systems

CS241 Computer Organization Spring Data Alignment

Department of Computer Science and Engineering Yonghong Yan

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Main Memory: Address Translation

CS 201 Linking Gerson Robboy Portland State University

Compiler, Assembler, and Linker

Deadlock Detection. Several Instances of a Resource Type. Single Instance of Each Resource Type

Lecture 19: Virtual Memory: Concepts

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

COS 318: Operating Systems. Overview. Jaswinder Pal Singh Computer Science Department Princeton University

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

Advanced Memory Organizations

Computer Organization - Overview

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Memory Management (Chaper 4, Tanenbaum)

Process Environment. Pradipta De

Introduction. CS3026 Operating Systems Lecture 01

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

Lecture 4: Memory Management & The Programming Interface

Processes. Johan Montelius KTH

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Introduction to OS. Introduction MOS Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

Machine Code and Assemblers November 6

A process. the stack

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

ECE Lab 8. Logic Design for a Direct-Mapped Cache. To understand the function and design of a direct-mapped memory cache.

Transcription:

A software view User Interface Computer Systems MTSU CSCI 3240 Spring 2016 Dr. Hyrum D. Carroll Materials from CMU and Dr. Butler How it works hello.c #include <stdio.h> int main() { printf( hello, world\n ); } The Compilation system gcc is the compiler driver gcc invokes several other compilation phases 1) Preprocessor 2) Compiler 3) Assembler 4) Linker What does each one do? What are their outputs? printf.o hello.c Source Preprocessor (cpp) hello.i Modified source Compiler (cc1) hello.s Assembly Assembler (as) hello.o Relocatable s Linker (ld) hello Executable 1. Preprocessor (cpp) First, gcc compiler driver invokes cpp to generate expanded C source! cpp just does text substitution! Converts the C source file to another C source file! Expands #defines, #includes, etc.! Output is another C source 1. Preprocesser Included files: #include <foo.h> #include bar.h Defined constants: #define MAXVAL 40000000 By convention, all capitals tells us it s a constant, not a variable. Macros: #define MIN(x,y) ((x)<(y)? (x):(y)) #define RIDX(i, j, n) ((i) * (n) + (j))

1. Preprocesser Conditional compilation: ( defined( #ifdef or #if #endif! Code you think you may need again (e.g. debug print ( statements " Include or exclude code based on #define/#ifdef " More readable than commenting code out! Portability " Compilers have built in constants defined " Operating system specific code» #if defined( i386 ) defined(win32) " Compiler-specific code» #if defined( INTEL_COMPILER) " Processor-specific code» #if defined( SSE ) 2. Compiler (cc1) Next, gcc compiler driver invokes cc1 to generate assembly code! Translates high-level C code into assembly " Variable abstraction mapped to memory locations and registers " Logical and arithmetic functions mapped to underlying machine opcodes 3. Assembler (as) Next, gcc compiler driver invokes as to generate code! Translates assembly code into binary code that can be directly executed by CPU 4. Linker (ld) Finally, gcc compiler driver calls linker (ld) to generate executable! Links together code and static libraries to form final executable Summary of compilation process Compiler driver (cc or gcc) coordinates all steps! Invokes preprocessor (cpp), compiler (cc1), assembler (as), and linker (ld).! Passes command line arguments to appropriate phases m.o a.o Libraries libc.a ( ld ) Linker printf.o p This is the executable hello.c Source Preprocessor (cpp) hello.i Modified source Compiler (cc1) hello.s Assembly Assembler (as) hello.o Relocatable s Linker (ld) hello Executable The run-time system Program runs on top of an operating system that implements! File system! Memory management! Processes! Device management! Network support! etc. Operating system functions Protection! Protects the hardware/itself from user s! Protects user s from each other! Protects files from unauthorized access Resource allocation! Memory, I/O devices, CPU time, space on disks

Operating system functions Abstract view of resources! Files as an abstraction of storage devices! System calls an abstraction for OS services! Virtual memory a uniform memory space abstraction for each process " Gives the illusion that each process has entire memory space! A process (in conjunction with the OS) provides an abstraction for a virtual computer " Slices of CPU time to run in Unix file system Key concepts! Everything is a file " Keyboards, mice, CD-ROMS, disks, modems, networks, pipes, sockets " One abstraction for accessing most external things! A file is a stream of bytes with no other structure. " on the hard disk or from an I/O device " Higher levels of structure are an application concept, not an operating system concept ( Windows/VMS» No records (contrast with Unix file systems Managed by OS on disk! Dynamically allocates space for files! Implements a name space so we can find files! Hides where the file lives and its physical layout on disk! Provides an illusion of sequential storage All we have to know to find a file is its name Process abstraction A fundamental concept of operating systems. A process is an instance of a when it is running.! A is a file on the disk containing instructions to execute! A process is an instance of that loaded in memory and running " Like you baking the cookies, following the instructions A process includes! Code and data in memory, CPU state, open files, thread of execution How does a get executed? The operating system creates a process.! Including among other things, a virtual memory space System loader reads from file system and loads its code into memory! Program includes any statically linked libraries ( access! Done via DMA (direct memory System loader loads dynamic shared s/libraries into memory Then it starts the thread of execution running! Note: the binary in file system remains and can be executed again Where are s loaded in memory? To start with, imagine a primitive operating system. # Single tasking. # Physical memory addresses go from zero to N. The problem of loading is simple # Load the starting at address zero # Use as much memory as it takes. # Linker binds the to absolute addresses # Code starts at zero # Data concatenated after that # etc.

Where are s loaded, cont d Next imagine a multi-tasking operating system on a primitive computer.! Physical memory space, from zero to N.! Applications share space! Memory allocated at load time in unused space! Linker does not know where the will be loaded! Binds together all the modules, but keeps them relocatable How does the operating system load this?! Not a pretty solution, must find contiguous unused blocks How does the operating system provide protection?! Not pretty either Where are s loaded, cont d Next, imagine a multi-tasking operating system on a modern computer, with hardware-assisted virtual memory The OS creates a virtual memory space for each user s.! As though there is a single user with the whole memory all to itself. Now we re back to the simple model! The linker statically binds the to virtual addresses! At load time, the operating system allocates memory, creates a virtual address space, and loads the code and data.! Binaries are simply virtual memory snapshots of s Example memory map Nothing is left relocatable, no relocation at load time 0xffffffff 0xc0000000 0x40000000 kernel virtual memory (code, data, heap, stack) user stack (created at runtime) memory mapped region for shared libraries memory invisible to user code ( pointer %esp (stack The memory hierarchy Operating system and CPU memory management unit gives each process the illusion of a uniform, dedicated memory space! i.e. 0x0 0xFFFFFFFF for IA32! Allows multitasking! Hides underlying non-uniform memory hierarchy 0x08048000 0 run-time heap (managed by malloc) read/write segment (.data,.bss) read-only segment (.init,.text,.rodata) unused brk loaded from the executable file Memory heirarchy motivation The memory heirarchy In 1980! CPUs ran at around 1 mhz.! A memory access took about as long as a CPU instruction! Memory was not a bottleneck to performance Today! CPUs are about 3000 times faster than in 1980! DRAM Memory is about 10 times faster than in 1980 We need a small amount of faster, more expensive memory for stuff we ll need in the near future! How do you know what you ll need in the future?! Locality! L1, L2, L3 caches Smaller Faster More Expensive Larger Slower Cheaper L5 L4 L3 L2 L1 L0 Registers Level 1 Cache On Chip Level 2 Cache ( chip (off Main Memory Local Secondary Storage Remote Secondary Storage

... Hardware organization The last piece how does it all run on hardware? CPU PC Register File Bus Interface ALU System Bus I/O Bridge Memory Bus Main Memory Reading the hello command from the keyboard Main "hello" USB Graphics I/O Bus... Disk controller Expansion slots for as network adapters MouseKeyboard User types "hello" Display Disk Loading the executable from disk into main memory Writing the output string from memory to the display Main "hello,world\n" hello code Main "hello,world\n" hello code controller as network adapters as network adapters MouseKeyboard Disk hello executable stored on disk MouseKeyboard "hello,world\n" Disk hello executable stored on disk