Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_TimedTlb.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: SS_TimedTlb.cc
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "SS_TimedTlb.h"
25
26SS_TimedTlb::SS_TimedTlb( SS_Tlb* _tlb, uint_t _upper_size )/*{{{*/
27 :
28 latest_time(0),
29 latest_tlb(_tlb),
30 upper_size(_upper_size),
31 socket(NULL)
32{
33 tlb[latest_time] = latest_tlb;
34}
35/*}}}*/
36SS_Tlb* SS_TimedTlb::modify( uint32_t time )/*{{{*/
37{
38 if (latest_time < time)
39 {
40 tlb[time] = latest_tlb = (latest_tlb->clone)(latest_tlb);
41 latest_time = time;
42 }
43 else if (latest_time > time)
44 {
45 // If we hit this assertion then we have an inconsistancy. Somehow we ended up with
46 // a tlb at modification times t1 and t2 and we get asked to create a tlb with a
47 // modification time tx such that t1 < tx < t2. Hence that would mean modification
48 // caused by tx should propagate to t2 and higher meaning that we used a wrong tlb
49 // earlier. So I think this should never occur. Hence bail out.
50 char buffer[256];
51 sprintf(buffer, "ERROR: TLB modification time violation: last tlb_write_time=%d >= new tlb_write_time=%d",latest_time,time);
52 fprintf(stderr,"%s\n", buffer);
53 if (socket)
54 {
55 socket->write_err(buffer);
56 // if pli-socket condition is bad, we should not process pli commands any further
57 socket->pli_stop();
58 }
59 }
60
61 // Keep the number of TLBs that we keep around under an upper limit
62 // as they can eat quite some memory over time.
63
64 while (tlb.size() >= upper_size)
65 {
66 std::map<uint32_t,SS_Tlb*,Cmp>::reverse_iterator i = tlb.rbegin();
67 delete (*i).second;
68 tlb.erase((*i).first);
69 }
70
71 return latest_tlb;
72}
73/*}}}*/
74
75
76SS_Tlb* SS_TimedTlb::lookup( uint32_t time )
77{
78 for (std::map<uint32_t,SS_Tlb*,Cmp>::iterator i = tlb.begin(); i != tlb.end(); i++)
79 if (time >= (*i).first)
80 if ((*i).second)
81 return (*i).second;
82 else
83 {
84 char buffer[256];
85 sprintf(buffer, "INTERNAL ERROR: SS_TimedTlb lookup time got deleted, max size=%d", upper_size);
86 fprintf(stderr,"%s\n",buffer);
87 if (socket)
88 {
89 socket->write_err(buffer);
90 // if pli-socket condition is bad, we should not process pli commands any further
91 socket->pli_stop();
92 }
93 }
94
95 // The above should always succeed as we insert the initial tlb with time stamp 0.
96
97 char buffer[256];
98 sprintf(buffer, "INTERNAL ERROR: SS_TimedTlb lookup time (%d) not matched, max size=%d", time, upper_size);
99 fprintf(stderr,"%s\n",buffer);
100 if (socket)
101 {
102 socket->write_err(buffer);
103 // if pli-socket condition is bad, we should not process pli commands any further
104 socket->pli_stop();
105 }
106 return 0;
107}
108
109