]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - gnu/usr.bin/binutils/gdb/kvm-fbsd-i386.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / gnu / usr.bin / binutils / gdb / kvm-fbsd-i386.h
1 /* Kernel core dump functions below target vector, for GDB on FreeBSD/i386.
2    Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
3    Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 __FBSDID("$FreeBSD$");
23
24 #include <machine/frame.h>
25
26 static CORE_ADDR
27 ksym_maxuseraddr (void)
28 {
29   static CORE_ADDR maxuseraddr;
30   struct minimal_symbol *sym;
31
32   if (maxuseraddr == 0)
33     {
34       sym = lookup_minimal_symbol ("PTmap", NULL, NULL);
35       if (sym == NULL) {
36         maxuseraddr = VM_MAXUSER_ADDRESS;
37       } else {
38         maxuseraddr = SYMBOL_VALUE_ADDRESS (sym);
39       }
40     }
41   return maxuseraddr;
42 }
43
44
45 /* Symbol names of kernel entry points.  Use special frames.  */
46 #define KSYM_TRAP       "calltrap"
47 #define KSYM_INTR       "Xintr"
48 #define KSYM_FASTINTR   "Xfastintr"
49 #define KSYM_OLDSYSCALL "Xlcall_syscall"
50 #define KSYM_SYSCALL    "Xint0x80_syscall"
51
52 /* The following is FreeBSD-specific hackery to decode special frames
53    and elide the assembly-language stub.  This could be made faster by
54    defining a frame_type field in the machine-dependent frame information,
55    but we don't think that's too important right now.  */
56 enum frametype { tf_normal, tf_trap, tf_interrupt, tf_syscall };
57
58 CORE_ADDR
59 fbsd_kern_frame_saved_pc (struct frame_info *fi)
60 {
61   struct minimal_symbol *sym;
62   CORE_ADDR this_saved_pc;
63   enum frametype frametype;
64
65   this_saved_pc = read_memory_integer (fi->frame + 4, 4);
66   sym = lookup_minimal_symbol_by_pc (this_saved_pc);
67   frametype = tf_normal;
68   if (sym != NULL)
69     {
70       if (strcmp (SYMBOL_NAME (sym), KSYM_TRAP) == 0)
71         frametype = tf_trap;
72       else
73         if (strncmp (SYMBOL_NAME (sym), KSYM_INTR,
74             strlen (KSYM_INTR)) == 0 || strncmp (SYMBOL_NAME(sym),
75             KSYM_FASTINTR, strlen (KSYM_FASTINTR)) == 0)
76           frametype = tf_interrupt;
77       else
78         if (strcmp (SYMBOL_NAME (sym), KSYM_SYSCALL) == 0 ||
79             strcmp (SYMBOL_NAME (sym), KSYM_OLDSYSCALL) == 0)
80           frametype = tf_syscall;
81     }
82
83   switch (frametype)
84     {
85       case tf_normal:
86         return (this_saved_pc);
87 #define oEIP   offsetof (struct trapframe, tf_eip)
88
89       case tf_trap:
90         return (read_memory_integer (fi->frame + 8 + oEIP, 4));
91
92       case tf_interrupt:
93         return (read_memory_integer (fi->frame + 12 + oEIP, 4));
94
95       case tf_syscall:
96         return (read_memory_integer (fi->frame + 8 + oEIP, 4));
97 #undef oEIP
98     }
99 }
100
101 static void
102 fetch_kcore_registers (struct pcb *pcb)
103 {
104   int i;
105   int noreg;
106
107   /* Get the register values out of the sys pcb and store them where
108      `read_register' will find them.  */
109   /*
110    * XXX many registers aren't available.
111    * XXX for the non-core case, the registers are stale - they are for
112    *     the last context switch to the debugger.
113    * XXX gcc's register numbers aren't all #defined in tm-i386.h.
114    */
115   noreg = 0;
116   for (i = 0; i < 3; ++i)               /* eax,ecx,edx */
117     supply_register (i, (char *)&noreg);
118
119   supply_register (3, (char *) &pcb->pcb_ebx);
120   supply_register (SP_REGNUM, (char *) &pcb->pcb_esp);
121   supply_register (FP_REGNUM, (char *) &pcb->pcb_ebp);
122   supply_register (6, (char *) &pcb->pcb_esi);
123   supply_register (7, (char *) &pcb->pcb_edi);
124   supply_register (PC_REGNUM, (char *) &pcb->pcb_eip);
125
126   for (i = 9; i < 14; ++i)              /* eflags, cs, ss, ds, es, fs */
127     supply_register (i, (char *) &noreg);
128   supply_register (15, (char *) &pcb->pcb_gs);
129
130   /* XXX 80387 registers?  */
131 }