Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_AsiCtrReg.h | |
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 | #ifndef __SS_AsiCtrReg_h__ | |
24 | #define __SS_AsiCtrReg_h__ | |
25 | ||
26 | #include "BL_Mutex.h" | |
27 | #include "SS_AsiSpace.h" | |
28 | #include "SS_SnapShot.h" | |
29 | ||
30 | class SS_Node; | |
31 | ||
32 | class SS_AsiCtrReg | |
33 | { | |
34 | public: | |
35 | SS_AsiCtrReg( const char* __name, uint64_t __mask_ro, uint64_t __mask_r1c, uint64_t __mask_rw, uint64_t __mask_w1c, uint64_t __init ) | |
36 | : | |
37 | _data(__init), | |
38 | _mask_ro(__mask_ro), | |
39 | _mask_rw(__mask_rw), | |
40 | _mask_r1c(__mask_r1c), | |
41 | _mask_w1c(__mask_w1c), | |
42 | _init(__init), | |
43 | _name(__name) | |
44 | {} | |
45 | ||
46 | const char* name() const { return _name; } | |
47 | ||
48 | uint64_t get() { uint64_t tmp = _data; _data &= ~_mask_r1c; return tmp; } | |
49 | void set( uint64_t v ) { _data = (v & _mask_rw) | (_data & ~(_mask_rw | (v & _mask_w1c))); } | |
50 | void set_unmasked( uint64_t v ) { _data = v; } | |
51 | ||
52 | uint64_t get_ro_mask() const { return _mask_ro; } | |
53 | uint64_t get_rw_mask() const { return _mask_rw; } | |
54 | uint64_t get_r1c_mask() const { return _mask_r1c; } | |
55 | uint64_t get_w1c_mask() const { return _mask_w1c; } | |
56 | uint64_t get_init_mask() const { return _init; } | |
57 | ||
58 | void snapshot( SS_SnapShot& ss, const char* prefix="", const char* suffix="" ); | |
59 | ||
60 | template<class Type> | |
61 | static void snapshot( SS_SnapShot& ss, Type* array, uint_t size, const char* prefix="", const char* suffix="" ) | |
62 | { | |
63 | for (int i=0; i<size; i++) | |
64 | { | |
65 | char num[32]; | |
66 | if (*suffix != 0) | |
67 | sprintf(num,"%s.%d",suffix,i); | |
68 | else | |
69 | sprintf(num,"%d",i); | |
70 | array[i].snapshot(ss,prefix,num); | |
71 | } | |
72 | } | |
73 | ||
74 | static SS_AsiSpace::Error ld64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t* data ); | |
75 | static SS_AsiSpace::Error st64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t data ); | |
76 | static SS_AsiSpace::Error rd64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t* data ); | |
77 | static SS_AsiSpace::Error wr64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t data ); | |
78 | ||
79 | protected: | |
80 | uint64_t _data; | |
81 | uint64_t _mask_ro; // read only | |
82 | uint64_t _mask_rw; // read write | |
83 | uint64_t _mask_r1c; // read one clear | |
84 | uint64_t _mask_w1c; // write one clear | |
85 | uint64_t _init; | |
86 | const char* _name; | |
87 | }; | |
88 | ||
89 | class SS_SharedAsiCtrReg : public SS_AsiCtrReg | |
90 | { | |
91 | public: | |
92 | SS_SharedAsiCtrReg( const char* __name, uint64_t __mask_ro, uint64_t __mask_r1c, uint64_t __mask_rw, uint64_t __mask_w1c, uint64_t __init ) | |
93 | : | |
94 | SS_AsiCtrReg(__name,__mask_ro,__mask_r1c,__mask_rw,__mask_w1c,__init) | |
95 | {} | |
96 | ||
97 | int lock() { return _mutex.lock(); } | |
98 | int unlock() { return _mutex.unlock(); } | |
99 | int trylock() { return _mutex.trylock(); } | |
100 | ||
101 | void snapshot( SS_SnapShot& ss, const char* prefix="", const char* suffix="" ) | |
102 | { | |
103 | SS_AsiCtrReg::snapshot(ss,prefix,suffix); | |
104 | } | |
105 | ||
106 | template<class Type> | |
107 | static void snapshot( SS_SnapShot& ss, Type* array, uint_t size, const char* prefix="", const char* suffix="" ) | |
108 | { | |
109 | SS_AsiCtrReg::snapshot<Type>(ss,array,size,prefix,suffix); | |
110 | } | |
111 | ||
112 | static SS_AsiSpace::Error ld64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t* data ); | |
113 | static SS_AsiSpace::Error st64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t data ); | |
114 | static SS_AsiSpace::Error rd64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t* data ); | |
115 | static SS_AsiSpace::Error wr64( SS_Node*, void*, SS_Strand*, SS_Vaddr, uint64_t data ); | |
116 | ||
117 | protected: | |
118 | BL_Mutex _mutex; | |
119 | }; | |
120 | ||
121 | #endif |