嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Utilizing the GDB debugger to analyze programs Background and application.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
Linking and Loading Fred Prussack CS 518. L&L: Overview Wake-up Questions Terms and Definitions / General Information LoadingLinking –Static vs. Dynamic.
Unix. Outline Commands Environment Variables Basic Commands CommandMeaning lslist files and directories ls -alist all files and directories mkdirmake.
©Colin Jamison 2004 Introduction to Linux Colin Jamison.
Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder.
Introduction to Fortran 90 Programming André Paul.
1 UQC122S3 Real-Time and Embedded Systems GCC as a cross compiler.
Selecting a Cross Development Environment. Why do you need to select a CDE? Through out your career the target systems will change rapidly –Both the h/w.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Lecture 01CS311 – Operating Systems 1 1 CS311 – Lecture 01 Outline Course introduction Setting up your system Logging onto the servers at OSU with ssh.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Building a Cross Compiler, Assembler and Linker Designed by Prof. Peng-Sheng Chen.
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
Abstracting the Underlying Multiple Operating System Architecture for Comprehensive Command Line Graphical Interface.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Lecture 7. Instructions and High-Level to Machine Code Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Programming With C.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Data Display Debugger (DDD)
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Linux Commands C151 Multi-User Operating Systems.
Chapter 13 : Symbol Management in Linking
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
CSc 453 Linking and Loading
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Hello world !!! ASCII representation of hello.c.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Operating Systems A Biswas, Dept. of Information Technology.
The World Leader in High Performance Signal Processing Solutions Toolchain Basics.
 CSC 215 : Procedural Programming with C C Compilers.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Introduction to GCC Department of Radio Physics and Electronics ILug-Cal Introduction to GCC Department of Radio Physics and Electronics, Calcutta University.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Introduction to C Topics Compilation Using the gcc Compiler
Precept I : Lab Environment, Unix, Bash, Emacs
CSC 215 : Procedural Programming with C
C151 Multi-User Operating Systems
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Program Execution in Linux
Introduction to C Topics Compilation Using the gcc Compiler
CSE 374 Programming Concepts & Tools
C Programming Lecture Series
CALL & Pthread.
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
Debugging.
SPL – PS1 Introduction to C++.
Presentation transcript:

嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月

2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction Set ARM Assembly Language ARM Assembly Programming  GNU ARM ToolChain Interrupts and Monitor

Lecture 5 GNU Development Tools

4 Outline Linux/Cygwin GNU Compiler Collection GNU Libraries and Linker GNU Binary Utilities

5 Cygwin Cygwin is a Linux-like environment for Windows. It consists of two parts: A DLL (cygwin1.dll) which acts as a Linux emulation layer providing substantial Linux API functionality. A collection of tools, which provide Linux look and feel.

6 Installation 1

7 Installation 2

8 Installation 3

9 Installation 4

10 Installation 5

11 Installation 6

12 Installation 7

13 Linux Commands 1 cat concatenate file(s) ex. $ cat hello.c ex. $ cat > newfile Hello World CTRL-D

14 Linux Commands 2 ls list information about the files (the current directory by default).

15 Linux Commands 3 cp copy source to destination ex. $ cp foo1 other mv move/rename source to destination ex. $ mv foo1 other rm delete file(s) ex. $ rm hello.c

16 Linux Commands 4 mkdir create a new directory ex. $ mkdir exercise rmdir remove a empty directory ex. $ rmdir exercise remove a directory containing files ex. $ rm –r exercise

17 Linux Commands 5 pwd show current directory ex. $ pwd /home/user1 cd change current directory ex. $ cd exercise

18 Linux Commands 6 ps show processes ex. $ ps kill kill a process ex. $ kill pid

19 Linux Commands 7 run a program in the background add & following the command line ex. $./hello &

20 Linux Commands 8 fg run a background program in the foreground ex. $ fg %job_num $ jobs [1]+ gcc program.c $ fg %1

21 Linux Commands 9 run the foreground program in the background ex. $ gcc program.c –o program Ctrl-z [1]+ stopped gcc program.c –o program $ bg [1]+ stopped gcc program.c –o program $

22 Outline Linux/Cygwin GNU Compiler Collection GNU Libraries and Linker GNU Binary Utilities

23 GNU Compiler Collection GNU Compiler Collection (GCC) An integrated distribution of compilers for several major programming languages C, C++, Objective-C, Fortran, Java, and Ada

24 Preprocessor Compiler Assembler Linker input files.c.s.o.a a.out / a.exe output files The Compilation Process

25 An Example #define GREETING ”Hello, World!\n” int main() { printf(GREETING); } hello.c

