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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 1452 nogj
/* op_support.c -- Support routines for micro operations
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
#include <stdlib.h>
22
 
23
#include "config.h"
24
 
25
#ifdef HAVE_INTTYPES_H
26
#include <inttypes.h>
27
#endif
28
 
29
#include "port.h"
30
#include "arch.h"
31
#include "opcode/or32.h"
32
#include "sim-config.h"
33
#include "spr_defs.h"
34
#include "except.h"
35
#include "immu.h"
36
#include "abstract.h"
37
#include "execute.h"
38
#include "sched.h"
39
 
40
#include "i386_regs.h"
41
 
42
#include "dyn_rec.h"
43
#include "op_support.h"
44
 
45
#include "rec_i386.h"
46
 
47
/* Stuff that is really a `micro' operation but is rather big (or for some other
48 1481 nogj
 * reason like calling exit()) */
49 1452 nogj
 
50 1481 nogj
void upd_reg_from_t(oraddr_t pc, int bound)
51 1452 nogj
{
52
  int reg;
53
 
54 1481 nogj
  pc = ((pc & (PAGE_SIZE - 1)) / 4);
55 1452 nogj
 
56 1481 nogj
  if(bound) {
57
    reg = cpu_state.curr_page->ts_bound[pc + 1];
58
  } else
59
    reg = cpu_state.curr_page->ts_during[pc];
60
 
61 1452 nogj
  if(reg & 0x1f)
62
    cpu_state.reg[reg & 0x1f] = cpu_state.t0;
63
 
64
  if((reg >> 5) & 0x1f)
65
    cpu_state.reg[(reg >> 5) & 0x1f] = cpu_state.t1;
66
 
67
  if((reg >> 10) & 0x1f)
68
    cpu_state.reg[(reg >> 10) & 0x1f] = cpu_state.t2;
69
}
70
 
71
void op_support_nop_exit(void)
72
{
73 1481 nogj
  upd_reg_from_t(get_pc(), 0);
74
  PRINTF("exit(%"PRIxREG")\n", cpu_state.reg[3]);
75 1452 nogj
  fprintf(stderr, "@reset : cycles %lld, insn #%lld\n",
76
          runtime.sim.reset_cycles, runtime.cpu.reset_instructions);
77
  fprintf(stderr, "@exit  : cycles %lld, insn #%lld\n", runtime.sim.cycles,
78
          runtime.cpu.instructions);
79
  fprintf(stderr, " diff  : cycles %lld, insn #%lld\n",
80
          runtime.sim.cycles - runtime.sim.reset_cycles,
81
          runtime.cpu.instructions - runtime.cpu.reset_instructions);
82
  /* FIXME: Implement emulation of a stalled cpu
83
  if (config.debug.gdb_enabled)
84
    set_stall_state (1);
85 1481 nogj
  else {
86
    handle_sim_command();
87
    sim_done();
88
  }
89 1452 nogj
  */
90
  exit(0);
91
}
92
 
93
void op_support_nop_reset(void)
94
{
95
  PRINTF("****************** counters reset ******************\n");
96
  PRINTF("cycles %lld, insn #%lld\n", runtime.sim.cycles, runtime.cpu.instructions);
97
  PRINTF("****************** counters reset ******************\n");
98
  runtime.sim.reset_cycles = runtime.sim.cycles;
99
  runtime.cpu.reset_instructions = runtime.cpu.instructions;
100
}
101
 
102
void op_support_nop_printf(void)
103
{
104 1481 nogj
  upd_reg_from_t(get_pc(), 0);
105 1452 nogj
  simprintf(cpu_state.reg[4], cpu_state.reg[3]);
106
}
107
 
108
void op_support_nop_report(void)
109
{
110 1481 nogj
  upd_reg_from_t(get_pc(), 0);
111 1452 nogj
  PRINTF("report(0x%"PRIxREG");\n", cpu_state.reg[3]);
112
}
113
 
114
void op_support_nop_report_imm(int imm)
115
{
116 1481 nogj
  upd_reg_from_t(get_pc(), 0);
117 1452 nogj
  PRINTF("report %i (0x%"PRIxREG");\n", imm, cpu_state.reg[3]);
118
}
119
 
