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;
26 static inline void flush_icache_range(unsigned long start, unsigned long stop)
32 static inline void flush_icache_range(unsigned long start, unsigned long stop)
38 static inline void flush_icache_range(unsigned long start, unsigned long stop)
44 static inline void flush_icache_range(unsigned long start, unsigned long stop)
51 #define MIN_CACHE_LINE_SIZE 8 /* conservative value */
53 static void inline flush_icache_range(unsigned long start, unsigned long stop)
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");
73 static inline void flush_icache_range(unsigned long start, unsigned long stop)
81 static void inline flush_icache_range(unsigned long start, unsigned long stop)
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));
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));
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);
114 register int gp asm("$29");
116 static inline void immediate_ldah(void *p, int val) {
118 long high = ((val >> 16) + ((val >> 15) & 1)) & 0xffff;
124 static inline void immediate_lda(void *dest, int val) {
125 *(uint16_t *) dest = val;
127 void fix_bsr(void *p, int offset) {
129 *dest &= ~((1 << 21) - 1);
130 *dest |= (offset >> 2) & ((1 << 21) - 1);
133 #endif /* __alpha__ */
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 {
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,
164 int offset, data_size, target;
168 data_size = (uint8_t *)data_end - (uint8_t *)data_start;
171 /* generate branch to skip the data */
174 target = (long)gen_code_ptr + data_size + 4;
175 arm_reloc_pc24((uint32_t *)gen_code_ptr, 0xeafffffe, target);
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);
196 if (offset > 0xfff) {
197 fprintf(stderr, "Error ldr offset\n");