Commit | Line | Data |
---|---|---|
195e46ea SC |
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" | |
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) | |
37 | ||
85e07872 | 38 | /* Shape of an H8/500 frame : |
195e46ea SC |
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 (); | |
ccf1e898 | 80 | |
85e07872 SC |
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 */ | |
ccf1e898 | 85 | |
195e46ea SC |
86 | CORE_ADDR |
87 | h8500_skip_prologue (start_pc) | |
88 | CORE_ADDR start_pc; | |
89 | ||
90 | { | |
91 | short int w; | |
92 | ||
195e46ea SC |
93 | w = read_memory_integer (start_pc, 1); |
94 | if (w == LINK_8) | |
95 | { | |
ccf1e898 | 96 | start_pc += 2; |
85e07872 | 97 | w = read_memory_integer (start_pc, 1); |
195e46ea SC |
98 | } |
99 | ||
100 | if (w == LINK_16) | |
101 | { | |
ccf1e898 | 102 | start_pc += 3; |
85e07872 | 103 | w = read_memory_integer (start_pc, 2); |
195e46ea SC |
104 | } |
105 | ||
195e46ea | 106 | return start_pc; |
195e46ea SC |
107 | } |
108 | ||
109 | int | |
110 | print_insn (memaddr, stream) | |
111 | CORE_ADDR memaddr; | |
112 | FILE *stream; | |
113 | { | |
195e46ea | 114 | disassemble_info info; |
85e07872 | 115 | GDB_INIT_DISASSEMBLE_INFO (info, stream); |
5d0734a7 | 116 | return print_insn_h8500 (memaddr, &info); |
195e46ea SC |
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 | |
ccf1e898 | 127 | h8500_frame_chain (thisframe) |
195e46ea SC |
128 | FRAME thisframe; |
129 | { | |
195e46ea | 130 | |
ccf1e898 | 131 | if (!inside_entry_file (thisframe->pc)) |
85e07872 SC |
132 | return (read_memory_integer (thisframe->frame, 2) & 0xffff) |
133 | | (read_register (SEG_T_REGNUM) << 16); | |
ccf1e898 SG |
134 | else |
135 | return 0; | |
195e46ea SC |
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 | #if 0 | |
218 | static CORE_ADDR | |
219 | examine_prologue (ip, limit, after_prolog_fp, fsr, fi) | |
220 | register CORE_ADDR ip; | |
221 | register CORE_ADDR limit; | |
222 | FRAME_ADDR after_prolog_fp; | |
223 | struct frame_saved_regs *fsr; | |
224 | struct frame_info *fi; | |
225 | { | |
226 | register CORE_ADDR next_ip; | |
227 | int r; | |
228 | int i; | |
229 | int have_fp = 0; | |
230 | ||
231 | register int src; | |
232 | register struct pic_prologue_code *pcode; | |
233 | char insn[2]; | |
234 | int size, offset; | |
235 | unsigned int reg_save_depth = 2; /* Number of things pushed onto | |
236 | stack, starts at 2, 'cause the | |
237 | PC is already there */ | |
238 | ||
239 | unsigned int auto_depth = 0; /* Number of bytes of autos */ | |
240 | ||
241 | char in_frame[8]; /* One for each reg */ | |
242 | ||
243 | memset (in_frame, 1, 8); | |
244 | for (r = 0; r < 8; r++) | |
245 | { | |
246 | fsr->regs[r] = 0; | |
247 | } | |
248 | if (after_prolog_fp == 0) | |
249 | { | |
250 | after_prolog_fp = read_register (SP_REGNUM); | |
251 | } | |
252 | if (ip == 0 || ip & ~0xffffff) | |
253 | return 0; | |
254 | ||
255 | ok = NEXT_PROLOGUE_INSN (ip, limit, &insn[0]); | |
256 | ||
257 | /* Skip over any fp push instructions */ | |
258 | fsr->regs[6] = after_prolog_fp; | |
259 | ||
260 | if (ok && IS_LINK_8 (insn[0])) | |
261 | { | |
262 | ip++; | |
263 | ||
264 | in_frame[6] = reg_save_depth; | |
265 | reg_save_depth += 2; | |
266 | } | |
267 | ||
268 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); | |
269 | ||
270 | /* Is this a move into the fp */ | |
271 | if (next_ip && IS_MOV_SP_FP (insn_word)) | |
272 | { | |
273 | ip = next_ip; | |
274 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); | |
275 | have_fp = 1; | |
276 | } | |
277 | ||
278 | /* Skip over any stack adjustment, happens either with a number of | |
279 | sub#2,sp or a mov #x,r5 sub r5,sp */ | |
280 | ||
281 | if (next_ip && IS_SUB2_SP (insn_word)) | |
282 | { | |
283 | while (next_ip && IS_SUB2_SP (insn_word)) | |
284 | { | |
285 | auto_depth += 2; | |
286 | ip = next_ip; | |
287 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); | |
288 | } | |
289 | } | |
290 | else | |
291 | { | |
292 | if (next_ip && IS_MOVK_R5 (insn_word)) | |
293 | { | |
294 | ip = next_ip; | |
295 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); | |
296 | auto_depth += insn_word; | |
297 | ||
298 | next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn_word); | |
299 | auto_depth += insn_word; | |
300 | ||
301 | } | |
302 | } | |
303 | /* Work out which regs are stored where */ | |
304 | while (next_ip && IS_PUSH (insn_word)) | |
305 | { | |
306 | ip = next_ip; | |
307 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word); | |
308 | fsr->regs[r] = after_prolog_fp + auto_depth; | |
309 | auto_depth += 2; | |
310 | } | |
311 | ||
312 | /* The args are always reffed based from the stack pointer */ | |
313 | fi->args_pointer = after_prolog_fp; | |
314 | /* Locals are always reffed based from the fp */ | |
315 | fi->locals_pointer = after_prolog_fp; | |
316 | /* The PC is at a known place */ | |
317 | fi->from_pc = read_memory_short (after_prolog_fp + 2); | |
318 | ||
319 | /* Rememeber any others too */ | |
320 | in_frame[PC_REGNUM] = 0; | |
321 | ||
322 | if (have_fp) | |
323 | /* We keep the old FP in the SP spot */ | |
324 | fsr->regs[SP_REGNUM] = (read_memory_short (fsr->regs[6])); | |
325 | else | |
326 | fsr->regs[SP_REGNUM] = after_prolog_fp + auto_depth; | |
327 | ||
328 | return (ip); | |
329 | } | |
85e07872 | 330 | |
195e46ea | 331 | #endif |
195e46ea SC |
332 | |
333 | /* Return the saved PC from this frame. */ | |
334 | ||
335 | CORE_ADDR | |
336 | frame_saved_pc (frame) | |
337 | FRAME frame; | |
338 | { | |
ccf1e898 | 339 | return read_memory_integer ((frame)->frame + 2, PTR_SIZE); |
195e46ea SC |
340 | } |
341 | ||
342 | CORE_ADDR | |
343 | frame_locals_address (fi) | |
344 | struct frame_info *fi; | |
345 | { | |
346 | return fi->frame; | |
347 | } | |
348 | ||
349 | /* Return the address of the argument block for the frame | |
350 | described by FI. Returns 0 if the address is unknown. */ | |
351 | ||
352 | CORE_ADDR | |
353 | frame_args_address (fi) | |
354 | struct frame_info *fi; | |
355 | { | |
ccf1e898 | 356 | return fi->frame; |
195e46ea SC |
357 | } |
358 | ||
359 | void | |
360 | h8300_pop_frame () | |
361 | { | |
362 | unsigned regnum; | |
363 | struct frame_saved_regs fsr; | |
364 | struct frame_info *fi; | |
365 | ||
366 | FRAME frame = get_current_frame (); | |
367 | ||
368 | fi = get_frame_info (frame); | |
369 | get_frame_saved_regs (fi, &fsr); | |
370 | ||
371 | for (regnum = 0; regnum < 8; regnum++) | |
372 | { | |
373 | if (fsr.regs[regnum]) | |
374 | { | |
375 | write_register (regnum, read_memory_short (fsr.regs[regnum])); | |
376 | } | |
377 | ||
378 | flush_cached_frames (); | |
379 | set_current_frame (create_new_frame (read_register (FP_REGNUM), | |
380 | read_pc ())); | |
381 | ||
382 | } | |
383 | ||
384 | } | |
385 | ||
386 | void | |
387 | print_register_hook (regno) | |
388 | { | |
389 | if (regno == CCR_REGNUM) | |
390 | { | |
391 | /* CCR register */ | |
392 | ||
393 | int C, Z, N, V; | |
394 | unsigned char b[2]; | |
395 | unsigned char l; | |
396 | ||
397 | read_relative_register_raw_bytes (regno, b); | |
398 | l = b[1]; | |
399 | printf ("\t"); | |
400 | printf ("I-%d - ", (l & 0x80) != 0); | |
401 | N = (l & 0x8) != 0; | |
402 | Z = (l & 0x4) != 0; | |
403 | V = (l & 0x2) != 0; | |
404 | C = (l & 0x1) != 0; | |
405 | printf ("N-%d ", N); | |
406 | printf ("Z-%d ", Z); | |
407 | printf ("V-%d ", V); | |
408 | printf ("C-%d ", C); | |
409 | if ((C | Z) == 0) | |
410 | printf ("u> "); | |
411 | if ((C | Z) == 1) | |
412 | printf ("u<= "); | |
413 | if ((C == 0)) | |
414 | printf ("u>= "); | |
415 | if (C == 1) | |
416 | printf ("u< "); | |
417 | if (Z == 0) | |
418 | printf ("!= "); | |
419 | if (Z == 1) | |
420 | printf ("== "); | |
421 | if ((N ^ V) == 0) | |
422 | printf (">= "); | |
423 | if ((N ^ V) == 1) | |
424 | printf ("< "); | |
425 | if ((Z | (N ^ V)) == 0) | |
426 | printf ("> "); | |
427 | if ((Z | (N ^ V)) == 1) | |
428 | printf ("<= "); | |
429 | } | |
430 | } | |
431 | ||
ccf1e898 SG |
432 | int |
433 | h8500_register_size (regno) | |
434 | int regno; | |
195e46ea | 435 | { |
ccf1e898 SG |
436 | if (regno <= PC_REGNUM) |
437 | return 2; | |
438 | else | |
439 | return 1; | |
195e46ea SC |
440 | } |
441 | ||
442 | struct type * | |
ccf1e898 SG |
443 | h8500_register_virtual_type (regno) |
444 | int regno; | |
195e46ea | 445 | { |
ccf1e898 | 446 | switch (regno) |
195e46ea | 447 | { |
ccf1e898 SG |
448 | case SEG_C_REGNUM: |
449 | case SEG_E_REGNUM: | |
450 | case SEG_D_REGNUM: | |
451 | case SEG_T_REGNUM: | |
195e46ea | 452 | return builtin_type_unsigned_char; |
ccf1e898 SG |
453 | case R0_REGNUM: |
454 | case R1_REGNUM: | |
455 | case R2_REGNUM: | |
456 | case R3_REGNUM: | |
457 | case R4_REGNUM: | |
458 | case R5_REGNUM: | |
459 | case R6_REGNUM: | |
460 | case R7_REGNUM: | |
461 | case PC_REGNUM: | |
195e46ea SC |
462 | case CCR_REGNUM: |
463 | return builtin_type_unsigned_short; | |
195e46ea | 464 | default: |
85e07872 | 465 | abort (); |
195e46ea SC |
466 | } |
467 | } | |
468 | ||
195e46ea SC |
469 | /* Put here the code to store, into a struct frame_saved_regs, |
470 | the addresses of the saved registers of frame described by FRAME_INFO. | |
471 | This includes special registers such as pc and fp saved in special | |
472 | ways in the stack frame. sp is even more special: | |
473 | the address we return for it IS the sp for the next frame. */ | |
474 | ||
475 | void | |
476 | frame_find_saved_regs (frame_info, frame_saved_regs) | |
477 | struct frame_info *frame_info; | |
478 | struct frame_saved_regs *frame_saved_regs; | |
479 | ||
480 | { | |
481 | register int regnum; | |
482 | register int regmask; | |
483 | register CORE_ADDR next_addr; | |
484 | register CORE_ADDR pc; | |
485 | unsigned char thebyte; | |
486 | ||
487 | bzero (frame_saved_regs, sizeof *frame_saved_regs); | |
488 | ||
489 | if ((frame_info)->pc >= (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4 | |
490 | && (frame_info)->pc <= (frame_info)->frame) | |
491 | { | |
492 | next_addr = (frame_info)->frame; | |
493 | pc = (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; | |
494 | } | |
495 | else | |
496 | { | |
497 | pc = get_pc_function_start ((frame_info)->pc); | |
498 | /* Verify we have a link a6 instruction next; | |
499 | if not we lose. If we win, find the address above the saved | |
500 | regs using the amount of storage from the link instruction. | |
501 | */ | |
502 | ||
85e07872 | 503 | thebyte = read_memory_integer (pc, 1); |
195e46ea SC |
504 | if (0x1f == thebyte) |
505 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 2), pc += 2; | |
506 | else if (0x17 == thebyte) | |
507 | next_addr = (frame_info)->frame + read_memory_integer (pc += 1, 1), pc += 1; | |
508 | else | |
509 | goto lose; | |
510 | #if 0 | |
511 | fixme steve | |
85e07872 SC |
512 | /* If have an add:g.waddal #-n, sp next, adjust next_addr. */ |
513 | if ((0x0c0177777 & read_memory_integer (pc, 2)) == 0157774) | |
514 | next_addr += read_memory_integer (pc += 2, 4), pc += 4; | |
195e46ea SC |
515 | #endif |
516 | } | |
517 | ||
85e07872 SC |
518 | thebyte = read_memory_integer (pc, 1); |
519 | if (thebyte == 0x12) | |
520 | { | |
521 | /* Got stm */ | |
522 | pc++; | |
523 | regmask = read_memory_integer (pc, 1); | |
524 | pc++; | |
525 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) | |
526 | { | |
527 | if (regmask & 1) | |
528 | { | |
529 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; | |
530 | } | |
531 | } | |
532 | thebyte = read_memory_integer (pc, 1); | |
533 | } | |
195e46ea | 534 | /* Maybe got a load of pushes */ |
85e07872 SC |
535 | while (thebyte == 0xbf) |
536 | { | |
537 | pc++; | |
538 | regnum = read_memory_integer (pc, 1) & 0x7; | |
539 | pc++; | |
540 | (frame_saved_regs)->regs[regnum] = (next_addr += 2) - 2; | |
541 | thebyte = read_memory_integer (pc, 1); | |
542 | } | |
543 | ||
544 | lose:; | |
545 | ||
195e46ea SC |
546 | /* Remember the address of the frame pointer */ |
547 | (frame_saved_regs)->regs[FP_REGNUM] = (frame_info)->frame; | |
548 | ||
549 | /* This is where the old sp is hidden */ | |
550 | (frame_saved_regs)->regs[SP_REGNUM] = (frame_info)->frame; | |
551 | ||
552 | /* And the PC - remember the pushed FP is always two bytes long */ | |
553 | (frame_saved_regs)->regs[PC_REGNUM] = (frame_info)->frame + 2; | |
554 | } | |
555 | ||
85e07872 | 556 | saved_pc_after_call (frame) |
195e46ea SC |
557 | { |
558 | int x; | |
85e07872 | 559 | int a = read_register (SP_REGNUM); |
195e46ea SC |
560 | x = read_memory_integer (a, PTR_SIZE); |
561 | return x; | |
562 | } | |
563 | ||
564 | ||
565 | /* Nonzero if instruction at PC is a return instruction. */ | |
566 | ||
85e07872 | 567 | about_to_return (pc) |
195e46ea | 568 | { |
85e07872 | 569 | int b1 = read_memory_integer (pc, 1); |
195e46ea | 570 | |
85e07872 | 571 | switch (b1) |
195e46ea SC |
572 | { |
573 | case 0x14: /* rtd #8 */ | |
574 | case 0x1c: /* rtd #16 */ | |
575 | case 0x19: /* rts */ | |
576 | case 0x1a: /* rte */ | |
577 | return 1; | |
578 | case 0x11: | |
579 | { | |
85e07872 SC |
580 | int b2 = read_memory_integer (pc + 1, 1); |
581 | switch (b2) | |
195e46ea SC |
582 | { |
583 | case 0x18: /* prts */ | |
584 | case 0x14: /* prtd #8 */ | |
585 | case 0x16: /* prtd #16 */ | |
586 | return 1; | |
587 | } | |
588 | } | |
589 | } | |
590 | return 0; | |
591 | } | |
592 | ||
593 | ||
594 | void | |
595 | h8500_set_pointer_size (newsize) | |
596 | int newsize; | |
597 | { | |
598 | static int oldsize = 0; | |
599 | ||
600 | if (oldsize != newsize) | |
601 | { | |
602 | printf ("pointer size set to %d bits\n", newsize); | |
603 | oldsize = newsize; | |
604 | if (newsize == 32) | |
605 | { | |
606 | minimum_mode = 0; | |
607 | } | |
608 | else | |
609 | { | |
610 | minimum_mode = 1; | |
611 | } | |
612 | _initialize_gdbtypes (); | |
613 | } | |
614 | } | |
615 | ||
616 | ||
617 | struct cmd_list_element *setmemorylist; | |
618 | ||
619 | ||
620 | static void | |
621 | segmented_command (args, from_tty) | |
622 | char *args; | |
623 | int from_tty; | |
624 | { | |
625 | h8500_set_pointer_size (32); | |
626 | } | |
627 | ||
628 | static void | |
629 | unsegmented_command (args, from_tty) | |
630 | char *args; | |
631 | int from_tty; | |
632 | { | |
633 | h8500_set_pointer_size (16); | |
634 | } | |
635 | ||
636 | static void | |
637 | set_memory (args, from_tty) | |
638 | char *args; | |
639 | int from_tty; | |
640 | { | |
641 | printf ("\"set memory\" must be followed by the name of a memory subcommand.\n"); | |
642 | help_list (setmemorylist, "set memory ", -1, stdout); | |
643 | } | |
644 | ||
ccf1e898 | 645 | /* See if variable name is ppc or pr[0-7] */ |
195e46ea | 646 | |
ccf1e898 SG |
647 | int |
648 | h8500_is_trapped_internalvar (name) | |
649 | char *name; | |
650 | { | |
651 | if (name[0] != 'p') | |
652 | return 0; | |
653 | ||
85e07872 | 654 | if (strcmp (name + 1, "pc") == 0) |
ccf1e898 SG |
655 | return 1; |
656 | ||
657 | if (name[1] == 'r' | |
658 | && name[2] >= '0' | |
659 | && name[2] <= '7' | |
660 | && name[3] == '\000') | |
661 | return 1; | |
662 | else | |
663 | return 0; | |
664 | } | |
665 | ||
a493d9a6 | 666 | value |
ccf1e898 SG |
667 | h8500_value_of_trapped_internalvar (var) |
668 | struct internalvar *var; | |
669 | { | |
670 | LONGEST regval; | |
671 | unsigned char regbuf[4]; | |
672 | int page_regnum, regnum; | |
673 | ||
674 | regnum = var->name[2] == 'c' ? PC_REGNUM : var->name[2] - '0'; | |
675 | ||
676 | switch (var->name[2]) | |
677 | { | |
678 | case 'c': | |
679 | page_regnum = SEG_C_REGNUM; | |
680 | break; | |
85e07872 SC |
681 | case '0': |
682 | case '1': | |
683 | case '2': | |
684 | case '3': | |
ccf1e898 SG |
685 | page_regnum = SEG_D_REGNUM; |
686 | break; | |
85e07872 SC |
687 | case '4': |
688 | case '5': | |
ccf1e898 SG |
689 | page_regnum = SEG_E_REGNUM; |
690 | break; | |
85e07872 SC |
691 | case '6': |
692 | case '7': | |
ccf1e898 SG |
693 | page_regnum = SEG_T_REGNUM; |
694 | break; | |
695 | } | |
696 | ||
697 | get_saved_register (regbuf, NULL, NULL, selected_frame, page_regnum, NULL); | |
698 | regval = regbuf[0] << 16; | |
699 | ||
700 | get_saved_register (regbuf, NULL, NULL, selected_frame, regnum, NULL); | |
701 | regval |= regbuf[0] << 8 | regbuf[1]; /* XXX host/target byte order */ | |
702 | ||
703 | free (var->value); /* Free up old value */ | |
704 | ||
705 | var->value = value_from_longest (builtin_type_unsigned_long, regval); | |
706 | release_value (var->value); /* Unchain new value */ | |
707 | ||
708 | VALUE_LVAL (var->value) = lval_internalvar; | |
709 | VALUE_INTERNALVAR (var->value) = var; | |
710 | return var->value; | |
711 | } | |
712 | ||
713 | void | |
714 | h8500_set_trapped_internalvar (var, newval, bitpos, bitsize, offset) | |
715 | struct internalvar *var; | |
716 | int offset, bitpos, bitsize; | |
717 | value newval; | |
195e46ea | 718 | { |
ccf1e898 SG |
719 | char *page_regnum, *regnum; |
720 | char expression[100]; | |
721 | unsigned new_regval; | |
722 | struct type *type; | |
723 | enum type_code newval_type_code; | |
724 | ||
725 | type = VALUE_TYPE (newval); | |
726 | newval_type_code = TYPE_CODE (type); | |
727 | ||
728 | if ((newval_type_code != TYPE_CODE_INT | |
729 | && newval_type_code != TYPE_CODE_PTR) | |
85e07872 SC |
730 | || TYPE_LENGTH (type) != sizeof (new_regval)) |
731 | error ("Illegal type (%s) for assignment to $%s\n", | |
732 | TYPE_NAME (type), var->name); | |
195e46ea | 733 | |
85e07872 | 734 | new_regval = *(long *) VALUE_CONTENTS_RAW (newval); |
ccf1e898 SG |
735 | |
736 | regnum = var->name + 1; | |
737 | ||
738 | switch (var->name[2]) | |
739 | { | |
740 | case 'c': | |
741 | page_regnum = "cp"; | |
742 | break; | |
85e07872 SC |
743 | case '0': |
744 | case '1': | |
745 | case '2': | |
746 | case '3': | |
ccf1e898 SG |
747 | page_regnum = "dp"; |
748 | break; | |
85e07872 SC |
749 | case '4': |
750 | case '5': | |
ccf1e898 SG |
751 | page_regnum = "ep"; |
752 | break; | |
85e07872 SC |
753 | case '6': |
754 | case '7': | |
ccf1e898 SG |
755 | page_regnum = "tp"; |
756 | break; | |
757 | } | |
758 | ||
759 | sprintf (expression, "$%s=%d", page_regnum, new_regval >> 16); | |
85e07872 | 760 | parse_and_eval (expression); |
ccf1e898 SG |
761 | |
762 | sprintf (expression, "$%s=%d", regnum, new_regval & 0xffff); | |
85e07872 | 763 | parse_and_eval (expression); |
ccf1e898 SG |
764 | } |
765 | ||
766 | _initialize_h8500_tdep () | |
767 | { | |
195e46ea SC |
768 | add_prefix_cmd ("memory", no_class, set_memory, |
769 | "set the memory model", &setmemorylist, "set memory ", 0, | |
770 | &setlist); | |
771 | add_cmd ("segmented", class_support, segmented_command, | |
772 | "Set segmented memory model.", &setmemorylist); | |
773 | add_cmd ("unsegmented", class_support, unsegmented_command, | |
774 | "Set unsegmented memory model.", &setmemorylist); | |
775 | ||
776 | } | |
85e07872 SC |
777 | |
778 | CORE_ADDR | |
779 | target_read_sp () | |
780 | { | |
781 | return (read_register (SEG_T_REGNUM) << 16) | (read_register (SP_REGNUM)); | |
782 | } | |
783 | ||
784 | void | |
785 | target_write_sp (v) | |
786 | CORE_ADDR v; | |
787 | { | |
788 | write_register (SEG_T_REGNUM, v >> 16); | |
789 | write_register (SP_REGNUM, v & 0xffff); | |
790 | } | |
791 | ||
792 | CORE_ADDR | |
793 | target_read_pc () | |
794 | { | |
795 | return (read_register (SEG_C_REGNUM) << 16) | (read_register (PC_REGNUM)); | |
796 | } | |
797 | ||
798 | void | |
799 | target_write_pc (v) | |
800 | CORE_ADDR v; | |
801 | { | |
802 | write_register (SEG_C_REGNUM, v >> 16); | |
803 | write_register (PC_REGNUM, v & 0xffff); | |
804 | } | |
805 | ||
806 | CORE_ADDR | |
807 | target_read_fp () | |
808 | { | |
809 | return (read_register (SEG_T_REGNUM) << 16) | (read_register (FP_REGNUM)); | |
810 | } | |
811 | ||
812 | void | |
813 | target_write_fp (v) | |
814 | CORE_ADDR v; | |
815 | { | |
816 | write_register (SEG_T_REGNUM, v >> 16); | |
817 | write_register (FP_REGNUM, v & 0xffff); | |
818 | } |