1 /* ARC target-dependent stuff. Extension structure access functions
2 Copyright 1995, 1997, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program 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 2 of the License, or
9 (at your option) any later version.
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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "libiberty.h"
26 /* Extension structure */
27 static struct arcExtMap arc_extension_map
;
29 /* Get the name of an extension instruction. */
32 arcExtMap_instName(int opcode
, int minor
, int *flags
)
36 /* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
37 if (minor
< 0x09 || minor
== 0x3f)
40 opcode
= 0x1f - 0x10 + minor
- 0x09 + 1;
47 if (!arc_extension_map
.instructions
[opcode
])
49 *flags
= arc_extension_map
.instructions
[opcode
]->flags
;
50 return arc_extension_map
.instructions
[opcode
]->name
;
53 /* Get the name of an extension core register. */
56 arcExtMap_coreRegName(int value
)
60 return (const char *) arc_extension_map
.coreRegisters
[value
-32];
63 /* Get the name of an extension condition code. */
66 arcExtMap_condCodeName(int value
)
70 return (const char *) arc_extension_map
.condCodes
[value
-16];
73 /* Get the name of an extension aux register. */
76 arcExtMap_auxRegName(long address
)
78 /* walk the list of aux reg names and find the name */
79 struct ExtAuxRegister
*r
;
81 for (r
= arc_extension_map
.auxRegisters
; r
; r
= r
->next
) {
82 if (r
->address
== address
)
83 return (const char *) r
->name
;
88 /* Recursively free auxilliary register strcture pointers until
92 clean_aux_registers(struct ExtAuxRegister
*r
)
96 clean_aux_registers( r
->next
);
105 /* Free memory that has been allocated for the extensions. */
108 cleanup_ext_map(void)
110 struct ExtAuxRegister
*r
;
111 struct ExtInstruction
*insn
;
114 /* clean aux reg structure */
115 r
= arc_extension_map
.auxRegisters
;
118 (clean_aux_registers(r
));
122 /* clean instructions */
123 for (i
= 0; i
< NUM_EXT_INST
; i
++)
125 insn
= arc_extension_map
.instructions
[i
];
130 /* clean core reg struct */
131 for (i
= 0; i
< NUM_EXT_CORE
; i
++)
133 if (arc_extension_map
.coreRegisters
[i
])
134 free(arc_extension_map
.coreRegisters
[i
]);
137 for (i
= 0; i
< NUM_EXT_COND
; i
++) {
138 if (arc_extension_map
.condCodes
[i
])
139 free(arc_extension_map
.condCodes
[i
]);
142 memset(&arc_extension_map
, 0, sizeof(struct arcExtMap
));
146 arcExtMap_add(void *base
, unsigned long length
)
148 unsigned char *block
= base
;
149 unsigned char *p
= block
;
151 /* Clean up and reset everything if needed. */
154 while (p
&& p
< (block
+ length
))
156 /* p[0] == length of record
157 p[1] == type of record
160 p[3] = minor opcode (if opcode == 3)
163 For core regs and condition codes:
169 (value is p[2]<<24|p[3]<<16|p[4]<<8|p[5]) */
176 case EXT_INSTRUCTION
:
180 char * insn_name
= (char *) xmalloc(( (int)*p
-5) * sizeof(char));
181 struct ExtInstruction
* insn
=
182 (struct ExtInstruction
*) xmalloc(sizeof(struct ExtInstruction
));
185 opcode
= 0x1f - 0x10 + minor
- 0x09 + 1;
188 insn
-> flags
= (char) *(p
+4);
189 strcpy(insn_name
, (p
+5));
190 insn
-> name
= insn_name
;
191 arc_extension_map
.instructions
[(int) opcode
] = insn
;
195 case EXT_CORE_REGISTER
:
197 char * core_name
= (char *) xmalloc(((int)*p
-3) * sizeof(char));
199 strcpy(core_name
, (p
+3));
200 arc_extension_map
.coreRegisters
[p
[2]-32] = core_name
;
206 char * cc_name
= (char *) xmalloc( ((int)*p
-3) * sizeof(char));
207 strcpy(cc_name
, (p
+3));
208 arc_extension_map
.condCodes
[p
[2]-16] = cc_name
;
212 case EXT_AUX_REGISTER
:
214 /* trickier -- need to store linked list to these */
215 struct ExtAuxRegister
*newAuxRegister
=
216 (struct ExtAuxRegister
*)malloc(sizeof(struct ExtAuxRegister
));
217 char * aux_name
= (char *) xmalloc ( ((int)*p
-6) * sizeof(char));
219 strcpy (aux_name
, (p
+6));
220 newAuxRegister
->name
= aux_name
;
221 newAuxRegister
->address
= p
[2]<<24 | p
[3]<<16 | p
[4]<<8 | p
[5];
222 newAuxRegister
->next
= arc_extension_map
.auxRegisters
;
223 arc_extension_map
.auxRegisters
= newAuxRegister
;
231 p
+= p
[0]; /* move to next record */
237 /* Load hw extension descibed in .extArcMap ELF section. */
240 build_ARC_extmap (text_bfd
)
247 for (p
= text_bfd
->sections
; p
!= NULL
; p
= p
->next
)
248 if (!strcmp (p
->name
, ".arcextmap"))
250 count
= p
->_raw_size
;
251 arcExtMap
= (char *) xmalloc (count
);
252 if (bfd_get_section_contents (text_bfd
, p
, (PTR
) arcExtMap
, 0, count
))
254 arcExtMap_add ((PTR
) arcExtMap
, count
);
257 free ((PTR
) arcExtMap
);