1/*
2 * Copyright (c) 2004 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "defs.h"
28#include "inferior.h"
29#include "regcache.h"
30
31#include <sys/types.h>
32#include <sys/ptrace.h>
33#include <machine/reg.h>
34
35#ifdef HAVE_SYS_PROCFS_H
36#include <sys/procfs.h>
37#endif
38
39#ifndef HAVE_GREGSET_T
40typedef struct reg gregset_t;
41#endif
42
43#ifndef HAVE_FPREGSET_T
44typedef struct fpreg fpregset_t;
45#endif
46
47#include "gregset.h"
48
49#define	FPREG_SUPPLIES(r)  ((r) >= IA64_FR0_REGNUM && (r) <= IA64_FR127_REGNUM)
50#define	GREG_SUPPLIES(r)   (!FPREG_SUPPLIES(r))
51
52void
53fetch_inferior_registers (int regno)
54{
55  union {
56    fpregset_t fpr;
57    gregset_t r;
58  } regs;
59
60  if (regno == -1 || GREG_SUPPLIES(regno))
61    {
62      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
63		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
64	perror_with_name ("Couldn't get registers");
65      supply_gregset (&regs.r);
66    }
67
68  if (regno == -1 || FPREG_SUPPLIES(regno))
69    {
70      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
71		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
72	perror_with_name ("Couldn't get FP registers");
73      supply_fpregset (&regs.fpr);
74    }
75}
76
77void
78store_inferior_registers (int regno)
79{
80  union {
81    fpregset_t fpr;
82    gregset_t r;
83  } regs;
84
85  if (regno == -1 || GREG_SUPPLIES(regno))
86    {
87      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
88		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
89	perror_with_name ("Couldn't get registers");
90      fill_gregset (&regs.r, regno);
91      if (ptrace (PT_SETREGS, PIDGET(inferior_ptid),
92		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
93	perror_with_name ("Couldn't get registers");
94      if (regno != -1)
95	return;
96    }
97
98  if (regno == -1 || FPREG_SUPPLIES(regno))
99    {
100      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
101		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
102	perror_with_name ("Couldn't get FP registers");
103      fill_fpregset (&regs.fpr, regno);
104      if (ptrace (PT_SETFPREGS, PIDGET(inferior_ptid),
105		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
106	perror_with_name ("Couldn't get FP registers");
107      if (regno != -1)
108	return;
109    }
110}
111
112LONGEST ia64_fbsd_xfer_dirty (struct target_ops *ops, enum target_object obj,
113			      const char *annex, void *rbuf, const void *wbuf,
114			      ULONGEST ofs, LONGEST len)
115{
116  if (len != 8)
117    return (-1);
118  if (rbuf != NULL) {
119    if (ptrace (PT_GETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)rbuf,
120		ofs >> 3) == -1) {
121      perror_with_name ("Couldn't read dirty register");
122      return (-1);
123    }
124  } else {
125    if (ptrace (PT_SETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)wbuf,
126		ofs >> 3) == -1) {
127      perror_with_name ("Couldn't write dirty register");
128      return (-1);
129    }
130  }
131  return (len);
132}
133
134void
135_initialize_ia64_fbsd_nat (void)
136{
137}
138