1 /* ARC target-dependent stuff. Extension structure access functions
2 Copyright 1995, 1997, 2000, 2001, 2004, 2005, 2007
3 Free Software Foundation, Inc.
5 This file is part of libopcodes.
7 This library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "libiberty.h"
29 /* Extension structure */
30 static struct arcExtMap arc_extension_map;
32 /* Get the name of an extension instruction. */
35 arcExtMap_instName(int opcode, int minor, int *flags)
39 /* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
40 if (minor < 0x09 || minor == 0x3f)
43 opcode = 0x1f - 0x10 + minor - 0x09 + 1;
50 if (!arc_extension_map.instructions[opcode])
52 *flags = arc_extension_map.instructions[opcode]->flags;
53 return arc_extension_map.instructions[opcode]->name;
56 /* Get the name of an extension core register. */
59 arcExtMap_coreRegName(int value)
63 return arc_extension_map.coreRegisters[value-32];
66 /* Get the name of an extension condition code. */
69 arcExtMap_condCodeName(int value)
73 return arc_extension_map.condCodes[value-16];
76 /* Get the name of an extension aux register. */
79 arcExtMap_auxRegName(long address)
81 /* walk the list of aux reg names and find the name */
82 struct ExtAuxRegister *r;
84 for (r = arc_extension_map.auxRegisters; r; r = r->next) {
85 if (r->address == address)
86 return (const char *) r->name;
91 /* Recursively free auxilliary register strcture pointers until
95 clean_aux_registers(struct ExtAuxRegister *r)
99 clean_aux_registers( r->next);
108 /* Free memory that has been allocated for the extensions. */
111 cleanup_ext_map(void)
113 struct ExtAuxRegister *r;
114 struct ExtInstruction *insn;
117 /* clean aux reg structure */
118 r = arc_extension_map.auxRegisters;
121 (clean_aux_registers(r));
125 /* clean instructions */
126 for (i = 0; i < NUM_EXT_INST; i++)
128 insn = arc_extension_map.instructions[i];
133 /* clean core reg struct */
134 for (i = 0; i < NUM_EXT_CORE; i++)
136 if (arc_extension_map.coreRegisters[i])
137 free(arc_extension_map.coreRegisters[i]);
140 for (i = 0; i < NUM_EXT_COND; i++) {
141 if (arc_extension_map.condCodes[i])
142 free(arc_extension_map.condCodes[i]);
145 memset(&arc_extension_map, 0, sizeof(struct arcExtMap));
149 arcExtMap_add(void *base, unsigned long length)
151 unsigned char *block = base;
152 unsigned char *p = block;
154 /* Clean up and reset everything if needed. */
157 while (p && p < (block + length))
159 /* p[0] == length of record
160 p[1] == type of record
163 p[3] = minor opcode (if opcode == 3)
166 For core regs and condition codes:
172 (value is p[2]<<24|p[3]<<16|p[4]<<8|p[5]) */
179 case EXT_INSTRUCTION:
183 char * insn_name = (char *) xmalloc(( (int)*p-5) * sizeof(char));
184 struct ExtInstruction * insn =
185 (struct ExtInstruction *) xmalloc(sizeof(struct ExtInstruction));
188 opcode = 0x1f - 0x10 + minor - 0x09 + 1;
191 insn -> flags = (char) *(p+4);
192 strcpy (insn_name, (char *) (p+5));
193 insn -> name = insn_name;
194 arc_extension_map.instructions[(int) opcode] = insn;
198 case EXT_CORE_REGISTER:
200 char * core_name = (char *) xmalloc(((int)*p-3) * sizeof(char));
202 strcpy(core_name, (char *) (p+3));
203 arc_extension_map.coreRegisters[p[2]-32] = core_name;
209 char * cc_name = (char *) xmalloc( ((int)*p-3) * sizeof(char));
210 strcpy(cc_name, (char *) (p+3));
211 arc_extension_map.condCodes[p[2]-16] = cc_name;
215 case EXT_AUX_REGISTER:
217 /* trickier -- need to store linked list to these */
218 struct ExtAuxRegister *newAuxRegister =
219 (struct ExtAuxRegister *)malloc(sizeof(struct ExtAuxRegister));
220 char * aux_name = (char *) xmalloc ( ((int)*p-6) * sizeof(char));
222 strcpy (aux_name, (char *) (p+6));
223 newAuxRegister->name = aux_name;
224 newAuxRegister->address = p[2]<<24 | p[3]<<16 | p[4]<<8 | p[5];
225 newAuxRegister->next = arc_extension_map.auxRegisters;
226 arc_extension_map.auxRegisters = newAuxRegister;
234 p += p[0]; /* move to next record */
240 /* Load hw extension descibed in .extArcMap ELF section. */
243 build_ARC_extmap (text_bfd)
250 for (p = text_bfd->sections; p != NULL; p = p->next)
251 if (!strcmp (p->name, ".arcextmap"))
253 count = bfd_get_section_size (p);
254 arcExtMap = (char *) xmalloc (count);
255 if (bfd_get_section_contents (text_bfd, p, (PTR) arcExtMap, 0, count))
257 arcExtMap_add ((PTR) arcExtMap, count);
260 free ((PTR) arcExtMap);