kernel/eka/common/arm/atomic_ops.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\common\arm\atomic_ops.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifdef	__OPERATION__
       
    19 
       
    20 #undef	__OPERATION__
       
    21 #undef	__OP_RMW1__
       
    22 #undef	__OP_RMW2__
       
    23 #undef	__OP_RMW3__
       
    24 #undef	__OP_SIGNED__
       
    25 #undef	__TYPE__
       
    26 #undef	__SIZE_CODE__
       
    27 #undef	__LDR_INST__
       
    28 #undef	__LDRS_INST__
       
    29 #undef	__STR_INST__
       
    30 #undef	__LDREX_INST__
       
    31 #undef	__STREX_INST__
       
    32 #undef	__SIGN_EXTEND__
       
    33 #undef	__LOG2_DATA_SIZE__
       
    34 
       
    35 #undef	__OP_LOAD__
       
    36 #undef	__OP_STORE__
       
    37 #undef	__OP_SWP__
       
    38 #undef	__OP_CAS__
       
    39 #undef	__OP_ADD__
       
    40 #undef	__OP_AND__
       
    41 #undef	__OP_IOR__
       
    42 #undef	__OP_XOR__
       
    43 #undef	__OP_AXO__
       
    44 #undef	__OP_TAU__
       
    45 #undef	__OP_TAS__
       
    46 
       
    47 #undef ENSURE_8BYTE_ALIGNMENT
       
    48 
       
    49 #else	// __OPERATION__
       
    50 
       
    51 #if defined(__OP_LOAD__)
       
    52 #define __OPERATION__	load
       
    53 #elif defined(__OP_STORE__)
       
    54 #define __OPERATION__	store
       
    55 #elif defined(__OP_SWP__)
       
    56 #define __OPERATION__	swp
       
    57 #define	__OP_RMW1__
       
    58 #elif defined(__OP_CAS__)
       
    59 #define __OPERATION__	cas
       
    60 #elif defined(__OP_ADD__)
       
    61 #define __OPERATION__	add
       
    62 #define	__OP_RMW1__
       
    63 #elif defined(__OP_AND__)
       
    64 #define __OPERATION__	and
       
    65 #define	__OP_RMW1__
       
    66 #elif defined(__OP_IOR__)
       
    67 #define __OPERATION__	ior
       
    68 #define	__OP_RMW1__
       
    69 #elif defined(__OP_XOR__)
       
    70 #define __OPERATION__	xor
       
    71 #define	__OP_RMW1__
       
    72 #elif defined(__OP_AXO__)
       
    73 #define __OPERATION__	axo
       
    74 #define	__OP_RMW2__
       
    75 #elif defined(__OP_TAU__)
       
    76 #define __OPERATION__	tau
       
    77 #define	__OP_RMW3__
       
    78 #elif defined(__OP_TAS__)
       
    79 #define __OPERATION__	tas
       
    80 #define	__OP_RMW3__
       
    81 #define	__OP_SIGNED__
       
    82 #else
       
    83 #error Unknown atomic operation
       
    84 #endif
       
    85 
       
    86 #if __DATA_SIZE__==8
       
    87 #define	__LOG2_DATA_SIZE__			3
       
    88 #define __SIZE_CODE__				"b"
       
    89 #ifdef __CPU_ARM_HAS_LDREX_STREX_V6K
       
    90 #define	__LDREX_INST__(Rd,Rn)		LDREXB(Rd,Rn)
       
    91 #define	__STREX_INST__(Rd,Rm,Rn)	STREXB(Rd,Rm,Rn)
       
    92 #endif
       
    93 #define	__SIGN_EXTEND__(reg)		asm("mov "#reg ", "#reg ", lsl #24 "); asm("mov "#reg ", "#reg ", asr #24 ");
       
    94 #define	__LDR_INST__(cc,args)		asm("ldr"#cc "b " args)
       
    95 #define	__LDRS_INST__(cc,args)		asm("ldr"#cc "sb " args)
       
    96 #define	__STR_INST__(cc,args)		asm("str"#cc "b " args)
       
    97 #ifdef	__OP_SIGNED__
       
    98 #define	__TYPE__					TInt8
       
    99 #else
       
   100 #define	__TYPE__					TUint8
       
   101 #endif
       
   102 #elif __DATA_SIZE__==16
       
   103 #define	__LOG2_DATA_SIZE__			4
       
   104 #define __SIZE_CODE__				"h"
       
   105 #ifdef __CPU_ARM_HAS_LDREX_STREX_V6K
       
   106 #define	__LDREX_INST__(Rd,Rn)		LDREXH(Rd,Rn)
       
   107 #define	__STREX_INST__(Rd,Rm,Rn)	STREXH(Rd,Rm,Rn)
       
   108 #endif
       
   109 #define	__SIGN_EXTEND__(reg)		asm("mov "#reg ", "#reg ", lsl #16 "); asm("mov "#reg ", "#reg ", asr #16 ");
       
   110 #define	__LDR_INST__(cc,args)		asm("ldr"#cc "h " args)
       
   111 #define	__LDRS_INST__(cc,args)		asm("ldr"#cc "sh " args)
       
   112 #define	__STR_INST__(cc,args)		asm("str"#cc "h " args)
       
   113 #ifdef	__OP_SIGNED__
       
   114 #define	__TYPE__					TInt16
       
   115 #else
       
   116 #define	__TYPE__					TUint16
       
   117 #endif
       
   118 #elif __DATA_SIZE__==32
       
   119 #define	__LOG2_DATA_SIZE__			5
       
   120 #define __SIZE_CODE__				""
       
   121 #ifdef __CPU_ARM_HAS_LDREX_STREX
       
   122 #define	__LDREX_INST__(Rd,Rn)		LDREX(Rd,Rn)
       
   123 #define	__STREX_INST__(Rd,Rm,Rn)	STREX(Rd,Rm,Rn)
       
   124 #endif
       
   125 #define	__SIGN_EXTEND__(reg)
       
   126 #define	__LDR_INST__(cc,args)		asm("ldr"#cc " " args)
       
   127 #define	__LDRS_INST__(cc,args)		asm("ldr"#cc " " args)
       
   128 #define	__STR_INST__(cc,args)		asm("str"#cc " " args)
       
   129 #ifdef	__OP_SIGNED__
       
   130 #define	__TYPE__					TInt32
       
   131 #else
       
   132 #define	__TYPE__					TUint32
       
   133 #endif
       
   134 #elif __DATA_SIZE__==64
       
   135 #define	__LOG2_DATA_SIZE__			6
       
   136 #define __SIZE_CODE__				"d"
       
   137 #ifdef __CPU_ARM_HAS_LDREX_STREX_V6K
       
   138 #define	__LDREX_INST__(Rd,Rn)		LDREXD(Rd,Rn)
       
   139 #define	__STREX_INST__(Rd,Rm,Rn)	STREXD(Rd,Rm,Rn)
       
   140 #endif
       
   141 #ifdef	__OP_SIGNED__
       
   142 #define	__TYPE__					TInt64
       
   143 #else
       
   144 #define	__TYPE__					TUint64
       
   145 #endif
       
   146 #else
       
   147 #error Invalid data size
       
   148 #endif
       
   149 
       
   150 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__EABI__)
       
   151 // Check 8 byte aligned and cause alignment fault if not.
       
   152 // Doesn't work if alignment checking is disabled but gives consistent behaviour
       
   153 // between processors with ldrexd etc and these hand coded versions.
       
   154 #define ENSURE_8BYTE_ALIGNMENT(rAddr) 		\
       
   155 	asm("tst r"#rAddr", #0x7 "); 			\
       
   156 	asm("orrne r"#rAddr", r"#rAddr", #1 "); \
       
   157 	asm("ldmne r"#rAddr", {r"#rAddr"} ")
       
   158 #else
       
   159 // Don't assert on old gcc (arm4) as it is not eabi compliant and this stops 
       
   160 // kernel booting.
       
   161 #define ENSURE_8BYTE_ALIGNMENT(rAddr)
       
   162 #endif
       
   163 #endif	// __OPERATION__