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