root/include/asm/segment.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. get_user_byte
  2. get_user_word
  3. get_user_long
  4. put_user_byte
  5. put_user_word
  6. put_user_long
  7. and_user_long
  8. or_user_long
  9. __generic_memcpy_tofs
  10. __constant_memcpy_tofs
  11. __generic_memcpy_fromfs
  12. __constant_memcpy_fromfs
  13. get_fs
  14. get_ds
  15. set_fs

   1 #ifndef _ASM_SEGMENT_H
   2 #define _ASM_SEGMENT_H
   3 
   4 static inline unsigned char get_user_byte(const char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
   5 {
   6         register unsigned char _v;
   7 
   8         __asm__ ("movb %%fs:%1,%0":"=q" (_v):"m" (*addr));
   9         return _v;
  10 }
  11 
  12 #define get_fs_byte(addr) get_user_byte((char *)(addr))
  13 
  14 static inline unsigned short get_user_word(const short *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  15 {
  16         unsigned short _v;
  17 
  18         __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr));
  19         return _v;
  20 }
  21 
  22 #define get_fs_word(addr) get_user_word((short *)(addr))
  23 
  24 static inline unsigned long get_user_long(const int *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         unsigned long _v;
  27 
  28         __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \
  29         return _v;
  30 }
  31 
  32 #define get_fs_long(addr) get_user_long((int *)(addr))
  33 
  34 static inline void put_user_byte(char val,char *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36 __asm__ ("movb %0,%%fs:%1": /* no outputs */ :"iq" (val),"m" (*addr));
  37 }
  38 
  39 #define put_fs_byte(x,addr) put_user_byte((x),(char *)(addr))
  40 
  41 static inline void put_user_word(short val,short * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43 __asm__ ("movw %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
  44 }
  45 
  46 #define put_fs_word(x,addr) put_user_word((x),(short *)(addr))
  47 
  48 static inline void put_user_long(unsigned long val,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50 __asm__ ("movl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
  51 }
  52 
  53 #define put_fs_long(x,addr) put_user_long((x),(int *)(addr))
  54 
  55 static inline void and_user_long(unsigned long val,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57 __asm__ ("andl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
  58 }
  59 
  60 #define and_fs_long(x,addr) and_user_long((x),(int *)(addr))
  61 
  62 static inline void or_user_long(unsigned long val,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64 __asm__ ("orl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
  65 }
  66 
  67 #define or_fs_long(x,addr) or_user_long((x),(int *)(addr))
  68 
  69 static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71 __asm__("cld\n\t"
  72         "push %%es\n\t"
  73         "push %%fs\n\t"
  74         "pop %%es\n\t"
  75         "testb $1,%%cl\n\t"
  76         "je 1f\n\t"
  77         "movsb\n"
  78         "1:\ttestb $2,%%cl\n\t"
  79         "je 2f\n\t"
  80         "movsw\n"
  81         "2:\tshrl $2,%%ecx\n\t"
  82         "rep ; movsl\n\t"
  83         "pop %%es"
  84         : /* no outputs */
  85         :"c" (n),"D" ((long) to),"S" ((long) from)
  86         :"cx","di","si");
  87 }
  88 
  89 static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91         switch (n) {
  92                 case 0:
  93                         return;
  94                 case 1:
  95                         put_user_byte(*(const char *) from, (char *) to);
  96                         return;
  97                 case 2:
  98                         put_user_word(*(const short *) from, (short *) to);
  99                         return;
 100                 case 3:
 101                         put_user_word(*(const short *) from, (short *) to);
 102                         put_user_byte(*(2+(const char *) from), 2+(char *) to);
 103                         return;
 104                 case 4:
 105                         put_user_long(*(const int *) from, (int *) to);
 106                         return;
 107         }
 108 #define COMMON(x) \
 109 __asm__("cld\n\t" \
 110         "push %%es\n\t" \
 111         "push %%fs\n\t" \
 112         "pop %%es\n\t" \
 113         "rep ; movsl\n\t" \
 114         x \
 115         "pop %%es" \
 116         : /* no outputs */ \
 117         :"c" (n/4),"D" ((long) to),"S" ((long) from) \
 118         :"cx","di","si")
 119 
 120         switch (n % 4) {
 121                 case 0:
 122                         COMMON("");
 123                         return;
 124                 case 1:
 125                         COMMON("movsb\n\t");
 126                         return;
 127                 case 2:
 128                         COMMON("movsw\n\t");
 129                         return;
 130                 case 3:
 131                         COMMON("movsw\n\tmovsb\n\t");
 132                         return;
 133         }
 134 #undef COMMON
 135 }
 136 
 137 static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
 138 {
 139 __asm__("cld\n\t"
 140         "testb $1,%%cl\n\t"
 141         "je 1f\n\t"
 142         "fs ; movsb\n"
 143         "1:\ttestb $2,%%cl\n\t"
 144         "je 2f\n\t"
 145         "fs ; movsw\n"
 146         "2:\tshrl $2,%%ecx\n\t"
 147         "rep ; fs ; movsl"
 148         : /* no outputs */
 149         :"c" (n),"D" ((long) to),"S" ((long) from)
 150         :"cx","di","si","memory");
 151 }
 152 
 153 static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155         switch (n) {
 156                 case 0:
 157                         return;
 158                 case 1:
 159                         *(char *)to = get_user_byte((const char *) from);
 160                         return;
 161                 case 2:
 162                         *(short *)to = get_user_word((const short *) from);
 163                         return;
 164                 case 3:
 165                         *(short *) to = get_user_word((const short *) from);
 166                         *(char *) to = get_user_byte(2+(const char *) from);
 167                         return;
 168                 case 4:
 169                         *(int *) to = get_user_long((const int *) from);
 170                         return;
 171         }
 172 #define COMMON(x) \
 173 __asm__("cld\n\t" \
 174         "rep ; fs ; movsl\n\t" \
 175         x \
 176         : /* no outputs */ \
 177         :"c" (n/4),"D" ((long) to),"S" ((long) from) \
 178         :"cx","di","si","memory")
 179 
 180         switch (n % 4) {
 181                 case 0:
 182                         COMMON("");
 183                         return;
 184                 case 1:
 185                         COMMON("fs ; movsb");
 186                         return;
 187                 case 2:
 188                         COMMON("fs ; movsw");
 189                         return;
 190                 case 3:
 191                         COMMON("fs ; movsw\n\tfs ; movsb");
 192                         return;
 193         }
 194 #undef COMMON
 195 }
 196 
 197 #define memcpy_fromfs(to, from, n) \
 198 (__builtin_constant_p(n) ? \
 199  __constant_memcpy_fromfs((to),(from),(n)) : \
 200  __generic_memcpy_fromfs((to),(from),(n)))
 201 
 202 #define memcpy_tofs(to, from, n) \
 203 (__builtin_constant_p(n) ? \
 204  __constant_memcpy_tofs((to),(from),(n)) : \
 205  __generic_memcpy_tofs((to),(from),(n)))
 206 
 207 /*
 208  * Someone who knows GNU asm better than I should double check the followig.
 209  * It seems to work, but I don't know if I'm doing something subtly wrong.
 210  * --- TYT, 11/24/91
 211  * [ nothing wrong here, Linus: I just changed the ax to be any reg ]
 212  */
 213 
 214 static inline unsigned long get_fs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216         unsigned long _v;
 217         __asm__("mov %%fs,%w0":"=r" (_v):"0" (0));
 218         return _v;
 219 }
 220 
 221 static inline unsigned long get_ds(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 222 {
 223         unsigned long _v;
 224         __asm__("mov %%ds,%w0":"=r" (_v):"0" (0));
 225         return _v;
 226 }
 227 
 228 static inline void set_fs(unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         __asm__ __volatile__("mov %w0,%%fs": /* no output */ :"r" (val));
 231 }
 232 
 233 #endif /* _ASM_SEGMENT_H */

/* [previous][next][first][last][top][bottom][index][help] */