1 /* Target-dependent code for Moxie.
3 Copyright (C) 2009-2022 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
)
84 gdb_static_assert (ARRAY_SIZE (moxie_register_names
) == MOXIE_NUM_REGS
);
85 return moxie_register_names
[reg_nr
];
88 /* Implement the "register_type" gdbarch method. */
91 moxie_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
93 if (reg_nr
== MOXIE_PC_REGNUM
)
94 return builtin_type (gdbarch
)->builtin_func_ptr
;
95 else if (reg_nr
== MOXIE_SP_REGNUM
|| reg_nr
== MOXIE_FP_REGNUM
)
96 return builtin_type (gdbarch
)->builtin_data_ptr
;
98 return builtin_type (gdbarch
)->builtin_int32
;
101 /* Write into appropriate registers a function return value
102 of type TYPE, given in virtual format. */
105 moxie_store_return_value (struct type
*type
, struct regcache
*regcache
,
106 const gdb_byte
*valbuf
)
108 struct gdbarch
*gdbarch
= regcache
->arch ();
109 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
111 int len
= type
->length ();
113 /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
114 regval
= extract_unsigned_integer (valbuf
, len
> 4 ? 4 : len
, byte_order
);
115 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
, regval
);
118 regval
= extract_unsigned_integer (valbuf
+ 4, len
- 4, byte_order
);
119 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
+ 1, regval
);
123 /* Decode the instructions within the given address range. Decide
124 when we must have reached the end of the function prologue. If a
125 frame_info pointer is provided, fill in its saved_regs etc.
127 Returns the address of the first instruction after the prologue. */
130 moxie_analyze_prologue (CORE_ADDR start_addr
, CORE_ADDR end_addr
,
131 struct moxie_frame_cache
*cache
,
132 struct gdbarch
*gdbarch
)
134 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
136 ULONGEST inst
, inst2
;
140 /* Record where the jsra instruction saves the PC and FP. */
141 cache
->saved_regs
[MOXIE_PC_REGNUM
] = -4;
142 cache
->saved_regs
[MOXIE_FP_REGNUM
] = 0;
143 cache
->framesize
= 0;
145 if (start_addr
>= end_addr
)
148 for (next_addr
= start_addr
; next_addr
< end_addr
; )
150 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
152 /* Match "push $sp $rN" where N is between 0 and 13 inclusive. */
153 if (inst
>= 0x0612 && inst
<= 0x061f)
155 regnum
= inst
& 0x000f;
156 cache
->framesize
+= 4;
157 cache
->saved_regs
[regnum
] = cache
->framesize
;
164 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
166 /* Optional stack allocation for args and local vars <= 4
168 if (inst
== 0x01e0) /* ldi.l $r12, X */
170 offset
= read_memory_integer (next_addr
+ 2, 4, byte_order
);
171 inst2
= read_memory_unsigned_integer (next_addr
+ 6, 2, byte_order
);
173 if (inst2
== 0x291e) /* sub.l $sp, $r12 */
175 cache
->framesize
+= offset
;
178 return (next_addr
+ 8);
180 else if ((inst
& 0xff00) == 0x9100) /* dec $sp, X */
182 cache
->framesize
+= (inst
& 0x00ff);
185 while (next_addr
< end_addr
)
187 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
188 if ((inst
& 0xff00) != 0x9100) /* no more dec $sp, X */
190 cache
->framesize
+= (inst
& 0x00ff);
198 /* Find the end of function prologue. */
201 moxie_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
203 CORE_ADDR func_addr
= 0, func_end
= 0;
204 const char *func_name
;
206 /* See if we can determine the end of the prologue via the symbol table.
207 If so, then return either PC, or the PC after the prologue, whichever
209 if (find_pc_partial_function (pc
, &func_name
, &func_addr
, &func_end
))
211 CORE_ADDR post_prologue_pc
212 = skip_prologue_using_sal (gdbarch
, func_addr
);
213 if (post_prologue_pc
!= 0)
214 return std::max (pc
, post_prologue_pc
);
217 /* Can't determine prologue from the symbol table, need to examine
219 struct symtab_and_line sal
;
221 struct moxie_frame_cache cache
;
224 memset (&cache
, 0, sizeof cache
);
226 plg_end
= moxie_analyze_prologue (func_addr
,
227 func_end
, &cache
, gdbarch
);
228 /* Found a function. */
229 sym
= lookup_symbol (func_name
, NULL
, VAR_DOMAIN
, NULL
).symbol
;
230 /* Don't use line number debug info for assembly source
232 if (sym
&& sym
->language () != language_asm
)
234 sal
= find_pc_line (func_addr
, 0);
235 if (sal
.end
&& sal
.end
< func_end
)
237 /* Found a line number, use it as end of
242 /* No useable line symbol. Use result of prologue parsing
248 /* No function symbol -- just return the PC. */
249 return (CORE_ADDR
) pc
;
252 struct moxie_unwind_cache
254 /* The previous frame's inner most stack address. Used as this
255 frame ID's stack_addr. */
257 /* The frame's base, optionally used by the high-level debug info. */
260 /* How far the SP and r13 (FP) have been offset from the start of
261 the stack frame (as defined by the previous frame's stack
266 /* Table indicating the location of each and every register. */
267 trad_frame_saved_reg
*saved_regs
;
270 /* Read an unsigned integer from the inferior, and adjust
273 moxie_process_readu (CORE_ADDR addr
, gdb_byte
*buf
,
274 int length
, enum bfd_endian byte_order
)
276 if (target_read_memory (addr
, buf
, length
))
279 gdb_printf (gdb_stderr
,
280 _("Process record: error reading memory at "
281 "addr 0x%s len = %d.\n"),
282 paddress (target_gdbarch (), addr
), length
);
286 return extract_unsigned_integer (buf
, length
, byte_order
);
290 /* Helper macro to extract the signed 10-bit offset from a 16-bit
291 branch instruction. */
292 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
294 /* Insert a single step breakpoint. */
296 static std::vector
<CORE_ADDR
>
297 moxie_software_single_step (struct regcache
*regcache
)
299 struct gdbarch
*gdbarch
= regcache
->arch ();
305 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
306 std::vector
<CORE_ADDR
> next_pcs
;
308 addr
= regcache_read_pc (regcache
);
310 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
312 /* Decode instruction. */
313 if (inst
& (1 << 15))
315 if (inst
& (1 << 14))
317 /* This is a Form 3 instruction. */
318 int opcode
= (inst
>> 10 & 0xf);
326 case 0x04: /* bltu */
327 case 0x05: /* bgtu */
330 case 0x08: /* bgeu */
331 case 0x09: /* bleu */
332 /* Insert breaks on both branches, because we can't currently tell
333 which way things will go. */
334 next_pcs
.push_back (addr
+ 2);
335 next_pcs
.push_back (addr
+ 2 + INST2OFFSET(inst
));
346 /* This is a Form 2 instruction. They are all 16 bits. */
347 next_pcs
.push_back (addr
+ 2);
352 /* This is a Form 1 instruction. */
353 int opcode
= inst
>> 8;
357 /* 16-bit instructions. */
359 case 0x02: /* mov (register-to-register) */
360 case 0x05: /* add.l */
361 case 0x06: /* push */
363 case 0x0a: /* ld.l (register indirect) */
364 case 0x0b: /* st.l */
367 case 0x10: /* sex.b */
368 case 0x11: /* sex.s */
369 case 0x12: /* zex.b */
370 case 0x13: /* zex.s */
371 case 0x14: /* umul.x */
372 case 0x15: /* mul.x */
376 case 0x1c: /* ld.b (register indirect) */
377 case 0x1e: /* st.b */
378 case 0x21: /* ld.s (register indirect) */
379 case 0x23: /* st.s */
381 case 0x27: /* lshr */
382 case 0x28: /* ashl */
383 case 0x29: /* sub.l */
387 case 0x2d: /* ashr */
389 case 0x2f: /* mul.l */
390 case 0x31: /* div.l */
391 case 0x32: /* udiv.l */
392 case 0x33: /* mod.l */
393 case 0x34: /* umod.l */
394 next_pcs
.push_back (addr
+ 2);
397 /* 32-bit instructions. */
398 case 0x0c: /* ldo.l */
399 case 0x0d: /* sto.l */
400 case 0x36: /* ldo.b */
401 case 0x37: /* sto.b */
402 case 0x38: /* ldo.s */
403 case 0x39: /* sto.s */
404 next_pcs
.push_back (addr
+ 4);
407 /* 48-bit instructions. */
408 case 0x01: /* ldi.l (immediate) */
409 case 0x08: /* lda.l */
410 case 0x09: /* sta.l */
411 case 0x1b: /* ldi.b (immediate) */
412 case 0x1d: /* lda.b */
413 case 0x1f: /* sta.b */
414 case 0x20: /* ldi.s (immediate) */
415 case 0x22: /* lda.s */
416 case 0x24: /* sta.s */
417 next_pcs
.push_back (addr
+ 6);
420 /* Control flow instructions. */
421 case 0x03: /* jsra */
422 case 0x1a: /* jmpa */
423 next_pcs
.push_back (moxie_process_readu (addr
+ 2, buf
, 4,
428 regcache_cooked_read_unsigned (regcache
, MOXIE_FP_REGNUM
, &fp
);
429 next_pcs
.push_back (moxie_process_readu (fp
+ 4, buf
, 4, byte_order
));
434 regcache
->raw_read ((inst
>> 4) & 0xf, (gdb_byte
*) & tmpu32
);
435 next_pcs
.push_back (tmpu32
);
440 /* Unsupported, for now. */
448 /* Given a return value in `regbuf' with a type `valtype',
449 extract and copy its value into `valbuf'. */
452 moxie_extract_return_value (struct type
*type
, struct regcache
*regcache
,
455 struct gdbarch
*gdbarch
= regcache
->arch ();
456 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
457 int len
= type
->length ();
460 /* By using store_unsigned_integer we avoid having to do
461 anything special for small big-endian values. */
462 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
, &tmp
);
463 store_unsigned_integer (dst
, (len
> 4 ? len
- 4 : len
), byte_order
, tmp
);
465 /* Ignore return values more than 8 bytes in size because the moxie
466 returns anything more than 8 bytes in the stack. */
469 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
+ 1, &tmp
);
470 store_unsigned_integer (dst
+ len
- 4, 4, byte_order
, tmp
);
474 /* Implement the "return_value" gdbarch method. */
476 static enum return_value_convention
477 moxie_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
478 struct type
*valtype
, struct regcache
*regcache
,
479 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
481 if (valtype
->length () > 8)
482 return RETURN_VALUE_STRUCT_CONVENTION
;
486 moxie_extract_return_value (valtype
, regcache
, readbuf
);
487 if (writebuf
!= NULL
)
488 moxie_store_return_value (valtype
, regcache
, writebuf
);
489 return RETURN_VALUE_REGISTER_CONVENTION
;
493 /* Allocate and initialize a moxie_frame_cache object. */
495 static struct moxie_frame_cache
*
496 moxie_alloc_frame_cache (void)
498 struct moxie_frame_cache
*cache
;
501 cache
= FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache
);
506 cache
->framesize
= 0;
507 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
508 cache
->saved_regs
[i
] = REG_UNAVAIL
;
513 /* Populate a moxie_frame_cache object for this_frame. */
515 static struct moxie_frame_cache
*
516 moxie_frame_cache (frame_info_ptr this_frame
, void **this_cache
)
518 struct moxie_frame_cache
*cache
;
519 CORE_ADDR current_pc
;
523 return (struct moxie_frame_cache
*) *this_cache
;
525 cache
= moxie_alloc_frame_cache ();
528 cache
->base
= get_frame_register_unsigned (this_frame
, MOXIE_FP_REGNUM
);
529 if (cache
->base
== 0)
532 cache
->pc
= get_frame_func (this_frame
);
533 current_pc
= get_frame_pc (this_frame
);
536 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
537 moxie_analyze_prologue (cache
->pc
, current_pc
, cache
, gdbarch
);
540 cache
->saved_sp
= cache
->base
- cache
->framesize
;
542 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
543 if (cache
->saved_regs
[i
] != REG_UNAVAIL
)
544 cache
->saved_regs
[i
] = cache
->base
- cache
->saved_regs
[i
];
549 /* Given a GDB frame, determine the address of the calling function's
550 frame. This will be used to create a new GDB frame struct. */
553 moxie_frame_this_id (frame_info_ptr this_frame
,
554 void **this_prologue_cache
, struct frame_id
*this_id
)
556 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
557 this_prologue_cache
);
559 /* This marks the outermost frame. */
560 if (cache
->base
== 0)
563 *this_id
= frame_id_build (cache
->saved_sp
, cache
->pc
);
566 /* Get the value of register regnum in the previous stack frame. */
568 static struct value
*
569 moxie_frame_prev_register (frame_info_ptr this_frame
,
570 void **this_prologue_cache
, int regnum
)
572 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
573 this_prologue_cache
);
575 gdb_assert (regnum
>= 0);
577 if (regnum
== MOXIE_SP_REGNUM
&& cache
->saved_sp
)
578 return frame_unwind_got_constant (this_frame
, regnum
, cache
->saved_sp
);
580 if (regnum
< MOXIE_NUM_REGS
&& cache
->saved_regs
[regnum
] != REG_UNAVAIL
)
581 return frame_unwind_got_memory (this_frame
, regnum
,
582 cache
->saved_regs
[regnum
]);
584 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
587 static const struct frame_unwind moxie_frame_unwind
= {
590 default_frame_unwind_stop_reason
,
592 moxie_frame_prev_register
,
594 default_frame_sniffer
597 /* Return the base address of this_frame. */
600 moxie_frame_base_address (frame_info_ptr this_frame
, void **this_cache
)
602 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
608 static const struct frame_base moxie_frame_base
= {
610 moxie_frame_base_address
,
611 moxie_frame_base_address
,
612 moxie_frame_base_address
615 /* Parse the current instruction and record the values of the registers and
616 memory that will be changed in current instruction to "record_arch_list".
617 Return -1 if something wrong. */
620 moxie_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
626 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
628 if (record_debug
> 1)
629 gdb_printf (gdb_stdlog
, "Process record: moxie_process_record "
631 paddress (target_gdbarch (), addr
));
633 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
635 /* Decode instruction. */
636 if (inst
& (1 << 15))
638 if (inst
& (1 << 14))
640 /* This is a Form 3 instruction. */
641 int opcode
= (inst
>> 10 & 0xf);
649 case 0x04: /* bltu */
650 case 0x05: /* bgtu */
653 case 0x08: /* bgeu */
654 case 0x09: /* bleu */
666 /* This is a Form 2 instruction. */
667 int opcode
= (inst
>> 12 & 0x3);
674 int reg
= (inst
>> 8) & 0xf;
675 if (record_full_arch_list_add_reg (regcache
, reg
))
681 /* Do nothing until GDB learns about moxie's special
693 /* This is a Form 1 instruction. */
694 int opcode
= inst
>> 8;
701 case 0x01: /* ldi.l (immediate) */
702 case 0x02: /* mov (register-to-register) */
704 int reg
= (inst
>> 4) & 0xf;
705 if (record_full_arch_list_add_reg (regcache
, reg
))
709 case 0x03: /* jsra */
712 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
713 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
715 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
716 || (record_full_arch_list_add_reg (regcache
,
718 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
724 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
725 || (record_full_arch_list_add_reg (regcache
,
730 case 0x05: /* add.l */
732 int reg
= (inst
>> 4) & 0xf;
733 if (record_full_arch_list_add_reg (regcache
, reg
))
737 case 0x06: /* push */
739 int reg
= (inst
>> 4) & 0xf;
740 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
741 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
743 if (record_full_arch_list_add_reg (regcache
, reg
)
744 || record_full_arch_list_add_mem (tmpu32
- 4, 4))
750 int a
= (inst
>> 4) & 0xf;
752 if (record_full_arch_list_add_reg (regcache
, a
)
753 || record_full_arch_list_add_reg (regcache
, b
))
757 case 0x08: /* lda.l */
759 int reg
= (inst
>> 4) & 0xf;
760 if (record_full_arch_list_add_reg (regcache
, reg
))
764 case 0x09: /* sta.l */
766 tmpu32
= (uint32_t) moxie_process_readu (addr
+2, buf
,
768 if (record_full_arch_list_add_mem (tmpu32
, 4))
772 case 0x0a: /* ld.l (register indirect) */
774 int reg
= (inst
>> 4) & 0xf;
775 if (record_full_arch_list_add_reg (regcache
, reg
))
779 case 0x0b: /* st.l */
781 int reg
= (inst
>> 4) & 0xf;
782 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
783 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
785 if (record_full_arch_list_add_mem (tmpu32
, 4))
789 case 0x0c: /* ldo.l */
791 int reg
= (inst
>> 4) & 0xf;
792 if (record_full_arch_list_add_reg (regcache
, reg
))
796 case 0x0d: /* sto.l */
798 int reg
= (inst
>> 4) & 0xf;
799 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
800 byte_order
)) << 16 ) >> 16;
801 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
802 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
805 if (record_full_arch_list_add_mem (tmpu32
, 4))
811 if (record_full_arch_list_add_reg (regcache
, MOXIE_CC_REGNUM
))
820 case 0x10: /* sex.b */
821 case 0x11: /* sex.s */
822 case 0x12: /* zex.b */
823 case 0x13: /* zex.s */
824 case 0x14: /* umul.x */
825 case 0x15: /* mul.x */
827 int reg
= (inst
>> 4) & 0xf;
828 if (record_full_arch_list_add_reg (regcache
, reg
))
842 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
843 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
845 if (record_full_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
846 || (record_full_arch_list_add_reg (regcache
,
848 || record_full_arch_list_add_mem (tmpu32
- 12, 12))
852 case 0x1a: /* jmpa */
857 case 0x1b: /* ldi.b (immediate) */
858 case 0x1c: /* ld.b (register indirect) */
859 case 0x1d: /* lda.b */
861 int reg
= (inst
>> 4) & 0xf;
862 if (record_full_arch_list_add_reg (regcache
, reg
))
866 case 0x1e: /* st.b */
868 int reg
= (inst
>> 4) & 0xf;
869 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
870 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
872 if (record_full_arch_list_add_mem (tmpu32
, 1))
876 case 0x1f: /* sta.b */
878 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
879 if (record_full_arch_list_add_mem (tmpu32
, 1))
883 case 0x20: /* ldi.s (immediate) */
884 case 0x21: /* ld.s (register indirect) */
885 case 0x22: /* lda.s */
887 int reg
= (inst
>> 4) & 0xf;
888 if (record_full_arch_list_add_reg (regcache
, reg
))
892 case 0x23: /* st.s */
894 int reg
= (inst
>> 4) & 0xf;
895 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
896 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
898 if (record_full_arch_list_add_mem (tmpu32
, 2))
902 case 0x24: /* sta.s */
904 tmpu32
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
905 if (record_full_arch_list_add_mem (tmpu32
, 2))
915 case 0x27: /* lshr */
916 case 0x28: /* ashl */
921 case 0x2d: /* ashr */
925 int reg
= (inst
>> 4) & 0xf;
926 if (record_full_arch_list_add_reg (regcache
, reg
))
932 /* We currently implement support for libgloss'
935 int inum
= moxie_process_readu (addr
+2, buf
, 4, byte_order
);
939 case 0x1: /* SYS_exit */
944 case 0x2: /* SYS_open */
946 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
950 case 0x4: /* SYS_read */
952 uint32_t length
, ptr
;
954 /* Read buffer pointer is in $r1. */
955 regcache
->raw_read (3, (gdb_byte
*) & ptr
);
956 ptr
= extract_unsigned_integer ((gdb_byte
*) & ptr
,
959 /* String length is at 0x12($fp). */
961 MOXIE_FP_REGNUM
, (gdb_byte
*) & tmpu32
);
962 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
964 length
= moxie_process_readu (tmpu32
+20, buf
, 4, byte_order
);
966 if (record_full_arch_list_add_mem (ptr
, length
))
970 case 0x5: /* SYS_write */
972 if (record_full_arch_list_add_reg (regcache
, RET1_REGNUM
))
981 case 0x31: /* div.l */
982 case 0x32: /* udiv.l */
983 case 0x33: /* mod.l */
984 case 0x34: /* umod.l */
986 int reg
= (inst
>> 4) & 0xf;
987 if (record_full_arch_list_add_reg (regcache
, reg
))
994 case 0x36: /* ldo.b */
996 int reg
= (inst
>> 4) & 0xf;
997 if (record_full_arch_list_add_reg (regcache
, reg
))
1001 case 0x37: /* sto.b */
1003 int reg
= (inst
>> 4) & 0xf;
1004 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1005 byte_order
)) << 16 ) >> 16;
1006 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
1007 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1010 if (record_full_arch_list_add_mem (tmpu32
, 1))
1014 case 0x38: /* ldo.s */
1016 int reg
= (inst
>> 4) & 0xf;
1017 if (record_full_arch_list_add_reg (regcache
, reg
))
1021 case 0x39: /* sto.s */
1023 int reg
= (inst
>> 4) & 0xf;
1024 uint32_t offset
= (((int16_t) moxie_process_readu (addr
+2, buf
, 2,
1025 byte_order
)) << 16 ) >> 16;
1026 regcache
->raw_read (reg
, (gdb_byte
*) & tmpu32
);
1027 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
1030 if (record_full_arch_list_add_mem (tmpu32
, 2))
1040 if (record_full_arch_list_add_reg (regcache
, MOXIE_PC_REGNUM
))
1042 if (record_full_arch_list_add_end ())
1047 /* Allocate and initialize the moxie gdbarch object. */
1049 static struct gdbarch
*
1050 moxie_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1052 struct gdbarch
*gdbarch
;
1054 /* If there is already a candidate, use it. */
1055 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1057 return arches
->gdbarch
;
1059 /* Allocate space for the new architecture. */
1060 moxie_gdbarch_tdep
*tdep
= new moxie_gdbarch_tdep
;
1061 gdbarch
= gdbarch_alloc (&info
, tdep
);
1063 set_gdbarch_wchar_bit (gdbarch
, 32);
1064 set_gdbarch_wchar_signed (gdbarch
, 0);
1066 set_gdbarch_num_regs (gdbarch
, MOXIE_NUM_REGS
);
1067 set_gdbarch_sp_regnum (gdbarch
, MOXIE_SP_REGNUM
);
1068 set_gdbarch_pc_regnum (gdbarch
, MOXIE_PC_REGNUM
);
1069 set_gdbarch_register_name (gdbarch
, moxie_register_name
);
1070 set_gdbarch_register_type (gdbarch
, moxie_register_type
);
1072 set_gdbarch_return_value (gdbarch
, moxie_return_value
);
1074 set_gdbarch_skip_prologue (gdbarch
, moxie_skip_prologue
);
1075 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1076 set_gdbarch_breakpoint_kind_from_pc (gdbarch
,
1077 moxie_breakpoint::kind_from_pc
);
1078 set_gdbarch_sw_breakpoint_from_kind (gdbarch
,
1079 moxie_breakpoint::bp_from_kind
);
1080 set_gdbarch_frame_align (gdbarch
, moxie_frame_align
);
1082 frame_base_set_default (gdbarch
, &moxie_frame_base
);
1084 /* Hook in ABI-specific overrides, if they have been registered. */
1085 gdbarch_init_osabi (info
, gdbarch
);
1087 /* Hook in the default unwinders. */
1088 frame_unwind_append_unwinder (gdbarch
, &moxie_frame_unwind
);
1090 /* Single stepping. */
1091 set_gdbarch_software_single_step (gdbarch
, moxie_software_single_step
);
1093 /* Support simple overlay manager. */
1094 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
1096 /* Support reverse debugging. */
1097 set_gdbarch_process_record (gdbarch
, moxie_process_record
);
1102 /* Register this machine's init routine. */
1104 void _initialize_moxie_tdep ();
1106 _initialize_moxie_tdep ()
1108 gdbarch_register (bfd_arch_moxie
, moxie_gdbarch_init
);