Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / verilog / niu / sparse_mem_model / pli / src / ext_sys_mem.h
CommitLineData
86530b38
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: ext_sys_mem.h
5* Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
6* 4150 Network Circle, Santa Clara, California 95054, U.S.A.
7*
8* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9*
10* This program is free software; you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation; version 2 of the License.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License
20* along with this program; if not, write to the Free Software
21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*
23* For the avoidance of doubt, and except that if any non-GPL license
24* choice is available it will apply instead, Sun elects to use only
25* the General Public License version 2 (GPLv2) at this time for any
26* software where a choice of GPL license versions is made
27* available with the language indicating that GPLv2 or any later version
28* may be used, or where a choice of which version of the GPL is applied is
29* otherwise unspecified.
30*
31* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
32* CA 95054 USA or visit www.sun.com if you need additional information or
33* have any questions.
34*
35*
36* ========== Copyright Header End ============================================
37*/
38// Copyright 2001 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
39//
40// This software and any related documentation (the "Materials") are the
41// confidential proprietary information of AMD. Unless otherwise provided
42// in an agreement specifically licensing the Materials, the Materials are
43// provided in confidence and may not to be used, distributed, modified, or
44// reproduced in whole or in part by any means.
45//
46// LIMITATION OF LIABILITY: THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY
47// EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO
48// WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY
49// PARTICULAR PURPOSE, OR WARRANTIES ARISING FORM CONDUCT, COURSE OF
50// DEALING, OR USAGE OF TRADE. IN NO EVENT SHALL AMD OR ITS LICENSORS BE
51// LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
52// DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF
53// INFORMATION) ARISING OUT OF THE USE OF OR INABILITY TO USE THE
54// MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
55// DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE EXCLUSION OR
56// LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE
57// ABOVE LIMITATION MAY NOT APPLY TO YOU.
58//
59// AMD does not assume any responsibility for any errors which may appear
60// in the Materials nor any responsibility to support or update the
61// Materials. AMD retains the right to modify the Materials at any time,
62// without notice, and is not obligated to provide such modified Materials
63// to you.
64//
65// NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make
66// any further information, software, technical information, know-how, or
67// show-how available to you.
68//
69// U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with
70// "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government
71// is subject to the restrictions as set forth in FAR 52.227-14 and DFAR
72// 252.227-7013, et seq., or its successor. Use of the Materials by the
73// Government constitutes acknowledgement of AMD's proprietary rights in
74// them.
75//
76////////////////////////////////////////////////////////////////////////////////
77
78/*****************************************************************************
79 *
80 * $RCSfile: ext_sys_mem.h,v $
81 *
82 * $Revision: 1.1.1.1 $
83 * $Date: 2007/02/13 22:21:46 $
84 * $Author: drp $
85 * $State: Exp $
86 * $Locker: $
87 *
88 * Copyright (c) 1997 by Advanced Micro Devices, Inc.
89 *
90 * This file is protected by Federal Copyright Law, with all rights
91 * reserved. No part of this file may be reproduced, stored in a
92 * retrieval system, translated, transcribed, or transmitted, in any
93 * form, or by any means manual, electric, electronic, mechanical,
94 * electro-magnetic, chemical, optical, or otherwise, without prior
95 * explicit written permission from Advanced Micro Devices, Inc.
96 *
97 ****************************************************************************/
98#ifndef __EXT_SYS_MEM_DEFINED__
99#define __EXT_SYS_MEM_DEFINED__
100
101#include <assert.h>
102#include <stdlib.h>
103#include <string.h>
104#include <ctype.h>
105#include <stdio.h>
106#include "uint64.h"
107
108#define SYS_HTBL_SIZE 1024
109#define SYS_CHUNK_SIZE 512
110#define SYS_CHUNK_BITS 19 // = lg(SYS_CHUNK_SIZE)
111
112typedef unsigned int dword;
113typedef unsigned int uint;
114typedef unsigned char byte;
115
116typedef struct HTABLE HTABLE;
117typedef struct MEMCHUNK MEMCHUNK;
118
119struct PAGE_INFO {
120 uint Present;
121 uint Global;
122 uint PageSize;
123 uint Accessed;
124 uint Dirty;
125 uint Pcd;
126 uint Pwt;
127 uint User;
128 uint Writeable;
129 uint PhysTag; // PA[35:12]
130 uint PF;
131 uint GP;
132};
133
134// 512 byte chunk of data + chunk tag + next chunk pointers
135struct MEMCHUNK {
136 long long unsigned int tag; // address bits 63:19
137 MEMCHUNK * left; // pointer to next (lesser) tag
138 MEMCHUNK * right; // pointer to next (greater) tag
139 dword data[SYS_CHUNK_SIZE/4]; // 512 byte block of data
140};
141
142// hash table entry
143struct HTABLE_ENTRY {
144 byte valid; // hash table valid bit
145 MEMCHUNK * mraPtr; // pointer to most recently accessed MEMCHUNK
146 MEMCHUNK * headPtr; // pointer to first MEMCHUNK in chunk binary tree
147};
148
149class SYS_MEM {
150private:
151 HTABLE_ENTRY htable[SYS_HTBL_SIZE];
152 uint _ClrMemVal;
153 int iUseRandom;
154 int GetAddressFromString(char *InputBuffer, unsigned int *Addr);
155 int PreCheckError(FILE *memfile, char *filename);
156
157public:
158 void *ReturnHTable(){return (void*)&htable;}
159 SYS_MEM();
160 void dump(char *FileName);
161 void dumpMemTree(FILE *memfile, MEMCHUNK *K7Block, int Index);
162 void load(FILE *memfile, char *Filename=NULL,
163 long long unsigned int addrLimitLow=0, long long unsigned int addrLimitHigh=0);
164
165 unsigned char read(dword addrh, dword addr); // byte
166 uint read(dword addrh, dword addr, dword *data); // dWord
167 void read(dword addrh, dword addr, dword *data1, dword *data0); // qWord
168 long long unsigned int read(long long unsigned int addr, long long unsigned int *data); // qWord #2
169 unsigned char * read(dword addrh, dword addr, uint Size); // defined Size
170 uint readBit(dword addrh, dword addr, dword bitField);
171
172 void write(dword addrh, dword addr, byte data); // byte
173 void write(dword addrh, dword addr, byte be, dword data); // dWord
174 void write(dword addrh, dword addr, byte be, dword data1, dword data0); // qWord
175 void write(long long unsigned int addr, byte be, long long unsigned int data); // qWord #2
176 void SetDefaultMemVal(uint val);
177 void SetDefaultMemRandom();
178
179 // unsigned long long versions
180 unsigned char read(unsigned long long Ad) {return read((uint)(Ad>>32),(uint)Ad);} // byte
181
182 /*
183 // uint64 versions
184 unsigned char read(uint64 Ad) {return read(Ad[1],Ad[0]);} // byte
185 void read(uint64 Ad, dword *data) {read(Ad[1],Ad[0],data);} // dWord
186 void read(uint64 Ad, dword *data1, dword *data0) {read(Ad[1],Ad[0],data1,data0);} // qWord
187 unsigned char * read(uint64 Ad, uint Size) {return read(Ad[1],Ad[0],Size);} // defined Size
188 uint readBit(uint64 Ad, dword bitField) {return readBit(Ad[1],Ad[0],bitField);}
189 void write(uint64 Ad, byte be, dword data1, dword data0) {write(Ad[1],Ad[0],be,data1,data0);}
190 void write(uint64 Ad, byte be, dword data) {write(Ad[1],Ad[0],be, data);}
191
192 */
193 uint debug;
194};
195
196#endif