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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [mmu/] [dmmu.c] - Blame information for rev 430

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

Line No. Rev Author Line
1 62 lampret
/* dmmu.c -- Data MMU simulation
2 6 lampret
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.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
/* DMMU model (not functional yet, currently just copy of data cache). */
21
 
22
#include "dmmu.h"
23
#include "abstract.h"
24
#include "stats.h"
25 62 lampret
#include "sprs.h"
26
#include "except.h"
27 425 markom
#include "sim-config.h"
28 6 lampret
 
29 62 lampret
extern int cont_run;
30
 
31 6 lampret
/* Data MMU */
32
 
33 430 markom
inline unsigned long dmmu_simulate_tlb(unsigned long virtaddr, int write_access)
34 6 lampret
{
35 430 markom
  int set, way = -1;
36
  int i;
37
  unsigned long tagaddr;
38
  unsigned long vpn;
39
 
40
  if (!(mfspr(SPR_SR) & SPR_SR_DME) || (!testsprbits(SPR_SR, SPR_SR_DME)))
41
    return virtaddr;
42
 
43
  /* Which set to check out? */
44
  set = (virtaddr / config.dmmu.pagesize) % config.dmmu.nsets;
45
  tagaddr = (virtaddr / config.dmmu.pagesize) / config.dmmu.nsets;
46
  vpn = virtaddr / config.dmmu.pagesize;
47
 
48
  /* Scan all ways and try to find a matching way. */
49
  for (i = 0; i < config.dmmu.nways; i++)
50
    if ((getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_VPN) == vpn) &&
51
        testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_V))
52
      way = i;
53
 
54
  /* Did we find our tlb entry? */
55
  if (way >= 0) { /* Yes, we did. */
56
    dmmu_stats.loads_tlbhit++;
57
    debug(5, "DTLB hit (virtaddr=%x).\n", virtaddr);
58
 
59
    /* Test for page fault */
60
    if (mfspr (SPR_SR) & SPR_SR_SUPV) {
61
      if ( write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_SWE)
62
       || !write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_SRE))
63
        except_handle(EXCEPT_DPF, virtaddr);
64
    } else {
65
      if ( write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_UWE)
66
       || !write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_URE))
67
        except_handle(EXCEPT_DPF, virtaddr);
68
    }
69
 
70
    /* Set LRUs */
71
    for (i = 0; i < config.dmmu.nways; i++)
72
      if (testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
73
        setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
74
    setsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
75
 
76
    return getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize);
77
  }
78
  else {  /* No, we didn't. */
79
    int minlru = config.dmmu.ustates - 1;
80
    int minway = 0;
81
 
82
    dmmu_stats.loads_tlbmiss++;
83
#if 0
84
    for (i = 0; i < config.dmmu.nways; i++)
85
      if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) < minlru)
86
        minway = i;
87
 
88
    setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_VPN, vpn);
89
    for (i = 0; i < config.dmmu.nways; i++)
90
      if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
91
        setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
92
    setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
93
    setsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN, vpn); /* 1 to 1 */
94
    setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_V, 1);
95
#endif
96
    except_handle(EXCEPT_DTLBMISS, virtaddr);
97
    /* if tlb refill implemented in HW */
98
    /* return getsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize); */
99
    return 0;
100
  }
101
}
102
 
103
unsigned long dmmu_translate(unsigned long virtaddr, int write_access)
104
{
105
  unsigned long phyaddr = dmmu_simulate_tlb(virtaddr, write_access);
106 429 markom
 
107
/*  printf("DMMU translate(%x) = %x\n", virtaddr, phyaddr);*/
108
  return phyaddr;
109 6 lampret
}
110
 
111
 
112 62 lampret
void dtlb_info()
113 6 lampret
{
114 429 markom
  if (!testsprbits(SPR_UPR, SPR_UPR_DMP)) {
115
    printf("DMMU not implemented. Set UPR[DMP].\n");
116
    return;
117
  }
118
 
119
  printf("Data MMU %dKB: ", config.dmmu.nsets * config.dmmu.entrysize * config.dmmu.nways / 1024);
120
  printf("%d ways, %d sets, entry size %d bytes\n", config.dmmu.nways, config.dmmu.nsets, config.dmmu.entrysize);
121 6 lampret
}
122
 
123 62 lampret
/* First check if virtual address is covered by DTLB and if it is:
124
    - increment DTLB read hit stats,
125 425 markom
    - set 'lru' at this way to config.dmmu.ustates - 1 and
126 6 lampret
      decrement 'lru' of other ways unless they have reached 0,
127 62 lampret
    - check page access attributes and invoke DMMU page fault exception
128
      handler if necessary
129 6 lampret
   and if not:
130 62 lampret
    - increment DTLB read miss stats
131
    - find lru way and entry and invoke DTLB miss exception handler
132 425 markom
    - set 'lru' with config.dmmu.ustates - 1 and decrement 'lru' of other
133 6 lampret
      ways unless they have reached 0
134
*/
135
 
136 102 lampret
void dtlb_status(int start_set)
137 6 lampret
{
138 429 markom
  int set;
139
  int way;
140
  int end_set = config.dmmu.nsets;
141 62 lampret
 
142 429 markom
  if (!testsprbits(SPR_UPR, SPR_UPR_DMP)) {
143
    printf("DMMU not implemented. Set UPR[DMP].\n");
144
    return;
145
  }
146 102 lampret
 
147 429 markom
  if ((start_set >= 0) && (start_set < end_set))
148
    end_set = start_set + 1;
149
  else
150
    start_set = 0;
151 62 lampret
 
152 429 markom
  printf("\nDMMU: ");
153
  /* Scan set(s) and way(s). */
154
  for (set = start_set; set < end_set; set++) {
155
    printf("\nSet %x: ", set);
156
    for (way = 0; way < config.dmmu.nways; way++) {
157
      printf("  way %d: ", way);
158
      printf("vpn=%x ", getsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_VPN));
159
      printf("lru=%x ", getsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_LRU));
160
      printf("pl1=%x ", getsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_PL1));
161
      printf("v=%x ", getsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_V));
162
 
163
      printf("a=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_A));
164
      printf("d=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_D));
165
      printf("ure=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_URE));
166
      printf("uwe=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_UWE));
167
      printf("sre=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_SRE));
168
      printf("swe=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_SWE));
169
      printf("ppn=%x ", getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_PPN));
170
    }
171
  }
172
  printf("\n");
173 6 lampret
}

powered by: WebSVN 2.1.0

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