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