- more 2.6.17 port work (still does not build)
[linux-flexiantxendom0-3.2.10.git] / include / asm-x86_64 / kdb.h
1 #ifndef _ASM_KDB_H
2 #define _ASM_KDB_H
3
4 /*
5  * Kernel Debugger Architecture Dependent Global Headers
6  *
7  * This file is subject to the terms and conditions of the GNU General Public
8  * License.  See the file "COPYING" in the main directory of this archive
9  * for more details.
10  *
11  * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
12  */
13
14         /*
15          * KDB_ENTER() is a macro which causes entry into the kernel
16          * debugger from any point in the kernel code stream.  If it
17          * is intended to be used from interrupt level, it must  use
18          * a non-maskable entry method. The vector is KDB_VECTOR,
19          * defined in hw_irq.h
20          */
21 #define KDB_ENTER()     do {if (kdb_on && !KDB_IS_RUNNING()) { asm("\tint $249\n"); }} while(0)
22
23         /*
24          * Needed for exported symbols.
25          */
26 typedef unsigned long kdb_machreg_t;
27
28 #define kdb_machreg_fmt         "0x%lx"
29 #define kdb_machreg_fmt0        "0x%016lx"
30 #define kdb_bfd_vma_fmt         "0x%lx"
31 #define kdb_bfd_vma_fmt0        "0x%016lx"
32 #define kdb_elfw_addr_fmt       "0x%x"
33 #define kdb_elfw_addr_fmt0      "0x%016x"
34
35         /*
36          * Per cpu arch specific kdb state.  Must be in range 0xff000000.
37          */
38 #define KDB_STATE_A_IF          0x01000000      /* Saved IF flag */
39
40         /*
41          * Functions to safely read and write kernel areas.  The {to,from}_xxx
42          * addresses are not necessarily valid, these functions must check for
43          * validity.  If the arch already supports get and put routines with
44          * suitable validation and/or recovery on invalid addresses then use
45          * those routines, otherwise check it yourself.
46          */
47
48         /*
49          * asm-i386 uaccess.h supplies __copy_to_user which relies on MMU to
50          * trap invalid addresses in the _xxx fields.  Verify the other address
51          * of the pair is valid by accessing the first and last byte ourselves,
52          * then any access violations should only be caused by the _xxx
53          * addresses,
54          */
55
56 #include <asm/uaccess.h>
57
58 static inline int
59 __kdba_putarea_size(unsigned long to_xxx, void *from, size_t size)
60 {
61         mm_segment_t oldfs = get_fs();
62         int r;
63         char c;
64         c = *((volatile char *)from);
65         c = *((volatile char *)from + size - 1);
66         
67         if (to_xxx < PAGE_OFFSET) {
68                 return kdb_putuserarea_size(to_xxx, from, size);
69         }
70
71         set_fs(KERNEL_DS);
72         r = __copy_to_user((void *)to_xxx, from, size);
73         set_fs(oldfs);
74         return r;
75 }
76
77 static inline int
78 __kdba_getarea_size(void *to, unsigned long from_xxx, size_t size)
79 {
80         mm_segment_t oldfs = get_fs();
81         int r;
82         *((volatile char *)to) = '\0';
83         *((volatile char *)to + size - 1) = '\0';
84
85         if (from_xxx < PAGE_OFFSET) {
86                 return kdb_getuserarea_size(to, from_xxx, size);
87         }
88
89         set_fs(KERNEL_DS);
90         r = __copy_to_user(to, (void *)from_xxx, size);
91         set_fs(oldfs);
92         return r;
93 }
94
95 /* For numa with replicated code/data, the platform must supply its own
96  * kdba_putarea_size and kdba_getarea_size routines.  Without replication kdb
97  * uses the standard architecture routines.
98  */
99 #ifdef CONFIG_NUMA_REPLICATE
100 extern int kdba_putarea_size(unsigned long to_xxx, void *from, size_t size);
101 extern int kdba_getarea_size(void *to, unsigned long from_xxx, size_t size);
102 #else
103 #define kdba_putarea_size __kdba_putarea_size
104 #define kdba_getarea_size __kdba_getarea_size
105 #endif
106
107 static inline int
108 kdba_verify_rw(unsigned long addr, size_t size)
109 {
110         unsigned char data[size];
111         return(kdba_getarea_size(data, addr, size) || kdba_putarea_size(addr, data, size));
112 }
113
114 static inline unsigned long
115 kdba_funcptr_value(void *fp)
116 {
117         return (unsigned long)fp;
118 }
119
120 #endif  /* !_ASM_KDB_H */