1 /* Target-dependent code for Moxie.
3 Copyright (C) 2009, 2010, 2011 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"
28 #include "gdb_string.h"
35 #include "arch-utils.h"
37 #include "trad-frame.h"
41 #include "gdb_assert.h"
43 #include "moxie-tdep.h"
45 /* Local functions. */
47 extern void _initialize_moxie_tdep (void);
49 /* Use an invalid address value as 'not available' marker. */
50 enum { REG_UNAVAIL
= (CORE_ADDR
) -1 };
52 struct moxie_frame_cache
58 CORE_ADDR saved_regs
[MOXIE_NUM_REGS
];
62 /* Implement the "frame_align" gdbarch method. */
65 moxie_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
67 /* Align to the size of an instruction (so that they can safely be
68 pushed onto the stack. */
72 /* Implement the "breakpoint_from_pc" gdbarch method. */
74 const static unsigned char *
75 moxie_breakpoint_from_pc (struct gdbarch
*gdbarch
,
76 CORE_ADDR
*pcptr
, int *lenptr
)
78 static unsigned char breakpoint
[] = { 0x35, 0x00 };
80 *lenptr
= sizeof (breakpoint
);
84 /* Moxie register names. */
86 char *moxie_register_names
[] = {
87 "$fp", "$sp", "$r0", "$r1", "$r2",
88 "$r3", "$r4", "$r5", "$r6", "$r7",
89 "$r8", "$r9", "$r10", "$r11", "$r12",
90 "$r13", "$pc", "$cc" };
92 /* Implement the "register_name" gdbarch method. */
95 moxie_register_name (struct gdbarch
*gdbarch
, int reg_nr
)
99 if (reg_nr
>= MOXIE_NUM_REGS
)
101 return moxie_register_names
[reg_nr
];
104 /* Implement the "register_type" gdbarch method. */
107 moxie_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
109 if (reg_nr
== MOXIE_PC_REGNUM
)
110 return builtin_type (gdbarch
)->builtin_func_ptr
;
111 else if (reg_nr
== MOXIE_SP_REGNUM
|| reg_nr
== MOXIE_FP_REGNUM
)
112 return builtin_type (gdbarch
)->builtin_data_ptr
;
114 return builtin_type (gdbarch
)->builtin_int32
;
117 /* Write into appropriate registers a function return value
118 of type TYPE, given in virtual format. */
121 moxie_store_return_value (struct type
*type
, struct regcache
*regcache
,
124 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
125 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
127 int len
= TYPE_LENGTH (type
);
129 /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
130 regval
= extract_unsigned_integer (valbuf
, len
> 4 ? 4 : len
, byte_order
);
131 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
, regval
);
134 regval
= extract_unsigned_integer ((gdb_byte
*) valbuf
+ 4,
135 len
- 4, byte_order
);
136 regcache_cooked_write_unsigned (regcache
, RET1_REGNUM
+ 1, regval
);
140 /* Decode the instructions within the given address range. Decide
141 when we must have reached the end of the function prologue. If a
142 frame_info pointer is provided, fill in its saved_regs etc.
144 Returns the address of the first instruction after the prologue. */
147 moxie_analyze_prologue (CORE_ADDR start_addr
, CORE_ADDR end_addr
,
148 struct moxie_frame_cache
*cache
,
149 struct gdbarch
*gdbarch
)
151 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
153 ULONGEST inst
, inst2
;
157 /* Record where the jsra instruction saves the PC and FP. */
158 cache
->saved_regs
[MOXIE_PC_REGNUM
] = -4;
159 cache
->saved_regs
[MOXIE_FP_REGNUM
] = 0;
160 cache
->framesize
= 0;
162 if (start_addr
>= end_addr
)
165 for (next_addr
= start_addr
; next_addr
< end_addr
; )
167 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
169 /* Match "push $rN" where N is between 2 and 13 inclusive. */
170 if (inst
>= 0x0614 && inst
<= 0x061f)
172 regnum
= inst
& 0x000f;
173 cache
->framesize
+= 4;
174 cache
->saved_regs
[regnum
] = cache
->framesize
;
181 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
183 /* Optional stack allocation for args and local vars <= 4
185 if (inst
== 0x0170) /* ldi.l $r5, X */
187 offset
= read_memory_integer (next_addr
+ 2, 4, byte_order
);
188 inst2
= read_memory_unsigned_integer (next_addr
+ 6, 2, byte_order
);
190 if (inst2
== 0x0517) /* add.l $sp, $r5 */
192 cache
->framesize
+= offset
;
195 return (next_addr
+ 8);
197 else if ((inst
& 0xff00) == 0x91) /* dec $sp, X */
199 cache
->framesize
+= (inst
& 0x00ff);
202 while (next_addr
< end_addr
)
204 inst
= read_memory_unsigned_integer (next_addr
, 2, byte_order
);
205 if ((inst
& 0xff00) != 0x91) /* no more dec $sp, X */
207 cache
->framesize
+= (inst
& 0x00ff);
215 /* Find the end of function prologue. */
218 moxie_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
220 CORE_ADDR func_addr
= 0, func_end
= 0;
223 /* See if we can determine the end of the prologue via the symbol table.
224 If so, then return either PC, or the PC after the prologue, whichever
226 if (find_pc_partial_function (pc
, &func_name
, &func_addr
, &func_end
))
228 CORE_ADDR post_prologue_pc
229 = skip_prologue_using_sal (gdbarch
, func_addr
);
230 if (post_prologue_pc
!= 0)
231 return max (pc
, post_prologue_pc
);
234 /* Can't determine prologue from the symbol table, need to examine
236 struct symtab_and_line sal
;
238 struct moxie_frame_cache cache
;
241 memset (&cache
, 0, sizeof cache
);
243 plg_end
= moxie_analyze_prologue (func_addr
,
244 func_end
, &cache
, gdbarch
);
245 /* Found a function. */
246 sym
= lookup_symbol (func_name
, NULL
, VAR_DOMAIN
, NULL
);
247 /* Don't use line number debug info for assembly source
249 if (sym
&& SYMBOL_LANGUAGE (sym
) != language_asm
)
251 sal
= find_pc_line (func_addr
, 0);
252 if (sal
.end
&& sal
.end
< func_end
)
254 /* Found a line number, use it as end of
259 /* No useable line symbol. Use result of prologue parsing
265 /* No function symbol -- just return the PC. */
266 return (CORE_ADDR
) pc
;
269 struct moxie_unwind_cache
271 /* The previous frame's inner most stack address. Used as this
272 frame ID's stack_addr. */
274 /* The frame's base, optionally used by the high-level debug info. */
277 /* How far the SP and r13 (FP) have been offset from the start of
278 the stack frame (as defined by the previous frame's stack
283 /* Table indicating the location of each and every register. */
284 struct trad_frame_saved_reg
*saved_regs
;
287 /* Implement the "read_pc" gdbarch method. */
290 moxie_read_pc (struct regcache
*regcache
)
294 regcache_cooked_read_unsigned (regcache
, MOXIE_PC_REGNUM
, &pc
);
298 /* Implement the "write_pc" gdbarch method. */
301 moxie_write_pc (struct regcache
*regcache
, CORE_ADDR val
)
303 regcache_cooked_write_unsigned (regcache
, MOXIE_PC_REGNUM
, val
);
306 /* Implement the "unwind_sp" gdbarch method. */
309 moxie_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
311 return frame_unwind_register_unsigned (next_frame
, MOXIE_SP_REGNUM
);
314 /* Given a return value in `regbuf' with a type `valtype',
315 extract and copy its value into `valbuf'. */
318 moxie_extract_return_value (struct type
*type
, struct regcache
*regcache
,
321 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
322 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
323 bfd_byte
*valbuf
= dst
;
324 int len
= TYPE_LENGTH (type
);
327 /* By using store_unsigned_integer we avoid having to do
328 anything special for small big-endian values. */
329 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
, &tmp
);
330 store_unsigned_integer (valbuf
, (len
> 4 ? len
- 4 : len
), byte_order
, tmp
);
332 /* Ignore return values more than 8 bytes in size because the moxie
333 returns anything more than 8 bytes in the stack. */
336 regcache_cooked_read_unsigned (regcache
, RET1_REGNUM
+ 1, &tmp
);
337 store_unsigned_integer (valbuf
+ len
- 4, 4, byte_order
, tmp
);
341 /* Implement the "return_value" gdbarch method. */
343 static enum return_value_convention
344 moxie_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
345 struct type
*valtype
, struct regcache
*regcache
,
346 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
348 if (TYPE_LENGTH (valtype
) > 8)
349 return RETURN_VALUE_STRUCT_CONVENTION
;
353 moxie_extract_return_value (valtype
, regcache
, readbuf
);
354 if (writebuf
!= NULL
)
355 moxie_store_return_value (valtype
, regcache
, writebuf
);
356 return RETURN_VALUE_REGISTER_CONVENTION
;
360 /* Allocate and initialize a moxie_frame_cache object. */
362 static struct moxie_frame_cache
*
363 moxie_alloc_frame_cache (void)
365 struct moxie_frame_cache
*cache
;
368 cache
= FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache
);
373 cache
->framesize
= 0;
374 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
375 cache
->saved_regs
[i
] = REG_UNAVAIL
;
380 /* Populate a moxie_frame_cache object for this_frame. */
382 static struct moxie_frame_cache
*
383 moxie_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
385 struct moxie_frame_cache
*cache
;
386 CORE_ADDR current_pc
;
392 cache
= moxie_alloc_frame_cache ();
395 cache
->base
= get_frame_register_unsigned (this_frame
, MOXIE_FP_REGNUM
);
396 if (cache
->base
== 0)
399 cache
->pc
= get_frame_func (this_frame
);
400 current_pc
= get_frame_pc (this_frame
);
403 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
404 moxie_analyze_prologue (cache
->pc
, current_pc
, cache
, gdbarch
);
407 cache
->saved_sp
= cache
->base
- cache
->framesize
;
409 for (i
= 0; i
< MOXIE_NUM_REGS
; ++i
)
410 if (cache
->saved_regs
[i
] != REG_UNAVAIL
)
411 cache
->saved_regs
[i
] = cache
->base
- cache
->saved_regs
[i
];
416 /* Implement the "unwind_pc" gdbarch method. */
419 moxie_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
421 return frame_unwind_register_unsigned (next_frame
, MOXIE_PC_REGNUM
);
424 /* Given a GDB frame, determine the address of the calling function's
425 frame. This will be used to create a new GDB frame struct. */
428 moxie_frame_this_id (struct frame_info
*this_frame
,
429 void **this_prologue_cache
, struct frame_id
*this_id
)
431 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
432 this_prologue_cache
);
434 /* This marks the outermost frame. */
435 if (cache
->base
== 0)
438 *this_id
= frame_id_build (cache
->saved_sp
, cache
->pc
);
441 /* Get the value of register regnum in the previous stack frame. */
443 static struct value
*
444 moxie_frame_prev_register (struct frame_info
*this_frame
,
445 void **this_prologue_cache
, int regnum
)
447 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
448 this_prologue_cache
);
450 gdb_assert (regnum
>= 0);
452 if (regnum
== MOXIE_SP_REGNUM
&& cache
->saved_sp
)
453 return frame_unwind_got_constant (this_frame
, regnum
, cache
->saved_sp
);
455 if (regnum
< MOXIE_NUM_REGS
&& cache
->saved_regs
[regnum
] != REG_UNAVAIL
)
456 return frame_unwind_got_memory (this_frame
, regnum
,
457 cache
->saved_regs
[regnum
]);
459 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
462 static const struct frame_unwind moxie_frame_unwind
= {
465 moxie_frame_prev_register
,
467 default_frame_sniffer
470 /* Return the base address of this_frame. */
473 moxie_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
475 struct moxie_frame_cache
*cache
= moxie_frame_cache (this_frame
,
481 static const struct frame_base moxie_frame_base
= {
483 moxie_frame_base_address
,
484 moxie_frame_base_address
,
485 moxie_frame_base_address
488 static struct frame_id
489 moxie_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
491 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, MOXIE_SP_REGNUM
);
493 return frame_id_build (sp
, get_frame_pc (this_frame
));
496 /* Read an unsigned integer from the inferior, and adjust
499 moxie_process_readu (CORE_ADDR addr
, char *buf
,
500 int length
, enum bfd_endian byte_order
)
502 if (target_read_memory (addr
, buf
, length
))
505 printf_unfiltered (_("Process record: error reading memory at "
506 "addr 0x%s len = %d.\n"),
507 paddress (target_gdbarch
, addr
), length
);
511 return extract_unsigned_integer (buf
, length
, byte_order
);
514 /* Parse the current instruction and record the values of the registers and
515 memory that will be changed in current instruction to "record_arch_list".
516 Return -1 if something wrong. */
519 moxie_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
525 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
527 if (record_debug
> 1)
528 fprintf_unfiltered (gdb_stdlog
, "Process record: moxie_process_record "
530 paddress (target_gdbarch
, addr
));
532 inst
= (uint16_t) moxie_process_readu (addr
, buf
, 2, byte_order
);
534 /* Decode instruction. */
535 if (inst
& (1 << 15))
537 if (inst
& (1 << 14))
539 /* This is a Form 3 instruction. */
540 int opcode
= (inst
>> 10 & 0xf);
548 case 0x04: /* bltu */
549 case 0x05: /* bgtu */
552 case 0x08: /* bgeu */
553 case 0x09: /* bleu */
565 /* This is a Form 2 instruction. */
566 int opcode
= (inst
>> 12 & 0x3);
573 int reg
= (inst
>> 8) & 0xf;
574 if (record_arch_list_add_reg (regcache
, reg
))
580 /* Do nothing until GDB learns about moxie's special
592 /* This is a Form 1 instruction. */
593 int opcode
= inst
>> 8;
600 case 0x01: /* ldi.l (immediate) */
601 case 0x02: /* mov (register-to-register) */
603 int reg
= (inst
>> 4) & 0xf;
604 if (record_arch_list_add_reg (regcache
, reg
))
608 case 0x03: /* jsra */
610 regcache_raw_read (regcache
,
611 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
612 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
614 if (record_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
615 || (record_arch_list_add_reg (regcache
,
617 || record_arch_list_add_mem (tmpu32
- 12, 12))
623 if (record_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
624 || (record_arch_list_add_reg (regcache
,
629 case 0x05: /* add.l */
631 int reg
= (inst
>> 4) & 0xf;
632 if (record_arch_list_add_reg (regcache
, reg
))
636 case 0x06: /* push */
638 int reg
= (inst
>> 4) & 0xf;
639 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
640 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
642 if (record_arch_list_add_reg (regcache
, reg
)
643 || record_arch_list_add_mem (tmpu32
- 4, 4))
649 int a
= (inst
>> 4) & 0xf;
651 if (record_arch_list_add_reg (regcache
, a
)
652 || record_arch_list_add_reg (regcache
, b
))
656 case 0x08: /* lda.l */
658 int reg
= (inst
>> 4) & 0xf;
659 if (record_arch_list_add_reg (regcache
, reg
))
663 case 0x09: /* sta.l */
665 tmpu32
= (uint32_t) moxie_process_readu (addr
+2, buf
,
667 if (record_arch_list_add_mem (tmpu32
, 4))
671 case 0x0a: /* ld.l (register indirect) */
673 int reg
= (inst
>> 4) & 0xf;
674 if (record_arch_list_add_reg (regcache
, reg
))
678 case 0x0b: /* st.l */
680 int reg
= (inst
>> 4) & 0xf;
681 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
682 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
684 if (record_arch_list_add_mem (tmpu32
, 4))
688 case 0x0c: /* ldo.l */
690 int reg
= (inst
>> 4) & 0xf;
691 if (record_arch_list_add_reg (regcache
, reg
))
695 case 0x0d: /* sto.l */
697 int reg
= (inst
>> 4) & 0xf;
698 uint32_t offset
= (uint32_t) moxie_process_readu (addr
+2, buf
, 4,
700 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
701 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
704 if (record_arch_list_add_mem (tmpu32
, 4))
710 if (record_arch_list_add_reg (regcache
, MOXIE_CC_REGNUM
))
730 regcache_raw_read (regcache
,
731 MOXIE_SP_REGNUM
, (gdb_byte
*) & tmpu32
);
732 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
734 if (record_arch_list_add_reg (regcache
, MOXIE_FP_REGNUM
)
735 || (record_arch_list_add_reg (regcache
,
737 || record_arch_list_add_mem (tmpu32
- 12, 12))
741 case 0x1a: /* jmpa */
746 case 0x1b: /* ldi.b (immediate) */
747 case 0x1c: /* ld.b (register indirect) */
748 case 0x1d: /* lda.b */
750 int reg
= (inst
>> 4) & 0xf;
751 if (record_arch_list_add_reg (regcache
, reg
))
755 case 0x1e: /* st.b */
757 int reg
= (inst
>> 4) & 0xf;
758 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
759 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
761 if (record_arch_list_add_mem (tmpu32
, 1))
765 case 0x1f: /* sta.b */
767 tmpu32
= moxie_process_readu (addr
+2, (char *) buf
,
769 if (record_arch_list_add_mem (tmpu32
, 1))
773 case 0x20: /* ldi.s (immediate) */
774 case 0x21: /* ld.s (register indirect) */
775 case 0x22: /* lda.s */
777 int reg
= (inst
>> 4) & 0xf;
778 if (record_arch_list_add_reg (regcache
, reg
))
782 case 0x23: /* st.s */
784 int reg
= (inst
>> 4) & 0xf;
785 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
786 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
788 if (record_arch_list_add_mem (tmpu32
, 2))
792 case 0x24: /* sta.s */
794 tmpu32
= moxie_process_readu (addr
+2, (char *) buf
,
796 if (record_arch_list_add_mem (tmpu32
, 2))
806 case 0x27: /* lshr */
807 case 0x28: /* ashl */
808 case 0x29: /* sub.l */
812 case 0x2d: /* ashr */
814 case 0x2f: /* mul.l */
816 int reg
= (inst
>> 4) & 0xf;
817 if (record_arch_list_add_reg (regcache
, reg
))
823 /* We currently implement support for libgloss'
826 int inum
= moxie_process_readu (addr
+2, (char *) buf
,
831 case 0x1: /* SYS_exit */
836 case 0x2: /* SYS_open */
838 if (record_arch_list_add_reg (regcache
, RET1_REGNUM
))
842 case 0x4: /* SYS_read */
844 uint32_t length
, ptr
;
846 /* Read buffer pointer is in $r1. */
847 regcache_raw_read (regcache
, 3, (gdb_byte
*) & ptr
);
848 ptr
= extract_unsigned_integer ((gdb_byte
*) & ptr
,
851 /* String length is at 0x12($fp) */
852 regcache_raw_read (regcache
,
853 MOXIE_FP_REGNUM
, (gdb_byte
*) & tmpu32
);
854 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
856 length
= moxie_process_readu (tmpu32
+20, (char *) buf
,
859 if (record_arch_list_add_mem (ptr
, length
))
863 case 0x5: /* SYS_write */
865 if (record_arch_list_add_reg (regcache
, RET1_REGNUM
))
874 case 0x31: /* div.l */
875 case 0x32: /* udiv.l */
876 case 0x33: /* mod.l */
877 case 0x34: /* umod.l */
879 int reg
= (inst
>> 4) & 0xf;
880 if (record_arch_list_add_reg (regcache
, reg
))
887 case 0x36: /* ldo.b */
889 int reg
= (inst
>> 4) & 0xf;
890 if (record_arch_list_add_reg (regcache
, reg
))
894 case 0x37: /* sto.b */
896 int reg
= (inst
>> 4) & 0xf;
897 uint32_t offset
= (uint32_t) moxie_process_readu (addr
+2, buf
, 4,
899 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
900 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
903 if (record_arch_list_add_mem (tmpu32
, 1))
907 case 0x38: /* ldo.s */
909 int reg
= (inst
>> 4) & 0xf;
910 if (record_arch_list_add_reg (regcache
, reg
))
914 case 0x39: /* sto.s */
916 int reg
= (inst
>> 4) & 0xf;
917 uint32_t offset
= (uint32_t) moxie_process_readu (addr
+2, buf
, 4,
919 regcache_raw_read (regcache
, reg
, (gdb_byte
*) & tmpu32
);
920 tmpu32
= extract_unsigned_integer ((gdb_byte
*) & tmpu32
,
923 if (record_arch_list_add_mem (tmpu32
, 2))
933 if (record_arch_list_add_reg (regcache
, MOXIE_PC_REGNUM
))
935 if (record_arch_list_add_end ())
940 /* Allocate and initialize the moxie gdbarch object. */
942 static struct gdbarch
*
943 moxie_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
945 struct gdbarch
*gdbarch
;
946 struct gdbarch_tdep
*tdep
;
948 /* If there is already a candidate, use it. */
949 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
951 return arches
->gdbarch
;
953 /* Allocate space for the new architecture. */
954 tdep
= XMALLOC (struct gdbarch_tdep
);
955 gdbarch
= gdbarch_alloc (&info
, tdep
);
957 set_gdbarch_read_pc (gdbarch
, moxie_read_pc
);
958 set_gdbarch_write_pc (gdbarch
, moxie_write_pc
);
959 set_gdbarch_unwind_sp (gdbarch
, moxie_unwind_sp
);
961 set_gdbarch_num_regs (gdbarch
, MOXIE_NUM_REGS
);
962 set_gdbarch_sp_regnum (gdbarch
, MOXIE_SP_REGNUM
);
963 set_gdbarch_pc_regnum (gdbarch
, MOXIE_PC_REGNUM
);
964 set_gdbarch_register_name (gdbarch
, moxie_register_name
);
965 set_gdbarch_register_type (gdbarch
, moxie_register_type
);
967 set_gdbarch_return_value (gdbarch
, moxie_return_value
);
969 set_gdbarch_skip_prologue (gdbarch
, moxie_skip_prologue
);
970 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
971 set_gdbarch_breakpoint_from_pc (gdbarch
, moxie_breakpoint_from_pc
);
972 set_gdbarch_frame_align (gdbarch
, moxie_frame_align
);
974 frame_base_set_default (gdbarch
, &moxie_frame_base
);
976 /* Methods for saving / extracting a dummy frame's ID. The ID's
977 stack address must match the SP value returned by
978 PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
979 set_gdbarch_dummy_id (gdbarch
, moxie_dummy_id
);
981 set_gdbarch_unwind_pc (gdbarch
, moxie_unwind_pc
);
983 set_gdbarch_print_insn (gdbarch
, print_insn_moxie
);
985 /* Hook in ABI-specific overrides, if they have been registered. */
986 gdbarch_init_osabi (info
, gdbarch
);
988 /* Hook in the default unwinders. */
989 frame_unwind_append_unwinder (gdbarch
, &moxie_frame_unwind
);
991 /* Support simple overlay manager. */
992 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
994 /* Support reverse debugging. */
995 set_gdbarch_process_record (gdbarch
, moxie_process_record
);
1000 /* Register this machine's init routine. */
1003 _initialize_moxie_tdep (void)
1005 register_gdbarch_init (bfd_arch_moxie
, moxie_gdbarch_init
);