OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [cpu/] [or32/] [dyn_rec_stubs.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1452 nogj
/* dyn_rec_stubs.c -- Stubs to allow the recompiler to be run standalone
2
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program 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
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
 
21
/* Stubs to test the recompiler */
22
#include <stdio.h>
23
#include <string.h>
24
#include <errno.h>
25
#include <byteswap.h>
26
#include <stdlib.h>
27
#include <inttypes.h>
28
 
29
#include "arch.h"
30
#include "immu.h"
31
#include "spr_defs.h"
32
#include "opcode/or32.h"
33
#include "abstract.h"
34
#include "execute.h"
35
#include "sim-config.h"
36
#include "sched.h"
37
 
38
#include "i386_regs.h"
39
#include "dyn_rec.h"
40
 
41
#define PAGE_LEN 8192
42
 
43
int do_stats = 0;
44
 
45
/* NOTE: Directly copied from execute.c */
46
uorreg_t eval_operand_val(uint32_t insn, struct insn_op_struct *opd)
47
{
48
  unsigned long operand = 0;
49
  unsigned long sbit;
50
  unsigned int nbits = 0;
51
 
52
  while(1) {
53
    operand |= ((insn >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
54
    nbits += opd->data;
55
 
56
    if(opd->type & OPTYPE_OP)
57
      break;
58
    opd++;
59
  }
60
 
61
  if(opd->type & OPTYPE_SIG) {
62
    sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
63
    if(operand & (1 << sbit)) operand |= ~REG_C(0) << sbit;
64
  }
65
 
66
  return operand;
67
}
68
 
69
oraddr_t immu_translate(oraddr_t virtaddr)
70
{
71
  return virtaddr;
72
}
73
 
74
oraddr_t peek_into_itlb(oraddr_t virtaddr)
75
{
76
  return virtaddr;
77
}
78
 
79
void do_scheduler()
80
{
81
  return;
82
}
83
 
84
static uint32_t page[PAGE_LEN / 4];
85
 
86
uint32_t eval_insn(oraddr_t addr, int *brkp)
87
{
88
  if(addr >= PAGE_LEN) {
89
    fprintf(stderr, "DR is trying to access memory outside the boundries of a page %08x\n", addr);
90
    return 0;
91
  }
92
 
93
  return bswap_32(page[addr / 4]);
94
}
95
 
96
int main(int argc, char **argv)
97
{
98
  FILE *f;
99
  long len;
100
  int i;
101
  struct dyn_page *dp;
102
  long off = 0;
103
 
104
  if((argc < 3) || (argc > 4)) {
105
    fprintf(stderr, "Usage: %s <binary file to recompile> <output code file> [offset into the file]\n",
106
            argv[0]);
107
    return 1;
108
  }
109
 
110
  if(argc == 4)
111
    off = strtol(argv[3], NULL, 0);
112
 
113
  f = fopen(argv[1], "r");
114
  if(!f) {
115
    fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
116
    return 1;
117
  }
118
 
119
  if(fseek(f, 0, SEEK_END)) {
120
    fprintf(stderr, "Uanble to seek to the end of the file %s: %s\n", argv[1],
121
            strerror(errno));
122
    return 1;
123
  }
124
 
125
  len = ftell(f);
126
 
127
  if(len == -1) {
128
    fprintf(stderr, "Unable to determine file length: %s\n", strerror(errno));
129
    return 1;
130
  }
131
 
132
  fseek(f, off, SEEK_SET);
133
 
134
  if((len - off) < PAGE_LEN) {
135
    printf("File is less than 1 page long, padding with zeros.\n");
136
    fread(page, len, 1, f);
137
    /* Pad the page with zeros */
138
    for(i = len; i < PAGE_LEN; i++)
139
      page[i] = 0;
140
  } else
141
    fread(page, PAGE_LEN, 1, f);
142
 
143
  fclose(f);
144
 
145
  build_automata();
146
  init_dyn_recomp();
147
 
148
  dp = new_dp(0);
149
 
150
  /* Cool, recompile the page */
151
  fprintf(stderr, "Hold on a sec, I'm recompileing the given page...\n");
152
 
153
  recompile_page(dp);
154
 
155
  fprintf(stderr, "Recompiled page length: %i\n", dp->host_len);
156 1481 nogj
  fprintf(stderr, "Recompiled to: %p\n", dp->host_page);
157 1452 nogj
  fprintf(stderr, "Dumping reced page to disk...\n");
158
 
159
  f = fopen(argv[2], "w");
160
  fwrite(dp->host_page, dp->host_len, 1, f);
161
  fclose(f);
162
 
163
/*
164
  printf("--- Recompiled or disassembly ---\n");
165
  for(i = 0; i < 2048; i++) {
166
    extern char *disassembled;
167
    disassemble_insn(eval_insn(i * 4, NULL));
168
    if(!eval_insn(i * 4, NULL)) continue;
169
    printf("%04x: %08x %s\n", i * 4, eval_insn(i * 4, NULL), disassembled);
170
  }
171
  printf("--- Recompiled or disassembly end ---\n");
172
*/
173
 
174 1481 nogj
  printf("--- Recompiled offsets ---\n");
175
  for(i = 0; i < (PAGE_LEN / 4); i++)
176
    printf("%"PRIxADDR": %x\n", i * 4, dp->locs[i] - dp->host_page);
177
  printf("--- Recompiled offsets end ---\n");
178 1452 nogj
  destruct_automata();
179
 
180
  return 0;
181
}
182
 
183
/* Lame linker stubs.  These are only referenced in the recompiled code */
184
struct cpu_state cpu_state;
185
struct runtime runtime;
186
struct scheduler_struct scheduler;
187
struct config config;
188
int immu_ex_from_insn;
189
 
190
/* FIXME: eval_insn should become this */
191 1487 nogj
uint32_t eval_insn_direct(oraddr_t memaddr, int through_mmu)
192 1452 nogj
{
193
  return 0;
194
}
195
 
196 1487 nogj
uint32_t eval_direct32(oraddr_t memaddr, int through_mmu, int through_dc)
197 1452 nogj
{
198
  return 0;
199
}
200
 
201
uint32_t eval_mem32(oraddr_t addr, int *breakpoint)
202
{
203
  return 0;
204
}
205
 
206
uint16_t eval_mem16(oraddr_t addr, int *breakpoint)
207
{
208
  return 0;
209
}
210
 
211
uint8_t eval_mem8(oraddr_t addr, int *breakpoint)
212
{
213
  return 0;
214
}
215
 
216
void set_mem32(oraddr_t addr, uint32_t val, int *breakpoint)
217
{
218
}
219
 
220
void set_mem16(oraddr_t addr, uint16_t val, int *breakpoint)
221
{
222
}
223
 
224
void set_mem8(oraddr_t addr, uint8_t val, int *breakpoint)
225
{
226
}
227
 
228
void analysis(struct iqueue_entry *current)
229
{
230
}
231
 
232
void mtspr(uint16_t regno, const uorreg_t value)
233
{
234
}
235
 
236
unsigned long spr_read_ttcr(void)
237
{
238
  return 0;
239
}
240
 
241
void debug(int level, const char *format,...)
242
{
243
}
244
 
245
void simprintf(oraddr_t stackaddr, unsigned long regparam)
246
{
247
}
248
 
249
const char *except_name(oraddr_t except)
250
{
251
  return NULL;
252
}
253
 
254 1508 nogj
uorreg_t mfspr(const uint16_t regno)
255
{
256
  return 0;
257
}
258
 
259 1481 nogj
static struct dev_memarea dummy_area = {
260 1486 nogj
 ops: { delayr: 1 },
261 1481 nogj
};
262
 
263 1452 nogj
struct dev_memarea *verify_memoryarea(oraddr_t addr)
264
{
265 1481 nogj
  return &dummy_area;
266 1452 nogj
}
267
 
268
void sim_done (void)
269
{
270
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.