1Index: gdb/ia64-fbsd-nat.c
2===================================================================
3RCS file: gdb/ia64-fbsd-nat.c
4diff -N gdb/ia64-fbsd-nat.c
5--- /dev/null	1 Jan 1970 00:00:00 -0000
6+++ gdb/ia64-fbsd-nat.c	17 Apr 2004 19:39:20 -0000	1.3
7@@ -0,0 +1,145 @@
8+/*
9+ * Copyright (c) 2004 Marcel Moolenaar
10+ * All rights reserved.
11+ *
12+ * Redistribution and use in source and binary forms, with or without
13+ * modification, are permitted provided that the following conditions
14+ * are met:
15+ *
16+ * 1. Redistributions of source code must retain the above copyright
17+ *    notice, this list of conditions and the following disclaimer.
18+ * 2. Redistributions in binary form must reproduce the above copyright
19+ *    notice, this list of conditions and the following disclaimer in the
20+ *    documentation and/or other materials provided with the distribution.
21+ *
22+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+ */
33+
34+#include "defs.h"
35+#include "inferior.h"
36+#include "regcache.h"
37+
38+#include <sys/types.h>
39+#include <sys/ptrace.h>
40+#include <machine/reg.h>
41+
42+#ifdef HAVE_SYS_PROCFS_H
43+#include <sys/procfs.h>
44+#endif
45+
46+#ifndef HAVE_GREGSET_T
47+typedef struct reg gregset_t;
48+#endif
49+
50+#ifndef HAVE_FPREGSET_T
51+typedef struct fpreg fpregset_t;
52+#endif
53+
54+#include "gregset.h"
55+
56+#define	FPREG_SUPPLIES(r)  ((r) >= IA64_FR0_REGNUM && (r) <= IA64_FR127_REGNUM)
57+#define	GREG_SUPPLIES(r)   (!FPREG_SUPPLIES(r))
58+
59+/* XXX need to go away. */
60+void ia64_fbsd_supply_fpregs (void *, int);
61+void ia64_fbsd_supply_gregs (void *, int);
62+
63+void
64+fetch_inferior_registers (int regno)
65+{
66+  union {
67+    fpregset_t fpr;
68+    gregset_t r;
69+  } regs;
70+
71+  if (regno == -1 || GREG_SUPPLIES(regno))
72+    {
73+      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
74+		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
75+	perror_with_name ("Couldn't get registers");
76+      ia64_fbsd_supply_gregs (&regs.r, regno);
77+      if (regno != -1)
78+	return;
79+    }
80+
81+  if (regno == -1 || FPREG_SUPPLIES(regno))
82+    {
83+      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
84+		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
85+	perror_with_name ("Couldn't get FP registers");
86+      ia64_fbsd_supply_fpregs (&regs.fpr, regno);
87+      if (regno != -1)
88+	return;
89+    }
90+}
91+
92+void
93+store_inferior_registers (int regno)
94+{
95+  union {
96+    fpregset_t fpr;
97+    gregset_t r;
98+  } regs;
99+
100+  if (regno == -1 || GREG_SUPPLIES(regno))
101+    {
102+      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
103+		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
104+	perror_with_name ("Couldn't get registers");
105+      fill_gregset (&regs.r, regno);
106+      if (ptrace (PT_SETREGS, PIDGET(inferior_ptid),
107+		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
108+	perror_with_name ("Couldn't get registers");
109+      if (regno != -1)
110+	return;
111+    }
112+
113+  if (regno == -1 || FPREG_SUPPLIES(regno))
114+    {
115+      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
116+		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
117+	perror_with_name ("Couldn't get FP registers");
118+      fill_fpregset (&regs.fpr, regno);
119+      if (ptrace (PT_SETFPREGS, PIDGET(inferior_ptid),
120+		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
121+	perror_with_name ("Couldn't get FP registers");
122+      if (regno != -1)
123+	return;
124+    }
125+}
126+
127+LONGEST ia64_fbsd_xfer_dirty (struct target_ops *ops, enum target_object obj,
128+			      const char *annex, void *rbuf, const void *wbuf,
129+			      ULONGEST ofs, LONGEST len)
130+{
131+  if (len != 8)
132+    return (-1);
133+  if (rbuf != NULL) {
134+    if (ptrace (PT_GETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)rbuf,
135+		ofs >> 3) == -1) {
136+      perror_with_name ("Couldn't read dirty register");
137+      return (-1);
138+    }
139+  } else {
140+    if (ptrace (PT_SETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)wbuf,
141+		ofs >> 3) == -1) {
142+      perror_with_name ("Couldn't write dirty register");
143+      return (-1);
144+    }
145+  }
146+  return (len);
147+}
148+
149+void
150+_initialize_ia64_fbsd_nat (void)
151+{
152+}
153Index: gdb/ia64-fbsd-tdep.c
154===================================================================
155RCS file: gdb/ia64-fbsd-tdep.c
156diff -N gdb/ia64-fbsd-tdep.c
157--- /dev/null	1 Jan 1970 00:00:00 -0000
158+++ gdb/ia64-fbsd-tdep.c	17 Apr 2004 19:39:20 -0000	1.6
159@@ -0,0 +1,291 @@
160+/*
161+ * Copyright (c) 2004 Marcel Moolenaar
162+ * All rights reserved.
163+ *
164+ * Redistribution and use in source and binary forms, with or without
165+ * modification, are permitted provided that the following conditions
166+ * are met:
167+ *
168+ * 1. Redistributions of source code must retain the above copyright
169+ *    notice, this list of conditions and the following disclaimer.
170+ * 2. Redistributions in binary form must reproduce the above copyright
171+ *    notice, this list of conditions and the following disclaimer in the
172+ *    documentation and/or other materials provided with the distribution.
173+ *
174+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
175+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
176+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
177+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
178+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
179+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
180+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
181+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
182+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
183+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
184+ */
185+
186+#include "defs.h"
187+#include "gdb_string.h"
188+#include "regcache.h"
189+#include "regset.h"
190+#include "solib-svr4.h"
191+#include "value.h"
192+
193+#include "ia64-tdep.h"
194+
195+#define FPREG_SUPPLIES(r) ((r) >= IA64_FR0_REGNUM && (r) <= IA64_FR127_REGNUM)
196+#define GREG_SUPPLIES(r)  (!FPREG_SUPPLIES(r))
197+
198+static int reg_offset[462] = {
199+    -1,   96,  248,  256,  152,  160,  168,  176,       /* Regs 0-7. */
200+   264,  272,  280,  288,    0,   64,  296,  304,       /* Regs 8-15. */
201+   312,  320,  328,  336,  344,  352,  360,  368,       /* Regs 16-23. */
202+   376,  384,  392,  400,  408,  416,  424,  432,       /* Regs 24-31. */
203+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 32-39. */
204+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 40-47. */
205+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 48-55. */
206+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 56-63. */
207+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 64-71. */
208+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 72-79. */
209+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 80-87. */
210+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 88-95. */
211+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 96-103. */
212+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 104-111. */
213+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 112-119. */
214+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 120-127. */
215+    -1,   -1,    0,   16,   32,   48,  320,  336,       /* Regs 128-135. */
216+   352,  368,  384,  400,  416,  432,  448,  464,       /* Regs 136-143. */
217+    64,   80,   96,  112,  128,  144,  160,  176,       /* Regs 144-151. */
218+   192,  208,  224,  240,  256,  272,  288,  304,       /* Regs 152-159. */
219+   480,  496,  512,  528,  544,  560,  576,  592,       /* Regs 160-167. */
220+   608,  624,  640,  656,  672,  688,  704,  720,       /* Regs 168-175. */
221+   736,  752,  768,  784,  800,  816,  832,  848,       /* Regs 176-183. */
222+   864,  880,  896,  912,  928,  944,  960,  976,       /* Regs 184-191. */
223+   992, 1008, 1024, 1040, 1056, 1072, 1088, 1104,       /* Regs 192-199. */
224+  1120, 1136, 1152, 1168, 1184, 1200, 1216, 1232,       /* Regs 200-207. */
225+  1248, 1264, 1280, 1296, 1312, 1328, 1344, 1360,       /* Regs 208-215. */
226+  1376, 1392, 1408, 1424, 1440, 1456, 1472, 1488,       /* Regs 216-223. */
227+  1504, 1520, 1536, 1552, 1568, 1584, 1600, 1616,       /* Regs 224-231. */
228+  1632, 1648, 1664, 1680, 1696, 1712, 1728, 1744,       /* Regs 232-239. */
229+  1760, 1776, 1792, 1808, 1824, 1840, 1856, 1872,       /* Regs 240-247. */
230+  1888, 1904, 1920, 1936, 1952, 1968, 1984, 2000,       /* Regs 248-255. */
231+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 256-263. */
232+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 264-271. */
233+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 272-279. */
234+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 280-287. */
235+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 288-295. */
236+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 296-303. */
237+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 304-311. */
238+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 312-319. */
239+    16,  184,  192,  200,  208,  216,  440,  448,       /* Regs 320-327. */
240+    -1,   -1,   24,  120,   88,  112,   -1,   -1,       /* Regs 328-335. */
241+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 336-343. */
242+    -1,   -1,   -1,   -1,   -1,   -1,   72,  104,       /* Regs 344-351. */
243+    40,   48,   -1,   -1,   -1,   -1,   -1,  464,       /* Regs 352-359. */
244+   472,   -1,   -1,   -1,   -1,   -1,  456,   -1,       /* Regs 360-367. */
245+    -1,   -1,    8,   -1,   -1,   -1,   80,   -1,       /* Regs 368-375. */
246+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 376-383. */
247+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 384-391. */
248+    -1,   -1,   -1,   -1,   -1,   -1,   32,  224,       /* Regs 392-399. */
249+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 400-407. */
250+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 408-415. */
251+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 416-423. */
252+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 424-431. */
253+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 432-439. */
254+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 440-447. */
255+    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,       /* Regs 448-455. */
256+    -1,   -1,   -1,   -1,   -1,   -1
257+};
258+
259+static void
260+ia64_fbsd_regcache_collect (struct regcache *regcache, int regno,
261+			    void *regs)
262+{
263+  int ofs;
264+
265+  if (regno < 0 || regno >= NUM_REGS)
266+    return;
267+
268+  ofs = reg_offset[regno];
269+  if (ofs >= 0)
270+    regcache_raw_collect (regcache, regno, (char*)regs + ofs);
271+}
272+
273+static void
274+ia64_fbsd_regcache_supply (struct regcache *regcache, int regno,
275+			   const void *regs)
276+{
277+  int ofs;
278+
279+  if (regno < 0 || regno >= NUM_REGS)
280+    return;
281+
282+  ofs = reg_offset[regno];
283+  if (regno == IA64_BSP_REGNUM)
284+    {
285+      /* BSP is synthesized. It's not actually present in struct reg,
286+	 but can be derived from bspstore and ndirty. The offset of
287+	 IA64_BSP_REGNUM in the reg_offset array above is that of the
288+	 ndirty field in struct reg. */
289+      uint64_t bsp;
290+      bsp = *((uint64_t*)((char *)regs + ofs));		/* ndirty */
291+      bsp += *((uint64_t*)((char *)regs + reg_offset[IA64_BSPSTORE_REGNUM]));
292+      regcache_raw_supply (regcache, regno, &bsp);
293+    }
294+  else
295+    {
296+      if (ofs < 0)
297+	regcache_raw_supply (regcache, regno, NULL);
298+      else
299+	regcache_raw_supply (regcache, regno, (char *)regs + ofs);
300+    }
301+}
302+
303+void
304+fill_fpregset (void *fpregs, int regno)
305+{
306+  if (regno == -1)
307+    {
308+      for (regno = 0; regno < NUM_REGS; regno++)
309+	{
310+	  if (FPREG_SUPPLIES(regno))
311+	    ia64_fbsd_regcache_collect (current_regcache, regno, fpregs);
312+	}
313+    }
314+  else
315+    {
316+      if (FPREG_SUPPLIES(regno))
317+	ia64_fbsd_regcache_collect (current_regcache, regno, fpregs);
318+    }
319+}
320+
321+void
322+fill_gregset (void *gregs, int regno)
323+{
324+  if (regno == -1)
325+    {
326+      for (regno = 0; regno < NUM_REGS; regno++)
327+	{
328+	  if (GREG_SUPPLIES(regno))
329+	    ia64_fbsd_regcache_collect (current_regcache, regno, gregs);
330+	}
331+    }
332+  else
333+    {
334+      if (GREG_SUPPLIES(regno))
335+	ia64_fbsd_regcache_collect (current_regcache, regno, gregs);
336+    }
337+}
338+
339+void
340+ia64_fbsd_supply_fpregs (const void *fpregs, int regno)
341+{
342+  if (regno == -1)
343+    {
344+      for (regno = 0; regno < NUM_REGS; regno++)
345+	{
346+	  if (FPREG_SUPPLIES(regno))
347+	    ia64_fbsd_regcache_supply (current_regcache, regno, fpregs);
348+	}
349+    }
350+  else
351+    {
352+      if (FPREG_SUPPLIES(regno))
353+	ia64_fbsd_regcache_supply (current_regcache, regno, fpregs);
354+    }
355+}
356+
357+void
358+ia64_fbsd_supply_gregs (const void *gregs, int regno)
359+{
360+  if (regno == -1)
361+    {
362+      for (regno = 0; regno < NUM_REGS; regno++)
363+	{
364+	  if (GREG_SUPPLIES(regno))
365+	    ia64_fbsd_regcache_supply (current_regcache, regno, gregs);
366+	}
367+    }
368+  else
369+    {
370+      if (GREG_SUPPLIES(regno))
371+	ia64_fbsd_regcache_supply (current_regcache, regno, gregs);
372+    }
373+}
374+
375+static void
376+ia64_fbsd_supply_gregset (const struct regset *regset,
377+			  struct regcache *regcache, int regno,
378+			  const void *gregs, size_t len)
379+{
380+  if (regno == -1)
381+    {
382+      for (regno = 0; regno < NUM_REGS; regno++)
383+	{
384+	  if (GREG_SUPPLIES(regno))
385+	    ia64_fbsd_regcache_supply (regcache, regno, gregs);
386+	}
387+    }
388+  else
389+    if (GREG_SUPPLIES(regno))
390+      ia64_fbsd_regcache_supply (regcache, regno, gregs);
391+}
392+
393+static void
394+ia64_fbsd_supply_fpregset (const struct regset *regset,
395+			   struct regcache *regcache, int regno,
396+			   const void *fpregs, size_t len)
397+{
398+  if (regno == -1)
399+    {
400+      for (regno = 0; regno < NUM_REGS; regno++)
401+	{
402+	  if (FPREG_SUPPLIES(regno))
403+	    ia64_fbsd_regcache_supply (regcache, regno, fpregs);
404+	}
405+    }
406+  else
407+    if (FPREG_SUPPLIES(regno))
408+      ia64_fbsd_regcache_supply (regcache, regno, fpregs);
409+}
410+
411+static struct regset gregset = { NULL, ia64_fbsd_supply_gregset };
412+static struct regset fpregset = { NULL, ia64_fbsd_supply_fpregset };
413+
414+static const struct regset *
415+ia64_fbsd_regset_from_core_section (struct gdbarch *gdbarch,
416+				    const char *sect_name, size_t sect_size)
417+{
418+  if (strcmp (sect_name, ".reg") == 0)
419+    return (&gregset);
420+  if (strcmp (sect_name, ".reg2") == 0)
421+    return (&fpregset);
422+  return (NULL);
423+}
424+
425+static int
426+ia64_fbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
427+{
428+  uint64_t gwpage = 5ULL << 61;
429+  return (pc >= gwpage && pc < (gwpage + 8192)) ? 1 : 0;
430+}
431+
432+static void
433+ia64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
434+{
435+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
436+
437+  set_gdbarch_pc_in_sigtramp (gdbarch, ia64_fbsd_pc_in_sigtramp);
438+  set_gdbarch_regset_from_core_section (gdbarch,
439+                                        ia64_fbsd_regset_from_core_section);
440+  set_solib_svr4_fetch_link_map_offsets (gdbarch,
441+					 svr4_lp64_fetch_link_map_offsets);
442+  tdep->find_global_pointer = ia64_generic_find_global_pointer;
443+}
444+
445+void
446+_initialize_ia64_fbsd_tdep (void)
447+{
448+  gdbarch_register_osabi (bfd_arch_ia64, 0ul, GDB_OSABI_FREEBSD_ELF,
449+                          ia64_fbsd_init_abi);
450+}
451Index: gdb/ia64-tdep.c
452===================================================================
453RCS file: /home/marcel/CVS/gdb6/gdb/ia64-tdep.c,v
454retrieving revision 1.1.1.3
455retrieving revision 1.5
456diff -u -r1.1.1.3 -r1.5
457--- gdb/ia64-tdep.c	16 Apr 2004 00:51:25 -0000	1.1.1.3
458+++ gdb/ia64-tdep.c	16 Apr 2004 01:28:33 -0000	1.5
459@@ -45,17 +45,6 @@
460 #include "libunwind-ia64.h"
461 #endif
462 
463-/* Hook for determining the global pointer when calling functions in
464-   the inferior under AIX.  The initialization code in ia64-aix-nat.c
465-   sets this hook to the address of a function which will find the
466-   global pointer for a given address.  
467-   
468-   The generic code which uses the dynamic section in the inferior for
469-   finding the global pointer is not of much use on AIX since the
470-   values obtained from the inferior have not been relocated.  */
471-
472-CORE_ADDR (*native_find_global_pointer) (CORE_ADDR) = 0;
473-
474 /* An enumeration of the different IA-64 instruction types.  */
475 
476 typedef enum instruction_type
477@@ -256,20 +245,6 @@
478 
479 };
480 
481-struct gdbarch_tdep
482-  {
483-    CORE_ADDR (*sigcontext_register_address) (CORE_ADDR, int);
484-    			/* OS specific function which, given a frame address
485-			   and register number, returns the offset to the
486-			   given register from the start of the frame. */
487-    CORE_ADDR (*find_global_pointer) (CORE_ADDR);
488-  };
489-
490-#define SIGCONTEXT_REGISTER_ADDRESS \
491-  (gdbarch_tdep (current_gdbarch)->sigcontext_register_address)
492-#define FIND_GLOBAL_POINTER \
493-  (gdbarch_tdep (current_gdbarch)->find_global_pointer)
494-
495 int
496 ia64_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
497 			  struct reggroup *group)
498@@ -682,9 +657,18 @@
499  
500       if ((cfm & 0x7f) > regnum - V32_REGNUM) 
501 	{
502+	  ULONGEST bspstore;
503 	  ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
504-	  reg = read_memory_integer ((CORE_ADDR)reg_addr, 8);
505-	  store_unsigned_integer (buf, register_size (current_gdbarch, regnum), reg);
506+	  regcache_cooked_read_unsigned (regcache, IA64_BSPSTORE_REGNUM,
507+					 &bspstore);
508+	  if (reg_addr < bspstore) {
509+	    reg = read_memory_integer ((CORE_ADDR)reg_addr, 8);
510+	    store_unsigned_integer (buf, register_size (current_gdbarch,
511+							regnum), reg);
512+	  } else
513+	    target_read_partial (&current_target, TARGET_OBJECT_DIRTY,
514+				 (void*)bspstore, buf, reg_addr - bspstore,
515+				 register_size (current_gdbarch, regnum));
516 	}
517       else
518 	store_unsigned_integer (buf, register_size (current_gdbarch, regnum), 0);
519@@ -725,7 +709,21 @@
520 	  if (nat_addr >= bsp)
521 	    regcache_cooked_read_unsigned (regcache, IA64_RNAT_REGNUM, &nat_collection);
522 	  else
523-	    nat_collection = read_memory_integer (nat_addr, 8);
524+	    {
525+	      ULONGEST bspstore;
526+	      regcache_cooked_read_unsigned (regcache, IA64_BSPSTORE_REGNUM,
527+					     &bspstore);
528+	      if (nat_addr < bspstore)
529+		nat_collection = read_memory_integer (nat_addr, 8);
530+	      else {
531+		char natbuf[8];
532+		target_read_partial (&current_target, TARGET_OBJECT_DIRTY,
533+				     (void*)bspstore, natbuf,
534+				     nat_addr - bspstore,
535+				     register_size (current_gdbarch, regnum));
536+		nat_collection = *((uint64_t*)natbuf);
537+	      }
538+	    }
539 	  nat_bit = (gr_addr >> 3) & 0x3f;
540 	  natN_val = (nat_collection >> nat_bit) & 1;
541 	}
542@@ -789,8 +787,16 @@
543  
544       if ((cfm & 0x7f) > regnum - V32_REGNUM) 
545 	{
546+	  ULONGEST bspstore;
547 	  ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
548-	  write_memory (reg_addr, (void *)buf, 8);
549+	  regcache_cooked_read_unsigned (regcache, IA64_BSPSTORE_REGNUM,
550+					 &bspstore);
551+	  if (reg_addr < bspstore)
552+	    write_memory (reg_addr, (void *)buf, 8);
553+	  else
554+	    target_write_partial (&current_target, TARGET_OBJECT_DIRTY,
555+				  (void*)bspstore, buf, reg_addr - bspstore,
556+				  register_size (current_gdbarch, regnum));
557 	}
558     }
559   else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM)
560@@ -845,13 +851,33 @@
561 	  else
562 	    {
563 	      char nat_buf[8];
564-	      nat_collection = read_memory_integer (nat_addr, 8);
565+	      ULONGEST bspstore;
566+	      regcache_cooked_read_unsigned (regcache, IA64_BSPSTORE_REGNUM,
567+					     &bspstore);
568+	      if (nat_addr < bspstore)
569+		nat_collection = read_memory_integer (nat_addr, 8);
570+	      else {
571+		char natbuf[8];
572+		target_read_partial (&current_target, TARGET_OBJECT_DIRTY,
573+				     (void*)bspstore, natbuf,
574+				     nat_addr - bspstore,
575+				     register_size (current_gdbarch, regnum));
576+		nat_collection = *((uint64_t*)natbuf);
577+	      }
578 	      if (natN_val)
579 		nat_collection |= natN_mask;
580 	      else
581 		nat_collection &= ~natN_mask;
582-	      store_unsigned_integer (nat_buf, register_size (current_gdbarch, regnum), nat_collection);
583-	      write_memory (nat_addr, nat_buf, 8);
584+	      store_unsigned_integer (nat_buf, register_size (current_gdbarch,
585+							      regnum),
586+				      nat_collection);
587+	      if (nat_addr < bspstore)
588+		write_memory (nat_addr, nat_buf, 8);
589+	      else
590+		target_write_partial (&current_target, TARGET_OBJECT_DIRTY,
591+				      (void*)bspstore, nat_buf,
592+				      nat_addr - bspstore,
593+				      register_size (current_gdbarch, regnum));
594 	    }
595 	}
596     }
597@@ -1813,6 +1839,7 @@
598 	  prev_bof = rse_address_add (prev_bsp, -(prev_cfm & 0x7f));
599 
600 	  addr = rse_address_add (prev_bof, (regnum - IA64_GR32_REGNUM));
601+	  /* XXX marcel */
602 	  *lvalp = lval_memory;
603 	  *addrp = addr;
604 	  read_memory (addr, valuep, register_size (current_gdbarch, regnum));
605@@ -2858,8 +2885,8 @@
606    DT_PLTGOT tag.  If it finds one of these, the corresponding
607    d_un.d_ptr value is the global pointer.  */
608 
609-static CORE_ADDR
610-generic_elf_find_global_pointer (CORE_ADDR faddr)
611+CORE_ADDR
612+ia64_generic_find_global_pointer (CORE_ADDR faddr)
613 {
614   struct obj_section *faddr_sect;
615      
616@@ -3255,32 +3282,9 @@
617 
618   tdep = xmalloc (sizeof (struct gdbarch_tdep));
619   gdbarch = gdbarch_alloc (&info, tdep);
620-
621-  /* Set the method of obtaining the sigcontext addresses at which
622-     registers are saved.  The method of checking to see if
623-     native_find_global_pointer is nonzero to indicate that we're
624-     on AIX is kind of hokey, but I can't think of a better way
625-     to do it.  */
626-  if (info.osabi == GDB_OSABI_LINUX)
627-    tdep->sigcontext_register_address = ia64_linux_sigcontext_register_address;
628-  else if (native_find_global_pointer != 0)
629-    tdep->sigcontext_register_address = ia64_aix_sigcontext_register_address;
630-  else
631-    tdep->sigcontext_register_address = 0;
632-
633-  /* We know that GNU/Linux won't have to resort to the
634-     native_find_global_pointer hackery.  But that's the only one we
635-     know about so far, so if native_find_global_pointer is set to
636-     something non-zero, then use it.  Otherwise fall back to using
637-     generic_elf_find_global_pointer.  This arrangement should (in
638-     theory) allow us to cross debug GNU/Linux binaries from an AIX
639-     machine.  */
640-  if (info.osabi == GDB_OSABI_LINUX)
641-    tdep->find_global_pointer = generic_elf_find_global_pointer;
642-  else if (native_find_global_pointer != 0)
643-    tdep->find_global_pointer = native_find_global_pointer;
644-  else
645-    tdep->find_global_pointer = generic_elf_find_global_pointer;
646+  tdep->osabi = info.osabi;
647+  tdep->sigcontext_register_address = NULL;
648+  tdep->find_global_pointer = ia64_generic_find_global_pointer;
649 
650   /* Define the ia64 floating-point format to gdb.  */
651   builtin_type_ia64_ext =
652@@ -3338,10 +3342,7 @@
653   set_gdbarch_memory_remove_breakpoint (gdbarch, ia64_memory_remove_breakpoint);
654   set_gdbarch_breakpoint_from_pc (gdbarch, ia64_breakpoint_from_pc);
655   set_gdbarch_read_pc (gdbarch, ia64_read_pc);
656-  if (info.osabi == GDB_OSABI_LINUX)
657-    set_gdbarch_write_pc (gdbarch, ia64_linux_write_pc);
658-  else
659-    set_gdbarch_write_pc (gdbarch, ia64_write_pc);
660+  set_gdbarch_write_pc (gdbarch, ia64_write_pc);
661 
662   /* Settings for calling functions in the inferior.  */
663   set_gdbarch_push_dummy_call (gdbarch, ia64_push_dummy_call);
664@@ -3365,6 +3366,8 @@
665 
666   set_gdbarch_print_insn (gdbarch, ia64_print_insn);
667   set_gdbarch_convert_from_func_ptr_addr (gdbarch, ia64_convert_from_func_ptr_addr);
668+
669+  gdbarch_init_osabi (info, gdbarch);
670 
671   return gdbarch;
672 }
673Index: gdb/ia64-tdep.h
674===================================================================
675RCS file: /home/marcel/CVS/gdb6/gdb/ia64-tdep.h,v
676retrieving revision 1.1.1.1
677retrieving revision 1.2
678diff -u -r1.1.1.1 -r1.2
679--- gdb/ia64-tdep.h	26 Mar 2004 02:54:41 -0000	1.1.1.1
680+++ gdb/ia64-tdep.h	28 Mar 2004 03:47:34 -0000	1.2
681@@ -22,10 +22,25 @@
682 #ifndef IA64_TDEP_H
683 #define IA64_TDEP_H
684 
685-extern CORE_ADDR ia64_linux_sigcontext_register_address (CORE_ADDR, int);
686-extern CORE_ADDR ia64_aix_sigcontext_register_address (CORE_ADDR, int);
687-extern unsigned long ia64_linux_getunwind_table (void *, size_t);
688-extern void ia64_write_pc (CORE_ADDR, ptid_t);
689-extern void ia64_linux_write_pc (CORE_ADDR, ptid_t);
690+#include "osabi.h"
691+
692+/* Target-dependent structure in gdbarch.  */
693+struct gdbarch_tdep
694+{
695+  enum gdb_osabi osabi;		/* OS/ABI of inferior.  */
696+
697+  CORE_ADDR (*sigcontext_register_address) (CORE_ADDR, int);
698+    			/* OS specific function which, given a frame address
699+			   and register number, returns the offset to the
700+			   given register from the start of the frame. */
701+  CORE_ADDR (*find_global_pointer) (CORE_ADDR);
702+};
703+
704+#define SIGCONTEXT_REGISTER_ADDRESS \
705+  (gdbarch_tdep (current_gdbarch)->sigcontext_register_address)
706+#define FIND_GLOBAL_POINTER \
707+  (gdbarch_tdep (current_gdbarch)->find_global_pointer)
708+
709+extern CORE_ADDR ia64_generic_find_global_pointer (CORE_ADDR);
710 
711 #endif /* IA64_TDEP_H */
712Index: gdb/inftarg.c
713===================================================================
714RCS file: /home/marcel/CVS/gdb6/gdb/inftarg.c,v
715retrieving revision 1.1.1.1
716retrieving revision 1.2
717diff -u -r1.1.1.1 -r1.2
718--- gdb/inftarg.c	26 Mar 2004 02:54:41 -0000	1.1.1.1
719+++ gdb/inftarg.c	28 Mar 2004 03:47:34 -0000	1.2
720@@ -592,6 +592,13 @@
721       return NATIVE_XFER_WCOOKIE (ops, object, annex, readbuf, writebuf,
722 				  offset, len);
723 
724+    case TARGET_OBJECT_DIRTY:
725+#ifndef TARGET_XFER_DIRTY
726+#define TARGET_XFER_DIRTY(OPS,OBJECT,ANNEX,WRITEBUF,READBUF,OFFSET,LEN) (-1)
727+#endif
728+      return TARGET_XFER_DIRTY (ops, object, annex, readbuf, writebuf,
729+				offset, len);
730+
731     default:
732       return -1;
733     }
734Index: gdb/remote.c
735===================================================================
736RCS file: /home/marcel/CVS/gdb6/gdb/remote.c,v
737retrieving revision 1.1.1.3
738retrieving revision 1.5
739diff -u -r1.1.1.3 -r1.5
740--- gdb/remote.c	16 Apr 2004 00:51:28 -0000	1.1.1.3
741+++ gdb/remote.c	16 Apr 2004 01:28:33 -0000	1.5
742@@ -998,6 +998,23 @@
743   show_packet_config_cmd (&remote_protocol_qPart_auxv);
744 }
745 
746+/* Should we try the 'qPart:dirty' (target dirty register read) request? */
747+static struct packet_config remote_protocol_qPart_dirty;
748+
749+static void
750+set_remote_protocol_qPart_dirty_packet_cmd (char *args, int from_tty,
751+					    struct cmd_list_element *c)
752+{
753+  update_packet_config (&remote_protocol_qPart_dirty);
754+}
755+
756+static void
757+show_remote_protocol_qPart_dirty_packet_cmd (char *args, int from_tty,
758+					     struct cmd_list_element *c)
759+{
760+  show_packet_config_cmd (&remote_protocol_qPart_dirty);
761+}
762+
763 
764 /* Tokens for use by the asynchronous signal handlers for SIGINT */
765 static void *sigint_remote_twice_token;
766@@ -2088,6 +2105,7 @@
767      downloading. */
768   update_packet_config (&remote_protocol_binary_download);
769   update_packet_config (&remote_protocol_qPart_auxv);
770+  update_packet_config (&remote_protocol_qPart_dirty);
771 }
772 
773 /* Symbol look-up. */
774@@ -4925,6 +4943,23 @@
775 	}
776       return -1;
777 
778+    case TARGET_OBJECT_DIRTY:
779+      if (remote_protocol_qPart_dirty.support != PACKET_DISABLE)
780+	{
781+	  snprintf (buf2, rs->remote_packet_size, "qPart:dirty:read::%lx",
782+		    (long)(offset >> 3));
783+	  i = putpkt (buf2);
784+	  if (i < 0)
785+	    return i;
786+	  buf2[0] = '\0';
787+	  getpkt (buf2, rs->remote_packet_size, 0);
788+	  if (packet_ok (buf2, &remote_protocol_qPart_dirty) != PACKET_OK)
789+	    return -1;
790+	  i = hex2bin (buf2, readbuf, len);
791+	  return i;
792+	}
793+      return -1;
794+
795     default:
796       return -1;
797     }
798@@ -5423,6 +5458,7 @@
799   show_remote_protocol_vcont_packet_cmd (args, from_tty, NULL);
800   show_remote_protocol_binary_download_cmd (args, from_tty, NULL);
801   show_remote_protocol_qPart_auxv_packet_cmd (args, from_tty, NULL);
802+  show_remote_protocol_qPart_dirty_packet_cmd (args, from_tty, NULL);
803 }
804 
805 static void
806@@ -5670,6 +5706,13 @@
807 			 "qPart_auxv", "read-aux-vector",
808 			 set_remote_protocol_qPart_auxv_packet_cmd,
809 			 show_remote_protocol_qPart_auxv_packet_cmd,
810+			 &remote_set_cmdlist, &remote_show_cmdlist,
811+			 0);
812+
813+  add_packet_config_cmd (&remote_protocol_qPart_dirty,
814+			 "qPart_dirty", "read-dirty-registers",
815+			 set_remote_protocol_qPart_dirty_packet_cmd,
816+			 show_remote_protocol_qPart_dirty_packet_cmd,
817 			 &remote_set_cmdlist, &remote_show_cmdlist,
818 			 0);
819 
820Index: gdb/target.h
821===================================================================
822RCS file: /home/marcel/CVS/gdb6/gdb/target.h,v
823retrieving revision 1.1.1.1
824retrieving revision 1.2
825diff -u -r1.1.1.1 -r1.2
826--- gdb/target.h	26 Mar 2004 02:54:42 -0000	1.1.1.1
827+++ gdb/target.h	28 Mar 2004 03:47:34 -0000	1.2
828@@ -229,7 +229,9 @@
829   /* Transfer auxilliary vector.  */
830   TARGET_OBJECT_AUXV,
831   /* StackGhost cookie.  See "sparc-tdep.c".  */
832-  TARGET_OBJECT_WCOOKIE
833+  TARGET_OBJECT_WCOOKIE,
834+  /* Dirty registers. See "ia64-tdep.c".  */
835+  TARGET_OBJECT_DIRTY
836 
837   /* Possible future objects: TARGET_OBJECT_FILE, TARGET_OBJECT_PROC, ... */
838 };
839Index: gdb/config/ia64/fbsd.mh
840===================================================================
841RCS file: gdb/config/ia64/fbsd.mh
842diff -N gdb/config/ia64/fbsd.mh
843--- /dev/null	1 Jan 1970 00:00:00 -0000
844+++ gdb/config/ia64/fbsd.mh	25 Jun 2004 03:55:31 -0000
845@@ -0,0 +1,3 @@
846+NATDEPFILES=	fbsd-proc.o fbsd-thread.o fork-child.o gcore.o \
847+		ia64-fbsd-nat.o infptrace.o inftarg.o
848+NAT_FILE=	nm-fbsd.h
849Index: gdb/config/ia64/fbsd.mt
850===================================================================
851RCS file: gdb/config/ia64/fbsd.mt
852diff -N gdb/config/ia64/fbsd.mt
853--- /dev/null	1 Jan 1970 00:00:00 -0000
854+++ gdb/config/ia64/fbsd.mt	28 Mar 2004 03:47:38 -0000	1.1
855@@ -0,0 +1,2 @@
856+TDEPFILES=	corelow.o ia64-fbsd-tdep.o ia64-tdep.o solib.o solib-svr4.o
857+TM_FILE=	tm-fbsd.h
858Index: gdb/config/ia64/nm-fbsd.h
859===================================================================
860RCS file: gdb/config/ia64/nm-fbsd.h
861diff -N gdb/config/ia64/nm-fbsd.h
862--- /dev/null	1 Jan 1970 00:00:00 -0000
863+++ gdb/config/ia64/nm-fbsd.h	16 Apr 2004 02:49:16 -0000	1.2
864@@ -0,0 +1,24 @@
865+/* GNU GPL */
866+
867+#ifndef NM_FBSD_H
868+#define	NM_FBSD_H
869+
870+/* Type of the third argument to the `ptrace' system call.  */
871+#define PTRACE_ARG3_TYPE caddr_t
872+
873+/* Override copies of {fetch,store}_inferior_registers in `infptrace.c'.  */
874+#define FETCH_INFERIOR_REGISTERS
875+
876+/* We can attach and detach.  */
877+#define ATTACH_DETACH
878+
879+/* Override child_pid_to_exec_file in 'inftarg.c'.  */
880+#define	CHILD_PID_TO_EXEC_FILE
881+
882+#include "target.h"
883+
884+#define	TARGET_XFER_DIRTY	ia64_fbsd_xfer_dirty
885+extern LONGEST ia64_fbsd_xfer_dirty(struct target_ops *, enum target_object,
886+    const char *, void *, const void *, ULONGEST, LONGEST);
887+
888+#endif /* NM_FBSD_H */
889Index: gdb/config/ia64/tm-fbsd.h
890===================================================================
891RCS file: gdb/config/ia64/tm-fbsd.h
892diff -N gdb/config/ia64/tm-fbsd.h
893--- /dev/null	1 Jan 1970 00:00:00 -0000
894+++ gdb/config/ia64/tm-fbsd.h	17 Apr 2004 01:43:21 -0000	1.2
895@@ -0,0 +1,34 @@
896+/*
897+ * Copyright (c) 2004 Marcel Moolenaar
898+ * All rights reserved.
899+ *
900+ * Redistribution and use in source and binary forms, with or without
901+ * modification, are permitted provided that the following conditions
902+ * are met:
903+ *
904+ * 1. Redistributions of source code must retain the above copyright
905+ *    notice, this list of conditions and the following disclaimer.
906+ * 2. Redistributions in binary form must reproduce the above copyright
907+ *    notice, this list of conditions and the following disclaimer in the
908+ *    documentation and/or other materials provided with the distribution.
909+ *
910+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
911+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
912+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
913+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
914+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
915+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
916+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
917+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
918+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
919+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
920+ */
921+
922+#ifndef TM_FBSD_H
923+#define	TM_FBSD_H
924+
925+#include "solib.h"
926+
927+#include "ia64/tm-ia64.h"
928+
929+#endif /* TM_FBSD_H */
930Index: gdb/sparc64fbsd-tdep.c
931===================================================================
932--- gdb/sparc64fbsd-tdep.c	(revision 223862)
933+++ gdb/sparc64fbsd-tdep.c	(working copy)
934@@ -64,6 +64,31 @@ sparc64fbsd_supply_fpregset (const struct regset *
935 {
936   sparc64_supply_fpregset (regcache, regnum, fpregs);
937 }
938+
939+void
940+supply_gregset (const void *gregs)
941+{
942+  sparc64_supply_gregset (&sparc64fbsd_gregset, current_regcache, -1, gregs);
943+}
944+
945+void
946+supply_fpregset (const void *fpregs)
947+{
948+  sparc64_supply_fpregset (current_regcache, -1, fpregs);
949+}
950+
951+void
952+fill_gregset (void *gregs, int regnum)
953+{
954+  sparc64_collect_gregset (&sparc64fbsd_gregset, current_regcache, regnum,
955+			   gregs);
956+}
957+
958+void
959+fill_fpregset (void *fpregs, int regnum)
960+{
961+  sparc64_collect_fpregset (current_regcache, regnum, fpregs);
962+}
963 
964 
965 /* Signal trampolines.  */
966