Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-machine dependent code for Hitachi H8/300, for GDB. |
cda5a58a AC |
2 | |
3 | Copyright 1988, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, | |
1e698235 | 4 | 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | /* | |
c5aa993b JM |
24 | Contributed by Steve Chamberlain |
25 | sac@cygnus.com | |
c906108c SS |
26 | */ |
27 | ||
28 | #include "defs.h" | |
c906108c | 29 | #include "value.h" |
928e48af CV |
30 | #include "inferior.h" |
31 | #include "symfile.h" | |
32 | #include "arch-utils.h" | |
4e052eda | 33 | #include "regcache.h" |
928e48af CV |
34 | #include "gdbcore.h" |
35 | #include "objfiles.h" | |
36 | #include "gdbcmd.h" | |
4904ba5b | 37 | #include "gdb_assert.h" |
a89aa300 | 38 | #include "dis-asm.h" |
c906108c | 39 | |
928e48af CV |
40 | /* Extra info which is saved in each frame_info. */ |
41 | struct frame_extra_info | |
42 | { | |
43 | CORE_ADDR from_pc; | |
928e48af | 44 | }; |
c906108c | 45 | |
928e48af CV |
46 | enum |
47 | { | |
48 | h8300_reg_size = 2, | |
49 | h8300h_reg_size = 4, | |
50 | h8300_max_reg_size = 4, | |
51 | }; | |
52 | #define BINWORD (h8300hmode ? h8300h_reg_size : h8300_reg_size) | |
53 | ||
54 | enum gdb_regnum | |
55 | { | |
56 | E_R0_REGNUM, E_ER0_REGNUM = E_R0_REGNUM, E_ARG0_REGNUM = E_R0_REGNUM, | |
0261a0d0 CV |
57 | E_RET0_REGNUM = E_R0_REGNUM, |
58 | E_R1_REGNUM, E_ER1_REGNUM = E_R1_REGNUM, E_RET1_REGNUM = E_R1_REGNUM, | |
928e48af CV |
59 | E_R2_REGNUM, E_ER2_REGNUM = E_R2_REGNUM, E_ARGLAST_REGNUM = E_R2_REGNUM, |
60 | E_R3_REGNUM, E_ER3_REGNUM = E_R3_REGNUM, | |
61 | E_R4_REGNUM, E_ER4_REGNUM = E_R4_REGNUM, | |
62 | E_R5_REGNUM, E_ER5_REGNUM = E_R5_REGNUM, | |
63 | E_R6_REGNUM, E_ER6_REGNUM = E_R6_REGNUM, E_FP_REGNUM = E_R6_REGNUM, | |
64 | E_SP_REGNUM, | |
65 | E_CCR_REGNUM, | |
66 | E_PC_REGNUM, | |
67 | E_CYCLES_REGNUM, | |
68 | E_TICK_REGNUM, E_EXR_REGNUM = E_TICK_REGNUM, | |
69 | E_INST_REGNUM, E_TICKS_REGNUM = E_INST_REGNUM, | |
084edea5 CV |
70 | E_INSTS_REGNUM, |
71 | E_MACH_REGNUM, | |
72 | E_MACL_REGNUM, | |
73 | E_SBR_REGNUM, | |
74 | E_VBR_REGNUM | |
928e48af | 75 | }; |
c906108c | 76 | |
4bb1dc5e CV |
77 | #define E_PSEUDO_CCR_REGNUM (NUM_REGS) |
78 | #define E_PSEUDO_EXR_REGNUM (NUM_REGS+1) | |
79 | ||
c906108c SS |
80 | #define UNSIGNED_SHORT(X) ((X) & 0xffff) |
81 | ||
82 | #define IS_PUSH(x) ((x & 0xfff0)==0x6df0) | |
83 | #define IS_PUSH_FP(x) (x == 0x6df6) | |
84 | #define IS_MOVE_FP(x) (x == 0x0d76 || x == 0x0ff6) | |
85 | #define IS_MOV_SP_FP(x) (x == 0x0d76 || x == 0x0ff6) | |
86 | #define IS_SUB2_SP(x) (x==0x1b87) | |
87 | #define IS_SUB4_SP(x) (x==0x1b97) | |
88 | #define IS_SUBL_SP(x) (x==0x7a37) | |
89 | #define IS_MOVK_R5(x) (x==0x7905) | |
90 | #define IS_SUB_R5SP(x) (x==0x1957) | |
91 | ||
928e48af CV |
92 | /* If the instruction at PC is an argument register spill, return its |
93 | length. Otherwise, return zero. | |
c906108c | 94 | |
928e48af CV |
95 | An argument register spill is an instruction that moves an argument |
96 | from the register in which it was passed to the stack slot in which | |
97 | it really lives. It is a byte, word, or longword move from an | |
4bb1dc5e CV |
98 | argument register to a negative offset from the frame pointer. |
99 | ||
100 | CV, 2003-06-16: Or, in optimized code or when the `register' qualifier | |
101 | is used, it could be a byte, word or long move to registers r3-r5. */ | |
c906108c | 102 | |
928e48af CV |
103 | static int |
104 | h8300_is_argument_spill (CORE_ADDR pc) | |
105 | { | |
106 | int w = read_memory_unsigned_integer (pc, 2); | |
107 | ||
4bb1dc5e CV |
108 | if (((w & 0xff88) == 0x0c88 /* mov.b Rsl, Rdl */ |
109 | || (w & 0xff88) == 0x0d00 /* mov.w Rs, Rd */ | |
110 | || (w & 0xff88) == 0x0f80) /* mov.l Rs, Rd */ | |
111 | && (w & 0x70) <= 0x20 /* Rs is R0, R1 or R2 */ | |
112 | && (w & 0x7) >= 0x3 && (w & 0x7) <= 0x5)/* Rd is R3, R4 or R5 */ | |
113 | return 2; | |
114 | ||
928e48af CV |
115 | if ((w & 0xfff0) == 0x6ee0 /* mov.b Rs,@(d:16,er6) */ |
116 | && 8 <= (w & 0xf) && (w & 0xf) <= 10) /* Rs is R0L, R1L, or R2L */ | |
117 | { | |
118 | int w2 = read_memory_integer (pc + 2, 2); | |
119 | ||
120 | /* ... and d:16 is negative. */ | |
121 | if (w2 < 0) | |
122 | return 4; | |
123 | } | |
124 | else if (w == 0x7860) | |
125 | { | |
126 | int w2 = read_memory_integer (pc + 2, 2); | |
c906108c | 127 | |
928e48af CV |
128 | if ((w2 & 0xfff0) == 0x6aa0) /* mov.b Rs, @(d:24,er6) */ |
129 | { | |
130 | LONGEST disp = read_memory_integer (pc + 4, 4); | |
c906108c | 131 | |
928e48af CV |
132 | /* ... and d:24 is negative. */ |
133 | if (disp < 0 && disp > 0xffffff) | |
134 | return 8; | |
135 | } | |
136 | } | |
137 | else if ((w & 0xfff0) == 0x6fe0 /* mov.w Rs,@(d:16,er6) */ | |
138 | && (w & 0xf) <= 2) /* Rs is R0, R1, or R2 */ | |
139 | { | |
140 | int w2 = read_memory_integer (pc + 2, 2); | |
c906108c | 141 | |
928e48af CV |
142 | /* ... and d:16 is negative. */ |
143 | if (w2 < 0) | |
144 | return 4; | |
145 | } | |
146 | else if (w == 0x78e0) | |
147 | { | |
148 | int w2 = read_memory_integer (pc + 2, 2); | |
c906108c | 149 | |
928e48af CV |
150 | if ((w2 & 0xfff0) == 0x6ba0) /* mov.b Rs, @(d:24,er6) */ |
151 | { | |
152 | LONGEST disp = read_memory_integer (pc + 4, 4); | |
153 | ||
154 | /* ... and d:24 is negative. */ | |
155 | if (disp < 0 && disp > 0xffffff) | |
156 | return 8; | |
157 | } | |
158 | } | |
159 | else if (w == 0x0100) | |
160 | { | |
161 | int w2 = read_memory_integer (pc + 2, 2); | |
162 | ||
163 | if ((w2 & 0xfff0) == 0x6fe0 /* mov.l Rs,@(d:16,er6) */ | |
164 | && (w2 & 0xf) <= 2) /* Rs is ER0, ER1, or ER2 */ | |
165 | { | |
166 | int w3 = read_memory_integer (pc + 4, 2); | |
167 | ||
168 | /* ... and d:16 is negative. */ | |
169 | if (w3 < 0) | |
170 | return 6; | |
171 | } | |
172 | else if (w2 == 0x78e0) | |
173 | { | |
174 | int w3 = read_memory_integer (pc + 4, 2); | |
175 | ||
176 | if ((w3 & 0xfff0) == 0x6ba0) /* mov.l Rs, @(d:24,er6) */ | |
177 | { | |
178 | LONGEST disp = read_memory_integer (pc + 6, 4); | |
179 | ||
180 | /* ... and d:24 is negative. */ | |
181 | if (disp < 0 && disp > 0xffffff) | |
182 | return 10; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
187 | return 0; | |
188 | } | |
189 | ||
190 | static CORE_ADDR | |
fba45db2 | 191 | h8300_skip_prologue (CORE_ADDR start_pc) |
c906108c SS |
192 | { |
193 | short int w; | |
194 | int adjust = 0; | |
195 | ||
196 | /* Skip past all push and stm insns. */ | |
197 | while (1) | |
198 | { | |
199 | w = read_memory_unsigned_integer (start_pc, 2); | |
200 | /* First look for push insns. */ | |
201 | if (w == 0x0100 || w == 0x0110 || w == 0x0120 || w == 0x0130) | |
202 | { | |
203 | w = read_memory_unsigned_integer (start_pc + 2, 2); | |
204 | adjust = 2; | |
205 | } | |
206 | ||
207 | if (IS_PUSH (w)) | |
208 | { | |
209 | start_pc += 2 + adjust; | |
210 | w = read_memory_unsigned_integer (start_pc, 2); | |
211 | continue; | |
212 | } | |
213 | adjust = 0; | |
214 | break; | |
215 | } | |
216 | ||
217 | /* Skip past a move to FP, either word or long sized */ | |
218 | w = read_memory_unsigned_integer (start_pc, 2); | |
219 | if (w == 0x0100) | |
220 | { | |
221 | w = read_memory_unsigned_integer (start_pc + 2, 2); | |
222 | adjust += 2; | |
223 | } | |
224 | ||
225 | if (IS_MOVE_FP (w)) | |
226 | { | |
227 | start_pc += 2 + adjust; | |
228 | w = read_memory_unsigned_integer (start_pc, 2); | |
229 | } | |
230 | ||
231 | /* Check for loading either a word constant into r5; | |
232 | long versions are handled by the SUBL_SP below. */ | |
233 | if (IS_MOVK_R5 (w)) | |
234 | { | |
235 | start_pc += 2; | |
236 | w = read_memory_unsigned_integer (start_pc, 2); | |
237 | } | |
238 | ||
239 | /* Now check for subtracting r5 from sp, word sized only. */ | |
240 | if (IS_SUB_R5SP (w)) | |
241 | { | |
242 | start_pc += 2 + adjust; | |
243 | w = read_memory_unsigned_integer (start_pc, 2); | |
244 | } | |
245 | ||
246 | /* Check for subs #2 and subs #4. */ | |
247 | while (IS_SUB2_SP (w) || IS_SUB4_SP (w)) | |
248 | { | |
249 | start_pc += 2 + adjust; | |
250 | w = read_memory_unsigned_integer (start_pc, 2); | |
251 | } | |
252 | ||
253 | /* Check for a 32bit subtract. */ | |
254 | if (IS_SUBL_SP (w)) | |
255 | start_pc += 6 + adjust; | |
256 | ||
4bb1dc5e CV |
257 | /* Skip past another possible stm insn for registers R3 to R5 (possibly used |
258 | for register qualified arguments. */ | |
259 | w = read_memory_unsigned_integer (start_pc, 2); | |
260 | /* First look for push insns. */ | |
261 | if (w == 0x0110 || w == 0x0120 || w == 0x0130) | |
262 | { | |
263 | w = read_memory_unsigned_integer (start_pc + 2, 2); | |
264 | if (IS_PUSH (w) && (w & 0xf) >= 0x3 && (w & 0xf) <= 0x5) | |
265 | start_pc += 4; | |
266 | } | |
267 | ||
928e48af CV |
268 | /* Check for spilling an argument register to the stack frame. |
269 | This could also be an initializing store from non-prologue code, | |
270 | but I don't think there's any harm in skipping that. */ | |
271 | for (;;) | |
272 | { | |
273 | int spill_size = h8300_is_argument_spill (start_pc); | |
274 | if (spill_size == 0) | |
275 | break; | |
276 | start_pc += spill_size; | |
277 | } | |
278 | ||
c906108c SS |
279 | return start_pc; |
280 | } | |
281 | ||
c906108c SS |
282 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or |
283 | is not the address of a valid instruction, the address of the next | |
284 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
c5aa993b | 285 | of the instruction. */ |
c906108c | 286 | |
928e48af | 287 | static CORE_ADDR |
884a26c8 MS |
288 | h8300_next_prologue_insn (CORE_ADDR addr, |
289 | CORE_ADDR lim, | |
290 | unsigned short* pword1) | |
c906108c SS |
291 | { |
292 | char buf[2]; | |
293 | if (addr < lim + 8) | |
294 | { | |
295 | read_memory (addr, buf, 2); | |
296 | *pword1 = extract_signed_integer (buf, 2); | |
297 | ||
298 | return addr + 2; | |
299 | } | |
300 | return 0; | |
301 | } | |
302 | ||
303 | /* Examine the prologue of a function. `ip' points to the first instruction. | |
304 | `limit' is the limit of the prologue (e.g. the addr of the first | |
305 | linenumber, or perhaps the program counter if we're stepping through). | |
306 | `frame_sp' is the stack pointer value in use in this frame. | |
307 | `fsr' is a pointer to a frame_saved_regs structure into which we put | |
308 | info about the registers saved by this frame. | |
309 | `fi' is a struct frame_info pointer; we fill in various fields in it | |
310 | to reflect the offsets of the arg pointer and the locals pointer. */ | |
311 | ||
928e48af CV |
312 | /* Any function with a frame looks like this |
313 | SECOND ARG | |
314 | FIRST ARG | |
315 | RET PC | |
316 | SAVED R2 | |
317 | SAVED R3 | |
318 | SAVED FP <-FP POINTS HERE | |
319 | LOCALS0 | |
320 | LOCALS1 <-SP POINTS HERE | |
321 | */ | |
322 | ||
c906108c | 323 | static CORE_ADDR |
928e48af CV |
324 | h8300_examine_prologue (register CORE_ADDR ip, register CORE_ADDR limit, |
325 | CORE_ADDR after_prolog_fp, CORE_ADDR *fsr, | |
326 | struct frame_info *fi) | |
c906108c SS |
327 | { |
328 | register CORE_ADDR next_ip; | |
329 | int r; | |
330 | int have_fp = 0; | |
928e48af | 331 | unsigned short insn_word; |
c906108c SS |
332 | /* Number of things pushed onto stack, starts at 2/4, 'cause the |
333 | PC is already there */ | |
928e48af | 334 | unsigned int reg_save_depth = BINWORD; |
c906108c SS |
335 | |
336 | unsigned int auto_depth = 0; /* Number of bytes of autos */ | |
337 | ||
338 | char in_frame[11]; /* One for each reg */ | |
339 | ||
340 | int adjust = 0; | |
341 | ||
342 | memset (in_frame, 1, 11); | |
343 | for (r = 0; r < 8; r++) | |
344 | { | |
928e48af | 345 | fsr[r] = 0; |
c906108c SS |
346 | } |
347 | if (after_prolog_fp == 0) | |
348 | { | |
928e48af | 349 | after_prolog_fp = read_register (E_SP_REGNUM); |
c906108c SS |
350 | } |
351 | ||
352 | /* If the PC isn't valid, quit now. */ | |
353 | if (ip == 0 || ip & (h8300hmode ? ~0xffffff : ~0xffff)) | |
354 | return 0; | |
355 | ||
d1a8e808 | 356 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c | 357 | |
4bb1dc5e | 358 | if (insn_word == 0x0100) /* mov.l */ |
c906108c SS |
359 | { |
360 | insn_word = read_memory_unsigned_integer (ip + 2, 2); | |
361 | adjust = 2; | |
362 | } | |
363 | ||
364 | /* Skip over any fp push instructions */ | |
928e48af | 365 | fsr[E_FP_REGNUM] = after_prolog_fp; |
c906108c SS |
366 | while (next_ip && IS_PUSH_FP (insn_word)) |
367 | { | |
368 | ip = next_ip + adjust; | |
369 | ||
370 | in_frame[insn_word & 0x7] = reg_save_depth; | |
d1a8e808 | 371 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
372 | reg_save_depth += 2 + adjust; |
373 | } | |
374 | ||
375 | /* Is this a move into the fp */ | |
376 | if (next_ip && IS_MOV_SP_FP (insn_word)) | |
377 | { | |
378 | ip = next_ip; | |
d1a8e808 | 379 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
380 | have_fp = 1; |
381 | } | |
382 | ||
383 | /* Skip over any stack adjustment, happens either with a number of | |
384 | sub#2,sp or a mov #x,r5 sub r5,sp */ | |
385 | ||
386 | if (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word))) | |
387 | { | |
388 | while (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word))) | |
389 | { | |
390 | auto_depth += IS_SUB2_SP (insn_word) ? 2 : 4; | |
391 | ip = next_ip; | |
d1a8e808 | 392 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
393 | } |
394 | } | |
395 | else | |
396 | { | |
397 | if (next_ip && IS_MOVK_R5 (insn_word)) | |
398 | { | |
399 | ip = next_ip; | |
d1a8e808 | 400 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
401 | auto_depth += insn_word; |
402 | ||
d1a8e808 | 403 | next_ip = h8300_next_prologue_insn (next_ip, limit, &insn_word); |
c906108c SS |
404 | auto_depth += insn_word; |
405 | } | |
406 | if (next_ip && IS_SUBL_SP (insn_word)) | |
407 | { | |
408 | ip = next_ip; | |
409 | auto_depth += read_memory_unsigned_integer (ip, 4); | |
410 | ip += 4; | |
411 | ||
d1a8e808 | 412 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
413 | } |
414 | } | |
415 | ||
416 | /* Now examine the push insns to determine where everything lives | |
417 | on the stack. */ | |
418 | while (1) | |
419 | { | |
420 | adjust = 0; | |
421 | if (!next_ip) | |
422 | break; | |
423 | ||
424 | if (insn_word == 0x0100) | |
425 | { | |
426 | ip = next_ip; | |
d1a8e808 | 427 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
428 | adjust = 2; |
429 | } | |
430 | ||
431 | if (IS_PUSH (insn_word)) | |
432 | { | |
ddd216ea CV |
433 | auto_depth += 2 + adjust; |
434 | fsr[insn_word & 0x7] = after_prolog_fp - auto_depth; | |
c906108c | 435 | ip = next_ip; |
d1a8e808 | 436 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
437 | continue; |
438 | } | |
439 | ||
440 | /* Now check for push multiple insns. */ | |
441 | if (insn_word == 0x0110 || insn_word == 0x0120 || insn_word == 0x0130) | |
442 | { | |
443 | int count = ((insn_word >> 4) & 0xf) + 1; | |
444 | int start, i; | |
445 | ||
446 | ip = next_ip; | |
d1a8e808 | 447 | next_ip = h8300_next_prologue_insn (ip, limit, &insn_word); |
c906108c SS |
448 | start = insn_word & 0x7; |
449 | ||
6d305052 | 450 | for (i = start; i < start + count; i++) |
c906108c | 451 | { |
c906108c | 452 | auto_depth += 4; |
ddd216ea | 453 | fsr[i] = after_prolog_fp - auto_depth; |
c906108c SS |
454 | } |
455 | } | |
456 | break; | |
457 | } | |
458 | ||
c906108c | 459 | /* The PC is at a known place */ |
da50a4b7 | 460 | get_frame_extra_info (fi)->from_pc = |
7e78f0ca | 461 | read_memory_unsigned_integer (after_prolog_fp + BINWORD, BINWORD); |
c906108c SS |
462 | |
463 | /* Rememeber any others too */ | |
928e48af | 464 | in_frame[E_PC_REGNUM] = 0; |
c5aa993b | 465 | |
c906108c SS |
466 | if (have_fp) |
467 | /* We keep the old FP in the SP spot */ | |
884a26c8 MS |
468 | fsr[E_SP_REGNUM] = read_memory_unsigned_integer (fsr[E_FP_REGNUM], |
469 | BINWORD); | |
c906108c | 470 | else |
928e48af | 471 | fsr[E_SP_REGNUM] = after_prolog_fp + auto_depth; |
c906108c SS |
472 | |
473 | return (ip); | |
474 | } | |
475 | ||
928e48af CV |
476 | static void |
477 | h8300_frame_init_saved_regs (struct frame_info *fi) | |
c906108c | 478 | { |
928e48af CV |
479 | CORE_ADDR func_addr, func_end; |
480 | ||
b2fb4676 | 481 | if (!get_frame_saved_regs (fi)) |
928e48af CV |
482 | { |
483 | frame_saved_regs_zalloc (fi); | |
484 | ||
485 | /* Find the beginning of this function, so we can analyze its | |
486 | prologue. */ | |
884a26c8 MS |
487 | if (find_pc_partial_function (get_frame_pc (fi), NULL, |
488 | &func_addr, &func_end)) | |
928e48af CV |
489 | { |
490 | struct symtab_and_line sal = find_pc_line (func_addr, 0); | |
884a26c8 MS |
491 | CORE_ADDR limit = (sal.end && sal.end < get_frame_pc (fi)) |
492 | ? sal.end : get_frame_pc (fi); | |
928e48af | 493 | /* This will fill in fields in fi. */ |
1e2330ba AC |
494 | h8300_examine_prologue (func_addr, limit, get_frame_base (fi), |
495 | get_frame_saved_regs (fi), fi); | |
928e48af CV |
496 | } |
497 | /* Else we're out of luck (can't debug completely stripped code). | |
498 | FIXME. */ | |
499 | } | |
500 | } | |
501 | ||
a5afb99f AC |
502 | /* Given a GDB frame, determine the address of the calling function's |
503 | frame. This will be used to create a new GDB frame struct, and | |
e9582e71 AC |
504 | then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC |
505 | will be called for the new frame. | |
928e48af CV |
506 | |
507 | For us, the frame address is its stack pointer value, so we look up | |
884a26c8 MS |
508 | the function prologue to determine the caller's sp value, and |
509 | return it. */ | |
928e48af CV |
510 | |
511 | static CORE_ADDR | |
512 | h8300_frame_chain (struct frame_info *thisframe) | |
513 | { | |
1e2330ba AC |
514 | if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (thisframe), |
515 | get_frame_base (thisframe), | |
516 | get_frame_base (thisframe))) | |
928e48af | 517 | { /* initialize the from_pc now */ |
da50a4b7 | 518 | get_frame_extra_info (thisframe)->from_pc = |
1e2330ba AC |
519 | deprecated_read_register_dummy (get_frame_pc (thisframe), |
520 | get_frame_base (thisframe), | |
135c175f | 521 | E_PC_REGNUM); |
1e2330ba | 522 | return get_frame_base (thisframe); |
c906108c | 523 | } |
b2fb4676 | 524 | return get_frame_saved_regs (thisframe)[E_SP_REGNUM]; |
c906108c SS |
525 | } |
526 | ||
527 | /* Return the saved PC from this frame. | |
528 | ||
529 | If the frame has a memory copy of SRP_REGNUM, use that. If not, | |
530 | just use the register SRP_REGNUM itself. */ | |
531 | ||
928e48af | 532 | static CORE_ADDR |
fba45db2 | 533 | h8300_frame_saved_pc (struct frame_info *frame) |
c906108c | 534 | { |
1e2330ba AC |
535 | if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), |
536 | get_frame_base (frame), | |
537 | get_frame_base (frame))) | |
538 | return deprecated_read_register_dummy (get_frame_pc (frame), | |
539 | get_frame_base (frame), | |
135c175f | 540 | E_PC_REGNUM); |
c906108c | 541 | else |
da50a4b7 | 542 | return get_frame_extra_info (frame)->from_pc; |
c906108c SS |
543 | } |
544 | ||
928e48af CV |
545 | static void |
546 | h8300_init_extra_frame_info (int fromleaf, struct frame_info *fi) | |
547 | { | |
da50a4b7 | 548 | if (!get_frame_extra_info (fi)) |
928e48af | 549 | { |
a00a19e9 | 550 | frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info)); |
da50a4b7 | 551 | get_frame_extra_info (fi)->from_pc = 0; |
928e48af | 552 | |
50abf9e5 | 553 | if (!get_frame_pc (fi)) |
928e48af | 554 | { |
11c02a10 AC |
555 | if (get_next_frame (fi)) |
556 | deprecated_update_frame_pc_hack (fi, h8300_frame_saved_pc (get_next_frame (fi))); | |
928e48af CV |
557 | } |
558 | h8300_frame_init_saved_regs (fi); | |
559 | } | |
560 | } | |
561 | ||
928e48af CV |
562 | /* Round N up or down to the nearest multiple of UNIT. |
563 | Evaluate N only once, UNIT several times. | |
564 | UNIT must be a power of two. */ | |
565 | #define round_up(n, unit) (((n) + (unit) - 1) & -(unit)) | |
566 | #define round_down(n, unit) ((n) & -(unit)) | |
567 | ||
63d47a7d | 568 | /* Function: push_dummy_call |
c906108c | 569 | Setup the function arguments for calling a function in the inferior. |
928e48af CV |
570 | In this discussion, a `word' is 16 bits on the H8/300s, and 32 bits |
571 | on the H8/300H. | |
572 | ||
573 | There are actually two ABI's here: -mquickcall (the default) and | |
574 | -mno-quickcall. With -mno-quickcall, all arguments are passed on | |
575 | the stack after the return address, word-aligned. With | |
576 | -mquickcall, GCC tries to use r0 -- r2 to pass registers. Since | |
577 | GCC doesn't indicate in the object file which ABI was used to | |
578 | compile it, GDB only supports the default --- -mquickcall. | |
579 | ||
580 | Here are the rules for -mquickcall, in detail: | |
581 | ||
582 | Each argument, whether scalar or aggregate, is padded to occupy a | |
583 | whole number of words. Arguments smaller than a word are padded at | |
584 | the most significant end; those larger than a word are padded at | |
585 | the least significant end. | |
586 | ||
587 | The initial arguments are passed in r0 -- r2. Earlier arguments go in | |
588 | lower-numbered registers. Multi-word arguments are passed in | |
589 | consecutive registers, with the most significant end in the | |
590 | lower-numbered register. | |
591 | ||
592 | If an argument doesn't fit entirely in the remaining registers, it | |
593 | is passed entirely on the stack. Stack arguments begin just after | |
594 | the return address. Once an argument has overflowed onto the stack | |
595 | this way, all subsequent arguments are passed on the stack. | |
596 | ||
597 | The above rule has odd consequences. For example, on the h8/300s, | |
598 | if a function takes two longs and an int as arguments: | |
599 | - the first long will be passed in r0/r1, | |
600 | - the second long will be passed entirely on the stack, since it | |
601 | doesn't fit in r2, | |
602 | - and the int will be passed on the stack, even though it could fit | |
603 | in r2. | |
604 | ||
605 | A weird exception: if an argument is larger than a word, but not a | |
606 | whole number of words in length (before padding), it is passed on | |
607 | the stack following the rules for stack arguments above, even if | |
608 | there are sufficient registers available to hold it. Stranger | |
609 | still, the argument registers are still `used up' --- even though | |
610 | there's nothing in them. | |
611 | ||
612 | So, for example, on the h8/300s, if a function expects a three-byte | |
613 | structure and an int, the structure will go on the stack, and the | |
614 | int will go in r2, not r0. | |
615 | ||
616 | If the function returns an aggregate type (struct, union, or class) | |
617 | by value, the caller must allocate space to hold the return value, | |
618 | and pass the callee a pointer to this space as an invisible first | |
619 | argument, in R0. | |
620 | ||
621 | For varargs functions, the last fixed argument and all the variable | |
622 | arguments are always passed on the stack. This means that calls to | |
623 | varargs functions don't work properly unless there is a prototype | |
624 | in scope. | |
625 | ||
626 | Basically, this ABI is not good, for the following reasons: | |
627 | - You can't call vararg functions properly unless a prototype is in scope. | |
628 | - Structure passing is inconsistent, to no purpose I can see. | |
629 | - It often wastes argument registers, of which there are only three | |
630 | to begin with. */ | |
c906108c | 631 | |
928e48af | 632 | static CORE_ADDR |
63d47a7d CV |
633 | h8300_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, |
634 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, | |
635 | struct value **args, CORE_ADDR sp, int struct_return, | |
636 | CORE_ADDR struct_addr) | |
c906108c | 637 | { |
63d47a7d | 638 | int stack_alloc = 0, stack_offset = 0; |
928e48af | 639 | int wordsize = BINWORD; |
63d47a7d | 640 | int reg = E_ARG0_REGNUM; |
928e48af CV |
641 | int argument; |
642 | ||
643 | /* First, make sure the stack is properly aligned. */ | |
644 | sp = round_down (sp, wordsize); | |
645 | ||
646 | /* Now make sure there's space on the stack for the arguments. We | |
647 | may over-allocate a little here, but that won't hurt anything. */ | |
928e48af CV |
648 | for (argument = 0; argument < nargs; argument++) |
649 | stack_alloc += round_up (TYPE_LENGTH (VALUE_TYPE (args[argument])), | |
650 | wordsize); | |
651 | sp -= stack_alloc; | |
652 | ||
653 | /* Now load as many arguments as possible into registers, and push | |
63d47a7d CV |
654 | the rest onto the stack. |
655 | If we're returning a structure by value, then we must pass a | |
928e48af CV |
656 | pointer to the buffer for the return value as an invisible first |
657 | argument. */ | |
658 | if (struct_return) | |
63d47a7d | 659 | regcache_cooked_write_unsigned (regcache, reg++, struct_addr); |
928e48af CV |
660 | |
661 | for (argument = 0; argument < nargs; argument++) | |
c906108c | 662 | { |
928e48af CV |
663 | struct type *type = VALUE_TYPE (args[argument]); |
664 | int len = TYPE_LENGTH (type); | |
665 | char *contents = (char *) VALUE_CONTENTS (args[argument]); | |
666 | ||
667 | /* Pad the argument appropriately. */ | |
668 | int padded_len = round_up (len, wordsize); | |
669 | char *padded = alloca (padded_len); | |
670 | ||
671 | memset (padded, 0, padded_len); | |
672 | memcpy (len < wordsize ? padded + padded_len - len : padded, | |
673 | contents, len); | |
674 | ||
675 | /* Could the argument fit in the remaining registers? */ | |
676 | if (padded_len <= (E_ARGLAST_REGNUM - reg + 1) * wordsize) | |
677 | { | |
678 | /* Are we going to pass it on the stack anyway, for no good | |
679 | reason? */ | |
680 | if (len > wordsize && len % wordsize) | |
681 | { | |
682 | /* I feel so unclean. */ | |
683 | write_memory (sp + stack_offset, padded, padded_len); | |
684 | stack_offset += padded_len; | |
685 | ||
686 | /* That's right --- even though we passed the argument | |
687 | on the stack, we consume the registers anyway! Love | |
688 | me, love my dog. */ | |
689 | reg += padded_len / wordsize; | |
690 | } | |
691 | else | |
692 | { | |
693 | /* Heavens to Betsy --- it's really going in registers! | |
694 | It would be nice if we could use write_register_bytes | |
695 | here, but on the h8/300s, there are gaps between | |
696 | the registers in the register file. */ | |
697 | int offset; | |
698 | ||
699 | for (offset = 0; offset < padded_len; offset += wordsize) | |
700 | { | |
884a26c8 MS |
701 | ULONGEST word = extract_unsigned_integer (padded + offset, |
702 | wordsize); | |
63d47a7d | 703 | regcache_cooked_write_unsigned (regcache, reg++, word); |
928e48af CV |
704 | } |
705 | } | |
706 | } | |
c906108c | 707 | else |
928e48af CV |
708 | { |
709 | /* It doesn't fit in registers! Onto the stack it goes. */ | |
710 | write_memory (sp + stack_offset, padded, padded_len); | |
711 | stack_offset += padded_len; | |
712 | ||
713 | /* Once one argument has spilled onto the stack, all | |
714 | subsequent arguments go on the stack. */ | |
715 | reg = E_ARGLAST_REGNUM + 1; | |
716 | } | |
c906108c | 717 | } |
928e48af | 718 | |
63d47a7d CV |
719 | /* Store return address. */ |
720 | sp -= wordsize; | |
721 | write_memory_unsigned_integer (sp, wordsize, bp_addr); | |
c906108c | 722 | |
63d47a7d CV |
723 | /* Update stack pointer. */ |
724 | regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, sp); | |
c906108c | 725 | |
c906108c SS |
726 | return sp; |
727 | } | |
728 | ||
7256e1a5 | 729 | /* Function: h8300_pop_frame |
c906108c SS |
730 | Restore the machine to the state it had before the current frame |
731 | was created. Usually used either by the "RETURN" command, or by | |
732 | call_function_by_hand after the dummy_frame is finished. */ | |
733 | ||
928e48af | 734 | static void |
fba45db2 | 735 | h8300_pop_frame (void) |
c906108c | 736 | { |
928e48af | 737 | unsigned regno; |
c906108c SS |
738 | struct frame_info *frame = get_current_frame (); |
739 | ||
1e2330ba AC |
740 | if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), |
741 | get_frame_base (frame), | |
742 | get_frame_base (frame))) | |
c906108c | 743 | { |
c5aa993b | 744 | generic_pop_dummy_frame (); |
c906108c SS |
745 | } |
746 | else | |
747 | { | |
928e48af | 748 | for (regno = 0; regno < 8; regno++) |
c906108c | 749 | { |
928e48af | 750 | /* Don't forget E_SP_REGNUM is a frame_saved_regs struct is the |
c906108c | 751 | actual value we want, not the address of the value we want. */ |
b2fb4676 | 752 | if (get_frame_saved_regs (frame)[regno] && regno != E_SP_REGNUM) |
928e48af | 753 | write_register (regno, |
884a26c8 MS |
754 | read_memory_integer |
755 | (get_frame_saved_regs (frame)[regno], BINWORD)); | |
b2fb4676 | 756 | else if (get_frame_saved_regs (frame)[regno] && regno == E_SP_REGNUM) |
1e2330ba | 757 | write_register (regno, get_frame_base (frame) + 2 * BINWORD); |
c906108c SS |
758 | } |
759 | ||
928e48af | 760 | /* Don't forget to update the PC too! */ |
da50a4b7 | 761 | write_register (E_PC_REGNUM, get_frame_extra_info (frame)->from_pc); |
c906108c SS |
762 | } |
763 | flush_cached_frames (); | |
764 | } | |
765 | ||
766 | /* Function: extract_return_value | |
767 | Figure out where in REGBUF the called function has left its return value. | |
768 | Copy that into VALBUF. Be sure to account for CPU type. */ | |
769 | ||
928e48af | 770 | static void |
0261a0d0 CV |
771 | h8300_extract_return_value (struct type *type, struct regcache *regcache, |
772 | void *valbuf) | |
c906108c | 773 | { |
928e48af | 774 | int len = TYPE_LENGTH (type); |
708cc1b6 | 775 | ULONGEST c, addr; |
c5aa993b JM |
776 | |
777 | switch (len) | |
778 | { | |
0261a0d0 CV |
779 | case 1: |
780 | case 2: | |
781 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c); | |
782 | store_unsigned_integer (valbuf, len, c); | |
783 | break; | |
784 | case 4: /* Needs two registers on plain H8/300 */ | |
785 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c); | |
786 | store_unsigned_integer (valbuf, 2, c); | |
787 | regcache_cooked_read_unsigned (regcache, E_RET1_REGNUM, &c); | |
788 | store_unsigned_integer ((void*)((char *)valbuf + 2), 2, c); | |
789 | break; | |
708cc1b6 MS |
790 | case 8: /* long long is now 8 bytes. */ |
791 | if (TYPE_CODE (type) == TYPE_CODE_INT) | |
792 | { | |
793 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr); | |
794 | c = read_memory_unsigned_integer ((CORE_ADDR) addr, len); | |
795 | store_unsigned_integer (valbuf, len, c); | |
796 | } | |
797 | else | |
798 | { | |
799 | error ("I don't know how this 8 byte value is returned."); | |
800 | } | |
0261a0d0 CV |
801 | break; |
802 | } | |
803 | } | |
804 | ||
805 | static void | |
806 | h8300h_extract_return_value (struct type *type, struct regcache *regcache, | |
807 | void *valbuf) | |
808 | { | |
809 | int len = TYPE_LENGTH (type); | |
708cc1b6 | 810 | ULONGEST c, addr; |
0261a0d0 CV |
811 | |
812 | switch (len) | |
813 | { | |
814 | case 1: | |
815 | case 2: | |
816 | case 4: | |
817 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &c); | |
818 | store_unsigned_integer (valbuf, len, c); | |
819 | break; | |
708cc1b6 MS |
820 | case 8: /* long long is now 8 bytes. */ |
821 | if (TYPE_CODE (type) == TYPE_CODE_INT) | |
822 | { | |
823 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr); | |
824 | c = read_memory_unsigned_integer ((CORE_ADDR) addr, len); | |
825 | store_unsigned_integer (valbuf, len, c); | |
826 | } | |
827 | else | |
828 | { | |
829 | error ("I don't know how this 8 byte value is returned."); | |
830 | } | |
0261a0d0 | 831 | break; |
c5aa993b | 832 | } |
c906108c SS |
833 | } |
834 | ||
0261a0d0 | 835 | |
c906108c SS |
836 | /* Function: store_return_value |
837 | Place the appropriate value in the appropriate registers. | |
838 | Primarily used by the RETURN command. */ | |
839 | ||
928e48af | 840 | static void |
0261a0d0 CV |
841 | h8300_store_return_value (struct type *type, struct regcache *regcache, |
842 | const void *valbuf) | |
c906108c | 843 | { |
928e48af | 844 | int len = TYPE_LENGTH (type); |
0261a0d0 | 845 | ULONGEST val; |
c906108c | 846 | |
c5aa993b JM |
847 | switch (len) |
848 | { | |
0261a0d0 | 849 | case 1: |
708cc1b6 | 850 | case 2: /* short... */ |
0261a0d0 CV |
851 | val = extract_unsigned_integer (valbuf, len); |
852 | regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM, val); | |
853 | break; | |
708cc1b6 | 854 | case 4: /* long, float */ |
0261a0d0 CV |
855 | val = extract_unsigned_integer (valbuf, len); |
856 | regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM, | |
857 | (val >> 16) &0xffff); | |
858 | regcache_cooked_write_unsigned (regcache, E_RET1_REGNUM, val & 0xffff); | |
859 | break; | |
708cc1b6 MS |
860 | case 8: /* long long, double and long double are all defined |
861 | as 4 byte types so far so this shouldn't happen. */ | |
862 | error ("I don't know how to return an 8 byte value."); | |
0261a0d0 CV |
863 | break; |
864 | } | |
865 | } | |
866 | ||
867 | static void | |
868 | h8300h_store_return_value (struct type *type, struct regcache *regcache, | |
869 | const void *valbuf) | |
870 | { | |
871 | int len = TYPE_LENGTH (type); | |
872 | ULONGEST val; | |
873 | ||
874 | switch (len) | |
875 | { | |
876 | case 1: | |
877 | case 2: | |
708cc1b6 | 878 | case 4: /* long, float */ |
0261a0d0 CV |
879 | val = extract_unsigned_integer (valbuf, len); |
880 | regcache_cooked_write_unsigned (regcache, E_RET0_REGNUM, val); | |
881 | break; | |
708cc1b6 MS |
882 | case 8: /* long long, double and long double are all defined |
883 | as 4 byte types so far so this shouldn't happen. */ | |
884 | error ("I don't know how to return an 8 byte value."); | |
0261a0d0 | 885 | break; |
c5aa993b | 886 | } |
c906108c SS |
887 | } |
888 | ||
928e48af | 889 | static struct cmd_list_element *setmachinelist; |
c906108c | 890 | |
928e48af CV |
891 | static const char * |
892 | h8300_register_name (int regno) | |
c906108c | 893 | { |
084edea5 | 894 | /* The register names change depending on which h8300 processor |
928e48af | 895 | type is selected. */ |
084edea5 | 896 | static char *register_names[] = { |
928e48af | 897 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", |
4bb1dc5e CV |
898 | "sp", "","pc","cycles", "tick", "inst", |
899 | "ccr", /* pseudo register */ | |
928e48af | 900 | }; |
084edea5 CV |
901 | if (regno < 0 |
902 | || regno >= (sizeof (register_names) / sizeof (*register_names))) | |
903 | internal_error (__FILE__, __LINE__, | |
904 | "h8300_register_name: illegal register number %d", regno); | |
905 | else | |
906 | return register_names[regno]; | |
907 | } | |
908 | ||
909 | static const char * | |
910 | h8300s_register_name (int regno) | |
911 | { | |
912 | static char *register_names[] = { | |
928e48af | 913 | "er0", "er1", "er2", "er3", "er4", "er5", "er6", |
4bb1dc5e | 914 | "sp", "", "pc", "cycles", "", "tick", "inst", |
7be04a68 | 915 | "mach", "macl", |
4bb1dc5e | 916 | "ccr", "exr" /* pseudo registers */ |
928e48af | 917 | }; |
084edea5 CV |
918 | if (regno < 0 |
919 | || regno >= (sizeof (register_names) / sizeof (*register_names))) | |
920 | internal_error (__FILE__, __LINE__, | |
921 | "h8300s_register_name: illegal register number %d", regno); | |
922 | else | |
923 | return register_names[regno]; | |
924 | } | |
925 | ||
926 | static const char * | |
927 | h8300sx_register_name (int regno) | |
928 | { | |
929 | static char *register_names[] = { | |
930 | "er0", "er1", "er2", "er3", "er4", "er5", "er6", | |
4bb1dc5e CV |
931 | "sp", "", "pc", "cycles", "", "tick", "inst", |
932 | "mach", "macl", "sbr", "vbr", | |
933 | "ccr", "exr" /* pseudo registers */ | |
084edea5 CV |
934 | }; |
935 | if (regno < 0 | |
936 | || regno >= (sizeof (register_names) / sizeof (*register_names))) | |
928e48af | 937 | internal_error (__FILE__, __LINE__, |
084edea5 | 938 | "h8300sx_register_name: illegal register number %d", regno); |
c906108c | 939 | else |
928e48af | 940 | return register_names[regno]; |
c906108c SS |
941 | } |
942 | ||
943 | static void | |
4904ba5b AC |
944 | h8300_print_register (struct gdbarch *gdbarch, struct ui_file *file, |
945 | struct frame_info *frame, int regno) | |
c906108c | 946 | { |
084edea5 CV |
947 | LONGEST rval; |
948 | const char *name = gdbarch_register_name (gdbarch, regno); | |
c906108c | 949 | |
928e48af CV |
950 | if (!name || !*name) |
951 | return; | |
c906108c | 952 | |
084edea5 | 953 | frame_read_signed_register (frame, regno, &rval); |
4904ba5b AC |
954 | |
955 | fprintf_filtered (file, "%-14s ", name); | |
4bb1dc5e | 956 | if (regno == E_PSEUDO_CCR_REGNUM || (regno == E_PSEUDO_EXR_REGNUM && h8300smode)) |
c906108c | 957 | { |
084edea5 CV |
958 | fprintf_filtered (file, "0x%02x ", (unsigned char)rval); |
959 | print_longest (file, 'u', 1, rval); | |
c906108c SS |
960 | } |
961 | else | |
962 | { | |
084edea5 CV |
963 | fprintf_filtered (file, "0x%s ", phex ((ULONGEST)rval, BINWORD)); |
964 | print_longest (file, 'd', 1, rval); | |
c906108c | 965 | } |
4bb1dc5e | 966 | if (regno == E_PSEUDO_CCR_REGNUM) |
c906108c SS |
967 | { |
968 | /* CCR register */ | |
969 | int C, Z, N, V; | |
084edea5 | 970 | unsigned char l = rval & 0xff; |
4904ba5b AC |
971 | fprintf_filtered (file, "\t"); |
972 | fprintf_filtered (file, "I-%d ", (l & 0x80) != 0); | |
973 | fprintf_filtered (file, "UI-%d ", (l & 0x40) != 0); | |
974 | fprintf_filtered (file, "H-%d ", (l & 0x20) != 0); | |
975 | fprintf_filtered (file, "U-%d ", (l & 0x10) != 0); | |
c906108c SS |
976 | N = (l & 0x8) != 0; |
977 | Z = (l & 0x4) != 0; | |
978 | V = (l & 0x2) != 0; | |
979 | C = (l & 0x1) != 0; | |
4904ba5b AC |
980 | fprintf_filtered (file, "N-%d ", N); |
981 | fprintf_filtered (file, "Z-%d ", Z); | |
982 | fprintf_filtered (file, "V-%d ", V); | |
983 | fprintf_filtered (file, "C-%d ", C); | |
c906108c | 984 | if ((C | Z) == 0) |
4904ba5b | 985 | fprintf_filtered (file, "u> "); |
c906108c | 986 | if ((C | Z) == 1) |
4904ba5b | 987 | fprintf_filtered (file, "u<= "); |
c906108c | 988 | if ((C == 0)) |
4904ba5b | 989 | fprintf_filtered (file, "u>= "); |
c906108c | 990 | if (C == 1) |
4904ba5b | 991 | fprintf_filtered (file, "u< "); |
c906108c | 992 | if (Z == 0) |
4904ba5b | 993 | fprintf_filtered (file, "!= "); |
c906108c | 994 | if (Z == 1) |
4904ba5b | 995 | fprintf_filtered (file, "== "); |
c906108c | 996 | if ((N ^ V) == 0) |
4904ba5b | 997 | fprintf_filtered (file, ">= "); |
c906108c | 998 | if ((N ^ V) == 1) |
4904ba5b | 999 | fprintf_filtered (file, "< "); |
c906108c | 1000 | if ((Z | (N ^ V)) == 0) |
4904ba5b | 1001 | fprintf_filtered (file, "> "); |
c906108c | 1002 | if ((Z | (N ^ V)) == 1) |
4904ba5b | 1003 | fprintf_filtered (file, "<= "); |
c906108c | 1004 | } |
4bb1dc5e | 1005 | else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode) |
fc974602 AV |
1006 | { |
1007 | /* EXR register */ | |
084edea5 | 1008 | unsigned char l = rval & 0xff; |
4904ba5b AC |
1009 | fprintf_filtered (file, "\t"); |
1010 | fprintf_filtered (file, "T-%d - - - ", (l & 0x80) != 0); | |
1011 | fprintf_filtered (file, "I2-%d ", (l & 4) != 0); | |
1012 | fprintf_filtered (file, "I1-%d ", (l & 2) != 0); | |
1013 | fprintf_filtered (file, "I0-%d", (l & 1) != 0); | |
d194345b | 1014 | } |
4904ba5b | 1015 | fprintf_filtered (file, "\n"); |
928e48af CV |
1016 | } |
1017 | ||
1018 | static void | |
4904ba5b AC |
1019 | h8300_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
1020 | struct frame_info *frame, int regno, int cpregs) | |
928e48af CV |
1021 | { |
1022 | if (regno < 0) | |
4bb1dc5e CV |
1023 | { |
1024 | for (regno = E_R0_REGNUM; regno <= E_SP_REGNUM; ++regno) | |
1025 | h8300_print_register (gdbarch, file, frame, regno); | |
1026 | h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM); | |
1027 | h8300_print_register (gdbarch, file, frame, E_PC_REGNUM); | |
1028 | if (h8300smode) | |
1029 | { | |
1030 | h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM); | |
1031 | if (h8300sxmode) | |
1032 | { | |
1033 | h8300_print_register (gdbarch, file, frame, E_SBR_REGNUM); | |
1034 | h8300_print_register (gdbarch, file, frame, E_VBR_REGNUM); | |
4bb1dc5e | 1035 | } |
7be04a68 MS |
1036 | h8300_print_register (gdbarch, file, frame, E_MACH_REGNUM); |
1037 | h8300_print_register (gdbarch, file, frame, E_MACL_REGNUM); | |
4bb1dc5e CV |
1038 | h8300_print_register (gdbarch, file, frame, E_CYCLES_REGNUM); |
1039 | h8300_print_register (gdbarch, file, frame, E_TICKS_REGNUM); | |
1040 | h8300_print_register (gdbarch, file, frame, E_INSTS_REGNUM); | |
1041 | } | |
1042 | else | |
1043 | { | |
1044 | h8300_print_register (gdbarch, file, frame, E_CYCLES_REGNUM); | |
1045 | h8300_print_register (gdbarch, file, frame, E_TICK_REGNUM); | |
1046 | h8300_print_register (gdbarch, file, frame, E_INST_REGNUM); | |
1047 | } | |
1048 | } | |
928e48af | 1049 | else |
4bb1dc5e CV |
1050 | { |
1051 | if (regno == E_CCR_REGNUM) | |
1052 | h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM); | |
1053 | else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode) | |
1054 | h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM); | |
1055 | else | |
1056 | h8300_print_register (gdbarch, file, frame, regno); | |
1057 | } | |
928e48af CV |
1058 | } |
1059 | ||
1060 | static CORE_ADDR | |
1061 | h8300_saved_pc_after_call (struct frame_info *ignore) | |
1062 | { | |
1063 | return read_memory_unsigned_integer (read_register (E_SP_REGNUM), BINWORD); | |
1064 | } | |
1065 | ||
928e48af | 1066 | static struct type * |
055c394a | 1067 | h8300_register_type (struct gdbarch *gdbarch, int regno) |
928e48af | 1068 | { |
4bb1dc5e | 1069 | if (regno < 0 || regno >= NUM_REGS + NUM_PSEUDO_REGS) |
928e48af | 1070 | internal_error (__FILE__, __LINE__, |
055c394a | 1071 | "h8300_register_type: illegal register number %d", |
928e48af CV |
1072 | regno); |
1073 | else | |
084edea5 CV |
1074 | { |
1075 | switch (regno) | |
1076 | { | |
1077 | case E_PC_REGNUM: | |
1078 | return builtin_type_void_func_ptr; | |
1079 | case E_SP_REGNUM: | |
1080 | case E_FP_REGNUM: | |
1081 | return builtin_type_void_data_ptr; | |
084edea5 | 1082 | default: |
4bb1dc5e CV |
1083 | if (regno == E_PSEUDO_CCR_REGNUM) |
1084 | return builtin_type_uint8; | |
1085 | else if (regno == E_PSEUDO_EXR_REGNUM) | |
1086 | return builtin_type_uint8; | |
1087 | else if (h8300hmode) | |
1088 | return builtin_type_int32; | |
1089 | else | |
1090 | return builtin_type_int16; | |
084edea5 CV |
1091 | } |
1092 | } | |
928e48af CV |
1093 | } |
1094 | ||
4bb1dc5e CV |
1095 | static void |
1096 | h8300_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
1097 | int regno, void *buf) | |
1098 | { | |
1099 | if (regno == E_PSEUDO_CCR_REGNUM) | |
1100 | regcache_raw_read (regcache, E_CCR_REGNUM, buf); | |
1101 | else if (regno == E_PSEUDO_EXR_REGNUM) | |
1102 | regcache_raw_read (regcache, E_EXR_REGNUM, buf); | |
1103 | else | |
1104 | regcache_raw_read (regcache, regno, buf); | |
1105 | } | |
1106 | ||
1107 | static void | |
1108 | h8300_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, | |
1109 | int regno, const void *buf) | |
1110 | { | |
1111 | if (regno == E_PSEUDO_CCR_REGNUM) | |
1112 | regcache_raw_write (regcache, E_CCR_REGNUM, buf); | |
1113 | else if (regno == E_PSEUDO_EXR_REGNUM) | |
1114 | regcache_raw_write (regcache, E_EXR_REGNUM, buf); | |
1115 | else | |
1116 | regcache_raw_write (regcache, regno, buf); | |
1117 | } | |
1118 | ||
1119 | static int | |
1120 | h8300_dbg_reg_to_regnum (int regno) | |
1121 | { | |
1122 | if (regno == E_CCR_REGNUM) | |
1123 | return E_PSEUDO_CCR_REGNUM; | |
1124 | return regno; | |
1125 | } | |
1126 | ||
1127 | static int | |
1128 | h8300s_dbg_reg_to_regnum (int regno) | |
1129 | { | |
1130 | if (regno == E_CCR_REGNUM) | |
1131 | return E_PSEUDO_CCR_REGNUM; | |
1132 | if (regno == E_EXR_REGNUM) | |
1133 | return E_PSEUDO_EXR_REGNUM; | |
1134 | return regno; | |
1135 | } | |
1136 | ||
928e48af | 1137 | static CORE_ADDR |
0261a0d0 | 1138 | h8300_extract_struct_value_address (struct regcache *regcache) |
928e48af | 1139 | { |
0261a0d0 CV |
1140 | ULONGEST addr; |
1141 | regcache_cooked_read_unsigned (regcache, E_RET0_REGNUM, &addr); | |
1142 | return addr; | |
928e48af CV |
1143 | } |
1144 | ||
1145 | const static unsigned char * | |
1146 | h8300_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
1147 | { | |
1148 | /*static unsigned char breakpoint[] = { 0x7A, 0xFF };*/ /* ??? */ | |
1149 | static unsigned char breakpoint[] = { 0x01, 0x80 }; /* Sleep */ | |
1150 | ||
1151 | *lenptr = sizeof (breakpoint); | |
1152 | return breakpoint; | |
1153 | } | |
1154 | ||
0261a0d0 CV |
1155 | static CORE_ADDR |
1156 | h8300_push_dummy_code (struct gdbarch *gdbarch, | |
1157 | CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc, | |
1158 | struct value **args, int nargs, | |
1159 | struct type *value_type, | |
1160 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr) | |
1161 | { | |
1162 | /* Allocate space sufficient for a breakpoint. */ | |
1163 | sp = (sp - 2) & ~1; | |
1164 | /* Store the address of that breakpoint */ | |
1165 | *bp_addr = sp; | |
1166 | /* h8300 always starts the call at the callee's entry point. */ | |
1167 | *real_pc = funaddr; | |
1168 | return sp; | |
1169 | } | |
1170 | ||
928e48af CV |
1171 | static void |
1172 | h8300_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, | |
1173 | struct frame_info *frame, const char *args) | |
1174 | { | |
1175 | fprintf_filtered (file, "\ | |
1176 | No floating-point info available for this processor.\n"); | |
1177 | } | |
1178 | ||
1179 | static struct gdbarch * | |
1180 | h8300_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1181 | { | |
928e48af CV |
1182 | struct gdbarch_tdep *tdep = NULL; |
1183 | struct gdbarch *gdbarch; | |
1184 | ||
1185 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1186 | if (arches != NULL) | |
1187 | return arches->gdbarch; | |
1188 | ||
1189 | #if 0 | |
1190 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); | |
1191 | #endif | |
1192 | ||
1193 | if (info.bfd_arch_info->arch != bfd_arch_h8300) | |
1194 | return NULL; | |
1195 | ||
084edea5 CV |
1196 | gdbarch = gdbarch_alloc (&info, 0); |
1197 | ||
928e48af CV |
1198 | switch (info.bfd_arch_info->mach) |
1199 | { | |
0a48e7e8 MS |
1200 | case bfd_mach_h8300: |
1201 | h8300sxmode = 0; | |
1202 | h8300smode = 0; | |
1203 | h8300hmode = 0; | |
084edea5 | 1204 | set_gdbarch_num_regs (gdbarch, 13); |
4bb1dc5e CV |
1205 | set_gdbarch_num_pseudo_regs (gdbarch, 1); |
1206 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1207 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1208 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1209 | set_gdbarch_stab_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
084edea5 | 1210 | set_gdbarch_register_name (gdbarch, h8300_register_name); |
084edea5 CV |
1211 | set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT); |
1212 | set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT); | |
0261a0d0 CV |
1213 | set_gdbarch_extract_return_value (gdbarch, h8300_extract_return_value); |
1214 | set_gdbarch_store_return_value (gdbarch, h8300_store_return_value); | |
4bb1dc5e | 1215 | set_gdbarch_print_insn (gdbarch, print_insn_h8300); |
0a48e7e8 MS |
1216 | break; |
1217 | case bfd_mach_h8300h: | |
8efca6ba | 1218 | case bfd_mach_h8300hn: |
0a48e7e8 MS |
1219 | h8300sxmode = 0; |
1220 | h8300smode = 0; | |
1221 | h8300hmode = 1; | |
084edea5 | 1222 | set_gdbarch_num_regs (gdbarch, 13); |
4bb1dc5e CV |
1223 | set_gdbarch_num_pseudo_regs (gdbarch, 1); |
1224 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1225 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1226 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
1227 | set_gdbarch_stab_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum); | |
084edea5 | 1228 | set_gdbarch_register_name (gdbarch, h8300_register_name); |
084edea5 CV |
1229 | set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
1230 | set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
0261a0d0 CV |
1231 | set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value); |
1232 | set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value); | |
4bb1dc5e | 1233 | set_gdbarch_print_insn (gdbarch, print_insn_h8300h); |
0a48e7e8 MS |
1234 | break; |
1235 | case bfd_mach_h8300s: | |
8efca6ba | 1236 | case bfd_mach_h8300sn: |
0a48e7e8 MS |
1237 | h8300sxmode = 0; |
1238 | h8300smode = 1; | |
1239 | h8300hmode = 1; | |
7be04a68 | 1240 | set_gdbarch_num_regs (gdbarch, 16); |
4bb1dc5e CV |
1241 | set_gdbarch_num_pseudo_regs (gdbarch, 2); |
1242 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1243 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1244 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1245 | set_gdbarch_stab_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
084edea5 | 1246 | set_gdbarch_register_name (gdbarch, h8300s_register_name); |
084edea5 CV |
1247 | set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
1248 | set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
0261a0d0 CV |
1249 | set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value); |
1250 | set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value); | |
4bb1dc5e | 1251 | set_gdbarch_print_insn (gdbarch, print_insn_h8300s); |
0a48e7e8 MS |
1252 | break; |
1253 | case bfd_mach_h8300sx: | |
084edea5 | 1254 | case bfd_mach_h8300sxn: |
0a48e7e8 MS |
1255 | h8300sxmode = 1; |
1256 | h8300smode = 1; | |
1257 | h8300hmode = 1; | |
084edea5 | 1258 | set_gdbarch_num_regs (gdbarch, 18); |
4bb1dc5e CV |
1259 | set_gdbarch_num_pseudo_regs (gdbarch, 2); |
1260 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1261 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1262 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
1263 | set_gdbarch_stab_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum); | |
084edea5 | 1264 | set_gdbarch_register_name (gdbarch, h8300sx_register_name); |
084edea5 CV |
1265 | set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
1266 | set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
0261a0d0 CV |
1267 | set_gdbarch_extract_return_value (gdbarch, h8300h_extract_return_value); |
1268 | set_gdbarch_store_return_value (gdbarch, h8300h_store_return_value); | |
4bb1dc5e | 1269 | set_gdbarch_print_insn (gdbarch, print_insn_h8300s); |
0a48e7e8 | 1270 | break; |
928e48af CV |
1271 | } |
1272 | ||
4bb1dc5e CV |
1273 | set_gdbarch_pseudo_register_read (gdbarch, h8300_pseudo_register_read); |
1274 | set_gdbarch_pseudo_register_write (gdbarch, h8300_pseudo_register_write); | |
1275 | ||
a5afb99f AC |
1276 | /* NOTE: cagney/2002-12-06: This can be deleted when this arch is |
1277 | ready to unwind the PC first (see frame.c:get_prev_frame()). */ | |
1278 | set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default); | |
1279 | ||
928e48af CV |
1280 | /* |
1281 | * Basic register fields and methods. | |
1282 | */ | |
1283 | ||
928e48af | 1284 | set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM); |
0ba6dca9 | 1285 | set_gdbarch_deprecated_fp_regnum (gdbarch, E_FP_REGNUM); |
928e48af | 1286 | set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM); |
055c394a | 1287 | set_gdbarch_register_type (gdbarch, h8300_register_type); |
4904ba5b | 1288 | set_gdbarch_print_registers_info (gdbarch, h8300_print_registers_info); |
928e48af CV |
1289 | set_gdbarch_print_float_info (gdbarch, h8300_print_float_info); |
1290 | ||
1291 | /* | |
1292 | * Frame Info | |
1293 | */ | |
0261a0d0 CV |
1294 | set_gdbarch_skip_prologue (gdbarch, h8300_skip_prologue); |
1295 | ||
884a26c8 MS |
1296 | set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, |
1297 | h8300_frame_init_saved_regs); | |
1298 | set_gdbarch_deprecated_init_extra_frame_info (gdbarch, | |
1299 | h8300_init_extra_frame_info); | |
618ce49f | 1300 | set_gdbarch_deprecated_frame_chain (gdbarch, h8300_frame_chain); |
884a26c8 MS |
1301 | set_gdbarch_deprecated_saved_pc_after_call (gdbarch, |
1302 | h8300_saved_pc_after_call); | |
8bedc050 | 1303 | set_gdbarch_deprecated_frame_saved_pc (gdbarch, h8300_frame_saved_pc); |
63d47a7d | 1304 | set_gdbarch_deprecated_pop_frame (gdbarch, h8300_pop_frame); |
928e48af CV |
1305 | |
1306 | /* | |
1307 | * Miscelany | |
1308 | */ | |
1309 | /* Stack grows up. */ | |
1310 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1311 | /* PC stops zero byte after a trap instruction | |
1312 | (which means: exactly on trap instruction). */ | |
1313 | set_gdbarch_decr_pc_after_break (gdbarch, 0); | |
1314 | /* This value is almost never non-zero... */ | |
1315 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1316 | /* This value is almost never non-zero... */ | |
1317 | set_gdbarch_frame_args_skip (gdbarch, 0); | |
928e48af CV |
1318 | set_gdbarch_frameless_function_invocation (gdbarch, |
1319 | frameless_look_for_prologue); | |
1320 | ||
0261a0d0 CV |
1321 | set_gdbarch_extract_struct_value_address (gdbarch, |
1322 | h8300_extract_struct_value_address); | |
1fd35568 | 1323 | set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention); |
928e48af | 1324 | set_gdbarch_breakpoint_from_pc (gdbarch, h8300_breakpoint_from_pc); |
0261a0d0 | 1325 | set_gdbarch_push_dummy_code (gdbarch, h8300_push_dummy_code); |
63d47a7d | 1326 | set_gdbarch_push_dummy_call (gdbarch, h8300_push_dummy_call); |
928e48af CV |
1327 | |
1328 | set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT); | |
1329 | set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
708cc1b6 | 1330 | set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
084edea5 CV |
1331 | set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
1332 | set_gdbarch_long_double_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
928e48af | 1333 | |
5247b418 | 1334 | /* set_gdbarch_stack_align (gdbarch, SOME_stack_align); */ |
928e48af CV |
1335 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); |
1336 | ||
708cc1b6 MS |
1337 | /* Char is unsigned. */ |
1338 | set_gdbarch_char_signed (gdbarch, 0); | |
1339 | ||
928e48af | 1340 | return gdbarch; |
c906108c SS |
1341 | } |
1342 | ||
a78f21af AC |
1343 | extern initialize_file_ftype _initialize_h8300_tdep; /* -Wmissing-prototypes */ |
1344 | ||
c906108c | 1345 | void |
fba45db2 | 1346 | _initialize_h8300_tdep (void) |
c906108c | 1347 | { |
928e48af | 1348 | register_gdbarch_init (bfd_arch_h8300, h8300_gdbarch_init); |
c906108c | 1349 | } |