Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 /*
0002  *  spr.h -- Access to special purpose registers.
0003  *
0004  *  Copyright (C) 1998 Gabriel Paubert, paubert@iram.es
0005  *
0006  *  Modified to compile in RTEMS development environment
0007  *  by Eric Valette
0008  *
0009  *  Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
0010  *
0011  *  The license and distribution terms for this file may be
0012  *  found in the file LICENSE in this distribution or at
0013  *  http://www.rtems.org/license/LICENSE.
0014  *
0015  */
0016 
0017 
0018 #ifndef _LIBCPU_SPR_H
0019 #define _LIBCPU_SPR_H
0020 
0021 #include <rtems/powerpc/registers.h>
0022 
0023 #define __MFSPR(reg, val) \
0024     __asm__ __volatile__("mfspr %0,"#reg : "=r" (val))
0025 
0026 #define __MTSPR(val, reg) \
0027     __asm__ __volatile__("mtspr "#reg",%0" : : "r" (val))
0028 
0029 
0030 #define SPR_RW(reg) \
0031 static inline unsigned long _read_##reg(void) \
0032 {\
0033     unsigned long val;\
0034     __MFSPR(reg, val);\
0035     return val;\
0036 }\
0037 static inline void _write_##reg(unsigned long val)\
0038 {\
0039     __MTSPR(val,reg);\
0040     return;\
0041 }
0042 
0043 #define SPR_RO(reg) \
0044 static inline unsigned long _read_##reg(void) \
0045 {\
0046     unsigned long val;\
0047     __MFSPR(reg,val);\
0048     return val;\
0049 }
0050 
0051 static inline unsigned long _read_MSR(void)
0052 {
0053     unsigned long val;
0054     __asm__ volatile("mfmsr %0" : "=r" (val));
0055     return val;
0056 }
0057 
0058 static inline void _write_MSR(unsigned long val)
0059 {
0060     __asm__ volatile("mtmsr %0" : : "r" (val));
0061     return;
0062 }
0063 
0064 static inline unsigned long _read_SR(void * va)
0065 {
0066     unsigned long val;
0067     __asm__ volatile (
0068         ".machine \"push\"\n"
0069         ".machine \"any\"\n"
0070         "mfsrin %0,%1\n"
0071         ".machine \"pop\"" :
0072         "=r" (val) :
0073         "r" (va)
0074     );
0075     return val;
0076 }
0077 
0078 static inline void _write_SR(unsigned long val, void * va)
0079 {
0080     __asm__ volatile (
0081         ".machine \"push\"\n"
0082         ".machine \"any\"\n"
0083         "mtsrin %0,%1\n"
0084         ".machine \"pop\"" : :
0085         "r" (val) , "r" (va) :
0086         "memory"
0087     );
0088     return;
0089 }
0090 
0091 
0092 #endif