1 /* lknoice.c - Extensions to CUG 292 linker ASLINK to produce NoICE debug files
3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 * Extensions to CUG 292 linker ASLINK to produce NoICE debug files
22 * 31-Oct-1997 by John Hartman
23 * 30-Jan-98 JLH add page to DefineNoICE for 8051
24 * 2-Feb-98 JLH Allow optional .nest on local vars - C scoping rules...
32 static void DefineGlobal( char *name, Addr_T value, int page );
33 static void DefineScoped( char *name, Addr_T value, int page );
34 static void DefineFile( char *name, Addr_T value, int page );
35 static void DefineFunction( char *name, Addr_T value, int page );
36 static void DefineStaticFunction( char *name, Addr_T value, int page );
37 static void DefineEndFunction( Addr_T value, int page );
38 static void DefineLine( char *lineString, Addr_T value, int page );
39 static void PagedAddress( Addr_T value, int page );
42 * Called from lstarea in lklist.c for each symbol.
44 * Generates appropriate NoICE commands into output file, if any is open
47 void DefineNoICE( char *name, Addr_T value, int page )
49 char token1[NCPS]; /* parse for file.function.symbol */
56 /* no output if file is not open */
57 if (jfp == NULL) return;
59 j = sscanf( name, "%[^.]%c%[^.]%c%s",
60 token1, &sep1, token2, &sep2, token3 );
63 /* file.function.symbol, or file.function..SPECIAL */
65 DefineFile( token1, 0, 0 );
68 if (strcmp( token3, ".FN" ) == 0)
71 DefineFunction( token2, value, page );
73 else if (strcmp( token3, ".SFN" ) == 0)
75 /* Static (file-scope) function */
76 DefineStaticFunction( token2, value, page );
78 else if (strcmp( token3, ".EFN" ) == 0)
81 DefineEndFunction( value, page );
86 /* Function-scope var. */
87 DefineFunction( token2, 0, 0 );
89 /* Look for optional level integer */
90 j = sscanf( token3, "%[^.]%c%u", token1, &sep1, &level );
91 if ((j == 3) && (level != 0))
93 sprintf( &token1[ strlen(token1) ], "_%u", level );
95 DefineScoped( token1, value, page );
99 /* file.func. is illegal */
103 /* either file.symbol or file.line# */
105 DefineFile( token1, 0, 0 );
106 if ((token2[0] >= '0') && (token2[0] <= '9'))
109 DefineLine( token2, value, page );
113 /* File-scope symbol. (Kill any function) */
114 DefineEndFunction( 0, 0 );
115 DefineScoped( token2, value, page );
119 /* symbol. is illegal */
125 DefineGlobal( token1, value, page );
130 static char currentFile[NCPS];
131 static char currentFunction[NCPS];
135 * Define "name" as a global symbol
137 void DefineGlobal( char *name, Addr_T value, int page )
139 fprintf( jfp, "DEF %s ", name );
140 PagedAddress( value, page );
145 * Define "name" as a static (scoped) symbol
147 void DefineScoped( char *name, Addr_T value, int page )
149 fprintf( jfp, "DEFS %s ", name );
150 PagedAddress( value, page );
155 * Define "name" as the current file
157 void DefineFile( char *name, Addr_T value, int page )
159 if (as_strcmpi( name, currentFile ) != 0)
161 strcpy( currentFile, name );
164 fprintf( jfp, "FILE %s ", name );
165 PagedAddress( value, page );
169 fprintf( jfp, "FILE %s\n", name );
176 * Define "name" as the current function
178 void DefineFunction( char *name, Addr_T value, int page )
180 if (as_strcmpi( name, currentFunction ) != 0)
182 strcpy( currentFunction, name );
185 fprintf( jfp, "DEF %s ", name );
186 PagedAddress( value, page );
187 fprintf( jfp, "FUNC %s ", name );
188 PagedAddress( value, page );
192 fprintf( jfp, "FUNC %s\n", name );
199 * Define "name" as the current static (scoped) function
201 void DefineStaticFunction( char *name, Addr_T value, int page )
203 if (as_strcmpi( name, currentFunction ) != 0)
205 strcpy( currentFunction, name );
208 fprintf( jfp, "DEFS %s ", name );
209 PagedAddress( value, page );
210 fprintf( jfp, "SFUNC %s ", name );
211 PagedAddress( value, page );
215 fprintf( jfp, "SFUNC %s\n", name );
222 * Define the end of the current function
224 void DefineEndFunction( Addr_T value, int page )
226 if (currentFunction[0] != 0)
230 fprintf( jfp, "ENDF " );
231 PagedAddress( value, page );
235 fprintf( jfp, "ENDF\n" );
238 currentFunction[0] = 0;
244 * Define "lineNumber" as a line in the current file
246 void DefineLine( char *lineString, Addr_T value, int page )
248 int indigit, lineNumber = 0;
250 while( (indigit=digit( *lineString++, 10 )) >= 0)
252 lineNumber = 10*lineNumber + indigit;
254 fprintf( jfp, "LINE %u ", lineNumber );
255 PagedAddress( value, page );
258 void PagedAddress( Addr_T value, int page )
260 fprintf( jfp, "%X:0x%X\n", page, value );