| 1 | /* Target-machine dependent code for Hitachi H8/500, for GDB. |
| 2 | Copyright (C) 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | /* |
| 21 | Contributed by Steve Chamberlain |
| 22 | sac@cygnus.com |
| 23 | */ |
| 24 | |
| 25 | #include "defs.h" |
| 26 | #include "frame.h" |
| 27 | #include "obstack.h" |
| 28 | #include "symtab.h" |
| 29 | #include "gdbtypes.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "value.h" |
| 32 | #include "dis-asm.h" |
| 33 | #include "../opcodes/h8500-opc.h" |
| 34 | ; |
| 35 | |
| 36 | #define UNSIGNED_SHORT(X) ((X) & 0xffff) |
| 37 | |
| 38 | /* Shape of an H8/500 frame : |
| 39 | |
| 40 | |
| 41 | arg-n |
| 42 | .. |
| 43 | arg-2 |
| 44 | arg-1 |
| 45 | return address <2 or 4 bytes> |
| 46 | old fp <2 bytes> |
| 47 | auto-n |
| 48 | .. |
| 49 | auto-1 |
| 50 | saved registers |
| 51 | |
| 52 | */ |
| 53 | |
| 54 | |
| 55 | /* an easy to debug H8 stack frame looks like: |
| 56 | 0x6df6 push r6 |
| 57 | 0x0d76 mov.w r7,r6 |
| 58 | 0x6dfn push reg |
| 59 | 0x7905 nnnn mov.w #n,r5 or 0x1b87 subs #2,sp |
| 60 | 0x1957 sub.w r5,sp |
| 61 | |
| 62 | */ |
| 63 | |
| 64 | #define IS_PUSH(x) (((x) & 0xff00)==0x6d00) |
| 65 | #define IS_LINK_8(x) ((x) == 0x17) |
| 66 | #define IS_LINK_16(x) ((x) == 0x1f) |
| 67 | #define IS_MOVE_FP(x) ((x) == 0x0d76) |
| 68 | #define IS_MOV_SP_FP(x) ((x) == 0x0d76) |
| 69 | #define IS_SUB2_SP(x) ((x) == 0x1b87) |
| 70 | #define IS_MOVK_R5(x) ((x) == 0x7905) |
| 71 | #define IS_SUB_R5SP(x) ((x) == 0x1957) |
| 72 | |
| 73 | #define LINK_8 0x17 |
| 74 | #define LINK_16 0x1f |
| 75 | |
| 76 | int minimum_mode = 1; |
| 77 | CORE_ADDR examine_prologue (); |
| 78 | |
| 79 | void frame_find_saved_regs (); |
| 80 | |
| 81 | int regoff[NUM_REGS] = |
| 82 | {0, 2, 4, 6, 8, 10, 12, 14, /* r0->r7 */ |
| 83 | 16, 18, /* ccr, pc */ |
| 84 | 20, 21, 22, 23}; /* cp, dp, ep, tp */ |
| 85 | |
| 86 | CORE_ADDR |
| 87 | h8500_skip_prologue (start_pc) |
| 88 | CORE_ADDR start_pc; |
| 89 | |
| 90 | { |
| 91 | short int w; |
| 92 | |
| 93 | w = read_memory_integer (start_pc, 1); |
| 94 | if (w == LINK_8) |
| 95 | { |
| 96 | start_pc += 2; |
| 97 | w = read_memory_integer (start_pc, 1); |
| 98 | } |
| 99 | |
| 100 | if (w == LINK_16) |
| 101 | { |
| 102 | start_pc += 3; |
| 103 | w = read_memory_integer (start_pc, 2); |
| 104 | } |
| 105 | |
| 106 | return start_pc; |
| 107 | } |
| 108 | |
| 109 | int |
| 110 | print_insn (memaddr, stream) |
| 111 | CORE_ADDR memaddr; |
| 112 | FILE *stream; |
| 113 | { |
| 114 | disassemble_info info; |
| 115 | GDB_INIT_DISASSEMBLE_INFO (info, stream); |
| 116 | return print_insn_h8500 (memaddr, &info); |
| 117 | } |
| 118 | |
| 119 | /* Given a GDB frame, determine the address of the calling function's frame. |
| 120 | This will be used to create a new GDB frame struct, and then |
| 121 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. |
| 122 | |
| 123 | For us, the frame address is its stack pointer value, so we look up |
| 124 | the function prologue to determine the caller's sp value, and return it. */ |
| 125 | |
| 126 | FRAME_ADDR |
| 127 | h8500_frame_chain (thisframe) |
| 128 | FRAME thisframe; |
| 129 | { |
| 130 | |
| 131 | if (!inside_entry_file (thisframe->pc)) |
| 132 | return (read_memory_integer (thisframe->frame, 2) & 0xffff) |
| 133 | | (read_register (SEG_T_REGNUM) << 16); |
| 134 | else |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* Put here the code to store, into a struct frame_saved_regs, |
| 139 | the addresses of the saved registers of frame described by FRAME_INFO. |
| 140 | This includes special registers such as pc and fp saved in special |
| 141 | ways in the stack frame. sp is even more special: |
| 142 | the address we return for it IS the sp for the next frame. |
| 143 | |
| 144 | We cache the result of doing this in the frame_cache_obstack, since |
| 145 | it is fairly expensive. */ |
| 146 | #if 0 |
| 147 | |
| 148 | void |
| 149 | frame_find_saved_regs (fi, fsr) |
| 150 | struct frame_info *fi; |
| 151 | struct frame_saved_regs *fsr; |
| 152 | { |
| 153 | register CORE_ADDR next_addr; |
| 154 | register CORE_ADDR *saved_regs; |
| 155 | register int regnum; |
| 156 | register struct frame_saved_regs *cache_fsr; |
| 157 | extern struct obstack frame_cache_obstack; |
| 158 | CORE_ADDR ip; |
| 159 | struct symtab_and_line sal; |
| 160 | CORE_ADDR limit; |
| 161 | |
| 162 | if (!fi->fsr) |
| 163 | { |
| 164 | cache_fsr = (struct frame_saved_regs *) |
| 165 | obstack_alloc (&frame_cache_obstack, |
| 166 | sizeof (struct frame_saved_regs)); |
| 167 | bzero (cache_fsr, sizeof (struct frame_saved_regs)); |
| 168 | |
| 169 | fi->fsr = cache_fsr; |
| 170 | |
| 171 | /* Find the start and end of the function prologue. If the PC |
| 172 | is in the function prologue, we only consider the part that |
| 173 | has executed already. */ |
| 174 | |
| 175 | ip = get_pc_function_start (fi->pc); |
| 176 | sal = find_pc_line (ip, 0); |
| 177 | limit = (sal.end && sal.end < fi->pc) ? sal.end : fi->pc; |
| 178 | |
| 179 | /* This will fill in fields in *fi as well as in cache_fsr. */ |
| 180 | examine_prologue (ip, limit, fi->frame, cache_fsr, fi); |
| 181 | } |
| 182 | |
| 183 | if (fsr) |
| 184 | *fsr = *fi->fsr; |
| 185 | } |
| 186 | |
| 187 | #endif |
| 188 | |
| 189 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or |
| 190 | is not the address of a valid instruction, the address of the next |
| 191 | instruction beyond ADDR otherwise. *PWORD1 receives the first word |
| 192 | of the instruction.*/ |
| 193 | |
| 194 | CORE_ADDR |
| 195 | NEXT_PROLOGUE_INSN (addr, lim, pword1) |
| 196 | CORE_ADDR addr; |
| 197 | CORE_ADDR lim; |
| 198 | char *pword1; |
| 199 | { |
| 200 | if (addr < lim + 8) |
| 201 | { |
| 202 | read_memory (addr, pword1, 1); |
| 203 | read_memory (addr, pword1 + 1, 1); |
| 204 | return 1; |
| 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* Examine the prologue of a function. `ip' points to the first instruction. |
| 210 | `limit' is the limit of the prologue (e.g. the addr of the first |
| 211 | linenumber, or perhaps the program counter if we're stepping through). |
| 212 | `frame_sp' is the stack pointer value in use in this frame. |
| 213 | `fsr' is a pointer to a frame_saved_regs structure into which we put |
| 214 | info about the registers saved by this frame. |
| 215 | `fi' is a struct frame_info pointer; we fill in various fields in it |
| 216 | to reflect the offsets of the arg pointer and the locals pointer. */ |
| 217 | |
| 218 | #if 0 |
| 219 | static CORE_ADDR |
| 220 | examine_prologue (ip, limit, after_prolog_fp, fsr, fi) |
| 221 | register CORE_ADDR ip; |
| 222 | register CORE_ADDR limit; |
| 223 | FRAME_ADDR after_prolog_fp; |
| 224 | struct frame_saved_regs *fsr; |
| 225 | struct frame_info *fi; |
| 226 | { |
| 227 | register CORE_ADDR next_ip; |
| 228 | int r; |
| 229 | int i; |
| 230 | int have_fp = 0; |
| 231 | |
| 232 | register int src; |
| 233 | register struct pic_prologue_code *pcode; |
| 234 | char insn[2]; |
| 235 | int size, offset; |
| 236 | unsigned int reg_save_depth = 2; /* Number of things pushed onto |
| 237 | stack, starts at 2, 'cause the |
| 238 | PC is already there */ |
| 239 | |
| 240 | unsigned int auto_depth = 0; /* Number of bytes of autos */ |
| 241 | |
| 242 | char in_frame[8]; /* One for each reg */ |
| 243 | |
| 244 | memset (in_frame, 1, 8); |
| 245 | for (r = 0; r < 8; r++) |
| 246 | { |
| 247 | fsr->regs[r] = 0; |
| 248 | } |
| 249 | if (after_prolog_fp == 0) |
| 250 | { |
| 251 | after_prolog_fp = read_register (SP_REGNUM); |
| 252 | } |
| 253 | if (ip == 0 || ip & ~0xffffff) |
| 254 | return 0; |
| 255 | |
| 256 | ok = NEXT_PROLOGUE_INSN (ip, limit, &insn[0]); |
| 257 | |
| 258 | /* Skip over any fp push instructions */ |
| 259 | fsr->regs[6] = after_prolog_fp; |
| 260 | |
| 261 | if (ok && IS_LINK_8 (insn[0])) |
| 262 | { |
| 263 | ip++; |
| 264 | |
| 265 | in_frame[6] = reg_save_depth; |
| 266 | reg_save_depth += 2; |
| 267 | } |
| 268 | |
| 269 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); |
| 270 | |
| 271 | /* Is this a move into the fp */ |
| 272 | if (next_ip && IS_MOV_SP_FP (insn_word)) |
| 273 | { |
| 274 | ip = next_ip; |
| 275 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); |
| 276 | have_fp = 1; |
| 277 | } |
| 278 | |
| 279 | /* Skip over any stack adjustment, happens either with a number of |
| 280 | sub#2,sp or a mov #x,r5 sub r5,sp */ |
| 281 | |
| 282 | if (next_ip && IS_SUB2_SP (insn_word)) |
| 283 | { |
| 284 | while (next_ip && IS_SUB2_SP (insn_word)) |
| 285 | { |
| 286 | auto_depth += 2; |
| 287 | ip = next_ip; |
| 288 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); |
| 289 | } |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | if (next_ip && IS_MOVK_R5 (insn_word)) |
| 294 | { |
| 295 | ip = next_ip; |
| 296 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); |
| 297 | auto_depth += insn_word; |
| 298 | |
| 299 | next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn_word); |
| 300 | auto_depth += insn_word; |
| 301 | |
| 302 | } |
| 303 | } |
| 304 | /* Work out which regs are stored where */ |
| 305 | while (next_ip && IS_PUSH (insn_word)) |
| 306 | { |
| 307 | ip = next_ip; |
| 308 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); |
| 309 | fsr->regs[r] = after_prolog_fp + auto_depth; |
| 310 | auto_depth += 2; |
| 311 | } |
| 312 | |
| 313 | /* The args are always reffed based from the stack pointer */ |
| 314 | fi->args_pointer = after_prolog_fp; |
| 315 | /* Locals are always reffed based from the fp */ |
| 316 | fi->locals_pointer = after_prolog_fp; |
| 317 | /* The PC is at a known place */ |
| 318 | fi->from_pc = read_memory_short (after_prolog_fp + 2); |
| 319 | |
| 320 | /* Rememeber any others too */ |
| 321 | in_frame[PC_REGNUM] = 0; |
| 322 | |
| 323 | if (have_fp) |
| 324 | /* We keep the old FP in the SP spot */ |
| 325 | fsr->regs[SP_REGNUM] = (read_memory_short (fsr->regs[6])); |
| 326 | else |
| 327 | fsr->regs[SP_REGNUM] = after_prolog_fp + auto_depth; |
| 328 | |
| 329 | return (ip); |
| 330 | } |
| 331 | |
| 332 | #endif |
| 333 | |
| 334 | /* Return the saved PC from this frame. */ |
| 335 | |
| 336 | CORE_ADDR |
| 337 | frame_saved_pc (frame) |
| 338 | FRAME frame; |
| 339 | { |
| 340 | return read_memory_integer ((frame)->frame + 2, PTR_SIZE); |
| 341 | } |
| 342 | |
| 343 | CORE_ADDR |
| 344 | frame_locals_address (fi) |
| 345 | struct frame_info *fi; |
| 346 | { |
| 347 | return fi->frame; |
| 348 | } |
| 349 | |
| 350 | /* Return the address of the argument block for the frame |
| 351 | described by FI. Returns 0 if the address is unknown. */ |
| 352 | |
| 353 | CORE_ADDR |
| 354 | frame_args_address (fi) |
| 355 | struct frame_info *fi; |
| 356 | { |
| 357 | return fi->frame; |
| 358 | } |
| 359 | |
| 360 | void |
| 361 | h8300_pop_frame () |
| 362 | { |
| 363 | unsigned regnum; |
| 364 | struct frame_saved_regs fsr; |
| 365 | struct frame_info *fi; |
| 366 | |
| 367 | FRAME frame = get_current_frame (); |
| 368 | |
| 369 | fi = get_frame_info (frame); |
| 370 | get_frame_saved_regs (fi, &fsr); |
| 371 | |
| 372 | for (regnum = 0; regnum < 8; regnum++) |
| 373 | { |
| 374 | if (fsr.regs[regnum]) |
| 375 | { |
| 376 | write_register (regnum, read_memory_short (fsr.regs[regnum])); |
| 377 | } |
| 378 | |
| 379 | flush_cached_frames (); |
| 380 | set_current_frame (create_new_frame (read_register (FP_REGNUM), |
| 381 | read_pc ())); |
| 382 | |
| 383 | } |
| 384 | |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | print_register_hook (regno) |
| 389 | { |
| 390 | if (regno == CCR_REGNUM) |
| 391 | { |
| 392 | /* CCR register */ |
| 393 | |
| 394 | int C, Z, N, V; |
| 395 | unsigned char b[2]; |
| 396 | unsigned char l; |
| 397 | |
| 398 | read_relative_register_raw_bytes (regno, b); |
| 399 | l = b[1]; |
| 400 | printf ("\t"); |
| 401 | printf ("I-%d - ", (l & 0x80) != 0); |
| 402 | N = (l & 0x8) != 0; |
| 403 | Z = (l & 0x4) != 0; |
| 404 | V = (l & 0x2) != 0; |
| 405 | C = (l & 0x1) != 0; |
| 406 | printf ("N-%d ", N); |
| 407 | printf ("Z-%d ", Z); |
| 408 | printf ("V-%d ", V); |
| 409 | printf ("C-%d ", C); |
| 410 | if ((C | Z) == 0) |
| 411 | printf ("u> "); |
| 412 | if ((C | Z) == 1) |
| 413 | printf ("u<= "); |
| 414 | if ((C == 0)) |
| 415 | printf ("u>= "); |
| 416 | if (C == 1) |
| 417 | printf ("u< "); |
| 418 | if (Z == 0) |
| 419 | printf ("!= "); |
| 420 | if (Z == 1) |
| 421 | printf ("== "); |
| 422 | if ((N ^ V) == 0) |
| 423 | printf (">= "); |
| 424 | if ((N ^ V) == 1) |
| 425 | printf ("< "); |
| 426 | if ((Z | (N ^ V)) == 0) |
| 427 | printf ("> "); |
| 428 | if ((Z | (N ^ V)) == 1) |
| 429 | printf ("<= "); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | int |
| 434 | h8500_register_size (regno) |
| 435 | int regno; |
| 436 | { |
| 437 | if (regno <= PC_REGNUM) |
| 438 | return 2; |
| 439 | else |
| 440 | return 1; |
| 441 | } |
| 442 | |
| 443 | struct type * |
| 444 | h8500_register_virtual_type (regno) |
| 445 | int regno; |
| 446 | { |
| 447 | switch (regno) |
| 448 | { |
| 449 | case SEG_C_REGNUM: |
| 450 | case SEG_E_REGNUM: |
| 451 | case SEG_D_REGNUM: |
| 452 | case SEG_T_REGNUM: |
| 453 | return builtin_type_unsigned_char; |
| 454 | case R0_REGNUM: |
| 455 | case R1_REGNUM: |
| 456 | case R2_REGNUM: |
| 457 | case R3_REGNUM: |
| 458 | case R4_REGNUM: |
| 459 | case R5_REGNUM: |
| 460 | case R6_REGNUM: |
| 461 | case R7_REGNUM: |
| 462 | case PC_REGNUM: |
| 463 | case CCR_REGNUM: |
| 464 | return builtin_type_unsigned_short; |
| 465 | default: |
| 466 | abort (); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /* Put here the code to store, into a struct frame_saved_regs, |
| 471 | the addresses of the saved registers of frame described by FRAME_INFO. |
| 472 | This includes special registers such as pc and fp saved in special |
| 473 | ways in the stack frame. sp is even more special: |
| 474 | the address we return for it IS the sp for the next frame. */ |
| 475 | |
| 476 | void |
| 477 | frame_find_saved_regs (frame_info, frame_saved_regs) |
| 478 | struct frame_info *frame_info; |
| 479 | struct frame_saved_regs *frame_saved_regs; |
| 480 | |
| 481 | { |
| 482 | register int regnum; |
| 483 | register int regmask; |
| 484 | register CORE_ADDR next_addr; |
| 485 | register CORE_ADDR pc; |
| 486 | unsigned char thebyte; |
| 487 | |
| 488 | bzero (frame_saved_regs, sizeof *frame_saved_regs); |
| 489 | |
| 490 | if ((frame_info)->pc >= (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4 |
| 491 | && (frame_info)->pc <= (frame_info)->frame) |
| 492 | { |
| 493 | next_addr = (frame_info)->frame; |
| 494 | pc = (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | pc = get_pc_function_start ((frame_info)->pc); |
| 499 | /* Verify we have a link a6 instruction next; |
| 500 | if not we lose. If we win, find the address above the saved |
| 501 | regs using the amount of storage from the link instruction. |
| 502 | */ |
| 503 | |
| 504 | thebyte = read_memory_integer (pc, 1); |
| 505 | if (0x1f == thebyte) |
| 506 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 2), pc += 2; |
| 507 | else if (0x17 == thebyte) |
| 508 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 1), pc += 1; |
| 509 | else |
| 510 | goto lose; |
| 511 | #if 0 |
| 512 | /* FIXME steve */ |
| 513 | /* If have an add:g.waddal #-n, sp next, adjust next_addr. */ |
| 514 | if ((0x0c0177777 & read_memory_integer (pc, 2)) == 0157774) |
| 515 | next_addr += read_memory_integer (pc += 2, 4), pc += 4; |
| 516 | #endif |
| 517 | } |
| 518 | |
| 519 | thebyte = read_memory_integer (pc, 1); |
| 520 | if (thebyte == 0x12) |
| 521 | { |
| 522 | /* Got stm */ |
| 523 | pc++; |
| 524 | regmask = read_memory_integer (pc, 1); |
| 525 | pc++; |
| 526 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) |
| 527 | { |
| 528 | if (regmask & 1) |
| 529 | { |
| 530 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; |
| 531 | } |
| 532 | } |
| 533 | thebyte = read_memory_integer (pc, 1); |
| 534 | } |
| 535 | /* Maybe got a load of pushes */ |
| 536 | while (thebyte == 0xbf) |
| 537 | { |
| 538 | pc++; |
| 539 | regnum = read_memory_integer (pc, 1) & 0x7; |
| 540 | pc++; |
| 541 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; |
| 542 | thebyte = read_memory_integer (pc, 1); |
| 543 | } |
| 544 | |
| 545 | lose:; |
| 546 | |
| 547 | /* Remember the address of the frame pointer */ |
| 548 | (frame_saved_regs)->regs[FP_REGNUM] = (frame_info)->frame; |
| 549 | |
| 550 | /* This is where the old sp is hidden */ |
| 551 | (frame_saved_regs)->regs[SP_REGNUM] = (frame_info)->frame; |
| 552 | |
| 553 | /* And the PC - remember the pushed FP is always two bytes long */ |
| 554 | (frame_saved_regs)->regs[PC_REGNUM] = (frame_info)->frame + 2; |
| 555 | } |
| 556 | |
| 557 | saved_pc_after_call (frame) |
| 558 | { |
| 559 | int x; |
| 560 | int a = read_register (SP_REGNUM); |
| 561 | x = read_memory_integer (a, PTR_SIZE); |
| 562 | return x; |
| 563 | } |
| 564 | |
| 565 | |
| 566 | /* Nonzero if instruction at PC is a return instruction. */ |
| 567 | |
| 568 | about_to_return (pc) |
| 569 | { |
| 570 | int b1 = read_memory_integer (pc, 1); |
| 571 | |
| 572 | switch (b1) |
| 573 | { |
| 574 | case 0x14: /* rtd #8 */ |
| 575 | case 0x1c: /* rtd #16 */ |
| 576 | case 0x19: /* rts */ |
| 577 | case 0x1a: /* rte */ |
| 578 | return 1; |
| 579 | case 0x11: |
| 580 | { |
| 581 | int b2 = read_memory_integer (pc + 1, 1); |
| 582 | switch (b2) |
| 583 | { |
| 584 | case 0x18: /* prts */ |
| 585 | case 0x14: /* prtd #8 */ |
| 586 | case 0x16: /* prtd #16 */ |
| 587 | return 1; |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | |
| 595 | void |
| 596 | h8500_set_pointer_size (newsize) |
| 597 | int newsize; |
| 598 | { |
| 599 | static int oldsize = 0; |
| 600 | |
| 601 | if (oldsize != newsize) |
| 602 | { |
| 603 | printf ("pointer size set to %d bits\n", newsize); |
| 604 | oldsize = newsize; |
| 605 | if (newsize == 32) |
| 606 | { |
| 607 | minimum_mode = 0; |
| 608 | } |
| 609 | else |
| 610 | { |
| 611 | minimum_mode = 1; |
| 612 | } |
| 613 | _initialize_gdbtypes (); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | |
| 618 | struct cmd_list_element *setmemorylist; |
| 619 | |
| 620 | |
| 621 | static void |
| 622 | segmented_command (args, from_tty) |
| 623 | char *args; |
| 624 | int from_tty; |
| 625 | { |
| 626 | h8500_set_pointer_size (32); |
| 627 | } |
| 628 | |
| 629 | static void |
| 630 | unsegmented_command (args, from_tty) |
| 631 | char *args; |
| 632 | int from_tty; |
| 633 | { |
| 634 | h8500_set_pointer_size (16); |
| 635 | } |
| 636 | |
| 637 | static void |
| 638 | set_memory (args, from_tty) |
| 639 | char *args; |
| 640 | int from_tty; |
| 641 | { |
| 642 | printf ("\"set memory\" must be followed by the name of a memory subcommand.\n"); |
| 643 | help_list (setmemorylist, "set memory ", -1, stdout); |
| 644 | } |
| 645 | |
| 646 | /* See if variable name is ppc or pr[0-7] */ |
| 647 | |
| 648 | int |
| 649 | h8500_is_trapped_internalvar (name) |
| 650 | char *name; |
| 651 | { |
| 652 | if (name[0] != 'p') |
| 653 | return 0; |
| 654 | |
| 655 | if (strcmp (name + 1, "pc") == 0) |
| 656 | return 1; |
| 657 | |
| 658 | if (name[1] == 'r' |
| 659 | && name[2] >= '0' |
| 660 | && name[2] <= '7' |
| 661 | && name[3] == '\000') |
| 662 | return 1; |
| 663 | else |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | value |
| 668 | h8500_value_of_trapped_internalvar (var) |
| 669 | struct internalvar *var; |
| 670 | { |
| 671 | LONGEST regval; |
| 672 | unsigned char regbuf[4]; |
| 673 | int page_regnum, regnum; |
| 674 | |
| 675 | regnum = var->name[2] == 'c' ? PC_REGNUM : var->name[2] - '0'; |
| 676 | |
| 677 | switch (var->name[2]) |
| 678 | { |
| 679 | case 'c': |
| 680 | page_regnum = SEG_C_REGNUM; |
| 681 | break; |
| 682 | case '0': |
| 683 | case '1': |
| 684 | case '2': |
| 685 | case '3': |
| 686 | page_regnum = SEG_D_REGNUM; |
| 687 | break; |
| 688 | case '4': |
| 689 | case '5': |
| 690 | page_regnum = SEG_E_REGNUM; |
| 691 | break; |
| 692 | case '6': |
| 693 | case '7': |
| 694 | page_regnum = SEG_T_REGNUM; |
| 695 | break; |
| 696 | } |
| 697 | |
| 698 | get_saved_register (regbuf, NULL, NULL, selected_frame, page_regnum, NULL); |
| 699 | regval = regbuf[0] << 16; |
| 700 | |
| 701 | get_saved_register (regbuf, NULL, NULL, selected_frame, regnum, NULL); |
| 702 | regval |= regbuf[0] << 8 | regbuf[1]; /* XXX host/target byte order */ |
| 703 | |
| 704 | free (var->value); /* Free up old value */ |
| 705 | |
| 706 | var->value = value_from_longest (builtin_type_unsigned_long, regval); |
| 707 | release_value (var->value); /* Unchain new value */ |
| 708 | |
| 709 | VALUE_LVAL (var->value) = lval_internalvar; |
| 710 | VALUE_INTERNALVAR (var->value) = var; |
| 711 | return var->value; |
| 712 | } |
| 713 | |
| 714 | void |
| 715 | h8500_set_trapped_internalvar (var, newval, bitpos, bitsize, offset) |
| 716 | struct internalvar *var; |
| 717 | int offset, bitpos, bitsize; |
| 718 | value newval; |
| 719 | { |
| 720 | char *page_regnum, *regnum; |
| 721 | char expression[100]; |
| 722 | unsigned new_regval; |
| 723 | struct type *type; |
| 724 | enum type_code newval_type_code; |
| 725 | |
| 726 | type = VALUE_TYPE (newval); |
| 727 | newval_type_code = TYPE_CODE (type); |
| 728 | |
| 729 | if ((newval_type_code != TYPE_CODE_INT |
| 730 | && newval_type_code != TYPE_CODE_PTR) |
| 731 | || TYPE_LENGTH (type) != sizeof (new_regval)) |
| 732 | error ("Illegal type (%s) for assignment to $%s\n", |
| 733 | TYPE_NAME (type), var->name); |
| 734 | |
| 735 | new_regval = *(long *) VALUE_CONTENTS_RAW (newval); |
| 736 | |
| 737 | regnum = var->name + 1; |
| 738 | |
| 739 | switch (var->name[2]) |
| 740 | { |
| 741 | case 'c': |
| 742 | page_regnum = "cp"; |
| 743 | break; |
| 744 | case '0': |
| 745 | case '1': |
| 746 | case '2': |
| 747 | case '3': |
| 748 | page_regnum = "dp"; |
| 749 | break; |
| 750 | case '4': |
| 751 | case '5': |
| 752 | page_regnum = "ep"; |
| 753 | break; |
| 754 | case '6': |
| 755 | case '7': |
| 756 | page_regnum = "tp"; |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | sprintf (expression, "$%s=%d", page_regnum, new_regval >> 16); |
| 761 | parse_and_eval (expression); |
| 762 | |
| 763 | sprintf (expression, "$%s=%d", regnum, new_regval & 0xffff); |
| 764 | parse_and_eval (expression); |
| 765 | } |
| 766 | |
| 767 | _initialize_h8500_tdep () |
| 768 | { |
| 769 | add_prefix_cmd ("memory", no_class, set_memory, |
| 770 | "set the memory model", &setmemorylist, "set memory ", 0, |
| 771 | &setlist); |
| 772 | add_cmd ("segmented", class_support, segmented_command, |
| 773 | "Set segmented memory model.", &setmemorylist); |
| 774 | add_cmd ("unsegmented", class_support, unsegmented_command, |
| 775 | "Set unsegmented memory model.", &setmemorylist); |
| 776 | |
| 777 | } |
| 778 | |
| 779 | CORE_ADDR |
| 780 | target_read_sp () |
| 781 | { |
| 782 | return (read_register (SEG_T_REGNUM) << 16) | (read_register (SP_REGNUM)); |
| 783 | } |
| 784 | |
| 785 | void |
| 786 | target_write_sp (v) |
| 787 | CORE_ADDR v; |
| 788 | { |
| 789 | write_register (SEG_T_REGNUM, v >> 16); |
| 790 | write_register (SP_REGNUM, v & 0xffff); |
| 791 | } |
| 792 | |
| 793 | CORE_ADDR |
| 794 | target_read_pc () |
| 795 | { |
| 796 | return (read_register (SEG_C_REGNUM) << 16) | (read_register (PC_REGNUM)); |
| 797 | } |
| 798 | |
| 799 | void |
| 800 | target_write_pc (v) |
| 801 | CORE_ADDR v; |
| 802 | { |
| 803 | write_register (SEG_C_REGNUM, v >> 16); |
| 804 | write_register (PC_REGNUM, v & 0xffff); |
| 805 | } |
| 806 | |
| 807 | CORE_ADDR |
| 808 | target_read_fp () |
| 809 | { |
| 810 | return (read_register (SEG_T_REGNUM) << 16) | (read_register (FP_REGNUM)); |
| 811 | } |
| 812 | |
| 813 | void |
| 814 | target_write_fp (v) |
| 815 | CORE_ADDR v; |
| 816 | { |
| 817 | write_register (SEG_T_REGNUM, v >> 16); |
| 818 | write_register (FP_REGNUM, v & 0xffff); |
| 819 | } |