Computer Systems Organization

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

Chris Riesbeck, Fall Introduction to Computer Systems

Introduction to Computer Systems

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

Introduction to Computer Systems

Introduction to Computer Systems

A Simplistic Program Translation Scheme

Linking Oct. 26, 2009"

Linking Oct. 15, 2002

Bilgisayar Sistemlerine Genel Bakış

M2 Instruction Set Architecture

LINKING. Jo, Heeseung

COS 318: Operating Systems

CS 201 Linking Gerson Robboy Portland State University

(Extract from the slides by Terrance E. Boult

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

Executables and Linking. CS449 Fall 2017

CS429: Computer Organization and Architecture

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

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info

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

CS 550 Operating Systems Spring Process I

Executables and Linking. CS449 Spring 2016

Virtual Memory Nov 9, 2009"

CSCI2467: Systems Programming Concepts

Computer Organization: A Programmer's Perspective

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

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

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

Linker Puzzles The course that gives CMU its Zip! Linking Mar 4, A Simplistic Program Translation Scheme. A Better Scheme Using a Linker

Compilation, Disassembly, and Profiling (in Linux)

Systems Programming and Computer Architecture ( ) Timothy Roscoe

COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES. Credit: Mostly Bryant & O Hallaron

Compiler Drivers = GCC

Systems I. Linking II

Linking February 24, 2005

Assembly Language Programming Linkers

Example C Program The course that gives CMU its Zip! Linking March 2, Static Linking. Why Linkers? Page # Topics

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

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

Linking. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

virtual memory Page 1 CSE 361S Disk Disk

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

Computer Systems. Linking. Han, Hwansoo

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

Exercise Session 7 Computer Architecture and Systems Programming

Lecture 8: linking CS 140. Dawson Engler Stanford CS department

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

Midterm. Median: 56, Mean: "midterm.data" using 1:2 1 / 37

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

Lecture 16: Linking Computer Architecture and Systems Programming ( )

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

Outline. Unresolved references

Process Environment. Pradipta De

Virtual Memory Oct. 29, 2002

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers

CS Basics 15) Compiling a C prog.

Today s Big Adventure

Today s Big Adventure

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Linking and Loading. CS61, Lecture 16. Prof. Stephen Chong October 25, 2011

Example C program. 11: Linking. Why linkers? Modularity! Static linking. Why linkers? Efficiency! What do linkers do? 10/28/2013

