2001-08-31 22:05:24 +02:00
|
|
|
/* ARC target-dependent stuff. Extension structure access functions
|
2014-03-05 12:46:15 +01:00
|
|
|
Copyright (C) 1995-2014 Free Software Foundation, Inc.
|
2001-01-11 22:20:20 +01:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This file is part of libopcodes.
|
2001-01-11 22:20:20 +01:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
This library is free software; you can redistribute it and/or modify
|
2001-01-11 22:20:20 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 11:49:03 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
2001-01-11 22:20:20 +01:00
|
|
|
|
2007-07-05 11:49:03 +02:00
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
License for more details.
|
2001-01-11 22:20:20 +01:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2007-07-05 11:49:03 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
2001-01-11 22:20:20 +01:00
|
|
|
|
2001-08-31 22:05:24 +02:00
|
|
|
#include "sysdep.h"
|
2001-01-11 22:20:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "arc-ext.h"
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
|
|
|
/* Extension structure */
|
|
|
|
static struct arcExtMap arc_extension_map;
|
|
|
|
|
|
|
|
/* Get the name of an extension instruction. */
|
|
|
|
|
|
|
|
const char *
|
2001-08-31 22:05:24 +02:00
|
|
|
arcExtMap_instName(int opcode, int minor, int *flags)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
2001-08-31 22:05:24 +02:00
|
|
|
if (opcode == 3)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
/* FIXME: ??? need to also check 0/1/2 in bit0 for (3f) brk/sleep/swi */
|
|
|
|
if (minor < 0x09 || minor == 0x3f)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
opcode = 0x1f - 0x10 + minor - 0x09 + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (opcode < 0x10)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
opcode -= 0x10;
|
|
|
|
if (!arc_extension_map.instructions[opcode])
|
|
|
|
return 0;
|
|
|
|
*flags = arc_extension_map.instructions[opcode]->flags;
|
|
|
|
return arc_extension_map.instructions[opcode]->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the name of an extension core register. */
|
|
|
|
|
|
|
|
const char *
|
2001-08-31 22:05:24 +02:00
|
|
|
arcExtMap_coreRegName(int value)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
if (value < 32)
|
|
|
|
return 0;
|
2005-02-22 14:01:53 +01:00
|
|
|
return arc_extension_map.coreRegisters[value-32];
|
2001-01-11 22:20:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the name of an extension condition code. */
|
|
|
|
|
|
|
|
const char *
|
2001-08-31 22:05:24 +02:00
|
|
|
arcExtMap_condCodeName(int value)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
if (value < 16)
|
|
|
|
return 0;
|
2005-02-22 14:01:53 +01:00
|
|
|
return arc_extension_map.condCodes[value-16];
|
2001-01-11 22:20:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the name of an extension aux register. */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
arcExtMap_auxRegName(long address)
|
|
|
|
{
|
|
|
|
/* walk the list of aux reg names and find the name */
|
|
|
|
struct ExtAuxRegister *r;
|
|
|
|
|
|
|
|
for (r = arc_extension_map.auxRegisters; r; r = r->next) {
|
|
|
|
if (r->address == address)
|
|
|
|
return (const char *) r->name;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recursively free auxilliary register strcture pointers until
|
|
|
|
the list is empty. */
|
|
|
|
|
2001-08-31 22:05:24 +02:00
|
|
|
static void
|
2001-01-11 22:20:20 +01:00
|
|
|
clean_aux_registers(struct ExtAuxRegister *r)
|
|
|
|
{
|
|
|
|
if (r -> next)
|
|
|
|
{
|
|
|
|
clean_aux_registers( r->next);
|
|
|
|
free(r -> name);
|
|
|
|
free(r -> next);
|
|
|
|
r ->next = NULL;
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
else
|
2001-01-11 22:20:20 +01:00
|
|
|
free(r -> name);
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
/* Free memory that has been allocated for the extensions. */
|
|
|
|
|
2001-08-31 22:05:24 +02:00
|
|
|
static void
|
|
|
|
cleanup_ext_map(void)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
struct ExtAuxRegister *r;
|
|
|
|
struct ExtInstruction *insn;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* clean aux reg structure */
|
|
|
|
r = arc_extension_map.auxRegisters;
|
2001-08-31 22:05:24 +02:00
|
|
|
if (r)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
(clean_aux_registers(r));
|
|
|
|
free(r);
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
/* clean instructions */
|
2001-08-31 22:05:24 +02:00
|
|
|
for (i = 0; i < NUM_EXT_INST; i++)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
insn = arc_extension_map.instructions[i];
|
|
|
|
if (insn)
|
|
|
|
free(insn->name);
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
/* clean core reg struct */
|
2001-08-31 22:05:24 +02:00
|
|
|
for (i = 0; i < NUM_EXT_CORE; i++)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
if (arc_extension_map.coreRegisters[i])
|
|
|
|
free(arc_extension_map.coreRegisters[i]);
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
for (i = 0; i < NUM_EXT_COND; i++) {
|
|
|
|
if (arc_extension_map.condCodes[i])
|
|
|
|
free(arc_extension_map.condCodes[i]);
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
|
|
|
memset(&arc_extension_map, 0, sizeof(struct arcExtMap));
|
2001-01-11 22:20:20 +01:00
|
|
|
}
|
|
|
|
|
2001-08-31 22:05:24 +02:00
|
|
|
int
|
|
|
|
arcExtMap_add(void *base, unsigned long length)
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
Update soruces to make alpha, arc and arm targets compile cleanly
with -Wc++-compat:
* config/tc-alpha.c: Add casts.
(extended_bfd_reloc_code_real_type): New type. Used to avoid
enumeration conversion warnings.
(struct alpha_fixup, void assemble_insn, assemble_insn)
(assemble_tokens): Use new type.
* ecoff.c: Add casts. (mark_stabs): Use enumeration names.
* config/obj-elf.c: Add cast
* config/tc-arc.c: Add casts.
* config/obj-aout.h (text_section,data_section,bss_section):
Make extern.
* config/obj-elf.c: Add cast.
* config/tc-arm.c: Add casts.
(X, TxCE, TxCE, TxC3, TxC3w, TxCM_, TxCM, TUE, TUF, CE, CL, cCE)
(cCL, C3E, xCM_, nUF, nCE_tag): Change input format to avoid the
need for keywords as arguments.
* ecoff.c: Add casts.
* ecofflink.c: Add casts.
* elf64-alpha.c: Add casts.
(struct alpha_elf_got_entry, struct alpha_elf_reloc_entry): Move
to top level.
(SKIP_HOWTO): Use enum name.
* elf32-arm.c: Add casts.
(elf32_arm_vxworks_bed): Update code to avoid multiple
declarations.
(struct map_stub): Move to top level.
* arc-dis.c Fix casts.
* arc-ext.c: Add casts.
* arm-dis.c (enum opcode_sentinel_enum): Gave name to anonymous
enum.
* emultempl/armelf.em: Add casts.
2009-09-25 21:13:27 +02:00
|
|
|
unsigned char *block = (unsigned char *) base;
|
|
|
|
unsigned char *p = (unsigned char *) block;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
/* Clean up and reset everything if needed. */
|
|
|
|
cleanup_ext_map();
|
|
|
|
|
2001-08-31 22:05:24 +02:00
|
|
|
while (p && p < (block + length))
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
/* p[0] == length of record
|
|
|
|
p[1] == type of record
|
|
|
|
For instructions:
|
|
|
|
p[2] = opcode
|
|
|
|
p[3] = minor opcode (if opcode == 3)
|
|
|
|
p[4] = flags
|
|
|
|
p[5]+ = name
|
|
|
|
For core regs and condition codes:
|
|
|
|
p[2] = value
|
|
|
|
p[3]+ = name
|
|
|
|
For aux regs:
|
|
|
|
p[2..5] = value
|
|
|
|
p[6]+ = name
|
|
|
|
(value is p[2]<<24|p[3]<<16|p[4]<<8|p[5]) */
|
|
|
|
|
|
|
|
if (p[0] == 0)
|
|
|
|
return -1;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
switch (p[1])
|
|
|
|
{
|
|
|
|
case EXT_INSTRUCTION:
|
|
|
|
{
|
|
|
|
char opcode = p[2];
|
|
|
|
char minor = p[3];
|
|
|
|
char * insn_name = (char *) xmalloc(( (int)*p-5) * sizeof(char));
|
2001-08-31 22:05:24 +02:00
|
|
|
struct ExtInstruction * insn =
|
2001-01-11 22:20:20 +01:00
|
|
|
(struct ExtInstruction *) xmalloc(sizeof(struct ExtInstruction));
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
if (opcode==3)
|
|
|
|
opcode = 0x1f - 0x10 + minor - 0x09 + 1;
|
|
|
|
else
|
|
|
|
opcode -= 0x10;
|
|
|
|
insn -> flags = (char) *(p+4);
|
2005-02-22 14:01:53 +01:00
|
|
|
strcpy (insn_name, (char *) (p+5));
|
2001-01-11 22:20:20 +01:00
|
|
|
insn -> name = insn_name;
|
|
|
|
arc_extension_map.instructions[(int) opcode] = insn;
|
|
|
|
}
|
|
|
|
break;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
|
|
|
case EXT_CORE_REGISTER:
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
char * core_name = (char *) xmalloc(((int)*p-3) * sizeof(char));
|
|
|
|
|
2005-02-22 14:01:53 +01:00
|
|
|
strcpy(core_name, (char *) (p+3));
|
2001-01-11 22:20:20 +01:00
|
|
|
arc_extension_map.coreRegisters[p[2]-32] = core_name;
|
|
|
|
}
|
|
|
|
break;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
|
|
|
case EXT_COND_CODE:
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
char * cc_name = (char *) xmalloc( ((int)*p-3) * sizeof(char));
|
2005-02-22 14:01:53 +01:00
|
|
|
strcpy(cc_name, (char *) (p+3));
|
2001-01-11 22:20:20 +01:00
|
|
|
arc_extension_map.condCodes[p[2]-16] = cc_name;
|
2001-08-31 22:05:24 +02:00
|
|
|
}
|
2001-01-11 22:20:20 +01:00
|
|
|
break;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
|
|
|
case EXT_AUX_REGISTER:
|
2001-01-11 22:20:20 +01:00
|
|
|
{
|
|
|
|
/* trickier -- need to store linked list to these */
|
2001-08-31 22:05:24 +02:00
|
|
|
struct ExtAuxRegister *newAuxRegister =
|
2001-01-11 22:20:20 +01:00
|
|
|
(struct ExtAuxRegister *)malloc(sizeof(struct ExtAuxRegister));
|
|
|
|
char * aux_name = (char *) xmalloc ( ((int)*p-6) * sizeof(char));
|
|
|
|
|
2005-02-22 14:01:53 +01:00
|
|
|
strcpy (aux_name, (char *) (p+6));
|
2001-01-11 22:20:20 +01:00
|
|
|
newAuxRegister->name = aux_name;
|
|
|
|
newAuxRegister->address = p[2]<<24 | p[3]<<16 | p[4]<<8 | p[5];
|
|
|
|
newAuxRegister->next = arc_extension_map.auxRegisters;
|
|
|
|
arc_extension_map.auxRegisters = newAuxRegister;
|
|
|
|
}
|
|
|
|
break;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
default:
|
|
|
|
return -1;
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
}
|
|
|
|
p += p[0]; /* move to next record */
|
|
|
|
}
|
2001-08-31 22:05:24 +02:00
|
|
|
|
2001-01-11 22:20:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load hw extension descibed in .extArcMap ELF section. */
|
|
|
|
|
|
|
|
void
|
|
|
|
build_ARC_extmap (text_bfd)
|
|
|
|
bfd *text_bfd;
|
|
|
|
{
|
|
|
|
char *arcExtMap;
|
|
|
|
bfd_size_type count;
|
|
|
|
asection *p;
|
|
|
|
|
|
|
|
for (p = text_bfd->sections; p != NULL; p = p->next)
|
|
|
|
if (!strcmp (p->name, ".arcextmap"))
|
|
|
|
{
|
2004-06-15 03:14:22 +02:00
|
|
|
count = bfd_get_section_size (p);
|
2001-01-11 22:20:20 +01:00
|
|
|
arcExtMap = (char *) xmalloc (count);
|
|
|
|
if (bfd_get_section_contents (text_bfd, p, (PTR) arcExtMap, 0, count))
|
|
|
|
{
|
|
|
|
arcExtMap_add ((PTR) arcExtMap, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free ((PTR) arcExtMap);
|
|
|
|
}
|
|
|
|
}
|