Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | #ifndef _M68K_SEGMENT_H #define _M68K_SEGMENT_H /* define constants */ /* Address spaces (FC0-FC2) */ #define USER_DATA (1) #ifndef USER_DS #define USER_DS (USER_DATA) #endif #define USER_PROGRAM (2) #define SUPER_DATA (5) #ifndef KERNEL_DS #define KERNEL_DS (SUPER_DATA) #endif #define SUPER_PROGRAM (6) #define CPU_SPACE (7) #ifndef __ASSEMBLY__ /* * Uh, these should become the main single-value transfer routines.. * They automatically use the right size if we just have the right * pointer type.. */ #define put_user(x,ptr) __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))) #define get_user(ptr) ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))) /* * This is a silly but good way to make sure that * the __put_user function is indeed always optimized, * and that we use the correct sizes.. */ extern int bad_user_access_length(void); #define __ptr(x) ((unsigned long *)(x)) static inline void __put_user(unsigned long x, void * y, int size) { switch (size) { case 1: __asm__ ("movesb %0,%1" : /* no outputs */ :"r" (x),"m" (*__ptr(y)) : "memory"); break; case 2: __asm__ ("movesw %0,%1" : /* no outputs */ :"r" (x),"m" (*__ptr(y)) : "memory"); break; case 4: __asm__ ("movesl %0,%1" : /* no outputs */ :"r" (x),"m" (*__ptr(y)) : "memory"); break; default: bad_user_access_length(); } } static inline unsigned long __get_user(const void * y, int size) { unsigned long result; switch (size) { case 1: __asm__ ("movesb %1,%0" :"=r" (result) :"m" (*__ptr(y))); return (unsigned char) result; case 2: __asm__ ("movesw %1,%0" :"=r" (result) :"m" (*__ptr(y))); return (unsigned short) result; case 4: __asm__ ("movesl %1,%0" :"=r" (result) :"m" (*__ptr(y))); return result; default: return bad_user_access_length(); } } #undef __ptr /* * These are deprecated.. * * Use "put_user()" and "get_user()" with the proper pointer types instead. */ #define get_fs_byte(addr) __get_user((const unsigned char *)(addr),1) #define get_fs_word(addr) __get_user((const unsigned short *)(addr),2) #define get_fs_long(addr) __get_user((const unsigned int *)(addr),4) #define put_fs_byte(x,addr) __put_user((x),(unsigned char *)(addr),1) #define put_fs_word(x,addr) __put_user((x),(unsigned short *)(addr),2) #define put_fs_long(x,addr) __put_user((x),(unsigned int *)(addr),4) #ifdef WE_REALLY_WANT_TO_USE_A_BROKEN_INTERFACE static inline unsigned char get_user_byte(const char * addr) { return __get_user(addr,1); } static inline unsigned short get_user_word(const short *addr) { return __get_user(addr,2); } static inline unsigned long get_user_long(const int *addr) { return __get_user(addr,4); } static inline void put_user_byte(char val,char *addr) { __put_user(val, addr, 1); } static inline void put_user_word(short val,short * addr) { __put_user(val, addr, 2); } static inline void put_user_long(unsigned long val,int * addr) { __put_user(val, addr, 4); } #endif static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n) { unsigned long tmp; if (n == 0) return; tmp = n; n >>= 2; if (n != 0) __asm__ ("1:\t" "movel %1@+,%/d0\n\t" "movesl %/d0,%2@+\n\t" "dbra %0,1b\n\t" "clrw %0\n\t" "subql #1,%0\n\t" "bccs 1b\n\t" : "=d" (n), "=a" (from), "=a" (to) : "0" (n-1), "1" (from), "2" (to) : "d0", "memory"); if (tmp & 2) __asm__ ("movew %0@+,%/d0\n\t" "movesw %/d0,%1@+\n\t" : "=a" (from), "=a" (to) : "0" (from), "1" (to) : "d0", "memory"); if (tmp & 1) __asm__ __volatile__ ("moveb %0@,%/d0\n\t" "movesb %/d0,%1@\n\t" : /* no outputs */ : "a" (from), "a" (to) : "d0", "memory"); } static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n) { switch (n) { case 0: return; case 1: __put_user(*(const char *) from, (char *) to, 1); return; case 2: __put_user(*(const short *) from, (short *) to, 2); return; case 3: __put_user(*(const short *) from, (short *) to, 2); __put_user(*(2+(const char *) from), 2+(char *) to, 1); return; case 4: __put_user(*(const int *) from, (int *) to, 4); return; case 8: __put_user(*(const int *) from, (int *) to, 4); __put_user(*(1+(const int *) from), 1+(int *) to, 4); return; case 12: __put_user(*(const int *) from, (int *) to, 4); __put_user(*(1+(const int *) from), 1+(int *) to, 4); __put_user(*(2+(const int *) from), 2+(int *) to, 4); return; case 16: __put_user(*(const int *) from, (int *) to, 4); __put_user(*(1+(const int *) from), 1+(int *) to, 4); __put_user(*(2+(const int *) from), 2+(int *) to, 4); __put_user(*(3+(const int *) from), 3+(int *) to, 4); return; } #define COMMON(x) \ __asm__ __volatile__ ("1:\n\t" \ "movel %1@+,%/d0\n\t" \ "movesl %/d0,%2@+\n\t" \ "dbra %0,1b\n\t" \ "clrw %0\n\t" \ "subql #1,%0\n\t" \ "bccs 1b\n\t" \ x \ : "=d" (n), "=a" (from), "=a" (to) \ : "1" (from), "2" (to), "0" (n/4-1) \ : "d0", "memory"); switch (n % 4) { case 0: COMMON(""); return; case 1: COMMON("moveb %1@+,%/d0; movesb %/d0,%2@+"); return; case 2: COMMON("movew %1@+,%/d0; movesw %/d0,%2@+"); return; case 3: COMMON("movew %1@+,%/d0; movesw %/d0,%2@+\n\t" "moveb %1@+,%/d0; movesb %/d0,%2@+"); return; } #undef COMMON } static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n) { unsigned long tmp; if (n == 0) return; tmp = n; n >>= 2; if (n != 0) __asm__ ("1:\t" "movesl %1@+,%/d0\n\t" "movel %/d0,%2@+\n\t" "dbra %0,1b\n\t" "clrw %0\n\t" "subql #1,%0\n\t" "bccs 1b\n\t" : "=d" (n), "=a" (from), "=a" (to) : "0" (n-1), "1" (from), "2" (to) : "d0", "memory"); if (tmp & 2) __asm__ ("movesw %0@+,%/d0\n\t" "movew %/d0,%1@+\n\t" : "=a" (from), "=a" (to) : "0" (from), "1" (to) : "d0", "memory"); if (tmp & 1) __asm__ __volatile__ ("movesb %0@,%/d0\n\t" "moveb %/d0,%1@\n\t" : /* no outputs */ : "a" (from), "a" (to) : "d0", "memory"); } static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n) { switch (n) { case 0: return; case 1: *(char *)to = __get_user((const char *) from, 1); return; case 2: *(short *)to = __get_user((const short *) from, 2); return; case 3: *(short *) to = __get_user((const short *) from, 2); *((char *) to + 2) = __get_user(2+(const char *) from, 1); return; case 4: *(int *) to = __get_user((const int *) from, 4); return; case 8: *(int *) to = __get_user((const int *) from, 4); *(1+(int *) to) = __get_user(1+(const int *) from, 4); return; case 12: *(int *) to = __get_user((const int *) from, 4); *(1+(int *) to) = __get_user(1+(const int *) from, 4); *(2+(int *) to) = __get_user(2+(const int *) from, 4); return; case 16: *(int *) to = __get_user((const int *) from, 4); *(1+(int *) to) = __get_user(1+(const int *) from, 4); *(2+(int *) to) = __get_user(2+(const int *) from, 4); *(3+(int *) to) = __get_user(3+(const int *) from, 4); return; } #define COMMON(x) \ __asm__ __volatile__ ("1:\n\t" \ "movesl %1@+,%/d0\n\t" \ "movel %/d0,%2@+\n\t" \ "dbra %0,1b\n\t" \ "clrw %0\n\t" \ "subql #1,%0\n\t" \ "bccs 1b\n\t" \ x \ : "=d" (n), "=a" (from), "=a" (to) \ : "1" (from), "2" (to), "0" (n/4-1) \ : "d0", "memory"); switch (n % 4) { case 0: COMMON(""); return; case 1: COMMON("movesb %1@+,%/d0; moveb %/d0,%2@+"); return; case 2: COMMON("movesw %1@+,%/d0; movew %/d0,%2@+"); return; case 3: COMMON("movesw %1@+,%/d0; movew %/d0,%2@+\n\t" "movesb %1@+,%/d0; moveb %/d0,%2@+"); return; } #undef COMMON } #define memcpy_fromfs(to, from, n) \ (__builtin_constant_p(n) ? \ __constant_memcpy_fromfs((to),(from),(n)) : \ __generic_memcpy_fromfs((to),(from),(n))) #define memcpy_tofs(to, from, n) \ (__builtin_constant_p(n) ? \ __constant_memcpy_tofs((to),(from),(n)) : \ __generic_memcpy_tofs((to),(from),(n))) /* * Get/set the SFC/DFC registers for MOVES instructions */ static inline unsigned long get_fs(void) { unsigned long _v; __asm__ ("movec %/dfc,%0":"=r" (_v):); return _v; } static inline unsigned long get_ds(void) { /* return the supervisor data space code */ return KERNEL_DS; } static inline void set_fs(unsigned long val) { __asm__ __volatile__ ("movec %0,%/sfc\n\t" "movec %0,%/dfc\n\t" : /* no outputs */ : "r" (val) : "memory"); } #endif /* __ASSEMBLY__ */ #endif /* _M68K_SEGMENT_H */ |