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

Subversion Repositories or1k

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

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
  fprintf(stderr, "Dumping reced page to disk...\n");
157
 
158
  f = fopen(argv[2], "w");
159
  fwrite(dp->host_page, dp->host_len, 1, f);
160
  fclose(f);
161
 
162
/*
163
  printf("--- Recompiled or disassembly ---\n");
164
  for(i = 0; i < 2048; i++) {
165
    extern char *disassembled;
166
    disassemble_insn(eval_insn(i * 4, NULL));
167
    if(!eval_insn(i * 4, NULL)) continue;
168
    printf("%04x: %08x %s\n", i * 4, eval_insn(i * 4, NULL), disassembled);
169
  }
170
  printf("--- Recompiled or disassembly end ---\n");
171
*/
172
 
173
  dump_xrefs(dp, stdout);
174
 
175
  destruct_automata();
176
 
177
  return 0;
178
}
179
 
180
/* Lame linker stubs.  These are only referenced in the recompiled code */
181
struct cpu_state cpu_state;
182
struct runtime runtime;
183
struct scheduler_struct scheduler;
184
struct config config;
185
int immu_ex_from_insn;
186
 
187
/* FIXME: This needs to go */
188
oraddr_t pcprev;
189
 
190
/* FIXME: eval_insn should become this */
191
uint32_t eval_insn_direct(oraddr_t memaddr, int* breakpoint, int through_mmu)
192
{
193
  return 0;
194
}
195
 
196
uint32_t eval_direct32(oraddr_t memaddr, int *breakpoint, int through_mmu,
197
                       int through_dc)
198
{
199
  return 0;
200
}
201
 
202
uint32_t eval_mem32(oraddr_t addr, int *breakpoint)
203
{
204
  return 0;
205
}
206
 
207
uint16_t eval_mem16(oraddr_t addr, int *breakpoint)
208
{
209
  return 0;
210
}
211
 
212
uint8_t eval_mem8(oraddr_t addr, int *breakpoint)
213
{
214
  return 0;
215
}
216
 
217
void set_mem32(oraddr_t addr, uint32_t val, int *breakpoint)
218
{
219
}
220
 
221
void set_mem16(oraddr_t addr, uint16_t val, int *breakpoint)
222
{
223
}
224
 
225
void set_mem8(oraddr_t addr, uint8_t val, int *breakpoint)
226
{
227
}
228
 
229
void analysis(struct iqueue_entry *current)
230
{
231
}
232
 
233
void mtspr(uint16_t regno, const uorreg_t value)
234
{
235
}
236
 
237
unsigned long spr_read_ttcr(void)
238
{
239
  return 0;
240
}
241
 
242
void debug(int level, const char *format,...)
243
{
244
}
245
 
246
void simprintf(oraddr_t stackaddr, unsigned long regparam)
247
{
248
}
249
 
250
const char *except_name(oraddr_t except)
251
{
252
  return NULL;
253
}
254
 
255
struct dev_memarea *verify_memoryarea(oraddr_t addr)
256
{
257
  return NULL;
258
}
259
 
260
void sim_done (void)
261
{
262
}

powered by: WebSVN 2.1.0

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