120
/* Handles a jump */
121
/* addr is a VIRTUAL address */
122
/* NOTE: We can't use env since this code is compiled like the rest of the
123
 * simulator (most likely without -fomit-frame-pointer) and thus env will point
124
 * to some bogus value. */
125
void do_jump(oraddr_t addr)
126
{
127
  struct dyn_page *target_dp;
128
  oraddr_t phys_page;
129
 
130 1481 nogj
  /* Temporaries are always shipped out */
131
  cpu_state.ts_current = 1;
132
 
133 1452 nogj
  /* The pc is set to the location of the jump in op_set_pc_preemt(_check) and
134
   * then it is incermented by 4 when the scheduler is run.  If a scheduled job
135
   * so happens to raise an exception cpu_state.delay_insn will still be set and
136
   * so except_handle will do its pc adjusting magic (ie. -4 from it) and every-
137
   * thing ends up just working right, except when a scheduled job does not
138
   * raise an exeception.  In that case we set the pc here explicitly */
139
  set_pc(addr);
140
 
141
  /* immu_translate must be called after set_pc.  If it would be called before
142
   * it and it issued an ITLB miss then it would appear that the instruction
143
   * that faulted was the instruction in the delay slot which is incorrect */
144
  phys_page = immu_translate(addr);
145
 
146
  /* do_jump is called from the delay slot, which is the jump instruction
147
   * address + 4. */
148
/*
149
  printf("Recompiled code jumping out to %"PRIxADDR" from %"PRIxADDR"\n",
150
         phys_page, cpu_state.sprs[SPR_PPC] - 4);
151
*/
152
 
153
  /* immu_translate() adds the hit delay to runtime.sim.mem_cycles but we add it
154
   * to the cycles when the instruction is executed so if we don't reset it now
155
   * it will produce wrong results */
156
  runtime.sim.mem_cycles = 0;
157
 
158
  target_dp = find_dynd_page(phys_page);
159
 
160
  if(!target_dp)
161
    target_dp = new_dp(phys_page);
162
 
163
  /* Since writes to the 0x0-0xff range do not dirtyfy a page recompile the 0x0
164
   * page if the jump is to that location */
165
  if(phys_page < 0x100)
166
    target_dp->dirty = 1;
167
 
168
  if(target_dp->dirty)
169
    recompile_page(target_dp);
170
 
171
  cpu_state.curr_page = target_dp;
172
 
173
  /* FIXME: If the page is backed by more than one type of memory, this will
174
   * produce wrong results */
175
  if(cpu_state.sprs[SPR_SR] & SPR_SR_IME)
176
    /* Add the mmu hit delay to the cycle counter */
177
    upd_cycles_dec(target_dp->delayr - config.immu.hitdelay);
178
  else
179
    upd_cycles_dec(target_dp->delayr);
180
 
181
  cpu_state.ts_current = 0;
182
 
183 1481 nogj
  /* Initially this returned the address that we should jump to and then the
184
   * recompiled code performed the jump.  This was no problem if the jump was
185
   * trully an interpage jump or if the location didn't need recompileation.  If
186
   * the jump is page local and the page needs recompileation there is a very
187
   * high probability that the page will move in memory and then the return
188
   * address that is on the stack will point to memory that has already been
189
   * freed, sometimes leading to crashes */
190 1452 nogj
  /* This looks like it could really be simpler, but no it can't.  The only
191
   * issue here is the stack: it has to be unwound.  This function is called
192
   * from except_handle, which generally ends up quite high on the stack... */
193 1481 nogj
  enter_dyn_code(phys_page, target_dp);
194 1452 nogj
}
195
 
196 1481 nogj
/* Wrapper around analysis() that contains all the recompiler specific stuff */
197
void op_support_analysis(void)
198 1452 nogj
{
199 1481 nogj
  upd_sim_cycles();
200
  if(ADDR_PAGE(cpu_state.pc) != cpu_state.pc)
201
    upd_reg_from_t(cpu_state.pc - (cpu_state.delay_insn ? 4 : 0), 0);
202 1452 nogj
  else
203 1481 nogj
    upd_reg_from_t(cpu_state.pc, 0);
204
  runtime.cpu.instructions++;
205
  analysis(&cpu_state.iqueue);
206 1452 nogj
}
207
 

powered by: WebSVN 2.1.0

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