1 /* ARC target-dependent stuff. Extension structure access functions
2 Copyright (C) 1995-2015 Free Software Foundation, Inc.
4 This file is part of libopcodes.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
26 #include "libiberty.h"
28 /* Extension structure */
29 static struct arcExtMap arc_extension_map;
31 /* Get the name of an extension instruction. */
34 arcExtMap_instName(int opcode, int minor, int *flags)
38 /* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
39 if (minor < 0x09 || minor == 0x3f)
42 opcode = 0x1f - 0x10 + minor - 0x09 + 1;
49 if (!arc_extension_map.instructions[opcode])
51 *flags = arc_extension_map.instructions[opcode]->flags;
52 return arc_extension_map.instructions[opcode]->name;
55 /* Get the name of an extension core register. */
58 arcExtMap_coreRegName(int value)
62 return arc_extension_map.coreRegisters[value-32];
65 /* Get the name of an extension condition code. */
68 arcExtMap_condCodeName(int value)
72 return arc_extension_map.condCodes[value-16];
75 /* Get the name of an extension aux register. */
78 arcExtMap_auxRegName(long address)
80 /* walk the list of aux reg names and find the name */
81 struct ExtAuxRegister *r;
83 for (r = arc_extension_map.auxRegisters; r; r = r->next) {
84 if (r->address == address)
85 return (const char *) r->name;
90 /* Recursively free auxilliary register strcture pointers until
94 clean_aux_registers(struct ExtAuxRegister *r)
98 clean_aux_registers( r->next);
107 /* Free memory that has been allocated for the extensions. */
110 cleanup_ext_map(void)
112 struct ExtAuxRegister *r;
113 struct ExtInstruction *insn;
116 /* clean aux reg structure */
117 r = arc_extension_map.auxRegisters;
120 (clean_aux_registers(r));
124 /* clean instructions */
125 for (i = 0; i < NUM_EXT_INST; i++)
127 insn = arc_extension_map.instructions[i];
132 /* clean core reg struct */
133 for (i = 0; i < NUM_EXT_CORE; i++)
135 if (arc_extension_map.coreRegisters[i])
136 free(arc_extension_map.coreRegisters[i]);
139 for (i = 0; i < NUM_EXT_COND; i++) {
140 if (arc_extension_map.condCodes[i])
141 free(arc_extension_map.condCodes[i]);
144 memset(&arc_extension_map, 0, sizeof(struct arcExtMap));
148 arcExtMap_add(void *base, unsigned long length)
150 unsigned char *block = (unsigned char *) base;
151 unsigned char *p = (unsigned char *) block;
153 /* Clean up and reset everything if needed. */
156 while (p && p < (block + length))
158 /* p[0] == length of record
159 p[1] == type of record
162 p[3] = minor opcode (if opcode == 3)
165 For core regs and condition codes:
171 (value is p[2]<<24|p[3]<<16|p[4]<<8|p[5]) */
178 case EXT_INSTRUCTION:
182 char * insn_name = (char *) xmalloc(( (int)*p-5) * sizeof(char));
183 struct ExtInstruction * insn =
184 (struct ExtInstruction *) xmalloc(sizeof(struct ExtInstruction));
187 opcode = 0x1f - 0x10 + minor - 0x09 + 1;
190 insn -> flags = (char) *(p+4);
191 strcpy (insn_name, (char *) (p+5));
192 insn -> name = insn_name;
193 arc_extension_map.instructions[(int) opcode] = insn;
197 case EXT_CORE_REGISTER:
199 char * core_name = (char *) xmalloc(((int)*p-3) * sizeof(char));
201 strcpy(core_name, (char *) (p+3));
202 arc_extension_map.coreRegisters[p[2]-32] = core_name;
208 char * cc_name = (char *) xmalloc( ((int)*p-3) * sizeof(char));
209 strcpy(cc_name, (char *) (p+3));
210 arc_extension_map.condCodes[p[2]-16] = cc_name;
214 case EXT_AUX_REGISTER:
216 /* trickier -- need to store linked list to these */
217 struct ExtAuxRegister *newAuxRegister =
218 (struct ExtAuxRegister *)malloc(sizeof(struct ExtAuxRegister));
219 char * aux_name = (char *) xmalloc ( ((int)*p-6) * sizeof(char));
221 strcpy (aux_name, (char *) (p+6));
222 newAuxRegister->name = aux_name;
223 newAuxRegister->address = p[2]<<24 | p[3]<<16 | p[4]<<8 | p[5];
224 newAuxRegister->next = arc_extension_map.auxRegisters;
225 arc_extension_map.auxRegisters = newAuxRegister;
233 p += p[0]; /* move to next record */
239 /* Load hw extension descibed in .extArcMap ELF section. */
242 build_ARC_extmap (text_bfd)
249 for (p = text_bfd->sections; p != NULL; p = p->next)
250 if (!strcmp (p->name, ".arcextmap"))
252 count = bfd_get_section_size (p);
253 arcExtMap = (char *) xmalloc (count);
254 if (bfd_get_section_contents (text_bfd, p, (PTR) arcExtMap, 0, count))
256 arcExtMap_add ((PTR) arcExtMap, count);
259 free ((PTR) arcExtMap);