| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: SS_Tlb.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 <string.h> |
| 23 | #include "SS_Tlb.h" |
| 24 | #include "SS_Strand.h" |
| 25 | |
| 26 | uint_t SS_Tlb::tlb_id_no = 0; |
| 27 | |
| 28 | SS_Tlb::SS_Tlb( Type type, uint_t size )/*{{{*/ |
| 29 | : |
| 30 | clone(ss_clone), |
| 31 | tlb_ident(tlb_id_no), |
| 32 | tlb_type(type), |
| 33 | tlb_size(size), |
| 34 | ptr_table(0), |
| 35 | generation_count(0), |
| 36 | not_a_clone(true), |
| 37 | strand_list(0), |
| 38 | no_strands(0), |
| 39 | tte_list(0) |
| 40 | { |
| 41 | tlb_id_no++; |
| 42 | |
| 43 | ptr_table = (SS_Tte**)ss_malloc(sizeof(SS_Tte*) * tlb_size); |
| 44 | |
| 45 | for (uint_t i = 0; i < tlb_size; i++) |
| 46 | ptr_table[i] = alloc_tte(i); |
| 47 | } |
| 48 | /*}}}*/ |
| 49 | SS_Tlb::SS_Tlb( SS_Tlb& tlb )/*{{{*/ |
| 50 | : |
| 51 | clone(tlb.clone), |
| 52 | tlb_type(tlb.tlb_type), |
| 53 | tlb_size(tlb.tlb_size), |
| 54 | ptr_table(0), |
| 55 | not_a_clone(false), // only the original not a clone tlb shoud destruct the strands list |
| 56 | strand_list(tlb.strand_list), // the structure can be shared ... not_a_clone controls destructing |
| 57 | no_strands(tlb.no_strands), |
| 58 | tte_list(tlb.tte_list) |
| 59 | { |
| 60 | ptr_table = (SS_Tte**)ss_malloc(sizeof(SS_Tte*) * tlb_size); |
| 61 | memcpy(ptr_table,tlb.ptr_table,sizeof(SS_Tte*) * tlb_size); |
| 62 | tlb.tte_list = 0; // Avoid having the free list at two places |
| 63 | } |
| 64 | /*}}}*/ |
| 65 | SS_Tlb::~SS_Tlb()/*{{{*/ |
| 66 | { |
| 67 | free(ptr_table); |
| 68 | } |
| 69 | /*}}}*/ |
| 70 | SS_Tlb* SS_Tlb::ss_clone( SS_Tlb* tlb )/*{{{*/ |
| 71 | { |
| 72 | return new SS_Tlb(*tlb); |
| 73 | } |
| 74 | /*}}}*/ |
| 75 | |
| 76 | void SS_Tlb::add_strand( SS_Strand* strand )/*{{{*/ |
| 77 | { |
| 78 | tlb_access.lock(); |
| 79 | ++no_strands; |
| 80 | strand_list = new Node(strand,strand_list); |
| 81 | tlb_access.unlock(); |
| 82 | } |
| 83 | /*}}}*/ |
| 84 | void SS_Tlb::rem_strand( SS_Strand* strand )/*{{{*/ |
| 85 | { |
| 86 | tlb_access.lock(); |
| 87 | assert(no_strands); |
| 88 | --no_strands; |
| 89 | |
| 90 | Node* head = strand_list; |
| 91 | |
| 92 | if (head->strand == strand) |
| 93 | { |
| 94 | strand_list = head->next; |
| 95 | delete head; |
| 96 | tlb_access.unlock(); |
| 97 | return; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | int i = 0; |
| 102 | for (Node* next = head->next; strand && next; head = next, next = next->next) |
| 103 | { |
| 104 | assert (++i <= no_strands); |
| 105 | if (next->strand == strand) |
| 106 | { |
| 107 | strand = 0; |
| 108 | head->next = next->next; |
| 109 | delete next; |
| 110 | tlb_access.unlock(); |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | assert(0); |
| 116 | tlb_access.unlock(); |
| 117 | } |
| 118 | /*}}}*/ |
| 119 | |
| 120 | SS_Tte* SS_Tlb::alloc_tte_block()/*{{{*/ |
| 121 | { |
| 122 | const SIZE = 64; |
| 123 | |
| 124 | SS_Tte* next = 0; |
| 125 | SS_Tte* block = (SS_Tte*)ss_malloc(sizeof(SS_Tte) * SIZE); |
| 126 | for (uint_t i = 1; i < SIZE; i++) |
| 127 | { |
| 128 | new(&block[i]) SS_Tte(); |
| 129 | block[i].next = next; |
| 130 | next = &block[i]; |
| 131 | } |
| 132 | tte_list = next; |
| 133 | |
| 134 | new(block) SS_Tte(); |
| 135 | |
| 136 | return block; |
| 137 | } |
| 138 | /*}}}*/ |
| 139 | |
| 140 | void SS_Tlb::dump(FILE *fp)/*{{{*/ |
| 141 | { |
| 142 | tlb_access.lock(); |
| 143 | for (int i=0; i < size(); i++) |
| 144 | { |
| 145 | if (ptr_table[i]->valid()) |
| 146 | { |
| 147 | fprintf(fp,"%04x ",i); |
| 148 | ptr_table[i]->dump(fp); |
| 149 | } |
| 150 | } |
| 151 | tlb_access.unlock(); |
| 152 | } |
| 153 | /*}}}*/ |