~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to cpu/icache.cc

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/////////////////////////////////////////////////////////////////////////
2
 
// $Id: icache.cc,v 1.12 2008/05/04 05:37:36 sshwarts Exp $
 
2
// $Id: icache.cc,v 1.25 2009/03/24 16:04:47 sshwarts Exp $
3
3
/////////////////////////////////////////////////////////////////////////
4
4
//
5
5
//   Copyright (c) 2007 Stanislav Shwartsman
17
17
//
18
18
//  You should have received a copy of the GNU Lesser General Public
19
19
//  License along with this library; if not, write to the Free Software
20
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
20
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
21
21
//
22
22
/////////////////////////////////////////////////////////////////////////
23
23
 
26
26
#include "cpu.h"
27
27
#define LOG_THIS BX_CPU_THIS_PTR
28
28
 
29
 
bx_bool BX_CPU_C::fetchInstruction(bxInstruction_c *iStorage, const Bit8u *fetchPtr, unsigned remainingInPage)
30
 
{
31
 
  unsigned ret;
32
 
 
33
 
#if BX_SUPPORT_X86_64
34
 
  if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64)
35
 
    ret = fetchDecode64(fetchPtr, iStorage, remainingInPage);
36
 
  else
37
 
#endif
38
 
    ret = fetchDecode32(fetchPtr, iStorage, remainingInPage);
39
 
 
40
 
  if (ret==0) {
41
 
    // handle instrumentation callback inside boundaryFetch
42
 
    boundaryFetch(fetchPtr, remainingInPage, iStorage);
43
 
    return 0;
44
 
  }
45
 
 
46
 
#if BX_INSTRUMENTATION
47
 
  BX_INSTR_OPCODE(BX_CPU_ID, fetchPtr, iStorage->ilen(),
48
 
       BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, Is64BitMode());
49
 
#endif
50
 
 
51
 
  return 1;
52
 
}
53
 
 
54
 
#if BX_SUPPORT_ICACHE
55
 
 
56
29
bxPageWriteStampTable pageWriteStampTable;
57
30
 
58
 
void purgeICaches(void)
59
 
{
60
 
  for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
61
 
    BX_CPU(i)->iCache.purgeICacheEntries();
62
 
 
63
 
  pageWriteStampTable.purgeWriteStamps();
64
 
}
65
 
 
66
31
void flushICaches(void)
67
32
{
68
 
  for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
 
33
  for (unsigned i=0; i<BX_SMP_PROCESSORS; i++) {
69
34
    BX_CPU(i)->iCache.flushICacheEntries();
 
35
    BX_CPU(i)->invalidate_prefetch_q();
 
36
#if BX_SUPPORT_TRACE_CACHE
 
37
    BX_CPU(i)->async_event |= BX_ASYNC_EVENT_STOP_TRACE;
 
38
#endif
 
39
  }
70
40
 
71
41
  pageWriteStampTable.resetWriteStamps();
72
42
}
73
43
 
 
44
void purgeICaches(void)
 
45
{
 
46
  flushICaches();
 
47
}
 
48
 
74
49
#if BX_SUPPORT_TRACE_CACHE
75
50
 
76
 
void stopTraceExecution(void)
 
51
void handleSMC(void)
77
52
{
78
53
  for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
79
54
    BX_CPU(i)->async_event |= BX_ASYNC_EVENT_STOP_TRACE;
86
61
  // Cache miss. We weren't so lucky, but let's be optimistic - try to build 
87
62
  // trace from incoming instruction bytes stream !
88
63
  cache_entry->pAddr = pAddr;
 
64
  pageWriteStampTable.markICache(pAddr);
89
65
  cache_entry->writeStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr);
90
66
 
91
67
  unsigned remainingInPage = BX_CPU_THIS_PTR eipPageWindowSize - eipBiased;
139
115
 
140
116
bx_bool BX_CPU_C::mergeTraces(bxICacheEntry_c *entry, bxInstruction_c *i, bx_phy_address pAddr)
141
117
{
142
 
  bxICacheEntry_c *e = BX_CPU_THIS_PTR iCache.get_entry(pAddr);
 
118
  bxICacheEntry_c *e = BX_CPU_THIS_PTR iCache.get_entry(pAddr, BX_CPU_THIS_PTR fetchModeMask);
143
119
 
144
120
  if ((e->pAddr == pAddr) && (e->writeStamp == entry->writeStamp))
145
121
  {
161
137
 
162
138
#else // BX_SUPPORT_TRACE_CACHE == 0
163
139
 
164
 
void BX_CPU_C::serveICacheMiss(bxICacheEntry_c *cache_entry, Bit32u eipBiased, bx_phy_address pAddr)
 
140
bx_bool BX_CPU_C::fetchInstruction(bxInstruction_c *iStorage, Bit32u eipBiased)
165
141
{
166
142
  unsigned remainingInPage = BX_CPU_THIS_PTR eipPageWindowSize - eipBiased;
167
143
  const Bit8u *fetchPtr = BX_CPU_THIS_PTR eipFetchPtr + eipBiased;
168
 
      
 
144
  unsigned ret;
 
145
 
 
146
#if BX_SUPPORT_X86_64
 
147
  if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64)
 
148
    ret = fetchDecode64(fetchPtr, iStorage, remainingInPage);
 
149
  else
 
150
#endif
 
151
    ret = fetchDecode32(fetchPtr, iStorage, remainingInPage);
 
152
 
 
153
  if (ret==0) {
 
154
    // handle instrumentation callback inside boundaryFetch
 
155
    boundaryFetch(fetchPtr, remainingInPage, iStorage);
 
156
    return 0;
 
157
  }
 
158
 
 
159
#if BX_INSTRUMENTATION
 
160
  BX_INSTR_OPCODE(BX_CPU_ID, fetchPtr, iStorage->ilen(),
 
161
       BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b, Is64BitMode());
 
162
#endif
 
163
 
 
164
  return 1;
 
165
}
 
166
 
 
167
void BX_CPU_C::serveICacheMiss(bxICacheEntry_c *cache_entry, Bit32u eipBiased, bx_phy_address pAddr)
 
168
{
169
169
  // The entry will be marked valid if fetchdecode will succeed
170
170
  cache_entry->writeStamp = ICacheWriteStampInvalid;
171
171
 
172
 
  if (fetchInstruction(cache_entry->i, fetchPtr, remainingInPage)) {
 
172
  if (fetchInstruction(cache_entry->i, eipBiased)) {
173
173
    cache_entry->pAddr = pAddr;
174
174
    cache_entry->writeStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr);
175
175
  }
176
176
}
177
177
 
178
178
#endif
179
 
 
180
 
#endif // BX_SUPPORT_ICACHE