198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata/* Register names and numbers for AArch64 DWARF.
2f48eb6b15fee66e54b488d71738979fc608f25eeMark Wielaard   Copyright (C) 2013, 2014 Red Hat, Inc.
398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   This file is part of elfutils.
498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   This file is free software; you can redistribute it and/or modify
698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   it under the terms of either
798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata     * the GNU Lesser General Public License as published by the Free
998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata       Software Foundation; either version 3 of the License, or (at
1098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata       your option) any later version
1198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
1298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   or
1398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
1498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata     * the GNU General Public License as published by the Free
1598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata       Software Foundation; either version 2 of the License, or (at
1698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata       your option) any later version
1798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
1898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   or both in parallel, as here.
1998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
2098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   elfutils is distributed in the hope that it will be useful, but
2198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   WITHOUT ANY WARRANTY; without even the implied warranty of
2298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   General Public License for more details.
2498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
2598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   You should have received copies of the GNU General Public License and
2698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   the GNU Lesser General Public License along with this program.  If
2798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata   not, see <http://www.gnu.org/licenses/>.  */
2898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
2998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#ifdef HAVE_CONFIG_H
3098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata# include <config.h>
3198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#endif
3298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
3398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#include <stdio.h>
3498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#include <string.h>
3598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#include <dwarf.h>
3627ffb08c789ca9c4b2635ca89b4004b324fb4ea4Petr Machata#include <stdarg.h>
3798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
3898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#define BACKEND aarch64_
3998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata#include "libebl_CPU.h"
4098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
41860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh__attribute__ ((format (printf, 7, 8)))
42860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsiehstatic ssize_t
43860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsiehdo_regtype (const char *setname, int type,
44860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh           const char **setnamep, int *typep,
45860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh           char *name, size_t namelen, const char *fmt, ...)
46860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh{
47860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  *setnamep = setname;
48860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  *typep = type;
49860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh
50860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  va_list ap;
51860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  va_start (ap, fmt);
52860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  int s = vsnprintf (name, namelen, fmt, ap);
53860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  va_end(ap);
54860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh
55860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  if (s < 0 || (unsigned) s >= namelen)
56860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh    return -1;
57860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh  return s + 1;
58860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh}
59860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh
6098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machatassize_t
6198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machataaarch64_register_info (Ebl *ebl __attribute__ ((unused)),
6298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata		       int regno, char *name, size_t namelen,
6398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata		       const char **prefix, const char **setnamep,
6498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata		       int *bits, int *typep)
6598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata{
6698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata  if (name == NULL)
6798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    return 128;
6898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
6998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
70b92af19f2110999579a65a5dceab532c97979559Mark Wielaard  *prefix = "";
7198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata  *bits = 64;
7298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
73860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh#define regtype(setname, type, ...) \
74860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh    do_regtype(setname, type, setnamep, typep, name, namelen, __VA_ARGS__)
75860d4312e61ceef1510035dfb851327246705785Chih-Hung Hsieh
7698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata  switch (regno)
7798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    {
7898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 0 ... 30:
7927ffb08c789ca9c4b2635ca89b4004b324fb4ea4Petr Machata      return regtype ("integer", DW_ATE_signed, "x%d", regno);
8098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
8198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 31:
8227ffb08c789ca9c4b2635ca89b4004b324fb4ea4Petr Machata      return regtype ("integer", DW_ATE_address, "sp");
8398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
8498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 32:
8598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      return 0;
8698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
8798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 33:
8827ffb08c789ca9c4b2635ca89b4004b324fb4ea4Petr Machata      return regtype ("integer", DW_ATE_address, "elr");
8998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
9098c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 34 ... 63:
9198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      return 0;
9298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
9398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 64 ... 95:
9498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      /* FP/SIMD register file supports a variety of data types--it
9598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata	 can be thought of as a register holding a single integer or
9698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata	 floating-point value, or a vector of 8-, 16-, 32- or 64-bit
9798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata	 integers.  128-bit quad-word is the only singular value that
9898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata	 covers the whole register, so mark the register thus.  */
9998c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      *bits = 128;
10027ffb08c789ca9c4b2635ca89b4004b324fb4ea4Petr Machata      return regtype ("FP/SIMD", DW_ATE_unsigned, "v%d", regno - 64);
10198c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
10298c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    case 96 ... 127:
10398c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      return 0;
10498c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata
10598c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    default:
10698c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata      return -1;
10798c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata    }
10898c8a7395b4e5e7bed233397148b15c1f8c66490Petr Machata}
109