1*5504Slinton /* Copyright (c) 1982 Regents of the University of California */
2*5504Slinton 
3*5504Slinton static char sccsid[] = "@(#)rdwr.c 1.1 01/18/82";
4*5504Slinton 
5*5504Slinton /*
6*5504Slinton  * These routines are used to access the debuggee process from
7*5504Slinton  * outside the "process" module.
8*5504Slinton  *
9*5504Slinton  * They invoke "pio" which eventually leads to a call to "ptrace".
10*5504Slinton  * The system generates an I/O error when a ptrace fails, we catch
11*5504Slinton  * that here and assume its due to a misguided address.
12*5504Slinton  */
13*5504Slinton 
14*5504Slinton #include "defs.h"
15*5504Slinton #include <errno.h>
16*5504Slinton #include "process.h"
17*5504Slinton #include "process.rep"
18*5504Slinton 
19*5504Slinton #	if (isvaxpx)
20*5504Slinton #		include "pxinfo.h"
21*5504Slinton #	endif
22*5504Slinton 
23*5504Slinton typedef int INTFUNC();
24*5504Slinton 
25*5504Slinton extern INTFUNC *onsyserr();
26*5504Slinton 
27*5504Slinton LOCAL badaddr;
28*5504Slinton LOCAL rwerr();
29*5504Slinton 
30*5504Slinton /*
31*5504Slinton  * Read from the process' instruction area.  For px, this is actually
32*5504Slinton  * the data area.
33*5504Slinton  */
34*5504Slinton 
35*5504Slinton iread(buff, addr, nbytes)
36*5504Slinton char *buff;
37*5504Slinton ADDRESS addr;
38*5504Slinton int nbytes;
39*5504Slinton {
40*5504Slinton 	INTFUNC *f;
41*5504Slinton 
42*5504Slinton 	f = onsyserr(EIO, &rwerr);
43*5504Slinton #	if (isvaxpx)
44*5504Slinton 		badaddr = addr + ENDOFF;
45*5504Slinton 		pio(process, PREAD, DATASEG, buff, addr + ENDOFF, nbytes);
46*5504Slinton #	else
47*5504Slinton 		badaddr = addr;
48*5504Slinton 		pio(process, PREAD, TEXTSEG, buff, addr, nbytes);
49*5504Slinton #	endif
50*5504Slinton 	onsyserr(EIO, f);
51*5504Slinton }
52*5504Slinton 
53*5504Slinton /*
54*5504Slinton  * Write to the process' instruction area, usually in order to set
55*5504Slinton  * or unset a breakpoint.
56*5504Slinton  */
57*5504Slinton 
58*5504Slinton iwrite(buff, addr, nbytes)
59*5504Slinton char *buff;
60*5504Slinton ADDRESS addr;
61*5504Slinton int nbytes;
62*5504Slinton {
63*5504Slinton 	INTFUNC *f;
64*5504Slinton 
65*5504Slinton 	f = onsyserr(EIO, &rwerr);
66*5504Slinton #	if (isvaxpx)
67*5504Slinton 		badaddr = addr + ENDOFF;
68*5504Slinton 		pio(process, PWRITE, DATASEG, buff, addr + ENDOFF, nbytes);
69*5504Slinton #	else
70*5504Slinton 		badaddr = addr;
71*5504Slinton 		pio(process, PWRITE, TEXTSEG, buff, addr, nbytes);
72*5504Slinton #	endif
73*5504Slinton 	onsyserr(EIO, f);
74*5504Slinton }
75*5504Slinton 
76*5504Slinton /*
77*5504Slinton  * Read for the process' data area.
78*5504Slinton  */
79*5504Slinton 
80*5504Slinton dread(buff, addr, nbytes)
81*5504Slinton char *buff;
82*5504Slinton ADDRESS addr;
83*5504Slinton int nbytes;
84*5504Slinton {
85*5504Slinton 	INTFUNC *f;
86*5504Slinton 
87*5504Slinton 	f = onsyserr(EIO, &rwerr);
88*5504Slinton 	badaddr = addr;
89*5504Slinton 	pio(process, PREAD, DATASEG, buff, addr, nbytes);
90*5504Slinton 	onsyserr(EIO, f);
91*5504Slinton }
92*5504Slinton 
93*5504Slinton /*
94*5504Slinton  * Write to the process' data area.
95*5504Slinton  */
96*5504Slinton 
97*5504Slinton dwrite(buff, addr, nbytes)
98*5504Slinton char *buff;
99*5504Slinton ADDRESS addr;
100*5504Slinton int nbytes;
101*5504Slinton {
102*5504Slinton 	INTFUNC *f;
103*5504Slinton 
104*5504Slinton 	f = onsyserr(EIO, &rwerr);
105*5504Slinton 	badaddr = addr;
106*5504Slinton 	pio(process, PWRITE, DATASEG, buff, addr, nbytes);
107*5504Slinton 	onsyserr(EIO, f);
108*5504Slinton }
109*5504Slinton 
110*5504Slinton /*
111*5504Slinton  * Error handler.
112*5504Slinton  */
113*5504Slinton 
114*5504Slinton LOCAL rwerr()
115*5504Slinton {
116*5504Slinton 	error("bad read/write process address 0x%x", badaddr);
117*5504Slinton }
118