Commit | Line | Data |
---|---|---|
195e46ea | 1 | /* Target-machine dependent code for Hitachi H8/500, for GDB. |
18b46e7c | 2 | Copyright 1993, 1994, 1995 Free Software Foundation, Inc. |
195e46ea SC |
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" | |
ccf1e898 | 31 | #include "value.h" |
195e46ea SC |
32 | #include "dis-asm.h" |
33 | #include "../opcodes/h8500-opc.h" | |
34 | ; | |
195e46ea SC |
35 | |
36 | #define UNSIGNED_SHORT(X) ((X) & 0xffff) | |
edd01519 SC |
37 | int code_size = 2; |
38 | int data_size = 2; | |
195e46ea | 39 | |
85e07872 | 40 | /* Shape of an H8/500 frame : |
195e46ea SC |
41 | |
42 | ||
43 | arg-n | |
44 | .. | |
45 | arg-2 | |
46 | arg-1 | |
47 | return address <2 or 4 bytes> | |
48 | old fp <2 bytes> | |
49 | auto-n | |
50 | .. | |
51 | auto-1 | |
52 | saved registers | |
53 | ||
54 | */ | |
55 | ||
56 | ||
57 | /* an easy to debug H8 stack frame looks like: | |
58 | 0x6df6 push r6 | |
59 | 0x0d76 mov.w r7,r6 | |
60 | 0x6dfn push reg | |
61 | 0x7905 nnnn mov.w #n,r5 or 0x1b87 subs #2,sp | |
62 | 0x1957 sub.w r5,sp | |
63 | ||
64 | */ | |
65 | ||
d1445327 | 66 | #define IS_PUSH(x) (((x) & 0xff00)==0x6d00) |
195e46ea SC |
67 | #define IS_LINK_8(x) ((x) == 0x17) |
68 | #define IS_LINK_16(x) ((x) == 0x1f) | |
d1445327 FF |
69 | #define IS_MOVE_FP(x) ((x) == 0x0d76) |
70 | #define IS_MOV_SP_FP(x) ((x) == 0x0d76) | |
71 | #define IS_SUB2_SP(x) ((x) == 0x1b87) | |
72 | #define IS_MOVK_R5(x) ((x) == 0x7905) | |
73 | #define IS_SUB_R5SP(x) ((x) == 0x1957) | |
195e46ea SC |
74 | |
75 | #define LINK_8 0x17 | |
76 | #define LINK_16 0x1f | |
77 | ||
78 | int minimum_mode = 1; | |
79 | CORE_ADDR examine_prologue (); | |
80 | ||
81 | void frame_find_saved_regs (); | |
ccf1e898 | 82 | |
ccf1e898 | 83 | |
195e46ea SC |
84 | CORE_ADDR |
85 | h8500_skip_prologue (start_pc) | |
86 | CORE_ADDR start_pc; | |
87 | ||
88 | { | |
89 | short int w; | |
90 | ||
08c0d7b8 | 91 | w = read_memory_integer (start_pc, 1); |
195e46ea SC |
92 | if (w == LINK_8) |
93 | { | |
ccf1e898 | 94 | start_pc += 2; |
85e07872 | 95 | w = read_memory_integer (start_pc, 1); |
195e46ea SC |
96 | } |
97 | ||
98 | if (w == LINK_16) | |
99 | { | |
ccf1e898 | 100 | start_pc += 3; |
85e07872 | 101 | w = read_memory_integer (start_pc, 2); |
195e46ea SC |
102 | } |
103 | ||
195e46ea | 104 | return start_pc; |
195e46ea SC |
105 | } |
106 | ||
195e46ea SC |
107 | /* Given a GDB frame, determine the address of the calling function's frame. |
108 | This will be used to create a new GDB frame struct, and then | |
109 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
110 | ||
111 | For us, the frame address is its stack pointer value, so we look up | |
112 | the function prologue to determine the caller's sp value, and return it. */ | |
113 | ||
669caa9c | 114 | CORE_ADDR |
ccf1e898 | 115 | h8500_frame_chain (thisframe) |
669caa9c | 116 | struct frame_info *thisframe; |
195e46ea | 117 | { |
ccf1e898 | 118 | if (!inside_entry_file (thisframe->pc)) |
08c0d7b8 | 119 | return (read_memory_integer (FRAME_FP (thisframe), PTR_SIZE)); |
ccf1e898 SG |
120 | else |
121 | return 0; | |
195e46ea SC |
122 | } |
123 | ||
195e46ea SC |
124 | |
125 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or | |
126 | is not the address of a valid instruction, the address of the next | |
127 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
128 | of the instruction.*/ | |
129 | ||
130 | CORE_ADDR | |
131 | NEXT_PROLOGUE_INSN (addr, lim, pword1) | |
132 | CORE_ADDR addr; | |
133 | CORE_ADDR lim; | |
134 | char *pword1; | |
135 | { | |
136 | if (addr < lim + 8) | |
137 | { | |
138 | read_memory (addr, pword1, 1); | |
139 | read_memory (addr, pword1 + 1, 1); | |
140 | return 1; | |
141 | } | |
142 | return 0; | |
143 | } | |
144 | ||
145 | /* Examine the prologue of a function. `ip' points to the first instruction. | |
146 | `limit' is the limit of the prologue (e.g. the addr of the first | |
147 | linenumber, or perhaps the program counter if we're stepping through). | |
148 | `frame_sp' is the stack pointer value in use in this frame. | |
149 | `fsr' is a pointer to a frame_saved_regs structure into which we put | |
150 | info about the registers saved by this frame. | |
151 | `fi' is a struct frame_info pointer; we fill in various fields in it | |
152 | to reflect the offsets of the arg pointer and the locals pointer. */ | |
d1445327 | 153 | |
195e46ea SC |
154 | |
155 | /* Return the saved PC from this frame. */ | |
156 | ||
157 | CORE_ADDR | |
158 | frame_saved_pc (frame) | |
669caa9c | 159 | struct frame_info *frame; |
195e46ea | 160 | { |
669caa9c | 161 | return read_memory_integer (FRAME_FP (frame) + 2, PTR_SIZE); |
195e46ea SC |
162 | } |
163 | ||
164 | CORE_ADDR | |
165 | frame_locals_address (fi) | |
166 | struct frame_info *fi; | |
167 | { | |
168 | return fi->frame; | |
169 | } | |
170 | ||
171 | /* Return the address of the argument block for the frame | |
172 | described by FI. Returns 0 if the address is unknown. */ | |
173 | ||
174 | CORE_ADDR | |
175 | frame_args_address (fi) | |
176 | struct frame_info *fi; | |
177 | { | |
ccf1e898 | 178 | return fi->frame; |
195e46ea SC |
179 | } |
180 | ||
181 | void | |
182 | h8300_pop_frame () | |
183 | { | |
184 | unsigned regnum; | |
185 | struct frame_saved_regs fsr; | |
669caa9c | 186 | struct frame_info *frame = get_current_frame (); |
195e46ea | 187 | |
669caa9c | 188 | get_frame_saved_regs (frame, &fsr); |
195e46ea SC |
189 | |
190 | for (regnum = 0; regnum < 8; regnum++) | |
191 | { | |
192 | if (fsr.regs[regnum]) | |
195e46ea | 193 | write_register (regnum, read_memory_short (fsr.regs[regnum])); |
195e46ea SC |
194 | |
195 | flush_cached_frames (); | |
195e46ea SC |
196 | } |
197 | ||
198 | } | |
199 | ||
200 | void | |
201 | print_register_hook (regno) | |
202 | { | |
203 | if (regno == CCR_REGNUM) | |
204 | { | |
205 | /* CCR register */ | |
206 | ||
207 | int C, Z, N, V; | |
208 | unsigned char b[2]; | |
209 | unsigned char l; | |
210 | ||
211 | read_relative_register_raw_bytes (regno, b); | |
212 | l = b[1]; | |
199b2450 TL |
213 | printf_unfiltered ("\t"); |
214 | printf_unfiltered ("I-%d - ", (l & 0x80) != 0); | |
195e46ea SC |
215 | N = (l & 0x8) != 0; |
216 | Z = (l & 0x4) != 0; | |
217 | V = (l & 0x2) != 0; | |
218 | C = (l & 0x1) != 0; | |
199b2450 TL |
219 | printf_unfiltered ("N-%d ", N); |
220 | printf_unfiltered ("Z-%d ", Z); | |
221 | printf_unfiltered ("V-%d ", V); | |
222 | printf_unfiltered ("C-%d ", C); | |
195e46ea | 223 | if ((C | Z) == 0) |
199b2450 | 224 | printf_unfiltered ("u> "); |
195e46ea | 225 | if ((C | Z) == 1) |
199b2450 | 226 | printf_unfiltered ("u<= "); |
195e46ea | 227 | if ((C == 0)) |
199b2450 | 228 | printf_unfiltered ("u>= "); |
195e46ea | 229 | if (C == 1) |
199b2450 | 230 | printf_unfiltered ("u< "); |
195e46ea | 231 | if (Z == 0) |
199b2450 | 232 | printf_unfiltered ("!= "); |
195e46ea | 233 | if (Z == 1) |
199b2450 | 234 | printf_unfiltered ("== "); |
195e46ea | 235 | if ((N ^ V) == 0) |
199b2450 | 236 | printf_unfiltered (">= "); |
195e46ea | 237 | if ((N ^ V) == 1) |
199b2450 | 238 | printf_unfiltered ("< "); |
195e46ea | 239 | if ((Z | (N ^ V)) == 0) |
199b2450 | 240 | printf_unfiltered ("> "); |
195e46ea | 241 | if ((Z | (N ^ V)) == 1) |
199b2450 | 242 | printf_unfiltered ("<= "); |
195e46ea SC |
243 | } |
244 | } | |
245 | ||
ccf1e898 SG |
246 | int |
247 | h8500_register_size (regno) | |
248 | int regno; | |
195e46ea | 249 | { |
08c0d7b8 SC |
250 | switch (regno) { |
251 | case SEG_C_REGNUM: | |
252 | case SEG_D_REGNUM: | |
253 | case SEG_E_REGNUM: | |
254 | case SEG_T_REGNUM: | |
ccf1e898 | 255 | return 1; |
08c0d7b8 SC |
256 | case R0_REGNUM: |
257 | case R1_REGNUM: | |
258 | case R2_REGNUM: | |
259 | case R3_REGNUM: | |
260 | case R4_REGNUM: | |
261 | case R5_REGNUM: | |
262 | case R6_REGNUM: | |
263 | case R7_REGNUM: | |
264 | case CCR_REGNUM: | |
265 | return 2; | |
266 | ||
267 | case PR0_REGNUM: | |
268 | case PR1_REGNUM: | |
269 | case PR2_REGNUM: | |
270 | case PR3_REGNUM: | |
271 | case PR4_REGNUM: | |
272 | case PR5_REGNUM: | |
273 | case PR6_REGNUM: | |
274 | case PR7_REGNUM: | |
275 | case PC_REGNUM: | |
276 | return 4; | |
277 | } | |
195e46ea SC |
278 | } |
279 | ||
280 | struct type * | |
ccf1e898 SG |
281 | h8500_register_virtual_type (regno) |
282 | int regno; | |
195e46ea | 283 | { |
ccf1e898 | 284 | switch (regno) |
195e46ea | 285 | { |
ccf1e898 SG |
286 | case SEG_C_REGNUM: |
287 | case SEG_E_REGNUM: | |
288 | case SEG_D_REGNUM: | |
289 | case SEG_T_REGNUM: | |
195e46ea | 290 | return builtin_type_unsigned_char; |
ccf1e898 SG |
291 | case R0_REGNUM: |
292 | case R1_REGNUM: | |
293 | case R2_REGNUM: | |
294 | case R3_REGNUM: | |
295 | case R4_REGNUM: | |
296 | case R5_REGNUM: | |
297 | case R6_REGNUM: | |
298 | case R7_REGNUM: | |
195e46ea SC |
299 | case CCR_REGNUM: |
300 | return builtin_type_unsigned_short; | |
08c0d7b8 SC |
301 | case PR0_REGNUM: |
302 | case PR1_REGNUM: | |
303 | case PR2_REGNUM: | |
304 | case PR3_REGNUM: | |
305 | case PR4_REGNUM: | |
306 | case PR5_REGNUM: | |
307 | case PR6_REGNUM: | |
308 | case PR7_REGNUM: | |
309 | case PC_REGNUM: | |
310 | return builtin_type_unsigned_long; | |
195e46ea | 311 | default: |
85e07872 | 312 | abort (); |
195e46ea SC |
313 | } |
314 | } | |
315 | ||
195e46ea SC |
316 | /* Put here the code to store, into a struct frame_saved_regs, |
317 | the addresses of the saved registers of frame described by FRAME_INFO. | |
318 | This includes special registers such as pc and fp saved in special | |
319 | ways in the stack frame. sp is even more special: | |
320 | the address we return for it IS the sp for the next frame. */ | |
321 | ||
322 | void | |
323 | frame_find_saved_regs (frame_info, frame_saved_regs) | |
324 | struct frame_info *frame_info; | |
325 | struct frame_saved_regs *frame_saved_regs; | |
326 | ||
327 | { | |
328 | register int regnum; | |
329 | register int regmask; | |
330 | register CORE_ADDR next_addr; | |
331 | register CORE_ADDR pc; | |
332 | unsigned char thebyte; | |
333 | ||
4ed97c9a | 334 | memset (frame_saved_regs, '\0', sizeof *frame_saved_regs); |
195e46ea SC |
335 | |
336 | if ((frame_info)->pc >= (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4 | |
337 | && (frame_info)->pc <= (frame_info)->frame) | |
338 | { | |
339 | next_addr = (frame_info)->frame; | |
340 | pc = (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; | |
341 | } | |
342 | else | |
343 | { | |
344 | pc = get_pc_function_start ((frame_info)->pc); | |
345 | /* Verify we have a link a6 instruction next; | |
346 | if not we lose. If we win, find the address above the saved | |
347 | regs using the amount of storage from the link instruction. | |
348 | */ | |
349 | ||
85e07872 | 350 | thebyte = read_memory_integer (pc, 1); |
195e46ea SC |
351 | if (0x1f == thebyte) |
352 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 2), pc += 2; | |
353 | else if (0x17 == thebyte) | |
354 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 1), pc += 1; | |
355 | else | |
356 | goto lose; | |
357 | #if 0 | |
d1445327 | 358 | /* FIXME steve */ |
85e07872 SC |
359 | /* If have an add:g.waddal #-n, sp next, adjust next_addr. */ |
360 | if ((0x0c0177777 & read_memory_integer (pc, 2)) == 0157774) | |
361 | next_addr += read_memory_integer (pc += 2, 4), pc += 4; | |
195e46ea SC |
362 | #endif |
363 | } | |
364 | ||
85e07872 SC |
365 | thebyte = read_memory_integer (pc, 1); |
366 | if (thebyte == 0x12) | |
367 | { | |
368 | /* Got stm */ | |
369 | pc++; | |
370 | regmask = read_memory_integer (pc, 1); | |
371 | pc++; | |
372 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) | |
373 | { | |
374 | if (regmask & 1) | |
375 | { | |
376 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; | |
377 | } | |
378 | } | |
379 | thebyte = read_memory_integer (pc, 1); | |
380 | } | |
195e46ea | 381 | /* Maybe got a load of pushes */ |
85e07872 SC |
382 | while (thebyte == 0xbf) |
383 | { | |
384 | pc++; | |
385 | regnum = read_memory_integer (pc, 1) & 0x7; | |
386 | pc++; | |
387 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; | |
388 | thebyte = read_memory_integer (pc, 1); | |
389 | } | |
390 | ||
391 | lose:; | |
392 | ||
195e46ea SC |
393 | /* Remember the address of the frame pointer */ |
394 | (frame_saved_regs)->regs[FP_REGNUM] = (frame_info)->frame; | |
395 | ||
396 | /* This is where the old sp is hidden */ | |
397 | (frame_saved_regs)->regs[SP_REGNUM] = (frame_info)->frame; | |
398 | ||
399 | /* And the PC - remember the pushed FP is always two bytes long */ | |
400 | (frame_saved_regs)->regs[PC_REGNUM] = (frame_info)->frame + 2; | |
401 | } | |
402 | ||
85e07872 | 403 | saved_pc_after_call (frame) |
195e46ea SC |
404 | { |
405 | int x; | |
85e07872 | 406 | int a = read_register (SP_REGNUM); |
edd01519 SC |
407 | x = read_memory_integer (a, code_size); |
408 | if (code_size == 2) | |
409 | { | |
410 | /* Stick current code segement onto top */ | |
411 | x &= 0xffff; | |
412 | x |= read_register (SEG_C_REGNUM) << 16; | |
413 | } | |
414 | x &= 0xffffff; | |
195e46ea SC |
415 | return x; |
416 | } | |
417 | ||
418 | ||
419 | /* Nonzero if instruction at PC is a return instruction. */ | |
420 | ||
85e07872 | 421 | about_to_return (pc) |
195e46ea | 422 | { |
85e07872 | 423 | int b1 = read_memory_integer (pc, 1); |
195e46ea | 424 | |
85e07872 | 425 | switch (b1) |
195e46ea SC |
426 | { |
427 | case 0x14: /* rtd #8 */ | |
428 | case 0x1c: /* rtd #16 */ | |
429 | case 0x19: /* rts */ | |
430 | case 0x1a: /* rte */ | |
431 | return 1; | |
432 | case 0x11: | |
433 | { | |
85e07872 SC |
434 | int b2 = read_memory_integer (pc + 1, 1); |
435 | switch (b2) | |
195e46ea SC |
436 | { |
437 | case 0x18: /* prts */ | |
438 | case 0x14: /* prtd #8 */ | |
439 | case 0x16: /* prtd #16 */ | |
440 | return 1; | |
441 | } | |
442 | } | |
443 | } | |
444 | return 0; | |
445 | } | |
446 | ||
447 | ||
448 | void | |
449 | h8500_set_pointer_size (newsize) | |
450 | int newsize; | |
451 | { | |
452 | static int oldsize = 0; | |
453 | ||
454 | if (oldsize != newsize) | |
455 | { | |
199b2450 | 456 | printf_unfiltered ("pointer size set to %d bits\n", newsize); |
195e46ea SC |
457 | oldsize = newsize; |
458 | if (newsize == 32) | |
459 | { | |
460 | minimum_mode = 0; | |
461 | } | |
462 | else | |
463 | { | |
464 | minimum_mode = 1; | |
465 | } | |
466 | _initialize_gdbtypes (); | |
467 | } | |
468 | } | |
469 | ||
470 | ||
471 | struct cmd_list_element *setmemorylist; | |
472 | ||
473 | ||
edd01519 | 474 | #define C(name,a,b,c) name () { h8500_set_pointer_size(a); code_size = b; data_size = c; } |
195e46ea | 475 | |
63eef03a | 476 | C(big_command, 32,4,4); |
edd01519 SC |
477 | C(medium_command, 32, 4,2); |
478 | C(compact_command, 32,2,4); | |
479 | C(small_command, 16,2,2); | |
195e46ea SC |
480 | |
481 | static void | |
482 | set_memory (args, from_tty) | |
483 | char *args; | |
484 | int from_tty; | |
485 | { | |
199b2450 TL |
486 | printf_unfiltered ("\"set memory\" must be followed by the name of a memory subcommand.\n"); |
487 | help_list (setmemorylist, "set memory ", -1, gdb_stdout); | |
195e46ea SC |
488 | } |
489 | ||
ccf1e898 | 490 | /* See if variable name is ppc or pr[0-7] */ |
195e46ea | 491 | |
ccf1e898 SG |
492 | int |
493 | h8500_is_trapped_internalvar (name) | |
494 | char *name; | |
495 | { | |
496 | if (name[0] != 'p') | |
497 | return 0; | |
498 | ||
85e07872 | 499 | if (strcmp (name + 1, "pc") == 0) |
ccf1e898 SG |
500 | return 1; |
501 | ||
502 | if (name[1] == 'r' | |
503 | && name[2] >= '0' | |
504 | && name[2] <= '7' | |
505 | && name[3] == '\000') | |
506 | return 1; | |
507 | else | |
508 | return 0; | |
509 | } | |
510 | ||
63eef03a | 511 | value_ptr |
ccf1e898 SG |
512 | h8500_value_of_trapped_internalvar (var) |
513 | struct internalvar *var; | |
514 | { | |
515 | LONGEST regval; | |
516 | unsigned char regbuf[4]; | |
517 | int page_regnum, regnum; | |
518 | ||
519 | regnum = var->name[2] == 'c' ? PC_REGNUM : var->name[2] - '0'; | |
520 | ||
521 | switch (var->name[2]) | |
522 | { | |
523 | case 'c': | |
524 | page_regnum = SEG_C_REGNUM; | |
525 | break; | |
85e07872 SC |
526 | case '0': |
527 | case '1': | |
528 | case '2': | |
529 | case '3': | |
ccf1e898 SG |
530 | page_regnum = SEG_D_REGNUM; |
531 | break; | |
85e07872 SC |
532 | case '4': |
533 | case '5': | |
ccf1e898 SG |
534 | page_regnum = SEG_E_REGNUM; |
535 | break; | |
85e07872 SC |
536 | case '6': |
537 | case '7': | |
ccf1e898 SG |
538 | page_regnum = SEG_T_REGNUM; |
539 | break; | |
540 | } | |
541 | ||
542 | get_saved_register (regbuf, NULL, NULL, selected_frame, page_regnum, NULL); | |
543 | regval = regbuf[0] << 16; | |
544 | ||
545 | get_saved_register (regbuf, NULL, NULL, selected_frame, regnum, NULL); | |
546 | regval |= regbuf[0] << 8 | regbuf[1]; /* XXX host/target byte order */ | |
547 | ||
548 | free (var->value); /* Free up old value */ | |
549 | ||
550 | var->value = value_from_longest (builtin_type_unsigned_long, regval); | |
551 | release_value (var->value); /* Unchain new value */ | |
552 | ||
553 | VALUE_LVAL (var->value) = lval_internalvar; | |
554 | VALUE_INTERNALVAR (var->value) = var; | |
555 | return var->value; | |
556 | } | |
557 | ||
558 | void | |
559 | h8500_set_trapped_internalvar (var, newval, bitpos, bitsize, offset) | |
560 | struct internalvar *var; | |
561 | int offset, bitpos, bitsize; | |
63eef03a | 562 | value_ptr newval; |
195e46ea | 563 | { |
ccf1e898 SG |
564 | char *page_regnum, *regnum; |
565 | char expression[100]; | |
566 | unsigned new_regval; | |
567 | struct type *type; | |
568 | enum type_code newval_type_code; | |
569 | ||
570 | type = VALUE_TYPE (newval); | |
571 | newval_type_code = TYPE_CODE (type); | |
572 | ||
573 | if ((newval_type_code != TYPE_CODE_INT | |
574 | && newval_type_code != TYPE_CODE_PTR) | |
85e07872 SC |
575 | || TYPE_LENGTH (type) != sizeof (new_regval)) |
576 | error ("Illegal type (%s) for assignment to $%s\n", | |
577 | TYPE_NAME (type), var->name); | |
195e46ea | 578 | |
85e07872 | 579 | new_regval = *(long *) VALUE_CONTENTS_RAW (newval); |
ccf1e898 SG |
580 | |
581 | regnum = var->name + 1; | |
582 | ||
583 | switch (var->name[2]) | |
584 | { | |
585 | case 'c': | |
586 | page_regnum = "cp"; | |
587 | break; | |
85e07872 SC |
588 | case '0': |
589 | case '1': | |
590 | case '2': | |
591 | case '3': | |
ccf1e898 SG |
592 | page_regnum = "dp"; |
593 | break; | |
85e07872 SC |
594 | case '4': |
595 | case '5': | |
ccf1e898 SG |
596 | page_regnum = "ep"; |
597 | break; | |
85e07872 SC |
598 | case '6': |
599 | case '7': | |
ccf1e898 SG |
600 | page_regnum = "tp"; |
601 | break; | |
602 | } | |
603 | ||
604 | sprintf (expression, "$%s=%d", page_regnum, new_regval >> 16); | |
85e07872 | 605 | parse_and_eval (expression); |
ccf1e898 SG |
606 | |
607 | sprintf (expression, "$%s=%d", regnum, new_regval & 0xffff); | |
85e07872 | 608 | parse_and_eval (expression); |
ccf1e898 SG |
609 | } |
610 | ||
976bb0be | 611 | void |
ccf1e898 SG |
612 | _initialize_h8500_tdep () |
613 | { | |
195e46ea SC |
614 | add_prefix_cmd ("memory", no_class, set_memory, |
615 | "set the memory model", &setmemorylist, "set memory ", 0, | |
616 | &setlist); | |
edd01519 SC |
617 | |
618 | add_cmd ("small", class_support, small_command, | |
619 | "Set small memory model. (16 bit code, 16 bit data)", &setmemorylist); | |
620 | ||
63eef03a SC |
621 | add_cmd ("big", class_support, big_command, |
622 | "Set big memory model. (32 bit code, 32 bit data)", &setmemorylist); | |
edd01519 SC |
623 | |
624 | add_cmd ("medium", class_support, medium_command, | |
625 | "Set medium memory model. (32 bit code, 16 bit data)", &setmemorylist); | |
626 | ||
627 | add_cmd ("compact", class_support, compact_command, | |
628 | "Set compact memory model. (16 bit code, 32 bit data)", &setmemorylist); | |
195e46ea SC |
629 | |
630 | } | |
85e07872 SC |
631 | |
632 | CORE_ADDR | |
f4eb9968 | 633 | h8500_read_sp () |
85e07872 | 634 | { |
08c0d7b8 | 635 | return read_register (PR7_REGNUM); |
85e07872 SC |
636 | } |
637 | ||
638 | void | |
f4eb9968 | 639 | h8500_write_sp (v) |
85e07872 SC |
640 | CORE_ADDR v; |
641 | { | |
08c0d7b8 | 642 | write_register (PR7_REGNUM, v); |
85e07872 SC |
643 | } |
644 | ||
645 | CORE_ADDR | |
f4eb9968 SS |
646 | h8500_read_pc (pid) |
647 | int pid; | |
85e07872 | 648 | { |
08c0d7b8 | 649 | return read_register (PC_REGNUM); |
85e07872 SC |
650 | } |
651 | ||
652 | void | |
f4eb9968 | 653 | h8500_write_pc (v, pid) |
85e07872 | 654 | CORE_ADDR v; |
f4eb9968 | 655 | int pid; |
85e07872 | 656 | { |
08c0d7b8 | 657 | write_register (PC_REGNUM, v); |
85e07872 SC |
658 | } |
659 | ||
660 | CORE_ADDR | |
f4eb9968 | 661 | h8500_read_fp () |
85e07872 | 662 | { |
08c0d7b8 | 663 | return read_register (PR6_REGNUM); |
85e07872 SC |
664 | } |
665 | ||
666 | void | |
f4eb9968 | 667 | h8500_write_fp (v) |
85e07872 SC |
668 | CORE_ADDR v; |
669 | { | |
08c0d7b8 | 670 | write_register (PR6_REGNUM, v); |
85e07872 | 671 | } |
1468bec9 | 672 | |
18b46e7c SS |
673 | void |
674 | _initialize_h8500_tdep () | |
675 | { | |
676 | tm_print_insn = gdb_print_insn_sh; | |
677 | } |