Ben Cheng | 25b3c04 | 2013-11-20 14:45:36 -0800 | [diff] [blame] | 1 | /* Register names and numbers for SPARC DWARF. |
| 2 | Copyright (C) 2005, 2006 Red Hat, Inc. |
| 3 | This file is part of Red Hat elfutils. |
| 4 | |
| 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
| 8 | |
| 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
| 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
| 17 | |
| 18 | Red Hat elfutils is an included package of the Open Invention Network. |
| 19 | An included package of the Open Invention Network is a package for which |
| 20 | Open Invention Network licensees cross-license their patents. No patent |
| 21 | license is granted, either expressly or impliedly, by designation as an |
| 22 | included package. Should you wish to participate in the Open Invention |
| 23 | Network licensing program, please visit www.openinventionnetwork.com |
| 24 | <http://www.openinventionnetwork.com>. */ |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_H |
| 27 | # include <config.h> |
| 28 | #endif |
| 29 | |
| 30 | #include <string.h> |
| 31 | #include <dwarf.h> |
| 32 | |
| 33 | #define BACKEND sparc_ |
| 34 | #include "libebl_CPU.h" |
| 35 | |
| 36 | ssize_t |
| 37 | sparc_register_info (Ebl *ebl, |
| 38 | int regno, char *name, size_t namelen, |
| 39 | const char **prefix, const char **setname, |
| 40 | int *bits, int *type) |
| 41 | { |
| 42 | const int nfp = 32 + (ebl->machine == EM_SPARC ? 0 : 16); |
| 43 | const int nspec = ebl->machine == EM_SPARC ? 8 : 6; |
| 44 | |
| 45 | if (name == NULL) |
| 46 | return 32 + nfp + nspec; |
| 47 | |
| 48 | if (regno < 0 || regno >= 32 + nfp + nspec || namelen < 6) |
| 49 | return -1; |
| 50 | |
| 51 | *bits = ebl->machine == EM_SPARC ? 32 : 64; |
| 52 | *type = DW_ATE_signed; |
| 53 | |
| 54 | *prefix = "%"; |
| 55 | |
| 56 | if (regno >= 32 + nfp) |
| 57 | { |
| 58 | regno -= 32 + nfp; |
| 59 | static const char names[2][8][6] = |
| 60 | { |
| 61 | { "y", "psr", "wim", "tbr", "pc", "npc", "fsr", "csr" }, /* v8 */ |
| 62 | { "pc", "npc", "state", "fsr", "fprs", "y" } /* v9 */ |
| 63 | }; |
| 64 | *setname = "control"; |
| 65 | *type = DW_ATE_unsigned; |
| 66 | if ((ebl->machine != EM_SPARC ? 0 : 4) + 1 - (unsigned int) regno <= 1) |
| 67 | *type = DW_ATE_address; |
| 68 | return stpncpy (name, names[ebl->machine != EM_SPARC][regno], |
| 69 | namelen) + 1 - name; |
| 70 | } |
| 71 | |
| 72 | if (regno < 32) |
| 73 | { |
| 74 | *setname = "integer"; |
| 75 | name[0] = "goli"[regno >> 3]; |
| 76 | name[1] = (regno & 7) + '0'; |
| 77 | namelen = 2; |
| 78 | if ((regno & 8) && (regno & 7) == 6) |
| 79 | *type = DW_ATE_address; |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | *setname = "FPU"; |
| 84 | *type = DW_ATE_float; |
| 85 | |
| 86 | regno -= 32; |
| 87 | if (regno >= 32) |
| 88 | regno = 32 + 2 * (regno - 32); |
| 89 | else |
| 90 | *bits = 32; |
| 91 | |
| 92 | name[0] = 'f'; |
| 93 | if (regno < 10) |
| 94 | { |
| 95 | name[1] = regno + '0'; |
| 96 | namelen = 2; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | name[1] = regno / 10 + '0'; |
| 101 | name[2] = regno % 10 + '0'; |
| 102 | namelen = 3; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | name[namelen++] = '\0'; |
| 107 | return namelen; |
| 108 | } |