| 1 | /* Native support for MIPS running SVR4, for GDB. |
| 2 | Copyright 1994, 1995 Free Software Foundation, Inc. |
| 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 |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 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]; |
| 46 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0}; |
| 47 | |
| 48 | for (regi = 0; regi <= CXT_RA; regi++) |
| 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)); |
| 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); |
| 60 | for (regi = FIRST_EMBED_REGNUM; regi <= LAST_EMBED_REGNUM; regi++) |
| 61 | supply_register (regi, zerobuf); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | fill_gregset (gregsetp, regno) |
| 66 | gregset_t *gregsetp; |
| 67 | int regno; |
| 68 | { |
| 69 | int regi; |
| 70 | register greg_t *regp = &(*gregsetp)[0]; |
| 71 | |
| 72 | for (regi = 0; regi <= 32; regi++) |
| 73 | if ((regno == -1) || (regno == regi)) |
| 74 | *(regp + regi) = *(greg_t *) ®isters[REGISTER_BYTE (regi)]; |
| 75 | |
| 76 | if ((regno == -1) || (regno == PC_REGNUM)) |
| 77 | *(regp + CXT_EPC) = *(greg_t *) ®isters[REGISTER_BYTE (PC_REGNUM)]; |
| 78 | |
| 79 | if ((regno == -1) || (regno == CAUSE_REGNUM)) |
| 80 | *(regp + CXT_CAUSE) = *(greg_t *) ®isters[REGISTER_BYTE (CAUSE_REGNUM)]; |
| 81 | |
| 82 | if ((regno == -1) || (regno == HI_REGNUM)) |
| 83 | *(regp + CXT_MDHI) = *(greg_t *) ®isters[REGISTER_BYTE (HI_REGNUM)]; |
| 84 | |
| 85 | if ((regno == -1) || (regno == LO_REGNUM)) |
| 86 | *(regp + CXT_MDLO) = *(greg_t *) ®isters[REGISTER_BYTE (LO_REGNUM)]; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Now we do the same thing for floating-point registers. |
| 91 | * We don't bother to condition on FP0_REGNUM since any |
| 92 | * reasonable MIPS configuration has an R3010 in it. |
| 93 | * |
| 94 | * Again, see the comments in m68k-tdep.c. |
| 95 | */ |
| 96 | |
| 97 | void |
| 98 | supply_fpregset (fpregsetp) |
| 99 | fpregset_t *fpregsetp; |
| 100 | { |
| 101 | register int regi; |
| 102 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0}; |
| 103 | |
| 104 | for (regi = 0; regi < 32; regi++) |
| 105 | supply_register (FP0_REGNUM + regi, |
| 106 | (char *)&fpregsetp->fp_r.fp_regs[regi]); |
| 107 | |
| 108 | supply_register (FCRCS_REGNUM, (char *)&fpregsetp->fp_csr); |
| 109 | |
| 110 | /* FIXME: how can we supply FCRIR_REGNUM? The ABI doesn't tell us. */ |
| 111 | supply_register (FCRIR_REGNUM, zerobuf); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | fill_fpregset (fpregsetp, regno) |
| 116 | fpregset_t *fpregsetp; |
| 117 | int regno; |
| 118 | { |
| 119 | int regi; |
| 120 | char *from, *to; |
| 121 | |
| 122 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) |
| 123 | { |
| 124 | if ((regno == -1) || (regno == regi)) |
| 125 | { |
| 126 | from = (char *) ®isters[REGISTER_BYTE (regi)]; |
| 127 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); |
| 128 | memcpy(to, from, REGISTER_RAW_SIZE (regi)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if ((regno == -1) || (regno == FCRCS_REGNUM)) |
| 133 | fpregsetp->fp_csr = *(unsigned *) ®isters[REGISTER_BYTE(FCRCS_REGNUM)]; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /* Figure out where the longjmp will land. |
| 138 | We expect the first arg to be a pointer to the jmp_buf structure from which |
| 139 | we extract the pc (_JB_PC) that we will land at. The pc is copied into PC. |
| 140 | This routine returns true on success. */ |
| 141 | |
| 142 | int |
| 143 | get_longjmp_target (pc) |
| 144 | CORE_ADDR *pc; |
| 145 | { |
| 146 | char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT]; |
| 147 | CORE_ADDR jb_addr; |
| 148 | |
| 149 | jb_addr = read_register (A0_REGNUM); |
| 150 | |
| 151 | if (target_read_memory (jb_addr + _JB_PC * JB_ELEMENT_SIZE, buf, |
| 152 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) |
| 153 | return 0; |
| 154 | |
| 155 | *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
| 156 | |
| 157 | return 1; |
| 158 | } |