Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: SS_AddressMap.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 "SS_AddressMap.h" | |
23 | #include <new> | |
24 | ||
25 | SS_AddressMap::Range* SS_AddressMap::fail = new SS_AddressMap::Range(SS_Paddr(0),~SS_Paddr(0),0,SS_AddressMap::REL,no_access,no_access); | |
26 | ||
27 | SS_AddressMap::SS_AddressMap()/*{{{*/ | |
28 | : | |
29 | table(0), | |
30 | alloc(0), | |
31 | _size(0) | |
32 | {} | |
33 | /*}}}*/ | |
34 | SS_AddressMap::~SS_AddressMap()/*{{{*/ | |
35 | { | |
36 | if (table) | |
37 | free(table); | |
38 | } | |
39 | /*}}}*/ | |
40 | ||
41 | void SS_AddressMap::add( SS_Paddr lo, SS_Paddr hi, void* obj, SS_AddressMap::Addressing rel, SS_Access::Func cpu, SS_Access::Func usr )/*{{{*/ | |
42 | { | |
43 | uint_t p; | |
44 | ||
45 | if (usr == 0) usr = cpu; | |
46 | ||
47 | if (_size == alloc) | |
48 | { | |
49 | alloc += ALLOC; | |
50 | table = (Range*)realloc(table,sizeof(Range) * alloc); | |
51 | } | |
52 | ||
53 | if (_size == 0) | |
54 | { | |
55 | p = 0; | |
56 | } | |
57 | else | |
58 | { | |
59 | uint_t l = 0; | |
60 | uint_t h = _size; | |
61 | uint_t m = _size >> 1; | |
62 | Range* r = &table[m]; | |
63 | ||
64 | while (l != m) | |
65 | { | |
66 | ((hi < r->lo) ? h : l) = m; | |
67 | m = l + ((h - l) >> 1); | |
68 | r = &table[m]; | |
69 | } | |
70 | ||
71 | if (hi < r->lo) | |
72 | { | |
73 | for (uint_t i=_size; i > m; i--) | |
74 | table[i] = table[i-1]; | |
75 | p = m; | |
76 | } | |
77 | else if (r->hi < lo) | |
78 | { | |
79 | for (uint_t i=_size; i > (m + 1); i--) | |
80 | table[i] = table[i-1]; | |
81 | p = m + 1; | |
82 | } | |
83 | else | |
84 | { | |
85 | fprintf(stderr,"SS_AddressMap: region with lo=0x%llx and hi=0x%llx overlaps with lo=0x%llx and hi=0x%llx\n",lo,hi,r->lo,r->hi); | |
86 | fprintf(stderr,"SS_AddressMap: Dropping the region\n"); | |
87 | return; | |
88 | } | |
89 | } | |
90 | ||
91 | new (&table[p]) Range(lo,hi,obj,rel,cpu,usr); | |
92 | ||
93 | ++_size; | |
94 | } | |
95 | /*}}}*/ | |
96 | ||
97 | void SS_AddressMap::no_access( void*, uint_t sid, SS_Access::Type type, SS_Paddr pa, uint_t size, uint64_t* )/*{{{*/ | |
98 | { | |
99 | fprintf(stderr,"Access unmapped address 0x%llx\n",pa); | |
100 | } | |
101 | /*}}}*/ | |
102 | ||
103 | ||
104 | ||
105 |