Import 1.3.87
[davej-history.git] / include / asm-mips / segment.h
blobd66607215505728a3d124933a75bdf40e34730c3
1 /*
2 * include/asm-mips/segment.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Copyright (C) 1994, 1995 by Ralf Baechle
10 * Note that the quad functions are only being used for the 64 bit kernel and
11 * therefore it isn't really important that they will be miscompiled for
12 * 32-bit kernels.
14 #ifndef __ASM_MIPS_SEGMENT_H
15 #define __ASM_MIPS_SEGMENT_H
17 #ifndef __LANGUAGE_ASSEMBLY__
19 * For memcpy()
21 #include <linux/string.h>
24 * This is a gcc optimization barrier, which essentially
25 * inserts a sequence point in the gcc RTL tree that gcc
26 * can't move code around. This is needed when we enter
27 * or exit a critical region (in this case around user-level
28 * accesses that may sleep, and we can't let gcc optimize
29 * global state around them).
31 #define __gcc_barrier() __asm__ __volatile__("": : :"memory")
34 * Uh, these should become the main single-value transfer routines..
35 * They automatically use the right size if we just have the right
36 * pointer type..
38 #define put_user(x,ptr) __put_user((unsigned long)(x),(ptr),sizeof(*(ptr)))
39 #define get_user(ptr) ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr))))
42 * This is a silly but good way to make sure that
43 * the __put_user function is indeed always optimized,
44 * and that we use the correct sizes..
46 externintbad_user_access_length(void);
48 /* I should make this use unaligned transfers etc.. */
49 staticinlinevoid__put_user(unsigned long x,void* y,int size)
51 __gcc_barrier();
52 switch(size) {
53 case1:
54 *(char*) y = x;
55 break;
56 case2:
57 *(short*) y = x;
58 break;
59 case4:
60 *(int*) y = x;
61 break;
62 case8:
63 *(long*) y = x;
64 break;
65 default:
66 bad_user_access_length();
68 __gcc_barrier();
71 /* I should make this use unaligned transfers etc.. */
72 staticinlineunsigned long__get_user(const void* y,int size)
74 unsigned long result;
76 __gcc_barrier();
77 switch(size) {
78 case1:
79 result = *(unsigned char*) y;
80 break;
81 case2:
82 result = *(unsigned short*) y;
83 break;
84 case4:
85 result = *(unsigned int*) y;
86 break;
87 case8:
88 result = *(unsigned long*) y;
89 break;
90 default:
91 result =bad_user_access_length();
92 break;
94 __gcc_barrier();
96 return result;
99 #define get_fs_byte(addr) get_user((unsigned char *)(addr))
100 #define get_fs_word(addr) get_user((unsigned short *)(addr))
101 #define get_fs_long(addr) get_user((unsigned int *)(addr))
102 #define get_fs_quad(addr) get_user((unsigned long *)(addr))
104 #define put_fs_byte(x,addr) put_user((x),(char *)(addr))
105 #define put_fs_word(x,addr) put_user((x),(short *)(addr))
106 #define put_fs_long(x,addr) put_user((x),(int *)(addr))
107 #define put_fs_quad(x,addr) put_user((x),(long *)(addr))
109 staticinlinevoidmemcpy_fromfs(void* to,const void* from,unsigned long n)
111 __gcc_barrier();
112 memcpy(to, from, n);
113 __gcc_barrier();
116 staticinlinevoidmemcpy_tofs(void* to,const void* from,unsigned long n)
118 __gcc_barrier();
119 memcpy(to, from, n);
120 __gcc_barrier();
124 * For segmented architectures, these are used to specify which segment
125 * to use for the above functions.
127 * MIPS is not segmented, so these are just dummies.
130 #define KERNEL_DS 0
131 #define USER_DS 1
133 staticinlineunsigned longget_fs(void)
135 return USER_DS;
138 staticinlineunsigned longget_ds(void)
140 return KERNEL_DS;
143 staticinlinevoidset_fs(unsigned long val)
147 #endif/* !__LANGUAGE_ASSEMBLY__ */
150 * Memory segments (32bit kernel mode addresses)
152 #define KUSEG 0x00000000
153 #define KSEG0 0x80000000
154 #define KSEG1 0xa0000000
155 #define KSEG2 0xc0000000
156 #define KSEG3 0xe0000000
159 * Returns the kernel segment base of a given address
161 #define KSEGX(a) (((unsigned long)(a)) & 0xe0000000)
164 * Returns the physical address of a KSEG0/KSEG1 address
166 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
169 * Map an address to a certain kernel segment
171 #define KSEG0ADDR(a) ((((unsigned long)(a)) & 0x1fffffff) | KSEG0)
172 #define KSEG1ADDR(a) ((((unsigned long)(a)) & 0x1fffffff) | KSEG1)
173 #define KSEG2ADDR(a) ((((unsigned long)(a)) & 0x1fffffff) | KSEG2)
174 #define KSEG3ADDR(a) ((((unsigned long)(a)) & 0x1fffffff) | KSEG3)
177 * Memory segments (64bit kernel mode addresses)
179 #define XKUSEG 0x0000 0000 0000 0000
180 #define XKSSEG 0x4000 0000 0000 0000
181 #define XKPHYS 0x8000 0000 0000 0000
182 #define XKSEG 0xc000 0000 0000 0000
183 #define CKSEG0 0xffff ffff 8000 0000
184 #define CKSEG1 0xffff ffff a000 0000
185 #define CKSSEG 0xffff ffff c000 0000
186 #define CKSEG3 0xffff ffff e000 0000
188 #endif/* __ASM_MIPS_SEGMENT_H */
close