XGCC the Gnu C/C++ Language System for Embedded Development Revision: Beta 1, 1/23/2000 Copyright © 1999, 2000 by Embedded Support Tools Corporation
Total Page:16
File Type:pdf, Size:1020Kb
XGCC The Gnu C/C++ Language System for Embedded Development Revision: Beta 1, 1/23/2000 Copyright © 1999, 2000 by Embedded Support Tools Corporation. Printed in U.S.A. All Rights Reserved. No part of this document may be reproduced or transmitted by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without express prior written permission from the copyright holder. Limits of Liability and Disclaimer of Warranty Embedded Support Tools Corporation have used their best efforts in preparing the book and the programs incorporated in this product. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. Embedded Support Tools Corporation makes no warranty of any kind, expressed or implied, with regard to these programs, or the documentation contained in this book. It is entirely your responsibility to determine the suitability of these programs for your particular needs. Neither Embedded Support Tools Corporation nor its employees, officers, directors, or distributors shall be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of this book or these programs, even if they have been advised of the possibility of such damages. Trademarks XGCC and VisionClick are trademarks of Embedded Support Tools Corporation. PowerPC is a trademark of IBM Corporation, used under license therefrom. ColdFire and BDM are trademarks of Motorola Inc. Microsoft and Microsoft Windows are trademarks of Microsoft Corporation. All other trademarks are acknowledged to be the property of their respective owners. Page 3 Table of Contents 1 Introduction ..............................................................................................9 1.1 XGCC: Gnu CC from Embedded Support Tools Corporation..................................... 9 1.2 The Gnu project............................................................................................................ 9 1.3 Technical Support Information................................................................................... 10 1.4 CD-ROM Contents..................................................................................................... 11 1.4.1 Gnu C/C++ compiler for M68K and PowerPC embedded systems .................. 12 1.4.2 Gnu assembler (as), linker (ld) and binary utilities ........................................ 12 1.4.3 newlib C runtime library.................................................................................... 12 1.4.4 Gnu iostream C++ library.................................................................................. 13 1.4.5 EST’s librom.a I/O driver library ...................................................................... 13 1.4.6 Gnu make........................................................................................................... 13 1.4.7 Gnu documentation in HTML ........................................................................... 13 1.5 Minimum System Requirements ................................................................................ 14 1.5.1 Processor............................................................................................................ 14 1.5.2 RAM .................................................................................................................. 14 1.5.3 Disk Space ......................................................................................................... 14 1.6 Installation.................................................................................................................. 14 2 Hello, GCC: compiling your first program with Gnu CC..........................15 2.1 Environment variables................................................................................................ 16 2.2 The command line ...................................................................................................... 16 2.3 Linking an executable file .......................................................................................... 18 2.4 Creating a symbol file and download file for VisionClick......................................... 19 2.5 Downloading to the Target......................................................................................... 19 3 Running the Gnu tools............................................................................23 3.1 Program names ........................................................................................................... 23 3.2 How gcc controls the compilation and link process................................................... 23 3.3 gcc handles C, C++, assembly language, object files, and libraries........................... 25 3.4 Selecting the target system (-b <name>) .................................................................... 26 3.5 Target-specific options (-m<xxx>)............................................................................. 27 3.6 Specifying the optimization level (-O<n>)................................................................. 30 3.7 Enabling generation of debug info (-g ) ..................................................................... 31 3.8 Position-Independent Code (-fpic, -fPIC) .................................................................. 32 http://www.estc.com Page 4 Embedded Development with Gnu CC 3.9 Outputting an object file (-c) or assembly language file (-S) ..................................... 32 3.10 Specifying directories for include files (-I, -I-) .......................................................... 33 3.11 Creating dependency files (-MMD) ........................................................................... 33 3.12 Define a macro (-D<name>) ...................................................................................... 34 3.13 Verbose mode (-v)...................................................................................................... 35 3.14 Enabling warning messages (-Wall)........................................................................... 35 3.15 Specifying a linker script (-T <filename>)................................................................. 36 3.16 Specifying library files (-l<libname>)........................................................................ 36 3.17 Specifying directories for library files (-L<dirname>)............................................... 36 3.18 Passing options to the assembler and linker (-Wa, -Wl) ............................................ 37 3.18.1 Common Assembler Options............................................................................. 37 3.18.2 Common Linker Options ................................................................................... 38 3.19 Assembling & Linking via gcc vs. invoking the tools directly .................................. 38 3.20 The Gnu assembler..................................................................................................... 39 3.20.1 Comments.......................................................................................................... 39 3.20.2 Statements.......................................................................................................... 39 3.20.3 Escapes in character strings ............................................................................... 40 3.20.4 Local symbols.................................................................................................... 40 3.20.5 Assembler Directives......................................................................................... 40 3.20.6 Register names................................................................................................... 40 3.21 Linker scripts.............................................................................................................. 40 3.21.1 Common Linker Directives ............................................................................... 41 3.21.2 The standard linker scripts rom.ld and ram.ld ................................................... 47 3.22 Building projects with Gnu Make .............................................................................. 48 3.22.1 Make basics ....................................................................................................... 48 3.22.2 Make command line .......................................................................................... 50 3.22.3 Dependancy Files............................................................................................... 51 3.22.4 The Makefile template....................................................................................... 52 4 Embedded Essentials.............................................................................55 4.1 Preprocessor symbols ................................................................................................. 55 4.1.1 All targets........................................................................................................... 55 4.1.2 68k ..................................................................................................................... 56 4.1.3 PowerPC ............................................................................................................ 57 4.2 Interfacing C and assembly language functions......................................................... 58 4.2.1 68k ....................................................................................................................