| 1 | /* Target-machine dependent code for WDC-65816, for GDB. |
| 2 | Copyright (C) 1995 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | /* |
| 22 | Contributed by Steve Chamberlain |
| 23 | sac@cygnus.com |
| 24 | */ |
| 25 | |
| 26 | #include "defs.h" |
| 27 | #include "frame.h" |
| 28 | #include "obstack.h" |
| 29 | #include "symtab.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "gdbtypes.h" |
| 32 | #include "dis-asm.h" |
| 33 | #include "gdbcore.h" |
| 34 | |
| 35 | /* Return the saved PC from this frame. */ |
| 36 | |
| 37 | |
| 38 | CORE_ADDR |
| 39 | w65_frame_saved_pc (struct frame_info *frame) |
| 40 | { |
| 41 | return (read_memory_integer (frame->frame + 2, 4) & 0xffffff); |
| 42 | } |
| 43 | |
| 44 | CORE_ADDR |
| 45 | w65_addr_bits_remove (CORE_ADDR addr) |
| 46 | { |
| 47 | return ((addr) & 0xffffff); |
| 48 | } |
| 49 | |
| 50 | read_memory_pointer (CORE_ADDR x) |
| 51 | { |
| 52 | return read_memory_integer (ADDR_BITS_REMOVE (x), 4); |
| 53 | } |
| 54 | |
| 55 | init_frame_pc (void) |
| 56 | { |
| 57 | abort (); |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | w65_push_dummy_frame (void) |
| 62 | { |
| 63 | abort (); |
| 64 | } |
| 65 | |
| 66 | /* Put here the code to store, into a struct frame_saved_regs, |
| 67 | the addresses of the saved registers of frame described by FRAME_INFO. |
| 68 | This includes special registers such as pc and fp saved in special |
| 69 | ways in the stack frame. sp is even more special: |
| 70 | the address we return for it IS the sp for the next frame. |
| 71 | |
| 72 | We cache the result of doing this in the frame_cache_obstack, since |
| 73 | it is fairly expensive. */ |
| 74 | |
| 75 | void |
| 76 | frame_find_saved_regs (struct frame_info *fip, struct frame_saved_regs *fsrp) |
| 77 | { |
| 78 | int locals; |
| 79 | CORE_ADDR pc; |
| 80 | CORE_ADDR adr; |
| 81 | int i; |
| 82 | |
| 83 | memset (fsrp, 0, sizeof *fsrp); |
| 84 | } |
| 85 | |
| 86 | int |
| 87 | saved_pc_after_call (void) |
| 88 | { |
| 89 | int sp = read_register (SP_REGNUM); |
| 90 | int val = read_memory_integer (sp + 1, 4); |
| 91 | return ADDR_BITS_REMOVE (val); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | extract_return_value (struct type *type, char *regbuf, char *valbuf) |
| 96 | { |
| 97 | int b; |
| 98 | int len = TYPE_LENGTH (type); |
| 99 | |
| 100 | for (b = 0; b < len; b += 2) |
| 101 | { |
| 102 | int todo = len - b; |
| 103 | if (todo > 2) |
| 104 | todo = 2; |
| 105 | memcpy (valbuf + b, regbuf + b, todo); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | write_return_value (struct type *type, char *valbuf) |
| 111 | { |
| 112 | int reg; |
| 113 | int len; |
| 114 | for (len = 0; len < TYPE_LENGTH (type); len += 2) |
| 115 | { |
| 116 | write_register_bytes (REGISTER_BYTE (len / 2 + 2), valbuf + len, 2); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
| 122 | { |
| 123 | write_register (2, addr); |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | w65_pop_frame (void) |
| 128 | { |
| 129 | } |
| 130 | |
| 131 | init_extra_frame_info (void) |
| 132 | { |
| 133 | } |
| 134 | |
| 135 | pop_frame (void) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | w65_frame_chain (struct frame_info *thisframe) |
| 140 | { |
| 141 | return 0xffff & read_memory_integer ((thisframe)->frame, 2); |
| 142 | } |
| 143 | |
| 144 | static int |
| 145 | gb (int x) |
| 146 | { |
| 147 | return read_memory_integer (x, 1) & 0xff; |
| 148 | } |
| 149 | |
| 150 | extern CORE_ADDR |
| 151 | w65_skip_prologue (CORE_ADDR pc) |
| 152 | { |
| 153 | CORE_ADDR too_far = pc + 20; |
| 154 | |
| 155 | /* looking for bits of the prologue, we can expect to |
| 156 | see this in a frameful function: |
| 157 | |
| 158 | stack adjust: |
| 159 | |
| 160 | 3B tsc |
| 161 | 1A inc a |
| 162 | 18 clc |
| 163 | 69E2FF adc #0xffe2 |
| 164 | 3A dec a |
| 165 | 1B tcs |
| 166 | 1A inc a |
| 167 | |
| 168 | link: |
| 169 | |
| 170 | A500 lda <r15 |
| 171 | 48 pha |
| 172 | 3B tsc |
| 173 | 1a inc a |
| 174 | 8500 sta <r15 |
| 175 | |
| 176 | */ |
| 177 | |
| 178 | #define TSC 0x3b |
| 179 | #define TCS 0x1b |
| 180 | #define INCA 0x1a |
| 181 | #define PHA 0x48 |
| 182 | #define LDADIR 0xa5 |
| 183 | #define STADIR 0x85 |
| 184 | |
| 185 | /* Skip a stack adjust - any area between a tsc and tcs */ |
| 186 | if (gb (pc) == TSC) |
| 187 | { |
| 188 | while (pc < too_far && gb (pc) != TCS) |
| 189 | { |
| 190 | pc++; |
| 191 | } |
| 192 | pc++; |
| 193 | /* Skip a stupid inc a */ |
| 194 | if (gb (pc) == INCA) |
| 195 | pc++; |
| 196 | |
| 197 | } |
| 198 | /* Stack adjust can also be done with n pha's */ |
| 199 | while (gb (pc) == PHA) |
| 200 | pc++; |
| 201 | |
| 202 | /* Skip a link - that's a ld/ph/tsc/inc/sta */ |
| 203 | |
| 204 | if (gb (pc) == LDADIR |
| 205 | && gb (pc + 5) == STADIR |
| 206 | && gb (pc + 1) == gb (pc + 6) |
| 207 | && gb (pc + 2) == PHA |
| 208 | && gb (pc + 3) == TSC |
| 209 | && gb (pc + 4) == INCA) |
| 210 | { |
| 211 | pc += 7; |
| 212 | } |
| 213 | |
| 214 | return pc; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | register_raw_size (int n) |
| 219 | { |
| 220 | return sim_reg_size (n); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | void |
| 225 | print_register_hook (int regno) |
| 226 | { |
| 227 | if (regno == P_REGNUM) |
| 228 | { |
| 229 | /* CCR register */ |
| 230 | |
| 231 | int C, Z, N, V, I, D, X, M; |
| 232 | unsigned char b[1]; |
| 233 | unsigned char l; |
| 234 | |
| 235 | read_relative_register_raw_bytes (regno, b); |
| 236 | l = b[0]; |
| 237 | printf_unfiltered ("\t"); |
| 238 | C = (l & 0x1) != 0; |
| 239 | Z = (l & 0x2) != 0; |
| 240 | I = (l & 0x4) != 0; |
| 241 | D = (l & 0x8) != 0; |
| 242 | X = (l & 0x10) != 0; |
| 243 | M = (l & 0x20) != 0; |
| 244 | V = (l & 0x40) != 0; |
| 245 | N = (l & 0x80) != 0; |
| 246 | |
| 247 | printf_unfiltered ("N-%d ", N); |
| 248 | printf_unfiltered ("V-%d ", V); |
| 249 | printf_unfiltered ("M-%d ", M); |
| 250 | printf_unfiltered ("X-%d ", X); |
| 251 | printf_unfiltered ("D-%d ", D); |
| 252 | printf_unfiltered ("I-%d ", I); |
| 253 | printf_unfiltered ("Z-%d ", Z); |
| 254 | printf_unfiltered ("C-%d ", C); |
| 255 | if ((C | Z) == 0) |
| 256 | printf_unfiltered ("u> "); |
| 257 | if ((C | Z) == 1) |
| 258 | printf_unfiltered ("u<= "); |
| 259 | if ((C == 0)) |
| 260 | printf_unfiltered ("u>= "); |
| 261 | if (C == 1) |
| 262 | printf_unfiltered ("u< "); |
| 263 | if (Z == 0) |
| 264 | printf_unfiltered ("!= "); |
| 265 | if (Z == 1) |
| 266 | printf_unfiltered ("== "); |
| 267 | if ((N ^ V) == 0) |
| 268 | printf_unfiltered (">= "); |
| 269 | if ((N ^ V) == 1) |
| 270 | printf_unfiltered ("< "); |
| 271 | if ((Z | (N ^ V)) == 0) |
| 272 | printf_unfiltered ("> "); |
| 273 | if ((Z | (N ^ V)) == 1) |
| 274 | printf_unfiltered ("<= "); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void |
| 279 | _initialize_w65_tdep (void) |
| 280 | { |
| 281 | tm_print_insn = print_insn_w65; |
| 282 | } |