root/include/asm-mips/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. get_user_dlong
  5. put_user_byte
  6. put_user_word
  7. put_user_long
  8. put_user_dlong
  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 /*
   2  * include/asm-mips/segment.h
   3  *
   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.
   7  *
   8  * Copyright (C) 1994 by Ralf Baechle
   9  *
  10  */
  11 
  12 #ifndef _ASM_MIPS_SEGMENT_H_
  13 #define _ASM_MIPS_SEGMENT_H_
  14 
  15 static inline unsigned char get_user_byte(const char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17         register unsigned char _v;
  18 
  19         __asm__ ("lbu\t%0,%1":"=r" (_v):"r" (*addr));
  20 
  21         return _v;
  22 }
  23 
  24 #define get_fs_byte(addr) get_user_byte((char *)(addr))
  25 
  26 static inline unsigned short get_user_word(const short *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28         unsigned short _v;
  29 
  30         __asm__ ("lhu\t%0,%1":"=r" (_v):"r" (*addr));
  31 
  32         return _v;
  33 }
  34 
  35 #define get_fs_word(addr) get_user_word((short *)(addr))
  36 
  37 static inline unsigned long get_user_long(const int *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39         unsigned long _v;
  40 
  41         __asm__ ("lwu\t%0,%1":"=r" (_v):"r" (*addr)); \
  42         return _v;
  43 }
  44 
  45 #define get_fs_long(addr) get_user_long((int *)(addr))
  46 
  47 static inline unsigned long get_user_dlong(const int *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         unsigned long _v;
  50 
  51         __asm__ ("ld\t%0,%1":"=r" (_v):"r" (*addr)); \
  52         return _v;
  53 }
  54 
  55 #define get_fs_dlong(addr) get_user_dlong((int *)(addr))
  56 
  57 static inline void put_user_byte(char val,char *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59 __asm__ ("sb\t%0,%1": /* no outputs */ :"r" (val),"r" (*addr));
  60 }
  61 
  62 #define put_fs_byte(x,addr) put_user_byte((x),(char *)(addr))
  63 
  64 static inline void put_user_word(short val,short * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66 __asm__ ("sh\t%0,%1": /* no outputs */ :"r" (val),"r" (*addr));
  67 }
  68 
  69 #define put_fs_word(x,addr) put_user_word((x),(short *)(addr))
  70 
  71 static inline void put_user_long(unsigned long val,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73 __asm__ ("sw\t%0,%1": /* no outputs */ :"r" (val),"r" (*addr));
  74 }
  75 
  76 #define put_fs_long(x,addr) put_user_long((x),(int *)(addr))
  77 
  78 static inline void put_user_dlong(unsigned long val,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80 __asm__ ("sd\t%0,%1": /* no outputs */ :"r" (val),"r" (*addr));
  81 }
  82 
  83 #define put_fs_dlong(x,addr) put_user_dlong((x),(int *)(addr))
  84 
  85 /*
  86  * These following two variables are defined in mips/head.S.
  87  */
  88 extern unsigned long segment_fs;
  89 
  90 static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92   __asm__(
  93         ".set\tnoreorder\n\t"
  94         ".set\tnoat\n"
  95         "1:\tlbu\t$1,(%2)\n\t"
  96         "addiu\t%2,%2,1\n\t"
  97         "sb\t$1,(%1)\n\t"
  98         "addiu\t%0,%0,-1\n\t"
  99         "bne\t$0,%0,1b\n\t"
 100         "addiu\t%1,%1,1\n\t"
 101         ".set\tat\n\t"
 102         ".set\treorder"
 103         : /* no outputs */
 104         :"d" (n),"d" (((long) to)| segment_fs),"d" ((long) from)
 105         :"$1");
 106 }
 107 
 108 static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110         /*
 111          * Use put_user_byte to avoid trouble with alignment.
 112          */
 113         switch (n) {
 114                 case 0:
 115                         return;
 116                 case 1:
 117                         put_user_byte(*(const char *) from, (char *) to);
 118                         return;
 119                 case 2:
 120                         put_user_byte(*(const char *) from, (char *) to);
 121                         put_user_byte(*(1+(const char *) from), 1+(char *) to);
 122                         return;
 123                 case 3:
 124                         put_user_byte(*((const char *) from), (char *) to);
 125                         put_user_byte(*(1+(const char *) from), 1+(char *) to);
 126                         put_user_byte(*(2+(const char *) from), 2+(char *) to);
 127                         return;
 128                 case 4:
 129                         put_user_byte(*((const char *) from), (char *) to);
 130                         put_user_byte(*(1+(const char *) from), 1+(char *) to);
 131                         put_user_byte(*(2+(const char *) from), 2+(char *) to);
 132                         put_user_byte(*(3+(const char *) from), 3+(char *) to);
 133                         return;
 134         }
 135 
 136         __generic_memcpy_tofs(to, from, n);
 137 
 138         return;
 139 }
 140 
 141 static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143   __asm__(
 144         ".set\tnoreorder\n\t"
 145         ".set\tnoat\n"
 146         "1:\tlbu\t$1,(%2)\n\t"
 147         "addiu\t%2,%2,1\n\t"
 148         "sb\t$1,(%1)\n\t"
 149         "addiu\t%0,%0,-1\n\t"
 150         "bne\t$0,%0,1b\n\t"
 151         "addiu\t%1,%1,1\n\t"
 152         ".set\tat\n\t"
 153         ".set\treorder"
 154         : /* no outputs */
 155         :"d" (n),"d" ((long) to),"d" (((long) from | segment_fs))
 156         :"$1","memory");
 157 }
 158 
 159 static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         /*
 162          * Use put_user_byte to avoid trouble with alignment.
 163          */
 164         switch (n) {
 165                 case 0:
 166                         return;
 167                 case 1:
 168                         *(char *)to = get_user_byte((const char *) from);
 169                         return;
 170                 case 2:
 171                         *(char *) to = get_user_byte((const char *) from);
 172                         *(char *) to = get_user_byte(1+(const char *) from);
 173                         return;
 174                 case 3:
 175                         *(char *) to = get_user_byte((const char *) from);
 176                         *(char *) to = get_user_byte(1+(const char *) from);
 177                         *(char *) to = get_user_byte(2+(const char *) from);
 178                         return;
 179                 case 4:
 180                         *(char *) to = get_user_byte((const char *) from);
 181                         *(char *) to = get_user_byte(1+(const char *) from);
 182                         *(char *) to = get_user_byte(2+(const char *) from);
 183                         *(char *) to = get_user_byte(3+(const char *) from);
 184                         return;
 185         }
 186 
 187         
 188         __generic_memcpy_fromfs(to, from, n);
 189         return;
 190 }
 191 
 192 #define memcpy_fromfs(to, from, n) \
 193 (__builtin_constant_p(n) ? \
 194  __constant_memcpy_fromfs((to),(from),(n)) : \
 195  __generic_memcpy_fromfs((to),(from),(n)))
 196 
 197 #define memcpy_tofs(to, from, n) \
 198 (__builtin_constant_p(n) ? \
 199  __constant_memcpy_tofs((to),(from),(n)) : \
 200  __generic_memcpy_tofs((to),(from),(n)))
 201 
 202 static inline unsigned long get_fs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 203 {
 204         return segment_fs;
 205 }
 206 
 207 static inline unsigned long get_ds(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 208 {
 209         return KERNEL_DS;
 210 }
 211 
 212 static inline void set_fs(unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 213 {
 214         segment_fs = val;
 215 }
 216 
 217 #endif /* _ASM_MIPS_SEGMENT_H_ */

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