root/include/asm-mips/system.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. xchg_u8
  2. xchg_u16
  3. xchg_u32
  4. xchg_u64
  5. tas
  6. xchg_ptr

   1 /*
   2  * include/asm-mips/system.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 #ifndef __ASM_MIPS_SYSTEM_H
  12 #define __ASM_MIPS_SYSTEM_H
  13 
  14 #include <linux/types.h>
  15 #include <asm/segment.h>
  16 #include <asm/mipsregs.h>
  17 #include <asm/mipsconfig.h>
  18 
  19 /*
  20  * (Currently empty to support debugging)
  21  */
  22 #define move_to_user_mode()              \
  23 __asm__ __volatile__ (                   \
  24         ".set\tnoreorder\n\t"            \
  25         ".set\tnoat\n\t"                 \
  26         "la\t$1,1f\n\t"                  \
  27         "subu\t$1,$1,%0\n\t"             \
  28         "jr\t$1\n\t"                     \
  29         "mfc0\t$1,$12\n\t"               \
  30         "1:ori\t$1,0x00\n\t"             \
  31         "mtc0\t$1,$12\n\t"               \
  32         "subu\t$29,%0\n\t"               \
  33         ".set\tat\n\t"                   \
  34         ".set\treorder"                  \
  35         : /* no outputs */               \
  36         : "r" (KERNELBASE));
  37 
  38 #if defined (__R4000__)
  39 #define sti() \
  40 __asm__ __volatile__(                    \
  41         ".set\tnoat\n\t"                 \
  42         "mfc0\t$1,"STR(CP0_STATUS)"\n\t" \
  43         "ori\t$1,$1,0x1f\n\t"            \
  44         "xori\t$1,$1,0x1e\n\t"           \
  45         "mtc0\t$1,"STR(CP0_STATUS)"\n\t" \
  46         ".set\tat"                       \
  47         : /* no outputs */               \
  48         : /* no inputs */                \
  49         : "$1")
  50 
  51 #define cli() \
  52 __asm__ __volatile__(                    \
  53         ".set\tnoat\n\t"                 \
  54         "mfc0\t$1,"STR(CP0_STATUS)"\n\t" \
  55         "ori\t$1,$1,1\n\t"               \
  56         "xori\t$1,$1,1\n\t"              \
  57         "mtc0\t$1,"STR(CP0_STATUS)"\n\t" \
  58         ".set\tat"                       \
  59         : /* no outputs */               \
  60         : /* no inputs */                \
  61         : "$1")
  62 #else /* !defined (__R4000__) */
  63 /*
  64  * Cheese - I don't have a R3000 manual
  65  */
  66 #error "Yikes - write cli()/sti() macros for  R3000!"
  67 #endif /* !defined (__R4000__) */
  68 
  69 #define nop() __asm__ __volatile__ ("nop")
  70 
  71 #define save_flags(x)                    \
  72 __asm__ __volatile__(                    \
  73         "mfc0\t%0,$12"                   \
  74         : "=r" (x))                      \
  75 
  76 #define restore_flags(x)                 \
  77 __asm__ __volatile__(                    \
  78         "mtc0\t%0,$12"                   \
  79         : /* no output */                \
  80         : "r" (x))                       \
  81 
  82 extern inline unsigned long xchg_u8(char * m, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         unsigned long flags, retval;
  85 
  86         save_flags(flags);
  87         sti();
  88         retval = *m;
  89         *m = val;
  90         restore_flags(flags);
  91 
  92         return retval;
  93 }
  94 
  95 extern inline unsigned long xchg_u16(short * m, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97         unsigned long flags, retval;
  98 
  99         save_flags(flags);
 100         sti();
 101         retval = *m;
 102         *m = val;
 103         restore_flags(flags);
 104 
 105         return retval;
 106 }
 107 
 108 /*
 109  * For 32 and 64 bit operands we can take advantage of ll and sc.
 110  * The later isn't currently being used.
 111  */
 112 extern inline unsigned long xchg_u32(int * m, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114         unsigned long dummy;
 115 
 116         __asm__ __volatile__(
 117                 ".set\tnoreorder\n\t"
 118                 ".set\tnoat\n\t"
 119                 "ll\t%0,(%1)\n"
 120                 "1:\tmove\t$1,%2\n\t"
 121                 "sc\t$1,(%1)\n\t"
 122                 "beqzl\t%3,1b\n\t"
 123                 "ll\t%0,(%1)\n\t"
 124                 ".set\tat\n\t"
 125                 ".set\treorder"
 126                 : "=r" (val), "=r" (m), "=r" (dummy)
 127                 : "1" (*m), "2" (val));
 128 
 129         return val;
 130 }
 131 
 132 extern inline unsigned long xchg_u64(long * m, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134         unsigned long dummy;
 135 
 136         __asm__ __volatile__(
 137                 ".set\tnoreorder\n\t"
 138                 ".set\tnoat\n\t"
 139                 "lld\t%0,(%1)\n"
 140                 "1:\tmove\t$1,%2\n\t"
 141                 "scd\t$1,(%1)\n\t"
 142                 "beqzl\t%3,1b\n\t"
 143                 "ll\t%0,(%1)\n\t"
 144                 ".set\tat\n\t"
 145                 ".set\treorder"
 146                 : "=r" (val), "=r" (m), "=r" (dummy)
 147                 : "1" (*m), "2" (val));
 148 
 149         return val;
 150 }
 151 
 152 #if 0
 153 extern inline int tas(char * m)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155         return xchg_u8(m,1);
 156 }
 157 #endif
 158 
 159 extern inline void * xchg_ptr(void * m, void * val)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         return (void *) xchg_u32(m, (unsigned long) val);
 162 }
 163 
 164 extern ulong IRQ_vectors[256];
 165 extern ulong exception_handlers[256];
 166 
 167 #define set_intr_gate(n,addr) \
 168         IRQ_vectors[n] = (ulong) (addr)
 169 
 170 #define set_except_vector(n,addr) \
 171         exception_handlers[n] = (ulong) (addr)
 172 
 173 /*
 174  * atomic exchange of one word
 175  */
 176 #if defined (__R4000__)
 177 #define atomic_exchange(m,r)             \
 178         __asm__ __volatile__(            \
 179                 ".set\tnoreorder\n\t"    \
 180                 "ll\t%0,(%2)\n"          \
 181                 "1:\tmove\t$8,%1\n\t"    \
 182                 "sc\t$8,(%2)\n\t"        \
 183                 "beql\t$0,$8,1b\n\t"     \
 184                 "ll\t%0,(%2)\n\t"        \
 185                 ".set\treorder"          \
 186                 : "=r" (r)               \
 187                 : "r" (r), "r" (&(m))    \
 188                 : "$8","memory")
 189 #else
 190 #define atomic_exchange(m,r)             \
 191         {                                \
 192                 unsigned long flags;     \
 193                 unsigned long tmp;       \
 194                 save_flags(flags);       \      
 195                 cli();                   \
 196                 tmp = (m);               \
 197                 (m) = (r);               \
 198                 (r) = tmp;               \
 199                 restore_flags(flags);    \      
 200         }
 201 #endif
 202 
 203 #endif /* __ASM_MIPS_SYSTEM_H */

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