2 * Copyright (C) 2003, 2004, 2005, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #define HANDLER_TABLE_T static const void
25 #define DOUBLE_1_BITS 0x3ff0000000000000LL
27 #define READ_DBL(v,p,l) v = ((u8)p[0]<<56)|((u8)p[1]<<48)|((u8)p[2]<<40) \
28 |((u8)p[3]<<32)|((u8)p[4]<<24)|((u8)p[5]<<16) \
29 |((u8)p[6]<<8)|(u8)p[7]; p+=8
31 /* Needed for i386 -- empty here */
35 #define COMPARE_AND_SWAP(addr, old_val, new_val) \
37 int result, read_val; \
38 __asm__ __volatile__ (" \
47 : "=&r" (result), "=&r" (read_val) \
48 : "r" (addr), "r" (old_val), "r" (new_val) \
53 #define COMPARE_AND_SWAP_64(addr, old_val, new_val) \
54 COMPARE_AND_SWAP(addr, old_val, new_val)
57 #define COMPARE_AND_SWAP(addr, old_val, new_val) \
59 int result, read_val; \
60 __asm__ __volatile__ (" \
69 : "=&r" (result), "=&r" (read_val) \
70 : "r" (addr), "r" (old_val), "r" (new_val) \
76 #define LOCKWORD_READ(addr) *addr
77 #define LOCKWORD_WRITE(addr, value) *addr = value
78 #define LOCKWORD_COMPARE_AND_SWAP(addr, old_val, new_val) \
79 COMPARE_AND_SWAP(addr, old_val, new_val)
81 #define CACHE_LINE_LEN 32
83 #define FLUSH_CACHE(addr, length) \
85 uintptr_t end = ((uintptr_t) addr) + length; \
86 uintptr_t start = ((uintptr_t) addr) \
87 & ~(CACHE_LINE_LEN - 1); \
90 for(i = start; i < end; i += CACHE_LINE_LEN) \
91 __asm__ ("dcbst 0, %0" :: "r" (i)); \
95 for(i = start; i < end; i += CACHE_LINE_LEN) \
96 __asm__ ("icbi 0, %0" :: "r" (i)); \
98 __asm__ ("sync; isync"); \
101 #define MBARRIER() __asm__ __volatile__ ("sync" ::: "memory")
102 #define UNLOCK_MBARRIER() __asm__ __volatile__ ("sync" ::: "memory")
103 #define JMM_LOCK_MBARRIER() __asm__ __volatile__ ("isync" ::: "memory")
104 #define JMM_UNLOCK_MBARRIER() __asm__ __volatile__ ("lwsync" ::: "memory")