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 425

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

powered by: WebSVN 2.1.0

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