home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / vmount-0.6a-I / src / my_include / asm / segment.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-14  |  3.5 KB  |  160 lines

  1. /*
  2.  * Name: segment.h
  3.  * Description: asm/segment.h from Linux, but get_fs() get_ds() and set_fs()
  4.  *     replaced with dummy functions.
  5.  * Modified: Christian Starkjohann <cs@hal.kph.tuwien.ac.at>
  6.  * Date: 1996-11-14
  7.  * Copyright: GNU-GPL
  8.  * Tabsize: 4
  9.  */
  10.  
  11. #ifndef _ASM_SEGMENT_H
  12. #define _ASM_SEGMENT_H
  13.  
  14. #define KERNEL_CS    0x10
  15. #define KERNEL_DS    0x18
  16.  
  17. #define USER_CS        0x23
  18. #define USER_DS        0x2B
  19.  
  20. #ifndef __ASSEMBLY__
  21.  
  22. /*
  23.  * Uh, these should become the main single-value transfer routines..
  24.  * They automatically use the right size if we just have the right
  25.  * pointer type..
  26.  */
  27. #define put_user(x,ptr) __put_user((unsigned long)(x),(ptr),sizeof(*(ptr)))
  28. #define get_user(ptr) ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr))))
  29.  
  30. /*
  31.  * This is a silly but good way to make sure that
  32.  * the __put_user function is indeed always optimized,
  33.  * and that we use the correct sizes..
  34.  */
  35. extern int bad_user_access_length(void);
  36.  
  37. /*
  38.  * dummy pointer type structure.. gcc won't try to do something strange
  39.  * this way..
  40.  */
  41. struct __segment_dummy { unsigned long a[100]; };
  42. #define __sd(x) ((struct __segment_dummy *) (x))
  43. #define __const_sd(x) ((const struct __segment_dummy *) (x))
  44.  
  45.  
  46. static inline void __put_user(unsigned long x, void * y, int size)
  47. {
  48.     switch (size) {
  49.         case 1:
  50.             *(char *)y = (char)x;
  51.             break;
  52.         case 2:
  53.             *(short *)y = (short)x;
  54.             break;
  55.         case 4:
  56.             *(long *)y = (long)x;
  57.             break;
  58.         default:
  59.             bad_user_access_length();
  60.     }
  61. }
  62.  
  63. static inline unsigned long __get_user(const void * y, int size)
  64. {
  65.     switch (size) {
  66.         case 1:
  67.             return *(unsigned char *)y;
  68.         case 2:
  69.             return *(unsigned short *)y;
  70.         case 4:
  71.             return *(unsigned long *)y;
  72.         default:
  73.             return bad_user_access_length();
  74.     }
  75. }
  76.  
  77.  
  78. #define memcpy_fromfs(to, from, n)    memcpy(to, from, n)
  79.  
  80. #define memcpy_tofs(to, from, n)    memcpy(to, from, n)
  81.  
  82. /*
  83.  * These are deprecated..
  84.  *
  85.  * Use "put_user()" and "get_user()" with the proper pointer types instead.
  86.  */
  87.  
  88. #define get_fs_byte(addr) __get_user((const unsigned char *)(addr),1)
  89. #define get_fs_word(addr) __get_user((const unsigned short *)(addr),2)
  90. #define get_fs_long(addr) __get_user((const unsigned int *)(addr),4)
  91.  
  92. #define put_fs_byte(x,addr) __put_user((x),(unsigned char *)(addr),1)
  93. #define put_fs_word(x,addr) __put_user((x),(unsigned short *)(addr),2)
  94. #define put_fs_long(x,addr) __put_user((x),(unsigned int *)(addr),4)
  95.  
  96. #ifdef WE_REALLY_WANT_TO_USE_A_BROKEN_INTERFACE
  97.  
  98. static inline unsigned short get_user_word(const short *addr)
  99. {
  100.     return __get_user(addr, 2);
  101. }
  102.  
  103. static inline unsigned char get_user_byte(const char * addr)
  104. {
  105.     return __get_user(addr,1);
  106. }
  107.  
  108. static inline unsigned long get_user_long(const int *addr)
  109. {
  110.     return __get_user(addr, 4);
  111. }
  112.  
  113. static inline void put_user_byte(char val,char *addr)
  114. {
  115.     __put_user(val, addr, 1);
  116. }
  117.  
  118. static inline void put_user_word(short val,short * addr)
  119. {
  120.     __put_user(val, addr, 2);
  121. }
  122.  
  123. static inline void put_user_long(unsigned long val,int * addr)
  124. {
  125.     __put_user(val, addr, 4);
  126. }
  127.  
  128. #endif
  129.  
  130. /*
  131.  * Someone who knows GNU asm better than I should double check the following.
  132.  * It seems to work, but I don't know if I'm doing something subtly wrong.
  133.  * --- TYT, 11/24/91
  134.  * [ nothing wrong here, Linus: I just changed the ax to be any reg ]
  135.  */
  136.  
  137. extern int    printf(const char *fmt, ...);
  138.  
  139. static inline unsigned long get_fs(void)
  140. {
  141. /*    printf("get_fs()\n"); */
  142.     return KERNEL_DS;
  143. }
  144.  
  145. static inline unsigned long get_ds(void)
  146. {
  147. /*    printf("get_ds()\n"); */
  148.     return KERNEL_DS;
  149. }
  150.  
  151. static inline void set_fs(unsigned long val)
  152. {
  153.     printf("*** set_fs()\n");
  154.     abort();
  155. }
  156.  
  157. #endif /* __ASSEMBLY__ */
  158.  
  159. #endif /* _ASM_SEGMENT_H */
  160.