1 /* ARC target-dependent stuff. Extension structure access functions
2 Copyright 1995, 1997, 2000, 2001, 2004 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. */
25 #include "libiberty.h"
27 /* Extension structure */
28 static struct arcExtMap arc_extension_map
;
30 /* Get the name of an extension instruction. */
33 arcExtMap_instName(int opcode
, int minor
, int *flags
)
37 /* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
38 if (minor
< 0x09 || minor
== 0x3f)
41 opcode
= 0x1f - 0x10 + minor
- 0x09 + 1;
48 if (!arc_extension_map
.instructions
[opcode
])
50 *flags
= arc_extension_map
.instructions
[opcode
]->flags
;
51 return arc_extension_map
.instructions
[opcode
]->name
;
54 /* Get the name of an extension core register. */
57 arcExtMap_coreRegName(int value
)
61 return (const char *) arc_extension_map
.coreRegisters
[value
-32];
64 /* Get the name of an extension condition code. */
67 arcExtMap_condCodeName(int value
)
71 return (const char *) arc_extension_map
.condCodes
[value
-16];
74 /* Get the name of an extension aux register. */
77 arcExtMap_auxRegName(long address
)
79 /* walk the list of aux reg names and find the name */
80 struct ExtAuxRegister
*r
;
82 for (r
= arc_extension_map
.auxRegisters
; r
; r
= r
->next
) {
83 if (r
->address
== address
)
84 return (const char *) r
->name
;
89 /* Recursively free auxilliary register strcture pointers until
93 clean_aux_registers(struct ExtAuxRegister
*r
)
97 clean_aux_registers( r
->next
);
106 /* Free memory that has been allocated for the extensions. */
109 cleanup_ext_map(void)
111 struct ExtAuxRegister
*r
;
112 struct ExtInstruction
*insn
;
115 /* clean aux reg structure */
116 r
= arc_extension_map
.auxRegisters
;
119 (clean_aux_registers(r
));
123 /* clean instructions */
124 for (i
= 0; i
< NUM_EXT_INST
; i
++)
126 insn
= arc_extension_map
.instructions
[i
];
131 /* clean core reg struct */
132 for (i
= 0; i
< NUM_EXT_CORE
; i
++)
134 if (arc_extension_map
.coreRegisters
[i
])
135 free(arc_extension_map
.coreRegisters
[i
]);
138 for (i
= 0; i
< NUM_EXT_COND
; i
++) {
139 if (arc_extension_map
.condCodes
[i
])
140 free(arc_extension_map
.condCodes
[i
]);
143 memset(&arc_extension_map
, 0, sizeof(struct arcExtMap
));
147 arcExtMap_add(void *base
, unsigned long length
)
149 unsigned char *block
= base
;
150 unsigned char *p
= block
;
152 /* Clean up and reset everything if needed. */
155 while (p
&& p
< (block
+ length
))
157 /* p[0] == length of record
158 p[1] == type of record
161 p[3] = minor opcode (if opcode == 3)
164 For core regs and condition codes:
170 (value is p[2]<<24|p[3]<<16|p[4]<<8|p[5]) */
177 case EXT_INSTRUCTION
:
181 char * insn_name
= (char *) xmalloc(( (int)*p
-5) * sizeof(char));
182 struct ExtInstruction
* insn
=
183 (struct ExtInstruction
*) xmalloc(sizeof(struct ExtInstruction
));
186 opcode
= 0x1f - 0x10 + minor
- 0x09 + 1;
189 insn
-> flags
= (char) *(p
+4);
190 strcpy(insn_name
, (p
+5));
191 insn
-> name
= insn_name
;
192 arc_extension_map
.instructions
[(int) opcode
] = insn
;
196 case EXT_CORE_REGISTER
:
198 char * core_name
= (char *) xmalloc(((int)*p
-3) * sizeof(char));
200 strcpy(core_name
, (p
+3));
201 arc_extension_map
.coreRegisters
[p
[2]-32] = core_name
;
207 char * cc_name
= (char *) xmalloc( ((int)*p
-3) * sizeof(char));
208 strcpy(cc_name
, (p
+3));
209 arc_extension_map
.condCodes
[p
[2]-16] = cc_name
;
213 case EXT_AUX_REGISTER
:
215 /* trickier -- need to store linked list to these */
216 struct ExtAuxRegister
*newAuxRegister
=
217 (struct ExtAuxRegister
*)malloc(sizeof(struct ExtAuxRegister
));
218 char * aux_name
= (char *) xmalloc ( ((int)*p
-6) * sizeof(char));
220 strcpy (aux_name
, (p
+6));
221 newAuxRegister
->name
= aux_name
;
222 newAuxRegister
->address
= p
[2]<<24 | p
[3]<<16 | p
[4]<<8 | p
[5];
223 newAuxRegister
->next
= arc_extension_map
.auxRegisters
;
224 arc_extension_map
.auxRegisters
= newAuxRegister
;
232 p
+= p
[0]; /* move to next record */
238 /* Load hw extension descibed in .extArcMap ELF section. */
241 build_ARC_extmap (text_bfd
)
248 for (p
= text_bfd
->sections
; p
!= NULL
; p
= p
->next
)
249 if (!strcmp (p
->name
, ".arcextmap"))
251 count
= bfd_get_section_size (p
);
252 arcExtMap
= (char *) xmalloc (count
);
253 if (bfd_get_section_contents (text_bfd
, p
, (PTR
) arcExtMap
, 0, count
))
255 arcExtMap_add ((PTR
) arcExtMap
, count
);
258 free ((PTR
) arcExtMap
);