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

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