| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: BL_ThinFieldObj.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 __BL_ThinFieldObj_h__ |
| 24 | #define __BL_ThinFieldObj_h__ |
| 25 | /************************************************************************ |
| 26 | ** |
| 27 | ** Copyright (C) 2002, Sun Microsystems, Inc. |
| 28 | ** |
| 29 | ** Sun considers its source code as an unpublished, proprietary |
| 30 | ** trade secret and it is available only under strict license provisions. |
| 31 | ** This copyright notice is placed here only to protect Sun in the event |
| 32 | ** the source is deemed a published work. Disassembly, decompilation, |
| 33 | ** or other means of reducing the object code to human readable form |
| 34 | ** is prohibited by the license agreement under which this code is |
| 35 | ** provided to the user or company in possession of this copy." |
| 36 | ** |
| 37 | *************************************************************************/ |
| 38 | |
| 39 | #include "BL_Types.h" |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * This class is used to represent objects that have fields |
| 44 | * For example, this class would be appropriate to represetn control or status |
| 45 | * registers or TTEs. |
| 46 | */ |
| 47 | template < |
| 48 | uint64_t mask, // Which bits are implemented as read/write |
| 49 | uint64_t rw1c, // Which bits are implemented as read/write-1-clear |
| 50 | uint64_t bits, // Which bits are physically implemented |
| 51 | uint64_t init> // The initial power-on-reset value |
| 52 | class BL_ThinFieldObj { |
| 53 | |
| 54 | public: |
| 55 | BL_ThinFieldObj() : |
| 56 | data(0) { } |
| 57 | |
| 58 | BL_ThinFieldObj& operator=( const BL_ThinFieldObj& obj ) |
| 59 | { |
| 60 | data = obj.data; |
| 61 | return *this; |
| 62 | } |
| 63 | |
| 64 | bool operator==( const BL_ThinFieldObj& obj ) const { return data == obj.data; } |
| 65 | |
| 66 | /** |
| 67 | * Return the field's size in bits |
| 68 | * |
| 69 | * @param field The number of this field |
| 70 | * @return The field's size in bits |
| 71 | * @see MM_McmTteTag::FieldT |
| 72 | */ |
| 73 | virtual uint32_t getSize( uint_t field ) const { return 0; } |
| 74 | |
| 75 | /** |
| 76 | * Return the field's offset in the BL_ThinFieldObj |
| 77 | * |
| 78 | * @param field The number of this field |
| 79 | * @return The field's offset |
| 80 | * @see MM_McmTteTag::FieldT |
| 81 | */ |
| 82 | virtual uint32_t getOffset( uint_t field ) const { return 0; } |
| 83 | |
| 84 | /** |
| 85 | * Return a string representation of the field name |
| 86 | * |
| 87 | * @param field The number of this field |
| 88 | * @return The name of the field |
| 89 | * @see MM_McmTteTag::FieldT |
| 90 | */ |
| 91 | virtual const char* getName() const { return "register with -f option in xml2reg"; } |
| 92 | |
| 93 | /** |
| 94 | * Return a string representation of the field name |
| 95 | * |
| 96 | * @param field The number of this field |
| 97 | * @return The name of the field |
| 98 | * @see MM_McmTteTag::FieldT |
| 99 | */ |
| 100 | virtual const char* getName( uint_t field ) const { return "register with -f option in xml2reg"; } |
| 101 | |
| 102 | uint64_t getNative() const { return get(); } |
| 103 | void setNative( uint64_t value ) { set(value); } |
| 104 | void setNotify( uint64_t value ) { set_notify(value); } |
| 105 | void setNativeHW( uint64_t value ) { set_phys_masked(value); } |
| 106 | |
| 107 | // The above getNative(), setNative(), and setNativeHW() will be depricated and are going to |
| 108 | // be replaced with the methods get(), set(), set_unmasked() |
| 109 | |
| 110 | // get() returns the value of the field object. |
| 111 | uint64_t get() const { return data; } |
| 112 | |
| 113 | // set() sets the value of the field object, respecting RO and RW1C fields. |
| 114 | void set( uint64_t v ) { data = (v & mask) | (data & ~(mask | (v & rw1c))); } |
| 115 | |
| 116 | // set_notify() is as set() and notifies the simulator that the value has changed. |
| 117 | // This method is primarily for front-end access since Riesling is wide open. |
| 118 | void set_notify( uint64_t v ) { call->call(this,(v & mask) | (data & ~(mask | (v & rw1c)))); } |
| 119 | |
| 120 | // set_data() sets the full 64bits of the field objects. |
| 121 | void set_data( uint64_t value ) { data = value; } |
| 122 | |
| 123 | // set_phys_masked() sets the RO, RW, and RW1C fields of the field object. This |
| 124 | // method respects the reserved fields. |
| 125 | void set_phys_masked( uint64_t value ) { data = (value & bits); } |
| 126 | |
| 127 | uint64_t get_mask() const { return mask; } |
| 128 | uint64_t get_rw1c_mask() const { return rw1c; } |
| 129 | uint64_t get_phys_mask() const { return bits; } |
| 130 | uint64_t get_init() const { return init; } |
| 131 | |
| 132 | void snapshot( SS_SnapShot &ss, const char* prefix="" ) |
| 133 | { |
| 134 | sprintf(ss.tag,"%s.data",prefix); ss.val(&data); |
| 135 | } |
| 136 | |
| 137 | protected: |
| 138 | uint64_t data; // Thew current contents of the register |
| 139 | }; |
| 140 | |
| 141 | #endif /* __BL_ThinFieldObj_h__ */ |