26 Using gcc 1 The simplest way to compile gcc hello.c  a.exe executable file If you want to produce a executable file named “hello” gcc -o hello hello.c  hello.exe executable file

27 Using gcc 2 To compile with multiple source files Ex: gcc -o hello hello.c foo.c  hello.exe executable file hello.c : extern void foo(char []) int main() { char str[]=“hello world!”; foo(str); } foo.c : void foo(char str[]) { printf(“%s\n”,str); }

28 Using gcc 3 -E: Stop after the preprocessing stage; do not run the compiler proper

29 Using gcc 4 -S: Stop after the stage of compilation proper; do not assemble. Output assembly code file (*.s)

30 Using gcc 5 -c : Compile and assemble the source files, but do not link. gcc –c hello.c  hello.o object file -o file : Place output in file file gcc –o hello hello.c  hello.exe

31 Using gcc 6 Specifying libraries -llibrary : Search the library named library when linking library file name : liblibrary.a  ex: foo.o refers to functions in library file “libz.a”  gcc -o foo foo.o -lz

32 Using gcc 7 Specify directories to search for header files, for libraries and for parts of the compiler -Idir: Add the directory dir to the head of the list of directories to be searched for header file. -Ldir : Add directory dir to the list of directories to be searched for -l.

33 Using gcc 8 Example A header file in “/tmp/foo.h” A function foo() in library “/tmp/libfoo.a” A program: /home/foo/foo.c gcc –I/tmp/foo.h –L/tmp/libfoo.a foo.c -lfoo #include int main() { … foo(); … }

34 Debugging Options -g : Produce debugging information in the operating system's native format -ggdb : Produce debugging information for use by GDB -time : Report the CPU time taken by each subprocess in the compilation sequence

35 Optimization Options 1 -O0 : Do not optimize (the default) -O or -O1 : Optimize Tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. -O2 : Optimize even more Performs nearly all supported optimizations that do not involve a space-speed tradeoff. Does not perform loop unrolling or function inlining.

36 Optimization Options 2 -O3 : Optimize yet more Turns on all optimizations specified by -O2 and also turns on the -finline-functions -Os : Optimize for size Enables all –O2 optimizations that do not typically increase code size -funroll-loops : Loop unrolling -finline-functions : Function inlining

37 Outline Linux/Cygwin GNU Compiler Collection GNU Libraries and Linker GNU Binary Utilities

38 How to make library 1 Example: write a function print_str in “foo.c” foo.c: #include void print_str(char str[]) { printf(“%s\n”, str); }

39 How to make library 2 First, make the object file “foo.o” Second, use “ar” to create archive file “libfoo.a”. Option “c” to crate archive file, “r” to insert or replace members to archive file. $ gcc -c foo.c $ ar cr libfoo.a foo.o

40 How to use library Write a header file “foo.h” : Our program “hello.c” : hello.c: #include main () { print_str(“hello world!”); } foo.h : extern void print_str(char []);

41 How to link library Compile with library (assume “foo.h” & “libfoo.a” in “/tmp” directory.) gcc include “linker” step. You can also use “ld” to linker objects and libraries. $ gcc -I/tmp -L/tmp hello.c -lfoo $./a.out hello world!

42 Practice #1 Temperature C = (5/9)(F-32) Write a subroutine that convert the temperature. Compile the subroutine into an object file. Make a temperature library Write a program that invokes the function to convert a source temperature to a target one

43 GNU C Library In Linux, header files is usually in “/usr/include”. Online manual To use GNU C library, you can search the function name to see what header files you need to include, and what library you need to link.

44 GNU Linker “ld” ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program, ex: $ gcc -I/tmp -c hello.c $ ld -o hello -L/tmp /usr/lib/crt1.o /usr/lib/crti.o hello.o -lfoo.a -lc $./hello hello world!

45 Shared Library 1 Use ld to make shared object (shared library). Compile a shared library Use “gcc” to make object file with “-fPIC” option (generate position-independent code for use in a shared library). Use “ld” with “-shared”, “-soname” to make shard object. $ gcc -fPIC -c foo.c $ ld -shared -soname libfoo.so -o libfoo.so.0 -lc foo.o

46 Shared Library 2 Install shared library Use “ldconfig” with “-v”, “-n” options. “-v” to show messages. “-n” to process directories specified on the command line. Not applicable on Cygwin! (why?) $ ldcofnig -v -n..: libfoo.so -> libfoo.so.0 (changed)

