| 1 | /* This file is part of the program psim. |
| 2 | |
| 3 | Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> |
| 4 | |
| 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 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 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. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #ifndef _REGISTERS_C_ |
| 23 | #define _REGISTERS_C_ |
| 24 | |
| 25 | #ifndef STATIC_INLINE_REGISTERS |
| 26 | #define STATIC_INLINE_REGISTERS STATIC_INLINE |
| 27 | #endif |
| 28 | |
| 29 | |
| 30 | #include <ctype.h> |
| 31 | |
| 32 | #include "basics.h" |
| 33 | #include "registers.h" |
| 34 | |
| 35 | #ifdef HAVE_STDLIB_H |
| 36 | #include <stdlib.h> |
| 37 | #endif |
| 38 | |
| 39 | #ifdef HAVE_STRING_H |
| 40 | #include <string.h> |
| 41 | #else |
| 42 | #ifdef HAVE_STRINGS_H |
| 43 | #include <strings.h> |
| 44 | #endif |
| 45 | #endif |
| 46 | |
| 47 | |
| 48 | INLINE_REGISTERS void |
| 49 | registers_dump(registers *registers) |
| 50 | { |
| 51 | int i; |
| 52 | int j; |
| 53 | for (i = 0; i < 8; i++) { |
| 54 | printf_filtered("GPR %2d:", i*4); |
| 55 | for (j = 0; j < 4; j++) { |
| 56 | printf_filtered(" 0x%08x", registers->gpr[i*4 + j]); |
| 57 | } |
| 58 | printf_filtered("\n"); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | STATIC_INLINE_REGISTERS sprs |
| 63 | find_spr(const char name[]) |
| 64 | { |
| 65 | sprs spr; |
| 66 | for (spr = 0; spr < nr_of_sprs; spr++) |
| 67 | if (spr_is_valid(spr) |
| 68 | && !strcmp(name, spr_name(spr)) |
| 69 | && spr_index(spr) == spr) |
| 70 | return spr; |
| 71 | return nr_of_sprs; |
| 72 | } |
| 73 | |
| 74 | STATIC_INLINE_REGISTERS int |
| 75 | are_digits(const char *digits) |
| 76 | { |
| 77 | while (isdigit(*digits)) |
| 78 | digits++; |
| 79 | return *digits == '\0'; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | INLINE_REGISTERS register_descriptions |
| 84 | register_description(const char reg[]) |
| 85 | { |
| 86 | register_descriptions description; |
| 87 | |
| 88 | /* try for a general-purpose integer or floating point register */ |
| 89 | if (reg[0] == 'r' && are_digits(reg + 1)) { |
| 90 | description.type = reg_gpr; |
| 91 | description.index = atoi(reg+1); |
| 92 | description.size = sizeof(gpreg); |
| 93 | } |
| 94 | else if (reg[0] == 'f' && are_digits(reg + 1)) { |
| 95 | description.type = reg_fpr; |
| 96 | description.index = atoi(reg+1); |
| 97 | description.size = sizeof(fpreg); |
| 98 | } |
| 99 | else if (!strcmp(reg, "pc") || !strcmp(reg, "nia")) { |
| 100 | description.type = reg_pc; |
| 101 | description.index = 0; |
| 102 | description.size = sizeof(unsigned_word); |
| 103 | } |
| 104 | else if (!strcmp(reg, "sp")) { |
| 105 | description.type = reg_gpr; |
| 106 | description.index = 1; |
| 107 | description.size = sizeof(gpreg); |
| 108 | } |
| 109 | else if (!strcmp(reg, "toc")) { |
| 110 | description.type = reg_gpr; |
| 111 | description.index = 2; |
| 112 | description.size = sizeof(gpreg); |
| 113 | } |
| 114 | else if (!strcmp(reg, "cr") || !strcmp(reg, "cnd")) { |
| 115 | description.type = reg_cr; |
| 116 | description.index = 0; |
| 117 | description.size = sizeof(creg); /* FIXME */ |
| 118 | } |
| 119 | else if (!strcmp(reg, "msr") || !strcmp(reg, "ps")) { |
| 120 | description.type = reg_msr; |
| 121 | description.index = 0; |
| 122 | description.size = sizeof(msreg); |
| 123 | } |
| 124 | else if (!strncmp(reg, "sr", 2) && are_digits(reg + 2)) { |
| 125 | description.type = reg_sr; |
| 126 | description.index = atoi(reg+2); |
| 127 | description.size = sizeof(sreg); |
| 128 | } |
| 129 | else if (!strcmp(reg, "cnt")) { |
| 130 | description.type = reg_spr; |
| 131 | description.index = spr_ctr; |
| 132 | description.size = sizeof(spreg); |
| 133 | } |
| 134 | else { |
| 135 | sprs spr = find_spr(reg); |
| 136 | if (spr != nr_of_sprs) { |
| 137 | description.type = reg_spr; |
| 138 | description.index = spr; |
| 139 | description.size = sizeof(spreg); |
| 140 | } |
| 141 | else { |
| 142 | description.type = reg_invalid; |
| 143 | description.index = 0; |
| 144 | description.size = 0; |
| 145 | } |
| 146 | } |
| 147 | return description; |
| 148 | } |
| 149 | |
| 150 | #endif /* _REGISTERS_C_ */ |