Debian Codegraph @

src/symbols.c

raw symbols SCIP
1 /*
2 the DASM macro assembler (aka small systems cross assembler)
3
4 Copyright (c) 1988-2002 by Matthew Dillon.
5 Copyright (c) 1995 by Olaf "Rhialto" Seibert.
6 Copyright (c) 2003-2008 by Andrew Davie.
7 Copyright (c) 2008 by Peter H. Froehlich.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 /*
25 * SYMBOLS.C
26 */
27
28 #include "asm.h"cxx . . $ `<file>/src/asm.h`/
29
30 static unsigned int hash1cxx . . $ hash1(cc09747f0f147881).(const char *str, int len);
31 SYMBOLcxx . . $ `src/asm.h:160:9`! *allocsymbolcxx . . $ allocsymbol(cdf7111cce0c7830).(void);
32
33 static SYMBOLcxx . . $ `src/asm.h:160:9`! orgcxx . . $ org.;
34 static SYMBOLcxx . . $ `src/asm.h:160:9`! specialcxx . . $ special.;
35 static SYMBOLcxx . . $ `src/asm.h:160:9`! specchkcxx . . $ specchk.;
36
37 void setspecialcxx . . $ setspecial(3e454b8ccf442868).(int value, int flags)
38 {
39 specialcxx . . $ special..valuecxx . . $ _SYMBOL#value. = value;
40 specialcxx . . $ special..flagscxx . . $ _SYMBOL#flags. = flags;
41 }
42
43 SYMBOLcxx . . $ `src/asm.h:160:9`! *findsymbolcxx . . $ findsymbol(83a8820e5b78665b).(const char *str, int len)
44 {
45 unsigned int h1;
46 SYMBOLcxx . . $ `src/asm.h:160:9`! *sym;
47 char buf[MAX_SYM_LENcxx . . $ `src/asm.h:68:9`! + 14]; /* historical */
48
49 if ( len > MAX_SYM_LENcxx . . $ `src/asm.h:68:9`! )
50 len = MAX_SYM_LENcxx . . $ `src/asm.h:68:9`!;
51
52 if (str[0] == '.')
53 {
54 if (len == 1)
55 {
56 if (Csegmentcxx . . $ Csegment.->flagscxx . . $ _SEGMENT#flags. & SF_RORGcxx . . $ `src/asm.h:311:9`!)
57 {
58 orgcxx . . $ org..flagscxx . . $ _SYMBOL#flags. = Csegmentcxx . . $ Csegment.->rflagscxx . . $ _SEGMENT#rflags. & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!;
59 orgcxx . . $ org..valuecxx . . $ _SYMBOL#value. = Csegmentcxx . . $ Csegment.->rorgcxx . . $ _SEGMENT#rorg.;
60 }
61 else
62 {
63 orgcxx . . $ org..flagscxx . . $ _SYMBOL#flags. = Csegmentcxx . . $ Csegment.->flagscxx . . $ _SEGMENT#flags. & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!;
64 orgcxx . . $ org..valuecxx . . $ _SYMBOL#value. = Csegmentcxx . . $ Csegment.->orgcxx . . $ _SEGMENT#org.;
65 }
66 return &orgcxx . . $ org.;
67 }
68 if (len == 2 && str[1] == '.')
69 return &specialcxx . . $ special.;
70 if (len == 3 && str[1] == '.' && str[2] == '.')
71 {
72 specchkcxx . . $ specchk..flagscxx . . $ _SYMBOL#flags. = 0;
73 specchkcxx . . $ specchk..valuecxx . . $ _SYMBOL#value. = CheckSumcxx . . $ CheckSum.;
74 return &specchkcxx . . $ specchk.;
75 }
76 sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%ld%.*s", Localindexcxx . . $ Localindex., len, str);
77 len = strlencxx . . $ strlen(751346f8406fd082).(buf);
78 str = buf;
79 }
80
81 else if (str[len - 1] == '$')
82 {
83 sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%ld$%.*s", Localdollarindexcxx . . $ Localdollarindex., len, str);
84 len = strlencxx . . $ strlen(751346f8406fd082).(buf);
85 str = buf;
86 }
87
88 h1 = hash1cxx . . $ hash1(cc09747f0f147881).(str, len);
89 for (sym = SHashcxx . . $ SHash.[h1]; sym; sym = sym->nextcxx . . $ _SYMBOL#next.)
90 {
91 if ((sym->namelencxx . . $ _SYMBOL#namelen. == len) && !memcmpcxx . . $ memcmp(36f949851efa3055).(sym->namecxx . . $ _SYMBOL#name., str, len))
92 break;
93 }
94 return sym;
95 }
96
97 SYMBOLcxx . . $ `src/asm.h:160:9`! *CreateSymbolcxx . . $ CreateSymbol(83a8820e5b78665b).( const char *str, int len )
98 {
99 SYMBOLcxx . . $ `src/asm.h:160:9`! *sym;
100 unsigned int h1;
101 char buf[ MAX_SYM_LENcxx . . $ `src/asm.h:68:9`! + 14 ]; /* historical */
102
103 if (len > MAX_SYM_LENcxx . . $ `src/asm.h:68:9`! )
104 len = MAX_SYM_LENcxx . . $ `src/asm.h:68:9`!;
105
106 if (str[0] == '.')
107 {
108 sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%ld%.*s", Localindexcxx . . $ Localindex., len, str);
109 len = strlencxx . . $ strlen(751346f8406fd082).(buf);
110 str = buf;
111 }
112
113
114 else if (str[len - 1] == '$')
115 {
116 sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%ld$%.*s", Localdollarindexcxx . . $ Localdollarindex., len, str);
117 len = strlencxx . . $ strlen(751346f8406fd082).(buf);
118 str = buf;
119 }
120
121 sym = allocsymbolcxx . . $ allocsymbol(cdf7111cce0c7830).();
122 sym->namecxx . . $ _SYMBOL#name. = permalloccxx . . $ permalloc(ff224f080444ee45).(len+1);
123 memcpycxx . . $ memcpy(cc817cb175f282d).(sym->namecxx . . $ _SYMBOL#name., str, len); /* permalloc zeros the array for us */
124 sym->namelencxx . . $ _SYMBOL#namelen. = len;
125 h1 = hash1cxx . . $ hash1(cc09747f0f147881).(str, len);
126 sym->nextcxx . . $ _SYMBOL#next. = SHashcxx . . $ SHash.[h1];
127 sym->flagscxx . . $ _SYMBOL#flags.= SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!;
128 SHashcxx . . $ SHash.[h1] = sym;
129 return sym;
130 }
131
132 static unsigned int hash1cxx . . $ hash1(cc09747f0f147881).(const char *str, int len)
133 {
134 uint8_tcxx . . $ uint8_t# a = 0;
135 uint8_tcxx . . $ uint8_t# b = 0;
136 while (len--) { // this is Fletcher's checksum, better distribution, faster
137 a += *str++;
138 b += a;
139 }
140 return ((((a << 8) & 0xFF00) | (b & 0xFF)) ) & SHASHANDcxx . . $ `src/asm.h:167:9`!;
141 }
142
143 /*
144 * Label Support Routines
145 */
146
147 void programlabelcxx . . $ programlabel(49f6e7a06ebc5aa8).(void)
148 {
149 int len;
150 SYMBOLcxx . . $ `src/asm.h:160:9`! *sym;
151 SEGMENTcxx . . $ `src/asm.h:159:9`! *cseg = Csegmentcxx . . $ Csegment.;
152 char *str;
153 unsigned char rorg = cseg->flagscxx . . $ _SEGMENT#flags. & SF_RORGcxx . . $ `src/asm.h:311:9`!;
154 unsigned char cflags = (rorg) ? cseg->rflagscxx . . $ _SEGMENT#rflags. : cseg->flagscxx . . $ _SEGMENT#flags.;
155 unsigned long pc = (rorg) ? cseg->rorgcxx . . $ _SEGMENT#rorg. : cseg->orgcxx . . $ _SEGMENT#org.;
156
157 Plabcxx . . $ Plab. = cseg->orgcxx . . $ _SEGMENT#org.;
158 Pflagscxx . . $ Pflags. = cseg->flagscxx . . $ _SEGMENT#flags.;
159 str = Avcxx . . $ Av.[0];
160 if (*str == 0)
161 return;
162 len = strlencxx . . $ strlen(751346f8406fd082).(str);
163
164
165 if (str[len-1] == ':')
166 --len;
167
168 if (str[0] != '.' && str[len-1] != '$')
169 {
170 Lastlocaldollarindexcxx . . $ Lastlocaldollarindex.++;
171 Localdollarindexcxx . . $ Localdollarindex. = Lastlocaldollarindexcxx . . $ Lastlocaldollarindex.;
172 }
173
174 /*
175 * Redo: unknown and referenced
176 * referenced and origin not known
177 * known and phase error (origin known)
178 */
179
180 if ((sym = findsymbolcxx . . $ findsymbol(83a8820e5b78665b).(str, len)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
181 {
182 if ((sym->flagscxx . . $ _SYMBOL#flags. & (SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!|SYM_REFcxx . . $ `src/asm.h:327:9`!)) == (SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!|SYM_REFcxx . . $ `src/asm.h:327:9`!))
183 {
184 ++Redocxx . . $ Redo.;
185 Redo_whycxx . . $ Redo_why. |= REASON_FORWARD_REFERENCEcxx . . $ REASON_FORWARD_REFERENCE.;
186 if (Xdebugcxx . . $ Xdebug.)
187 printfcxx . . $ printf(581fddd72a8db8fc).("redo 13: '%s' %04x %04x\n", sym->namecxx . . $ _SYMBOL#name., sym->flagscxx . . $ _SYMBOL#flags., cflags);
188 }
189 else if ((cflags & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!) && (sym->flagscxx . . $ _SYMBOL#flags. & SYM_REFcxx . . $ `src/asm.h:327:9`!))
190 {
191 ++Redocxx . . $ Redo.;
192 Redo_whycxx . . $ Redo_why. |= REASON_FORWARD_REFERENCEcxx . . $ REASON_FORWARD_REFERENCE.;
193 }
194 else if (!(cflags & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!) && !(sym->flagscxx . . $ _SYMBOL#flags. & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!))
195 {
196 if (pc != sym->valuecxx . . $ _SYMBOL#value.)
197 {
198
199 /*
200 * If we had an unevaluated IF expression in the
201 * previous pass, don't complain about phase errors
202 * too loudly.
203 */
204
205 //FIX: calling asmerr with ERROR_LABEL_MISMATCH is fatal. The clause
206 // below was causing aborts if verbosity was up, even when the
207 // phase errors were the result of unevaluated IF expressions in
208 // the previous pass.
209
210 //if (F_verbose >= 1 || !(Redo_if & (REASON_OBSCURE)))
211
212 if (!(Redo_ifcxx . . $ Redo_if. & (REASON_OBSCUREcxx . . $ REASON_OBSCURE.)))
213 {
214 char sBuffer[ MAX_SYM_LENcxx . . $ `src/asm.h:68:9`! * 4 ];
215 sprintfcxx . . $ sprintf(26c8642d26409d6d).( sBuffer, "%s %s", sym->namecxx . . $ _SYMBOL#name., sftoscxx . . $ sftos(ef4cfbd1f56d9042).( sym->valuecxx . . $ _SYMBOL#value., 0 ) );
216 asmerrcxx . . $ asmerr(1daa6892c969c96d).( ERROR_LABEL_MISMATCHcxx . . $ ERROR_LABEL_MISMATCH., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, sBuffer );
217 }
218 ++Redocxx . . $ Redo.;
219 Redo_whycxx . . $ Redo_why. |= REASON_PHASE_ERRORcxx . . $ REASON_PHASE_ERROR.;
220 }
221 }
222 }
223 else
224 {
225 sym = CreateSymbolcxx . . $ CreateSymbol(83a8820e5b78665b).( str, len );
226 }
227 sym->valuecxx . . $ _SYMBOL#value. = pc;
228 sym->flagscxx . . $ _SYMBOL#flags. = (sym->flagscxx . . $ _SYMBOL#flags. & ~SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!) | (cflags & SYM_UNKNOWNcxx . . $ `src/asm.h:326:9`!);
229 }
230
231 SYMBOLcxx . . $ `src/asm.h:160:9`! *SymAlloccxx . . $ SymAlloc.;
232
233 SYMBOLcxx . . $ `src/asm.h:160:9`! *allocsymbolcxx . . $ allocsymbol(cdf7111cce0c7830).(void)
234 {
235 SYMBOLcxx . . $ `src/asm.h:160:9`! *sym;
236
237 if (SymAlloccxx . . $ SymAlloc.)
238 {
239 sym = SymAlloccxx . . $ SymAlloc.;
240 SymAlloccxx . . $ SymAlloc. = SymAlloccxx . . $ SymAlloc.->nextcxx . . $ _SYMBOL#next.;
241 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sym, 0, sizeof(SYMBOLcxx . . $ `src/asm.h:160:9`!));
242 }
243 else
244 {
245 sym = (SYMBOLcxx . . $ `src/asm.h:160:9`! *)permalloccxx . . $ permalloc(ff224f080444ee45).(sizeof(SYMBOLcxx . . $ `src/asm.h:160:9`!));
246 }
247 return sym;
248 }
249
250 /* defined but not used [phf] */
251 /*
252 static void freesymbol(SYMBOL *sym)
253 {
254 sym->next = SymAlloc;
255 SymAlloc = sym;
256 }
257 */
258
259
260
261 void FreeSymbolListcxx . . $ FreeSymbolList(54782e8e250fbf33).(SYMBOLcxx . . $ `src/asm.h:160:9`! *sym)
262 {
263 SYMBOLcxx . . $ `src/asm.h:160:9`! *next;
264
265 while (sym)
266 {
267 next = sym->nextcxx . . $ _SYMBOL#next.;
268 sym->nextcxx . . $ _SYMBOL#next. = SymAlloccxx . . $ SymAlloc.;
269 if (sym->flagscxx . . $ _SYMBOL#flags. & SYM_STRINGcxx . . $ `src/asm.h:328:9`!)
270 freecxx . . $ free(5d22bdacc48458e8).(sym->stringcxx . . $ _SYMBOL#string.);
271 SymAlloccxx . . $ SymAlloc. = sym;
272 sym = next;
273 }
274 }
275