Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / lib / cpu / src / SS_MsyncMemory.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: SS_MsyncMemory.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_MsyncMemory_h__
24#define __SS_MsyncMemory_h__
25
26#ifdef MEMORY_MSYNC
27#include <string.h>
28#include <sys/mman.h>
29#include "MemoryTransaction.h"
30#include "SS_FastMemory.h"
31
32class SS_Strand;
33
34class SS_MsyncMemory:public SS_FastMemory/*{{{*/
35{
36 public:
37 SS_MsyncMemory();
38 ~SS_MsyncMemory();
39
40 // Supported Fetch Operation (instruction fetch)
41
42 virtual uint32_t fetch32 ( uint64_t addr );
43 virtual void fetch256( uint64_t addr, uint64_t data[4] );
44 virtual void fetch512( uint64_t addr, uint64_t data[8] );
45
46 // Supported Store Operations. st8(), st16(), st32() and st64() are gueranteed to be atomic.
47 // st128() and st512() are atomic per 64bit quantity.
48
49 virtual void st8 ( uint64_t addr, uint8_t data );
50 virtual void st16 ( uint64_t addr, uint16_t data );
51 virtual void st32 ( uint64_t addr, uint32_t data );
52 virtual void st64 ( uint64_t addr, uint64_t data );
53 virtual void st128( uint64_t addr, uint64_t data[2] );
54 virtual void st512( uint64_t addr, uint64_t data[8] );
55
56 // Supported Load Operations. ld8[su]() to ld64() are quaranteed to be atomic. ld128() and
57 // above are atomic at the 64 bit granularity.
58
59 virtual uint8_t ld8u ( uint64_t addr );
60 virtual int8_t ld8s ( uint64_t addr );
61 virtual uint16_t ld16u( uint64_t addr );
62 virtual int16_t ld16s( uint64_t addr );
63 virtual uint32_t ld32u( uint64_t addr );
64 virtual int32_t ld32s( uint64_t addr );
65 virtual uint64_t ld64 ( uint64_t addr );
66 virtual void ld128( uint64_t addr, uint64_t data[2] );
67 virtual void ld256( uint64_t addr, uint64_t data[4] );
68 virtual void ld512( uint64_t addr, uint64_t data[8] );
69
70 // st64partial() performs 8 byte partial store. The bytes to store are specified by mask. A 1 in bit N of
71 // mask denotes that byte (data >> (8*N)) & 0xff should be written to memory
72
73 virtual void st64partial( uint64_t addr, uint64_t data, uint64_t mask );
74
75 // ld128atomic() (aka load twin double, load quad atomic) atomically loads two
76 // 64bit values from memory at addr into rd. rd[0] is the value at addr, rd[1]
77 // is the value at addr + 8. Note ld128 does() not guarantee atomicity.
78
79 virtual void ld128atomic( uint64_t addr, uint64_t data[2] );
80
81 // ldstub() return a byte from memory at addr, and set the byte at addr
82 // to 0xff. The ldstub() operation is atomic.
83
84 virtual uint8_t ldstub( uint64_t addr );
85
86 // swap() stores the 32bit value rd with the 32bit value at addr.
87 // The old 32bit value at addr is returned. The operation is atomic.
88
89 virtual uint32_t swap( uint64_t addr, uint32_t rd );
90
91 // casx() compares the 64bit value rs2 with the 64bit value at addr.
92 // If the two values are equal, the value rd is stored in the
93 // 64bit value at addr. In both cases the old 64bit value at addr is
94 // returned, that is the value at addr before the storei happened.
95 // The casx() operation is atomic.
96
97 virtual uint64_t casx( uint64_t addr, uint64_t rd, uint64_t rs2 );
98
99 // cas() is as casx, but for 32bit.
100
101 virtual uint32_t cas( uint64_t addr, uint32_t rd, uint32_t rs2 );
102
103 // prefetch() prefetches data from memory into the cache hierarchy.
104
105 void prefetch( uint64_t addr, uint_t size ) {}
106
107 // flush() writes dirty data in the cache back to memory.
108
109 void flush( uint64_t addr, uint_t size ) {} // process does not provide data.
110
111 static SS_MsyncMemory memory;
112
113 //----------------------------------------------------------------------------
114 // Memory Sync additional interface
115 //----------------------------------------------------------------------------
116
117 enum Info
118 {
119 NONE = 0,
120 LDD = 1, // Treat as 2xld32
121 STD = 2, // Treat as 2xst32
122 HTW = 3 // Ignore ld128atomic
123 };
124
125
126 void msync_info( uint_t strand_id, SS_Vaddr va, Info info=NONE )
127 {
128 mem_xact.setStrand(strand_id);
129 mem_xact.vaddr(va);
130 msync_help = info;
131 }
132
133 void* msync_object;
134 void (*msync_pre_access)( void* obj, MemoryTransaction& );
135 void (*msync_post_access)( void* obj, MemoryTransaction& );
136
137 private:
138 MemoryTransaction mem_xact;
139
140 uint64_t msync_ld( uint64_t addr, uint_t size );
141 void msync_ld( uint64_t addr, uint_t size, uint64_t* data );
142 void msync_st( uint64_t addr, uint_t size, uint64_t data );
143 void msync_st( uint64_t addr, uint_t size, uint64_t* data );
144
145 Info msync_help;
146};
147/*}}}*/
148
149#endif /* MEMORY_MSYNC */
150#endif /* __SS_MsyncMemory_h__ */