1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright 2003 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
30 #include "sparc64-tdep.h"
32 /* From <machine/reg.h>. */
34 /* Offset of registers in `struct reg'. */
35 int sparc64fbsd_r_global_offset
= (0 * 8);
36 int sparc64fbsd_r_out_offset
= (8 * 8);
37 int sparc64fbsd_r_fprs_offset
= (16 * 8);
38 int sparc64fbsd_r_tnpc_offset
= (24 * 8);
39 int sparc64fbsd_r_tpc_offset
= (25 * 8);
40 int sparc64fbsd_r_tstate_offset
= (26 * 8);
41 int sparc64fbsd_r_y_offset
= (28 * 8);
43 /* Size of `struct reg' and `struct fpreg'. */
44 int sparc64fbsd_sizeof_struct_reg
= 256;
45 int sparc64fbsd_sizeof_struct_fpreg
= 272;
48 sparc64fbsd_supply_reg (const char *regs
, int regnum
)
53 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
54 supply_register (SPARC64_PC_REGNUM
, regs
+ sparc64fbsd_r_tpc_offset
);
56 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
57 supply_register (SPARC64_NPC_REGNUM
, regs
+ sparc64fbsd_r_tnpc_offset
);
59 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
60 supply_register (SPARC64_STATE_REGNUM
, regs
+ sparc64fbsd_r_tstate_offset
);
62 if (regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
63 supply_register (SPARC64_FPRS_REGNUM
, regs
+ sparc64fbsd_r_fprs_offset
);
65 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
66 supply_register (SPARC64_Y_REGNUM
, regs
+ sparc64fbsd_r_y_offset
);
68 if ((regnum
>= SPARC_G0_REGNUM
&& regnum
<= SPARC_G7_REGNUM
) || regnum
== -1)
70 if (regnum
== SPARC_G0_REGNUM
|| regnum
== -1)
71 supply_register (SPARC_G0_REGNUM
, NULL
); /* %g0 is always zero. */
72 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_G7_REGNUM
; i
++)
74 if (regnum
== i
|| regnum
== -1)
75 supply_register (i
, (regs
+ sparc64fbsd_r_global_offset
76 + ((i
- SPARC_G0_REGNUM
) * 8)));
80 if ((regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
82 for (i
= SPARC_O0_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
84 if (regnum
== i
|| regnum
== -1)
85 supply_register (i
, (regs
+ sparc64fbsd_r_out_offset
86 + ((i
- SPARC_O0_REGNUM
) * 8)));
90 /* Inputs and Locals are stored onto the stack by by the kernel. */
91 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
95 regcache_cooked_read_unsigned (current_regcache
, SPARC_SP_REGNUM
, &sp
);
96 sparc_supply_rwindow (sp
, regnum
);
101 sparc64fbsd_fill_reg (char *regs
, int regnum
)
106 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
107 regcache_collect (SPARC64_PC_REGNUM
, regs
+ sparc64fbsd_r_tpc_offset
);
109 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
110 regcache_collect (SPARC64_NPC_REGNUM
, regs
+ sparc64fbsd_r_tnpc_offset
);
112 if (regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
113 regcache_collect (SPARC64_FPRS_REGNUM
, regs
+ sparc64fbsd_r_fprs_offset
);
115 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
116 regcache_collect (SPARC64_Y_REGNUM
, regs
+ sparc64fbsd_r_y_offset
);
118 if ((regnum
>= SPARC_G0_REGNUM
&& regnum
<= SPARC_G7_REGNUM
) || regnum
== -1)
120 /* %g0 is always zero. */
121 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_G7_REGNUM
; i
++)
123 if (regnum
== i
|| regnum
== -1)
124 regcache_collect (i
, (regs
+ sparc64fbsd_r_global_offset
125 + ((i
- SPARC_G0_REGNUM
) * 8)));
129 if ((regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
131 for (i
= SPARC_O0_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
133 if (regnum
== i
|| regnum
== -1)
134 regcache_collect (i
, (regs
+ sparc64fbsd_r_out_offset
135 + ((i
- SPARC_O0_REGNUM
) * 8)));
139 /* Responsibility for the stack regs is pushed off onto the caller. */
143 sparc64fbsd_supply_fpreg (const char *fpregs
, int regnum
)
147 for (i
= 0; i
< 32; i
++)
149 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
150 supply_register (SPARC_F0_REGNUM
+ i
, fpregs
+ (i
* 4));
153 for (i
= 0; i
< 16; i
++)
155 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
156 supply_register (SPARC64_F32_REGNUM
+ i
, fpregs
+ (32 * 4) + (i
* 8));
159 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
160 supply_register (SPARC64_FSR_REGNUM
, fpregs
+ (32 * 4) + (16 * 8));
164 sparc64fbsd_fill_fpreg (char *fpregs
, int regnum
)
168 for (i
= 0; i
< 32; i
++)
170 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
171 regcache_collect (SPARC_F0_REGNUM
+ i
, fpregs
+ (i
* 4));
174 for (i
= 0; i
< 16; i
++)
176 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
177 regcache_collect (SPARC64_F32_REGNUM
+ i
, fpregs
+ (32 * 4) + (i
* 8));
180 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
181 regcache_collect (SPARC64_FSR_REGNUM
, fpregs
+ (32 * 4) + (16 * 8));
186 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
191 case 0: /* Integer registers */
192 if (core_reg_size
!= sparc64fbsd_sizeof_struct_reg
)
193 warning ("Wrong size register set in core file.");
195 sparc64fbsd_supply_reg (core_reg_sect
, -1);
198 case 2: /* Floating pointer registers */
199 if (core_reg_size
!= sparc64fbsd_sizeof_struct_fpreg
)
200 warning ("Wrong size FP register set in core file.");
202 sparc64fbsd_supply_fpreg (core_reg_sect
, -1);
206 /* Don't know what kind of register request this is; just ignore it. */
211 static struct core_fns sparc64fbsd_core_fns
=
213 bfd_target_elf_flavour
, /* core_flavour */
214 default_check_format
, /* check_format */
215 default_core_sniffer
, /* core_sniffer */
216 fetch_core_registers
, /* core_read_registers */
222 sparc64fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
227 /* Provide a prototype to silence -Wmissing-prototypes. */
228 void _initialize_sparc64fbsd_tdep (void);
231 _initialize_sparc64fbsd_tdep (void)
233 gdbarch_register_osabi (bfd_arch_sparc
, bfd_mach_sparc_v9
,
234 GDB_OSABI_FREEBSD_ELF
, sparc64fbsd_init_abi
);
236 add_core_fns (&sparc64fbsd_core_fns
);