1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1996, 1997, 1998, 1999, 2000 by Ralf Baechle
7  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8  *
9  * Protected memory access.  Used for everything that might take revenge
10  * by sending a DBE error like accessing possibly non-existant memory or
11  * devices.
12  */
13 #ifndef _ASM_PACCESS_H
14 #define _ASM_PACCESS_H
15 
16 #include <linux/errno.h>
17 
18 #define put_dbe(x,ptr) __put_dbe((x),(ptr),sizeof(*(ptr)))
19 #define get_dbe(x,ptr) __get_dbe((x),(ptr),sizeof(*(ptr)))
20 
21 struct __large_pstruct { unsigned long buf[100]; };
22 #define __mp(x) (*(struct __large_pstruct *)(x))
23 
24 #define __get_dbe(x,ptr,size) ({ \
25 long __gu_err; \
26 __typeof(*(ptr)) __gu_val; \
27 long __gu_addr; \
28 __asm__("":"=r" (__gu_val)); \
29 __gu_addr = (long) (ptr); \
30 __asm__("":"=r" (__gu_err)); \
31 switch (size) { \
32 case 1: __get_dbe_asm("lb"); break; \
33 case 2: __get_dbe_asm("lh"); break; \
34 case 4: __get_dbe_asm("lw"); break; \
35 case 8:  __get_dbe_asm("ld"); break; \
36 default: __get_dbe_unknown(); break; \
37 } x = (__typeof__(*(ptr))) __gu_val; __gu_err; })
38 
39 #define __get_dbe_asm(insn) \
40 ({ \
41 __asm__ __volatile__( \
42 	"1:\t" insn "\t%1,%2\n\t" \
43 	"move\t%0,$0\n" \
44 	"2:\n\t" \
45 	".section\t.fixup,\"ax\"\n" \
46 	"3:\tli\t%0,%3\n\t" \
47 	"move\t%1,$0\n\t" \
48 	"j\t2b\n\t" \
49 	".previous\n\t" \
50 	".section\t__dbe_table,\"a\"\n\t" \
51 	".dword\t1b,3b\n\t" \
52 	".previous" \
53 	:"=r" (__gu_err), "=r" (__gu_val) \
54 	:"o" (__mp(__gu_addr)), "i" (-EFAULT)); })
55 
56 extern void __get_dbe_unknown(void);
57 
58 #define __put_dbe(x,ptr,size) ({ \
59 long __pu_err; \
60 __typeof__(*(ptr)) __pu_val; \
61 long __pu_addr; \
62 __pu_val = (x); \
63 __pu_addr = (long) (ptr); \
64 __asm__("":"=r" (__pu_err)); \
65 switch (size) { \
66 case 1: __put_dbe_asm("sb"); break; \
67 case 2: __put_dbe_asm("sh"); break; \
68 case 4: __put_dbe_asm("sw"); break; \
69 case 8: __put_dbe_asm("sd"); break; \
70 default: __put_dbe_unknown(); break; \
71 } __pu_err; })
72 
73 #define __put_dbe_asm(insn) \
74 ({ \
75 __asm__ __volatile__( \
76 	"1:\t" insn "\t%1,%2\n\t" \
77 	"move\t%0,$0\n" \
78 	"2:\n\t" \
79 	".section\t.fixup,\"ax\"\n" \
80 	"3:\tli\t%0,%3\n\t" \
81 	"j\t2b\n\t" \
82 	".previous\n\t" \
83 	".section\t__dbe_table,\"a\"\n\t" \
84 	".dword\t1b,3b\n\t" \
85 	".previous" \
86 	:"=r" (__pu_err) \
87 	:"r" (__pu_val), "o" (__mp(__pu_addr)), "i" (-EFAULT)); })
88 
89 extern void __put_dbe_unknown(void);
90 
91 #endif /* _ASM_PACCESS_H */
92