source: trunk/src/binutils/opcodes/arc-ext.c@ 1917

Last change on this file since 1917 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.2 KB
Line 
1/* ARC target-dependent stuff. Extension structure access functions
2 Copyright 1995, 1997, 2000, 2001 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20#include "sysdep.h"
21#include <stdlib.h>
22#include <stdio.h>
23#include "bfd.h"
24#include "arc-ext.h"
25#include "libiberty.h"
26
27/* Extension structure */
28static struct arcExtMap arc_extension_map;
29
30/* Get the name of an extension instruction. */
31
32const char *
33arcExtMap_instName(int opcode, int minor, int *flags)
34{
35 if (opcode == 3)
36 {
37 /* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
38 if (minor < 0x09 || minor == 0x3f)
39 return 0;
40 else
41 opcode = 0x1f - 0x10 + minor - 0x09 + 1;
42 }
43 else
44 if (opcode < 0x10)
45 return 0;
46 else
47 opcode -= 0x10;
48 if (!arc_extension_map.instructions[opcode])
49 return 0;
50 *flags = arc_extension_map.instructions[opcode]->flags;
51 return arc_extension_map.instructions[opcode]->name;
52}
53
54/* Get the name of an extension core register. */
55
56const char *
57arcExtMap_coreRegName(int value)
58{
59 if (value < 32)
60 return 0;
61 return (const char *) arc_extension_map.coreRegisters[value-32];
62}
63
64/* Get the name of an extension condition code. */
65
66const char *
67arcExtMap_condCodeName(int value)
68{
69 if (value < 16)
70 return 0;
71 return (const char *) arc_extension_map.condCodes[value-16];
72}
73
74/* Get the name of an extension aux register. */
75
76const char *
77arcExtMap_auxRegName(long address)
78{
79 /* walk the list of aux reg names and find the name */
80 struct ExtAuxRegister *r;
81
82 for (r = arc_extension_map.auxRegisters; r; r = r->next) {
83 if (r->address == address)
84 return (const char *) r->name;
85 }
86 return 0;
87}
88
89/* Recursively free auxilliary register strcture pointers until
90 the list is empty. */
91
92static void
93clean_aux_registers(struct ExtAuxRegister *r)
94{
95 if (r -> next)
96 {
97 clean_aux_registers( r->next);
98 free(r -> name);
99 free(r -> next);
100 r ->next = NULL;
101 }
102 else
103 free(r -> name);
104}
105
106/* Free memory that has been allocated for the extensions. */
107
108static void
109cleanup_ext_map(void)
110{
111 struct ExtAuxRegister *r;
112 struct ExtInstruction *insn;
113 int i;
114
115 /* clean aux reg structure */
116 r = arc_extension_map.auxRegisters;
117 if (r)
118 {
119 (clean_aux_registers(r));
120 free(r);
121 }
122
123 /* clean instructions */
124 for (i = 0; i < NUM_EXT_INST; i++)
125 {
126 insn = arc_extension_map.instructions[i];
127 if (insn)
128 free(insn->name);
129 }
130
131 /* clean core reg struct */
132 for (i = 0; i < NUM_EXT_CORE; i++)
133 {
134 if (arc_extension_map.coreRegisters[i])
135 free(arc_extension_map.coreRegisters[i]);
136 }
137
138 for (i = 0; i < NUM_EXT_COND; i++) {
139 if (arc_extension_map.condCodes[i])
140 free(arc_extension_map.condCodes[i]);
141 }
142
143 memset(&arc_extension_map, 0, sizeof(struct arcExtMap));
144}
145
146int
147arcExtMap_add(void *base, unsigned long length)
148{
149 unsigned char *block = base;
150 unsigned char *p = block;
151
152 /* Clean up and reset everything if needed. */
153 cleanup_ext_map();
154
155 while (p && p < (block + length))
156 {