1 /* Target-dependent code for Moxie.
3 Copyright (C) 2009-2017 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 constexpr gdb_byte moxie_break_insn[] = { 0x35, 0x00 };
73 typedef BP_MANIPULATION (moxie_break_insn) moxie_breakpoint;
75 /* Moxie register names. */
77 static const char *moxie_register_names[] = {
78 "$fp", "$sp", "$r0", "$r1", "$r2",
79 "$r3", "$r4", "$r5", "$r6", "$r7",
80 "$r8", "$r9", "$r10", "$r11", "$r12",
81 "$r13", "$pc", "$cc" };
83 /* Implement the "register_name" gdbarch method. */
86 moxie_register_name (struct gdbarch *gdbarch, int reg_nr)
90 if (reg_nr >= MOXIE_NUM_REGS)
92 return moxie_register_names[reg_nr];
95 /* Implement the "register_type" gdbarch method. */
98 moxie_register_type (struct gdbarch *gdbarch, int reg_nr)
100 if (reg_nr == MOXIE_PC_REGNUM)
101 return builtin_type (gdbarch)->builtin_func_ptr;
102 else if (reg_nr == MOXIE_SP_REGNUM || reg_nr == MOXIE_FP_REGNUM)
103 return builtin_type (gdbarch)->builtin_data_ptr;
105 return builtin_type (gdbarch)->builtin_int32;
108 /* Write into appropriate registers a function return value
109 of type TYPE, given in virtual format. */
112 moxie_store_return_value (struct type *type, struct regcache *regcache,
113 const gdb_byte *valbuf)
115 struct gdbarch *gdbarch = get_regcache_arch (regcache);
116 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
118 int len = TYPE_LENGTH (type);
120 /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
121 regval = extract_unsigned_integer (valbuf, len > 4 ? 4 : len, byte_order);
122 regcache_cooked_write_unsigned (regcache, RET1_REGNUM, regval);
125 regval = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
126 regcache_cooked_write_unsigned (regcache, RET1_REGNUM + 1, regval);
130 /* Decode the instructions within the given address range. Decide
131 when we must have reached the end of the function prologue. If a
132 frame_info pointer is provided, fill in its saved_regs etc.
134 Returns the address of the first instruction after the prologue. */
137 moxie_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr,
138 struct moxie_frame_cache *cache,
139 struct gdbarch *gdbarch)
141 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
143 ULONGEST inst, inst2;
147 /* Record where the jsra instruction saves the PC and FP. */
148 cache->saved_regs[MOXIE_PC_REGNUM] = -4;
149 cache->saved_regs[MOXIE_FP_REGNUM] = 0;
150 cache->framesize = 0;
152 if (start_addr >= end_addr)
155 for (next_addr = start_addr; next_addr < end_addr; )
157 inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
159 /* Match "push $sp $rN" where N is between 0 and 13 inclusive. */
160 if (inst >= 0x0612 && inst <= 0x061f)
162 regnum = inst & 0x000f;
163 cache->framesize += 4;
164 cache->saved_regs[regnum] = cache->framesize;
171 inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
173 /* Optional stack allocation for args and local vars <= 4
175 if (inst == 0x01e0) /* ldi.l $r12, X */
177 offset = read_memory_integer (next_addr + 2, 4, byte_order);
178 inst2 = read_memory_unsigned_integer (next_addr + 6, 2, byte_order);
180 if (inst2 == 0x291e) /* sub.l $sp, $r12 */
182 cache->framesize += offset;
185 return (next_addr + 8);
187 else if ((inst & 0xff00) == 0x9100) /* dec $sp, X */
189 cache->framesize += (inst & 0x00ff);
192 while (next_addr < end_addr)
194 inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
195 if ((inst & 0xff00) != 0x9100) /* no more dec $sp, X */
197 cache->framesize += (inst & 0x00ff);
205 /* Find the end of function prologue. */
208 moxie_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
210 CORE_ADDR func_addr = 0, func_end = 0;
211 const char *func_name;
213 /* See if we can determine the end of the prologue via the symbol table.
214 If so, then return either PC, or the PC after the prologue, whichever
216 if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end))
218 CORE_ADDR post_prologue_pc
219 = skip_prologue_using_sal (gdbarch, func_addr);
220 if (post_prologue_pc != 0)
221 return std::max (pc, post_prologue_pc);
224 /* Can't determine prologue from the symbol table, need to examine
226 struct symtab_and_line sal;
228 struct moxie_frame_cache cache;
231 memset (&cache, 0, sizeof cache);
233 plg_end = moxie_analyze_prologue (func_addr,
234 func_end, &cache, gdbarch);
235 /* Found a function. */
236 sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
237 /* Don't use line number debug info for assembly source
239 if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
241 sal = find_pc_line (func_addr, 0);
242 if (sal.end && sal.end < func_end)
244 /* Found a line number, use it as end of
249 /* No useable line symbol. Use result of prologue parsing
255 /* No function symbol -- just return the PC. */
256 return (CORE_ADDR) pc;
259 struct moxie_unwind_cache
261 /* The previous frame's inner most stack address. Used as this
262 frame ID's stack_addr. */
264 /* The frame's base, optionally used by the high-level debug info. */
267 /* How far the SP and r13 (FP) have been offset from the start of
268 the stack frame (as defined by the previous frame's stack
273 /* Table indicating the location of each and every register. */
274 struct trad_frame_saved_reg *saved_regs;
277 /* Read an unsigned integer from the inferior, and adjust
280 moxie_process_readu (CORE_ADDR addr, gdb_byte *buf,
281 int length, enum bfd_endian byte_order)
283 if (target_read_memory (addr, buf, length))
286 printf_unfiltered (_("Process record: error reading memory at "
287 "addr 0x%s len = %d.\n"),
288 paddress (target_gdbarch (), addr), length);
292 return extract_unsigned_integer (buf, length, byte_order);
296 /* Helper macro to extract the signed 10-bit offset from a 16-bit
297 branch instruction. */
298 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
300 /* Insert a single step breakpoint. */
302 static std::vector<CORE_ADDR>
303 moxie_software_single_step (struct regcache *regcache)
305 struct gdbarch *gdbarch = get_regcache_arch (regcache);
311 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
312 std::vector<CORE_ADDR> next_pcs;
314 addr = regcache_read_pc (regcache);
316 inst = (uint16_t) moxie_process_readu (addr, buf, 2, byte_order);
318 /* Decode instruction. */
319 if (inst & (1 << 15))
321 if (inst & (1 << 14))
323 /* This is a Form 3 instruction. */
324 int opcode = (inst >> 10 & 0xf);
332 case 0x04: /* bltu */
333 case 0x05: /* bgtu */
336 case 0x08: /* bgeu */
337 case 0x09: /* bleu */
338 /* Insert breaks on both branches, because we can't currently tell
339 which way things will go. */
340 next_pcs.push_back (addr + 2);
341 next_pcs.push_back (addr + 2 + INST2OFFSET(inst));
352 /* This is a Form 2 instruction. They are all 16 bits. */
353 next_pcs.push_back (addr + 2);
358 /* This is a Form 1 instruction. */
359 int opcode = inst >> 8;
363 /* 16-bit instructions. */
365 case 0x02: /* mov (register-to-register) */
366 case 0x05: /* add.l */
367 case 0x06: /* push */
369 case 0x0a: /* ld.l (register indirect) */
370 case 0x0b: /* st.l */
373 case 0x10: /* sex.b */
374 case 0x11: /* sex.s */
375 case 0x12: /* zex.b */
376 case 0x13: /* zex.s */
377 case 0x14: /* umul.x */
378 case 0x15: /* mul.x */
382 case 0x1c: /* ld.b (register indirect) */
383 case 0x1e: /* st.b */
384 case 0x21: /* ld.s (register indirect) */
385 case 0x23: /* st.s */
387 case 0x27: /* lshr */
388 case 0x28: /* ashl */
389 case 0x29: /* sub.l */
393 case 0x2d: /* ashr */
395 case 0x2f: /* mul.l */
396 case 0x31: /* div.l */
397 case 0x32: /* udiv.l */
398 case 0x33: /* mod.l */
399 case 0x34: /* umod.l */
400 next_pcs.push_back (addr + 2);
403 /* 32-bit instructions. */
404 case 0x0c: /* ldo.l */
405 case 0x0d: /* sto.l */
406 case 0x36: /* ldo.b */
407 case 0x37: /* sto.b */
408 case 0x38: /* ldo.s */
409 case 0x39: /* sto.s */
410 next_pcs.push_back (addr + 4);
413 /* 48-bit instructions. */
414 case 0x01: /* ldi.l (immediate) */
415 case 0x08: /* lda.l */
416 case 0x09: /* sta.l */
417 case 0x1b: /* ldi.b (immediate) */
418 case 0x1d: /* lda.b */
419 case 0x1f: /* sta.b */
420 case 0x20: /* ldi.s (immediate) */
421 case 0x22: /* lda.s */
422 case 0x24: /* sta.s */
423 next_pcs.push_back (addr + 6);
426 /* Control flow instructions. */
427 case 0x03: /* jsra */
428 case 0x1a: /* jmpa */
429 next_pcs.push_back (moxie_process_readu (addr + 2, buf, 4,
434 regcache_cooked_read_unsigned (regcache, MOXIE_FP_REGNUM, &fp);
435 next_pcs.push_back (moxie_process_readu (fp + 4, buf, 4, byte_order));
440 regcache_raw_read (regcache,
441 (inst >> 4) & 0xf, (gdb_byte *) & tmpu32);
442 next_pcs.push_back (tmpu32);
447 /* Unsupported, for now. */
455 /* Implement the "read_pc" gdbarch method. */
458 moxie_read_pc (struct regcache *regcache)
462 regcache_cooked_read_unsigned (regcache, MOXIE_PC_REGNUM, &pc);
466 /* Implement the "write_pc" gdbarch method. */
469 moxie_write_pc (struct regcache *regcache, CORE_ADDR val)
471 regcache_cooked_write_unsigned (regcache, MOXIE_PC_REGNUM, val);
474 /* Implement the "unwind_sp" gdbarch method. */
477 moxie_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
479 return frame_unwind_register_unsigned (next_frame, MOXIE_SP_REGNUM);
482 /* Given a return value in `regbuf' with a type `valtype',
483 extract and copy its value into `valbuf'. */
486 moxie_extract_return_value (struct type *type, struct regcache *regcache,
489 struct gdbarch *gdbarch = get_regcache_arch (regcache);
490 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
491 int len = TYPE_LENGTH (type);
494 /* By using store_unsigned_integer we avoid having to do
495 anything special for small big-endian values. */
496 regcache_cooked_read_unsigned (regcache, RET1_REGNUM, &tmp);
497 store_unsigned_integer (dst, (len > 4 ? len - 4 : len), byte_order, tmp);
499 /* Ignore return values more than 8 bytes in size because the moxie
500 returns anything more than 8 bytes in the stack. */
503 regcache_cooked_read_unsigned (regcache, RET1_REGNUM + 1, &tmp);
504 store_unsigned_integer (dst + len - 4, 4, byte_order, tmp);
508 /* Implement the "return_value" gdbarch method. */
510 static enum return_value_convention
511 moxie_return_value (struct gdbarch *gdbarch, struct value *function,
512 struct type *valtype, struct regcache *regcache,
513 gdb_byte *readbuf, const gdb_byte *writebuf)
515 if (TYPE_LENGTH (valtype) > 8)
516 return RETURN_VALUE_STRUCT_CONVENTION;
520 moxie_extract_return_value (valtype, regcache, readbuf);
521 if (writebuf != NULL)
522 moxie_store_return_value (valtype, regcache, writebuf);
523 return RETURN_VALUE_REGISTER_CONVENTION;
527 /* Allocate and initialize a moxie_frame_cache object. */
529 static struct moxie_frame_cache *
530 moxie_alloc_frame_cache (void)
532 struct moxie_frame_cache *cache;
535 cache = FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache);
540 cache->framesize = 0;
541 for (i = 0; i < MOXIE_NUM_REGS; ++i)
542 cache->saved_regs[i] = REG_UNAVAIL;
547 /* Populate a moxie_frame_cache object for this_frame. */
549 static struct moxie_frame_cache *
550 moxie_frame_cache (struct frame_info *this_frame, void **this_cache)
552 struct moxie_frame_cache *cache;
553 CORE_ADDR current_pc;
557 return (struct moxie_frame_cache *) *this_cache;
559 cache = moxie_alloc_frame_cache ();
562 cache->base = get_frame_register_unsigned (this_frame, MOXIE_FP_REGNUM);
563 if (cache->base == 0)
566 cache->pc = get_frame_func (this_frame);
567 current_pc = get_frame_pc (this_frame);
570 struct gdbarch *gdbarch = get_frame_arch (this_frame);
571 moxie_analyze_prologue (cache->pc, current_pc, cache, gdbarch);
574 cache->saved_sp = cache->base - cache->framesize;
576 for (i = 0; i < MOXIE_NUM_REGS; ++i)
577 if (cache->saved_regs[i] != REG_UNAVAIL)
578 cache->saved_regs[i] = cache->base - cache->saved_regs[i];
583 /* Implement the "unwind_pc" gdbarch method. */
586 moxie_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
588 return frame_unwind_register_unsigned (next_frame, MOXIE_PC_REGNUM);
591 /* Given a GDB frame, determine the address of the calling function's
592 frame. This will be used to create a new GDB frame struct. */
595 moxie_frame_this_id (struct frame_info *this_frame,
596 void **this_prologue_cache, struct frame_id *this_id)
598 struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
599 this_prologue_cache);
601 /* This marks the outermost frame. */
602 if (cache->base == 0)
605 *this_id = frame_id_build (cache->saved_sp, cache->pc);
608 /* Get the value of register regnum in the previous stack frame. */
610 static struct value *
611 moxie_frame_prev_register (struct frame_info *this_frame,
612 void **this_prologue_cache, int regnum)
614 struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
615 this_prologue_cache);
617 gdb_assert (regnum >= 0);
619 if (regnum == MOXIE_SP_REGNUM && cache->saved_sp)
620 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
622 if (regnum < MOXIE_NUM_REGS && cache->saved_regs[regnum] != REG_UNAVAIL)
623 return frame_unwind_got_memory (this_frame, regnum,
624 cache->saved_regs[regnum]);
626 return frame_unwind_got_register (this_frame, regnum, regnum);
629 static const struct frame_unwind moxie_frame_unwind = {
631 default_frame_unwind_stop_reason,
633 moxie_frame_prev_register,
635 default_frame_sniffer
638 /* Return the base address of this_frame. */
641 moxie_frame_base_address (struct frame_info *this_frame, void **this_cache)
643 struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
649 static const struct frame_base moxie_frame_base = {
651 moxie_frame_base_address,
652 moxie_frame_base_address,
653 moxie_frame_base_address
656 static struct frame_id
657 moxie_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
659 CORE_ADDR sp = get_frame_register_unsigned (this_frame, MOXIE_SP_REGNUM);
661 return frame_id_build (sp, get_frame_pc (this_frame));
664 /* Parse the current instruction and record the values of the registers and
665 memory that will be changed in current instruction to "record_arch_list".
666 Return -1 if something wrong. */
669 moxie_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
675 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
677 if (record_debug > 1)
678 fprintf_unfiltered (gdb_stdlog, "Process record: moxie_process_record "
680 paddress (target_gdbarch (), addr));
682 inst = (uint16_t) moxie_process_readu (addr, buf, 2, byte_order);
684 /* Decode instruction. */
685 if (inst & (1 << 15))
687 if (inst & (1 << 14))
689 /* This is a Form 3 instruction. */
690 int opcode = (inst >> 10 & 0xf);
698 case 0x04: /* bltu */
699 case 0x05: /* bgtu */
702 case 0x08: /* bgeu */
703 case 0x09: /* bleu */
715 /* This is a Form 2 instruction. */
716 int opcode = (inst >> 12 & 0x3);
723 int reg = (inst >> 8) & 0xf;
724 if (record_full_arch_list_add_reg (regcache, reg))
730 /* Do nothing until GDB learns about moxie's special
742 /* This is a Form 1 instruction. */
743 int opcode = inst >> 8;
750 case 0x01: /* ldi.l (immediate) */
751 case 0x02: /* mov (register-to-register) */
753 int reg = (inst >> 4) & 0xf;
754 if (record_full_arch_list_add_reg (regcache, reg))
758 case 0x03: /* jsra */
760 regcache_raw_read (regcache,
761 MOXIE_SP_REGNUM, (gdb_byte *) & tmpu32);
762 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
764 if (record_full_arch_list_add_reg (regcache, MOXIE_FP_REGNUM)
765 || (record_full_arch_list_add_reg (regcache,
767 || record_full_arch_list_add_mem (tmpu32 - 12, 12))
773 if (record_full_arch_list_add_reg (regcache, MOXIE_FP_REGNUM)
774 || (record_full_arch_list_add_reg (regcache,
779 case 0x05: /* add.l */
781 int reg = (inst >> 4) & 0xf;
782 if (record_full_arch_list_add_reg (regcache, reg))
786 case 0x06: /* push */
788 int reg = (inst >> 4) & 0xf;
789 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
790 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
792 if (record_full_arch_list_add_reg (regcache, reg)
793 || record_full_arch_list_add_mem (tmpu32 - 4, 4))
799 int a = (inst >> 4) & 0xf;
801 if (record_full_arch_list_add_reg (regcache, a)
802 || record_full_arch_list_add_reg (regcache, b))
806 case 0x08: /* lda.l */
808 int reg = (inst >> 4) & 0xf;
809 if (record_full_arch_list_add_reg (regcache, reg))
813 case 0x09: /* sta.l */
815 tmpu32 = (uint32_t) moxie_process_readu (addr+2, buf,
817 if (record_full_arch_list_add_mem (tmpu32, 4))
821 case 0x0a: /* ld.l (register indirect) */
823 int reg = (inst >> 4) & 0xf;
824 if (record_full_arch_list_add_reg (regcache, reg))
828 case 0x0b: /* st.l */
830 int reg = (inst >> 4) & 0xf;
831 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
832 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
834 if (record_full_arch_list_add_mem (tmpu32, 4))
838 case 0x0c: /* ldo.l */
840 int reg = (inst >> 4) & 0xf;
841 if (record_full_arch_list_add_reg (regcache, reg))
845 case 0x0d: /* sto.l */
847 int reg = (inst >> 4) & 0xf;
848 uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
849 byte_order)) << 16 ) >> 16;
850 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
851 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
854 if (record_full_arch_list_add_mem (tmpu32, 4))
860 if (record_full_arch_list_add_reg (regcache, MOXIE_CC_REGNUM))
869 case 0x10: /* sex.b */
870 case 0x11: /* sex.s */
871 case 0x12: /* zex.b */
872 case 0x13: /* zex.s */
873 case 0x14: /* umul.x */
874 case 0x15: /* mul.x */
876 int reg = (inst >> 4) & 0xf;
877 if (record_full_arch_list_add_reg (regcache, reg))
890 regcache_raw_read (regcache,
891 MOXIE_SP_REGNUM, (gdb_byte *) & tmpu32);
892 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
894 if (record_full_arch_list_add_reg (regcache, MOXIE_FP_REGNUM)
895 || (record_full_arch_list_add_reg (regcache,
897 || record_full_arch_list_add_mem (tmpu32 - 12, 12))
901 case 0x1a: /* jmpa */
906 case 0x1b: /* ldi.b (immediate) */
907 case 0x1c: /* ld.b (register indirect) */
908 case 0x1d: /* lda.b */
910 int reg = (inst >> 4) & 0xf;
911 if (record_full_arch_list_add_reg (regcache, reg))
915 case 0x1e: /* st.b */
917 int reg = (inst >> 4) & 0xf;
918 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
919 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
921 if (record_full_arch_list_add_mem (tmpu32, 1))
925 case 0x1f: /* sta.b */
927 tmpu32 = moxie_process_readu (addr+2, buf, 4, byte_order);
928 if (record_full_arch_list_add_mem (tmpu32, 1))
932 case 0x20: /* ldi.s (immediate) */
933 case 0x21: /* ld.s (register indirect) */
934 case 0x22: /* lda.s */
936 int reg = (inst >> 4) & 0xf;
937 if (record_full_arch_list_add_reg (regcache, reg))
941 case 0x23: /* st.s */
943 int reg = (inst >> 4) & 0xf;
944 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
945 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
947 if (record_full_arch_list_add_mem (tmpu32, 2))
951 case 0x24: /* sta.s */
953 tmpu32 = moxie_process_readu (addr+2, buf, 4, byte_order);
954 if (record_full_arch_list_add_mem (tmpu32, 2))
964 case 0x27: /* lshr */
965 case 0x28: /* ashl */
970 case 0x2d: /* ashr */
974 int reg = (inst >> 4) & 0xf;
975 if (record_full_arch_list_add_reg (regcache, reg))
981 /* We currently implement support for libgloss'
984 int inum = moxie_process_readu (addr+2, buf, 4, byte_order);
988 case 0x1: /* SYS_exit */
993 case 0x2: /* SYS_open */
995 if (record_full_arch_list_add_reg (regcache, RET1_REGNUM))
999 case 0x4: /* SYS_read */
1001 uint32_t length, ptr;
1003 /* Read buffer pointer is in $r1. */
1004 regcache_raw_read (regcache, 3, (gdb_byte *) & ptr);
1005 ptr = extract_unsigned_integer ((gdb_byte *) & ptr,
1008 /* String length is at 0x12($fp). */
1009 regcache_raw_read (regcache,
1010 MOXIE_FP_REGNUM, (gdb_byte *) & tmpu32);
1011 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1013 length = moxie_process_readu (tmpu32+20, buf, 4, byte_order);
1015 if (record_full_arch_list_add_mem (ptr, length))
1019 case 0x5: /* SYS_write */
1021 if (record_full_arch_list_add_reg (regcache, RET1_REGNUM))
1030 case 0x31: /* div.l */
1031 case 0x32: /* udiv.l */
1032 case 0x33: /* mod.l */
1033 case 0x34: /* umod.l */
1035 int reg = (inst >> 4) & 0xf;
1036 if (record_full_arch_list_add_reg (regcache, reg))
1040 case 0x35: /* brk */
1043 case 0x36: /* ldo.b */
1045 int reg = (inst >> 4) & 0xf;
1046 if (record_full_arch_list_add_reg (regcache, reg))
1050 case 0x37: /* sto.b */
1052 int reg = (inst >> 4) & 0xf;
1053 uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
1054 byte_order)) << 16 ) >> 16;
1055 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
1056 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1059 if (record_full_arch_list_add_mem (tmpu32, 1))
1063 case 0x38: /* ldo.s */
1065 int reg = (inst >> 4) & 0xf;
1066 if (record_full_arch_list_add_reg (regcache, reg))
1070 case 0x39: /* sto.s */
1072 int reg = (inst >> 4) & 0xf;
1073 uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
1074 byte_order)) << 16 ) >> 16;
1075 regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
1076 tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1079 if (record_full_arch_list_add_mem (tmpu32, 2))
1089 if (record_full_arch_list_add_reg (regcache, MOXIE_PC_REGNUM))
1091 if (record_full_arch_list_add_end ())
1096 /* Allocate and initialize the moxie gdbarch object. */
1098 static struct gdbarch *
1099 moxie_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1101 struct gdbarch *gdbarch;
1102 struct gdbarch_tdep *tdep;
1104 /* If there is already a candidate, use it. */
1105 arches = gdbarch_list_lookup_by_info (arches, &info);
1107 return arches->gdbarch;
1109 /* Allocate space for the new architecture. */
1110 tdep = XCNEW (struct gdbarch_tdep);
1111 gdbarch = gdbarch_alloc (&info, tdep);
1113 set_gdbarch_wchar_bit (gdbarch, 32);
1114 set_gdbarch_wchar_signed (gdbarch, 0);
1116 set_gdbarch_read_pc (gdbarch, moxie_read_pc);
1117 set_gdbarch_write_pc (gdbarch, moxie_write_pc);
1118 set_gdbarch_unwind_sp (gdbarch, moxie_unwind_sp);
1120 set_gdbarch_num_regs (gdbarch, MOXIE_NUM_REGS);
1121 set_gdbarch_sp_regnum (gdbarch, MOXIE_SP_REGNUM);
1122 set_gdbarch_pc_regnum (gdbarch, MOXIE_PC_REGNUM);
1123 set_gdbarch_register_name (gdbarch, moxie_register_name);
1124 set_gdbarch_register_type (gdbarch, moxie_register_type);
1126 set_gdbarch_return_value (gdbarch, moxie_return_value);
1128 set_gdbarch_skip_prologue (gdbarch, moxie_skip_prologue);
1129 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1130 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
1131 moxie_breakpoint::kind_from_pc);
1132 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
1133 moxie_breakpoint::bp_from_kind);
1134 set_gdbarch_frame_align (gdbarch, moxie_frame_align);
1136 frame_base_set_default (gdbarch, &moxie_frame_base);
1138 /* Methods for saving / extracting a dummy frame's ID. The ID's
1139 stack address must match the SP value returned by
1140 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
1141 set_gdbarch_dummy_id (gdbarch, moxie_dummy_id);
1143 set_gdbarch_unwind_pc (gdbarch, moxie_unwind_pc);
1145 /* Hook in ABI-specific overrides, if they have been registered. */
1146 gdbarch_init_osabi (info, gdbarch);
1148 /* Hook in the default unwinders. */
1149 frame_unwind_append_unwinder (gdbarch, &moxie_frame_unwind);
1151 /* Single stepping. */
1152 set_gdbarch_software_single_step (gdbarch, moxie_software_single_step);
1154 /* Support simple overlay manager. */
1155 set_gdbarch_overlay_update (gdbarch, simple_overlay_update);
1157 /* Support reverse debugging. */
1158 set_gdbarch_process_record (gdbarch, moxie_process_record);
1163 /* Register this machine's init routine. */
1166 _initialize_moxie_tdep (void)
1168 register_gdbarch_init (bfd_arch_moxie, moxie_gdbarch_init);