Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: xicache.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | /* | |
24 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | |
25 | * Use is subject to license terms. | |
26 | */ | |
27 | #pragma ident "@(#)xicache.c 1.16 06/08/31 SMI" | |
28 | ||
29 | /* | |
30 | * Support routines for the execution instruction cache | |
31 | */ | |
32 | ||
33 | #include <assert.h> | |
34 | ||
35 | #include "basics.h" | |
36 | #include "allocate.h" | |
37 | #include "simcore.h" | |
38 | #include "config.h" | |
39 | #include "xicache.h" | |
40 | ||
41 | ||
42 | /* | |
43 | * XI cache consists of two components ... | |
44 | * trans_cache: | |
45 | * A translation cache to speed I tlb and simulated I cache operation | |
46 | * instn_cache: | |
47 | * A cache of pre-decoded instructions - so we can handle snooping of | |
48 | * writes to instruction memory. | |
49 | */ | |
50 | ||
51 | xicache_t * xicache_alloc(simcpu_t * sp) | |
52 | { | |
53 | xicache_t * xcp; | |
54 | xicache_line_t * lp; | |
55 | xicache_instn_t * xip; | |
56 | ulong_t i,j; | |
57 | void (*decodemep)(simcpu_t *, xicache_instn_t *); | |
58 | ||
59 | xcp = Xcalloc(1, xicache_t); | |
60 | lp = &(xcp->line[0]); | |
61 | xip = &xcp->instn[0]; | |
62 | decodemep = sp->decodemep; | |
63 | ASSERT(decodemep != NULL); | |
64 | ||
65 | for (j=0; j<XICACHE_NUM_LINES; j++, lp++) { | |
66 | lp->tag = XC_INVALID_TAG; | |
67 | lp->memoryoffset = XICACHE_DEAD_MEMOFF; | |
68 | } | |
69 | ||
70 | for (i=0; i<XICACHE_NUM_INSTRS; i++, xip++) { | |
71 | xip->exec_funcp = decodemep; | |
72 | xip->rawi = XICACHE_DEAD_INSTN; | |
73 | } | |
74 | ||
75 | return xcp; | |
76 | } | |
77 | ||
78 | ||
79 | ||
80 | /* | |
81 | * This flush resets the decode for all instructions. | |
82 | * | |
83 | * exec_loop does this one a per-instruction basis by | |
84 | * comparing rawi to memory. | |
85 | */ | |
86 | ||
87 | void xicache_instn_flush(simcpu_t * sp) | |
88 | { | |
89 | ulong_t i; | |
90 | xicache_t * xcp; | |
91 | xicache_instn_t * xip; | |
92 | void (*decodemep)(simcpu_t *, xicache_instn_t *); | |
93 | ||
94 | XIC_FLUSH(sp); | |
95 | ||
96 | DBGXCACHE( lprintf(sp->gid, "xicache_instn_flush: pc=0x%llx " | |
97 | "[cycle=0x%llx]\n", sp->pc, sp->cycle); ); | |
98 | ||
99 | xcp = sp->xicachep; | |
100 | xip = &xcp->instn[0]; | |
101 | decodemep = sp->decodemep; | |
102 | ||
103 | for (i=0; i<XICACHE_NUM_INSTRS; i++, xip++) { | |
104 | xip->exec_funcp = decodemep; | |
105 | } | |
106 | } | |
107 | ||
108 | ||
109 | /* | |
110 | * This flush merely forces a miss in the XI-cache by | |
111 | * invalidating the translation tags. | |
112 | */ | |
113 | ||
114 | void xicache_trans_flush(simcpu_t * sp) | |
115 | { | |
116 | ulong_t j; | |
117 | xicache_t * xcp; | |
118 | xicache_line_t * lp; | |
119 | ||
120 | XIC_FLUSH(sp); | |
121 | ||
122 | DBGXCACHE( lprintf(sp->gid, "xicache_trans_flush: pc=0x%llx " | |
123 | "[cycle=0x%llx]\n", sp->pc, sp->cycle); ); | |
124 | ||
125 | xcp = sp->xicachep; | |
126 | lp = &(xcp->line[0]); | |
127 | ||
128 | for (j=0; j<XICACHE_NUM_LINES; j++, lp++) { | |
129 | if (lp->tag != XC_INVALID_TAG && | |
130 | (lp->tag & XCACHE_TAGSTATE_MASK) != XCACHE_TAGSTATE_PHYS) { | |
131 | lp->tag = XC_INVALID_TAG; | |
132 | lp->memoryoffset = XICACHE_DEAD_MEMOFF; | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | ||
138 | /* | |
139 | * This function is used to clobber the instruction decodes | |
140 | * in the xicache that correspond to a single xi-cache line | |
141 | * that is being displaced. | |
142 | * As the cache is direct-mapped you may pass in a full VA | |
143 | * or a index. | |
144 | * No tag check is done because we are explicitly clobbering the | |
145 | * line to avoid instruction aliasing .. | |
146 | */ | |
147 | ||
148 | void xicache_clobber_line_decodes(simcpu_t * sp, tvaddr_t tagva) | |
149 | { | |
150 | tvaddr_t tag; | |
151 | xicache_t * xcp; | |
152 | xicache_instn_t * ip; | |
153 | ulong_t idx, i; | |
154 | void (*decodemep)(simcpu_t *, xicache_instn_t *); | |
155 | ||
156 | DBGXCACHE( lprintf(sp->gid, "xicache_clobber_line_decodes: pc=0x%llx " | |
157 | "[cycle=0x%llx]\n", sp->pc, sp->cycle); ); | |
158 | ||
159 | xcp = sp->xicachep; | |
160 | tag = tagva & XICACHE_TAG_PURE_MASK; | |
161 | idx = (tag >> XICACHE_INSTR_SHIFT_BITS) & XICACHE_NUM_INSTR_MASK; | |
162 | decodemep = sp->decodemep; | |
163 | ||
164 | ip = &(xcp->instn[idx]); | |
165 | for (i=0; i<(XICACHE_LINE_SIZE >> XICACHE_INSTR_SHIFT_BITS); i++) { | |
166 | ip->exec_funcp = decodemep; | |
167 | ip++; | |
168 | } | |
169 | } | |
170 |