1131082Smarcel/*
2131082Smarcel * Copyright (c) 2004 Marcel Moolenaar
3131082Smarcel * All rights reserved.
4131082Smarcel *
5131082Smarcel * Redistribution and use in source and binary forms, with or without
6131082Smarcel * modification, are permitted provided that the following conditions
7131082Smarcel * are met:
8131082Smarcel *
9131082Smarcel * 1. Redistributions of source code must retain the above copyright
10131082Smarcel *    notice, this list of conditions and the following disclaimer.
11131082Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12131082Smarcel *    notice, this list of conditions and the following disclaimer in the
13131082Smarcel *    documentation and/or other materials provided with the distribution.
14131082Smarcel *
15131082Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16131082Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17131082Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18131082Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19131082Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20131082Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21131082Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22131082Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23131082Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24131082Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25131082Smarcel */
26131082Smarcel
27131082Smarcel#include "defs.h"
28131082Smarcel#include "inferior.h"
29131082Smarcel#include "regcache.h"
30131082Smarcel
31131082Smarcel#include <sys/types.h>
32131082Smarcel#include <sys/ptrace.h>
33131082Smarcel#include <machine/reg.h>
34131082Smarcel
35131082Smarcel#ifdef HAVE_SYS_PROCFS_H
36131082Smarcel#include <sys/procfs.h>
37131082Smarcel#endif
38131082Smarcel
39131082Smarcel#ifndef HAVE_GREGSET_T
40131082Smarceltypedef struct reg gregset_t;
41131082Smarcel#endif
42131082Smarcel
43131082Smarcel#ifndef HAVE_FPREGSET_T
44131082Smarceltypedef struct fpreg fpregset_t;
45131082Smarcel#endif
46131082Smarcel
47131082Smarcel#include "gregset.h"
48131082Smarcel
49131082Smarcel#define	FPREG_SUPPLIES(r)  ((r) >= IA64_FR0_REGNUM && (r) <= IA64_FR127_REGNUM)
50131082Smarcel#define	GREG_SUPPLIES(r)   (!FPREG_SUPPLIES(r))
51131082Smarcel
52131082Smarcelvoid
53131082Smarcelfetch_inferior_registers (int regno)
54131082Smarcel{
55131082Smarcel  union {
56131082Smarcel    fpregset_t fpr;
57131082Smarcel    gregset_t r;
58131082Smarcel  } regs;
59131082Smarcel
60131082Smarcel  if (regno == -1 || GREG_SUPPLIES(regno))
61131082Smarcel    {
62131082Smarcel      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
63131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
64131082Smarcel	perror_with_name ("Couldn't get registers");
65132685Smarcel      supply_gregset (&regs.r);
66131082Smarcel    }
67131082Smarcel
68131082Smarcel  if (regno == -1 || FPREG_SUPPLIES(regno))
69131082Smarcel    {
70131082Smarcel      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
71131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
72131082Smarcel	perror_with_name ("Couldn't get FP registers");
73132685Smarcel      supply_fpregset (&regs.fpr);
74131082Smarcel    }
75131082Smarcel}
76131082Smarcel
77131082Smarcelvoid
78131082Smarcelstore_inferior_registers (int regno)
79131082Smarcel{
80131082Smarcel  union {
81131082Smarcel    fpregset_t fpr;
82131082Smarcel    gregset_t r;
83131082Smarcel  } regs;
84131082Smarcel
85131082Smarcel  if (regno == -1 || GREG_SUPPLIES(regno))
86131082Smarcel    {
87131082Smarcel      if (ptrace (PT_GETREGS, PIDGET(inferior_ptid),
88131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
89131082Smarcel	perror_with_name ("Couldn't get registers");
90131082Smarcel      fill_gregset (&regs.r, regno);
91131082Smarcel      if (ptrace (PT_SETREGS, PIDGET(inferior_ptid),
92131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.r, 0) == -1)
93131082Smarcel	perror_with_name ("Couldn't get registers");
94131082Smarcel      if (regno != -1)
95131082Smarcel	return;
96131082Smarcel    }
97131082Smarcel
98131082Smarcel  if (regno == -1 || FPREG_SUPPLIES(regno))
99131082Smarcel    {
100131082Smarcel      if (ptrace (PT_GETFPREGS, PIDGET(inferior_ptid),
101131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
102131082Smarcel	perror_with_name ("Couldn't get FP registers");
103131082Smarcel      fill_fpregset (&regs.fpr, regno);
104131082Smarcel      if (ptrace (PT_SETFPREGS, PIDGET(inferior_ptid),
105131082Smarcel		  (PTRACE_ARG3_TYPE)&regs.fpr, 0) == -1)
106131082Smarcel	perror_with_name ("Couldn't get FP registers");
107131082Smarcel      if (regno != -1)
108131082Smarcel	return;
109131082Smarcel    }
110131082Smarcel}
111131082Smarcel
112131082SmarcelLONGEST ia64_fbsd_xfer_dirty (struct target_ops *ops, enum target_object obj,
113131082Smarcel			      const char *annex, void *rbuf, const void *wbuf,
114131082Smarcel			      ULONGEST ofs, LONGEST len)
115131082Smarcel{
116131082Smarcel  if (len != 8)
117131082Smarcel    return (-1);
118131082Smarcel  if (rbuf != NULL) {
119131082Smarcel    if (ptrace (PT_GETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)rbuf,
120131082Smarcel		ofs >> 3) == -1) {
121131082Smarcel      perror_with_name ("Couldn't read dirty register");
122131082Smarcel      return (-1);
123131082Smarcel    }
124131082Smarcel  } else {
125131082Smarcel    if (ptrace (PT_SETKSTACK, PIDGET(inferior_ptid), (PTRACE_ARG3_TYPE)wbuf,
126131082Smarcel		ofs >> 3) == -1) {
127131082Smarcel      perror_with_name ("Couldn't write dirty register");
128131082Smarcel      return (-1);
129131082Smarcel    }
130131082Smarcel  }
131131082Smarcel  return (len);
132131082Smarcel}
133131082Smarcel
134131082Smarcelvoid
135131082Smarcel_initialize_ia64_fbsd_nat (void)
136131082Smarcel{
137131082Smarcel}
138