add missing FORCE_RET (Paul Brook)
[qemu/qemu_0_9_1_stable.git] / dyngen.h
blobf1ce2484c8c46616d766dcb633744d87185e0243
1 /*
2 * dyngen helpers
3 *
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 int __op_param1, __op_param2, __op_param3;
22 int __op_gen_label1, __op_gen_label2, __op_gen_label3;
23 int __op_jmp0, __op_jmp1, __op_jmp2, __op_jmp3;
25 #ifdef __i386__
26 static inline void flush_icache_range(unsigned long start, unsigned long stop)
29 #endif
31 #ifdef __x86_64__
32 static inline void flush_icache_range(unsigned long start, unsigned long stop)
35 #endif
37 #ifdef __s390__
38 static inline void flush_icache_range(unsigned long start, unsigned long stop)
41 #endif
43 #ifdef __ia64__
44 static inline void flush_icache_range(unsigned long start, unsigned long stop)
47 #endif
49 #ifdef __powerpc__
51 #define MIN_CACHE_LINE_SIZE 8 /* conservative value */
53 static void inline flush_icache_range(unsigned long start, unsigned long stop)
55 unsigned long p;
57 p = start & ~(MIN_CACHE_LINE_SIZE - 1);
58 stop = (stop + MIN_CACHE_LINE_SIZE - 1) & ~(MIN_CACHE_LINE_SIZE - 1);
60 for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
61 asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
63 asm volatile ("sync" : : : "memory");
64 for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
65 asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
67 asm volatile ("sync" : : : "memory");
68 asm volatile ("isync" : : : "memory");
70 #endif
72 #ifdef __alpha__
73 static inline void flush_icache_range(unsigned long start, unsigned long stop)
75 asm ("imb");
77 #endif
79 #ifdef __sparc__
81 static void inline flush_icache_range(unsigned long start, unsigned long stop)
83 unsigned long p;
85 p = start & ~(8UL - 1UL);
86 stop = (stop + (8UL - 1UL)) & ~(8UL - 1UL);
88 for (; p < stop; p += 8)
89 __asm__ __volatile__("flush\t%0" : : "r" (p));
92 #endif
94 #ifdef __arm__
95 static inline void flush_icache_range(unsigned long start, unsigned long stop)
97 register unsigned long _beg __asm ("a1") = start;
98 register unsigned long _end __asm ("a2") = stop;
99 register unsigned long _flg __asm ("a3") = 0;
100 __asm __volatile__ ("swi 0x9f0002" : : "r" (_beg), "r" (_end), "r" (_flg));
102 #endif
104 #ifdef __mc68000
105 #include <asm/cachectl.h>
106 static inline void flush_icache_range(unsigned long start, unsigned long stop)
108 cacheflush(start,FLUSH_SCOPE_LINE,FLUSH_CACHE_BOTH,stop-start+16);
110 #endif
112 #ifdef __alpha__
114 register int gp asm("$29");
116 static inline void immediate_ldah(void *p, int val) {
117 uint32_t *dest = p;
118 long high = ((val >> 16) + ((val >> 15) & 1)) & 0xffff;
120 *dest &= ~0xffff;
121 *dest |= high;
122 *dest |= 31 << 16;
124 static inline void immediate_lda(void *dest, int val) {
125 *(uint16_t *) dest = val;
127 void fix_bsr(void *p, int offset) {
128 uint32_t *dest = p;
129 *dest &= ~((1 << 21) - 1);
130 *dest |= (offset >> 2) & ((1 << 21) - 1);
133 #endif /* __alpha__ */
135 #ifdef __arm__
137 #define MAX_OP_SIZE (128 * 4) /* in bytes */
138 /* max size of the code that can be generated without calling arm_flush_ldr */
139 #define MAX_FRAG_SIZE (1024 * 4)
140 //#define MAX_FRAG_SIZE (135 * 4) /* for testing */
142 typedef struct LDREntry {
143 uint8_t *ptr;
144 uint32_t *data_ptr;
145 } LDREntry;
147 static LDREntry arm_ldr_table[1024];
148 static uint32_t arm_data_table[1024];
150 extern char exec_loop;
152 static inline void arm_reloc_pc24(uint32_t *ptr, uint32_t insn, int val)
154 *ptr = (insn & ~0xffffff) | ((insn + ((val - (int)ptr) >> 2)) & 0xffffff);
157 static uint8_t *arm_flush_ldr(uint8_t *gen_code_ptr,
158 LDREntry *ldr_start, LDREntry *ldr_end,
159 uint32_t *data_start, uint32_t *data_end,
160 int gen_jmp)
162 LDREntry *le;
163 uint32_t *ptr;
164 int offset, data_size, target;
165 uint8_t *data_ptr;
166 uint32_t insn;
168 data_size = (uint8_t *)data_end - (uint8_t *)data_start;
170 if (gen_jmp) {
171 /* generate branch to skip the data */
172 if (data_size == 0)
173 return gen_code_ptr;
174 target = (long)gen_code_ptr + data_size + 4;
175 arm_reloc_pc24((uint32_t *)gen_code_ptr, 0xeafffffe, target);
176 gen_code_ptr += 4;
179 /* copy the data */
180 data_ptr = gen_code_ptr;
181 memcpy(gen_code_ptr, data_start, data_size);
182 gen_code_ptr += data_size;
184 /* patch the ldr to point to the data */
185 for(le = ldr_start; le < ldr_end; le++) {
186 ptr = (uint32_t *)le->ptr;
187 offset = ((unsigned long)(le->data_ptr) - (unsigned long)data_start) +
188 (unsigned long)data_ptr -
189 (unsigned long)ptr - 8;
190 insn = *ptr & ~(0xfff | 0x00800000);
191 if (offset < 0) {
192 offset = - offset;
193 } else {
194 insn |= 0x00800000;
196 if (offset > 0xfff) {
197 fprintf(stderr, "Error ldr offset\n");
198 abort();
200 insn |= offset;
201 *ptr = insn;
203 return gen_code_ptr;
206 #endif /* __arm__ */