1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "build-config.h"
32 error (const char *msg
, ...)
44 void *memory
= malloc(size
);
46 error("zalloc failed\n");
47 memset(memory
, 0, size
);
52 dumpf (int indent
, const char *msg
, ...)
55 for (; indent
> 0; indent
--)
80 if (a
[1] == 'x' || a
[1] == 'X') {
98 if (ch
>= '0' && ch
<= '9') {
99 num
= (num
* 10) + (ch
- '0');
106 if (ch
>= '0' && ch
<= '7') {
107 num
= (num
* 8) + (ch
- '0');
114 if (ch
>= '0' && ch
<= '9') {
115 num
= (num
* 16) + (ch
- '0');
116 } else if (ch
>= 'a' && ch
<= 'f') {
117 num
= (num
* 16) + (ch
- 'a' + 10);
118 } else if (ch
>= 'A' && ch
<= 'F') {
119 num
= (num
* 16) + (ch
- 'A' + 10);
134 target_a2i(int ms_bit_nr
,
138 return (ms_bit_nr
- a2i(a
));
144 i2target(int ms_bit_nr
,
148 return ms_bit_nr
- bit
;
155 name2i(const char *names
,
158 const name_map
*curr
;
159 const char *name
= names
;
160 while (*name
!= '\0') {
162 const char *end
= strchr(name
, ',');
166 end
= strchr(name
, '\0');
175 while (curr
->name
!= NULL
) {
176 if (strncmp(curr
->name
, name
, len
) == 0
177 && strlen(curr
->name
) == len
)
183 /* nothing found, possibly return a default */
185 while (curr
->name
!= NULL
)
190 error("%s contains no valid names\n", names
);
198 while (map
->name
!= NULL
) {
203 error("map lookup failed for %d\n", i
);