1 /* Target-dependent code for Moxie.
3 Copyright (C) 2009-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "frame-unwind.h"
23 #include "frame-base.h"
34 #include "arch-utils.h"
36 #include "trad-frame.h"
39 #include "record-full.h"
41 #include "moxie-tdep.h"
44 /* Local functions. */
46 extern void _initialize_moxie_tdep (void);
48 /* Use an invalid address value as 'not available' marker. */
49 enum { REG_UNAVAIL
= (CORE_ADDR
) -1 };
51 struct moxie_frame_cache
57 CORE_ADDR saved_regs
[MOXIE_NUM_REGS
];
61 /* Implement the "frame_align" gdbarch method. */
64 moxie_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
66 /* Align to the size of an instruction (so that they can safely be
67 pushed onto the stack. */
71 /* Implement the "breakpoint_from_pc" gdbarch method. */
73 static const unsigned char *
74 moxie_breakpoint_from_pc (struct gdbarch
*gdbarch
,
75 CORE_ADDR
*pcptr
, int *lenptr
)
77 static unsigned char breakpoint
[] = { 0x35, 0x00 };
79 *lenptr
= sizeof (breakpoint
);
83 /* Moxie register names. */
85 char *moxie_register_names
[] = {
86 "$fp", "$sp", "$r0", "$r1", "$r2",
87 "$r3", "$r4", "$r5", "$r6", "$r7",
88 "$r8", "$r9", "$r10", "$r11", "$r12",
89 "$r13", "$pc", "$cc" };
91 /* Implement the "register_name" gdbarch method. */
94 moxie_register_name (struct gdbarch
*gdbarch
, int reg_nr
)
98 if (reg_nr
>= MOXIE_NUM_REGS
)
100 return moxie_register_names
[reg_nr
];
103 /* Implement the "register_type" gdbarch method. */
106 moxie_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
108 if (reg_nr
== MOXIE_PC_REGNUM
)
109 return builtin_type (gdbarch
)->builtin_func_ptr
;
110 else if (reg_nr
== MOXIE_SP_REGNUM
|| reg_nr
== MOXIE_FP_REGNUM
)
111 return builtin_type (gdbarch
)->builtin_data_ptr
;
113 return builtin_type (gdbarch
)->builtin_int32
;
116 /* Write into appropriate registers a function return value
117 of type TYPE, given in virtual format. */
120 moxie_store_return_value (struct type
*type
, struct regcache
*regcache
,
121 const gdb_byte
*valbuf
)
123 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
124 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
126 int len
= TYPE_LENGTH (type
);
128 /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
129 regval
= extract_unsigned_integer (valbuf
, len
> 4 ? 4 : len
, byte_order
);
130 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
, regval
);
133 regval
= extract_unsigned_integer (valbuf
+ 4, len
- 4, byte_order
);
134 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
+ 1, regval
);
138 /* Decode the instructions within the given address range. Decide
139 when we must have reached the end of the function prologue. If a
140 frame_info pointer is provided, fill in its saved_regs etc.
142 Returns the address of the first instruction after the prologue. */
145 moxie_analyze_prologue (CORE_ADDR start_addr
, CORE_ADDR end_addr
,
146 struct moxie_frame_cache
*cache
,
147 struct gdbarch
*gdbarch
)
149 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
151 ULONGEST inst
, inst2
;
155 /* Record where the jsra instruction saves the PC and FP. */
156 cache
->saved_regs
[MOXIE_PC_REGNUM
] = -4;
157 cache
->saved_regs
[MOXIE_FP_REGNUM
] = 0;
158 cache
->framesize
= 0;
160 if (start_addr
>= end_addr
)
163 for (next_addr
= start_addr
; next_addr
< end_addr
; )
165 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
167 /* Match "push $sp $rN" where N is between 0 and 13 inclusive. */
168 if (inst
>= 0x0612 && inst
<= 0x061f)
170 regnum
= inst
& 0x000f;
171 cache
->framesize
+= 4;
172 cache
->saved_regs
[regnum
] = cache
->framesize
;
179 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
181 /* Optional stack allocation for args and local vars <= 4
183 if (inst
== 0x01e0) /* ldi.l $r12, X */
185 offset
= read_memory_integer (next_addr
+ 2, 4, byte_order
);
186 inst2
= read_memory_unsigned_integer (next_addr
+ 6, 2, byte_order
);
188 if (inst2
== 0x291e) /* sub.l $sp, $r12 */
190 cache
->framesize
+= offset
;
193 return (next_addr
+ 8);
195 else if ((inst
& 0xff00) == 0x9100) /* dec $sp, X */
197 cache
->framesize
+= (inst
& 0x00ff);
200 while (next_addr
< end_addr
)
202 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
203 if ((inst
& 0xff00) != 0x9100) /* no more dec $sp, X */
205 cache
->framesize
+= (inst
& 0x00ff);
213 /* Find the end of function prologue. */
216 moxie_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
218 CORE_ADDR func_addr
= 0, func_end
= 0;
219 const char *func_name
;
221 /* See if we can determine the end of the prologue via the symbol table.
222 If so, then return either PC, or the PC after the prologue, whichever
224 if (find_pc_partial_function (pc
, &func_name
, &func_addr
, &func_end
))
226 CORE_ADDR post_prologue_pc
227 = skip_prologue_using_sal (gdbarch
, func_addr
);
228 if (post_prologue_pc
!= 0)
229 return std::max (pc
, post_prologue_pc
);
232 /* Can't determine prologue from the symbol table, need to examine
234 struct symtab_and_line sal
;
236 struct moxie_frame_cache cache
;
239 memset (&cache
, 0, sizeof cache
);
241 plg_end
= moxie_analyze_prologue (func_addr
,
242 func_end
, &cache
, gdbarch
);
243 /* Found a function. */
244 sym
= lookup_symbol (func_name
, NULL
, VAR_DOMAIN
, NULL
).symbol
;
245 /* Don't use line number debug info for assembly source
247 if (sym
&& SYMBOL_LANGUAGE (sym
) != language_asm
)
249 sal
= find_pc_line (func_addr
, 0);
250 if (sal
.end
&& sal
.end
< func_end
)
252 /* Found a line number, use it as end of
257 /* No useable line symbol. Use result of prologue parsing
263 /* No function symbol -- just return the PC. */
264 return (CORE_ADDR
) pc
;
267 struct moxie_unwind_cache
269 /* The previous frame's inner most stack address. Used as this
270 frame ID's stack_addr. */
272 /* The frame's base, optionally used by the high-level debug info. */
275 /* How far the SP and r13 (FP) have been offset from the start of
276 the stack frame (as defined by the previous frame's stack
281 /* Table indicating the location of each and every register. */
282 struct trad_frame_saved_reg
*saved_regs
;
285 /* Read an unsigned integer from the inferior, and adjust
288 moxie_process_readu (CORE_ADDR addr
, gdb_byte
*buf
,
289 int length
, enum bfd_endian byte_order
)
291 if (target_read_memory (addr
, buf
, length
))
294 printf_unfiltered (_("Process record: error reading memory at "
295 "addr 0x%s len = %d.\n"),
296 paddress (target_gdbarch (), addr
), length
);
300 return extract_unsigned_integer (buf
, length
, byte_order
);
304 /* Helper macro to extract the signed 10-bit offset from a 16-bit
305 branch instruction. */
306 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
308 /* Insert a single step breakpoint. */
311 moxie_software_single_step (struct frame_info
*frame
)
313 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
314 struct address_space
*aspace
= get_frame_address_space (frame
);
320 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
321 struct regcache
*regcache
= get_current_regcache ();
323 addr
= get_frame_pc (frame
);
325 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
327 /* Decode instruction. */
328 if (inst
& (1 << 15))
330 if (inst
& (1 << 14))
332 /* This is a Form 3 instruction. */
333 int opcode
= (inst
>> 10 & 0xf);
341 case 0x04: /* bltu */
342 case 0x05: /* bgtu */
345 case 0x08: /* bgeu */
346 case 0x09: /* bleu */
347 /* Insert breaks on both branches, because we can't currently tell
348 which way things will go. */
349 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 2);
350 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 2 + INST2OFFSET(inst
));
361 /* This is a Form 2 instruction. They are all 16 bits. */
362 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 2);
367 /* This is a Form 1 instruction. */
368 int opcode
= inst
>> 8;
372 /* 16-bit instructions. */
374 case 0x02: /* mov (register-to-register) */
375 case 0x05: /* add.l */
376 case 0x06: /* push */
378 case 0x0a: /* ld.l (register indirect) */
379 case 0x0b: /* st.l */
382 case 0x10: /* sex.b */
383 case 0x11: /* sex.s */
384 case 0x12: /* zex.b */
385 case 0x13: /* zex.s */
386 case 0x14: /* umul.x */
387 case 0x15: /* mul.x */
391 case 0x1c: /* ld.b (register indirect) */
392 case 0x1e: /* st.b */
393 case 0x21: /* ld.s (register indirect) */
394 case 0x23: /* st.s */
396 case 0x27: /* lshr */
397 case 0x28: /* ashl */
398 case 0x29: /* sub.l */
402 case 0x2d: /* ashr */
404 case 0x2f: /* mul.l */
405 case 0x31: /* div.l */
406 case 0x32: /* udiv.l */
407 case 0x33: /* mod.l */
408 case 0x34: /* umod.l */
409 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 2);
412 /* 32-bit instructions. */
413 case 0x0c: /* ldo.l */
414 case 0x0d: /* sto.l */
415 case 0x36: /* ldo.b */
416 case 0x37: /* sto.b */
417 case 0x38: /* ldo.s */
418 case 0x39: /* sto.s */
419 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 4);
422 /* 48-bit instructions. */
423 case 0x01: /* ldi.l (immediate) */
424 case 0x08: /* lda.l */
425 case 0x09: /* sta.l */
426 case 0x1b: /* ldi.b (immediate) */
427 case 0x1d: /* lda.b */
428 case 0x1f: /* sta.b */
429 case 0x20: /* ldi.s (immediate) */
430 case 0x22: /* lda.s */
431 case 0x24: /* sta.s */
432 insert_single_step_breakpoint (gdbarch
, aspace
, addr
+ 6);
435 /* Control flow instructions. */
436 case 0x03: /* jsra */
437 case 0x1a: /* jmpa */
438 insert_single_step_breakpoint (gdbarch
, aspace
,
439 moxie_process_readu (addr
+ 2,
445 regcache_cooked_read_unsigned (regcache
, MOXIE_FP_REGNUM
, &fp
);
446 insert_single_step_breakpoint (gdbarch
, aspace
,
447 moxie_process_readu (fp
+ 4,
454 regcache_raw_read (regcache
,
455 (inst
>> 4) & 0xf, (gdb_byte
*) & tmpu32
);
456 insert_single_step_breakpoint (gdbarch
, aspace
,
462 /* Unsupported, for now. */
470 /* Implement the "read_pc" gdbarch method. */
473 moxie_read_pc (struct regcache
*regcache
)
477 regcache_cooked_read_unsigned (regcache
, MOXIE_PC_REGNUM
, &pc
);
481 /* Implement the "write_pc" gdbarch method. */
484 moxie_write_pc (struct regcache
*regcache
, CORE_ADDR val
)
486 regcache_cooked_write_unsigned (regcache
, MOXIE_PC_REGNUM
, val
);
489 /* Implement the "unwind_sp" gdbarch method. */
492 moxie_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
494 return frame_unwind_register_unsigned (next_frame
, MOXIE_SP_REGNUM
);
497 /* Given a return value in `regbuf' with a type `valtype',
498 extract and copy its value into `valbuf'. */
501 moxie_extract_return_value (struct type
*type
, struct regcache
*regcache
,
504 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
505 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
506 int len
= TYPE_LENGTH (type
);
509 /* By using store_unsigned_integer we avoid having to do
510 anything special for small big-endian values. */
511 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
, &tmp
);
512 store_unsigned_integer (dst
, (len
> 4 ? len
- 4 : len
), byte_order
, tmp
);
514 /* Ignore return values more than 8 bytes in size because the moxie
515 returns anything more than 8 bytes in the stack. */
518 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
+ 1, &tmp
);
519 store_unsigned_integer (dst
+ len
- 4, 4, byte_order
, tmp
);
523 /* Implement the "return_value" gdbarch method. */
525 static enum return_value_convention
526 moxie_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
527 struct type
*valtype
, struct regcache
*regcache
,
528 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
530 if (TYPE_LENGTH (valtype
) > 8)
531 return RETURN_VALUE_STRUCT_CONVENTION
;
535 moxie_extract_return_value (valtype
, regcache
, readbuf
);
536 if (writebuf
!= NULL
)
537 moxie_store_return_value (valtype
, regcache
, writebuf
);
538 return RETURN_VALUE_REGISTER_CONVENTION
;
542 /* Allocate and initialize a moxie_frame_cache object. */
544 static struct moxie_frame_cache
*
545 moxie_alloc_frame_cache (void)
547 struct moxie_frame_cache
*cache
;
550 cache
= FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache
);
555 cache
->framesize
= 0;
556 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
557 cache
->saved_regs
[i
] = REG_UNAVAIL
;
562 /* Populate a moxie_frame_cache object for this_frame. */
564 static struct moxie_frame_cache
*
565 moxie_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
567 struct moxie_frame_cache
*cache
;
568 CORE_ADDR current_pc
;
572 return (struct moxie_frame_cache
*) *this_cache
;
574 cache
= moxie_alloc_frame_cache ();
577 cache
->base
= get_frame_register_unsigned (this_frame
, MOXIE_FP_REGNUM
);
578 if (cache
->base
== 0)
581 cache
->pc
= get_frame_func (this_frame
);
582 current_pc
= get_frame_pc (this_frame
);
585 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
586 moxie_analyze_prologue (cache
->pc
, current_pc
, cache
, gdbarch
);
589 cache
->saved_sp
= cache
->base
- cache
->framesize
;
591 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
592 if (cache
->saved_regs
[i
] != REG_UNAVAIL
)
593 cache
->saved_regs
[i
] = cache
->base
- cache
->saved_regs
[i
];
598 /* Implement the "unwind_pc" gdbarch method. */
601 moxie_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
603 return frame_unwind_register_unsigned (next_frame
, MOXIE_PC_REGNUM
);
606 /* Given a GDB frame, determine the address of the calling function's
607 frame. This will be used to create a new GDB frame struct. */
610 moxie_frame_this_id (struct frame_info
*this_frame
,
611 void **this_prologue_cache
, struct frame_id
*this_id
)
613 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
614 this_prologue_cache
);
616 /* This marks the outermost frame. */
617 if (cache
->base
== 0)
620 *this_id
= frame_id_build (cache
->saved_sp
, cache
->pc
);
623 /* Get the value of register regnum in the previous stack frame. */
625 static struct value
*
626 moxie_frame_prev_register (struct frame_info
*this_frame
,
627 void **this_prologue_cache
, int regnum
)
629 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
630 this_prologue_cache
);
632 gdb_assert (regnum
>= 0);
634 if (regnum
== MOXIE_SP_REGNUM
&& cache
->saved_sp
)
635 return frame_unwind_got_constant (this_frame
, regnum
, cache
->saved_sp
);
637 if (regnum
< MOXIE_NUM_REGS
&& cache
->saved_regs
[regnum
] != REG_UNAVAIL
)
638 return frame_unwind_got_memory (this_frame
, regnum
,
639 cache
->saved_regs
[regnum
]);
641 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
644 static const struct frame_unwind moxie_frame_unwind
= {
646 default_frame_unwind_stop_reason
,
648 moxie_frame_prev_register
,
650 default_frame_sniffer
653 /* Return the base address of this_frame. */
656 moxie_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
658 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
664 static const struct frame_base moxie_frame_base
= {
666 moxie_frame_base_address
,
667 moxie_frame_base_address
,
668 moxie_frame_base_address
671 static struct frame_id
672 moxie_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
674 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, MOXIE_SP_REGNUM
);
676 return frame_id_build (sp
, get_frame_pc (this_frame
));
679 /* Parse the current instruction and record the values of the registers and
680 memory that will be changed in current instruction to "record_arch_list".
681 Return -1 if something wrong. */
684 moxie_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
690 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
692 if (record_debug
> 1)
693 fprintf_unfiltered (gdb_stdlog
, "Process record: moxie_process_record "
695 paddress (target_gdbarch (), addr
));
697 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
699 /* Decode instruction. */
700 if (inst
& (1 << 15))
702 if (inst
& (1 << 14))
704 /* This is a Form 3 instruction. */
705 int opcode
= (inst
>> 10 & 0xf);
713 case 0x04: /* bltu */
714 case 0x05: /* bgtu */
717 case 0x08: /* bgeu */
718 case 0x09: /* bleu */
730 /* This is a Form 2 instruction. */
731 int opcode
= (inst
>> 12 & 0x3);
738 int reg
= (inst
>> 8) & 0xf;
739 if (record_full_arch_list_add_reg (regcache
, reg
))
745 /* Do nothing until GDB learns about moxie's special
757 /* This is a Form 1 instruction. */
758 int opcode
= inst
>> 8;
765 case 0x01: /* ldi.l (immediate) */
766 case 0x02: /* mov (register-to-register) */
768 int reg
= (inst
>> 4) & 0xf;
769 if (record_full_arch_list_add_reg (regcache
, reg
))
773 case 0x03: /* jsra */
775 regcache_raw_read (regcache
,
776 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
777 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
779 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
780 || (record_full_arch_list_add_reg (regcache
,
782 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
788 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
789 || (record_full_arch_list_add_reg (regcache
,
794 case 0x05: /* add.l */
796 int reg
= (inst
>> 4) & 0xf;
797 if (record_full_arch_list_add_reg (regcache
, reg
))
801 case 0x06: /* push */
803 int reg
= (inst
>> 4) & 0xf;
804 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
805 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
807 if (record_full_arch_list_add_reg (regcache
, reg
)
808 || record_full_arch_list_add_mem (tmpu32
- 4, 4))
814 int a
= (inst
>> 4) & 0xf;
816 if (record_full_arch_list_add_reg (regcache
, a
)
817 || record_full_arch_list_add_reg (regcache
, b
))
821 case 0x08: /* lda.l */
823 int reg
= (inst
>> 4) & 0xf;
824 if (record_full_arch_list_add_reg (regcache
, reg
))
828 case 0x09: /* sta.l */
830 tmpu32
= (uint32_t) moxie_process_readu (addr
+2, buf
,
832 if (record_full_arch_list_add_mem (tmpu32
, 4))
836 case 0x0a: /* ld.l (register indirect) */
838 int reg
= (inst
>> 4) & 0xf;
839 if (record_full_arch_list_add_reg (regcache
, reg
))
843 case 0x0b: /* st.l */
845 int reg
= (inst
>> 4) & 0xf;
846 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
847 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
849 if (record_full_arch_list_add_mem (tmpu32
, 4))
853 case 0x0c: /* ldo.l */
855 int reg
= (inst
>> 4) & 0xf;
856 if (record_full_arch_list_add_reg (regcache
, reg
))
860 case 0x0d: /* sto.l */
862 int reg
= (inst
>> 4) & 0xf;
863 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
864 byte_order
)) << 16 ) >> 16;
865 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
866 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
869 if (record_full_arch_list_add_mem (tmpu32
, 4))
875 if (record_full_arch_list_add_reg (regcache
, MOXIE_CC_REGNUM
))
884 case 0x10: /* sex.b */
885 case 0x11: /* sex.s */
886 case 0x12: /* zex.b */
887 case 0x13: /* zex.s */
888 case 0x14: /* umul.x */
889 case 0x15: /* mul.x */
891 int reg
= (inst
>> 4) & 0xf;
892 if (record_full_arch_list_add_reg (regcache
, reg
))
905 regcache_raw_read (regcache
,
906 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
907 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
909 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
910 || (record_full_arch_list_add_reg (regcache
,
912 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
916 case 0x1a: /* jmpa */
921 case 0x1b: /* ldi.b (immediate) */
922 case 0x1c: /* ld.b (register indirect) */
923 case 0x1d: /* lda.b */
925 int reg
= (inst
>> 4) & 0xf;
926 if (record_full_arch_list_add_reg (regcache
, reg
))
930 case 0x1e: /* st.b */
932 int reg
= (inst
>> 4) & 0xf;
933 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
934 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
936 if (record_full_arch_list_add_mem (tmpu32
, 1))
940 case 0x1f: /* sta.b */
942 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
943 if (record_full_arch_list_add_mem (tmpu32
, 1))
947 case 0x20: /* ldi.s (immediate) */
948 case 0x21: /* ld.s (register indirect) */
949 case 0x22: /* lda.s */
951 int reg
= (inst
>> 4) & 0xf;
952 if (record_full_arch_list_add_reg (regcache
, reg
))
956 case 0x23: /* st.s */
958 int reg
= (inst
>> 4) & 0xf;
959 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
960 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
962 if (record_full_arch_list_add_mem (tmpu32
, 2))
966 case 0x24: /* sta.s */
968 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
969 if (record_full_arch_list_add_mem (tmpu32
, 2))
979 case 0x27: /* lshr */
980 case 0x28: /* ashl */
985 case 0x2d: /* ashr */
989 int reg
= (inst
>> 4) & 0xf;
990 if (record_full_arch_list_add_reg (regcache
, reg
))
996 /* We currently implement support for libgloss'
999 int inum
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
1003 case 0x1: /* SYS_exit */
1008 case 0x2: /* SYS_open */
1010 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
1014 case 0x4: /* SYS_read */
1016 uint32_t length
, ptr
;
1018 /* Read buffer pointer is in $r1. */
1019 regcache_raw_read (regcache
, 3, (gdb_byte
*) & ptr
);
1020 ptr
= extract_unsigned_integer ((gdb_byte
*) & ptr
,
1023 /* String length is at 0x12($fp). */
1024 regcache_raw_read (regcache
,
1025 MOXIE_FP_REGNUM
, (gdb_byte
*) & tmpu32
);
1026 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1028 length
= moxie_process_readu (tmpu32
+20, buf
, 4, byte_order
);
1030 if (record_full_arch_list_add_mem (ptr
, length
))
1034 case 0x5: /* SYS_write */
1036 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
1045 case 0x31: /* div.l */
1046 case 0x32: /* udiv.l */
1047 case 0x33: /* mod.l */
1048 case 0x34: /* umod.l */
1050 int reg
= (inst
>> 4) & 0xf;
1051 if (record_full_arch_list_add_reg (regcache
, reg
))
1055 case 0x35: /* brk */
1058 case 0x36: /* ldo.b */
1060 int reg
= (inst
>> 4) & 0xf;
1061 if (record_full_arch_list_add_reg (regcache
, reg
))
1065 case 0x37: /* sto.b */
1067 int reg
= (inst
>> 4) & 0xf;
1068 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1069 byte_order
)) << 16 ) >> 16;
1070 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
1071 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1074 if (record_full_arch_list_add_mem (tmpu32
, 1))
1078 case 0x38: /* ldo.s */
1080 int reg
= (inst
>> 4) & 0xf;
1081 if (record_full_arch_list_add_reg (regcache
, reg
))
1085 case 0x39: /* sto.s */
1087 int reg
= (inst
>> 4) & 0xf;
1088 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1089 byte_order
)) << 16 ) >> 16;
1090 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
1091 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1094 if (record_full_arch_list_add_mem (tmpu32
, 2))
1104 if (record_full_arch_list_add_reg (regcache
, MOXIE_PC_REGNUM
))
1106 if (record_full_arch_list_add_end ())
1111 /* Allocate and initialize the moxie gdbarch object. */
1113 static struct gdbarch
*
1114 moxie_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1116 struct gdbarch
*gdbarch
;
1117 struct gdbarch_tdep
*tdep
;
1119 /* If there is already a candidate, use it. */
1120 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1122 return arches
->gdbarch
;
1124 /* Allocate space for the new architecture. */
1125 tdep
= XNEW (struct gdbarch_tdep
);
1126 gdbarch
= gdbarch_alloc (&info
, tdep
);
1128 set_gdbarch_read_pc (gdbarch
, moxie_read_pc
);
1129 set_gdbarch_write_pc (gdbarch
, moxie_write_pc
);
1130 set_gdbarch_unwind_sp (gdbarch
, moxie_unwind_sp
);
1132 set_gdbarch_num_regs (gdbarch
, MOXIE_NUM_REGS
);
1133 set_gdbarch_sp_regnum (gdbarch
, MOXIE_SP_REGNUM
);
1134 set_gdbarch_pc_regnum (gdbarch
, MOXIE_PC_REGNUM
);
1135 set_gdbarch_register_name (gdbarch
, moxie_register_name
);
1136 set_gdbarch_register_type (gdbarch
, moxie_register_type
);
1138 set_gdbarch_return_value (gdbarch
, moxie_return_value
);
1140 set_gdbarch_skip_prologue (gdbarch
, moxie_skip_prologue
);
1141 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1142 set_gdbarch_breakpoint_from_pc (gdbarch
, moxie_breakpoint_from_pc
);
1143 set_gdbarch_frame_align (gdbarch
, moxie_frame_align
);
1145 frame_base_set_default (gdbarch
, &moxie_frame_base
);
1147 /* Methods for saving / extracting a dummy frame's ID. The ID's
1148 stack address must match the SP value returned by
1149 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
1150 set_gdbarch_dummy_id (gdbarch
, moxie_dummy_id
);
1152 set_gdbarch_unwind_pc (gdbarch
, moxie_unwind_pc
);
1154 set_gdbarch_print_insn (gdbarch
, print_insn_moxie
);
1156 /* Hook in ABI-specific overrides, if they have been registered. */
1157 gdbarch_init_osabi (info
, gdbarch
);
1159 /* Hook in the default unwinders. */
1160 frame_unwind_append_unwinder (gdbarch
, &moxie_frame_unwind
);
1162 /* Single stepping. */
1163 set_gdbarch_software_single_step (gdbarch
, moxie_software_single_step
);
1165 /* Support simple overlay manager. */
1166 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
1168 /* Support reverse debugging. */
1169 set_gdbarch_process_record (gdbarch
, moxie_process_record
);
1174 /* Register this machine's init routine. */
1177 _initialize_moxie_tdep (void)
1179 register_gdbarch_init (bfd_arch_moxie
, moxie_gdbarch_init
);