| 1 | #!/bin/sh -u |
| 2 | |
| 3 | # Register protocol definitions for GDB, the GNU debugger. |
| 4 | # Copyright (C) 2001-2017 Free Software Foundation, Inc. |
| 5 | # |
| 6 | # This file is part of GDB. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 3 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | # Format of the input files |
| 22 | read="type entry" |
| 23 | |
| 24 | do_read () |
| 25 | { |
| 26 | type="" |
| 27 | entry="" |
| 28 | while read line |
| 29 | do |
| 30 | if test "${line}" = "" |
| 31 | then |
| 32 | continue |
| 33 | elif test "${line}" = "#" -a "${comment}" = "" |
| 34 | then |
| 35 | continue |
| 36 | elif expr "${line}" : "#" > /dev/null |
| 37 | then |
| 38 | comment="${comment} |
| 39 | ${line}" |
| 40 | else |
| 41 | |
| 42 | # The semantics of IFS varies between different SH's. Some |
| 43 | # treat ``::' as three fields while some treat it as just too. |
| 44 | # Work around this by eliminating ``::'' .... |
| 45 | line="`echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g'`" |
| 46 | |
| 47 | OFS="${IFS}" ; IFS="[:]" |
| 48 | eval read ${read} <<EOF |
| 49 | ${line} |
| 50 | EOF |
| 51 | IFS="${OFS}" |
| 52 | |
| 53 | # .... and then going back through each field and strip out those |
| 54 | # that ended up with just that space character. |
| 55 | for r in ${read} |
| 56 | do |
| 57 | if eval test \"\${${r}}\" = \"\ \" |
| 58 | then |
| 59 | eval ${r}="" |
| 60 | fi |
| 61 | done |
| 62 | |
| 63 | break |
| 64 | fi |
| 65 | done |
| 66 | if [ -n "${type}" ] |
| 67 | then |
| 68 | true |
| 69 | else |
| 70 | false |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | if test ! -r $1; then |
| 75 | echo "$0: Could not open $1." 1>&2 |
| 76 | exit 1 |
| 77 | fi |
| 78 | |
| 79 | copyright () |
| 80 | { |
| 81 | cat <<EOF |
| 82 | /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */ |
| 83 | |
| 84 | /* A register protocol for GDB, the GNU debugger. |
| 85 | Copyright (C) 2001-2013 Free Software Foundation, Inc. |
| 86 | |
| 87 | This file is part of GDB. |
| 88 | |
| 89 | This program is free software; you can redistribute it and/or modify |
| 90 | it under the terms of the GNU General Public License as published by |
| 91 | the Free Software Foundation; either version 3 of the License, or |
| 92 | (at your option) any later version. |
| 93 | |
| 94 | This program is distributed in the hope that it will be useful, |
| 95 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 96 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 97 | GNU General Public License for more details. |
| 98 | |
| 99 | You should have received a copy of the GNU General Public License |
| 100 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 101 | |
| 102 | /* This file was created with the aid of \`\`regdat.sh'' and \`\`$1''. */ |
| 103 | |
| 104 | EOF |
| 105 | } |
| 106 | |
| 107 | |
| 108 | exec > new-$2 |
| 109 | copyright $1 |
| 110 | echo '#include "server.h"' |
| 111 | echo '#include "regdef.h"' |
| 112 | echo '#include "tdesc.h"' |
| 113 | echo |
| 114 | offset=0 |
| 115 | i=0 |
| 116 | name=x |
| 117 | xmltarget=x |
| 118 | xmlarch=x |
| 119 | xmlosabi=x |
| 120 | expedite=x |
| 121 | exec < $1 |
| 122 | while do_read |
| 123 | do |
| 124 | if test "${type}" = "name"; then |
| 125 | name="${entry}" |
| 126 | |
| 127 | echo "const struct target_desc *tdesc_${name};" |
| 128 | echo "" |
| 129 | echo "void" |
| 130 | echo "init_registers_${name} (void)" |
| 131 | echo "{" |
| 132 | echo " static struct target_desc tdesc_${name}_s;" |
| 133 | echo " struct target_desc *result = &tdesc_${name}_s;" |
| 134 | |
| 135 | continue |
| 136 | elif test "${type}" = "xmltarget"; then |
| 137 | xmltarget="${entry}" |
| 138 | continue |
| 139 | elif test "${type}" = "xmlarch"; then |
| 140 | xmlarch="${entry}" |
| 141 | continue |
| 142 | elif test "${type}" = "osabi"; then |
| 143 | xmlosabi="${entry}" |
| 144 | continue |
| 145 | elif test "${type}" = "expedite"; then |
| 146 | expedite="${entry}" |
| 147 | continue |
| 148 | elif test "${name}" = x; then |
| 149 | echo "$0: $1 does not specify \`\`name''." 1>&2 |
| 150 | exit 1 |
| 151 | else |
| 152 | echo " tdesc_create_reg ((struct tdesc_feature *) result, \"${entry}\"," |
| 153 | echo " 0, 0, NULL, ${type}, NULL);" |
| 154 | |
| 155 | offset=`expr ${offset} + ${type}` |
| 156 | i=`expr $i + 1` |
| 157 | fi |
| 158 | done |
| 159 | |
| 160 | echo |
| 161 | echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };" |
| 162 | if test "${xmltarget}" = x; then |
| 163 | if test "${xmlarch}" = x && test "${xmlosabi}" = x; then |
| 164 | echo "static const char *xmltarget_${name} = 0;" |
| 165 | else |
| 166 | echo "static const char *xmltarget_${name} = \"@<target>\\" |
| 167 | if test "${xmlarch}" != x; then |
| 168 | echo "<architecture>${xmlarch}</architecture>\\" |
| 169 | fi |
| 170 | if test "${xmlosabi}" != x; then |
| 171 | echo "<osabi>${xmlosabi}</osabi>\\" |
| 172 | fi |
| 173 | echo "</target>\";" |
| 174 | fi |
| 175 | else |
| 176 | echo "static const char *xmltarget_${name} = \"${xmltarget}\";" |
| 177 | fi |
| 178 | echo |
| 179 | |
| 180 | cat <<EOF |
| 181 | #ifndef IN_PROCESS_AGENT |
| 182 | result->expedite_regs = expedite_regs_${name}; |
| 183 | result->xmltarget = xmltarget_${name}; |
| 184 | #endif |
| 185 | |
| 186 | init_target_desc (result); |
| 187 | |
| 188 | tdesc_${name} = result; |
| 189 | } |
| 190 | EOF |
| 191 | |
| 192 | # close things off |
| 193 | exec 1>&2 |
| 194 | mv -- "new-$2" "$2" |