or1k-asm.c revision 1.7 1 1.6 christos /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
2 1.1 christos /* Assembler interface for targets using CGEN. -*- C -*-
3 1.1 christos CGEN: Cpu tools GENerator
4 1.1 christos
5 1.1 christos THIS FILE IS MACHINE GENERATED WITH CGEN.
6 1.1 christos - the resultant file is machine generated, cgen-asm.in isn't
7 1.1 christos
8 1.7 christos Copyright (C) 1996-2020 Free Software Foundation, Inc.
9 1.1 christos
10 1.1 christos This file is part of libopcodes.
11 1.1 christos
12 1.1 christos This library is free software; you can redistribute it and/or modify
13 1.1 christos it under the terms of the GNU General Public License as published by
14 1.1 christos the Free Software Foundation; either version 3, or (at your option)
15 1.1 christos any later version.
16 1.1 christos
17 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT
18 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 1.1 christos License for more details.
21 1.1 christos
22 1.1 christos You should have received a copy of the GNU General Public License
23 1.1 christos along with this program; if not, write to the Free Software Foundation, Inc.,
24 1.1 christos 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 1.1 christos
26 1.1 christos
27 1.1 christos /* ??? Eventually more and more of this stuff can go to cpu-independent files.
28 1.1 christos Keep that in mind. */
29 1.1 christos
30 1.1 christos #include "sysdep.h"
31 1.1 christos #include <stdio.h>
32 1.1 christos #include "ansidecl.h"
33 1.1 christos #include "bfd.h"
34 1.1 christos #include "symcat.h"
35 1.1 christos #include "or1k-desc.h"
36 1.1 christos #include "or1k-opc.h"
37 1.1 christos #include "opintl.h"
38 1.1 christos #include "xregex.h"
39 1.1 christos #include "libiberty.h"
40 1.1 christos #include "safe-ctype.h"
41 1.1 christos
42 1.1 christos #undef min
43 1.1 christos #define min(a,b) ((a) < (b) ? (a) : (b))
44 1.1 christos #undef max
45 1.1 christos #define max(a,b) ((a) > (b) ? (a) : (b))
46 1.1 christos
47 1.1 christos static const char * parse_insn_normal
48 1.1 christos (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
49 1.1 christos
50 1.1 christos /* -- assembler routines inserted here. */
52 1.1 christos
53 1.1 christos /* -- asm.c */
54 1.1 christos
55 1.6 christos static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
56 1.6 christos static const char * INVALID_STORE_RELOC = N_("relocation invalid for store");
57 1.1 christos static const char * INVALID_RELOC_TYPE = N_("internal relocation type invalid");
58 1.1 christos
59 1.1 christos #define CGEN_VERBOSE_ASSEMBLER_ERRORS
60 1.1 christos
61 1.1 christos static const char *
62 1.1 christos parse_disp26 (CGEN_CPU_DESC cd,
63 1.1 christos const char ** strp,
64 1.6 christos int opindex,
65 1.1 christos int opinfo ATTRIBUTE_UNUSED,
66 1.1 christos enum cgen_parse_operand_result * resultp,
67 1.1 christos bfd_vma * valuep)
68 1.6 christos {
69 1.1 christos const char *str = *strp;
70 1.6 christos const char *errmsg = NULL;
71 1.1 christos bfd_reloc_code_real_type reloc = BFD_RELOC_OR1K_REL_26;
72 1.6 christos
73 1.6 christos if (strncasecmp (str, "plta(", 5) == 0)
74 1.6 christos {
75 1.6 christos *strp = str + 5;
76 1.6 christos reloc = BFD_RELOC_OR1K_PLTA26;
77 1.6 christos }
78 1.1 christos else if (strncasecmp (str, "plt(", 4) == 0)
79 1.6 christos {
80 1.6 christos *strp = str + 4;
81 1.1 christos reloc = BFD_RELOC_OR1K_PLT26;
82 1.1 christos }
83 1.6 christos
84 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc, resultp, valuep);
85 1.6 christos
86 1.1 christos if (reloc != BFD_RELOC_OR1K_REL_26)
87 1.1 christos {
88 1.1 christos if (**strp != ')')
89 1.6 christos errmsg = MISSING_CLOSING_PARENTHESIS;
90 1.6 christos else
91 1.1 christos ++*strp;
92 1.1 christos }
93 1.6 christos
94 1.6 christos return errmsg;
95 1.1 christos }
96 1.6 christos
97 1.6 christos static const char *
98 1.6 christos parse_disp21 (CGEN_CPU_DESC cd,
99 1.6 christos const char ** strp,
100 1.6 christos int opindex,
101 1.6 christos int opinfo ATTRIBUTE_UNUSED,
102 1.6 christos enum cgen_parse_operand_result * resultp,
103 1.6 christos bfd_vma * valuep)
104 1.6 christos {
105 1.6 christos const char *str = *strp;
106 1.6 christos const char *errmsg = NULL;
107 1.1 christos bfd_reloc_code_real_type reloc = BFD_RELOC_OR1K_PCREL_PG21;
108 1.6 christos
109 1.6 christos if (strncasecmp (str, "got(", 4) == 0)
110 1.6 christos {
111 1.6 christos *strp = str + 4;
112 1.1 christos reloc = BFD_RELOC_OR1K_GOT_PG21;
113 1.6 christos }
114 1.1 christos else if (strncasecmp (str, "tlsgd(", 6) == 0)
115 1.6 christos {
116 1.6 christos *strp = str + 6;
117 1.1 christos reloc = BFD_RELOC_OR1K_TLS_GD_PG21;
118 1.6 christos }
119 1.1 christos else if (strncasecmp (str, "tlsldm(", 7) == 0)
120 1.6 christos {
121 1.6 christos *strp = str + 7;
122 1.1 christos reloc = BFD_RELOC_OR1K_TLS_LDM_PG21;
123 1.6 christos }
124 1.1 christos else if (strncasecmp (str, "gottp(", 6) == 0)
125 1.6 christos {
126 1.6 christos *strp = str + 6;
127 1.1 christos reloc = BFD_RELOC_OR1K_TLS_IE_PG21;
128 1.1 christos }
129 1.6 christos
130 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc, resultp, valuep);
131 1.6 christos
132 1.6 christos if (reloc != BFD_RELOC_OR1K_PCREL_PG21)
133 1.1 christos {
134 1.6 christos if (**strp != ')')
135 1.6 christos errmsg = MISSING_CLOSING_PARENTHESIS;
136 1.6 christos else
137 1.1 christos ++*strp;
138 1.1 christos }
139 1.6 christos
140 1.6 christos return errmsg;
141 1.6 christos }
142 1.6 christos
143 1.6 christos enum or1k_rclass
144 1.6 christos {
145 1.6 christos RCLASS_DIRECT = 0,
146 1.6 christos RCLASS_GOT = 1,
147 1.6 christos RCLASS_GOTPC = 2,
148 1.6 christos RCLASS_GOTOFF = 3,
149 1.6 christos RCLASS_TLSGD = 4,
150 1.6 christos RCLASS_TLSLDM = 5,
151 1.6 christos RCLASS_DTPOFF = 6,
152 1.6 christos RCLASS_GOTTPOFF = 7,
153 1.6 christos RCLASS_TPOFF = 8,
154 1.1 christos };
155 1.6 christos
156 1.6 christos enum or1k_rtype
157 1.6 christos {
158 1.6 christos RTYPE_LO = 0,
159 1.6 christos RTYPE_SLO = 1,
160 1.6 christos RTYPE_PO = 2,
161 1.6 christos RTYPE_SPO = 3,
162 1.6 christos RTYPE_HI = 4,
163 1.6 christos RTYPE_AHI = 5,
164 1.1 christos };
165 1.6 christos
166 1.6 christos #define RCLASS_SHIFT 3
167 1.1 christos #define RTYPE_MASK 7
168 1.6 christos
169 1.6 christos static const bfd_reloc_code_real_type or1k_imm16_relocs[][6] = {
170 1.6 christos { BFD_RELOC_LO16,
171 1.6 christos BFD_RELOC_OR1K_SLO16,
172 1.6 christos BFD_RELOC_OR1K_LO13,
173 1.6 christos BFD_RELOC_OR1K_SLO13,
174 1.6 christos BFD_RELOC_HI16,
175 1.6 christos BFD_RELOC_HI16_S, },
176 1.6 christos { BFD_RELOC_OR1K_GOT16,
177 1.6 christos BFD_RELOC_UNUSED,
178 1.6 christos BFD_RELOC_OR1K_GOT_LO13,
179 1.6 christos BFD_RELOC_UNUSED,
180 1.6 christos BFD_RELOC_UNUSED,
181 1.6 christos BFD_RELOC_UNUSED },
182 1.6 christos { BFD_RELOC_OR1K_GOTPC_LO16,
183 1.6 christos BFD_RELOC_UNUSED,
184 1.6 christos BFD_RELOC_UNUSED,
185 1.6 christos BFD_RELOC_UNUSED,
186 1.6 christos BFD_RELOC_OR1K_GOTPC_HI16,
187 1.6 christos BFD_RELOC_UNUSED },
188 1.6 christos { BFD_RELOC_LO16_GOTOFF,
189 1.6 christos BFD_RELOC_OR1K_GOTOFF_SLO16,
190 1.6 christos BFD_RELOC_UNUSED,
191 1.6 christos BFD_RELOC_UNUSED,
192 1.6 christos BFD_RELOC_HI16_GOTOFF,
193 1.6 christos BFD_RELOC_HI16_S_GOTOFF },
194 1.6 christos { BFD_RELOC_OR1K_TLS_GD_LO16,
195 1.6 christos BFD_RELOC_UNUSED,
196 1.6 christos BFD_RELOC_OR1K_TLS_GD_LO13,
197 1.6 christos BFD_RELOC_UNUSED,
198 1.6 christos BFD_RELOC_OR1K_TLS_GD_HI16,
199 1.6 christos BFD_RELOC_UNUSED },
200 1.6 christos { BFD_RELOC_OR1K_TLS_LDM_LO16,
201 1.6 christos BFD_RELOC_UNUSED,
202 1.6 christos BFD_RELOC_OR1K_TLS_LDM_LO13,
203 1.6 christos BFD_RELOC_UNUSED,
204 1.6 christos BFD_RELOC_OR1K_TLS_LDM_HI16,
205 1.6 christos BFD_RELOC_UNUSED },
206 1.6 christos { BFD_RELOC_OR1K_TLS_LDO_LO16,
207 1.6 christos BFD_RELOC_UNUSED,
208 1.6 christos BFD_RELOC_UNUSED,
209 1.6 christos BFD_RELOC_UNUSED,
210 1.6 christos BFD_RELOC_OR1K_TLS_LDO_HI16,
211 1.6 christos BFD_RELOC_UNUSED },
212 1.6 christos { BFD_RELOC_OR1K_TLS_IE_LO16,
213 1.6 christos BFD_RELOC_UNUSED,
214 1.6 christos BFD_RELOC_OR1K_TLS_IE_LO13,
215 1.6 christos BFD_RELOC_UNUSED,
216 1.6 christos BFD_RELOC_OR1K_TLS_IE_HI16,
217 1.6 christos BFD_RELOC_OR1K_TLS_IE_AHI16 },
218 1.6 christos { BFD_RELOC_OR1K_TLS_LE_LO16,
219 1.6 christos BFD_RELOC_OR1K_TLS_LE_SLO16,
220 1.6 christos BFD_RELOC_UNUSED,
221 1.6 christos BFD_RELOC_UNUSED,
222 1.6 christos BFD_RELOC_OR1K_TLS_LE_HI16,
223 1.6 christos BFD_RELOC_OR1K_TLS_LE_AHI16 },
224 1.1 christos };
225 1.6 christos
226 1.6 christos static int
227 1.6 christos parse_reloc (const char **strp)
228 1.6 christos {
229 1.6 christos const char *str = *strp;
230 1.6 christos enum or1k_rclass cls = RCLASS_DIRECT;
231 1.1 christos enum or1k_rtype typ;
232 1.6 christos
233 1.6 christos if (strncasecmp (str, "got(", 4) == 0)
234 1.6 christos {
235 1.6 christos *strp = str + 4;
236 1.6 christos return (RCLASS_GOT << RCLASS_SHIFT) | RTYPE_LO;
237 1.6 christos }
238 1.6 christos if (strncasecmp (str, "gotpo(", 6) == 0)
239 1.6 christos {
240 1.6 christos *strp = str + 6;
241 1.6 christos return (RCLASS_GOT << RCLASS_SHIFT) | RTYPE_PO;
242 1.6 christos }
243 1.6 christos if (strncasecmp (str, "gottppo(", 8) == 0)
244 1.6 christos {
245 1.6 christos *strp = str + 8;
246 1.6 christos return (RCLASS_GOTTPOFF << RCLASS_SHIFT) | RTYPE_PO;
247 1.1 christos }
248 1.6 christos
249 1.6 christos if (strncasecmp (str, "gotpc", 5) == 0)
250 1.6 christos {
251 1.6 christos str += 5;
252 1.6 christos cls = RCLASS_GOTPC;
253 1.6 christos }
254 1.6 christos else if (strncasecmp (str, "gotoff", 6) == 0)
255 1.6 christos {
256 1.6 christos str += 6;
257 1.6 christos cls = RCLASS_GOTOFF;
258 1.6 christos }
259 1.6 christos else if (strncasecmp (str, "tlsgd", 5) == 0)
260 1.6 christos {
261 1.6 christos str += 5;
262 1.6 christos cls = RCLASS_TLSGD;
263 1.6 christos }
264 1.6 christos else if (strncasecmp (str, "tlsldm", 6) == 0)
265 1.6 christos {
266 1.6 christos str += 6;
267 1.6 christos cls = RCLASS_TLSLDM;
268 1.6 christos }
269 1.6 christos else if (strncasecmp (str, "dtpoff", 6) == 0)
270 1.6 christos {
271 1.6 christos str += 6;
272 1.6 christos cls = RCLASS_DTPOFF;
273 1.6 christos }
274 1.6 christos else if (strncasecmp (str, "gottpoff", 8) == 0)
275 1.6 christos {
276 1.6 christos str += 8;
277 1.6 christos cls = RCLASS_GOTTPOFF;
278 1.6 christos }
279 1.6 christos else if (strncasecmp (str, "tpoff", 5) == 0)
280 1.6 christos {
281 1.6 christos str += 5;
282 1.6 christos cls = RCLASS_TPOFF;
283 1.1 christos }
284 1.6 christos
285 1.6 christos if (strncasecmp (str, "hi(", 3) == 0)
286 1.6 christos {
287 1.6 christos str += 3;
288 1.6 christos typ = RTYPE_HI;
289 1.6 christos }
290 1.6 christos else if (strncasecmp (str, "lo(", 3) == 0)
291 1.6 christos {
292 1.6 christos str += 3;
293 1.6 christos typ = RTYPE_LO;
294 1.6 christos }
295 1.6 christos else if (strncasecmp (str, "ha(", 3) == 0)
296 1.6 christos {
297 1.6 christos str += 3;
298 1.6 christos typ = RTYPE_AHI;
299 1.6 christos }
300 1.6 christos else if (strncasecmp (str, "po(", 3) == 0 && cls != RCLASS_GOTTPOFF)
301 1.6 christos {
302 1.6 christos str += 3;
303 1.6 christos typ = RTYPE_PO;
304 1.6 christos }
305 1.6 christos else
306 1.1 christos return -1;
307 1.6 christos
308 1.6 christos *strp = str;
309 1.6 christos return (cls << RCLASS_SHIFT) | typ;
310 1.1 christos }
311 1.6 christos
312 1.6 christos static const char *
313 1.6 christos parse_imm16 (CGEN_CPU_DESC cd, const char **strp, int opindex,
314 1.6 christos long *valuep, int splitp)
315 1.6 christos {
316 1.6 christos const char *errmsg;
317 1.6 christos enum cgen_parse_operand_result result_type;
318 1.6 christos bfd_reloc_code_real_type reloc = BFD_RELOC_UNUSED;
319 1.6 christos enum or1k_rtype reloc_type;
320 1.6 christos int reloc_code;
321 1.1 christos bfd_vma ret;
322 1.6 christos
323 1.6 christos if (**strp == '#')
324 1.1 christos ++*strp;
325 1.6 christos
326 1.6 christos reloc_code = parse_reloc (strp);
327 1.6 christos reloc_type = reloc_code & RTYPE_MASK;
328 1.6 christos if (reloc_code >= 0)
329 1.6 christos {
330 1.6 christos enum or1k_rclass reloc_class = reloc_code >> RCLASS_SHIFT;
331 1.6 christos if (splitp)
332 1.6 christos {
333 1.6 christos if ((reloc_type == RTYPE_LO || reloc_type == RTYPE_PO)
334 1.6 christos && reloc_class != RCLASS_GOT)
335 1.6 christos /* If split we or up the type to RTYPE_SLO or RTYPE_SPO. */
336 1.6 christos reloc_type |= 1;
337 1.6 christos else
338 1.6 christos return INVALID_STORE_RELOC;
339 1.6 christos }
340 1.1 christos reloc = or1k_imm16_relocs[reloc_class][reloc_type];
341 1.6 christos }
342 1.6 christos
343 1.1 christos if (reloc != BFD_RELOC_UNUSED)
344 1.1 christos {
345 1.1 christos bfd_vma value;
346 1.6 christos
347 1.1 christos errmsg = cgen_parse_address (cd, strp, opindex, reloc,
348 1.1 christos &result_type, &value);
349 1.6 christos if (**strp != ')')
350 1.1 christos errmsg = MISSING_CLOSING_PARENTHESIS;
351 1.1 christos ++*strp;
352 1.6 christos
353 1.1 christos ret = value;
354 1.6 christos
355 1.6 christos if (errmsg == NULL && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
356 1.6 christos switch (reloc_type)
357 1.6 christos {
358 1.6 christos case RTYPE_AHI:
359 1.6 christos ret += 0x8000;
360 1.6 christos /* FALLTHRU */
361 1.6 christos case RTYPE_HI:
362 1.6 christos ret >>= 16;
363 1.6 christos /* FALLTHRU */
364 1.6 christos case RTYPE_LO:
365 1.6 christos case RTYPE_SLO:
366 1.6 christos ret &= 0xffff;
367 1.6 christos ret = (ret ^ 0x8000) - 0x8000;
368 1.6 christos break;
369 1.6 christos case RTYPE_PO:
370 1.6 christos case RTYPE_SPO:
371 1.6 christos ret &= 0x1fff;
372 1.6 christos break;
373 1.6 christos default:
374 1.6 christos errmsg = INVALID_RELOC_TYPE;
375 1.1 christos }
376 1.1 christos }
377 1.1 christos else
378 1.1 christos {
379 1.1 christos long value;
380 1.1 christos errmsg = cgen_parse_signed_integer (cd, strp, opindex, &value);
381 1.1 christos ret = value;
382 1.1 christos }
383 1.1 christos
384 1.1 christos if (errmsg == NULL)
385 1.1 christos *valuep = ret;
386 1.1 christos
387 1.1 christos return errmsg;
388 1.1 christos }
389 1.1 christos
390 1.6 christos static const char *
391 1.6 christos parse_simm16 (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep)
392 1.6 christos {
393 1.6 christos return parse_imm16(cd, strp, opindex, (long *) valuep, 0);
394 1.6 christos }
395 1.6 christos
396 1.6 christos static const char *
397 1.6 christos parse_simm16_split (CGEN_CPU_DESC cd, const char **strp, int opindex,
398 1.1 christos long *valuep)
399 1.6 christos {
400 1.6 christos return parse_imm16(cd, strp, opindex, (long *) valuep, 1);
401 1.1 christos }
402 1.6 christos
403 1.6 christos static const char *
404 1.6 christos parse_uimm16 (CGEN_CPU_DESC cd, const char **strp, int opindex,
405 1.6 christos unsigned long *valuep)
406 1.6 christos {
407 1.6 christos const char *errmsg = parse_imm16(cd, strp, opindex, (long *) valuep, 0);
408 1.6 christos if (errmsg == NULL)
409 1.6 christos *valuep &= 0xffff;
410 1.6 christos return errmsg;
411 1.6 christos }
412 1.6 christos
413 1.6 christos static const char *
414 1.6 christos parse_uimm16_split (CGEN_CPU_DESC cd, const char **strp, int opindex,
415 1.6 christos unsigned long *valuep)
416 1.6 christos {
417 1.1 christos const char *errmsg = parse_imm16(cd, strp, opindex, (long *) valuep, 1);
418 1.1 christos if (errmsg == NULL)
419 1.1 christos *valuep &= 0xffff;
420 1.1 christos return errmsg;
421 1.1 christos }
422 1.7 christos
423 1.7 christos /* Parse register pairs with syntax rA,rB to a flag + rA value. */
424 1.7 christos
425 1.7 christos static const char *
426 1.7 christos parse_regpair (CGEN_CPU_DESC cd, const char **strp,
427 1.7 christos int opindex ATTRIBUTE_UNUSED, unsigned long *valuep)
428 1.7 christos {
429 1.7 christos long reg1_index;
430 1.7 christos long reg2_index;
431 1.7 christos const char *errmsg;
432 1.7 christos
433 1.7 christos /* The first part should just be a register. */
434 1.7 christos errmsg = cgen_parse_keyword (cd, strp, &or1k_cgen_opval_h_gpr,
435 1.7 christos ®1_index);
436 1.7 christos
437 1.7 christos /* If that worked skip the comma separator. */
438 1.7 christos if (errmsg == NULL)
439 1.7 christos {
440 1.7 christos if (**strp == ',')
441 1.7 christos ++*strp;
442 1.7 christos else
443 1.7 christos errmsg = "Unexpected character, expected ','";
444 1.7 christos }
445 1.7 christos
446 1.7 christos /* If that worked the next part is just another register. */
447 1.7 christos if (errmsg == NULL)
448 1.7 christos errmsg = cgen_parse_keyword (cd, strp, &or1k_cgen_opval_h_gpr,
449 1.7 christos ®2_index);
450 1.7 christos
451 1.7 christos /* Validate the register pair is valid and create the output value. */
452 1.7 christos if (errmsg == NULL)
453 1.7 christos {
454 1.7 christos int regoffset = reg2_index - reg1_index;
455 1.7 christos
456 1.7 christos if (regoffset == 1 || regoffset == 2)
457 1.7 christos {
458 1.7 christos unsigned short offsetmask;
459 1.7 christos unsigned short value;
460 1.7 christos
461 1.7 christos offsetmask = ((regoffset == 2 ? 1 : 0) << 5);
462 1.7 christos value = offsetmask | reg1_index;
463 1.7 christos
464 1.7 christos *valuep = value;
465 1.7 christos }
466 1.7 christos else
467 1.7 christos errmsg = "Invalid register pair, offset not 1 or 2.";
468 1.7 christos }
469 1.7 christos
470 1.7 christos return errmsg;
471 1.7 christos }
472 1.1 christos
473 1.1 christos /* -- */
474 1.1 christos
475 1.1 christos const char * or1k_cgen_parse_operand
476 1.1 christos (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
477 1.1 christos
478 1.1 christos /* Main entry point for operand parsing.
479 1.1 christos
480 1.1 christos This function is basically just a big switch statement. Earlier versions
481 1.1 christos used tables to look up the function to use, but
482 1.1 christos - if the table contains both assembler and disassembler functions then
483 1.1 christos the disassembler contains much of the assembler and vice-versa,
484 1.1 christos - there's a lot of inlining possibilities as things grow,
485 1.1 christos - using a switch statement avoids the function call overhead.
486 1.1 christos
487 1.1 christos This function could be moved into `parse_insn_normal', but keeping it
488 1.1 christos separate makes clear the interface between `parse_insn_normal' and each of
489 1.1 christos the handlers. */
490 1.1 christos
491 1.1 christos const char *
492 1.1 christos or1k_cgen_parse_operand (CGEN_CPU_DESC cd,
493 1.1 christos int opindex,
494 1.1 christos const char ** strp,
495 1.1 christos CGEN_FIELDS * fields)
496 1.1 christos {
497 1.1 christos const char * errmsg = NULL;
498 1.1 christos /* Used by scalar operands that still need to be parsed. */
499 1.1 christos long junk ATTRIBUTE_UNUSED;
500 1.1 christos
501 1.1 christos switch (opindex)
502 1.6 christos {
503 1.6 christos case OR1K_OPERAND_DISP21 :
504 1.6 christos {
505 1.6 christos bfd_vma value = 0;
506 1.6 christos errmsg = parse_disp21 (cd, strp, OR1K_OPERAND_DISP21, 0, NULL, & value);
507 1.6 christos fields->f_disp21 = value;
508 1.6 christos }
509 1.1 christos break;
510 1.1 christos case OR1K_OPERAND_DISP26 :
511 1.1 christos {
512 1.1 christos bfd_vma value = 0;
513 1.1 christos errmsg = parse_disp26 (cd, strp, OR1K_OPERAND_DISP26, 0, NULL, & value);
514 1.1 christos fields->f_disp26 = value;
515 1.1 christos }
516 1.1 christos break;
517 1.1 christos case OR1K_OPERAND_RA :
518 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r2);
519 1.7 christos break;
520 1.7 christos case OR1K_OPERAND_RAD32F :
521 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RAD32F, (unsigned long *) (& fields->f_rad32));
522 1.7 christos break;
523 1.7 christos case OR1K_OPERAND_RADI :
524 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RADI, (unsigned long *) (& fields->f_rad32));
525 1.1 christos break;
526 1.1 christos case OR1K_OPERAND_RASF :
527 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r2);
528 1.1 christos break;
529 1.1 christos case OR1K_OPERAND_RB :
530 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r3);
531 1.7 christos break;
532 1.7 christos case OR1K_OPERAND_RBD32F :
533 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RBD32F, (unsigned long *) (& fields->f_rbd32));
534 1.7 christos break;
535 1.7 christos case OR1K_OPERAND_RBDI :
536 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RBDI, (unsigned long *) (& fields->f_rbd32));
537 1.1 christos break;
538 1.1 christos case OR1K_OPERAND_RBSF :
539 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r3);
540 1.1 christos break;
541 1.1 christos case OR1K_OPERAND_RD :
542 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r1);
543 1.7 christos break;
544 1.7 christos case OR1K_OPERAND_RDD32F :
545 1.7 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RDD32F, (unsigned long *) (& fields->f_rdd32));
546 1.7 christos break;
547 1.7 christos case OR1K_OPERAND_RDDI :
548 1.1 christos errmsg = parse_regpair (cd, strp, OR1K_OPERAND_RDDI, (unsigned long *) (& fields->f_rdd32));
549 1.1 christos break;
550 1.1 christos case OR1K_OPERAND_RDSF :
551 1.1 christos errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r1);
552 1.1 christos break;
553 1.1 christos case OR1K_OPERAND_SIMM16 :
554 1.1 christos errmsg = parse_simm16 (cd, strp, OR1K_OPERAND_SIMM16, (long *) (& fields->f_simm16));
555 1.1 christos break;
556 1.6 christos case OR1K_OPERAND_SIMM16_SPLIT :
557 1.1 christos errmsg = parse_simm16_split (cd, strp, OR1K_OPERAND_SIMM16_SPLIT, (long *) (& fields->f_simm16_split));
558 1.1 christos break;
559 1.1 christos case OR1K_OPERAND_UIMM16 :
560 1.1 christos errmsg = parse_uimm16 (cd, strp, OR1K_OPERAND_UIMM16, (unsigned long *) (& fields->f_uimm16));
561 1.1 christos break;
562 1.6 christos case OR1K_OPERAND_UIMM16_SPLIT :
563 1.1 christos errmsg = parse_uimm16_split (cd, strp, OR1K_OPERAND_UIMM16_SPLIT, (unsigned long *) (& fields->f_uimm16_split));
564 1.1 christos break;
565 1.1 christos case OR1K_OPERAND_UIMM6 :
566 1.1 christos errmsg = cgen_parse_unsigned_integer (cd, strp, OR1K_OPERAND_UIMM6, (unsigned long *) (& fields->f_uimm6));
567 1.1 christos break;
568 1.1 christos
569 1.1 christos default :
570 1.6 christos /* xgettext:c-format */
571 1.6 christos opcodes_error_handler
572 1.6 christos (_("internal error: unrecognized field %d while parsing"),
573 1.1 christos opindex);
574 1.1 christos abort ();
575 1.1 christos }
576 1.1 christos
577 1.1 christos return errmsg;
578 1.1 christos }
579 1.4 christos
580 1.1 christos cgen_parse_fn * const or1k_cgen_parse_handlers[] =
581 1.1 christos {
582 1.1 christos parse_insn_normal,
583 1.1 christos };
584 1.1 christos
585 1.1 christos void
586 1.1 christos or1k_cgen_init_asm (CGEN_CPU_DESC cd)
587 1.1 christos {
588 1.1 christos or1k_cgen_init_opcode_table (cd);
589 1.1 christos or1k_cgen_init_ibld_table (cd);
590 1.1 christos cd->parse_handlers = & or1k_cgen_parse_handlers[0];
591 1.1 christos cd->parse_operand = or1k_cgen_parse_operand;
592 1.1 christos #ifdef CGEN_ASM_INIT_HOOK
593 1.1 christos CGEN_ASM_INIT_HOOK
594 1.1 christos #endif
595 1.1 christos }
596 1.1 christos
597 1.1 christos
598 1.1 christos
600 1.1 christos /* Regex construction routine.
601 1.1 christos
602 1.1 christos This translates an opcode syntax string into a regex string,
603 1.1 christos by replacing any non-character syntax element (such as an
604 1.1 christos opcode) with the pattern '.*'
605 1.1 christos
606 1.1 christos It then compiles the regex and stores it in the opcode, for
607 1.1 christos later use by or1k_cgen_assemble_insn
608 1.1 christos
609 1.4 christos Returns NULL for success, an error message for failure. */
610 1.1 christos
611 1.4 christos char *
612 1.1 christos or1k_cgen_build_insn_regex (CGEN_INSN *insn)
613 1.1 christos {
614 1.1 christos CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
615 1.1 christos const char *mnem = CGEN_INSN_MNEMONIC (insn);
616 1.1 christos char rxbuf[CGEN_MAX_RX_ELEMENTS];
617 1.1 christos char *rx = rxbuf;
618 1.1 christos const CGEN_SYNTAX_CHAR_TYPE *syn;
619 1.1 christos int reg_err;
620 1.1 christos
621 1.1 christos syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
622 1.1 christos
623 1.1 christos /* Mnemonics come first in the syntax string. */
624 1.1 christos if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
625 1.1 christos return _("missing mnemonic in syntax string");
626 1.1 christos ++syn;
627 1.1 christos
628 1.1 christos /* Generate a case sensitive regular expression that emulates case
629 1.1 christos insensitive matching in the "C" locale. We cannot generate a case
630 1.1 christos insensitive regular expression because in Turkish locales, 'i' and 'I'
631 1.1 christos are not equal modulo case conversion. */
632 1.1 christos
633 1.1 christos /* Copy the literal mnemonic out of the insn. */
634 1.1 christos for (; *mnem; mnem++)
635 1.1 christos {
636 1.1 christos char c = *mnem;
637 1.1 christos
638 1.1 christos if (ISALPHA (c))
639 1.1 christos {
640 1.1 christos *rx++ = '[';
641 1.1 christos *rx++ = TOLOWER (c);
642 1.1 christos *rx++ = TOUPPER (c);
643 1.1 christos *rx++ = ']';
644 1.1 christos }
645 1.1 christos else
646 1.1 christos *rx++ = c;
647 1.1 christos }
648 1.1 christos
649 1.1 christos /* Copy any remaining literals from the syntax string into the rx. */
650 1.4 christos for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
651 1.1 christos {
652 1.1 christos if (CGEN_SYNTAX_CHAR_P (* syn))
653 1.1 christos {
654 1.4 christos char c = CGEN_SYNTAX_CHAR (* syn);
655 1.1 christos
656 1.1 christos switch (c)
657 1.4 christos {
658 1.4 christos /* Escape any regex metacharacters in the syntax. */
659 1.1 christos case '.': case '[': case '\\':
660 1.1 christos case '*': case '^': case '$':
661 1.4 christos
662 1.1 christos #ifdef CGEN_ESCAPE_EXTENDED_REGEX
663 1.1 christos case '?': case '{': case '}':
664 1.1 christos case '(': case ')': case '*':
665 1.1 christos case '|': case '+': case ']':
666 1.1 christos #endif
667 1.1 christos *rx++ = '\\';
668 1.1 christos *rx++ = c;
669 1.1 christos break;
670 1.1 christos
671 1.1 christos default:
672 1.1 christos if (ISALPHA (c))
673 1.1 christos {
674 1.1 christos *rx++ = '[';
675 1.1 christos *rx++ = TOLOWER (c);
676 1.1 christos *rx++ = TOUPPER (c);
677 1.1 christos *rx++ = ']';
678 1.1 christos }
679 1.1 christos else
680 1.1 christos *rx++ = c;
681 1.1 christos break;
682 1.1 christos }
683 1.1 christos }
684 1.1 christos else
685 1.1 christos {
686 1.1 christos /* Replace non-syntax fields with globs. */
687 1.1 christos *rx++ = '.';
688 1.1 christos *rx++ = '*';
689 1.1 christos }
690 1.1 christos }
691 1.4 christos
692 1.4 christos /* Trailing whitespace ok. */
693 1.4 christos * rx++ = '[';
694 1.4 christos * rx++ = ' ';
695 1.4 christos * rx++ = '\t';
696 1.1 christos * rx++ = ']';
697 1.1 christos * rx++ = '*';
698 1.4 christos
699 1.1 christos /* But anchor it after that. */
700 1.1 christos * rx++ = '$';
701 1.1 christos * rx = '\0';
702 1.1 christos
703 1.1 christos CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
704 1.4 christos reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
705 1.1 christos
706 1.1 christos if (reg_err == 0)
707 1.1 christos return NULL;
708 1.1 christos else
709 1.1 christos {
710 1.1 christos static char msg[80];
711 1.1 christos
712 1.1 christos regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
713 1.1 christos regfree ((regex_t *) CGEN_INSN_RX (insn));
714 1.1 christos free (CGEN_INSN_RX (insn));
715 1.1 christos (CGEN_INSN_RX (insn)) = NULL;
716 1.1 christos return msg;
717 1.1 christos }
718 1.1 christos }
719 1.1 christos
720 1.1 christos
721 1.1 christos /* Default insn parser.
723 1.1 christos
724 1.1 christos The syntax string is scanned and operands are parsed and stored in FIELDS.
725 1.1 christos Relocs are queued as we go via other callbacks.
726 1.1 christos
727 1.1 christos ??? Note that this is currently an all-or-nothing parser. If we fail to
728 1.1 christos parse the instruction, we return 0 and the caller will start over from
729 1.1 christos the beginning. Backtracking will be necessary in parsing subexpressions,
730 1.1 christos but that can be handled there. Not handling backtracking here may get
731 1.1 christos expensive in the case of the m68k. Deal with later.
732 1.1 christos
733 1.1 christos Returns NULL for success, an error message for failure. */
734 1.1 christos
735 1.1 christos static const char *
736 1.1 christos parse_insn_normal (CGEN_CPU_DESC cd,
737 1.1 christos const CGEN_INSN *insn,
738 1.1 christos const char **strp,
739 1.1 christos CGEN_FIELDS *fields)
740 1.1 christos {
741 1.1 christos /* ??? Runtime added insns not handled yet. */
742 1.1 christos const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
743 1.1 christos const char *str = *strp;
744 1.1 christos const char *errmsg;
745 1.1 christos const char *p;
746 1.1 christos const CGEN_SYNTAX_CHAR_TYPE * syn;
747 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS
748 1.1 christos /* FIXME: wip */
749 1.1 christos int past_opcode_p;
750 1.1 christos #endif
751 1.1 christos
752 1.1 christos /* For now we assume the mnemonic is first (there are no leading operands).
753 1.1 christos We can parse it without needing to set up operand parsing.
754 1.1 christos GAS's input scrubber will ensure mnemonics are lowercase, but we may
755 1.1 christos not be called from GAS. */
756 1.1 christos p = CGEN_INSN_MNEMONIC (insn);
757 1.1 christos while (*p && TOLOWER (*p) == TOLOWER (*str))
758 1.1 christos ++p, ++str;
759 1.1 christos
760 1.1 christos if (* p)
761 1.1 christos return _("unrecognized instruction");
762 1.1 christos
763 1.1 christos #ifndef CGEN_MNEMONIC_OPERANDS
764 1.1 christos if (* str && ! ISSPACE (* str))
765 1.1 christos return _("unrecognized instruction");
766 1.1 christos #endif
767 1.1 christos
768 1.1 christos CGEN_INIT_PARSE (cd);
769 1.1 christos cgen_init_parse_operand (cd);
770 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS
771 1.1 christos past_opcode_p = 0;
772 1.1 christos #endif
773 1.1 christos
774 1.1 christos /* We don't check for (*str != '\0') here because we want to parse
775 1.1 christos any trailing fake arguments in the syntax string. */
776 1.1 christos syn = CGEN_SYNTAX_STRING (syntax);
777 1.1 christos
778 1.1 christos /* Mnemonics come first for now, ensure valid string. */
779 1.1 christos if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
780 1.1 christos abort ();
781 1.1 christos
782 1.1 christos ++syn;
783 1.1 christos
784 1.1 christos while (* syn != 0)
785 1.1 christos {
786 1.1 christos /* Non operand chars must match exactly. */
787 1.1 christos if (CGEN_SYNTAX_CHAR_P (* syn))
788 1.1 christos {
789 1.1 christos /* FIXME: While we allow for non-GAS callers above, we assume the
790 1.1 christos first char after the mnemonic part is a space. */
791 1.1 christos /* FIXME: We also take inappropriate advantage of the fact that
792 1.1 christos GAS's input scrubber will remove extraneous blanks. */
793 1.1 christos if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
794 1.1 christos {
795 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS
796 1.1 christos if (CGEN_SYNTAX_CHAR(* syn) == ' ')
797 1.1 christos past_opcode_p = 1;
798 1.1 christos #endif
799 1.1 christos ++ syn;
800 1.1 christos ++ str;
801 1.1 christos }
802 1.1 christos else if (*str)
803 1.1 christos {
804 1.1 christos /* Syntax char didn't match. Can't be this insn. */
805 1.1 christos static char msg [80];
806 1.1 christos
807 1.1 christos /* xgettext:c-format */
808 1.1 christos sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
809 1.1 christos CGEN_SYNTAX_CHAR(*syn), *str);
810 1.1 christos return msg;
811 1.1 christos }
812 1.1 christos else
813 1.1 christos {
814 1.1 christos /* Ran out of input. */
815 1.1 christos static char msg [80];
816 1.1 christos
817 1.1 christos /* xgettext:c-format */
818 1.1 christos sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
819 1.1 christos CGEN_SYNTAX_CHAR(*syn));
820 1.1 christos return msg;
821 1.1 christos }
822 1.1 christos continue;
823 1.1 christos }
824 1.1 christos
825 1.1 christos #ifdef CGEN_MNEMONIC_OPERANDS
826 1.1 christos (void) past_opcode_p;
827 1.1 christos #endif
828 1.1 christos /* We have an operand of some sort. */
829 1.1 christos errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
830 1.1 christos if (errmsg)
831 1.1 christos return errmsg;
832 1.1 christos
833 1.1 christos /* Done with this operand, continue with next one. */
834 1.1 christos ++ syn;
835 1.1 christos }
836 1.1 christos
837 1.1 christos /* If we're at the end of the syntax string, we're done. */
838 1.1 christos if (* syn == 0)
839 1.1 christos {
840 1.1 christos /* FIXME: For the moment we assume a valid `str' can only contain
841 1.1 christos blanks now. IE: We needn't try again with a longer version of
842 1.1 christos the insn and it is assumed that longer versions of insns appear
843 1.1 christos before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
844 1.1 christos while (ISSPACE (* str))
845 1.1 christos ++ str;
846 1.1 christos
847 1.1 christos if (* str != '\0')
848 1.1 christos return _("junk at end of line"); /* FIXME: would like to include `str' */
849 1.1 christos
850 1.1 christos return NULL;
851 1.1 christos }
852 1.1 christos
853 1.1 christos /* We couldn't parse it. */
854 1.1 christos return _("unrecognized instruction");
855 1.1 christos }
856 1.1 christos
857 1.1 christos /* Main entry point.
859 1.1 christos This routine is called for each instruction to be assembled.
860 1.1 christos STR points to the insn to be assembled.
861 1.1 christos We assume all necessary tables have been initialized.
862 1.1 christos The assembled instruction, less any fixups, is stored in BUF.
863 1.1 christos Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
864 1.1 christos still needs to be converted to target byte order, otherwise BUF is an array
865 1.1 christos of bytes in target byte order.
866 1.1 christos The result is a pointer to the insn's entry in the opcode table,
867 1.1 christos or NULL if an error occured (an error message will have already been
868 1.1 christos printed).
869 1.1 christos
870 1.1 christos Note that when processing (non-alias) macro-insns,
871 1.1 christos this function recurses.
872 1.1 christos
873 1.1 christos ??? It's possible to make this cpu-independent.
874 1.1 christos One would have to deal with a few minor things.
875 1.1 christos At this point in time doing so would be more of a curiosity than useful
876 1.1 christos [for example this file isn't _that_ big], but keeping the possibility in
877 1.1 christos mind helps keep the design clean. */
878 1.1 christos
879 1.1 christos const CGEN_INSN *
880 1.1 christos or1k_cgen_assemble_insn (CGEN_CPU_DESC cd,
881 1.1 christos const char *str,
882 1.1 christos CGEN_FIELDS *fields,
883 1.1 christos CGEN_INSN_BYTES_PTR buf,
884 1.1 christos char **errmsg)
885 1.1 christos {
886 1.1 christos const char *start;
887 1.1 christos CGEN_INSN_LIST *ilist;
888 1.1 christos const char *parse_errmsg = NULL;
889 1.1 christos const char *insert_errmsg = NULL;
890 1.1 christos int recognized_mnemonic = 0;
891 1.1 christos
892 1.1 christos /* Skip leading white space. */
893 1.1 christos while (ISSPACE (* str))
894 1.1 christos ++ str;
895 1.1 christos
896 1.1 christos /* The instructions are stored in hashed lists.
897 1.1 christos Get the first in the list. */
898 1.1 christos ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
899 1.1 christos
900 1.1 christos /* Keep looking until we find a match. */
901 1.1 christos start = str;
902 1.1 christos for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
903 1.4 christos {
904 1.1 christos const CGEN_INSN *insn = ilist->insn;
905 1.1 christos recognized_mnemonic = 1;
906 1.1 christos
907 1.1 christos #ifdef CGEN_VALIDATE_INSN_SUPPORTED
908 1.1 christos /* Not usually needed as unsupported opcodes
909 1.1 christos shouldn't be in the hash lists. */
910 1.1 christos /* Is this insn supported by the selected cpu? */
911 1.1 christos if (! or1k_cgen_insn_supported (cd, insn))
912 1.1 christos continue;
913 1.1 christos #endif
914 1.1 christos /* If the RELAXED attribute is set, this is an insn that shouldn't be
915 1.1 christos chosen immediately. Instead, it is used during assembler/linker
916 1.1 christos relaxation if possible. */
917 1.1 christos if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
918 1.1 christos continue;
919 1.1 christos
920 1.1 christos str = start;
921 1.1 christos
922 1.1 christos /* Skip this insn if str doesn't look right lexically. */
923 1.1 christos if (CGEN_INSN_RX (insn) != NULL &&
924 1.1 christos regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
925 1.1 christos continue;
926 1.1 christos
927 1.1 christos /* Allow parse/insert handlers to obtain length of insn. */
928 1.1 christos CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
929 1.1 christos
930 1.1 christos parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
931 1.1 christos if (parse_errmsg != NULL)
932 1.1 christos continue;
933 1.1 christos
934 1.1 christos /* ??? 0 is passed for `pc'. */
935 1.1 christos insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
936 1.1 christos (bfd_vma) 0);
937 1.1 christos if (insert_errmsg != NULL)
938 1.1 christos continue;
939 1.1 christos
940 1.1 christos /* It is up to the caller to actually output the insn and any
941 1.1 christos queued relocs. */
942 1.1 christos return insn;
943 1.1 christos }
944 1.1 christos
945 1.1 christos {
946 1.1 christos static char errbuf[150];
947 1.1 christos const char *tmp_errmsg;
948 1.1 christos #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
949 1.1 christos #define be_verbose 1
950 1.1 christos #else
951 1.1 christos #define be_verbose 0
952 1.1 christos #endif
953 1.1 christos
954 1.1 christos if (be_verbose)
955 1.1 christos {
956 1.1 christos /* If requesting verbose error messages, use insert_errmsg.
957 1.1 christos Failing that, use parse_errmsg. */
958 1.1 christos tmp_errmsg = (insert_errmsg ? insert_errmsg :
959 1.1 christos parse_errmsg ? parse_errmsg :
960 1.1 christos recognized_mnemonic ?
961 1.1 christos _("unrecognized form of instruction") :
962 1.1 christos _("unrecognized instruction"));
963 1.4 christos
964 1.1 christos if (strlen (start) > 50)
965 1.1 christos /* xgettext:c-format */
966 1.1 christos sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
967 1.1 christos else
968 1.1 christos /* xgettext:c-format */
969 1.1 christos sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
970 1.1 christos }
971 1.1 christos else
972 1.4 christos {
973 1.1 christos if (strlen (start) > 50)
974 1.1 christos /* xgettext:c-format */
975 1.1 christos sprintf (errbuf, _("bad instruction `%.50s...'"), start);
976 1.4 christos else
977 1.1 christos /* xgettext:c-format */
978 1.1 christos sprintf (errbuf, _("bad instruction `%.50s'"), start);
979 1.1 christos }
980 1.1 christos
981 *errmsg = errbuf;
982 return NULL;
983 }
984 }
985