]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Native support for MIPS running SVR4, for GDB. |
2 | Copyright 1994, 1995 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "inferior.h" | |
23 | #include "gdbcore.h" | |
24 | #include "target.h" | |
25 | ||
26 | #include <sys/time.h> | |
27 | #include <sys/procfs.h> | |
28 | #include <setjmp.h> /* For JB_XXX. */ | |
29 | ||
30 | /* Size of elements in jmpbuf */ | |
31 | ||
32 | #define JB_ELEMENT_SIZE 4 | |
33 | ||
34 | /* | |
35 | * See the comment in m68k-tdep.c regarding the utility of these functions. | |
36 | * | |
37 | * These definitions are from the MIPS SVR4 ABI, so they may work for | |
38 | * any MIPS SVR4 target. | |
39 | */ | |
40 | ||
c5aa993b | 41 | void |
c906108c SS |
42 | supply_gregset (gregsetp) |
43 | gregset_t *gregsetp; | |
44 | { | |
45 | register int regi; | |
46 | register greg_t *regp = &(*gregsetp)[0]; | |
c5aa993b JM |
47 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = |
48 | {0}; | |
c906108c SS |
49 | |
50 | for (regi = 0; regi <= CXT_RA; regi++) | |
c5aa993b | 51 | supply_register (regi, (char *) (regp + regi)); |
c906108c | 52 | |
c5aa993b JM |
53 | supply_register (PC_REGNUM, (char *) (regp + CXT_EPC)); |
54 | supply_register (HI_REGNUM, (char *) (regp + CXT_MDHI)); | |
55 | supply_register (LO_REGNUM, (char *) (regp + CXT_MDLO)); | |
56 | supply_register (CAUSE_REGNUM, (char *) (regp + CXT_CAUSE)); | |
c906108c SS |
57 | |
58 | /* Fill inaccessible registers with zero. */ | |
59 | supply_register (PS_REGNUM, zerobuf); | |
60 | supply_register (BADVADDR_REGNUM, zerobuf); | |
61 | supply_register (FP_REGNUM, zerobuf); | |
62 | supply_register (UNUSED_REGNUM, zerobuf); | |
63 | for (regi = FIRST_EMBED_REGNUM; regi <= LAST_EMBED_REGNUM; regi++) | |
64 | supply_register (regi, zerobuf); | |
65 | } | |
66 | ||
67 | void | |
68 | fill_gregset (gregsetp, regno) | |
69 | gregset_t *gregsetp; | |
70 | int regno; | |
71 | { | |
72 | int regi; | |
73 | register greg_t *regp = &(*gregsetp)[0]; | |
74 | ||
75 | for (regi = 0; regi <= 32; regi++) | |
76 | if ((regno == -1) || (regno == regi)) | |
c5aa993b | 77 | *(regp + regi) = *(greg_t *) & registers[REGISTER_BYTE (regi)]; |
c906108c SS |
78 | |
79 | if ((regno == -1) || (regno == PC_REGNUM)) | |
c5aa993b | 80 | *(regp + CXT_EPC) = *(greg_t *) & registers[REGISTER_BYTE (PC_REGNUM)]; |
c906108c SS |
81 | |
82 | if ((regno == -1) || (regno == CAUSE_REGNUM)) | |
c5aa993b | 83 | *(regp + CXT_CAUSE) = *(greg_t *) & registers[REGISTER_BYTE (CAUSE_REGNUM)]; |
c906108c SS |
84 | |
85 | if ((regno == -1) || (regno == HI_REGNUM)) | |
c5aa993b | 86 | *(regp + CXT_MDHI) = *(greg_t *) & registers[REGISTER_BYTE (HI_REGNUM)]; |
c906108c SS |
87 | |
88 | if ((regno == -1) || (regno == LO_REGNUM)) | |
c5aa993b | 89 | *(regp + CXT_MDLO) = *(greg_t *) & registers[REGISTER_BYTE (LO_REGNUM)]; |
c906108c SS |
90 | } |
91 | ||
92 | /* | |
93 | * Now we do the same thing for floating-point registers. | |
94 | * We don't bother to condition on FP0_REGNUM since any | |
95 | * reasonable MIPS configuration has an R3010 in it. | |
96 | * | |
97 | * Again, see the comments in m68k-tdep.c. | |
98 | */ | |
99 | ||
100 | void | |
101 | supply_fpregset (fpregsetp) | |
102 | fpregset_t *fpregsetp; | |
103 | { | |
104 | register int regi; | |
c5aa993b JM |
105 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = |
106 | {0}; | |
c906108c SS |
107 | |
108 | for (regi = 0; regi < 32; regi++) | |
109 | supply_register (FP0_REGNUM + regi, | |
c5aa993b | 110 | (char *) &fpregsetp->fp_r.fp_regs[regi]); |
c906108c | 111 | |
c5aa993b | 112 | supply_register (FCRCS_REGNUM, (char *) &fpregsetp->fp_csr); |
c906108c SS |
113 | |
114 | /* FIXME: how can we supply FCRIR_REGNUM? The ABI doesn't tell us. */ | |
115 | supply_register (FCRIR_REGNUM, zerobuf); | |
116 | } | |
117 | ||
118 | void | |
119 | fill_fpregset (fpregsetp, regno) | |
120 | fpregset_t *fpregsetp; | |
121 | int regno; | |
122 | { | |
123 | int regi; | |
124 | char *from, *to; | |
125 | ||
126 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) | |
127 | { | |
128 | if ((regno == -1) || (regno == regi)) | |
129 | { | |
130 | from = (char *) ®isters[REGISTER_BYTE (regi)]; | |
131 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); | |
c5aa993b | 132 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
c906108c SS |
133 | } |
134 | } | |
135 | ||
136 | if ((regno == -1) || (regno == FCRCS_REGNUM)) | |
c5aa993b | 137 | fpregsetp->fp_csr = *(unsigned *) ®isters[REGISTER_BYTE (FCRCS_REGNUM)]; |
c906108c SS |
138 | } |
139 | ||
140 | ||
141 | /* Figure out where the longjmp will land. | |
142 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
143 | we extract the pc (_JB_PC) that we will land at. The pc is copied into PC. | |
144 | This routine returns true on success. */ | |
145 | ||
146 | int | |
147 | get_longjmp_target (pc) | |
148 | CORE_ADDR *pc; | |
149 | { | |
150 | char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT]; | |
151 | CORE_ADDR jb_addr; | |
152 | ||
153 | jb_addr = read_register (A0_REGNUM); | |
154 | ||
155 | if (target_read_memory (jb_addr + _JB_PC * JB_ELEMENT_SIZE, buf, | |
156 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
157 | return 0; | |
158 | ||
159 | *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
160 | ||
161 | return 1; | |
162 | } |