usermode/library/mtm/src/sysdeps/x86/target.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2011 Computer Sciences Department, 
00003     University of Wisconsin -- Madison
00004 
00005     ----------------------------------------------------------------------
00006 
00007     This file is part of Mnemosyne: Lightweight Persistent Memory, 
00008     originally developed at the University of Wisconsin -- Madison.
00009 
00010     Mnemosyne was originally developed primarily by Haris Volos
00011     with contributions from Andres Jaan Tack.
00012 
00013     ----------------------------------------------------------------------
00014 
00015     Mnemosyne is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU General Public License
00017     as published by the Free Software Foundation, version 2
00018     of the License.
00019  
00020     Mnemosyne is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024 
00025     You should have received a copy of the GNU General Public License
00026     along with this program; if not, write to the Free Software
00027     Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00028     Boston, MA  02110-1301, USA.
00029 
00030 ### END HEADER ###
00031 */
00032 
00042 #ifndef TARGET_H_HBX9MKK6
00043 #define TARGET_H_HBX9MKK6
00044 
00045 # include <stdint.h>
00046 # include <xmmintrin.h>
00047 
00048 #ifdef __x86_64__
00049 # define CACHELINE_SIZE 64
00050 # define CACHELINE_SIZE_LOG 6
00051 #else
00052 # define CACHELINE_SIZE 32
00053 # define CACHELINE_SIZE_LOG 5
00054 #endif
00055 
00056 typedef struct mtm_jmpbuf_s mtm_jmpbuf_t;
00057 
00058 #ifdef __x86_64__
00059 struct mtm_jmpbuf_s
00060 {
00061         uint64_t sp;
00062         uint64_t rbx;
00063         uint64_t rbp;
00064         uint64_t r12;
00065         uint64_t r13;
00066         uint64_t r14;
00067         uint64_t r15;
00068         uint64_t abendPC;
00069         uint32_t mxcsr;
00070         uint32_t txn_flags;
00071         uint16_t fpcsr;
00072 };
00073 #else
00074 struct mtm_jmpbuf_s
00075 {
00076         uint32_t sp;
00077         uint32_t ebx;
00078         uint32_t esi;
00079         uint32_t edi;
00080         uint32_t ebp;
00081         uint32_t abendPC;
00082         uint32_t mxcsr;
00083         uint32_t txn_flags;
00084         uint16_t fpcsr;
00085 };
00086 #endif
00087 
00088 /* These are taken from the GCC's TM library */
00089 /* Why not using fence for x86??? */
00090 
00091 static inline void
00092 cpu_relax (void)
00093 {
00094   __asm volatile ("rep; nop" : : : "memory");
00095 }
00096 
00097 static inline void
00098 atomic_read_barrier (void)
00099 {
00100   /* x86 is a strong memory ordering machine.  */
00101   __asm volatile ("" : : : "memory");
00102 }
00103 
00104 static inline void
00105 atomic_write_barrier (void)
00106 {
00107   /* x86 is a strong memory ordering machine.  */
00108   __asm volatile ("" : : : "memory");
00109 }
00110 
00111 
00112 static inline uintptr_t *
00113 get_stack_pointer(void)
00114 {
00115     uintptr_t *result;
00116 
00117 #ifdef __x86_64__
00118         __asm__ ("movq %%rsp,%0": "=r"(result):);
00119         return result;
00120 #else
00121         __asm__ ("movl %%esp,%0": "=r"(result):);
00122         return result;
00123 #endif  
00124 }
00125 
00126 
00127 static inline uintptr_t *
00128 get_frame_pointer(void)
00129 {
00130     uintptr_t *result;
00131 
00132 #ifdef __x86_64__
00133         __asm__ ("movq %%rbp,%0": "=r"(result):);
00134         return result;
00135 #else
00136         __asm__ ("movl %%ebp,%0": "=r"(result):);
00137         return result;
00138 #endif  
00139 }
00140 
00141 /* This requires frame pointers being enabled */
00142 static inline uintptr_t
00143 get_stack_base()
00144 {
00145         uintptr_t frame_pointer;
00146         uintptr_t stack_base;
00147 
00148         asm volatile ("movq %%rbp,%0": "=r"(frame_pointer):);
00149         while (frame_pointer) {
00150                 stack_base = frame_pointer;
00151                 if (*((uintptr_t*) frame_pointer) <= frame_pointer) {
00152                         break;
00153                 }
00154                 frame_pointer = *((uintptr_t*) frame_pointer);
00155         }
00156         return stack_base;
00157 }
00158 
00159 #endif /* TARGET_H_HBX9MKK6 */

Generated on Sat Apr 23 11:43:36 2011 for Mnemosyne by  doxygen 1.4.7