Motorola DSP56000 C Copiler
Motorola DSP56000 C Copiler
Motorola DSP56000 C Copiler
Optimizing C Compiler
User’s Manual, Release 6.3
DSP56KCCUM/D
Document Rev. 2.0, 07/1999
Suite56, OnCe, and MFAX are trademarks of Motorola, Inc.
Motorola reserves the right to make changes without further notice to any products herein. Motorola makes no
warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does
Motorola assume any liability arising out of the application or use of any product or circuit, and specifically disclaims
any and all liability, including without limitation consequential or incidental damages. “Typical” parameters which may
be provided in Motorola data sheets and/or specifications can and do vary in different applications and actual
performance may vary over time. All operating parameters, including “Typicals” must be validated for each customer
application by customer’s technical experts. Motorola does not convey any license under its patent rights nor the
rights of others. Motorola products are not designed, intended, or authorized for use as components in systems
intended for surgical implant into the body, or other applications intended to support life, or for any other application in
which the failure of the Motorola product could create a situation where personal injury or death may occur. Should
Buyer purchase or use Motorola products for any such unintended or unauthorized application, Buyer shall indemnify
and hold Motorola and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims,
costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of
personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that
Motorola was negligent regarding the design or manufacture of the part.
Motorola and are registered trademarks of Motorola, Inc. Motorola, Inc. is an Equal Opportunity/Affirmative
Action Employer.
All other tradenames, trademarks, and registered trademarks are the property of their respective owners.
Chapter 1
Introduction
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
1.2 Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
1.3 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
1.4 Manual Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Chapter 2
Installation Guide
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
2.2 Installation On An MS-DOS Machine (80386 or 80486) . . . . . . . . . . . . . . . . . . 2-1
2.3 Standard Installation On A SUN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
2.4 Alternate Installation On A SUN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
2.5 Test Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Chapter 3
Control Program Options
3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1
3.2 G56k Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
3.2.1 Preprocessor Phase Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
3.2.2 Compile Phase Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
3.3 Assemble Phase Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
3.4 Link Phase Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
Chapter 4
About g56k
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
4.2 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
4.3 Predefined Preprocessor Macro Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
4.4 Data Types and Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
4.4.1 Integral Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4.4.2 Floating-point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
4.4.2.1 Floating-point Format Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
4.4.2.2 Comparison with IEEE STD 754-1985 Standard . . . . . . . . . . . . . . . . . . . 4-5
Motorola v
4.4.3 Pointer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
4.5 Register Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
4.6 Memory Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
4.6.1 Activation Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
4.6.2 Global/Static Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
4.7 Compiler Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
4.8 Subroutine Call Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
4.8.1 Caller Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
4.8.2 Callee Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15
4.8.3 Return Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15
4.9 Software Support for Aritmetic Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15
4.10 Run-time Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16
4.10.1 Memory Allocation Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16
4.10.2 Run-time Stack Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
4.11 Optimization Techniques Implemented. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
4.11.1 Register Promotion and Lifetime Analysis . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
4.11.2 Common Sub-expression Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
4.11.3 Constant Propagation/Folding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18
4.11.4 Dead Code Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18
4.11.5 Tail Merging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18
4.11.6 Strength Reduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19
4.11.7 Loop Invariant Code Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19
4.11.8 Hardware DO Loop Instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19
4.11.9 Loop Rotation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
4.11.10 Jump Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
4.11.11 Instruction Combination. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
4.11.12 Leaf Routine Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
4.11.13 Function In-lining. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
4.11.14 Instruction Scheduling / Microcode Compaction . . . . . . . . . . . . . . . . . . . . 4-21
Chapter 5
Mixing C and Assembly Language
5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
5.2 In-line Assembly Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
5.2.1 Instruction Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
5.2.2 Output/Input Operands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
5.2.3 Explicit Register Saving. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
5.2.4 In-line Assembly Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5.2.5 Controlling Labels Generated by the Compiler . . . . . . . . . . . . . . . . . . . . . . 5-17
5.2.5.1 Calling Assembly Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Chapter 6
Software-Hardware Integration
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
6.2 Run-Time Environment Specification Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
6.3 crt0 File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
6.4 Bootstrapping the C program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
6.5 Memory Configuration and Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
6.6 Interrupt Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
6.7 Miscellaneous Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
6.8 Signal File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
6.9 Signal() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
6.9.1 Raise() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
6.10 Setjmp File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
6.11 Host-Supported I/O (printf (), et al). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
6.11.1 DSP functions __send () and __receive () . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13
6.11.2 The Host-Side I/O Driver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13
6.11.3 Communication between the Host and DSP . . . . . . . . . . . . . . . . . . . . . . . . 6-13
Motorola vii
Appendix A
Programming Support
A.1 Standard ANSI Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
A.2 ANSI C Library Sub-routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
A.2.1 Hosted vs. Non-Hosted Library Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
A.3 Forcing Library Routines Out-of-line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
A.4 Function Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-4
A.4.1 abort—Force abnormal program termination . . . . . . . . . . . . . . . . . . . . . . . . A-9
A.4.2 abs—Absolute value of integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-10
A.4.3 acos—Arc cosine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-11
A.4.4 asin—Arc sine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-12
A.4.5 atan—Arc tangent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-13
A.4.6 atan2—Arc tangent of angle defined by point y/x . . . . . . . . . . . . . . . . . . . . A-14
A.4.7 atexit—Register a function for execution at normal program termination . A-15
A.4.8 atof—String to floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-16
A.4.9 atoi—String to integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-17
A.4.10 atol—String to long integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-18
A.4.11 bsearch—Perform binary search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-19
A.4.12 calloc—Dynamically allocate zero-initialized storage for objects . . . . . . . A-20
A.4.13 ceil—Ceiling function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-22
A.4.14 clearerr—Clear any error indicators associated with a specified stream . . . A-22
A.4.15 cos—Cosine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A.4.16 cosh—Hyperbolic cosine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A.4.17 div—integer division with remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-24
A.4.18 exit—Terminate program normally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-25
A.4.19 exp—Exponential, ex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-26
A.4.20 fabs—Absolute value of a double . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-26
A.4.21 fclose—Close a stream. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-27
A.4.22 feof—Test the end-of-file indicator of a specified stream . . . . . . . . . . . . . . A-28
A.4.23 ferror—Test the error indicator of a stream . . . . . . . . . . . . . . . . . . . . . . . . . A-29
A.4.24 fflush—Flush all pending output associated with a stream . . . . . . . . . . . . . A-29
A.4.25 fgetc—Read a character from the specified stream . . . . . . . . . . . . . . . . . . . A-30
A.4.26 fgetpos—Get value of file position indicator associated with a stream. . . . A-31
A.4.27 fgets—Read a string from the specified stream . . . . . . . . . . . . . . . . . . . . . . A-32
A.4.28 floor—Floor function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-33
A.4.29 fmod—Floating point remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-33
A.4.30 fopen—Open a named file on the host’s disk . . . . . . . . . . . . . . . . . . . . . . . A-34
A.4.31 fprintf—Write formatted output to a stream . . . . . . . . . . . . . . . . . . . . . . . . A-36
A.4.32 fputc—Write a single character to a stream . . . . . . . . . . . . . . . . . . . . . . . . . A-36
A.4.33 fputs—Write a string to a stream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-37
Motorola ix
A.4.74 pow—Raise a double to a power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-77
A.4.75 printf—Print to standard output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-78
A.4.76 putc—Write a single character to a stream . . . . . . . . . . . . . . . . . . . . . . . . . A-83
A.4.77 putchar—Write a character to standard output . . . . . . . . . . . . . . . . . . . . . . A-84
A.4.78 puts—Write a string to standard output . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-85
A.4.79 qsort—Quick sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-86
A.4.80 raise—Raise a signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-87
A.4.81 rand—Pseudo- random number generator . . . . . . . . . . . . . . . . . . . . . . . . . . A-88
A.4.82 realloc—hange size of dynamically allocated storage area . . . . . . . . . . . . . A-88
A.4.83 remove—Remove a file from the disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-90
A.4.84 rename —Rename a file on the disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-90
A.4.85 rewind—Reset the file position indicator to the beginning of the file. . . . . A-90
A.4.86 scanf—Read formatted input from standard input. . . . . . . . . . . . . . . . . . . . A-91
A.4.87 setjmp—Save reference of current calling environment
for later use by longjmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-92
A.4.88 setbuf—Read formatted input from standard input . . . . . . . . . . . . . . . . . . . A-93
A.4.89 setvbuf—Alter stream buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-94
A.4.90 signal—Set up signal handler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-94
A.4.91 sin—Sine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-95
A.4.92 sinh—Hyperbolic Sine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-96
A.4.93 sprintf—Print to a string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-96
A.4.94 sqrt—Square root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-97
A.4.95 srand—Seed the pseudo-random number generator . . . . . . . . . . . . . . . . . . A-98
A.4.96 sscanf—Read formatted input from a string . . . . . . . . . . . . . . . . . . . . . . . . A-98
A.4.97 strcat—Concatenate two strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-99
A.4.98 strchr—Find first occurrence of a character in a string . . . . . . . . . . . . . . . A-100
A.4.99 strcmp—Compare two strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-100
A.4.100 strcoll—Compare two strings based on current locale . . . . . . . . . . . . . . . A-102
A.4.101 strcpy—Copy one string into another . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-102
A.4.102 strcspn—Compute length of prefix of one string
consisting entirely of characters not from another . . . . . . . . . . . . . . . . A-104
A.4.103 strerror—Map error code into an error message string . . . . . . . . . . . . . . . A-105
A.4.104 strlen—Determine length of a string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-106
A.4.105 strncat—Concatenate a portion of one string to another . . . . . . . . . . . . . . A-106
A.4.106 strncmp—Compare a portions of two strings . . . . . . . . . . . . . . . . . . . . . . A-108
A.4.107 strncpy—Copy a portion of one string into another. . . . . . . . . . . . . . . . . . A-109
A.4.108 strpbrk—Find first occurrence of a character from one string in another . A-110
A.4.109 strrchr—Find last occurrence of a character from one string in another . . A-111
A.4.110 strspn—Compute length of prefix of one string
consisting entirely of characters from another . . . . . . . . . . . . . . . . . . . A-112
Appendix B
DSP56000/DSP56001 Instruction Set
and Assembler Directive Summary
B.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
B.2 Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
B.2.1 Arithmetic Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
B.2.2 Logical Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2
B.2.3 Bit Manipulation Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3
B.2.4 Loop Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3
B.2.5 Move Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4
B.2.6 Program Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4
B.3 Directive Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-5
B.3.1 Assembly Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-5
B.3.2 Symbol Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B.3.3 Data Definition/Storage Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B.3.4 Listing Control and Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B.3.5 Object File Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
B.3.6 Macros and Conditional Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
B.3.7 Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-8
Motorola xi
Appendix C
Utilities
C.1 Utility Programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-1
C.1.1 asm56000—Motorola DSP56000/DSP56001 COFF Assembler. . . . . . . . . . C-1
C.1.1.1 asm5600 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-2
C.1.2 cldinfo—Memory size information from Motorola DSP COFF object file. . C-4
C.1.3 cldlod—Motorola COFF to LOD Format converter . . . . . . . . . . . . . . . . . . . C-5
C.1.4 cofdmp—Motorola DSP COFF File Dump Utility . . . . . . . . . . . . . . . . . . . . C-5
C.1.4.1 cofdmp Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-5
C.1.5 dsplib—Motorola DSP COFF Librarian . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-6
C.1.5.1 dsplib Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-6
C.1.6 dsplnk—Motorola DSP COFF Linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-7
C.1.6.1 dsplnk Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-8
C.1.7 gdb56—GNU Source-level Debugger for DSP56000/DSP56001. . . . . . . . C-11
C.1.7.1 gdb56 Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-11
C.1.8 run56—Motorola DSP56000/DSP56001 Simulator Based
Execution Device.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-12
C.1.8.1 run56 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-12
C.1.9 srec—Motorola DSP S-Record Conversion Utility . . . . . . . . . . . . . . . . . . . C-13
C.1.9.1 srec Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-13
Appendix D
GNU Debugger (GDB)
D.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1
D.1.1 Commands Not Implemented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1
D.1.2 DSP56000 Family Differences / Specific Requirements . . . . . . . . . . . . . . . . D-1
D.1.3 Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-3
D.1.4 GNU General Public License. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-3
D.1.5 Preamble. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-3
D.1.6 Terms and Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-4
D.1.7 No Warranty. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-6
D.1.8 End of Terms and Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-7
D.2 Input and Output Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-8
D.3 Specifying GDB’s Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-10
D.3.1 Specifying Files with Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-10
D.3.2 Specifying Files with Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-10
D.4 Compiling Your Program for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-12
D.5 Running Your Program Under GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-12
D.5.1 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-13
D.5.2 Your Program’s Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-13
Motorola xiii
D.11.3 Giving the Program a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-47
D.11.4 Returning from a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-48
D.12 Canned Sequences of Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-48
D.13 User-Defined Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-48
D.13.1 Command Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-49
D.13.2 Commands for Controlled Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-49
D.14 Options and Arguments for GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-50
D.14.1 Mode Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-50
D.14.2 File-specifying Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-51
D.14.3 Other Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-51
D.15 Using GDB under GNU Emacs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-52
Appendix E
Additional Support
E.1 Motorola DSP Product Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-2
E.2 DSP56000CLASx Assembler/Simulator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-2
E.2.1 Macro Cross Assembler Features: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-3
E.2.2 Simulator Features: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-3
E.3 DSP320to56001 Translator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-4
E.3.1 DSP320to56001 Translator Features: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-4
E.4 DSP56000ADSx Application Development Systems (ADS) . . . . . . . . . . . . . . . E-4
E.4.1 DSP56000ADS ADS Hardware Features: . . . . . . . . . . . . . . . . . . . . . . . . . . . E-4
E.4.2 DSP56000ADSx ADS Software Features: . . . . . . . . . . . . . . . . . . . . . . . . . . E-5
E.4.2.1 Support Integrated Circuits: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-5
E.5 Dr. BuB Electronic Bulletin Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-6
E.5.1 Motorola DSP News . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-14
E.5.2 Motorola Field Application Engineers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-14
E.5.3 Design Hotline – 1-800-521-6274 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-14
E.5.4 DSP Applications Helpline– (512) 891-3230 . . . . . . . . . . . . . . . . . . . . . . . E-14
E.5.5 DSP Marketing Information – (512) 891-2030 . . . . . . . . . . . . . . . . . . . . . . E-15
E.5.6 DSP Third-Party Support Information – (512) 891-3098 . . . . . . . . . . . . . . E-15
E.5.7 DSP University Support – (512) 891-3098 . . . . . . . . . . . . . . . . . . . . . . . . . E-15
E.5.8 DSP Training Courses – (602) 994-6900. . . . . . . . . . . . . . . . . . . . . . . . . . . E-15
E.5.9 Reference Books and Manuals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-16
E.5.10 General DSP: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-16
E.5.11 Digital Audio and Filters:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-17
E.5.12 C Programming Language: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-18
E.5.13 Controls:. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-19
E.5.14 Graphics: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-19
E.5.15 Image Processing: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . E-21
Motorola xv
xvi Motorola DSP56000 Family Optimizing C Compiler User’s Manual Motorola
List of Tables
Motorola xvii
B-5 Move Operation Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4
B-6 Program Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4
B-7 Assembly Control Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-5
B-8 Control Symbol Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B-9 Storage Allocation Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B-10 Output Listing Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-6
B-11 Object file Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
B-12 Conditional Assembly Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-7
B-13 Programming Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-8
C-1 asm56000 Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-3
C-2 cofdmp Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-5
C-3 cldinfo Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-7
C-4 dsplnk Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-9
C-5 gdb56 Command Line Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-11
C-6 run56 Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-12
C-7 srec Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-13
D-1 GDB File Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-11
D-2 Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-14
D-3 Working Directory Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-14
D-4 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-17
D-5 Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-18
D-6 Deleting Breakpoints Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-20
D-7 Disabling Breakpoint Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-20
D-8 Stepping Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-25
D-9 Backtraces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-28
D-10 Frame Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-29
D-11 Frame Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-30
D-12 List Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-31
D-13 Single Source Line Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-31
D-14 Directory Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-33
D-15 GDB Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-34
Motorola xix
xx Motorola DSP56000 Family Optimizing C Compiler User’s Manual Motorola
List of Figures
Motorola xxi
xxii Motorola DSP56000 Family Optimizing C Compiler User’s Manual Motorola
List of Examples
Motorola xxiii
3-28 -Wimplicit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
3-29 -Wreturn-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
3-30 -Wunused . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
3-31 Pass a single option to the assembler.. . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
3-32 Pass multiple options to the assembler. . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
3-33 -crt file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
3-34 Pass a single option to the linker. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
3-35 Pass multiple options to the linker.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
3-36 -lLIBRARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
3-37 -r CTLFILE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
5-1 reg_save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5-2 instruction_template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
5-3 operand_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
5-4 OES Modifier j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
5-5 OES Modifier e. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
5-6 OES Modifier h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
5-7 OES Modifier k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
5-8 OES Modifier g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
5-9 OES Modifier g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
5-10 OES Modifier i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
5-11 OES Modifier f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
5-12 OES Modifier p and q. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
5-13 Input Expression / Output Expression . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5-14 Read-Only Operand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5-15 Write-Only Operand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5-16 Read-Write Operand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5-17 Read-Write Operand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5-18 Multiple Instruction — Single-Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5-19 Multiple Instruction — Multiple-Line . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5-20 Mulitple Use of _ _asm() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5-21 Line Separation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
5-22 Instruction Template Label. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
Motorola xxv
A-10 atol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-18
A-11 bsearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-19
A-12 calloc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-21
A-13 ceil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-22
A-14 clearerr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-22
A-15 cos. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A-16 cosh. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A-17 div . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-24
A-18 exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-25
A-19 exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-26
A-20 fabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-27
A-21 fclose. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-27
A-22 feof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-28
A-23 fflush. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-29
A-24 fgetc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-30
A-25 fgetpos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-31
A-26 fgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-32
A-27 floor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-33
A-28 fmod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-33
A-29 fopen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-35
A-30 fprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-36
A-31 fputc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-36
A-32 fputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-37
A-33 fread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-38
A-34 free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-39
A-35 freopen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-40
A-36 frexp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-41
A-37 fscanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-43
A-38 fseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-44
A-39 fsetpos. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-45
A-40 ftell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-46
A-41 fwrite. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-47
Motorola xxvii
A-74 printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-82
A-75 putc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-83
A-76 putchar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-84
A-77 puts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-85
A-78 qsort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-86
A-79 raise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-87
A-80 rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-88
A-81 realloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-89
A-82 remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-90
A-83 rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-90
A-84 rewind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-91
A-85 scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-91
A-86 setjmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-92
A-87 signal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-95
A-88 sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-95
A-89 sinh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-96
A-90 sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-97
A-91 sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-97
A-92 srand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-98
A-93 strcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-99
A-94 strchr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-100
A-95 strcmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-101
A-96 strcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-103
A-97 strcspn. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-104
A-98 strerror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-105
A-99 strlen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-106
A-100 strncat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-107
A-101 strncmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-108
A-102 strncpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-109
A-103 strbrk. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-110
A-104 strrchr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-111
A-105 strspn. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-112
Motorola xxix
xxx Motorola DSP56000 Family Optimizing C Compiler User’s Manual Motorola
Overview
Chapter 1
Introduction
1.1 Overview
The DSP56KCC GNU based C cross-compiler is the latest high-level language
development system for the Motorola DSP56000 family of digital signal processors
(DSP). It includes:
• an integrated control program — g56k
• an ANSI compliant C language preprocessor — mcpp
• an ANSI optimizing C compiler — g56-cc1
• a DSP56000 common object file format (COFF) assembler — asm56000
• a COFF linker — dsplnk
• a COFF librarian — dsplib
• a source level debugger for C — gdb56
• a simulator based execution program — run56
• various object file manipulation tools — srec, cldlod, cofdmp
This integrated software system runs on a variety of machines and operating systems,
including the IBM PCä (80386 family and above — 386sx, 486, etc.), and Sun SPARCä
workstations.
The compiler implements the full C language as defined in American National Standard
for Information Systems - Programming Language - C, ANSI X3.159-1989. It accepts one
or more C language source files as input and generates a corresponding number of
assembly language source files which are suitable as inputs to the DSP56000 COFF
assembler. The compiler automatically implements numerous optimizations which
simplifies implementing fast and efficient DSP algorithms.
The C language preprocessor is an implementation of the ANSI standard which includes
support for arbitrary text file inclusion, macro definition and expansion, and conditional
compilation. The preprocessor exists as a separate program and may be used as a
general-purpose macro preprocessor.
The compiler control program, g56k, is the standard compiler interface used to control the
sequence of operations required to compile a program. This control program allows the
user to select a wide variety of control options which affect the four compilation phases —
preprocessing, compiling, assembling, and linking. The control program parses the
command line options, and invokes the required sub-programs on the specified files.
User’s Input Files
C Source Asm
Files Files
ANSI C
Preprocessor
ANSI C
Compiler
srec User
Conversion Provided
utility PROM
Programmer
Execution Devices
Target
run56 gdb56 sim56000 ads56000 System
Object files are stored using the COFF format. COFF stands for Common Object File
Format. Utilities such as Cldinfo and Cldlod may be used to gain visibility into object
files.
1. Given a list of C source files from the user (see Figure 1-1) and options to apply to
those files, the control program runs each file through the C preprocessor and the C
compiler. The compiler creates individual assembly language source files for each
C source file provided on the command line.
2. The control program then sends the compiler output from these files to the
assembler, in addition to any assembly language files specified by the user on the
G56k command line.
3. The assembler output is routed to the linker for final processing. The linker tries to
resolve all unresolved link-time symbols with the standard (and any explicitly
requested) C libraries. The COFF linker object file output may then be directed to
any of several execution devices. Notice that the assembler can also be used to
create library files which can be included in a user defined library.
4. The execution devices shown in Figure 1-1 are:
a. RUN56 which allows the DSP56000/1 code (in COFF format) to be executed
on the host computer’s CPU
b. GDB56 which is a debugging tool for trouble-shooting the compiled application
c. SIM56000 which is a complete DSP56000/1 simulator that can be used to
execute the compiled application (in either COFF format or .lod file format) and
allow examination of registers and memory
d. ADS56000 is the development system hardware that can then be used to load
and execute the compiled application (in either COFF format or .lod file format)
on the ADS development system
e. The target system shown is the user’s custom DSP system.
Note: The three execution devices in the shaded boxes are not part of the C compiler
software. The COFF linker output can be used by these execution devices
directly. The conversion utility Srec (see Figure 1-1) can be used to convert the
executable file from the COFF Linker to a suitable format for PROM burning.
These PROMs can then be used on the ADS development system or the user’s
target system. The PROM programmer, ADS development system and user’s
target system are not part of the DSP56KCC compiler.
The DSP56000 family represents a departure from more conventional architectures on
which other implementations of the C language are based. Also, the nature of DSP
applications dictates that a greater measure of control be provided to the programmer in
specifying the constraints of the run-time environment. For these reasons, the components
of the development system include options for handling separate memory spaces, stack
initialization, chip operating modes and other issues.
The purpose of this manual is to:
1. Provide detailed installation procedures for both UNIX based systems and
MS-DOS based systems. This manual explains how to install and operate the
DSP56KCC ANSI C compiler development system in a hosted environment.
2. Provide an overview of the compiler operation. It also includes information on
combining C modules with assembly language programs and advanced topics
pertaining to compiler run-time characteristics.
3. Provide reference information on compiler options, ANSI library routines, and
utilities.
This manual assumes a familiarity with the C programming language, with the host
machine and operating system environment. It also assumes that the programmer
understands how to create and edit C language source files on this host system. For more
information on the C language and other DSP56000/1 development tools, see the
references listed in Appendix D.
1.3 Notation
The following notation will be used in this text.
1. A prompt is indicated in this manual by:
C:\>
2. An example of an MS-DOS directory name is:
\USR\DIRECTORY
3. The contents of an MS-DOS directory are examined by entering:
C:\> DIR
4. The contents of an MS-DOS file are displayed by entering:
C:\> TYPE FILE
5. The program “HELLO.EXE” would be executed by the command line:
C:\> HELLO
Appendix E, "Additional Support," , provides information on how you can obtain further
support from Motorola and third party companies.
Chapter 2
Installation Guide
2.1 Introduction
This chapter describes installation on MS-DOS and Sun computers. Two installation
procedures are detailed for the Sun. The first procedure uses the default location for the
files. The second procedure allows the user to select the directory where the compiler’s
files will be located. Only one procedure is needed for MS-DOS machines.
The various parts of the compiler reside in a directory tree named DSP. The default
location for the DSP directory tree is /usr/local on UNIX systems. If this default location
is acceptable, then perform the standard installation; if it is not acceptable, then perform
the alternate installation. The alternate installation procedure allows the user to install the
DSP directory tree anywhere.
h. DSPLOC need only be set if the default output drive or the default location is
not chosen. If DSPLOC is set, it must be set to the location of the dsp directory
tree. For example, if the user installed the compiler’s directory tree DSP in the
directory D:\usr\mydir, then DSPLOC would need to be set as D:\usr\mydir:
SET DSPLOC=<compiler’s dsp directory tree>
if the directory <compiler’s dsp directory tree> is d:\usr\mydir, then
SET DSPLOC=D:\USR\MYDIR
5. Make sure that <compiler’s dsp directory tree>\dsp\bin is included in the path
instruction. This is needed by command.com if it is to find G56k. If the default
drive and path were chosen, then the path C:\dsp\bin would need to be added as
follows:
PATH ...;C:\DSP\BIN;...
If, for example the compiler’s dsp directory tree was installed in C:\usr\mydir, then
C:\usr\mydir\dsp\bin would need to be added as follows:
PATH ...;C:\USR\MYDIR\DSP\BIN;...
6. Make sure that other DOS memory managers do not interfere with the DOS
extended memory manager for G56k. The compiler uses its own DOS extended
memory manager called dos4gw.exe, and this memory manager may not work if
a different memory manager is already installed. Although this DOS extender is
DPMI 0.9 compliant, It is recommended that initially all other DOS extended
memory managers be removed, in order to test the installation. The DOS extended
memory manager dos4gw.exe is called during the compiler’s execution, and
requires at least 2M bytes of RAM. This memory manager uses hard drives for the
swap space for the memory management. By default, the swap space location is the
C drive and the size of the swap space is 16 Mbytes.
7. The DOS environment DOS4GVM controls the configuration of the DOS extended
memory management, and the environment DOS4GVM has the following format.
[option[#value]] [option[#value]]
As an example, the following line in the autoexec.bat file will enable an 8MB swap
file with automatic deletion of the swap file:
SET DOS4GVM=DELETESWAP VIRTUALSIZE#8192
The following line will use F drive for the swap space instead of the current drive.
SET DOS4GVM=DELETESWAP SWAPNAME#F:\BIG.SWP
8. There is a READ.ME file included in the package and it should be read for any
recent changes in the installation on compiler itself.
Chapter 3
Control Program Options
3.1 Overview
Program G56k is the control program for Motorola’s optimizing C compiler for the
DSP56000/DSP56001 family of digital signal processors. The program G56k automates
control of the four C compiler phases – preprocessing, compiling, assembling, and linking.
The program G56k utilizes a command syntax similar to those adopted by UNIX utilities.
The G56k syntax is:
g56k [options] files
where:
1. [options] is one or more of the options found in this chapter. One difference
between G56k and UNIX-style utilities is that the combination of multiple single
character options is not allowed. For example, “-O -g” instructs the compiler to
generate an optimized executable with source level debug information, whereas
“-Og”, which is acceptable to UNIX-style compilers is not acceptable to G56k.
2. “file …” is the file(s) to be processed. Program G56k accepts input filenames
suffixed with “.c” (ANSI C source files), “.i” (preprocessed C source files), “.asm”
(DSP56000/DSP56001 assembly code), and “.cln” (COFF link files). The control
program processes each file according to this suffix. The G56k output is controlled
by the specific set of command line options provided. For instance, if no command
line arguments are provided, the compiler will generate a COFF load file “a.cld”. If
the -c option is invoked, the compiler will generate a COFF link file suffixed with
“.cln”. A complete description of the command line options, with examples, is
provided in Section 3.2.
Note: It is strongly recommended that g56k always be used to invoke the C compiler
utilities rather than individually executing them.
A standard directory search list is consulted by G56k for:
options specific to the DSP56000/1. Although these various methods of optimization are
all effective, they may have side effects which are undesirable in specific cases, e.g. an
optimization option may increase code speed at the cost of increased memory usage. It is
often preferable to trade memory space for speed, but in cases where the extra memory
space is not available, this particular optimization could not be used.
The various compiler phases will report errors; however, the user has the option to turn off
all warnings using -w and can enable additional warnings individually or as a group using
-wall. The warnings which are not enabled by -wall are those listed below -wall in
Table 3-1, “DSP56KCC Options,” on page 3-4.
g56k Preprocesso
Assemble Phase Link Phase Compile Phase
Command r Phase
Options Options Options
Line Options Options
-bPREFIX
Direct G56k to search for compilation phases, start-up files and libraries whose
names are prefixed with the word PREFIX. Note that only one additional prefix can
be specified. This is very similar to the -B option.
-o FILE
Select FILE as the output file. This applies to all phases of the compiler. When the
-o flag is not in use, the following file names are used by the compiler as the default
output file names depending upon the compile options as follows:
Only generate a preprocessed file (do not invoke the compiler, assembler or linker) and
put the results in file.i.
C:\> g56k -E file.c -o file.i
Compile file.c and generate the executable output file, fft.cld. If an output name is
not given, the default file name is a.cld.
C:\> g56k file.c -o fft.cld
-v
Verbose mode. The compiler control program announces to Stderr all commands
that it attempts to execute for each phase of the compilation process. This
command is also used by the preprocessor to print the software version
information. If the -E option is selected, -v will only enable the verbose mode,
otherwise it will enable the verbose mode and print the version information.
-DMACRO
Define the preprocessor macro MACRO with a constant value of “1”. This is
equivalent to making MACRO a constant set to one.
Example 3-9. Compile and Run Program Dsp.c
Compile and run a simple program, Dsp.c, and enable or disable a printed message
depending on the macro definition given at the command line.
C:\> type dsp.c
#include <stdio.h>
main()
{
#ifdef DSP56000
printf("message: DSP56000.\n");
#else
printf("message: DSP56001.\n");
#endif
}
-DMACRO=DEFN
Define preprocessor macro MACRO as DEFN.
The program Dsp.c uses the macro FROM_COMMAND_LINE which prints a message to
the standard output using a message code given on the command line.
C:\> type dsp.c
#include <stdio.h>
main()
{
printf("message code: %d.\n", FROM_COMMAND_LINE);
}
-E
The input source file will only be preprocessed through CPP and the output results
will be sent to the standard output. See the -O option to save the output into a
named file.
Example 3-11. Preprocess C Source Program Foo.c
This example shows how to preprocess the C source program Foo.c and send the results to
the standard output.
C:\> type foo.c
#define DELAY 1000
main()
{
int cnt = DELAY;
while(cnt--);
}
C:\> g56k -E foo.c
# 1 "foo.c"
main()
{
int cnt = 1000 ;
while(cnt--);
}
The CPP output can be saved into file "foo.i" by using the -o option.
C:\> type foo.c
#define DELAY 1000
main()
{
int cnt = DELAY;
while(cnt--);
}
main()
{
int cnt = 1000 ;
while(cnt--);
}
-IDIR
The control line of the C source program of the form
#include <filename>
will cause the replacement of that line by the entire contents of the file filename.
This is normally referred to as “file inclusion”. The named file is searched for in a
sequence of implementation-dependent directories. The standard include directory
for this compiler is /usr/local/dsp/include. Similarly, a control line of the form
#include “filename”
searches first in the current working directory, and if that fails, then searches as if
the control line were #include <filename>.
The option -IDIR directs the C compiler to include the directory DIR in addition to
the standard include directory. For the file inclusion <filename>, the compiler
searches first in the DIR directory and if that fails, then searches
/usr/local/dsp/include. For the file inclusion “filename”, the compiler searches
first in the DIR directory and if that fails, then searches the current working
directory, and if that fails also, then searches /usr/local/dsp/include.
A delay program Foo.c uses delay constant DELAY which is defined in the include file,
myinclude.h. The program uses the control line #include “myinclude.h” to include
the definition of the constant DELAY. Without any option the include file should be
located in the currently working directory since it is not in the standard include directory.
Assuming that the include file “myinclude.h” is desired to be in the directory ./inc, the
following sequence of the commands explains how the -I option is used to include the file
myinclude.h in the ./inc directory with the control line #include “myinclude.h” in the
Foo.c program.
Example 3-13. -I Option Used to Include the File “myinclude.h”
C:\> dir
foo.c inc/
-I-
This option is always used in conjunction with the -IDIR option and limits the file
search to look for file inclusions #include “filename”, whereas -IDIR alone
directs C compiler to search the directory DIR for both file inclusion <filename>
and “filename”. Any directories specified with -I options before the -I- option are
searched only for the case of #include “filename”; they are not searched for
#include <filename>.
If additional directories are specified with -I options after the -I- option, these
directories are searched for both #include “filename” and #include
<filename> directives.
Note: The -I- option inhibits the use of the current directory as the first search
directory for #include “filename”. There is no way to override this effect
of -I-. However, the directory which is current when the compiler is invoked
can be searched by using -I. This is different from the preprocessor’s default
search list, but it is often satisfactory. -I- does not inhibit the use of the standard
system directories for header files. Thus, -I- and -nostdinc are independent.
A test program File.c is used to test a file operation fopen() which is, in this example,
desired to be developed for a DSP56000/1 system. The file include <stdio.h> is used as if
it is in the standard include directory. The file is desired to be developed or debugged, and
it is located in the user working directory ./mysys. This example shows how to use -IDIR
and -I- combination to test file inclusion <filename>. Notice that the -I./inc -I-
-I./mysys option specifies the Inc directory only for the file inclusion “cnt.h” and mysys
directory for the file inclusion <stdio.h>.
Example 3-14. Test Program “file.c”
C:\> dir
file.c inc/ mysys/
main()
{
int delay = 25;
FILE *fp;
fp = fopen (“myfile”, ”w”);
while (--delay);
}
Notice that the file inclusion “cnt.h” is from the directory ./inc as shown in the line # 1
“.\inc\cnt.h” 1 and the file inclusion <stdio.h> is from the directory .\myinc as shown in
the line # 1 “.\myinc\stdio.h” 1.
-i FILE
Process FILE as an input, discarding the resulting output, before processing the
regular input file. Because the output generated from FILE is discarded, the only
effect of -i FILE is to make the macros defined in FILE available for use in the
main input.
The program Greeting.c prints a simple message using the macro MESSAGE. The file
macros.c contains the macro definition, i.e. the actual message. The only role of the file
macros.c is to provide the macro definitions and will not affect any other code or data
segments.
C:\> dir
macros.c greeting.c
-M
Cause the preprocessor to output the makefile rules to describe the dependencies of
each source file. For each source file, the preprocessor outputs one make-rule
whose target is the object file name for that source file and whose dependencies are
all the files needed to generate the object target file. This rule may be a single line
or may be continued with ‘\’-newline if it is long. -M implies -E with makefile
rules.
The program Big.c, which prints the larger of two integers, uses the macro greater (x,y)
which is defined in the file greater.h. A command line output using the -M option can
be used for makefile utilities. For more information on how to use this dependency check
the make utility information in any UNIX utility manual.
C:\> dir
big.c greater.h
-MM
Like -M but the output mentions only the header files described in the #include
“FILE” directive. System header files included with #include <FILE> are
omitted. -MM implies -E with makefile rules.
Example 3-17. Program Big.c
The program Big.c, which prints the larger of two integers, uses the macro greater (x,y)
defined in the file greater.h. The -MM option is used to generate a makefile rule.
Notice that the rule that generates an output file appended by “.o” can be modified to
generate “.cld” which is required for the Motorola Cross C Compiler.
C:\> dir
big.c greater.h
C:\> dir
big.c greater.h makefile text
-nostdinc
Do not search the standard system directories for file inclusions. Only the
directories specified with -I options (and the current directory, if appropriate) are
searched.
Using both -nostdinc and -I- options, all directories from the search path except
those specified can be eliminated.
Example 3-18. Test Program Test.c
A test program, Test.c, is used to test a new version of the function printf() which is
declared in a new header file inc/stdio.h. The directive #include <stdio.h> causes the
program to use stdio.h; however, it would normally find it in the standard search directory,
/usr/local/dsp/include/. Using the -nostdinc option prevents the standard search directory
from being searched and allows the -l option to point to the correct directory.
C:\> dir
inc/ test.c
#include <stdio.h>
main()
{
printf("Hello, there.\n");
}
main()
{
printf("Hello, there.\n");
}
-pedantic
The -pedantic option is used by both the preprocessor and the compiler (see
-pedantic in the section 3.2.2, “Compile Phase Options.” for an explanation of this
option).
-P
Only run the source file through the C preprocessor. This option sends the output to
a file with a .i suffix. This output file does not include # line information in the
output file.
-v
Output preprocessor version information. The primary purpose of this command is
to display the software version. This information is needed when calling the
Motorola DSP helpline for assistance (see Appendix D — Additional Support for
the helpline phone number). Although information pertaining to the internal flags
and switch settings is included in this information, it is not intended for use by the
programmer and may be misleading. This command is also used by the command
program to initiate the verbose mode of operation.
The -v option is selected using the control program G56k. The version numbers for G56k,
MCPP and G56-cc1 are printed. This information is showing the commands that the
control program invokes along with the selected options. In this case it is showing the
default options plus the -v option. However, the user should not invoke these programs
independently but should always use the control program to invoke them.
C:\> dir
foo.c
C:\> g56k -v foo.c
g56k version Motorola Version: g1.11 -- GNU 1.37.1
c:\dsp\bin\mcpp -v -undef -D__Y_MEMORY -trigraphs
-$ -D__STRICT_ANSI__ -D__DSP56K__ -D__OPTIMIZE__
foo.c cca00527.cpp
GNU CPP version 1.37.1
c:\dsp\bin\g56-cc1 cca00527.cpp -ansi
-fstrength-reduce -quiet -dumpbase foo.c -O -version
-o cca00527.asm
GNU C version 1.37.1 Motorola DSP56000/1 Motorola
Version: g1.11 compiled by GNU C version 1.37.1.
default target switches: -mdsp
-mlinv-plus-biv-promotion -mdo-loop-generation
-my-memory -mcall-overhead-reduction -mrep
-mreload-cleanup -mnormalization-reduction
c:\dsp\bin\asm56000 -c -B foo.cln -- cca00527.asm
c:\dsp\bin\dsplnk -c -B a.cld
--c:\dsp\lib\crt056y.cln foo.cln -L
c:\dsp\lib\lib56cy.clb
C:\> dir
a.cld foo.c
-UMACRO
Undefine macro MACRO.
An application program, Test.c, is being tested and some portions of the code need to be
debugged. The flag DEBUG may be turned on or off through the command line with the
-D and -U options respectively. This flag can then be used inside the program to
enable/disable debugging features within the program.
C:\> dir
debug.c
-Wcomment
Warn the user whenever the comment start sequence /* appears within a comment.
Example 3-21. -Wcomment Option
A comment is enclosed with /* and */ and therefore is ignored by the preprocessor. Any
number of leading /*’s are permitted within the comment and will not be reported;
however, a warning message can be enabled by using the -Wcomment option.
C:\> dir
foo.c
-Wtrigraphs
Warn if any trigraphs are encountered (Trigraphs are sequences of three characters
which are replaced by a single character. These trigraph sequences enable the input
of characters that are not defined in the Invariant Code Set as described in ISO
646:1983, which is a subset of the seven-bit ASCII code set.).
-fno-defer-pop
By default, the compiler will try to defer (delay) restoring the stack pointer upon
the return of a function call. The purpose of deferring restoration of the stack
pointer is to reduce code size and decrease execution time; however, the stack
penetration may increase (see the DSP56000 Family Manual for information on
stack overflow).
Examples of function calls that will not incur deferred pops whether or not the
-fno-defer-pop option is specified are:
• calls as function arguments
• calls in conditional expressions
• calls inside a statement expression
-fforce-addr
Force memory address constants to be copied into registers before doing arithmetic
on them. The code generated with this option may be better or it may be worse
depending on the source code. This option forces memory addresses into registers
which, in turn, may be handled as common sub-expressions.
-finline-functions
Attempt to insert all simple functions in-line into their callers. The compiler
heuristically decides which functions are simple enough to merit this form of
integration.
If all calls to a given function are inserted, and the function is declared static, then
the function is no longer needed as a separate function and normally is not output as
a separate function in assembly code.
-fcaller-saves
Enable values to be allocated in registers that will be overwritten by function calls
by emitting extra instructions to save and restore the registers around such calls.
Such allocation is done only when it seems to result in better code than would
otherwise be produced.
-fkeep-inline-functions
Output a separate run-time callable version of the function even if all calls to a
given function are integrated and the function is declared static.
-fwritable-strings
Store string constants in the writable data segment without making them unique.
This is for compatibility with old programs which assume they can write into string
constants. Writing into string constants is poor technique; constants should be
constant.
-fcond-mismatch
Allow conditional expressions with mismatched types in the second and third
arguments. The value of such an expression is void.
-fvolatile
Consider all memory references through pointers to be volatile.
-ffixed-REG
Treat the register named REG as a fixed register; generated code should never refer
to it (except perhaps as a stack or frame pointer). Legal values for REG are:
r1, r2, r3, r4, r5, r7
This flag should be used sparingly as it can have devastating results on the code
generated.
Example 3-22. R4
Warning
C code that utilizes library code can produces
non-deterministic results, as the libraries have been written to
utilize the complete set of registers.
-g
Produce COFF debugging information for Gdb56, the GDB cross debugger for the
DSP56000/DSP56001.
A key feature afforded by the use of the GNU C compiler (G56k) teamed with the
GNU source level debugger (Gdb56) is that the programmer is allowed to generate
optimized code with debug information (select options -g -O) making it possible
for the programmer to debug optimized code directly. Due to the optimizations
performed, it is possible that variables will not be defined (unused variable
elimination), statements may not be executed (dead code elimination), and code
may be executed early (code motion). This is a partial list of the oddities that may
be encountered when debugging optimized code. However, the improved code
performance due to optimization normally out weighs the problems encountered.
Example 3-23. Program Foo.c
The program Foo.c has a bug. In this application the line i *= 2 should be i += 2. In order
to use the symbolic debugger, Gdb56, to locate this problem, the -g option is used when
Foo.c is compiled. This causes the compiler to generate additional information used by the
debugger.
C:\> ls
foo.c
-O
Perform machine dependent and independent optimizations. This is the default
mode of the compiler.
Invoking the compiler with the optimizer may cause compile times to increase and
require more system memory.
Invoking the compiler without the optimizer should be done only when the
programmer requires additional flexibility while debugging code. An example of
such flexibility includes the ability to assign new values to declared c variables.
Additionally, non-optimized code takes register usage clues from the storage class
specifier register, something not done with the optimizer invoked.
Disabling the optimizer is done via -f options listed above.
-m56002
Enables the generation of DSP56002 instructions.
-mno-dsp-optimization
Disables all Motorola optimizer enhancements.
-mno-do-loop-generation
Disable DO instruction usage by optimizer.
-mno-biv-plus-linv-promotion
Disable the promotion of address expressions to address registers within loops.
This optimization transforms array base address plus induction variable
expressions into auto-increment/decrement style memory references.
-mp-mem-switchtable
Forces the compiler to locate all switch tables in P memory.
-mstack-check
Generate extra run-time code to check for run-time stack collision with the heap.
This option causes run-time execution times to increase dramatically.
-mx-memory
Direct the compiler to locate data in the X data memory space. Memory modes
cannot be mixed, i.e. only one of -mx-memory, -my-memory or -ml-memory may
be selected.
Example 3-24. -mx-memory Option
An application is programmed to utilize only the DSP56001 X data memory space and
therefore must be compiled using the -mx-memory option.
C:\> ls
x.c
-my-memory
Direct the compiler to locate data in the Y data memory space. This is the default
memory mode. Memory modes cannot be mixed, i.e. only one of -mx-memory,
-my-memory or -ml-memory may be selected.
-ml-memory
Direct the compiler to locate data in the L data memory space. This has 2 side
effects.
1. A performance increase for 48-bit data code (long, float, and double).
2. This requires that the X and Y memory spaces be evenly populated.
Memory modes cannot be mixed, i.e. only one of -mx-memory, -my-memory or
-ml-memory may be selected.
-pedantic
Issue all the warnings demanded by strict ANSI standard C; reject all programs that
use forbidden extensions.
Without this option, certain GNU extensions and traditional C features are
supported. With this option, they are rejected. Valid ANSI standard C programs
will compile properly with or without this option.
-pedantic does not cause warning messages for use of the alternate keywords
whose names begin and end with “_ _”.
-Q
Direct the compiler to execute in verbose mode.
-S
Compile to DSP56000/1 assembly code with the original C source lines as
comments but do not assemble. The assembly language output is placed into a file
suffixed .asm.
The compiler sees only the calls to setjmp. It cannot know where longjmp will
be called; in fact, a signal handler could call it at any point in the code. As a result,
a warning may be issued even when there is no problem because longjmp cannot
be called at the place which would cause a problem.
A function can return either with or without a value. (Falling off the end of the
function body is considered returning without a value.) For example, this function
would evoke such a warning:
foo (a)
{
if (a > 0)
return a;
}
Spurious warnings can occur because GNU CC does not realize that certain
functions (including ‘abort’ and ‘longjmp’) will never return.
• An expression-statement contains no side effects.
Example 3-27. -W
Extra warning messages are wanted to help find potential problems in a test function,
foo(), which is programmed to return a value only if a > 0.
C:\> dir
foo.c
-Wimplicit
Warn whenever a function is implicitly declared.
Example 3-28. -Wimplicit
The function foo() is declared implicitly in the program foo.c, the -Wimplicit option will
generate a warning message for this situation.
C:\> dir
foo.c
-Wreturn-type
Warn whenever a function is defined with a return-type that defaults to int. Also
warn about any return statement with no return-value in a function whose
return-type is not void.
Example 3-29. -Wreturn-type
The function foo() is declared as a function that should return an integer but in this case
does not return an integer. The -Wreturn-type option generates a warning message in this
situation.
C:\> dir
foo.c
int foo(){}
C:\> dir
a.cld foo.c
-Wunused
Warn whenever a local variable is unused aside from its declaration, whenever a
function is declared static but never defined and whenever a statement computes a
result that is explicitly not used.
Example 3-30. -Wunused
The file foo.c contains an undefined static function, unused local variable, and a dead
statement. The -Wunused option will issue warnings to indicate these situations.
C:\> dir
foo.c
C:\> dir
a.cld foo.c
-Wswitch
Warn whenever a switch statement has an enumeration type of index and lacks a
case for one or more of the named codes of that enumeration. (The presence of a
default label prevents this warning.) case labels outside the enumeration range also
provoke warnings when this option is used.
-Wall
All of the above -W options combined. The remaining -W options described below
are not implied by -Wall because certain kinds of useful macros are almost
impossible to write without causing those warnings.
-Wshadow
Warn whenever a local variable shadows another local variable.
-Wid-clash-LEN
Warn whenever two distinct identifiers match in the first LEN characters. This may
help prepare a program that will compile with certain obsolete compilers.
-Wpointer-arith
Warn about anything that depends on the sizeof a function type or of void. GNU C
assigns these types a size of 1, for convenience in calculations with void * pointers
and pointers to functions.
-Wcast-qual
Warn whenever a pointer is cast so as to remove a type qualifier from the target
type. For example, warn if a const char * is cast to an ordinary char *.
-Wwrite-strings
Give string constants the type const char[LENGTH] so that copying the address of
one into a non-const char * pointer will generate a warning. These warnings help at
compile time to find code that can try to write into a string constant, but only if
const in declarations and prototypes have been used carefully.
-asm string
Pass the argument string directly to Asm56000, the DSP56000/1 assembler.
Example 3-31. Pass a single option to the assembler.
C:\> g56k -asm -v file.c
-c
Compile and/or assemble the source files, suppressing the link phase. This option
generates corresponding output files suffixed “.cln”. Affected input files are
suffixed with “.c” and “.asm”.
Compile the C program foo.c with the crt0 file crt.asm. Notice that the crt0 file crt.asm
should be assembled before use since the option -crt takes .cln file not .asm file.
C:\> dir
crt.asm foo.c
C:\> g56k -c crt.asm
C:\> dir
crt.cln crt.asm foo.c
C:\> g56k -crt crt.cln foo.c
-j string
Pass the argument string directly to dsplnk, the DSP56000/1 linker.
Example 3-34. Pass a single option to the linker.
C:\> g56k -j -v file.c
-lLIBRARY
Search the standard list of directories for a library file named libLIBRARY.clb.
The linker automatically expands LIBRARY from the option command into
libLIBRARY.clb and uses this file as if it had been specified precisely by name.
Compile the source code using the special dsp application library. Searching the standard
list of directories for a library named libdspaps.clb.
C:\> g56k -O file.c -ldspaps
-r CTLFILE
Search the standard list of directories for the memory control file CTLFILE to be
passed as an argument to the DSP56000/1 relocatable linker. This control file will
be used as a table to locate object files sections to be linked. For more detailed
information, see the -R options and the section on “Memory Control File” in the
Motorola Linker/Librarian Reference Manual.
Compile the source code main.c and data.c with the memory configuration described
in the control file map.ctl. Notice that the section main_c of the program Main.c is
located at the memory address p:$3000 and the section of data_c of the data data.c is
located at the memory address y:$5000. See chapter 5 for detailed information on the
in-line assembly code ( _ _ asm( ... ) ).
Example 3-37. -r CTLFILE
C:\> type map.ctl
sectionmain_c p:$3000
section data_c y:$5000
Chapter 4
About g56k
4.1 Introduction
The DSP56000 digital signal processors are designed to execute DSP oriented calculations
as fast as possible. As a by-product, they have an architecture that is somewhat
unconventional for C programming. Because of this architecture, there are characteristics
of the compiler, and the code generated by the compiler, that the programmer must
understand in order to take full advantage of the DSP56KCC programming environment.
All programmers, whether they are familiar with DSP or not, should understand the
DSP56000 family architecture before attempting to program it in C. The following
sections provide important information on data types, storage classes, memory and
register usage, and other topics which will be useful to the DSP56000 application
developer programming in C.
4.2 Identifiers
An identifier is defined as a sequence of letters, digits and underscore characters (‘_’). The
first character must be a letter or underscore. DSP56KCC identifier length limits are listed
in Table 4-1.
Auto unlimited
_ _LINE_ _ YES The line number of the current source line (a decimal
constant).
_ _DATE_ _ YES The compilation date (a character string of the form “Mmm
dd yyyy” e.g., Jul 22 1991).
-0.5000003
-0.5000000
-0.0000003
(Decimal)
0.0000000
0.0000003
0.4999997
0.5000000
0.9999997
Mantissa Value
$BFFFFF
$FFFFFF
$3FFFFF
$7FFFFF
$C00000
$000001
$800000
$000000
$400000
(Hex)
Exponent Reserved
(Decimal)
Exponent Value
2-8192
28192
$7FFFFF
$003FFF
$000000
$004000
(Hex)
Note:
1. No distinct exponents are reserved for plus infinity, minus infinity, Not-a-Number
(IEEE NaN), minus zero or denormalized numbers as is done in IEEE format.
2. All reserved mantissas are illegal since they represent denormalized mantissas.
3. If the 15th bit is set, exponent overflow has occurred.
4. If the 16th bit is set, exponent underflow has occurred.
DSP56KCC
CHARACTERISTIC IEEE FORMAT
FORMAT
DSP56KCC
CHARACTERISTIC IEEE FORMAT
FORMAT
One major difference is the use of affine arithmetic in the IEEE standard versus the use of
saturation arithmetic in the DSP56KCC format. Affine arithmetic gives separate identity
to plus infinity, minus infinity, plus zero and minus zero. In operations involving these
values, finite quantities remain finite and infinite quantities remain infinite. In contrast,
DSP56KCC format gives special identity only to unsigned zero. This format performs
saturation arithmetic such that any result out of the representable floating-point range is
replaced with the closest floating-point representation. Since the dynamic range of this
format is quite large, it is adequate for most applications.
The IEEE floating-point standard provides extensive error handling required by affine
arithmetic, denormalized numbers, signaling Not-a-Numbers (NaNs) and quiet NaNs. It
postpones the introduction of computational errors by using internal signaling and user
traps to process each exception condition. Computational errors will be introduced by the
application program if the calculation is completed instead of aborting the program. The
DSP56KCC format introduces computation errors when an exception occurs in order to
maintain real-time execution. An error flag (L bit in CCR) is set to inform the application
program that an exception has occurred. This bit will remain set until reset by the
application program. The user can then eliminate the exception by algorithm
modifications.
pointers 1 0 0xFFFF
Data ALU
Address ALU
Warning
The mn address modifier registers are not used directly by
DSP56KCC. Some of these registers are implied whenever
any address registers (r0 - r7) are referenced either in C library
or in C. While assembly code can access and use these
registers, the programmer must restore them to their previous
state ($FFFF) before returning control to DSP56KCC. Failing
to do so will cause unpredictable errors when DSP56KCC
accesses these registers.
The programmer is required to preserve any registers that are directly used in in-line and
in out-of-line assembly language code (see Chapter 5, Mixing C and Assembly Language).
Table 4-9 outlines the compiler’s usage of each register.
Register Usage
r0 Frame Pointer
r6 Stack Pointer
Top_Of_Memory
Program Area $FFFF Max
jsr Fabort 31
•
•
•
jsr Fabort 3
Interrupt
Table
jsr Fabort 2
jsr Fabort 1
jmp F_ _start 0
3. Return address — which is pushed on the DSP’s system stack high (ssh) register.
This is the return address to the calling subroutine. The return address is not saved
for subroutines that have been determined to be a leaf. A leaf subroutine is one that
makes no subroutine calls.
4. Local data space. The location of C variables that have a lifetime that extends only
as long as the subroutine is active and that could not be explicitly promoted to
register storage class by the optimizer.
Note: The frame pointer (r0) points to the first element in the local data space.
5. Register spill and compiler temporary space. This area is utilized by the compiler to
store intermediate results and preserve registers.
Note: The Stack Pointer (r6) points to the next available data memory location.
Higher Memory
local data
param 1
param 2
•
•
•
param N
Lower Memory
Figure 4-3. Activation Record
Each subroutine called puts a new copy of the subroutine activation record in the run-time
stack and returning from the subroutine removes the activation record. The run-time stack
is described in Figure 4-4, “Default Data Memory Configuration,” on page 4-12. The
variables shown in the bottom of the “X or Y memory option selected” memory are
controlled by the crt0 file. For example, the F_ _fp_shift variable is typically 23 words but
can be changed by the user or may vary with later releases of this compiler. When the L
memory option is selected, the heap, run-time stack, global/static data and data that is
more than 24 bits in length will occupy one word in L memory i.e., 48-bit memory. 16-bit
and 24-bit data memory will occupy only one word in Y memory. DSIZE is set by the
linker and points to the top address of the global and static data. DSIZE is used by the crt0
file as the default initial stack pointer.
The dynamic run-time stack growth is illustrated in Figure 4-5. In this example, there is
one activation record as execution of the sample C code begins. This activation record is
pushed onto the stack and a new activation record is built with a dynamic link to the old
frame pointer. When the function returns, the function’s activation record is popped and
the original activation record is restored to its original place on the stack.
Heap Heap
TOP_OF_MEMORY
$FFFF Max
F_ _y_size (1 word)
F_ _break (1 word)
F_ _mem_limit (1 word)
Predefined
F_ _stack_safety (1 word) in crt0 48-bit
Ferrno (1 word) memory
16- and 24-bit
F_ _fp_shift (23 words) data memory
F_ _time (1 word)
main()
{
func_1();
}
Sample C code
func_1
activation
record
old frame
pointer
fadd_ba fadd56.asm
fsub_ba fsub56.asm
fmpy_ba fmpy56.asm
fdiv_ba fdiv56.asm
fneg_a fneg56.asm
fcmp_a fcmp56.asm
Source Module
Routine
div_ba idiv56.asm
mod_ba imod56.asm
udiv_ba uidiv56.asm
umod_ba uimod56.asm
lmpy_ba l_mpy56.asm
ldiv_ba l_div56.asm
lmod_ba l_mod56.asm
F_ _uldiv ulongdivmod.c
F_ _ulmod ulongdivmod.c
Note: All run-time libraries provided have been compiled/assembled without the stack
checking option. Thus it is possible to have a run-time stack/heap collision
during execution of library routines.
if (a>b) if (a>b)
{ becomes {
b = a;
func (a); b = a;
} }
else
func (a); func (a);
Note: The function in-lining method can cause program memory requirements to
grow significantly. See Appendix A, Programming Support, for instructions on
disabling library routine in-lining.
Chapter 5
Mixing C and Assembly Language
5.1 Overview
In cases where the DSP56000/DSP56001 programmer requires direct access to the
hardware or greater performance at the inner-loop of an algorithm, C programs can be
mixed with assembly programs. This chapter describes two methods for combining C and
assembly language source code. The first is the in-line method which is a convenient way
to put assembly code into the compiler output via the non-ANSI C directive _ _asm(). The
second is the out-of-line method, a generic method of combining C and assembly
language source files.
Warning
Before mixing C and assembly, read and understand Chapter
4, About G56k, and the DSP56000 Family Manual.
Attempting to write programs for this DSP without knowledge
of the chip and how the compiler utilizes registers, memory,
defines labels, etc. may generate unsatisfactory results.
However, with an understanding of the DSP architecture and
how this implementation of C uses it, programming should be
straightforward.
Labels which begin with a double underline (e.g., _ _asm ()) in this manual have a space
between the double underlines to visually separate them. Do not separate the leading
double underlines with a space when coding them (i.e., code _ _asm () as __asm
()).
where:
1. instruction_template is a string used to describe a sequence of assembly code
instructions that are to be inserted into the compiler output stream. It may specify
arguments, which are listed in output_operands and input_operands. It does this via
a substring called an operand expansion string (OES). An OES starts with a ‘%’.
OES and instruction_template interpretation is described in Section 5.2.1.
2. output_operands are optional operands used to provide specific output
information to the compiler. Each output_operand string is separated by a comma
and should begin with the character ‘=’. As an example, the output_operand “=A”
(cptr) means “the C variable cptr will get its value from this output operand, which
will be in an address register”. See Section 5.2.2 for more details.
3. input_operands are optional operands to provide specific input information to the
compiler. Each input_operand is separated by a comma and may include a C
variable. As an example, the input_operand “A” (cptr) means “the value of this
input operand will be taken from the C variable cptr, and placed in an address
register”. Again, full descriptions of the input and output operands can be found in
Section 5.2.2.
4. reg_save specifies registers that are to be explicitly reserved for the _ _asm ()
statement. The registers to be saved must be named as strings such as ”a” and “b”.
Each register is separated by a comma (see Section 5.2.3 for additional
information) The compiler assumes that all data residing in the reg_save registers
will be invalidated by the _ _ asm () statement.
where:
1. modifier is a single optional character which specifies a particular class of
operand. The available modifiers are ‘j’, ‘e’, ‘h’, ‘k’, ‘g’, ‘i’, ‘f’, ‘p’, and ‘q’.
j—an offset register (nx) associated with the corresponding address registers
(rx). Since the offset register is paired with the address register, the allocated
offset register has the same index as the address register (see Section in Section
5.2.4).
e—a1 or b1, upper word of the destination registers a or b (see Section in
Section 5.2.4).
h—a0 or b0, lower word of the destination registers a or b (see Section in
Section 5.2.4).
k—a2 or b2, extension register of the destination register, a or b (see Section
in Section 5.2.4).
g—Select the 24-bit portion of the 48-bit ALU register (x or y) that is not
occupied by data pointed to by the operand id — e.g., if the operand id points to
x0 then x1 is selected and similarly x1→x0, y0→y1, y1→y0 (see Section and
Section 5-9 in Section 5.2.4).
i—strip the 0 or 1 from the allocated register name i.e., a1→a, a0→a, b1→b,
b0→b (see Section in Section 5.2.4).
f—insert the memory space identifier (x or y) for the memory location (see
Section in Section 5.2.4).
p—generate an immediate 16-bit constant without # sign (see Example in
Section 5.2.4).
q—generate an immediate 24-bit constant without # sign (see Section in
Section 5.2.4).
2. operand_id_number specifies the operand location in the operand descriptor list
(see Section in Section 5.2.4). The operand descriptor list is a concatenation of the
output operands and input operands (see Section 5.2.2). The first operand is labeled
zero and there can be up to 31 more operands in the list. More than one instruction
template can be used if more than 32 operands are needed.
In-line assembly code can also be used to insert a label directly into the compiler output. A
label without any white spaces in the in-line assembly code instruction template will
guarantee that the same template label will be in the compiler output (see Section ). Care
should be taken not to use labels that the C compiler generates. Using the same labels as
the C compiler will cause a duplicate label error (see Section 4.7, "Compiler Naming
Conventions," on page 4-13.)
Example 5-15). In most of cases, the operand is used as both an input and an output
operand (see Example 5-16 and Example 5-17). In these cases the operand should be
described as both. Since output operands should be listed first, the operand id number is
determined when the input operand is declared. The id number will be used as the operand
constraint of the input operand.
Section lists the operand constraints and their related modifiers.
Accumulator “a”,”b”
An example for reg_save is a program performing an IIR filter operation which is based
on the Dr. BuB IIR filter program “iir1.asm”. The program data structure is the same as
the Dr. BuB program and data is passed through the C variable “data”. Pointers “sptr” and
“cptr” are used to point to static variables.
Example 5-1. reg_save
reg_save: This in-line assembly code is converted from the Dr. BuB IIR filter program
using reg_save. This program is based on Y Memory Model, and there are other in-line
assembly features used here for the demonstration of the reg save. Section 5.2.4 may need
to be referenced for the other feature of the in-line assembly.
iir1( int data, int* sptr, int* cptr )
{
_ _asm volatile ( “move %0,a\n\
move %1,r1\n\
move %2,r4\n\
move y:(r1)+,x0\n\
move y:(r4)+,y0\n\
mac x0,y0,a y:(r4)-,y0\n\
move y:(r1),x1\n\
macr x1,y0,a x0,y:(r1)-\n\
move a,y:(r1)” : /* no output */ : “D” (data), “A”
(sptr), “A” (cptr) :
“a”, “x1”, “x0”, “y0”, “r1”, “r4” );
}
Instruction_template: The following are a few examples of how to utilize the instruction
template in in-line assembly code. This feature allows the generation of any valid
assembly instruction and it is probably the most frequently used feature in in-line
assembly coding.
_ _asm(“clr a”); /* clears the register A */
_ _asm(“move #$10, a2”); /* load the register A2 with
the hex value 10 */
_ _asm(“HCR EQU $FFE8”); /* equate the Host Control
Register to
$FFE8 */
A pseudo operand will be used to illustrate use of the OES operand id number. The pseudo
operand functions as an input or output operand. Example 5-3 uses five pseudo operands:
V, W, X, Y and Z each of which is referenced by operand ids 0, 1, 2, 3 and 4, respectively.
The pseudo operands are used as in the OES “%0”, “%1”, “%2”, “%3” and “%4”.
Table 5-3 shows which operands in Example 5-3 are input or output operands.
Instruction template with operand_id: In order to illustrate how to use output or input
operands, pseudo operands V, W, X, Y, and Z are used. The operand_id listed in this
example can be used as part of an instruction_template.
_ _asm(“instruction_template” : V, W, X : Y, Z );
Example 5-3 through Example 5-12 illustrate the use of OES modifier (see Section 5.2.1).
0 V output %0
1 W output %1
2 X output %2
3 Y input %3
4 Z input %4
OES modifier j: The following in-line assembly code is used to generate executable
assembly code. Notice that the actual register selection is totally dependent on the C
compiler but the register selected (r3 in this example) is guaranteed to be related to the C
expression used (in this case cptr, see Section 5.2).
In-line Assembly code:
char *cptr;
_ _asm(“move (%0)+%j0”::“A”(cptr));
Assembly Code Generated:
move (r3)+n3
OES modifier e: The modifier e can be used to generate the assembly code below because
a1 is the upper part of register A.
In-line Assembly code:
int foo;
_ _asm(“move #$ffffff,%e0”:“=D”(foo));
Assembly Code Generated:
move #$ffffff,a1
OES modifier h: The h modifier can be used to generate the following assembly code
because a0 is the lower part of register A.
In-line Assembly code:
int foo;
_ _asm(“move #$ffffff,%h0”:“=D”(foo))
Assembly Code Generated:
move #$ffffff,a0
OES modifier k: The k modifier can be used to generate the following assembly code
because a2 is the extension portion of register A.
In-line Assembly code:
int foo;
_ _asm(“move #$ff,%k0”:“=D” (foo));
Assembly Code Generated:
move #$ff,a2
OES modifier g: Swap the most significant 24-bit portion and the least significant 24-bit
portion of 48-bit registers xand y to allow the OR instruction to operate on an entire 48-bit
register.
/*
* The following assembly code could be generated
(note that the
* optimizer may vary the code actually generated).
move x1,a1
move x0,x1
move a1,x0
*
* The variable foo can be allocated to either x0,
x1, y0, or y1
* by using the operand constraint S. The swap
operation can
* be applied to the register allocated to the
variable foo by
* using the following in-line assembly code.
*
*/
main()
{
int foo;
_ _asm volatile ("move %g0,a1" : : "S" (foo));
_ _asm volatile ("move %0,%g0" : "=S" (foo) : "0"
(foo));
_ _asm volatile ("move a1,%0" : "=S" (foo));
}
OES modifier g: Program bit checker looks to see if any bit in the 48-bit registers x or y is
a one. In this case, Bit Checker looks to see whether the variable foo which is placed in
either the xor yregister is all zeros or contains a one. The result is stored in register a1. If
register a1 is not 0x000000, then foo has one or more bits set to one.
/*
* The variable foo can be allocated to either the x or
y register by using
* the operand constraint S. The OR instruction only
operates on 24-bit
* registers so that to OR the x register with another
register, x1 must
* be ORed separately from x0. The same applies for
the y register.
*/
main()
{
long volatile foo;
OES modifier i: The modifier can be used to generate the following assembly code
because x is a register without a 0 or 1 portion.
In-line Assembly code:
int foo;
_ _asm(“move l:<$0,%i0” : “=R”(foo));
Assembly Code Generated:
move l:<$0, x
OES modifier f: The f modifier can be used to generate the following assembly code.
Assuming that Y memory space is used and the memory location of the variable “foo” is
233, then the desired memory space indicator “y” will be automatically generated by the f
modifier.
In-line Assembly code:
int foo;
_ _asm(“move #$ffffff,%f0”: “=m” (foo));
Assembly Code Generated:
move #$ffffff,Y:233
OES modifier p, and q: This in-line assembly code programs the SCI of DSP56001 by
setting up the SCI registers located at X:$FFF0 and X:$FFF2. You may use modifier p for
any 16-bit value.
#define SCR 0xFFF0
#define SCCR 0xFFF2
#define V_SCR 0x2000
#define V_SCCR 0x013F
main()
{
_ _asm(“movep %0,x:%q1” : : “i” ( V_SCR), “i” (SCR));
_ _asm(“movep %0,x:%q1” : : “i” ( V_SCCR), “i” (SCCR));
}
Assembly Code Generated:
movep #>$002000,x:65520
movep #>$00013f,x:65522
Input Expression / Output Expression: This in-line assembly code uses the pseudo
assembly mnemonic “asm_instruction” and refers to two C expressions:
output_expression and input_expression. This example illustrates how to interpret the
operand constraint (see Section 5.2.2) and operand id (see Section 5.2.1 and Example 5-3).
The example implies that the C expression output_expression is expanded with constraint
D and is an output of the assembly code instruction asm_instruction. Similarly, the C
expression input_expression is expanded with constraint S and used as an input to the
assembly code instruction asm_instruction.
_ _asm(“asm_instruction %1,%0” : “=D”
(output_expression) : “S” (input_expression));
Read-Only Operand: This in-line assembly code uses the pseudo assembly mnemonic
“asm_instruction” and uses input_expression as a read-only operand.
_ _asm(“asm_instruction %0” :: “S” (input_expression));
Write-Only Operand: This in-line assembly code uses the pseudo assembly mnemonic
“asm_instruction” and uses output_expression as a write-only operand.
_ _asm(“asm_instruction %0” :“=D”(output_expression));
Read-Write Operand: An addition is programmed using in-line assembly code and the C
expression result is used as a read-write operand. The variable, foo, is used as a read only
operand. Notice that operand constraint ‘0’ was used to reference the add instructions
second source operand which is also the destination operand (see the
DSP56000/DSP56001 User’s Manual — Appendix A for the syntax of the add
instruction).
int foo, result;
_ _asm(“add %1,%0” : “=D” (result) : “S” (foo), “0”
(result));
Read-Write Operand: The same result will be obtained as in Example 5-16. Notice how
the operand id is changed according to the placement of the C variables.
int foo, result;
_ _asm(“add %2,%0” : “=D” (result) : “0” (result), “S”
(foo));
Multiple Instruction — Multiple-Line: The two lines of in-line assembly code in this
example have the same effect as the one line in Section 5-18. Notice that using two lines
increases the in-line assembly code readability. The line continuation character ‘\’ used at
the end of the in-line assembly codes first line makes this possible.
_ _asm(“move #$709,A\n\
neg A”);
Multiple use of _ _asm(). This example and Example 5-21 are done in-line with the
compiler performing all register allocation and all operands are referenced via C
expressions.This in-line program is a single memory space version of the Dr. BuB IIR
filter program iir1.asm. The method used to write this in-line assembly program is to use
an _ _asm() statement for each assembly language instruction.
int iir1( int data, int* sptr, int* cptr )
{
int state1, state2, coef;
_ _asm ( “move y:(%1)+,%0” : “=R” (state1) : “A” (sptr)
);
_ _asm ( “move y:(%1)+,%0” : “=R” (coef) : “A” (cptr)
);
_ _asm ( “mac %2,%3,%0\ty:(%4)-,%1”
: “=D” (data), “=R” (coef)
: “R” (state1), “1” (coef), “A” (cptr), “0” (data) );
_ _asm ( “move y:(%1),%0” : “=S” (state2) : “A” (sptr)
);
_ _asm ( “macr %1,%2,%0\t%3,y:(%4)-”
: “=D” (data)
: “S” (state2), “R” (coef), “R” (state1), “A” (sptr) );
_ _asm ( “move %0,y:(%1)” : : “D” (data), “A” (sptr) );
return data;
}
Line Separation. This in-line program is functionally identical to Section except that line
separation is used to insert the entire assembly language program (Dr. BuB IIR filter
program, iir1.asm) into a single _ _asm() statement. Notice how much easier it is to read
the program.
int iir1( int data, int* sptr, int* cptr )
{
int state1, state2, coef;
_ _asm ( "\n\
move y:(%4)+,%2\n\
move y:(%5)+,%1\n\
mac %8,%7,%0\ty:(%5)-,%1\n\
move y:(%4),%3\n\
macr %9,%7,%0\t%8,y:(%4)-\n\
move %6,y:(%4)":
“=D” (data), “=R” (coef), “=R” (state1), “=S”
(state2):
“A” (sptr), “A” (cptr), “0” (data), “1”
(coef),“2” (state1),
“3” (state2) );
return data;
}
Instruction Template Label: The following in-line assembly code which generates the
label “foo” uses a return character “\n” to insure that there is no white space in front of the
label.
_ _asm(“\nfoo”);
Program DSP56001 SCI Timer: The SCI timer can be programmed so that a SCI interrupt
service routine is accessed periodically. The following in-line assembly program is based
on the SCI timer described in section 11.2 of the DSP56000/DSP56001 User Manual.
_ _asm(“\nSCR EQU $FFF0”);
_ _asm(“\nSCCR EQU $FFF2”);
_ _asm(“\nIPR EQU $FFFF”);
main()
{
_ _asm( “move #0,r7\n\
movep #$2000,x:SCR\n\
movep #$013f,x:SCCR\n\
movep #$C000,x:IPR\n\
andi #$fc,mr\n\
\nEND jmp END”);
_ _asm (“org p:$001c\n\
move (r7)+\n\
nop”);
}
using the out-of-line assembly technique described in Section 5.4. The listings for ReadX
and ReadY are shown in Example 5-38 in Section 5.4.5.
By using the statement
extern int ValOfX() _ _asm(“ReadX”), ValOfY() _
_asm(“ReadY”);
all C compiler generated function labels for ValOfX() and ValOfY() are replaced by the
labels ReadX and ReadY, respectively.
Example 5-24. Calling Assembly from C
Calling assembly from C. This C program (called test.c) can be used to examine the data
in x or y memory by calling assembly routines “ReadX” or “ReadY”. Notice that the
assembly code for ReadX and ReadY is listed in Section 5-38 of Section 5.4.5.
C:\> type test.c
#include <stdio.h>
extern int ValOfX() _ _asm(“ReadX”), ValOfY() _
_asm(“ReadY”);
unsigned Y[] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
main()
{
printf(“<%x><%x>\n”, ValOfX(100), ValOfY(Y+2));
}
The following two command lines test Section .
C:\> g56k test.c memread.asm
C:\> run56 a.cld
Calling C from assembly. This C subroutine (called C_print.c) uses the standard C library
routine, printf(), to print the input argument as a string.
C:\> type c_print.c
#include <stdio.h>
int C_printf() _ _asm(“print”);
C_printf(char *msg)
{
printf(“%s\n”, msg);
}
Calling C from assembly. This assembly program (called greeting.asm) prints the
message “greeting: hello, there” on the screen. It uses the C subroutine, printf (),
to print this message. Notice that the assembly program name is Fmain because the control
program, G56k, uses the default start-up file crt056y.cln and crt056y.cln uses
Fmain to start up the main program (see Chapter 6 in this manual).
C:\> type greeting.asm
section greeting
org y:
LC0 dc “greeting: hello,there.”,$00
org p:
global Fmain
Fmain move ssh,y:(r6)+
move r1,y:(r6)+
move #LC0,r1
move r1,y:(r6)+
jsr print
move (r6)-
move y:-(r6),r1
move y:-(r6),ssh
rts
endsec
The following two command lines are used to test two programs: c_print.c and
greeting.asm.
C:\> g56k greeting.asm c_print.c
C:\> run56 a.cld
Generate data with assembly language. The data file, sqtbl.asm, is generated in assembly
language and consists of the squares of the numbers 0 - 8. Notice that directives BSC, DC,
DS, DSM and DSR (see Section 6.3 of the Motorola DSP56000 Macro Assembler
Reference Manual) can be used depending on the application.
C:\> type sqtbl.asm
section data
global table
org y:
table dc 0,1,4,9,16,25,36,49,64
endsec
Access data with C. This test program (called test.c) prints the value of 52 on the screen.
C:\> type test.c
#include <stdio.h>
extern int SQUARE[] _ _asm(“table”);
main()
{
printf(“square of %d is %d\n”, 5, SQUARE[5]);
}
The following two command lines for Example 5-28 test the two programs sqtbl.asm and
test.c.
C:\> g56k test.c sqtbl.asm
C:\> run56 a.cld
Generate data with C. Data file, data.c, is generated by a C language program and
contains the coefficients of an average filter which takes the average of the last four input
data.
% cat data.c
/*
* data.c
*/
int Cwaddr[] _ _asm(“waddr”);
int Ccaddr[] _ _asm(“caddr”);
int NTAP _ _asm(“N_1”);
int Cwaddr[4];
int Ccaddr[] = { 0x200000, 0x200000, 0x200000, 0x200000
};
int NTAP = 4;
4-tap FIR filter — Access data with assembly language: This FIR filter reads an input
sample from memory location Y:input and writes the filtered output to memory location
y:output. The input data array is stored in X memory starting at waddr and the FIR
coefficients are stored in Y memory starting at caddr. Notice that the memory space for
waddr and caddr is allocated in the C routine described in Example 5-29.
% cat fir.asm
org p:
move #waddr,r0
move #caddr,r4
move y:N_1,m0
move m0,m4
movep y:input,x:(r0)
clr a x:(r0)+,x0y:(r4)+,y0
rep #n-1
movep a,y:output
end
extending the C language. Users now have complete freedom in specifying both the
run-time and load-time counters for any static or global object. These directives may be
used with either code or data.
This flexibility is achieved by allowing the user to modify any of eight counter strings
maintained by the compiler — two for each memory space: x, y, l and p. When an object is
or defined, the current values of those counter strings are bound to that object.
Syntax for the pragma directive is
#pragma counter_string argument
C function or data storage definition
#pragma counter_string
where
1. The two #pragma statements must encase the entire definition.
2. counter_string in the first #pragma specifies which phase (run or load time) and
memory space is to be affected. It can be x_run, y_run, l_run, p_run, x_load,
y_load, l_load, or p_load. The memory model used in the C compiler should
match the memory model specified by counter_string. Note that the p_run and
p_load counter_strings will always have an effect.
3. The argument in the first #pragma is the string that will be passed as either the
runtime or load-time argument to the org assembler directive. This address, which
is optional, is of the form x:address_value where x is the counter associated with
the x, y, l, or p memory, and address_value is the value to be initially assigned to
that counter. As an example, p:$300 might be used for the counter string p_load.
4. The C function or data storage definition is a declaration that reserves storage.
5. The second counter_string should be the same as the first counter_string and will
return the memory specification to the default setting.
If and only if the memory space of the counter string in the #pragma directive matches the
memory model of the C compiler, then the compiler will insert an assembly org statement
of the form:
(1) org a:runtime_address,b:loadtime_address
or
(2) org a:runtime_address
where“a” is the run time counter and runtime_address is the optional initial value for that
counter, as specified in the “argument” to #pragma.
“b” is the load time counter and loadtime_address is the optional initial value for that
counter, as specified in the “argument” to #pragma.
The following two examples illustrate that the load time counter is optional. See the
section on the ORG statement in the Motorola DSP56000/DSP56001 Assembler Manual
for a complete description and list of options.
Notice that the pragma directive run-time counter string will only affect the run-time
address and the pragma directive load-time counter string will only affect the load-time
address.
As a simple example, assuming that y-memory model (or default memory model) is used
(see Chapter 3 to change the memory model to be used), the following C segment
#pragma y_load x:$100
int coeff[5] = {0x19999a, 0x200000, 0x266666, 0x2ccccd,
0x333333};
#pragma y_load
Let’s assume that the coefficients of the above example is desired to be in the program
space when burning the PROM. Then the following C segment
#pragma y_load p:$100
int coeff[5] = {0x19999a, 0x200000, 0x266666, 0x2ccccd,
0x333333};
#pragma y_load
org y:,p:$100
Fcoeff
dc 1677722
dc 2097152
dc 2516582
dc 2936013
dc 3355443
The above assembly code will be loaded into the P memory space at p:$100 for the PROM
burning, and it should be copied to the L memory space before the actual program is
executed. Manipulating the assembler’s run-time and load-time counters requires a
thorough understanding of the underlying assumptions about memory layout, which are
made by the compiler (see Chapter 6).
Note: Incorrect use of this feature may cause compile-time, link-time and even
run-time errors.
5.4.1.1 Prologue
The first two lines of the prologue make the assembly program visible to the C program so
that the subroutine or function is callable from the C program. In this case, any one of the
following C statements can be used to access out-of-line assembly code.
foo();
x = foo();
x = foo(arg1, arg2, arg3);
The first function call assumes that the C function does not use any arguments and does
not return any values. The second only returns a value which is the same data type as the
variable x. The last call assumes that the C function uses the three arguments: arg1, arg2
and arg3 and then returns the value x.
The rest of the prologue saves the old frame pointer, updates the current frame pointer and
saves the return address. The return address is saved when the JSR instruction pushes the
hardware stack which saves the program counter in the high 16 bits of the system stack
i.e., SSH. This section of the prologue provides bookkeeping for the C compiler activation
record. Detailed information on the structure of the activation record can be found in
Section 4.6.1, "Activation Record," on page 4-10. After this prologue, the R0 register is
the frame pointer and R6 is the stack pointer.
5.4.1.5 Epilogue
The out-of-line template epilogue is the reverse of the prologue. The epilogue restores the
return address and updates the frame pointer, R0. Notice that the stack pointer, R6, should
be decremented before each move operation. In addition, register A is tested to update the
SR register. This testing is a part of the C compiler code generation feature and should be
included (see Section 5.4.5 for optimization).
General Template for Out-of-line Assembly Code: The two sections of this out-of-line
assembly code are mod1 and mod2. The first section implements:
1. mac01(arg) which takes a fractional argument and returns 0.01 times the argument
and
2. mac02(arg) which takes a fractional argument and returns 0.02 times the
argument.
The second section implements mactwo(arg) which takes two fractional arguments and
returns arg1*arg2.
; section mod1:
; int mac01(int arg);
; takes a fractional argument and returns 0.01 *
argument.
; int mac02(int arg);
; takes a fractional argument and returns 0.02 *
argument.
section mod1
global Fmac01
Fmac01
move r0,y:(r6)+ ; prologue
lua (r6)+,r0
move ssh,y:(r6)+
move x1,y:(r6)+ ; save register X1
move y0,y:(r6)+ ; save register Y0
move n0,y:(r6)+ ; save register n0
move #-3,n0
move y:(r0+n0),x1 ; argument
move #0.01,y0 ; operand 0.01
clr a
macr x1,y0,a ; main program: calculates
multiplication of
; x1 and y0
; section mod2
; int mactwo( int arg1, int arg2);
; takes two fractional arguments and returns
arg1 * arg2.
section mod2
global Fmactwo
Fmactwo
move r0,y:(r6)+ ; prologue
lua (r6)+,r0
move ssh,y:(r6)+
move x1,y:(r6)+ ; save register X1
move y0,y:(r6)+ ; save register Y0
move n0,y:(r6)+ ; save register n0
move #-3,n0
move y:(r0+n0),x1 ; the first argument
move #-4,n0
move y:(r0+n0),y0 ; the second argument
clr a
macr x1,y0,a ; main program:
; calculates multiplication of
x1 and y0
The DSP56KCC control program, G56k, should be used to assemble the out-of-line
assembly code. The two sections of this code, mod1 and mod2, can be put in the same file
or in separate files.The following command lines and source files provide a test for the
case where each program is in a separate file.
C:\> type main.c
#include <stdio.h>
int mac01(int), mac02(int), mactwo(int,int);
main()
{
printf(“%x, %x\n”, mac01(0x123456), mactwo(0x123456,
0x0147ae));
printf(“%x, %x\n”, mac02(0x123456), mactwo(0x123456,
0x28f5c));
}
Global Label in Assembly Language. This example shows assembly code that defines a
global integer (named FGinteger) which is normally accessed as Ginteger in the C
environment and FGinteger in the assembly programming environment.
FGinteger dc $0
globalFGinteger
Global Variable Declaration. This is the C code equivalent to Section which defines the
global integer Ginteger.
extern int Ginteger;
Changing a Global Label. This example shows C code that generates a global integer
(Ginteger) which is accessed as Ginteger in both the C environment and the assembly
programming environment.
extern int Ginteger _ _asm(“Ginteger”);
Which will appear in assembly language code as:
Ginteger dc $0
global Ginteger
Run-time stack allocation: This code segment can be inserted in the general template
prologue for out-of-line assembly code. Notice that “size” in the move statement below
should be replaced with the appropriate constant.
move #size,n6; the stack size needed
nop ; wait until n6 is available to operate
on r6
move (r6)+n6 ; allocate the run-time stack for
locals
Referencing the data space can then be accomplished using negative offsets from the stack
pointer or via initialized address registers. There are many alternatives to these methods
but they are all similar.
In the epilogue, an extra step is required to restore the stack pointer — i.e., deallocate the
run-time local stack. This is simply the reverse of the allocation process in the prologue.
Run-time stack deallocation: This code segment can be inserted in the general template
epilogue for out-of-line assembly code. Notice that “size” in the move statement below
should be replaced with the appropriate constant.
move #size,n6; the stack size used before
nop ; wait until n6 is available to operate on r6
move (r6)-n6 ; deallocate the run-time stack
There are many ways to do this, one simple optimization would be to advance the n6 load
instruction in the program to eliminate the nop.
Calling C Routines. The C function, foo(), is called from the following assembly code.
Function foo() is declared as int foo(int, int, int, int);
move x1,y:(r6)+ ; pushing arguments onto
move x0,y:(r6)+; run-time stack in reverse
move b1,y:(r6)+; order
move a1,y:(r6)+
jsr Ffoo ; subroutine call
move #4,n6 ; the stack size restored.
nop
move (r6)-n6 ; restore it.
optimizations can dramatically improve the quality of the application specific library
routines. A careful review of the DSP56000/DSP56001 User’s Manual will be worthwhile
for efficient library development.
Example 5-38. ReadX / ReadY Routines
ReadX / ReadY Routines. This out-of-line assembly program (called memread.asm) reads
the contents of x or y memory and returns the data to the caller. The ReadX subroutine
returns the x memory space contents pointed to by the input argument and the ReadY
subroutine returns the y memory contents.
section memread
org p:
global ReadX ; prologue
ReadX
mover 0,y:(r6)+;
lua (r6)+,r0 ;
move r1,y:(r6)+; save register r1
move #-3,n0 ; the first parameter
move x:(r0+n0),r1 ;
move x:(r1),a; main program
; restore register & epilogue
move y:-(r6),r1 ; Note: r6 decrement can
tst a y:-(r6),r0; be a parallel move in the
rts ; main program.
Chapter 6
Software-Hardware Integration
6.1 Overview
This chapter explains how the run-time environment may be changed and provides
examples of some changes and their effects. The run-time environment provided with the
compiler assumes, as a default, that the simulator is the target execution device. Several
aspects of the default run-time environment must be altered in order to adapt the compiler
to work with a custom hardware configuration.
The files which are alterable are discussed and classified according to effect. Aspects of
the run-time environment such as: bootstrapping, interrupts and memory management are
addressed individually.
The operation of setjmp() and longjmp() is described in Section 6.10 and detailed
implementation information can be obtained from the files provided with DSP56KCC.
Note: Labels which begin with a double underline (e.g., _ _crt0_end) in this manual
have a space between the double underlines to visually separate them. Do not
separate the leading double underlines with a space when coding them (i.e.,
code _ _crt0_end as __crt0_end).
Example 6-1. DSP56000/DSP56001 Operation Mode Change
Mode 2 has a reset vector of $E000 which must contain a jmp to the C program bootstrap
code. Adding the following code segment to the crt0 file will change the bootstrap mode
to Mode2.
section mode2_reset
org p:$e000
jmp F_ _start; jump to the C start-up program.
endsec
Hardware was designed to have a 256 byte ROM monitor located in the program memory
space starting at $0000 and ending at $FF. Program RAM starts at location p:$100. The
following changes to the crt0 file will change the beginning location of the C bootstrap
code to the first available RAM location (p:$100). The DS statement allocates program
space starting at p:$0000 and lets the ROM be located at address p:$0000. The org
statement places the C bootstrap code at memory location p:$100.
DSP56KCC provides three different memory models to minimize these differences. They
are the x memory model, y memory model and l memory model. Selection of the
appropriate memory model is made using the -m option of the control program, G56k (see
Section 3.2.2, "Compile Phase Options," on page 3-20). The memory configuration for
each memory model is discussed later in this section. The crt0 file can be modified to
configure memory for any hardware design.
There are four data segments in the C programming environment. These are the program
segment, global-static data segment, stack data segment and heap data segment. The
program segment is located in program memory. The three data segments can be located
in x memory, y memory or l memory space (which is a concatenation of x and y memory)
depending on the memory model used.
TOP_OF_MEMORY X: Y: L:
Stack Pointer
Stack
_ _y_size
Stack Stack
DSIZE
As indicated in Section 5.1, "Overview," on page 5-1, global and static data reside at the
bottom of the available data memory and the top address of the global and static data area,
which is called DSIZE, is set by the linker. The constant TOP_OF_MEMORY is defined
to indicate the top of the entire available memory.
The two data segments, heap and stack, are located as shown Section 5.1, "Overview," on
page 5-1. The stack is located so that it can grow up and the heap is located so that it can
grow down. There are two locations used to indicate the initial values for the heap pointer
and stack pointer. These locations are _ _y_size and _ _break and are initialized in the
crt0 file as DSIZE and TOP_OF_MEMORY, respectively.
In summary, two variables _ _y_size and _ _break and the constant TOP_OF_MEMORY
are used to configure the data segment. The program segment is configured using the org
statement in the crt0 file. The variable, _ _y_size, should be initialized with the initial
stack pointer and the variable, _ _break, should be initialized with the initial heap pointer.
Warning
The stack and heap regions must not contain on-chip
peripheral memory or the static or global data regions. Also,
no region may be reconfigured after the C main function is
called. Variables _ _y_size and _ _break should not be altered
by an arbitrary function since they are utilized by system level
libraries such as malloc and free.
Example 6-3. Fast Stack
In this example, the stack is required to reside in an 8k SRAM starting at L:$4000. The
following program reserves the stack space using org and ds statements and sets the initial
stack pointer to the SRAM stack area.
Add this section to the crt0 file:
section fast_ram
org L:$4000
ds $2000
endsec
Change the following line of C bootstrap code in the crt0 file:
move y:F_ _y_size,r6
to:
move #$4000,r6
The heap is required to reside in an 8k SRAM starting at L:$4000. The following program
reserves the heap space using org and ds statements and sets the initial heap pointer to the
SRAM heap area.
Add this section to the crt0 file:
section fast_ram
org L:$4000
ds $2000
endsec
Change the following line of C bootstrap code in the crt0 file:
TOP_OF_MEMORY equ $ffbe
to:
TOP_OF_MEMORY equ $5fff
Sometimes hardware configurations map more than one memory space into a single
physical memory. Other implementations partially populate various address spaces
leaving holes. Some may have different regions with fast memory and slow memory. All
of these special cases can usually be handled by modifying the crt0 file.
When multiple memory spaces are mapped into a single physical memory, the memory
must be partitioned among the memory spaces. A way to restrict the linker from
overlapping these memory spaces is needed. For example, suppose that both the Y and P
spaces are mapped into the same 64k physical RAM and need to be partitioned with the
low 48k for program memory and the high 16k for data memory.
The linker can be restricted from allocating across holes in physical memory by using the
org and ds directives to confiscate those addresses. Note that the linker may not
automatically take advantage of memory which is present between holes. It may be
required to manually place assembly language data structures to utilize this memory.
The crt0 file contains code to initialize these interrupt vectors. By default, all vectors are
initialized with the instruction jsr Fabort. The first element of the vector table, which
is the hardware RESET interrupt, is initialized with the instruction jmp F_ _start. The
purpose of the C function abort(), which is labeled as Fabort in the assembly
environment, is to stop program execution and leave the chip in the STOP mode. The F_
_start label is the program address of the C program bootstrap code which calls the C
main() function after execution.
Interrupt vectors that are to be used must be reprogrammed to point to the interrupt service
routines instead of the abort() function. Initialization of the interrupt vectors in the crt0
file reduces the size of the resulting application program and may increase its speed.
The following crt0 code segment (called section reset) is the default interrupt vector
table initialization.
section reset
org p:$0
jmp F_start
org p:$2
dup 31
jsr Fabort
endm
endsec
The interrupt vector table can be changed to point to user-provided interrupt service
routines instead of the abort() routine in this portion of crt0. Example 6-5 illustrates how
to initialize pointers to these user-provided interrupt service routines.
Example 6-5. User-defined Interrupt Vector Table
Assume the hardware supports all interrupts and each interrupt service routine is located at
the address labeled interruptXX (where XX is the value of the interrupt vector). The
following code initializes the interrupt vector table. Each service routine starting at
interruptXX can be programmed in assembly language as shown in Section .
section reset
org p:$0
jmp F_start
jsr interrupt02
jsr interrupt04
jsr interrupt06
jsr interrupt08
…
jsr interrupt3e
endsec
Interrupt Service Routine: This service routine updates the global variable F_ _time at
each SCI timer interrupt. The SCI timer period can be set by programming the SCCR (see
Section 11.2.2.3 of the DSP56000/DSP56001 User’s Manual). This program is based on
the y memory model and the SCI interface control registers (X:FFF0 and X:FFF2) should
be initialized for proper SCI timer operation (see Section 11.2 in the
DSP56000/DSP56001 User’s Manual for detailed information on the SCI operation).
section interrupt
org p:
global interrupt1c
interrupt1c
move (r6)+ ; secure the stack pointer
; (refer to section 5.4.1.4)
move r2,y:(r6) ; save the r2 register
move y:F_ _time,r2 ; retrieve the variable _ _time
move (r2)+ ; increment the variable
move r2,y:F_ _time ; save the result
move y:(r6)-,r2 ; restore the r2 register
rti ; return from interrupt service
endsec
Notice that fast interrupts can also be programmed by modifying the crt0 file in the same
way as for the long interrupts (see Chapter 8 of the DSP56000/DSP56001 User’s Manual
for more information on fast and long interrupts).)
6.9 Signal()
The signal() function is passed two arguments:
1. A signal number — On the DSP56000 family processor, the signal number
corresponds directly to the interrupt vector address. Notice that the signal number
is not an integer sequence but is an even number.
2. A function pointer — The function pointer passed is assumed to belong to a C
function either generated by this compiler or by assembly code.
Signal() performs the following three steps when binding the specified signal number and
function:
1. The instruction jsr F_ _c_sig_goto_dispatch+<signal number> is placed into the
interrupt table location specified by the signal number.
2. The function pointer passed is entered into the table _ _c_sig_handlers, which is
used to store pointers to C signal handlers, indexed by the signal number.
3. The old signal handler address is returned.
Once the signal number and specified function are bound, the instruction
jsrF_ _c_sig_goto_dispatch+<signal number>
is executed upon receiving the interrupt, where the F_ _c_sig_goto_dispatch variable is
the starting address of a table of
jsrF_ _c_sig_dispatch
instructions and each jsr instruction points to an interrupt service routine. The
pseudo-function _ _c_sig_dispatch() is used to calculate the actual C interrupt routine.
All registers are saved before the _ _c_sig_dispatch() function calls the C signal handler.
Pseudo function _ _c_sig_dispatch() then calculates the signal number using the return
address program counter of the ssh. Since the signal number is the same as the interrupt
vector address, each entry of the _ _c_sig_goto_dispatch table corresponds to an interrupt
vector. The pseudo function uses the signal number to fetch the actual C signal handler
from the _ _c_sig_handlers table which is the C function pointer table.
Once the C signal handler is fetched from the _ _c_sig_handler table, its entry is replaced
with the default signal handler SIG_DFL. This replacement is in compliance with the
ANSI standard and forces the next signal service to abort. In most situations, this feature is
not needed because any given interrupt will always invoke the same interrupt service
routine. Resetting signal() after each C service routine or modifying this file so that it does
not replace the table entry with SIG_DFL will change the interrupt service scheme.
Modification of the signal file is only recommended when optimization of the service time
is critical to the application.
Upon return from the C signal handler, all the registers are restored. Finally, the rti
instruction is executed to return to the code that was executing when the interrupt
occurred. Notice two factors in this scheme,
1. all registers are saved and restored before and after the C signal handler and
2. the rti instruction is executed by the _ _c_sig_dispatch() function.
Warning
The signal handler must not contain the rti instruction at the
end of the program regardless which language is used to
program the interrupt. The signal handler does not need to
save or restore any context or registers. The function _
_c_sig_dispatch() will not act like a normal C function
because it never returns to its caller. Instead, it will return to
the code that was executing when the interrupt happened by
executing the rti instruction.
Assembly language interrupt handlers can coexist with C signal handlers. The code in the
signal file will not alter any interrupt vector except the one specified by the signal number
passed to the signal() function (see the first of the three steps above). The C signal
interface could be used with an assembly routine but would be unnecessarily slow. To use
an assembly language interrupt handler, alter the vector (e.g., interrupt 08) with a jsr to it
(e.g., jsr interrupt 08)or use a fast interrupt routine.
6.9.1 Raise()
The raise() function is used to simulate an interrupt. The code in raise() simply calls the
entry in _ _c_sig_goto_dispatch that is matched to the interrupt vector specified by the
signal number passed.
The ANSI standard signal handlers SIG_DFL, SIG_ERR and SIG_IGN are
implemented by the hand-coded functions _ _sig_dfl(), _ _sig_err() and _ _sig_ign(),
respectively.
1. SIG_DFL notes that the interrupt happened by incrementing _ _sig_drop_count
and then returns.
2. SIG_ERR calls abort() and never returns.
3. SIG_IGN returns without any effect (i.e., ignore).
The mechanisms used to implement the C signal interface may be altered to fit a particular
hardware application. Any series of alterations applied to the signal file must leave an
implementation conforming to the ANSI standard X3.159 for C. Alteration of the signal
file is done at one’s own risk and is not generally advised. Again, the contents of the signal
file must remain consistent with the include file signal.h.
messages between the DSP and the host, with the host eventually returning a message
containing the completion status of the original request. The file dsp/include/ioprim.h is
included by both the host-side I/O driver, and the standard I/O library code; it defines the
constant definitions used in the aforementioned messages. A typical series of events and
messages that comprise a standard I/O call might look like this:
1. The application running on the DSP makes a call to fopen ().
2. The library code in lib56c[xyl].clb calls __send (), with a buffer that contains the
code DSP_OPEN, the flags, the mode, and the string length of the path.
3. The host receives the message into the buffer hio_receive, sets its valid flag, and
calls process_pending_host_io (). The state machine inside
process_pending_host_io () notes that it is now in the middle of an open file
request, records the values from the first message, and then returns. At this point,
code written by the application developer must check the valid flag of the buffer
hio_send; in this case, the buffer hio_send has not been marked valid.
4. The library code in lib56c[xyl].clb calls __send () again, this time sending the path.
5. Again, the host receives the message into the buffer hio_receive, and calls
process_pending_host_io () after setting the buffer’s valid flag.
6. process_pending_host_io () uses the information from the two messages to
perform the file open. It then builds an operation status message, places it in the
buffer hio_send, and sets that buffer’s valid flag. process_pending_host_io ()
resets its internal state and returns.
7. The host checks the buffer valid flag on hio_send, sees that it is true, and transmits
the message to the DSP.
8. The library code running on the DSP finishes the fopen () call and returns.
On the host side of the interface, the application writer must write the code that exchanges
data with the DSP, the code that calls process_pending_host_io (), and the code that
checks buffer valid flags. On the DSP side of the interface, the application writer must
write the routines __send () and __receive (). The communication between the DSP and
the host is always initiated by the DSP and always follows a predetermined pattern,
depending on the initial message. Because this communication is so simple, the code that
calls process_pending_host_io () can also be quite simple.
Example 6-7 is a hypothetical non-reentrant interrupt handler written in C. It uses two
functions, peek () and poke (), to access some sort of hardware communication device
connected to the DSP. The functions peek () and poke () aren’t provided; they’re simply
an abstraction for host-side hardware access. This code assumes that the DSP sends the
size of a message directly before sending a message. CHECK_BUFFER_SIZE is a macro
defined in dsp/etc/hostio.h. It should always be used to ensure that the buffer hio_receive
is large enough to handle the incoming message. Finally, this example assumes that the
function signal () is available to register interrupt handlers.
This code doesn’t have to be implemented in an interrupt driven manner; periodic polling
could be used as well. The critical issues are that the communication must be reliable, and
that the system must not deadlock; the latter is easy to ensure, given the simple nature of
the communication protocol.
Example 6-7. Sample Host-Side Glue Code
void interrupt_driven_io ( )
{
int i;
Header Files
In general, header files may be included in any order and as often as desired with no
negative side effects. The one exception occurs when including <assert.h>. The
definition of the assert macro depends on the definition of the macro NDEBUG.
The contents of the standard header files provided are exactly as described by the ANSI
document X3.159-1989 dated December 14, 1989.
toupper — — — fmod — —
When it is necessary to disable this feature, possibly for debugging or decreasing program
size, simply do one of the following.
1. Add the following line to each C module (or once to a common header file)
#undef ROUTINE_NAME
where ROUTINE_NAME is the library routine that must be
forced out-of-line. For example, to force the library routine
ceil out-of-line:
#undef ceil
2. Use the command-line option -U, see Chapter 3, Control Program Options. This
will force the library routine to be called for this compilation. If the code is
re-compiled, the -U option must be used again.
C:\> g56k -Uceil file.c
3. Do not include the header file.
Function Description
cos Cosine.
Function Description
fgetpos Retrieve the current value of the file position indicator of a stream.
getchar Read a character from the stream stdin (this may be a macro).
Function Description
memmove Copy from one area to another (source and destination may overlap).
Function Description
rewind Reset the file position indicator of a stream to the beginning of the file on the disk.
setjmp Save a reference of the current calling environment for later use by longjmp.
setvbuf Associate a buffer with a stream, while also specifying the buffering mode and buffer size.
sin Sine.
strcspn Compute the length of the prefix of a string not contained in a second string.
Function Description
strpbrk Find the first occurrence of a character from one string in another.
strspn Compute the length of the prefix of a string contained in a second string.
tan Tangent.
tmpfile Create a temporary binary file on the disk to be referenced via a stream.
void main()
{
printf(“-- make abort call --\n”);
abort();
printf(“this line not reached\n”);
}
void main()
{
int neg = -709;
printf("-- abs(%d) == %d --\n", neg,abs( neg ));
}
void main()
{
printf("atan2(7.09,7.09) == %f\n", atan2(7.09,7.09));
printf("atan2(-7.09,7.09) == %f\n", atan2(-7.09,7.09));
printf("atan2(7.09,-7.09) == %f\n", atan2(7.09,-7.09));
printf("atan2(-7.09,-7.09) == %f\n",atan2(-7.09,-7.09));
}
void main()
{
atexit( func_1 );
atexit( func_2 );
printf( "-- testing atexit --\n" );
}
void main()
{
printf( "atof( \"7.09\" ) == %f\n", atof( "7.09" ) );
}
void main()
{
printf( "atoi( \"709\" ) == %d\n", atoi( "709" ) );
}
void main()
{
printf( "atol( \"709\" ) == %ld\n", atol( "709" ) );
}
char* stuff[6] =
{
"bald", "driving", "feet”, "flintstone", "fred", "on"
};
void main()
{
char* p;
char* key = "bald";
p = bsearch( &key, stuff, 6, sizeof(char*), compare );
if ( p )
{
printf( "YES, fred flintstone drives on bald feet\n" );
}
else
{
printf( "NO, sam the butcher brings alice the meat\n" );
}
}
int* iptr;
if ( iptr != NULL )
{
/* check first entry for zero initialization */
if ( *iptr != 0 )
{
printf( "error: calloc failed to initialize\n" );
}
else
{
printf( "success: calloc ok\n" );
}
}
else
{
printf( "error: calloc failed\n" );
}
}
void main()
{
printf( "ceil( 7.09 ) == %f\n", ceil( 7.09 ) );
}
void main ()
{
FILE *stream = tmpfile (); /* initially empty. */
clearerr ( stream );
printf ( “end-of-file indicator is: %d\n”, feof ( stream ));
}
void main()
{
printf( "cos( 45.0 ) == %f\n", cos( 45.0 ) );
}
void main()
{
printf( "cosh( 3.1415 ) == %f\n", cosh( 3.1415 ) );
}
void main()
{
printf( "-- exit test --\n" );
exit ( 0 );/* return with 0 status */
printf( "Error: exit made this unreachable\n" );
}
void main()
{
printf( "exp( 7.09 ) == %f\n", exp( 7.09 ) );
}
void main()
{
double pos, neg = -7.09;
void main()
{
fprintf ( stdout, “see me second” );
fprintf ( stderr, “see me first\n” );
fclose ( stdout );
}
Note that stdout is by default line buffered, while stderr is not. The
call to fclose
causes the pending output on stdout to be flushed.
void main()
{
FILE *somefile = fopen ( “somefile”, “rb+” );
(void) fseek ( somefile, 0L, SEEK_END );
(void) fgetc ( somefile );
fprintf ( stdout, “are we at the file’s end? %s\n”,
feof ( somefile ) ? “yes” : “no” );
}
prints to standard output:
are we at the file’s end? yes
void main()
{
fprintf ( stdout, “see me second” );
fprintf ( stderr, “see me first\n” );
fflush ( stdout );
}
Note that stdout is by default line buffered, while stderr is not. The
call to fflush
causes the pending output on stdout to be flushed.
will echo all characters from standard input to standard output until
the input is
exhausted.
void main ()
{
FILE *preexisting = fopen ( “already.here”, “r” );
fpos_t pos;
void main ()
{
FILE *disk_file = fopen ( “newfile”, “a+” );
char one_line[64];
will open a new file on the disk named “newfile”. Two lines will be
written to the new file, and the first line will be read back using
fgets. The retrieved line is then printed to standard output as follows:
void main()
{
printf( "floor( 7.09 ) == %f\n", floor( 7.09 ) );
}
prints to standard output:
floor( 7.09 ) == 7.000000
void main()
{
printf( "fmod( -10.0, 3.0 ) == %f\n", fmod( -10.0, 3.0 ) );
}
Argument Stream
“a” text type, append only (write after end of current file),
“ab” binary type, append only (write after end of current file),
“w+” text type, read and write (any pre-existing file is destroyed),
“a+” text type, append only (read/write after end of current file),
“wb+” binary type, read and write (any pre-existing file is destroyed),
“ab+” binary type, append only (read/write after end of current file).
Note: Opening a file that does not exist will fail if r is the first character in the mode
string. When opened, the stream is initially line buffered.
void main ()
{
FILE *stream = fopen ( “file.new”, “w” );
char data[64];
verify this
hello world
void main ()
{
fputc ( (int) ‘S’, stdout );
fputc ( (int) ‘h’, stdout );
fputc ( (int) ‘a’, stdout );
fputc ( (int) ‘d’, stdout );
fputc ( (int) ‘r’, stdout );
fputc ( (int) ‘a’, stdout );
fputc ( (int) ‘c’, stdout );
fputc ( (int) ‘k’, stdout );
fputc ( (int) ‘\n’, stdout );
}
Shadrack
void main ()
{
fputs ( “hand me down pumas\n”, stdout );
}
#include <stdio.h>
void main ()
{
FILE *booty = fopen ( “professor”, “r” );
char buffer[64];
void main()
{
char* alloc;
if ( ( alloc = (char*) malloc( 709 ) ) == NULL )
{
printf( "malloc error\n" );
exit ( -1 );
}
void main ()
{
freopen ( “diskfile”, “w”, stdout );
printf ( “hello world\n” );
}
void main()
{
int exp;
double mant;
Conversion
Description
Specifyer
‘i’ match a signed integer, whose base is determined in the same manner as a C integer constant.
‘e’,’f’,’g’ match a floating-point number. ( ‘E’,’F’ and ’G’ are also valid).
‘[‘ match a non-empty sequence of characters from a set of expected characters, which are
bounded by a following ‘]’.
Conversion
Description
Specifyer
‘c’ match a sequence of characters, as specified by the field width. As a default, scan only one
character.
‘n’ don’t match anything, just store the number of characters read from the input stream during this
call to fscanf.
fscanf returns EOF if an input failure is detected before any conversions take place.
Otherwise it returns the number of assignments made. Note that an optional assignment
suppression character ‘*’ may follow the initial ‘%’. This character will cause fscanf to
discard the converted value without advancing along the list of object pointers.
Refer to the following sections for more information:
• Section A.4.86, “scanf—Read formatted input from standard input,” on page A-91
• Section A.4.96, “sscanf—Read formatted input from a string,” on page A-98
Example A-37. fscanf
(a) The following program will, assuming that the input pending on standard input is “my
98”, store the three characters ‘m’, ‘y’, ‘\0’ will be stored in word[], and 98 will be stored
in number.
#include <stdio.h>
void main ()
{
char word[8];
int number;
fscanf ( stdin, “ %s %d”, word, & number );
}
(b) The following program will, assuming that the input pending on
standard input is “yall come”, store the following five characters in
the array word: ‘y’, ‘a’, ‘l’, ‘l’, ‘\0’.
#include <stdio.h>
void main ()
{
char word[8];
fscanf ( stdin, “%[lay]”, word );
}
The following function will read the last character in a text file specified by the parameter
name.
#include <stdio.h>
#include <stdio.h>
void main ()
{
FILE *preexisting = fopen ( “already.here”, “r” );
fpos_t pos;
main ()
{
FILE *stream = fopen ( “file.abc”, “r” );
long int beginning = ftell ( stream );
char send;
main ()
{
char message[] = “hand me down pumas”;
will write the message “hand me down pumas” onto standard output.
void main ()
{
char value = (char) getc ( stdin );
will echo all characters from standard input to standard output until
the input is exhausted.
void main ()
{
char value = (char) getchar ();
will echo all characters from standard input to standard output until
the input is exhausted.
void main ()
{
char line_buffer[BUFSIZ];
if ( ! ( isalnum( ’@’ ) ) )
{
printf( "@ -- neither alpha nor numeric\n" );
}
}
prints to standard output:
c, 1 -- alpha and numeric
@ -- neither alpha nor numeric
void main()
{
/* check the "beep" character */
if ( ( iscntrl( 0x07 ) ) )
{
printf( "\"beep\" (0x07) -- control character\n" );
}
if ( ! ( iscntrl( ’@’ ) ) )
{
printf( "@ -- not control character\n" );
}
}
void main()
{
if ( ( isdigit( ’1’ ) ) )
{
printf( "1 -- is a decimal character\n" );
}
if ( ! ( isdigit( ’f’ ) ) )
{
printf( "f -- not a decimal character\n" );
}
}
prints to standard output:
1 -- is a decimal character
f -- not a decimal character
if ( ( isgraph( ’f’ ) ) )
{
printf( "f -- \"graph\" character\n" );
}
}
void main()
{
if ( ( islower( ’a’ ) ) )
{
printf( "a -- lower case character\n" );
}
if ( ! ( islower( ’F’ ) ) )
{
printf( "F -- not a lower case character\n" );
}
}
prints to standard output:
a -- lower case character
F -- not a lower case character
void main()
{
if ( ( ispunct( ’ ’ ) ) )
{
printf( "space -- \"print\" character\n" );
}
if ( ! ( ispunct( ’\t’ ) ) )
{
printf( "tab -- not \"print\" character\n" );
}
}
void main()
{
if ( ( isspace( ’ ’ ) ) )
{
printf( "space -- white-space character\n" );
}
if ( ! ( isspace( ’@’ ) ) )
{
printf( "@ -- not white-space character\n" );
}
}
prints to standard output:
space -- white-space character
@ -- not white-space character
if ( ! ( isxdigit ( ’G’ ) ) )
{
printf( "G -- not a hexadecimal character\n" );
}
}
prints to standard output:
F -- hexadecimal character
G -- not a hexadecimal character
void main()
{
long int j = -19089709l;
void main()
{
printf( "log( 7.09 ) == %f\n", log( 7.09 ) );
}
void main()
{
printf( "log10( 7.09 ) == %f\n", log10( 7.09 ) );
}
jmp_buf env;
main()
{
if ( setjmp( env ) != 0 )
{
printf( "-- longjmp has been called --\n" );
exit( 1 );
}
printf( "-- setjmp called --\n" );
func();
}
void main()
{
char *char_array;
Note: The DSP56000/DSP56001 does not provide byte addressing, thus characters
always require an entire word of memory each. One way to better utilize data
memory (with a run-time cost) is to combine the ANSI data type wchar_t and
the special ANSI multibyte and wide character library routines.
Example A-63. mblem
#include <stdio.h>
#include <stdlib.h>
void main()
{
int max = MB_CUR_MAX;
char* strnull = gstr;
char* str1 = "709";
Note: The DSP56000/DSP56001 does not provide byte addressing, thus characters
always require an entire word of memory each. One way to better utilize data
memory (with a run-time cost) is to combine the ANSI data type wchar_t and
the special ANSI multibyte and wide character library routines.
wchar_t warray[10];
void main()
{
char array = "abcdedgh";
char* ptr = array;
int convert;
Note: The DSP56000/DSP56001 does not provide byte addressing, thus characters
always require an entire word of memory each. One way to better utilize data
memory (with a run-time cost) is to combine the ANSI data type wchar_t and
the special ANSI multibyte and wide character library routines.
void main()
{
wchar_t wide = 0;
char* mbstr = "abcde";
int convert;
void main()
{
char*string = "fred flintstone driving on bald feet";
char*result;
struct test
{
char cartoon[20];
int value;
}g1 = { "flintstones", 709 },
g2 = { "flintstones", 709 },
g3 = { "jetsons", 709 };
void main()
{
if ( memcmp( &g1, &g2, sizeof( struct test ) ) != 0 )
{
printf( "error: flintstones differ\n" );
}
else
{
printf( "-- flintstones are flintstones --\n" );
}
if ( memcmp( &g1, &g3, sizeof( struct test ) ) != 0 )
{
printf( "-- flintstones are not jetsons --\n" );
}
else
{
printf( "error: flintstones are NOT jetsons\n" );
}
}
prints to standard output:
-- flintstones are flintstones --
-- flintstones are not jetsons --
struct test
{
char cartoon[20];
int value;
}g1, g2 = { "flintstones", 709 };
void main()
{
memcpy( &g1, &g2, sizeof( struct test ) );
printf( "-- I watch the %s --\n", g1.cartoon );
}
struct test
{
char cartoon[20];
int value;
} g1, g2 = {"flintstones", 709 };
void main()
{
memmove( &g1, &g2, sizeof( struct test ) );
printf( "-- I watch the %s --\n", g1.cartoon );
}
prints to standard output:
-- I watch the flintstones --
Note: Due to the word orientation of the DSP56000/DSP56001, the l memory model
version of memset may not act as expected when attempting to initialize double
size elements (the x memory portion is unaffected).
Example A-70. memset
#include <stdio.h>
#include <string.h>
structtest
{
charcartoon[20];
int value;
}
void main()
{
struct test local;
/* random check */
if ( local.cartoon[7] != 9 )
{
printf( "error: memset busted\n" );
}
else
{
printf( "-- memset OK --\n" );
}
}
void main()
{
double result;
void main()
{
printf( "-- pow( 2.0, 2.0 ) == %f --\n", pow( 2.0, 2.0 ) );
}
Flag Description
- Left justify the result within the field. The default is right justified.
+ The result of a signed conversion will always have a sign (+ or -). The default case
provides only for -.
space If the first character of a signed conversion is not a sign, or if a signed conversion
results in no characters, a space character will be prefixed to the result. If the space
and the + flags both appear, the space flag is ignored. The default mode is no
space.
Each conversion takes place in character fields. The minimum size of the field can be
specified with the field width. If the converted result contains fewer characters than
specified by field width, the result will be left padded with spaces by default (see flags
above). The field width takes the form of a decimal integer or an asterisk ‘*’. When the
field width is an asterisk, the value is to be taken from an integer argument that precedes
the argument to be converted.
Precision specifies the minimum number of digits to appear for the d, i, o, u, x, X
conversions, the number of digits appear after the decimal point character for e, E, and f
conversions, the maximum number of significant digits for the g and G conversions, or the
maximum number of characters to be written from a string in the s conversion. The
precision takes the form of a ‘.’ followed by ‘*’, or by an optional decimal integer; if only
the period is specified, the precision is taken to be zero. If precision appears with any other
conversion character, the behavior is undefined.
Size specifies the argument size expected. There are three size specifiers defined by ANSI.
The h specifies that the argument for the conversion characters d, i, o, u, x, or X will be
unsigned short. The l specifies that the argument for the conversion characters d, i, o, u, x,
or X will be long integer. The L specifies that the argument for the conversion characters
e, E, f, g, or G will be long double.
d, i The int argument is printed as a signed decimal number. The precision specifies
the minimum number of digits to appear; if the value being printed can be
represented in fewer digits, it is expanded with leading zeros. The default precision
is 1. The result of printing a zero with precision zero is no characters (this is
independent of padding specified by field width).
f The double argument is printed out in decimal notation of the form [-]ddd.ddd,
where precision specifies the number of digits to follow the decimal point. The
default precision 6. When precision is 0 and the # flag is not specified, no decimal
point character will be printed. A decimal digit will always follow at least one digit.
The value printed is rounded to the appropriate number of digits.
e, E The double argument is printed out in the form [-] d.ddde±dd, where precision
specifies the number of digits to follow the decimal point. The default precision 6.
When precision is 0 and the # flag is not specified, no decimal point character will
be printed. A decimal digit will always follow at least one digit. The exponent
always contains at least two digits.
g, G The double argument is printed in the f, e, or E form. The f form is used unless
the exponent to be printed is less than -4 or greater than the precision. If precision
is zero, the printed value consists of no characters (this is independent of padding
specified by field width). Trailing zeros are removed from the fractional portion of
the result; a decimal point character is printed only if it is followed by a digit.
p The argument is a pointer to the void data type ( (void*) ). The value of the of the
pointer is printed out as a hexadecimal digit.
% Print the percent character, %. Note that the complete specifier is %%.
Shadrack
void main()
{
while ( *str != ’\0’ )
{
putchar ( *str++ );
}
}
void main()
{
puts ( str );
}
char* stuff[] = {
"fred", "flintstone", "driving", "bald", "on", "feet"
};
main()
{
int i;
printf( "\n" );
}
void main()
{
int onintr();
onintr()
{
printf( "caught SIGINT, see ya ...\n" );
exit( -9 );
}
void main()
{
char* str;
void main()
{
remove ( “foo.exe” );
}
will remove the file “foo.exe” on the disk, if such a file exists.
void main()
{
rename ( “old.exe”, “new.exe” );
}
void main ()
{
FILE *preexisting = fopen ( “already.here”, “r” );
jmp_buf env;
void main()
{
if ( setjmp( env ) != 0 )
{
printf( "-- longjmp has been called --\n" );
exit( 1 );
}
printf( "-- setjmp called --\n" );
func();
}
_IOFBF—Use the full size of the buffer in the most efficient way.
_IOLBF—Use a line buffering policy: flush on newlines.
_IONBF—Do not buffer the stream at all.
The argument size specified the buffer size for this stream. The pointer buf, if
non-NULL, may be used for stream buffering. If buf is NULL, then setvbuf will allocate
any needed buffer.
Refer to the following sections for more information:
• Section A.4.88, “setbuf—Read formatted input from standard input,” on page A-93
1. If the value of func is the macro SIG_DFL, default handling for the signal will
occur.
2. If the value of func is the macro SIG_IGN, the signal is ignored.
3. Otherwise, func is a pointer to a function that will be called on the receipt of signal
sig.
When a signal occurs, the signal handler for sig is reset to SIG_DFL; this is equivalent to
making the call signal( sig, SIG_DFL ). The function func terminates by executing
the return statement or by calling the abort, exit, or longjmp function. If the
function func terminates with a return statement, execution continues at the point the
signal was caught. Note that if the value of sig was SIGFPE, the behavior is undefined.
Also note that in order to continue catching signal sig, the signal handler must reissue the
signal call.
For more information, see Chapter 6, “Software-Hardware Integration.” .
void main()
{
int onintr();
onintr()
{
printf( "caught SIGINT, see ya ...\n" );
exit( -9 );
}
prints to standard output:
caught SIGINT, see ya ...
A.4.91 sin—Sine
#include <math.h>
double sin( double x );
The sin function computes and returns the sine of x, measured in radians.
Refer to the following sections for more information:
• Section A.4.4, “asin—Arc sine,” on page A-12
Example A-88. sin
#include <stdio.h>
#include <math.h>
void main()
{
printf( "sin( 45.0 ) == %f\n", sin( 45.0 ) );
}
void main()
{
printf( "sinh( 3.1415 ) == %f\n", sinh( 3.1415 ) );
}
void main()
{
char buffer[256];
char* bptr = buffer;
char* str = "strings";
int i = 709, count;
double d = 7.09;
void main()
{
double = 50.2681;
void main()
{
char bigstr[80] = "string 1";
char smallstr[20] = " string 2";
void main()
{
char* string = "fred flintstone driving on bald feet";
char* found;
void main()
{
if ( strcmp( "xxx", "xxxyz" ) < 0 )
{
puts( "xxx is less than xxxyz" );
}
else
{
puts( "xxx is greater than xxxyz" );
}
void main()
{
char string[80];
char* sptr;
void main()
{
int i;
void main()
{
char* s = "is your name michael diamond?";
void main()
{
char bstr[80] = "string 1";
char sstr[20] = " string 2";
void main()
{
char bigstr[80] = "string 1";
char smallstr[20] = "string 2";
void main()
{
char bigstr[80] = "string 1";
char smallstr[20] = "spanky 2";
void main()
{
char* string = "abcde random characters fghijkl";
char* fndstr = "klmnopqr";
char* found;
else
{
puts( "can’t find a character" );
}
}
void main()
{
char* string = "fred flintstone driving on bald feet";
char* found;
/*result will be 5 */
void main()
{
char* string = "abcdef random characters ghijkl";
char* fndstr = "random";
char* found;
void main()
{
char* string = "7.09strtod stopped";
char* stopped;
double result;
void main()
{
char* str1 = "$%^this#is string\tnumber!one.";
char str2[] = "?a???b,,,#c";
char* token;
void main()
{
char* hexstr = "0xabcdef709hexstr stopped";
char* decstr = "709709709decstr stopped";
char* octstr = "012341234octstr stopped";
char* stopped;
long result;
void main()
{
char* hexstr = "0xabcdef709hexstr stopped";
char* decstr = "709709709decstr stopped";
char* octstr = "012341234octstr stopped";
char* stopped;
unsigned long result;
A.4.117 tan—Tangent
#include <math.h>
double tan( double x );
The tan function computes and returns the tangent of x, where x is in radians.
Refer to the following sections for more information:
• Section A.4.5, “atan—Arc tangent,” on page A-13
• Section A.4.6, “atan2—Arc tangent of angle defined by point y/x,” on page A-14
Example A-111. tan
#include <stdio.h>
#include <math.h>
void main()
{
printf( "tan( 45 ) == %f\n", tan( 45 ) );
}
void main()
{
printf( "tanh( 45 ) == %f\n", tanh( 45 ) );
}
void main ()
{
char buffer[L_tmpnam];
will create a temporary text file on the disk. Note that unlike when tmpfile is called, one
must remove any files created using fopen and tmpnam.
void main()
{
printf( "tolower( ’A’ ) == %c\n", tolower( ’A’ ) );
printf( "tolower( ’z’ ) == %c\n", tolower( ’z’ ) );
printf( "tolower( ’#’ ) == %c\n", tolower( ’#’ ) );
}
void main()
{
printf( "toupper( ’A’ ) == %c\n", toupper( ’A’ ) );
printf( "toupper( ’z’ ) == %c\n", toupper( ’z’ ) );
printf( "toupper( ’#’ ) == %c\n", toupper( ’#’ ) );
}
void main ()
{
char peek = getchar ();
putchar ( peek );
ungetc ( peek, stdin );
putchar ( getchar ());
}
will print the first character from standard input twice on standard
output.
Note: The DSP56000/DSP56001 does not provide byte addressing, thus characters
always require an entire word of memory each. One way to better utilize data
memory (with a run-time cost) is to combine the ANSI data type wchar_t and
the special ANSI multibyte and wide character library routines.
char array[16];
wchar_t wstr[10] = L"abcdefgh";
void main()
{
char* ptr = (char*) wstr;
int convert;
Note: The DSP56000/DSP56001 does not provide byte addressing, thus characters
always require an entire word of memory each. One way to better utilize data
memory (with a run-time cost) is to combine the ANSI data type wchar_t and
the special ANSI multibyte and wide character library routines.
char mbarray[8];
void main()
{
wchar_t wide = L’abc’;
char* ptr = array;
int convert;
Arithmetic
Description
Operations
ADD Add
Arithmetic
Description
Operations
CMP Compare
SUB Subtract
TST Test
OR Logical inclusive OR
Instruction Description
Instruction Description
Instruction Description
Instruction Description
JMP Jump
NOP No operation
Directive Description
Directive Description
Directive Description
DC Define constant
DS Define storage
Directive Description
Directive Description
Directive Description
Directive Description
1. asm56000
2. cldinfo
3. cldlod
4. cofdmp
5. dsplib
6. dsplnk
7. gdb56
8. run56
9. srec
files is a list of operating system compatible file names including optional pathnames. If
no extension is supplied for a given file, the assembler will first attempt to open the file
using the file name as supplied. If that is not successful, the assembler appends.asm to the
file name and tries to open the file again. If no path is given for a particular file, the
assembler will look for that file in the current directory. The list of files will be processed
Option arguments may immediately follow the option letter or may be separated from the
option letter by blanks or tabs. However, an ambiguity arises if an option takes an optional
argument. Consider the following command line:
asm56000 -b main io
In this example it is not clear whether the file main is a source file or is meant to be an
argument to the -B option. If the ambiguity is not resolved, the assembler will assume that
main is a source file and attempt to open it for reading. This may not be what the
programmer intended.
There are several ways to avoid this ambiguity. If main is supposed to be an argument to
the -B option, it can be placed immediately after the option letter, without intervening
white space:
asm56000 -bmain io
If there are other options on the command line besides those that take optional arguments,
the other options can be placed between the ambiguous option and the list of source file
names:
asm56000 -b main -v io
In this case the assembler interprets main as a source file name and uses the default
naming conventions for the -B option. Table C-1 lists the different Command Line
Options that can be used with asm5600:
Option Description
-A indicates that the assembler should operate in absolute mode, creating a load file (. cld) if the
-B option is given. By default, the assembler produces a link file (.cln) which is subsequently
processed by the Motorola DSP linker.
-B[<objfil>] This option specifies that an object file is to be created for assembler output. objfil can be
any legal operating system file name, including an optional pathname. A hyphen may also be
used as an argument to indicate that the object file should be sent to the standard output.
If a path is not specified, the file will be created in the current directory. If no file name is
supplied, the assembler will use the basename (file name without extension) of the first file
name encountered in the source input file list. The resulting output file will have an extension
of .cln unless the -A option is given in which case the file will have a .cld extension. If the -B
option is not given, then the assembler will not generate an object file. The -B option should
be specified only once.
string must be enclosed in quotes if it contains any embedded blanks. Note that if quotes are
used, they must be passed to the assembler intact, e.g. some host command interpreters will
strip quotes from around arguments. The -D<symbol> <string> sequence may
be repeated as often as desired.
-F<argfil> This option indicates that an external file should be read for further command arguments. It is
useful in host environments where the command line length is restricted. argfil must be
present on the command line, but can be any legal operating system file name including an
optional pathname.
The file may contain any legal command line options, including the -F option itself. The
arguments need be separated only by white space (spaces, tabs, or newlines). A semicolon
(;) on a line following white space causes the rest of the line in the file to be treated as a
comment.
-G Send source file line number information to the object file. This option is valid only in
conjunction with -B command line option. The generated line number information can be
used by debuggers to provide source-level debugging.
-I<ipath> When the assembler encounters include files, the current directory (or the directory specified
in the INCLUDE directive) is first searched for the file. If it is not found and the -l option is
supplied, the assembler prefixes the file name (and optional pathname) specified in the
INCLUDE directive with ipath and searches the newly formed directory pathname for the file.
The -I<ipath> sequence may be repeated as many times as desired. The directories will be
searched in the order given on the command line.
Option Description
-L[<lstfil>] This option specifies that a listing file is to be created for the assembler output. lstfil can be
any legal operating system file name including an optional pathname. A hyphen also may be
used as an argument to indicate that the listing file should be sent to the standard output.
If a path is not specified, the file will be created in the current directory. If no file name is
supplied, the assembler will use the basename (file name without extension) of the first file
name encountered in the source input file list. The resulting output file will have an extension
of .lst. If the -L option is not given, then the assembler will route the listing output to the
standard output. The -L option should be specified only once.
MACLIB <mpath>
The -M<mpath> sequence may be repeated as many times as desired. The directories will
be searched in the order specified on the command line.
-O<opt>[,<opt>...] opt can be any of the options that are available with the assembler OPT directive. If multiple
options are supplied, they must be separated by commas. The -O<opt> sequence may be
repeated for as many options as desired.
-R< rev>[,<rev>...] Run the assembler without the specified processor revision level enhancements. This is for
backward compatibility so that the assembler will flag new constructions as illegal. rev can be
any of the revision specifiers given below, but must be appropriate for the target processor.
ProcessorRevision
DSP56000C
If multiple revision levels are supplied, they must be separated by commas. The -R<rev>
sequence may be repeated as many times as desired.
-Z This option causes the assembler to strip symbol information from the absolute load file.
Normally symbol information is retained in the object file for symbolic reference purposes.
Note that this option is valid only when the assembler is in absolute mode via the -A
command line option and when an object file is created (-B option).
-V Indicates that the assembler should be verbose during processing, displaying a progress
report as it assembles the input files. The assembler will show the beginning of each pass
and when files are opened and closed. The information is sent to the standard error output
stream.
cldfile is an operating system compatible file name which contains COFF information.
Only a single file name may be supplied, and it must be explicit; there is no default
extension for the input file.
file is an operating system compatible file name. Only a single file name may be
supplied, and it must be explicit; there is no default extension for the input file.
Any of the following command line options listed in Table C-2, may be given . Option
letters may be entered in either upper or lower case. If no option is specified, the entire
object file is dumped.
Option Description
-c Dump the object file string table. This information may not be available if the object file has been
stripped.
-l Dump the object file line number information. This information may not be available if the object file has
been stripped.
Option Description
-r Dump the object file relocation information. This information is available only in relocatable object files.
-v Dump the object file symbolically, expanding bit flag, symbol type, and storage class names.
files is a list of operating system compatible file names. For input operations the file
names may also contain an optional pathname; the path is stripped when the file is written
to the library. For output operations only the file name should be used to refer to library
modules.
If no arguments are given on the command line, the librarian enters an interactive mode
where multiple commands may be entered without exiting the program. The syntax for the
interactive mode is command library [files...] where command is an action corresponding
to one of the options listed below, library is the library name, and files is the optional
(based on the action requested) list of files/modules upon which to operate. For example
the command add foo bar.cln adds the module bar.cln to the library foo. Because
interactive input is taken from the standard input channel of the host environment, it is
possible to create a batch of librarian commands and feed them to the program for
execution via redirection. For more information on interactive commands, invoke the
librarian without any arguments and enter help.
Option Description
-a This option adds the modules in the file list to the named library. The library file must exist and the
modules must not already be in the library.
-c Create a new library file and add any specified modules to it. If the library file already exists, an
error is issued.
-d Delete named modules from the library. If the module is not in the library, an error is issued.
-f<argfil> This option indicates that an external file should be read for further command arguments. It is
useful in host environments where the command line length is restricted. argfil must be present
on the command line but can be any legal operating system file name, including an optional
pathname.
argfil is a text file containing module names to be passed to the librarian. The names need be
separated only by white space (spaces, tabs, or newlines). A semicolon (;) on a line following
white space causes the rest of the line to be treated as a comment.
-l List library contents. This option lists the module name as contained in the library header, the
module size (minus library overhead), and the date and time the file was stored into the library.
The listing output is routed to standard output so that it may be redirected to a file if desired.
-r This option replaces the named modules in the given library. The modules must already be
present in the library file.
-u This option updates the specified modules if they exist in the library; otherwise it adds them to the
end of the library file.
-v This option displays the librarian version number and copyright notice.
-x Extract named modules from the library. The resulting files are given the name of the modules as
stored in the library module header. All files are created in the current working directory.
files is a list of operating system compatible file names including optional pathnames. If
no extension is supplied for a given file, the linker will first attempt to open the file using
the file name as supplied. If that is not successful the linker appends .cln to the file name
and tries to open the file again. If no pathname is supplied for a given file, the linker will
Option arguments may immediately follow the option letter or may be separated from the
option letter by blanks or tabs. However, an ambiguity arises if an option takes an optional
argument. Consider the following command line:
dsplnk -b main io
In this example it is not clear whether the file main is a link file or is meant to be an
argument to the -B option. If the ambiguity is not resolved, the linker will assume that
main is a link file and attempt to open it for reading. This may not be what the programmer
intended.There are several ways to avoid this ambiguity. If main is supposed to be an
argument to the -B option, it can be placed immediately after the option letter without
intervening white space:
dsplnk -bmain io
If there are other options on the command line besides those that take optional arguments
the other options can be placed between the ambiguous option and the list of link file
names.
dsplnk -b main -v io
Alternatively, two successive hyphens may be used to indicate the end of the option list:
dsplnk -b -- main io
In this case the linker interprets main as a link file name and uses the default naming
conventions for the -B option. Table C-4 lists the different Command Line Options that
can be used with dsplnk:
Option Description
-B[<objfil>] This option specifies a name for the object file generated by the linker. objfil can be any
legal operating system file name including an optional pathname. A hyphen may also be
used as an argument to indicate that the object file should be sent to the standard output.
If a pathname is not given, the file will be created in the current directory. If no file name is
supplied or if the -B option is not given, the linker will use the basename (file name without
extension) of the first file name encountered in the link input file list. The resulting output file
will have an extension of .cld. The -B option should be specified only once.
-F<argfil> This option indicates that an external file should be read for further command arguments. It
is useful in host environments where the command line length is restricted. argfil must be
present on the command line but can be any legal operating system file name, including an
optional pathname.
The file may contain any legal command line options including the -F option itself. The
arguments need be separated only by white space (spaces, tabs, or newlines). A
semicolon (;) on a line following white space causes the rest of the line to be treated as a
comment.
-I Under normal operation, the linker produces an absolute load file as output. If the -I option
appears on the command line, the linker combines the input files into a single relocatable
link file suitable for a subsequent linker pass. No absolute addresses are assigned and no
errors are issued for unresolved external references.
-L<library> The linker ordinarily processes a list of link files which each contain a single relocatable
code module. If the -L option is encountered, the linker treats the accompanying pathname
as a library file, and searches the file for any outstanding unresolved references.
If a module is found in the library that resolves an outstanding external reference, the
module is read from the library and included in the load file output. The linker continues to
search a library until all external references are resolved or no more references can be
satisfied within the current library. The linker searches a library only once: when it is
encountered on the command line. Therefore, the position of the -L option on the command
line is significant.
-M[<mapfil> This option specifies that a map file is to be created. mapfil can be any legal operating
system file name including an optional pathname.
If a pathname is not given, the file will be created in the current directory. If no file name is
supplied, the linker will use the basename (file name without extension) of the first file name
encountered in the link input file list. The resulting output file will have an extension of .map.
The linker will not generate a map file if the -M option is not specified. The -M option should
be specified only once.
-N Indicates that the linker should ignore case in symbol names. Ordinarily the linker is
sensitive to upper and lower case letters in symbol names. If the -N option is supplied the
linker maps all symbol characters to lower case.
Option Description
-O<mem>[<ctr>][< By default, the linker generates instructions and data for the load file beginning at absolute
map>]:<origin> location zero for all DSP memory spaces. This option allows the programmer to redefine
the start address for any memory space and associated location counter.mem is one of the
single-character memory space identifiers (X, Y, L, and P). The letter may be upper or
lower case. The optional ctr is a letter indicating the high (H) or low (L) location counters. If
no counter is specified, the default counter is used. map is also optional and signifies the
desired physical mapping for all relocatable code in the given memory space. It may be I for
internal memory, E for external memory, or B for bootstrap memory (valid only in P program
memory space). If map is not supplied, then no explicit mapping is presumed.The origin is
a hexadecimal number signifying the new relocation address for the given memory space.
The -O option may be specified as many times as needed on the command line.
-P<lpath> When the linker encounters a library specification on the command line, the current
directory (or the directory given in the library specification) is first searched for the library
file. If it is not found and the -P option is supplied, the linker prefixes the file name (and
optional pathname) provided in the library specification with lpath and searches the newly
formed directory pathname for the file. The directories will be searched in the order given
on the command line.
-R[<ctlfil>] This option indicates that a memory control file is to be read to determine the absolute
placement of sections in DSP memory. ctlfil can be any legal operating system file name
including an optional pathname.If a pathname is not given, an attempt will be made to open
the file in the current directory. If no file name is supplied, the linker will use the basename
(file name without extension) of the first file name encountered in the link input file list,
appending an extension of .ctl. If the -R option is not specified, then the linker will not use a
memory map file. The -R option should be specified only once.
-U<symbol> Causes symbol to be entered into the unresolved external reference table. This is useful
when the initial or only link file is a library. Since there are no external references when the
linker is invoked, the -U option may be used to force inclusion of a library module that
resolves the undefined reference. The -U option may be specified as often as desired.
-V Indicates that the linker should be verbose during processing, displaying a progress report
as it links the input files. The linker will show the beginning of each pass and when files are
opened and closed. The information is sent to the standard error output stream.
-X<opt>[,<opt>,..., The -X option directs the linker to perform a little bit of different operation than standard
<opt>] operation of the linker.The options are described below with their different operations
performed. All options may be preceded by NO to reverse their meaning. The -X<opt>
sequence can be repeated for as many options as desired.
Option Meaning
XC Relative terms from different sections used in an expression cause an error
RSV Reserve special target processor memory areas (e.g. DSP96000 DMA)
AEC Check form of address expressions
RO Allow region overlap
ESO Do not allocate memory below ordered sections
ASC Enable absolute section bounds checking
-Z The linker strips source file line number and symbol information from the input file. Symbol
information normally is retained for debugging purposes. This options has no effect if
incremental linking is being done (see the -l option).
gdb56 is invoked with the shell command gdb56. Once started, it reads commands from
the terminal until given the quit command. name is the name of the executable program,
and core, if specified, is the name of the DSP56000/DSP56001 state file to be examined or
have execution resumed.
gdb56 has been modified to run with both software and hardware DSP56000/DSP56001
execution devices.
The following command-line options listed in Table C-5 can be used to more precisely
specify the files to be debugged. All the options and command line arguments given are
processed in sequential order. The order makes a difference when the -x command is used.
Table C-5. gdb56 Command Line Options
Option Description
-e EXECFILE Use EXECFILE as the executable file to execute when appropriate and for examining pure data
in conjunction with a core dump.
-se FILE Read symbol table from FILE and use it as the executable file.
-batch Run in batch mode. Exit with code 1 after processing all the command files specified with -x
(and .gdbinit, if not inhibited). Exit also if, due to an error, gdb56 would otherwise attempt to read
a command from the terminal.
-fullname This option is used when Emacs runs GDB as a subprocess. It tells GDB to produce the full file
name and line number each time a stack frame is displayed (which includes each time the
program stops).
-tty TTY Use TTY for input/output by the program being debugged.
Option Description
The following additional command-line options can be used to affect certain aspects of the behavior of gdb56:
-nx Don’t execute commands from the init files .gdbinit. Normally, the commands in these files are
executed after all the command options and arguments have been processed.
SEE ALSO
file is an operating system compatible file name. Only a single file name may be supplied
and it must be explicit; there is no default extension for the input file.
Table C-6 lists the different Command Line Options that can be used with run56:
Option Description
-b BCR_VALUE Use BCR_VALUE to set the DSP56000/DSP56001 bus control register. Default bcr value is 0.
-t Update global C variable __time at each clock tick. Used to benchmark code.
-x Indicates the input file was generated from the x memory model of C compiler. The C compiler
may use x, y or l memory model for the compilation (refer to the option -m of the C compiler), and
this option directs the run56 program to use the X memory space for data buffer. Without this
option, y memory model or L memory model is assumed.
files is a list of operating system compatible file names. If no pathname is specified for a
given file, srec will look for that file in the current directory. If the special character ‘-’ is
used as a file name srec will read from the standard input stream. The list of files will be
processed sequentially in the order given.
Only one of the following command line options listed in Table C-7 may be given for each
invocation of the librarian. Option letters may be entered in either upper or lower case. If
no option is given, the librarian operates as if the -U option were specified.
Option Description
-b Use byte addressing when transferring load addresses to S-record addresses. This means
that load file DATA record start addresses are multiplied by the number of bytes per target
DSP word and subsequent S1/S3 record addresses are computed based on the data byte
count. The -b and -w options are mutually exclusive.
-l Use double-word addressing when transferring load addresses from L space to S-record
addresses. This means that load file DATA records for L space data are moved unchanged
and subsequent S1/S3 record addresses are computed based on the data word count divided
by 2. This option should always be used when the source load file contains DATA records in L
memory space.
-m Split each DSP word into bytes and store the bytes in parallel S-records. The -m and -s options
are mutually exclusive.
-r Write bytes high to low, rather than low to high. This option has no effect when used with the
-m option.
-s Write data to a single file, putting memory space information into the address field of the S0
header record. The -m and -s options are mutually exclusive.
-w Use word addressing when transferring load addresses to S-record addresses. This means
that load file DATA record start addresses are moved unchanged and subsequent S1/S3
record addresses are computed based on the data word count.
D.1.5 Preamble
The license agreements of most software companies try to keep users at the mercy of those
companies. By contrast, our General Public License is intended to guarantee your freedom
to share and change free software---to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation’s software and to any
other program whose authors commit to using it. You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not price. Specifically, the
General Public License is designed to make sure that you have the freedom to give away
or sell copies of free software, that you receive source code or can get it if you want it, that
you can change the software or use pieces of it in new free programs; and that you know
you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these
rights or to ask you to surrender the rights. These restrictions translate to certain
responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether gratis or for a fee, you
must give the recipients all the rights that you have. You must make sure that they, too,
receive or can get the source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this
license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author’s protection and ours, we want to make certain that everyone
understands that there is no warranty for this free software. If the software is modified by
someone else and passed on, we want its recipients to know that what they have is not the
original, so that any problems introduced by others will not reflect on the original authors’
reputations.
The precise terms and conditions for copying, distribution and modification follow.
— cause the whole of any work that you distribute or publish, that in whole or in
part contains the Program or any part thereof, either with or without
modifications, to be licensed at no charge to all third parties under the terms of
this General Public License (except that you may choose to grant warranty
protection to some or all third parties, at your option).
— If the modified program normally reads commands interactively when run, you
must cause it, when started running for such interactive use in the simplest and
most usual way, to print or display an announcement including an appropriate
copyright notice and a notice that there is no warranty (or else, saying that you
provide a warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General Public
License.
— You may charge a fee for the physical act of transferring a copy, and you may at
your option offer warranty protection in exchange for a fee.
Mere aggregation of another independent work with the Program (or its derivative) on a
volume of a storage or distribution medium does not bring the other work under the scope
of these terms.
4. You may copy and distribute the Program (or a portion or derivative of it, under
Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and
2 above provided that you also do one of the following:
— accompany it with the complete corresponding machine-readable source code,
which must be distributed under the terms of Paragraphs 1 and 2 above; or,
— accompany it with a written offer, valid for at least three years, to give any third
party free (except for a nominal charge for the cost of distribution) a complete
machine-readable copy of the corresponding source code, to be distributed
under the terms of Paragraphs 1 and 2 above; or,
— accompany it with the information you received as to where the corresponding
source code may be obtained. (This alternative is allowed only for
noncommercial distribution and only if you received the program in object code
or executable form alone.)
Source code for a work means the preferred form of the work for making modifications to
it. For an executable file, complete source code means all the source code for all modules
it contains; but, as a special exception, it need not include source code for modules which
are standard libraries that accompany the operating system on which the executable file
runs, or for standard header files or definitions files that accompany that operating system.
5. You may not copy, modify, sublicense, distribute or transfer the Program except as
expressly provided under this General Public License. Any attempt otherwise to
copy, modify, sublicense, distribute or transfer the Program is void, and will
automatically terminate your rights to use the Program under this License.
However, parties who have received copies, or rights to use copies, from you under
this General Public License will not have their licenses terminated so long as such
parties remain in full compliance.
6. By copying, distributing or modifying the Program (or any work based on the
Program) you indicate your acceptance of this license to do so, and all its terms and
conditions.
7. Each time you redistribute the Program (or any work based on the Program), the
recipient automatically receives a license from the original licensor to copy,
distribute or modify the Program subject to these terms and conditions. You may
not impose any further restrictions on the recipients’ exercise of the rights granted
herein.
The Free Software Foundation may publish revised and/or new versions of the General
Public License from time to time. Such new versions will be similar in spirit to the present
version, but may differ in detail to address new problems or concerns.
8. Each version is given a distinguishing version number. If the Program specifies a
version number of the license which applies to it and “any later version”, you have
the option of following the terms and conditions either of that version or of any
later version published by the Free Software Foundation. If the Program does not
specify a version number of the license, you may choose any version ever
published by the Free Software Foundation.
9. If you wish to incorporate parts of the Program into other free programs whose
distribution conditions are different, write to the author to ask for permission. For
software which is copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our decision will be
guided by the two goals of preserving the free status of all derivatives of our free
software and of promoting the sharing and reuse of software generally.
D.1.7 No Warranty
1. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING
THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave., Cambridge,
MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an
interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’.
This is free software, and you are welcome to redistribute it under certain conditions; type
‘show c’ for details.
The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate parts of
the General Public License. Of course, the commands you use may be called something
other than ‘show w’ and ‘show c’; they could even be mouse-clicks or menu
items---whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any,
to sign a “copyright disclaimer” for the program, if necessary. Here a sample; alter the
names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program ‘Gnomovision’ (a
program to direct compilers to make passes at assemblers) written by James Hacker.
signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice
That’s all there is to it!
Also, GDB may at times produce more information about its own workings than is of
interest to the user. Some of these informational messages can be turned on and off with
the ‘set verbose’ command:
set verbose on
Re-enables GDB’s output of certain informational messages.
Currently, the messages controlled by ‘set verbose’ are those which announce that the
symbol table for a source file is being read (see section File Commands, in the description
of the command ‘symbol-file’).
Command Description
exec-file filename Specify that the program to be run is found in filename. If you do not specify a
directory and the file is not found in GDB’s working directory, GDB will use the
environment variable PATH as a list of directories to search, just as the shell
does when looking for a program to run.
symbol-file filename Read symbol table information from file filename. PATH is searched when
necessary. Most of the time you will use both the ‘exec-file’ and ‘symbol-file’
commands on the same file.
‘symbol-file’ with no argument clears out GDB’s symbol table.
The ‘symbol-file’ command does not actually read the symbol table in full right
away. Instead, it scans the symbol table quickly to find which source files and
which symbols are present. The details are read later, one source file at a time,
when they are needed.
The purpose of this two-stage reading strategy is to make GDB start up faster.
For the most part, it is invisible except for occasional messages telling you that
the symbol table details for a particular source file are being read. (The ‘set
verbose’ command controls whether these messages are printed; see section
User Interface).
However, you will sometimes see in backtraces lines for functions in source
files whose data has not been read in; these lines omit some of the information,
such as argument values, which cannot be printed without full details of the
symbol table.
When the symbol table is stored in COFF format, ‘symbol-file’ does read the
symbol table data in full right away. We haven’t bothered to implement the
two-stage strategy for COFF.
core-file filename Specify the whereabouts of a core dump file to be used as the “contents of
memory”. Note that the core dump contains only the writable parts of memory;
the read-only parts must come from the executable file.
‘core-file’ with no argument specifies that no core file is to be used.
Note that the core file is ignored when your program is actually running under
GDB. So, if you have been running the program and you wish to debug a core
file instead, you must kill the sub-process in which the program is running. To
do this, use the ‘kill’ command (see section Kill Process).
add-file filename address The ‘add-file’ command reads additional symbol table
information from the file filename. You would use this when that file has been
dynamically loaded into the program that is running. address should be the
memory address at which the file has been loaded; GDB cannot figure this out
for itself.
The symbol table of the file filename is added to the symbol table originally
read with the ‘symbol-file’ command. You can use the ‘add-file’ command any
number of times; the new symbol data thus read keeps adding to the old. The
‘symbol-file’ command forgets all the symbol data GDB has read; that is the
only time symbol data is forgotten in GDB.
Command Description
info files Print the names of the executable and core dump files currently in use by GDB,
and the file from which symbols were loaded.
While all three file-specifying commands allow both absolute and relative file
names as arguments, GDB always converts the file name to an absolute one
and remembers it that way.
The ‘symbol-file’ command causes GDB to forget the contents of its
convenience variables, the value history, and all breakpoints and auto-display
expressions. This is because they may contain pointers to the internal data
recording symbols and data types, which are part of the old symbol table data
being discarded inside GDB.
• The arguments.
You specify the arguments to give the program as the arguments of the ‘run’
command.
• The environment.
The program normally inherits its environment from GDB, but you can use the
GDB commands ‘set environment’ and ‘unset environment’ to change parts of the
environment that will be given to the program.
• The working directory.
The program inherits its working directory from GDB. You can set GDB’s working
directory with the ‘cd’ command in GDB.
After the ‘run’ command, the debugger does nothing but wait for your program to
stop. See section Stopping.
Note that once your program has been started by the ‘run’ command, you may
evaluate expressions that involve calls to functions in the inferior. See section
Expressions. If you wish to evaluate a function simply for its side affects, you may
use the ‘set’ command. See section Assignment.
Variable Description
info environment varname Print the value of environment variable varname to be given to your
program when it is started. This command can be abbreviated ‘i env
varname’.
info environment Print the names and values of all environment variables to be given
to your program when it is started. This command can be
abbreviated ‘i env’.
set environment varname value Sets environment variable varname to value, for your program only,
set environment varname = value not for GDB itself. value may be any string; the values of
environment variables are just strings, and any interpretation is
supplied by your program itself. The value parameter is optional; if it
is eliminated, the variable is set to a null value. This command can
be abbreviated as short as ‘set e’.
For example, this command:
set env USER = foo
tells the program, when subsequently run, to assume it is being run
on behalf of the user named ‘foo’.
delete environment varname Remove variable varname from the environment to be passed to
unset environment varname your program. This is different from ‘set env varname =’ because
‘delete environment’ leaves the variable with no value, which is
distinguishable from an empty value. This command can be
abbreviated ‘d e’.
Command Description
You can redirect the program’s input and/or output using ‘sh’-style redirection commands
in the ‘run’ command. For example,
tty /dev/ttyb
directs that processes started with subsequent ‘run’ commands default to do input and
output on the terminal ‘/dev/ttyb’ and have that as their controlling terminal.
An explicit redirection in ‘run’ overrides the ‘tty’ command’s effect on input/output
redirection, but not its effect on the controlling terminal.
When you use the ‘tty’ command or redirect input in the ‘run’ command, only the input
for your program is affected. The input for GDB still comes from your terminal.
The ‘attach’ command is also used to debug a remote machine via a serial connection. See
section Attach, for more info.
D.6.1 Signals
A signal is an asynchronous event that can happen in a program. The operating system
defines the possible kinds of signals, and gives each kind a name and a number. For
example, SIGINT is the signal a program gets when you type Ctrl-c; SIGSEGV is the
signal a program gets from referencing a place in memory far away from all the areas in
use; SIGALRM occurs when the alarm clock timer goes off (which happens only if the
program has requested an alarm).
Some signals, including SIGALRM, are a normal part of the functioning of the program.
Others, such as SIGSEGV, indicate errors; these signals are fatal (kill the program
immediately) if the program has not specified in advance some other way to handle the
signal. SIGINT does not indicate an error in the program, but it is normally fatal so it can
carry out the purpose of Ctrl-c: to kill the program.
GDB has the ability to detect any occurrence of a signal in the program running under
GDB’s control. You can tell GDB in advance what to do for each kind of signal.
Normally, GDB is set up to ignore non-erroneous signals like SIGALRM (so as not to
interfere with their role in the functioning of the program) but to stop the program
immediately whenever an error signal happens. You can change these settings with the
‘handle’ command. You must specify which signal you are talking about with its number.
info signal
Print a table of all the kinds of signals and how GDB has been told to handle each one.
You can use this to see the signal numbers of all the defined types of signals.
Keyword Description
stop GDB should stop the program when this signal happens. This implies the ‘print’ keyword as well.
nostop GDB should not stop the program when this signal happens. It may still print a message telling
you that the signal has come in.
noprint GDB should not mention the occurrence of the signal at all. This implies the ‘nostop’ keyword as
well.
pass GDB should allow the program to see this signal; the program will be able to handle the signal,
or may be terminated if the signal is fatal and not handled.
nopass GDB should not allow the program to see this signal.When a signal has been set to stop the
program, the program cannot see the signal until you continue. It will see the signal then, if
‘pass’ is in effect for the signal in question at that time. In other words, after GDB reports a
signal, you can use the ‘handle’ command with ‘pass’ or ‘nopass’ to control whether that signal
will be seen by the program when you later continue it.You can also use the ‘signal’ command to
prevent the program from seeing a signal, or cause it to see a signal it normally would not see,
or to give it any signal at any time. See section Signaling.
D.6.2 Breakpoints
A breakpoint makes your program stop whenever a certain point in the program is
reached. You set breakpoints explicitly with GDB commands, specifying the place where
the program should stop by line number, function name or exact address in the program.
You can add various other conditions to control whether the program will stop.
Each breakpoint is assigned a number when it is created; these numbers are successive
integers starting with 1. In many of the commands for controlling various features of
breakpoints you use the breakpoint number to say which breakpoint you want to change.
Each breakpoint may be enabled or disabled; if disabled, it has no effect on the program
until you enable it again.
The command ‘info break’ prints a list of all breakpoints set and not deleted, showing their
numbers, where in the program they are, and any special features in use for them. Disabled
breakpoints are included in the list, but marked as disabled. ‘info break’ with a breakpoint
number as argument lists only that breakpoint. The convenience variable $_ and the
default examining-address for the ‘x’ command are set to the address of the last breakpoint
listed (see section Memory).
Command Description
break +offset Set a breakpoint some number of lines forward or back from the position at which
break -offset execution stopped in the currently selected frame.
break linenum Set a breakpoint at line linenum in the current source file. That file is the last file
whose source text was printed. This breakpoint will stop the program just before
it executes any of the code on that line.
break filename:function Set a breakpoint at entry to function function found in file filename. Specifying a
file name as well as a function name is superfluous except when multiple files
contain similarly named functions.
break *address Set a breakpoint at address address. You can use this to set breakpoints in parts
of the program which do not have debugging information or source files.
Command Description
break Set a breakpoint at the next instruction to be executed in the selected stack
frame (see section Stack). In any selected frame but the innermost, this will
cause the program to stop as soon as control returns to that frame. This is
equivalent to a ‘finish’ command in the frame inside the selected frame. If this is
done in the innermost frame, GDB will stop the next time it reaches the current
location; this may be useful inside of loops.
GDB normally ignores breakpoints when it resumes execution, until at least one
instruction has been executed. If it did not do this, you would be unable to
proceed past a breakpoint without first disabling the breakpoint. This rule applies
whether or not the breakpoint already existed when the program stopped.
break ... if cond Set a breakpoint with condition cond; evaluate the expression cond each time the
breakpoint is reached, and stop only if the value is nonzero. ‘...’ stands for one of
the possible arguments described above (or no argument) specifying where to
break. See section Conditions, for more information on breakpoint conditions.
tbreak args Set a breakpoint enabled only for one stop. args are the same as in the ‘break’
command, and the breakpoint is set in the same way, but the breakpoint is
automatically disabled the first time it is hit. See section Disabling.
GDB allows you to set any number of breakpoints at the same place in the
program. There is nothing silly or meaningless about this. When the breakpoints
are conditional, this is even useful (see section Conditions).
Command Description
clear Delete any breakpoints at the next instruction to be executed in the selected
stack frame (see section Selection). When the innermost frame is selected,
this is a good way to delete a breakpoint that the program just stopped at.
clear function Delete any breakpoints set at entry to the function function.
clear filename:function
clear linenum Delete any breakpoints set at or within the code of the specified line.
clear filename:linenum
Command Description
disable breakpoints bnums... Disable the specified breakpoints. A disabled breakpoint has no
disable bnums... effect but is not forgotten. All options such as ignore-counts,
conditions and commands are remembered in case the
breakpoint is enabled again later.
Command Description
enable breakpoints bnums... Enable the specified breakpoints. They become effective once
enable bnums... again in stopping the program, until you specify otherwise.
enable breakpoints once bnums... Enable the specified breakpoints temporarily. Each will be
enable once bnums... disabled again the next time it stops the program (unless you
have used one of these commands to specify a different state
before that time comes).
enable breakpoints delete bnums... Enable the specified breakpoints to work once and then die.
enable delete bnums... Each of the breakpoints will be deleted the next time it stops the
program (unless you have used one of these commands to
specify a different state before that time comes).
Aside from the automatic disablement or deletion of a breakpoint when it stops the
program, which happens only in certain states, the state of enablement of a breakpoint
changes only when one of the commands above is used.
condition bnum
Remove the condition from breakpoint number bnum. It becomes an ordinary
unconditional breakpoint.
A special case of a breakpoint condition is to stop only when the breakpoint has been
reached a certain number of times. This is so useful that there is a special way to do it,
using the ignore count of the breakpoint. Every breakpoint has an ignore count, which is
an integer. Most of the time, the ignore count is zero, and therefore has no effect. But if the
program reaches a breakpoint whose ignore count is positive, then instead of stopping, it
just decrements the ignore count by one and continues. As a result, if the ignore count
value is n, the breakpoint will not stop the next n times it is reached.
cont count
Continue execution of the program, setting the ignore count of the breakpoint that the
program stopped at to count minus one. Thus, the program will not stop at this breakpoint
until the count’th time it is reached.
This command is allowed only when the program stopped due to a breakpoint. At other
times, the argument to ‘cont’ is ignored.
If a breakpoint has a positive ignore count and a condition, the condition is not checked.
Once the ignore count reaches zero, the condition will start to be checked.
Note that you could achieve the effect of the ignore count with a condition such as
‘$foo-<= 0’ using a debugger convenience variable that is decremented each time. See
section Convenience Vars.
commands bnum
Specify commands for breakpoint number bnum. The commands themselves appear on
the following lines. Type a line containing just ‘end’ to terminate the commands.
To remove all commands from a breakpoint, use the command ‘commands’ and follow it
immediately by ‘end’; that is, give no commands.
With no arguments, ‘commands’ refers to the last breakpoint set.
It is possible for breakpoint commands to start the program up again. Simply use the
‘cont’ command, or ‘step’, or any other command to resume execution. However, any
remaining breakpoint commands are ignored. When the program stops again, GDB will
act according to the cause of that stop.
If the first command specified is ‘silent’, the usual message about stopping at a breakpoint
is not printed. This may be desirable for breakpoints that are to print a specific message
and then continue. If the remaining commands too print nothing, you will see no sign that
the breakpoint was reached at all. ‘silent’ is not really a command; it is meaningful only at
the beginning of the commands for a breakpoint.
The commands ‘echo’ and ‘output’ that allow you to print precisely controlled output are
often useful in silent breakpoints. See section Output.
For example, here is how you could use breakpoint commands to print the value of x at
entry to foo whenever it is positive.
break foo if x>0
commands
silent
echo x is\040
output x
echo \n
cont
end
One application for breakpoint commands is to correct one bug so you can test another.
Put a breakpoint just after the erroneous line of code, give it a condition to detect the case
in which something erroneous has been done, and give it commands to assign correct
values to any variables that need them. End with the ‘cont’ command so that the program
does not stop, and start with the ‘silent’ command so that no output is produced.
Here is an example:
break 403
commands
silent
set x = y + 4
cont
end
One deficiency in the operation of automatically continuing breakpoints under Unix
appears when your program uses raw mode for the terminal. GDB switches back to its
own terminal modes (not raw) before executing commands, and then must switch back to
raw mode when your program is continued. This causes any pending terminal input to be
lost.
In the GNU system, this will be fixed by changing the behavior of terminal modes.
Under Unix, when you have this problem, you might be able to get around it by putting
your actions into the breakpoint condition instead of commands. For example
condition 5 (x = y + 4), 0
specifies a condition expression (See section Expressions) that will change x as needed,
then always have the value 0 so the program will not stop. Loss of input is avoided here
because break conditions are evaluated without changing the terminal modes. When you
want to have nontrivial conditions for performing the side effects, the operators ‘&&’, ‘||’
and ‘?...:’ may be useful.
D.6.3 Continuing
After your program stops, most likely you will want it to run some more if the bug you are
looking for has not happened yet.
cont
Continue running the program at the place where it stopped.
If the program stopped at a breakpoint, the place to continue running is the address of the
breakpoint. You might expect that continuing would just stop at the same breakpoint
immediately. In fact, ‘cont’ takes special care to prevent that from happening. You do not
need to delete the breakpoint to proceed through it after stopping at it.
You can, however, specify an ignore-count for the breakpoint that the program stopped at,
by means of an argument to the ‘cont’ command. See section Conditions.
If the program stopped because of a signal other than SIGINT or SIGTRAP, continuing
will cause the program to see that signal. You may not want this to happen. For example,
if the program stopped due to some sort of memory reference error, you might store
correct values into the erroneous variables and continue, hoping to see more execution;
but the program would probably terminate immediately as a result of the fatal signal once
it sees the signal. To prevent this, you can continue with ‘signal 0’. See section Signaling.
You can also act in advance to prevent the program from seeing certain kinds of signals,
using the ‘handle’ command (see section Signals).
D.6.4 Stepping
Stepping means setting your program in motion for a limited time, so that control will
return automatically to the debugger after one line of code or one machine instruction.
Breakpoints are active during stepping and the program will stop for them even if it has
not gone as far as the stepping command specifies.
Command Description
step Continue running the program until control reaches a different line, then stop it and return
control to the debugger. This command is abbreviated ‘s’.
This command may be given when control is within a function for which there is no debugging
information. In that case, execution will proceed until control reaches a different function, or is
about to return from this function. An argument repeats this action.
step count Continue running as in ‘step’, but do so count times. If a breakpoint is reached or a signal not
related to stepping occurs before count steps, stepping stops right away.
Command Description
next Similar to ‘step’, but any function calls appearing within the line of code are executed without
stopping. Execution stops when control reaches a different line of code at the stack level
which was executing when the ‘next’ command was given. This command is abbreviated ‘n’.
An argument is a repeat count, as in ‘step’.
‘next’ within a function without debugging information acts as does ‘step’, but any function
calls appearing within the code of the function are executed without stopping.
finish Continue running until just after the selected stack frame returns (or until there is some other
reason to stop, such as a fatal signal or a breakpoint). Print value returned by the selected
stack frame (if any).
Contrast this with the ‘return’ command (see section Returning).
until This command is used to avoid single stepping through a loop more than once. It is like the
‘next’ command, except that when ‘until’ encounters a jump, it automatically continues
execution until the program counter is greater than the address of the jump.
This means that when you reach the end of a loop after single stepping though it, ‘until’ will
cause the program to continue execution until the loop is exited. In contrast, a ‘next’ command
at the end of a loop will simply step back to the beginning of the loop, which would force you
to step through the next iteration.
‘until’ always stops the program if it attempts to exit the current stack frame.
‘until’ may produce somewhat counterintuitive results if the order of the source lines does not
match the actual order of execution. For example, in a typical C for-loop, the third expression
in the for-statement (the loop-step expression) is executed after the statements in the body of
the loop, but is written before them. Therefore, the ‘until’ command would appear to step back
to the beginning of the loop when it advances to this expression. However, it has not really
done so, not in terms of the actual machine code.
Note that ‘until’ with no argument works by means of single instruction stepping, and hence is
slower than ‘until’ with an argument.
until location Continue running the program until either the specified location is reached, or the current
(innermost) stack frame returns. This form of the command uses breakpoints, and hence is
quicker than ‘until’ without an argument.
stepi Execute one machine instruction, then stop and return to the debugger.
si It is often useful to do ‘display/i $pc’ when stepping by machine instructions. This will cause
the next instruction to be executed to be displayed automatically at each stop. See section
Auto Display.
An argument is a repeat count, as in ‘step’.
nexti Execute one machine instruction, but if it is a subroutine call, proceed until the subroutine
ni returns.
An argument is a repeat count, as in ‘next’.
A typical technique for using stepping is to put a breakpoint (see section Breakpoints) at the
beginning of the function or the section of the program in which a problem is believed to lie,
and then step through the suspect area, examining the variables that are interesting, until the
problem happens.
The ‘cont’ command can be used after stepping to resume execution until the next breakpoint
or signal.
exist in your program; they are to give you a way of talking about stack frames in GDB
commands.
Many GDB commands refer implicitly to one stack frame. GDB records a stack frame that
is called the selected stack frame; you can select any frame using one set of GDB
commands, and then other commands will operate on that frame. When your program
stops, GDB automatically selects the innermost frame.
Some functions can be compiled to run without a frame reserved for them on the stack.
This is occasionally done with heavily used library functions to save the frame setup time.
GDB has limited facilities for dealing with these function invocations; if the innermost
function invocation has no stack frame, GDB will give it a virtual stack frame of 0 and
correctly allow tracing of the function call chain. Results are undefined if a function
invocation besides the innermost one is frameless.
D.7.2 Backtraces
A backtrace is a summary of how the program got where it is. It shows one line per frame,
for many frames, starting with the currently executing frame (frame zero), followed by its
caller (frame one), and on up the stack. See Table D-6.
Backtrace Description
backtrace Print a backtrace of the entire stack: one line per frame for all frames in the stack.
bt You can stop the backtrace at any time by typing the system interrupt character, normally
Control-C.
If the function is in a source file whose symbol table data has been fully read, the
backtrace shows the source file name and line number, as well as the arguments to the
function. (The program counter value is omitted if it is at the beginning of the code for that
line number.)
If the source file’s symbol data has not been fully read, just scanned, this extra information
is replaced with an ellipsis. You can force the symbol data for that frame’s source file to
be read by selecting the frame. (See section Selection).
Here is an example of a backtrace. It was made with the command ‘bt 3’, so it shows the
innermost three frames.
#0 rtx_equal_p (x=(rtx) 0x8e58c, y=(rtx) 0x1086c4)
(/gp/rms/cc/rtlanal.c line 337)
#1 0x246b0 in expand_call (...) (...)
#2 0x21cfc in expand_expr (...) (...)
(More stack frames follow...)
The functions expand_call and expand_expr are in a file whose symbol details have not
been fully read. Full detail is available for the function rtx_equal_p, which is in the file
‘rtlanal.c’. Its arguments, named x and y, are shown with their typed values.
Frame Description
frame n Select frame number n. Recall that frame zero is the innermost (currently executing)
frame, frame one is the frame that called the innermost one, and so on. The
highest-numbered frame is main’s frame.
frame addr Select the frame at address addr. This is useful mainly if the chaining of stack frames has
been damaged by a bug, making it impossible for GDB to assign numbers properly to all
frames. In addition, this can be useful when the program has multiple stacks and
switches between them.
up n Select the frame n frames up from the frame previously selected. For positive numbers n,
this advances toward the outermost frame, to higher frame numbers, to frames that have
existed longer. n defaults to one.
down n Select the frame n frames down from the frame previously selected. For positive numbers
n, this advances toward the innermost frame, to lower frame numbers, to frames that
were created more recently. n defaults to one.
All of these commands end by printing some information on the frame that has been
selected: the frame number, the function name, the arguments, the source file and line
number of execution in that frame, and the text of that source line. For example:
#3 main (argc=3, argv=??, env=??) at main.c, line 67
67 read_input_file (argv[i]);
After such a printout, the ‘list’ command with no arguments will print ten lines centered
on the point of execution in the frame. See section List.
Command Description
frame This command prints a brief description of the selected stack frame. It can be abbreviated
‘f’. With an argument, this command is used to select a stack frame; with no argument, it
does not change which frame is selected, but still prints the same information.
info frame This command prints a verbose description of the selected stack frame, including the
address of the frame, the addresses of the next frame in (called by this frame) and the next
frame out (caller of this frame), the address of the frame’s arguments, the program counter
saved in it (the address of execution in the caller frame), and which registers were saved in
the frame. The verbose description is useful when something has gone wrong that has
made the stack format fail to fit the usual conventions.
info frame addr Print a verbose description of the frame at address addr, without selecting that frame. The
selected frame remains unchanged by this command.
info args Print the arguments of the selected frame, each on a separate line.
info locals Print the local variables of the selected frame, each on a separate line. These are all
variables declared static or automatic within all program blocks that execution in this frame
is currently inside of.
Table D-12 shows the forms of the ‘list’ command most commonly used:
Command Description
list linenum Print ten lines centered around line number linenum in the current source file.
list function Print ten lines centered around the beginning of function function.
list Print ten more lines. If the last lines printed were printed with a ‘list’ command, this prints
ten lines following the last lines printed; however, if the last line printed was a solitary line
printed as part of displaying a stack frame (see section Stack), this prints ten lines
centered around that line.
list - Print ten lines just before the lines last printed.Repeating a ‘list’ command with RET
discards the argument, so it is equivalent to typing just ‘list’. This is more useful than
listing the same lines again. An exception is made for an argument of ‘-’; that argument is
preserved in repetition so that each repetition moves up in the file.In general, the ‘list’
command expects you to supply zero, one or two linespecs. Linespecs specify source
lines; there are several ways of writing them but the effect is always to specify some
source line. Here is a complete description of the possible arguments for ‘list’:
list linespec Print ten lines centered around the line specified by linespec.
list first,last Print lines from first to last. Both arguments are linespecs.
list + Print ten lines just after the lines last printed.
list - Print ten lines just before the lines last printed.
Table D-13 shows the ways of specifying a single source line--all the kinds of linespec.
linenum Specifies line linenum of the current source file. When a ‘list’ command has two
linespecs, this refers to the same source file as the first linespec.
+offset Specifies the line offset lines after the last line printed. When used as the second
linespec in a ‘list’ command that has two, this specifies the line offset lines down
from the first linespec.
-offset Specifies the line offset lines before the last line printed.
function Specifies the line of the open-brace that begins the body of the function function.
Command Description
filename:function Specifies the line of the open-brace that begins the body of the function function
in the file filename. The file name is needed with a function name only for
disambiguation of identically named functions in different source files.
*address Specifies the line containing the program address address. address may be any
expression.One other command is used to map source lines to program
addresses.
info line linenum Print the starting and ending addresses of the compiled code for source line
linenum.
The default examine address for the ‘x’ command is changed to the starting address of the
line, so that ‘x/i’ is sufficient to begin examining the machine code (see section Memory).
Also, this address is saved as the value of the convenience variable $_ (see section
Convenience Vars).
Note: The executable search path is not used for this purpose. Neither is the current
working directory, unless it happens to be in the source path.
When you start GDB, its source path contains just the current working directory. To add
other directories, use the ‘directory’ command as shown in Table D-14.
Command Description
directory dirnames... Add directory dirname to the end of the source path. Several directory names may
be given to this command, separated by whitespace or ‘:’.
directory Reset the source path to just the current working directory of GDB.
This requires confirmation.Since this command deletes directories from the search
path, it may change the directory in which a previously read source file will be
discovered. To make this work correctly, this command also clears out the tables
GDB maintains about the source files it has already found.
info directories Print the source path: show which directories it contains.
Because the ‘directory’ command adds to the end of the source path, it does not affect any
file that GDB has already found. If the source path contains directories that you do not
want, and these directories contain misleading files with names matching your source
files, the way to correct the situation is as follows:
1. Choose the directory you want at the beginning of the source path. Use the ‘cd’
command to make that the current working directory.
2. Use ‘directory’ with no argument to reset the source path to just that directory.
3. Use ‘directory’ with suitable arguments to add any other directories you want in the
source path.
D.9.1 Expressions
Many different GDB commands accept an expression and compute its value. Any kind of
constant, variable or operator defined by the programming language you are using is legal
in an expression in GDB. This includes conditional expressions, function calls, casts and
Operator Description
@ ‘@’ is a binary operator for treating parts of memory as arrays. See section Arrays, for more
information.
:: ‘::’ allows you to specify a variable in terms of the file or function it is defined in. See section
Variables.
{type} addr Refers to an object of type type stored at address addr in memory. addr may be any
expression whose value is an integer or pointer (but parentheses are required around
non-unary operators, just as in a cast). This construct is allowed regardless of what kind of data
is officially supposed to reside at addr.
As a special exception, you can refer to a variable or function whose scope is a single
source file even if the current execution point is not in this file. But it is possible to have
more than one such variable or function with the same name (if they are in different source
files). In such a case, it is not defined which one you will get. If you wish, you can specify
any one of them using the colon colon construct:
block::variable
Here block is the name of the source file whose variable you want.
set prettyprint on
Cause GDB to print structures in an indented format with one member per line, like this:
$1 = {
next = 0x0,
flags = {
sweet = 1,
sour = 1
},
meat = 0x54 “Pork”
}
set prettyprint off
Cause GDB to print structures in a compact format, like this:
$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, meat = 0x54 “Pork”}
This is the default format.
set unionprint on
Tell GDB to print unions which are contained in structures. This is the default setting.
set unionprint off
Tell GDB not to print unions which are contained in structures.
For example, given the declarations
typedef enum {Tree, Bug} Species;
typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
typedef enum {Caterpiller, Cocoon, Butterfly}
Bug_forms;
struct thing {
Species it;
union {
Tree_forms tree;
Bug_forms bug;
} form;
};
struct thing foo = {Tree, {Acorn}};
‘x’ Regard the bits of the value as an integer, and print the integer in hexadecimal.
‘a’ Print as an address, both absolute in hex and then relative to a symbol defined as an address
below it.
‘f’ Regard the bits of the value as a floating point number and print using typical floating point
syntax.
For example, to print the program counter in hex (see section Registers), type
p/x $pc
Note that no space is required before the slash; this is because command names in GDB
cannot contain a slash.
To reprint the last value in the value history with a different format, you can use the ‘print’
command with just a format and no expression. For example, ‘p/x’ reprints the last value
in hex.
Many assemblers and cpu designers still use ‘word’ for a 16-bit quantity, as a holdover
from specific predecessor machines of the 1970’s that really did use two byte words. But
more generally the term ‘word’ has always referred to the size of quantity that a machine
normally operates on and stores in its registers. This is 32 bits for all the machines that
GDB runs on.
‘g’ Examine giant words (8 bytes).
These letters, as listed in Table D-18, specify just the way to print the contents:
Table D-18. Print Output Format Letters
‘a’ Print as an address, both absolute in hex and then relative to a symbol defined as an address
below it.
‘f’ Print as floating point. This works only with sizes ‘w’ and ‘g’.
‘s’ Print a null-terminated string of characters. The specified unit size is ignored; instead, the unit is
however many bytes it takes to reach a null character (including the null character).
‘i’ Print a machine instruction in assembler syntax (or nearly). The specified unit size is ignored;
the number of bytes in an instruction varies depending on the type of machine, the opcode and
the addressing modes used.
If either the manner of printing or the size of unit fails to be specified, the default is to use
the same one that was used last. If you don’t want to use any letters after the slash, you can
omit the slash as well.
You can also omit the address to examine. Then the address used is just after the last unit
examined. This is why string and instruction formats actually compute a unit size based on
the data: so that the next string or instruction examined will start in the right place. The
‘print’ command sometimes sets the default address for the ‘x’ command; when the value
printed resides in memory, the default is set to examine the same location. ‘info line’ also
sets the default for ‘x’, to the address of the start of the machine code for the specified line
and ‘info breakpoints’ sets it to the address of the last breakpoint listed.
When you use RET to repeat an ‘x’ command, it does not repeat exactly the same: the
address specified previously (if any) is ignored, so that the repeated command examines
the successive locations in memory rather than the same ones.
You can examine several consecutive units of memory with one command by writing a
repeat-count after the slash (before the format letters, if any). The repeat count must be a
decimal integer. It has the same effect as repeating the ‘x’ command that many times
except that the output may be more compact with several units per line. For example,
x/10i $pc
prints ten instructions starting with the one to be executed next in the selected frame. After
doing this, you could print another ten following instructions with
x/10
in which the format and address are allowed to default.
The addresses and contents printed by the ‘x’ command are not put in the value history
because there is often too much of them and they would get in the way. Instead, GDB
makes these values available for subsequent use in expressions as values of the
convenience variables $_ and $__.
After an ‘x’ command, the last address examined is available for use in expressions in the
convenience variable $_. The contents of that address, as examined, are available in the
convenience variable $__.
If the ‘x’ command has a repeat count, the address and contents saved are from the last
memory unit printed; this is not the same as the last address printed if several units were
printed on the last line of output.
The specialized command ‘disassemble’ is also provided to dump a range of memory as
machine instructions. The default memory range is the function surrounding the program
counter of the selected frame. A single argument to this command is a program counter
value; the function surrounding this value will be dumped. Two arguments specify a range
of address (first inclusive, second exclusive) to be dumped.
Command Description
display exp Add the expression exp to the list of expressions to display each time the
program stops. See section Expressions.
display/fmt exp For fmt specifying only a display format and not a size or count, add the
expression exp to the auto-display list but arranges to display it each time in
the specified format fmt.
display/fmt addr For fmt ‘i’ or ‘s’, or including a unit-size or a number of units, add the
expression addr as a memory address to be examined each time the program
stops. Examining means in effect doing ‘x/fmt addr’. See section Memory.
undisplay dnums... Remove item numbers dnums from the list of expressions to display.
delete display dnums...
disable display dnums... Disable the display of item numbers dnums. A disabled display item is not
printed automatically, but is not forgotten. It may be re-enabled later.
enable display dnums... Enable display of item numbers dnums. It becomes effective once again in
auto display of its expression, until you specify otherwise.
display Display the current values of the expressions on the list, just as is done when
the program stops.
info display Print the list of expressions previously set up to display automatically, each
one with its item number, but without showing the values. This includes
disabled expressions, which are marked as such. It also includes expressions
which would not be displayed right now because they refer to automatic
variables not currently available.
p *$.next
It might be useful to repeat this command many times by typing RET.
Note: The history records values, not expressions.
If the value of x is 4 and you type this command:
print x
set x=5
then the value recorded in the value history by the ‘print’ command remains 4 even though
the value of x has changed. See Table D-20.
Command Description
info values Print the last ten values in the value history, with their item numbers. This is like ‘p $$9’
repeated ten times, except that ‘info values’ does not change the history.
info values n Print ten history values centered on history item number n.
info values + Print ten history values just after the values last printed.
info convenience
Print a list of convenience variables used so far, and their values. Abbreviated ‘i con’.
One of the ways to use a convenience variable is as a counter to be incremented or a
pointer to be advanced. For example:
set $i = 0
print bar[$i++]->contents
...repeat that command by typing RET.
Some convenience variables are created automatically by GDB and given values likely to
be useful. See Table D-21.
$_ The variable $_ is automatically set by the ‘x’ command to the last address examined (see
section Memory). Other commands which provide a default address for ‘x’ to examine also set
$_ to that address; these commands include ‘info line’ and ‘info breakpoint’.
$__ The variable $__ is automatically set by the ‘x’ command to the value found in the last address
examined.
D.9.9 Registers
Machine register contents can be referred to in expressions as variables with names
starting with ‘$’. The names of registers are different for each machine; use ‘info registers’
to see the names used on your machine. The names $pc and $sp are used on all machines
for the program counter register and the stack pointer. Often $fp is used for a register that
contains a pointer to the current stack frame, and $ps is used for a register that contains the
processor status. These standard register names may be available on your machine even
though the info registers command displays them with a different name. For example, on
the SPARC, info registers displays the processor status register as $psr but you can also
refer to it as $ps.
GDB always considers the contents of an ordinary register as an integer when the register
is examined in this way. Some machines have special registers which can hold nothing but
floating point; these registers are considered floating point. There is no way to refer to the
contents of an ordinary register as floating point value (although you can print it as a
floating point value with ‘print/f $regname’).
Some registers have distinct “raw” and “virtual” data formats. This means that the data
format in which the register contents are saved by the operating system is not the same one
that your program normally sees. For example, the registers of the 68881 floating point
coprocessor are always saved in “extended” format, but all C programs expect to work
with “double” format. In such cases, GDB normally works with the virtual format only
(the format that makes sense for your program), but the ‘info registers’ command prints
the data in both formats.
Register values are relative to the selected stack frame (see section Selection). This means
that you get the value that the register would contain if all stack frames farther in were
exited and their saved registers restored. In order to see the real contents of all registers,
you must select the innermost frame (with ‘frame 0’).
Some registers are never saved (typically those numbered zero or one) because they are
used for returning function values; for these registers, relativization makes no difference.
info registers
Print the names and relativized values of all registers.
info registers regname
Print the relativized value of register regname. regname may be any register name valid
on the machine you are using, with or without the initial ‘$’.
D.9.9.1 Examples
You could print the program counter in hex with
p/x $pc
or print the instruction to be executed next with
x/i $pc
or add four to the stack pointer with
set $sp += 4
The last is a way of removing one word from the stack, on machines where stacks grow
downward in memory (most machines, nowadays). This assumes that the innermost stack
frame is selected. Setting $sp is not allowed when other stack frames are selected.
Command Description
whatis exp Print the data type of expression exp. exp is not actually evaluated, and any
side-effecting operations (such as assignments or function calls) inside it do not
take place. See section Expressions.
whatis Print the data type of $, the last value in the value history.
info address symbol Describe where the data for symbol is stored. For a register variable, this says
which register it is kept in. For a non-register local variable, this prints the
stack-frame offset at which the variable is always stored.
Note the contrast with ‘print &symbol’, which does not work at all for a register
variables, and for a stack local variable prints the exact address of the current
instantiation of the variable.
ptype typename Print a description of data type typename. typename may be the name of a type,
or for C code it may have the form ‘struct struct-tag’, ‘union union-tag’ or ‘enum
enum-tag’.
info sources Print the names of all source files in the program for which there is debugging
information.
info functions Print the names and data types of all defined functions.
info functions regexp Print the names and data types of all defined functions whose names contain a
match for regular expression regexp. Thus, ‘info fun step’ finds all functions
whose names include ‘step’; ‘info fun ^step’ finds those whose names start with
‘step’.
info variables Print the names and data types of all variables that are declared outside of
functions (i.e., except for local variables).
info variables regexp Print the names and data types of all variables (except for local variables) whose
names contain a match for regular expression regexp.
info types Print all data types that are defined in the program.
info types regexp Print all data types that are defined in the program whose names contain a match
for regular expression regexp.
printsyms filename Write a complete dump of the debugger’s symbol data into the file filename.
jump linenum
Resume execution at line number linenum. Execution may stop immediately if there is a
breakpoint there.
The ‘jump’ command does not change the current stack frame, or the stack pointer, or the
contents of any memory location or any register other than the program counter. If line
linenum is in a different function from the one currently executing, the results may be
bizarre if the two functions expect different patterns of arguments or of local variables.
For this reason, the ‘jump’ command requests confirmation if the specified line is not in
the function currently executing. However, even bizarre results are predictable based on
careful study of the machine-language code of the program.
jump *address
Resume execution at the instruction at address address.
You can get much the same effect as the jump command by storing a new value into the
register $pc. The difference is that this does not start the program running; it only changes
the address where it will run when it is continued. For example,
set $pc = 0x485
causes the next ‘cont’ command or stepping command to execute at address 0x485, rather
than at the address where the program stopped. See section Stepping.
The most common occasion to use the ‘jump’ command is when you have stepped across
a function call with next, and found that the return value is incorrect. If all the relevant
data appeared correct before the function call, the error is probably in the function that just
returned.
In general, your next step would now be to rerun the program and execute up to this
function call, and then step into it to see where it goes astray. But this may be time
consuming. If the function did not have significant side effects, you could get the same
information by resuming execution just before the function call and stepping through it.
To do this, first put a breakpoint on that function; then, use the ‘jump’ command to
continue on the line with the function call.
Command Description
define commandname Define a command named commandname. If there is already a command by that
name, you are asked to confirm that you want to redefine it.The definition of the
command is made up of other GDB command lines, which are given following the
‘define’ command. The end of these commands is marked by a line containing ‘end’.
document commandname Give documentation to the user-defined command commandname. The command
commandname must already be defined. This command reads lines of
documentation just as ‘define’ reads the lines of the command definition, ending with
‘end’. After the ‘document’ command is finished, ‘help’ on command commandname
will print the documentation you have specified.
You may use the ‘document’ command again to change the documentation of a command.
Redefining the command with ‘define’ does not change the documentation.
User-defined commands do not take arguments. When they are executed, the commands
of the definition are not printed. An error in any command stops execution of the
user-defined command.
Commands that would ask for confirmation if used interactively proceed without asking
when used inside a user-defined command. Many GDB commands that normally print
messages to say what they are doing omit the messages when used in user-defined
command.
Command Description
echo text Print text. Non-printing characters can be included in text using C
escape sequences, such as ‘\n’ to print a newline. No newline will be
printed unless you specify one. In addition to the standard C escape
sequences a backslash followed by a space stands for a space. This
is useful for outputting a string with spaces at the beginning or the
end, since leading and trailing spaces are trimmed from all arguments.
Thus, to print “and foo = ‘’ , use the command ‘‘echo \ and foo = \ ‘’
A backslash at the end of text can be used, as in C, to continue the
command onto subsequent lines.
echo This is some text\n\
which is continued\n\
onto several lines.\n
produces the same output as
echo This is some text\n echo which is continued\n
echo onto several lines.\n
output expression Print the value of expression and nothing but that value: no newlines,
no ‘$nn = ‘. The value is not entered in the value history either. See
section Expressions for more information on expressions.
output/fmt expression Print the value of expression in format fmt. See section Output
formats, for more information.
printf string, expressions... Print the values of the expressions under the control of string. The
expressions are separated by commas and may be either numbers or
pointers. Their values are printed as specified by string, exactly as if
the program were to execute
printf (string, expressions...);
For example, you can print two values in hex like this:
printf “foo, bar-foo = 0x%x, 0x%x\n”, foo,
bar-foo
only backslash-escape sequences that you can use in the string are
the simple ones that consist of backslash followed by a letter.
‘-nx’ Do not execute commands from the init files ‘.gdbinit’. Normally, the commands in these files are
executed after all the command options and arguments have been processed. See section
Command Files.
‘-batch’ Run in batch mode. Exit with code 0 after processing all the command files specified with ‘-x’
(and ‘.gdbinit’, if not inhibited). Exit with nonzero status if an error occurs in executing the GDB
commands in the command files.
‘-fullname’ This option is used when Emacs runs GDB as a subprocess. It tells GDB to output the full file
name and line number in a standard, recognizable fashion each time a stack frame is displayed
(which includes each time the program stops). This recognizable format looks like two ‘\032’
characters, followed by the file name, line number and character position separated by colons,
and a newline. The Emacs-to-GDB interface program uses the two ‘\032’ characters as a signal
to display the source code for the frame.
Options Description
‘-e file’ Use file file as the executable file to execute when appropriate, and for examining pure data in
conjunction with a core dump.
‘-se file’ Read symbol table from file file and use it as the executable file.
Commands Description
M-s Execute to another source line, like the GDB ‘step’ command.
M-n Execute to next source line in this function, skipping all function calls, like the GDB ‘next’
command.
C-c C-f Execute until exit from the selected stack frame, like the GDB ‘finish’ command.
M-c Continue execution of the program, like the GDB ‘cont’ command.
M-u Go up the number of frames indicated by the numeric argument (see section Arguments,
Numeric Arguments, emacs, The GNU Emacs Manual), like the GDB ‘up’ command.
M-d Go down the number of frames indicated by the numeric argument, like the GDB ‘down’
command.
In any source file, the Emacs command C-x SPC (gdb break) tells GDB to set a breakpoint
on the source line point is on.
The source files displayed in Emacs are in ordinary Emacs buffers which are visiting the
source files in the usual way. You can edit the files with these buffers if you wish; but
keep in mind that GDB communicates with Emacs in terms of line numbers. If you add or
delete lines from the text, the line numbers that GDB knows will cease to correspond
properly to the code.
Audio:
Codec Routines:
DTMF Routines:
ex56.bat 1.0 94
load.cmd 1.0 46
fftr2d.asm 1.0 Radix 2, In-Place, DIT FFT (using DSP56001 sine-cosine 3727
ROM tables)
fftr2en.asm 1.0 1024 point, not-in-place, complex FFT macro with normally 9723
ordered input/output
Filters:
IIR Filter
iir2.asm 1.0 Direct Form Second Order All Pole IIR Filter with Scaling 801
iir3.asm 1.0 Direct Form Arbitrary Order All Pole IIR Filter 776
iir4.asm 1.0 Second Order Direct Canonic IIR Filter (Biquad IIR Filter) 713
iir5.asm 1.0 Second Order Direct Canonic IIR Filter with Scaling (Biquad 842
IIR Filter)
Floating-Point Routines:
Functions:
Lattice Filters:
latfir2.asm 1.0 Lattice FIR Filter Macro (modified modulo count) 1174
Matrix Operations:
Reed-Solomon Encoder:
Sorting Routines:
Speech:
sloader.asm 1.1 Serial loader from the SCI port for the DSP56001 3986
sloader.p 1.1 Serial loader s-record file for download to EPROM 736
E.5.13 Controls:
ADAPTIVE CONTROL
K. Astrom and B. Wittenmark
New York, NY: Addison-Welsey Publishing Company, Inc.,
1989
ADAPTIVE FILTERING PREDICTION & CONTROL
G. Goodwin and K. Sin
Englewood Cliffs, NJ: Prentice-Hall, Inc., 1984
AUTOMATIC CONTROL SYSTEMS
B. C. Kuo
Englewood Cliffs, NJ: Prentice-Hall, Inc., 1987
COMPUTER CONTROLLED SYSTEMS: THEORY &
DESIGN
K. Astrom and B. Wittenmark
Englewood Cliffs, NJ: Prentice-Hall, Inc., 1984
DIGITAL CONTROL SYSTEMS
B. C. Kuo
New York, NY: Holt, Reinholt, and Winston, Inc., 1980
DIGITAL CONTROL SYSTEM ANALYSIS & DESIGN
C. Phillips and H. Nagle
Englewood Cliffs, NJ: Prentice-Hall, Inc., 1984
ISSUES IN THE IMPLEMENTATION OF DIGITAL
FEEDBACK COMPENSATORS
P. Moroney
Cambridge, MA: The MIT Press, 1983
E.5.14 Graphics:
CGM AND CGI
D. B. Arnold and P. R. Bono
New York, NY: Springer-Verlag, 1988
COMPUTER GRAPHICS (Second Edition)
D. Hearn and M. Pauline Baker
Englewood Cliffs, NJ: Prentice-Hall, Inc., 1986
E.5.20 Telecommunications:
DIGITAL COMMUNICATION
Edward A. Lee and David G. Messerschmitt
Higham, MA: Kluwer Academic Publishers, 1988
DIGITAL COMMUNICATIONS
John G. Proakis
New York, NY: McGraw-Hill Publishing Co., 1983
Motorola I-i
DOS4GVM 2-2 G56K 3-1
DOS4GVM.SWP 2-3 GDB56 3-22
dos4gw.exe 2-2 gdb56 C-11
DSIZE 6-2 global assembler directive 5-33
dsp 2-1
dsplib C-6 H
dsplnk C-7
DSPLOC 2-1, 2-2, 2-4 hello.c 2-4
host port 6-2
E
I
-E option 3-4, 3-9
errno 4-16, 6-8 -I option 3-4, 3-10, 3-11
exit A-25 -i option 3-4, 3-13
exp A-26 identifier length limits 4-1
exponent 4-6 IEEE P754-1985 4-3
in-line assembly
F instruction template 5-3
in-line assembly code 5-1
F_ _uldiv 4-16 Input Registers 4-8
F_ _ulmod 4-16 install.exe 2-1
fabs A-26, A-27, A-28, A-29 int 4-2
fadd_ba 4-16 interrupt vectors 6-1
-fcaller-saves option 3-4, 3-21 isalnum A-45, A-46, A-50
fcmp_a 4-16 isalpha A-51
-fcond-mismatch option 3-4, 3-22 iscntrl A-52
fdiv_ba 4-16 isdigit A-52
-ffixed-REG option 3-4, 3-22 isgraph A-54
-fforce-addr option 3-4, 3-21 islower A-54
file inclusion 3-10 isprint A-55
-finline-functions option 3-4, 3-21 ispunct A-56
-fkeep-inline-functions option 3-4 , 3-21 isspace A-56
float 4-3 isupper A-57
floor A-29, A-30, A-31, A-32, A-33, A-48, A-49 isxdigit A-58
fmod A-33
fmpy_ba 4-16 J
fneg_a 4-16
-fno-defer-pop option 3-4, 3-21 -j option 3-4, 3-32
-fno-opt option 3-4, 3-20
-fno-peephole option 3-4, 3-20 L
-fno-strength-reduce option 3-4, 3-20
-l option 3-4, 3-32
Frame Pointer 4-9
l_load 5-23
frame pointer 4-11, 6-2
l_run 5-23
free A-34, A-36, A-37, A-38, A-39, A-40, A-47, A-83
labs A-58
frexp A-41, A-42
ldexp A-59
fsub_ba 4-16
ldiv A-60
-fvolatile option 3-4, 3-22
ldiv_ba 4-16
-fwritable-strings option 3-4, 3-22
lmod_ba 4-16
G lmpy_ba 4-16
log A-61
-g option 3-4, 3-22 log10 A-62
G56_EXEC_PREFIX 3-5, 3-31 long 4-2
g561c 2-3 longjmp 3-26, 6-1, 6-12, A-63
Motorola I-iii
out-of-line calling C routines 5-35 strncat A-106
strncmp A-108
P strncpy A-109
strpbrk A-110, A-111
-P option 3-4, 3-17 strstr A-112
p_load 5-23 strtod A-114
p_run 5-23 strtok A-115
-pedantic option 3-4 , 3-17, 3-25 strtol A-116
perror A-76 strtoul A-118
pow A-77 strxfrm A-120
pragma 5-22 SWAPNAME 2-3
printf A-78
putchar A-84 T
puts A-85
tan A-120
Q tanh A-121
TERM 2-1
-Q option 3-4, 3-25 TERMCAP 2-1
qsort A-86 tolower A-121 , A-122
toupper A-123
R
U
-r option 3-4, 3-32
raise 6-1, A-87 -U option 3-4, 3-18
rand A-88 udiv_ba 4-16
realloc 6-8, A-88 unsigned char 4-2
RUN56 1-3 unsigned int 4-2
run56sim 2-4, C-12 unsigned short 4-2
S V
-S option 3-4, 3-25 -v option 3-4, 3-7, 3-17
setjmp 3-27, 6-1, 6-12, A-90, A-92 VIRTUALSIZE 2-3
short 4-2 volatile 3-26, 5-22
SIG_ERR 6-11
SIG_IGN 6-11 W
signal 6-1, A-94
signal file 6-9 -W option 3-4, 3-19, 3-26
sin A-95 -w option 3-26
sinh A-96 -Wall option 3-4, 3-30
sizeof 4-1 -Wcast-qual option 3-4, 3-30
sprintf A-96 wcstombs A-124, A-125, A-126
sqrt A-97, A-98 wctomb A-128
srec C-13 -Wid-clash-LEN option 3-4, 3-30
stack pointer 4-9, 4-11, 6-2 -Wimplicit option 3-4, 3-28
standard directory search list 3-2 -Wpointer-arith option 3-4, 3-30
standard include directory 3-10 -Wreturn-type option 3-4, 3-28
strcat A-98, A-99 -Wshadow option 3-4, 3-30
strchr A-100 -Wswitch option 3-4, 3-30
strcmp A-100 -Wunused option 3-4, 3-29
strcoll A-102 -Wwrite-strings option 3-4, 3-30
strcpy A-102
strcspn A-104, A-112 X
strerror A-105
strlen A-106 x_load 5-23
Y
y_load 5-23
y_run 5-23
Motorola I-v
I-vi Motorola DSP56000 Family Optimizing C Compiler User’s Manual Motorola
DSP56KCC Optimizing C Compiler Trouble Report
DSP Applications Assistance – (512) 891-3230
Phone________________________ Date__________________________________
Describe the system used with this product (include PC manufacturer, Operating sys-
tem type and version, memory size, and configuration.
Describe the problem and give details on how it can be reproduced, and any sugges-
tions on how it can or may be fixed. Use extra sheets if needed.
DSP56KCC Optimizing C Compiler User’s Manual Report Form
We welcome your comments and suggestions. They help us provide you with better prod-
uct documentation. Mail completed form to:
Motorola Inc.
6501 Wm. Cannon Drive West
Austin, Texas 78735-8598
Attn: Digital Signal Processors
1. Did you find errors in the manual? Please give page number and a description of
each error.
3. Did you find the manual clear and easy to use? Please comment on specific
sections that you feel need improvement.