1 /* Target-dependent code for Moxie.
3 Copyright (C) 2009-2021 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 /* Use an invalid address value as 'not available' marker. */
45 enum { REG_UNAVAIL
= (CORE_ADDR
) -1 };
47 struct moxie_frame_cache
53 CORE_ADDR saved_regs
[MOXIE_NUM_REGS
];
57 /* Implement the "frame_align" gdbarch method. */
60 moxie_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
62 /* Align to the size of an instruction (so that they can safely be
63 pushed onto the stack. */
67 constexpr gdb_byte moxie_break_insn
[] = { 0x35, 0x00 };
69 typedef BP_MANIPULATION (moxie_break_insn
) moxie_breakpoint
;
71 /* Moxie register names. */
73 static const char * const moxie_register_names
[] = {
74 "$fp", "$sp", "$r0", "$r1", "$r2",
75 "$r3", "$r4", "$r5", "$r6", "$r7",
76 "$r8", "$r9", "$r10", "$r11", "$r12",
77 "$r13", "$pc", "$cc" };
79 /* Implement the "register_name" gdbarch method. */
82 moxie_register_name (struct gdbarch
*gdbarch
, int reg_nr
)
86 if (reg_nr
>= MOXIE_NUM_REGS
)
88 return moxie_register_names
[reg_nr
];
91 /* Implement the "register_type" gdbarch method. */
94 moxie_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
96 if (reg_nr
== MOXIE_PC_REGNUM
)
97 return builtin_type (gdbarch
)->builtin_func_ptr
;
98 else if (reg_nr
== MOXIE_SP_REGNUM
|| reg_nr
== MOXIE_FP_REGNUM
)
99 return builtin_type (gdbarch
)->builtin_data_ptr
;
101 return builtin_type (gdbarch
)->builtin_int32
;
104 /* Write into appropriate registers a function return value
105 of type TYPE, given in virtual format. */
108 moxie_store_return_value (struct type
*type
, struct regcache
*regcache
,
109 const gdb_byte
*valbuf
)
111 struct gdbarch
*gdbarch
= regcache
->arch ();
112 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
114 int len
= TYPE_LENGTH (type
);
116 /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
117 regval
= extract_unsigned_integer (valbuf
, len
> 4 ? 4 : len
, byte_order
);
118 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
, regval
);
121 regval
= extract_unsigned_integer (valbuf
+ 4, len
- 4, byte_order
);
122 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
+ 1, regval
);
126 /* Decode the instructions within the given address range. Decide
127 when we must have reached the end of the function prologue. If a
128 frame_info pointer is provided, fill in its saved_regs etc.
130 Returns the address of the first instruction after the prologue. */
133 moxie_analyze_prologue (CORE_ADDR start_addr
, CORE_ADDR end_addr
,
134 struct moxie_frame_cache
*cache
,
135 struct gdbarch
*gdbarch
)
137 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
139 ULONGEST inst
, inst2
;
143 /* Record where the jsra instruction saves the PC and FP. */
144 cache
->saved_regs
[MOXIE_PC_REGNUM
] = -4;
145 cache
->saved_regs
[MOXIE_FP_REGNUM
] = 0;
146 cache
->framesize
= 0;
148 if (start_addr
>= end_addr
)
151 for (next_addr
= start_addr
; next_addr
< end_addr
; )
153 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
155 /* Match "push $sp $rN" where N is between 0 and 13 inclusive. */
156 if (inst
>= 0x0612 && inst
<= 0x061f)
158 regnum
= inst
& 0x000f;
159 cache
->framesize
+= 4;
160 cache
->saved_regs
[regnum
] = cache
->framesize
;
167 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
169 /* Optional stack allocation for args and local vars <= 4
171 if (inst
== 0x01e0) /* ldi.l $r12, X */
173 offset
= read_memory_integer (next_addr
+ 2, 4, byte_order
);
174 inst2
= read_memory_unsigned_integer (next_addr
+ 6, 2, byte_order
);
176 if (inst2
== 0x291e) /* sub.l $sp, $r12 */
178 cache
->framesize
+= offset
;
181 return (next_addr
+ 8);
183 else if ((inst
& 0xff00) == 0x9100) /* dec $sp, X */
185 cache
->framesize
+= (inst
& 0x00ff);
188 while (next_addr
< end_addr
)
190 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
191 if ((inst
& 0xff00) != 0x9100) /* no more dec $sp, X */
193 cache
->framesize
+= (inst
& 0x00ff);
201 /* Find the end of function prologue. */
204 moxie_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
206 CORE_ADDR func_addr
= 0, func_end
= 0;
207 const char *func_name
;
209 /* See if we can determine the end of the prologue via the symbol table.
210 If so, then return either PC, or the PC after the prologue, whichever
212 if (find_pc_partial_function (pc
, &func_name
, &func_addr
, &func_end
))
214 CORE_ADDR post_prologue_pc
215 = skip_prologue_using_sal (gdbarch
, func_addr
);
216 if (post_prologue_pc
!= 0)
217 return std::max (pc
, post_prologue_pc
);
220 /* Can't determine prologue from the symbol table, need to examine
222 struct symtab_and_line sal
;
224 struct moxie_frame_cache cache
;
227 memset (&cache
, 0, sizeof cache
);
229 plg_end
= moxie_analyze_prologue (func_addr
,
230 func_end
, &cache
, gdbarch
);
231 /* Found a function. */
232 sym
= lookup_symbol (func_name
, NULL
, VAR_DOMAIN
, NULL
).symbol
;
233 /* Don't use line number debug info for assembly source
235 if (sym
&& sym
->language () != language_asm
)
237 sal
= find_pc_line (func_addr
, 0);
238 if (sal
.end
&& sal
.end
< func_end
)
240 /* Found a line number, use it as end of
245 /* No useable line symbol. Use result of prologue parsing
251 /* No function symbol -- just return the PC. */
252 return (CORE_ADDR
) pc
;
255 struct moxie_unwind_cache
257 /* The previous frame's inner most stack address. Used as this
258 frame ID's stack_addr. */
260 /* The frame's base, optionally used by the high-level debug info. */
263 /* How far the SP and r13 (FP) have been offset from the start of
264 the stack frame (as defined by the previous frame's stack
269 /* Table indicating the location of each and every register. */
270 trad_frame_saved_reg
*saved_regs
;
273 /* Read an unsigned integer from the inferior, and adjust
276 moxie_process_readu (CORE_ADDR addr
, gdb_byte
*buf
,
277 int length
, enum bfd_endian byte_order
)
279 if (target_read_memory (addr
, buf
, length
))
282 printf_unfiltered (_("Process record: error reading memory at "
283 "addr 0x%s len = %d.\n"),
284 paddress (target_gdbarch (), addr
), length
);
288 return extract_unsigned_integer (buf
, length
, byte_order
);
292 /* Helper macro to extract the signed 10-bit offset from a 16-bit
293 branch instruction. */
294 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
296 /* Insert a single step breakpoint. */
298 static std::vector
<CORE_ADDR
>
299 moxie_software_single_step (struct regcache
*regcache
)
301 struct gdbarch
*gdbarch
= regcache
->arch ();
307 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
308 std::vector
<CORE_ADDR
> next_pcs
;
310 addr
= regcache_read_pc (regcache
);
312 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
314 /* Decode instruction. */
315 if (inst
& (1 << 15))
317 if (inst
& (1 << 14))
319 /* This is a Form 3 instruction. */
320 int opcode
= (inst
>> 10 & 0xf);
328 case 0x04: /* bltu */
329 case 0x05: /* bgtu */
332 case 0x08: /* bgeu */
333 case 0x09: /* bleu */
334 /* Insert breaks on both branches, because we can't currently tell
335 which way things will go. */
336 next_pcs
.push_back (addr
+ 2);
337 next_pcs
.push_back (addr
+ 2 + INST2OFFSET(inst
));
348 /* This is a Form 2 instruction. They are all 16 bits. */
349 next_pcs
.push_back (addr
+ 2);
354 /* This is a Form 1 instruction. */
355 int opcode
= inst
>> 8;
359 /* 16-bit instructions. */
361 case 0x02: /* mov (register-to-register) */
362 case 0x05: /* add.l */
363 case 0x06: /* push */
365 case 0x0a: /* ld.l (register indirect) */
366 case 0x0b: /* st.l */
369 case 0x10: /* sex.b */
370 case 0x11: /* sex.s */
371 case 0x12: /* zex.b */
372 case 0x13: /* zex.s */
373 case 0x14: /* umul.x */
374 case 0x15: /* mul.x */
378 case 0x1c: /* ld.b (register indirect) */
379 case 0x1e: /* st.b */
380 case 0x21: /* ld.s (register indirect) */
381 case 0x23: /* st.s */
383 case 0x27: /* lshr */
384 case 0x28: /* ashl */
385 case 0x29: /* sub.l */
389 case 0x2d: /* ashr */
391 case 0x2f: /* mul.l */
392 case 0x31: /* div.l */
393 case 0x32: /* udiv.l */
394 case 0x33: /* mod.l */
395 case 0x34: /* umod.l */
396 next_pcs
.push_back (addr
+ 2);
399 /* 32-bit instructions. */
400 case 0x0c: /* ldo.l */
401 case 0x0d: /* sto.l */
402 case 0x36: /* ldo.b */
403 case 0x37: /* sto.b */
404 case 0x38: /* ldo.s */
405 case 0x39: /* sto.s */
406 next_pcs
.push_back (addr
+ 4);
409 /* 48-bit instructions. */
410 case 0x01: /* ldi.l (immediate) */
411 case 0x08: /* lda.l */
412 case 0x09: /* sta.l */
413 case 0x1b: /* ldi.b (immediate) */
414 case 0x1d: /* lda.b */
415 case 0x1f: /* sta.b */
416 case 0x20: /* ldi.s (immediate) */
417 case 0x22: /* lda.s */
418 case 0x24: /* sta.s */
419 next_pcs
.push_back (addr
+ 6);
422 /* Control flow instructions. */
423 case 0x03: /* jsra */
424 case 0x1a: /* jmpa */
425 next_pcs
.push_back (moxie_process_readu (addr
+ 2, buf
, 4,
430 regcache_cooked_read_unsigned (regcache
, MOXIE_FP_REGNUM
, &fp
);
431 next_pcs
.push_back (moxie_process_readu (fp
+ 4, buf
, 4, byte_order
));
436 regcache
->raw_read ((inst
>> 4) & 0xf, (gdb_byte
*) & tmpu32
);
437 next_pcs
.push_back (tmpu32
);
442 /* Unsupported, for now. */
450 /* Given a return value in `regbuf' with a type `valtype',
451 extract and copy its value into `valbuf'. */
454 moxie_extract_return_value (struct type
*type
, struct regcache
*regcache
,
457 struct gdbarch
*gdbarch
= regcache
->arch ();
458 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
459 int len
= TYPE_LENGTH (type
);
462 /* By using store_unsigned_integer we avoid having to do
463 anything special for small big-endian values. */
464 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
, &tmp
);
465 store_unsigned_integer (dst
, (len
> 4 ? len
- 4 : len
), byte_order
, tmp
);
467 /* Ignore return values more than 8 bytes in size because the moxie
468 returns anything more than 8 bytes in the stack. */
471 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
+ 1, &tmp
);
472 store_unsigned_integer (dst
+ len
- 4, 4, byte_order
, tmp
);
476 /* Implement the "return_value" gdbarch method. */
478 static enum return_value_convention
479 moxie_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
480 struct type
*valtype
, struct regcache
*regcache
,
481 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
483 if (TYPE_LENGTH (valtype
) > 8)
484 return RETURN_VALUE_STRUCT_CONVENTION
;
488 moxie_extract_return_value (valtype
, regcache
, readbuf
);
489 if (writebuf
!= NULL
)
490 moxie_store_return_value (valtype
, regcache
, writebuf
);
491 return RETURN_VALUE_REGISTER_CONVENTION
;
495 /* Allocate and initialize a moxie_frame_cache object. */
497 static struct moxie_frame_cache
*
498 moxie_alloc_frame_cache (void)
500 struct moxie_frame_cache
*cache
;
503 cache
= FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache
);
508 cache
->framesize
= 0;
509 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
510 cache
->saved_regs
[i
] = REG_UNAVAIL
;
515 /* Populate a moxie_frame_cache object for this_frame. */
517 static struct moxie_frame_cache
*
518 moxie_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
520 struct moxie_frame_cache
*cache
;
521 CORE_ADDR current_pc
;
525 return (struct moxie_frame_cache
*) *this_cache
;
527 cache
= moxie_alloc_frame_cache ();
530 cache
->base
= get_frame_register_unsigned (this_frame
, MOXIE_FP_REGNUM
);
531 if (cache
->base
== 0)
534 cache
->pc
= get_frame_func (this_frame
);
535 current_pc
= get_frame_pc (this_frame
);
538 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
539 moxie_analyze_prologue (cache
->pc
, current_pc
, cache
, gdbarch
);
542 cache
->saved_sp
= cache
->base
- cache
->framesize
;
544 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
545 if (cache
->saved_regs
[i
] != REG_UNAVAIL
)
546 cache
->saved_regs
[i
] = cache
->base
- cache
->saved_regs
[i
];
551 /* Given a GDB frame, determine the address of the calling function's
552 frame. This will be used to create a new GDB frame struct. */
555 moxie_frame_this_id (struct frame_info
*this_frame
,
556 void **this_prologue_cache
, struct frame_id
*this_id
)
558 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
559 this_prologue_cache
);
561 /* This marks the outermost frame. */
562 if (cache
->base
== 0)
565 *this_id
= frame_id_build (cache
->saved_sp
, cache
->pc
);
568 /* Get the value of register regnum in the previous stack frame. */
570 static struct value
*
571 moxie_frame_prev_register (struct frame_info
*this_frame
,
572 void **this_prologue_cache
, int regnum
)
574 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
575 this_prologue_cache
);
577 gdb_assert (regnum
>= 0);
579 if (regnum
== MOXIE_SP_REGNUM
&& cache
->saved_sp
)
580 return frame_unwind_got_constant (this_frame
, regnum
, cache
->saved_sp
);
582 if (regnum
< MOXIE_NUM_REGS
&& cache
->saved_regs
[regnum
] != REG_UNAVAIL
)
583 return frame_unwind_got_memory (this_frame
, regnum
,
584 cache
->saved_regs
[regnum
]);
586 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
589 static const struct frame_unwind moxie_frame_unwind
= {
592 default_frame_unwind_stop_reason
,
594 moxie_frame_prev_register
,
596 default_frame_sniffer
599 /* Return the base address of this_frame. */
602 moxie_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
604 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
610 static const struct frame_base moxie_frame_base
= {
612 moxie_frame_base_address
,
613 moxie_frame_base_address
,
614 moxie_frame_base_address
617 /* Parse the current instruction and record the values of the registers and
618 memory that will be changed in current instruction to "record_arch_list".
619 Return -1 if something wrong. */
622 moxie_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
628 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
630 if (record_debug
> 1)
631 fprintf_unfiltered (gdb_stdlog
, "Process record: moxie_process_record "
633 paddress (target_gdbarch (), addr
));
635 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
637 /* Decode instruction. */
638 if (inst
& (1 << 15))
640 if (inst
& (1 << 14))
642 /* This is a Form 3 instruction. */
643 int opcode
= (inst
>> 10 & 0xf);
651 case 0x04: /* bltu */
652 case 0x05: /* bgtu */
655 case 0x08: /* bgeu */
656 case 0x09: /* bleu */
668 /* This is a Form 2 instruction. */
669 int opcode
= (inst
>> 12 & 0x3);
676 int reg
= (inst
>> 8) & 0xf;
677 if (record_full_arch_list_add_reg (regcache
, reg
))
683 /* Do nothing until GDB learns about moxie's special
695 /* This is a Form 1 instruction. */
696 int opcode
= inst
>> 8;
703 case 0x01: /* ldi.l (immediate) */
704 case 0x02: /* mov (register-to-register) */
706 int reg
= (inst
>> 4) & 0xf;
707 if (record_full_arch_list_add_reg (regcache
, reg
))
711 case 0x03: /* jsra */
714 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
715 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
717 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
718 || (record_full_arch_list_add_reg (regcache
,
720 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
726 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
727 || (record_full_arch_list_add_reg (regcache
,
732 case 0x05: /* add.l */
734 int reg
= (inst
>> 4) & 0xf;
735 if (record_full_arch_list_add_reg (regcache
, reg
))
739 case 0x06: /* push */
741 int reg
= (inst
>> 4) & 0xf;
742 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
743 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
745 if (record_full_arch_list_add_reg (regcache
, reg
)
746 || record_full_arch_list_add_mem (tmpu32
- 4, 4))
752 int a
= (inst
>> 4) & 0xf;
754 if (record_full_arch_list_add_reg (regcache
, a
)
755 || record_full_arch_list_add_reg (regcache
, b
))
759 case 0x08: /* lda.l */
761 int reg
= (inst
>> 4) & 0xf;
762 if (record_full_arch_list_add_reg (regcache
, reg
))
766 case 0x09: /* sta.l */
768 tmpu32
= (uint32_t) moxie_process_readu (addr
+2, buf
,
770 if (record_full_arch_list_add_mem (tmpu32
, 4))
774 case 0x0a: /* ld.l (register indirect) */
776 int reg
= (inst
>> 4) & 0xf;
777 if (record_full_arch_list_add_reg (regcache
, reg
))
781 case 0x0b: /* st.l */
783 int reg
= (inst
>> 4) & 0xf;
784 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
785 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
787 if (record_full_arch_list_add_mem (tmpu32
, 4))
791 case 0x0c: /* ldo.l */
793 int reg
= (inst
>> 4) & 0xf;
794 if (record_full_arch_list_add_reg (regcache
, reg
))
798 case 0x0d: /* sto.l */
800 int reg
= (inst
>> 4) & 0xf;
801 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
802 byte_order
)) << 16 ) >> 16;
803 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
804 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
807 if (record_full_arch_list_add_mem (tmpu32
, 4))
813 if (record_full_arch_list_add_reg (regcache
, MOXIE_CC_REGNUM
))
822 case 0x10: /* sex.b */
823 case 0x11: /* sex.s */
824 case 0x12: /* zex.b */
825 case 0x13: /* zex.s */
826 case 0x14: /* umul.x */
827 case 0x15: /* mul.x */
829 int reg
= (inst
>> 4) & 0xf;
830 if (record_full_arch_list_add_reg (regcache
, reg
))
844 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
845 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
847 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
848 || (record_full_arch_list_add_reg (regcache
,
850 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
854 case 0x1a: /* jmpa */
859 case 0x1b: /* ldi.b (immediate) */
860 case 0x1c: /* ld.b (register indirect) */
861 case 0x1d: /* lda.b */
863 int reg
= (inst
>> 4) & 0xf;
864 if (record_full_arch_list_add_reg (regcache
, reg
))
868 case 0x1e: /* st.b */
870 int reg
= (inst
>> 4) & 0xf;
871 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
872 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
874 if (record_full_arch_list_add_mem (tmpu32
, 1))
878 case 0x1f: /* sta.b */
880 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
881 if (record_full_arch_list_add_mem (tmpu32
, 1))
885 case 0x20: /* ldi.s (immediate) */
886 case 0x21: /* ld.s (register indirect) */
887 case 0x22: /* lda.s */
889 int reg
= (inst
>> 4) & 0xf;
890 if (record_full_arch_list_add_reg (regcache
, reg
))
894 case 0x23: /* st.s */
896 int reg
= (inst
>> 4) & 0xf;
897 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
898 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
900 if (record_full_arch_list_add_mem (tmpu32
, 2))
904 case 0x24: /* sta.s */
906 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
907 if (record_full_arch_list_add_mem (tmpu32
, 2))
917 case 0x27: /* lshr */
918 case 0x28: /* ashl */
923 case 0x2d: /* ashr */
927 int reg
= (inst
>> 4) & 0xf;
928 if (record_full_arch_list_add_reg (regcache
, reg
))
934 /* We currently implement support for libgloss'
937 int inum
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
941 case 0x1: /* SYS_exit */
946 case 0x2: /* SYS_open */
948 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
952 case 0x4: /* SYS_read */
954 uint32_t length
, ptr
;
956 /* Read buffer pointer is in $r1. */
957 regcache
->raw_read (3, (gdb_byte
*) & ptr
);
958 ptr
= extract_unsigned_integer ((gdb_byte
*) & ptr
,
961 /* String length is at 0x12($fp). */
963 MOXIE_FP_REGNUM
, (gdb_byte
*) & tmpu32
);
964 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
966 length
= moxie_process_readu (tmpu32
+20, buf
, 4, byte_order
);
968 if (record_full_arch_list_add_mem (ptr
, length
))
972 case 0x5: /* SYS_write */
974 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
983 case 0x31: /* div.l */
984 case 0x32: /* udiv.l */
985 case 0x33: /* mod.l */
986 case 0x34: /* umod.l */
988 int reg
= (inst
>> 4) & 0xf;
989 if (record_full_arch_list_add_reg (regcache
, reg
))
996 case 0x36: /* ldo.b */
998 int reg
= (inst
>> 4) & 0xf;
999 if (record_full_arch_list_add_reg (regcache
, reg
))
1003 case 0x37: /* sto.b */
1005 int reg
= (inst
>> 4) & 0xf;
1006 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1007 byte_order
)) << 16 ) >> 16;
1008 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
1009 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1012 if (record_full_arch_list_add_mem (tmpu32
, 1))
1016 case 0x38: /* ldo.s */
1018 int reg
= (inst
>> 4) & 0xf;
1019 if (record_full_arch_list_add_reg (regcache
, reg
))
1023 case 0x39: /* sto.s */
1025 int reg
= (inst
>> 4) & 0xf;
1026 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1027 byte_order
)) << 16 ) >> 16;
1028 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
1029 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1032 if (record_full_arch_list_add_mem (tmpu32
, 2))
1042 if (record_full_arch_list_add_reg (regcache
, MOXIE_PC_REGNUM
))
1044 if (record_full_arch_list_add_end ())
1049 /* Allocate and initialize the moxie gdbarch object. */
1051 static struct gdbarch
*
1052 moxie_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1054 struct gdbarch
*gdbarch
;
1055 struct gdbarch_tdep
*tdep
;
1057 /* If there is already a candidate, use it. */
1058 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1060 return arches
->gdbarch
;
1062 /* Allocate space for the new architecture. */
1063 tdep
= XCNEW (struct gdbarch_tdep
);
1064 gdbarch
= gdbarch_alloc (&info
, tdep
);
1066 set_gdbarch_wchar_bit (gdbarch
, 32);
1067 set_gdbarch_wchar_signed (gdbarch
, 0);
1069 set_gdbarch_num_regs (gdbarch
, MOXIE_NUM_REGS
);
1070 set_gdbarch_sp_regnum (gdbarch
, MOXIE_SP_REGNUM
);
1071 set_gdbarch_pc_regnum (gdbarch
, MOXIE_PC_REGNUM
);
1072 set_gdbarch_register_name (gdbarch
, moxie_register_name
);
1073 set_gdbarch_register_type (gdbarch
, moxie_register_type
);
1075 set_gdbarch_return_value (gdbarch
, moxie_return_value
);
1077 set_gdbarch_skip_prologue (gdbarch
, moxie_skip_prologue
);
1078 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1079 set_gdbarch_breakpoint_kind_from_pc (gdbarch
,
1080 moxie_breakpoint::kind_from_pc
);
1081 set_gdbarch_sw_breakpoint_from_kind (gdbarch
,
1082 moxie_breakpoint::bp_from_kind
);
1083 set_gdbarch_frame_align (gdbarch
, moxie_frame_align
);
1085 frame_base_set_default (gdbarch
, &moxie_frame_base
);
1087 /* Hook in ABI-specific overrides, if they have been registered. */
1088 gdbarch_init_osabi (info
, gdbarch
);
1090 /* Hook in the default unwinders. */
1091 frame_unwind_append_unwinder (gdbarch
, &moxie_frame_unwind
);
1093 /* Single stepping. */
1094 set_gdbarch_software_single_step (gdbarch
, moxie_software_single_step
);
1096 /* Support simple overlay manager. */
1097 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
1099 /* Support reverse debugging. */
1100 set_gdbarch_process_record (gdbarch
, moxie_process_record
);
1105 /* Register this machine's init routine. */
1107 void _initialize_moxie_tdep ();
1109 _initialize_moxie_tdep ()
1111 register_gdbarch_init (bfd_arch_moxie
, moxie_gdbarch_init
);