Compila(on, Disassembly, and Profiling

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

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

CISC 360. Virtual Memory Dec. 4, 2008

CS240: Programming in C

Computer Systems. Virtual Memory. Han, Hwansoo

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

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

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

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

2 Compiling a C program

Dynamic Memory Allocation. Zhaoguo Wang

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

Raspberry Pi / ARM Assembly. OrgArch / Fall 2018

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

CSL373: Operating Systems Linking

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

Lectures 5-6: Introduction to C

ECE 498 Linux Assembly Language Lecture 1

Introduction Presentation A

Compiler, Assembler, and Linker

C03c: Linkers and Loaders

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

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

Department of Computer Science and Engineering Yonghong Yan

ECE 471 Embedded Systems Lecture 5

18-447: Computer Architecture Lecture 16: Virtual Memory

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

ECE 471 Embedded Systems Lecture 4

Object Files. An Overview of. And Linking. Harry H. Porter III. Goals of this Paper. Portland State University cs.pdx.edu/~harry.

CSE 153 Design of Operating Systems

CS140 - Summer Handout #8

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Transcription:

Computer Systems Organization 1

Outline 2

A software view User Interface 3

How it works 4

The gcc compilation system 5

The gcc compilation system hello.c (source code) Pre-processor (cpp) hello.i (modified source) Compiler (cc) Assembler (as) hello.s (assembly code) hello.o (object file) Linker (ld) hello (executable) 6

The Preprocessor: cpp First step: gcc compiler driver invokes cpp Output is expanded C source cpp does text substitution! Converts the C source file to another C source file! Expands #define #include #if! Output is another C source file 7

The Preprocessor: cpp 8

Macros Whitespace required Whitespace forbidden 9

Macros - Why the parens? Whitespace required Whitespace forbidden 10

Macros Just Textual Substitution Perfectly Okay No syntax error, after all! 11

Conditional Compilation 12

Compiler Assembler 13

Linker Libraries libc.a hello.o there.o Linker (ld) hello The executable file 14

The gcc compilation system hello.c (source code) Pre-processor (cpp) hello.i (modified source) Compiler (cc) Assembler (as) hello.s (assembly code) hello.o (object file) Linker (ld) hello (executable) 15

GCC variations default is a.out 16

GCC variations default is hello.i default is hello.s default is hello.o default is a.out 17

GCC variations default is hello.i default is hello.s default is hello.o default is a.out 18

GCC variations 19

The Virtual Address Space FFFFFFFF 000000000 20

The Virtual Address Space FFFFFFFF Program Code 000000000 21

The Virtual Address Space FFFFFFFF Constants Program Code 000000000 22

The Virtual Address Space FFFFFFFF Data Constants Program Code 000000000 23

The Virtual Address Space FFFFFFFF Stack Data Constants Program Code 000000000 24

The Virtual Address Space FFFFFFFF Stack Heap Data Constants Program Code 000000000 25

The Virtual Address Space FFFFFFFF Stack Memory Maped Pages Heap Data Constants Program Code 000000000 26

The Virtual Address Space FFFFFFFF Stack Memory Maped Pages Heap.data segment.text segment Read-Write Data Constants Read-Only Program Code 000000000 27

The Executable File FFFFFFFF Additional Info.data segment Read-Write.text segment Read-Only 000000000 Header 28

Why Link? 29

The linking process (ld) 30

The Linking Process Header.text Header.data Additional Info main.o.text Header.text.data Additional Info foo.o.data Additional Info Executable File 31

Resolving External References Header.text Header.data Additional Info main.o.text Header.text.data Additional Info foo.o.data Additional Info Executable File 32

Example Virtual Address Space 0xffffffff 0xc0000000 Memory used by the kernel for this process invisible to user code stack %rsp (stack pointer) 0x40000000 memory mapped region for shared library functions shared by other processes 0x08048000 0x00000000 run-time heap (managed by malloc) read/write segment (.data,.bss) read-only segment (.init,.text,.rodata) unused brk loaded from the executable file 33

Libraries and Linking 34

Three Kinds of Object Files (Modules) Relocatable object file (.o file) Contains code and data in a form that can be combined with other relocatable object files to form executable object file. Each.o file is produced from exactly one source (.c) file Executable object file (a.out file) Contains code and data in a form that can be copied directly into memory and then executed. Shared object file (.so file) Special type of relocatable object file that can be loaded into memory and linked dynamically, at either load time or runtime. Called Dynamic Link Libraries (DLLs) by Windows 35

The Complete Picture main.c foo.c Translators (cc1, as) main.o Translators (cc1, as) foo.o libwhatever.a Partially linked executable (on disk) Linker (ld) myprog libc.so Shared library of dynamically relocatable object files libm.so Loader / Dynamic Linker (ld-linux.so) Fully linked executable myprog (in memory) libc.so functions called by main.c and foo.c are loaded, linked, and (potentially) shared among processes. 36

The Operating System 37

Operating system functions 38

Operating system functions 39

Unix file system 40

Unix file systems 41

Process abstraction 42

How does a program get executed? 43

Loading Executable Binaries Executable object file for example program p ELF header Program header table (required for executables).text section 0 Process image init and shared lib segments Virtual addr 0x080483e0.data section.bss section.symtab.rel.text.rel.data.debug Section header table (required for relocatables).text segment (r/o).data segment (initialized r/w).bss segment (uninitialized r/w) 0x08048494 0x0804a010 0x0804a3b0 44

Where are programs loaded in memory? 45

Where are programs loaded, cont d 46

Where are programs loaded, cont d 47

Modern linking and loading 48

The memory hierarchy 49

Memory heirarchy motivation 50

The memory heirarchy Smaller Faster More Expensive L1 L0 Registers Level 1 Cache On Chip Larger Slower Cheaper L3 L2 Level 2 Cache ( chip (off Main Memory L4 Local Secondary Storage L5 Remote Secondary Storage 51

Hardware organization CPU PC... Register File Bus Interface ALU System Bus I/O Bridge Memory Bus Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 52

Summary using hello.c 1. Shell process running, waiting for input CPU PC... Register File Bus Interface ALU System Bus I/O Bridge Memory Bus Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 53

Summary using hello.c 3. Command read into registers 4. Before sent to main memory before being read by shell process CPU Register File Memory Bus PC... Bus Interface ALU System Bus I/O Bridge Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 2. User types./hello 54

Summary using hello.c 5. Shell process creates new process through OS and initiates DMA of hello executable from disk to main memory CPU Register File Memory Bus PC... Bus Interface ALU System Bus I/O Bridge Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 55

Summary using hello.c 6. CPU executes hello code from main memory CPU PC... Register File Bus Interface ALU System Bus I/O Bridge Memory Bus Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 56

Summary using hello.c 7. CPU copies string hello, world\n from main memory to display CPU PC... Register File Bus Interface ALU System Bus I/O Bridge Memory Bus Main Memory I/O Bus USB Controller Graphics Controller... Disk Controller 57