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
23 register int gp asm("$29");
25 static inline void immediate_ldah(void *p, int val) {
27 long high = ((val >> 16) + ((val >> 15) & 1)) & 0xffff;
33 static inline void immediate_lda(void *dest, int val) {
34 *(uint16_t *) dest = val;
36 void fix_bsr(void *p, int offset) {
38 *dest &= ~((1 << 21) - 1);
39 *dest |= (offset >> 2) & ((1 << 21) - 1);
42 #endif /* __alpha__ */
46 #define MAX_OP_SIZE (128 * 4) /* in bytes */
47 /* max size of the code that can be generated without calling arm_flush_ldr */
48 #define MAX_FRAG_SIZE (1024 * 4)
49 //#define MAX_FRAG_SIZE (135 * 4) /* for testing */
51 typedef struct LDREntry {
56 static LDREntry arm_ldr_table[1024];
57 static uint32_t arm_data_table[1024];
59 extern char exec_loop;
61 static inline void arm_reloc_pc24(uint32_t *ptr, uint32_t insn, int val)
63 *ptr = (insn & ~0xffffff) | ((insn + ((val - (int)ptr) >> 2)) & 0xffffff);
66 static uint8_t *arm_flush_ldr(uint8_t *gen_code_ptr,
67 LDREntry *ldr_start, LDREntry *ldr_end,
68 uint32_t *data_start, uint32_t *data_end,
73 int offset, data_size, target;
77 data_size = (uint8_t *)data_end - (uint8_t *)data_start;
81 arm_reloc_pc24((uint32_t *)gen_code_ptr, 0xeafffffe, (long)(&exec_loop));
84 /* generate branch to skip the data */
87 target = (long)gen_code_ptr + data_size + 4;
88 arm_reloc_pc24((uint32_t *)gen_code_ptr, 0xeafffffe, target);
93 data_ptr = gen_code_ptr;
94 memcpy(gen_code_ptr, data_start, data_size);
95 gen_code_ptr += data_size;
97 /* patch the ldr to point to the data */
98 for(le = ldr_start; le < ldr_end; le++) {
99 ptr = (uint32_t *)le->ptr;
100 offset = ((unsigned long)(le->data_ptr) - (unsigned long)data_start) +
101 (unsigned long)data_ptr -
102 (unsigned long)ptr - 8;
103 insn = *ptr & ~(0xfff | 0x00800000);
109 if (offset > 0xfff) {
110 fprintf(stderr, "Error ldr offset\n");