47 Shared Library 3 Using shared library Add “/tmp” in LD_LIBRARY_PATH (assume our libfoo.so in “/tmp” directory)  In bash  In tcsh or csh Compile with library $ export LD_LIBRARY_PATH=/tmp:$LD_LIBRARY_PATH $ setenv LD_LIBRARY_PATH /tmp:$LD_LIBRARY_PATH $ gcc -I/tmp -L/tmp -o hello hello.c –lfoo $./hello hello world!

48 Linker Options 1 -o output : Use output as the name for the program produced by ld. -larchive : Add archive file archive to the list of files to link. -Lsearchdir : Add path searchdir to the list of paths that ld will search for archive libraries.

49 Linker Options 2 -b input-format : to specify the binary format for input object files. ld may be configured to support more than one kind of object file. -r : generate an output file that can in turn serve as input to ld. This is often called partial linking. -E : When creating a dynamically linked executable, add all symbols to the dynamic symbol table.

50 Linker Options 3 When using gcc, you can pass linking options by “-Wl,option”. Pass one option at once $ gcc –Wl,-L. -Wl,-ohello -I/tmp -L/tmp hello.c -lfoo $./hello hello world!

51 Practice #2 Temperature C = (5/9)(F-32) Make a temperature shared library Write a program that invokes the function to convert a source temperature to a target one

52 Outline Linux/Cygwin GNU Compiler Collection GNU Libraries and Linker GNU Binary Utilities

53 ar Creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files. ar is considered a binary utility because archives of this sort are most often used as libraries holding commonly needed subroutines. ar creates an index to the symbols defined in relocatable object modules in the archive.

54 ar - Some Options ar [options] archive [member...] c - create the archive. r - insert the files member... into archive. a - add new files after an existing member of the archive. b - add new files before an existing member of the archive.

55 ar - Example Write a function print_str in “foo.c” Make the object file “foo.o” Use “ar” to create archive file “libfoo.a”. Option “c” to crate archive file, “r” to insert or replace members to archive file. void print_str(char str[]) { printf(“%s\n”, str); } $ gcc -c foo.c $ ar cr libfoo.a foo.o

56 ranlib Generates an index to the contents of an archive and stores it in the archive. The index lists each symbol defined by a member of an archive that is a relocatable object file. Example $ ranlib libfoo.a

57 nm Lists the symbols from object files. For each symbol, nm shows: The symbol value The symbol type The symbol name Example $ nm -s libfoo.a Archive index: foo in foo.o foo.o: T foo U printf

58 nm - Symbol Types In the example T : The symbol is in the text (code) section. U : The symbol is undefined. Some other types D : The symbol is in the initialized data section. N : The symbol is a debugging symbol.

59 nm - Some Options -A, -o, --print-file-name : precede each symbol by the name of the input file (or archive member) in which it was found. -s, --print-armap : include the index. -a, --debug-syms : display all symbols. -g, --extern-only : display only external symbols.

60 objdump Displays information about one or more object files. Options -a : Display archive header information. $ objdump -a libfoo.a In archive libfoo.a: foo.o: file format elf32-i386 rw-r--r-- 824/ May 13 11: foo.o

61 objdump - Other Options -f : Display contents of the overall file header. -h : Display contents of the section headers. -x : Display contents of all headers. -d : Display assembler contents of executable sections. -r : Display the relocation entries of the file. -t : Display contents of the symbol table(s).

62 objdump - Sample 1 $ objdump -h -r test1.o test1.o: file format pe-i386 Sections: Idx Name Size VMA LMA File off Algn 0.text b4 2**4 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1.data **4 ALLOC, LOAD, DATA 2.bss **4 ALLOC 3.rdata f4 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE DISP32 __alloca DISP32 ___main d dir32.rdata DISP32 _printf

63 objdump - Sample 2 $ objdump -h -r test1.exe test1.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0.text **4 CONTENTS, ALLOC, LOAD, READONLY, CODE 1.rdata **4 CONTENTS, ALLOC, LOAD, READONLY, DATA 2.bss **4 ALLOC 3.idata a00 2**2 CONTENTS, ALLOC, LOAD, DATA

64 readelf Displays information about one or more ELF format object files. Example: we use “-e” option to read all header from the executable file of “hello.c” Not applicable on Cygwin! (why?) $ gcc hello.c $ readelf -e a.out

65 readelf - Some Options -h : Show ELF header information. -l : Show program header information. -S : Show section header informaion. -s : Show the entries in symbol table section. -e : Show all headers.

66 Other Binary Utilities objcopy - copy and translate object files size - list section sizes and total size strings - list printable strings from files strip - discard symbols addr2line - convert addresses to file and line