ParaNut SystemC Model
A SystemC Model of the ParaNut architecture
lsu.h
Go to the documentation of this file.
1 /*************************************************************************
2 
3  This file is part of the ParaNut project.
4 
5  Copyright (C) 2010-2022 Alexander Bahle <alexander.bahle@hs-augsburg.de>
6  Gundolf Kiefer <gundolf.kiefer@hs-augsburg.de>
7  Christian H. Meyer <christian.meyer@hs-augsburg.de>
8  Hochschule Augsburg, University of Applied Sciences
9 
10  Description:
11  This is a SystemC model of the load & store unit (LSU) of the ParaNut.
12  The LSU interfaces with the EXU and the MEMU (1 load & 1 store port).
13  It contains a write buffer with forwarding capabilities to the
14  respective read port.
15 
16  Redistribution and use in source and binary forms, with or without modification,
17  are permitted provided that the following conditions are met:
18 
19  1. Redistributions of source code must retain the above copyright notice, this
20  list of conditions and the following disclaimer.
21 
22  2. Redistributions in binary form must reproduce the above copyright notice,
23  this list of conditions and the following disclaimer in the documentation and/or
24  other materials provided with the distribution.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
30  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 
37  *************************************************************************/
38 
39 
40 #ifndef _LSU_
41 #define _LSU_
42 
43 #include "base.h"
44 #include "paranut-config.h"
45 
46 #include <systemc.h>
47 
48 struct SWbufEntry {
49  sc_uint<30> adr;
50  sc_uint<32> data;
51  sc_uint<4> valid;
52  sc_uint<3> special;
53 
54  // Necessary operators for using this structure as signals...
55  bool operator== (const SWbufEntry &t) const {
56  return adr == t.adr && valid == t.valid && special == t.special && data == t.data;
57  }
58 
60  adr = t.adr;
61  data = t.data;
62  valid = t.valid;
63  special = t.special;
64  return *this;
65  }
66 
67  // Displaying
68  friend ostream& operator << ( ostream& os, const SWbufEntry &t ) {
69  os << "adr:" << t.adr << " data:" << t.data << " valid:" << t.valid;
70  return os;
71  }
72 
73  //Overload function
74  friend void sc_trace( sc_trace_file* f, const SWbufEntry& t, const std::string& _s ) {
75  sc_trace( f, t.adr, _s + ".adr" );
76  sc_trace( f, t.data, _s + ".data" );
77  sc_trace( f, t.valid, _s + ".valid" );
78  sc_trace( f, t.special, _s + ".special" );
79  }
80 };
81 
82 // TODO:
83 // - support uncached access (no write buffer)
84 
85 // **************** MLsu *************
86 class MLsu : ::sc_core::sc_module {
87 public:
88  // Ports ...
89  sc_in<bool> clk, reset;
90 
91  // to EXU...
92  // Caution: Inputs to LSU->R/WP->... Mealy Machine (should be registers from EXU)
93  sc_in<bool> rd, wr, flush;
94  sc_in<sc_uint<3> > cache_op;
95  sc_in<bool> lres_scond;
96  sc_in<bool> exts;
97  sc_in<bool> dcache_enable;
98  sc_in<sc_uint<32> > adr;
99  sc_in<sc_uint<32> > wdata;
100  sc_in<sc_uint<2> > width; // "00" = word, "01" = byte, "10" = half word
101  sc_in<bool> trap_u;
102  sc_in<bool> trap_no_u;
103  sc_out<bool> ac_u;
104  sc_out<bool> ac_r;
105  sc_out<bool> ac_w;
106  sc_in<bool> paging;
107  // Caution: Outputs from LSU->R/WP->... Mealy Machine (should end in registers/states in EXU)
108  sc_out<bool> ack, align_err, scond_ok;
109  sc_out<sc_uint<32> > rdata; // Note: 'rdata' is delayed by one clock relative to 'ack' (see comment to the read port interface in 'memu.h')
110 
111  // to MEMU/read port...
112  sc_out<bool> rp_rd;
113  sc_out<bool> rp_paging;
114  sc_out<sc_uint<4> > rp_bsel;
115  sc_in<bool> rp_ack;
116  sc_out<sc_uint<32> > rp_adr;
117  sc_in<sc_uint<32> > rp_data;
118  sc_out<bool> rp_direct;
119  sc_in<bool> rp_ac_r, rp_ac_u;
120 
121  // to MEMU/write port...
122  sc_out<bool> wp_wr;
123  sc_out<bool> wp_paging;
124  sc_out<sc_uint<4> > wp_bsel;
125  sc_in<bool> wp_ack;
126  sc_out<bool> wp_lres_scond;
127  sc_in<bool> wp_scond_ok;
128  sc_out<sc_uint<3> > wp_cache_op;
129  sc_out<sc_uint<32> > wp_adr;
130  sc_out<sc_uint<32> > wp_data;
131  sc_out<bool> wp_direct;
132  sc_in<bool> wp_ac_w;
133  sc_out<bool> wp_trap_u, wp_trap_no_u;
134 
135 
136  // Constructor...
137  SC_HAS_PROCESS (MLsu);
138  MLsu (sc_module_name name)
139  : sc_module (name) {
140  SC_METHOD (TransitionMethod);
141  sensitive << clk.pos ();
142  SC_METHOD (OutputMethod);
143  sensitive << rd << wr << flush << cache_op << lres_scond << dcache_enable;
144  sensitive << width << exts << adr << wdata;
145  sensitive << rp_ack << rp_data << wp_ack << wp_scond_ok;
146  sensitive << rp_ac_r << wp_ac_w << rp_ac_u;
147  sensitive << trap_no_u << trap_u;
148  sensitive << wbuf_dirty0 << wbuf_hit_reg << wp_ack_reg;
149  sensitive << paging_reg;
150  for (int n = 0; n < CFG_LSU_WBUF_SIZE; n++)
151  sensitive << wbuf[n];
152  }
153 
154  // Functions...
155  void Trace (sc_trace_file * tf, int level = 1);
156 
157  // Processes...
158  void OutputMethod ();
159  void TransitionMethod ();
160 
161 protected:
162  // Registers...
163  sc_signal<SWbufEntry> wbuf[CFG_LSU_WBUF_SIZE];
164  sc_signal<bool> wp_ack_reg;
165  sc_signal<bool> paging_reg;
166 
167 // sc_signal<sc_uint<30> > wbuf_adr[CFG_LSU_WBUF_SIZE]; // only bits 31:2 are relevant!!
168 // sc_signal<sc_uint<32> > wbuf_data[CFG_LSU_WBUF_SIZE];
169 // sc_signal<sc_uint<4> > wbuf_valid[CFG_LSU_WBUF_SIZE];
170 // sc_signal<sc_uint<2> > wbuf_special[CFG_LSU_WBUF_SIZE];
171  sc_signal<bool> wbuf_dirty0; // is '1' if entry 0 needs to be written back
172  sc_signal<sc_uint<CFG_LSU_WBUF_SIZE_LD + 1> > wbuf_hit_reg;
173 
174  // Internal signals...
175  sc_signal<sc_uint<32> > sig_wbdata;
176  sc_signal<sc_uint<4> > sig_wbbsel;
177  sc_signal<sc_uint<CFG_LSU_WBUF_SIZE_LD + 1> > sig_wbuf_entry, sig_wbuf_entry_new, sig_wbuf_hit;
178  sc_signal<bool> sig_wbuf_remove;
179  sc_signal<bool> sig_wbuf_write;
180 
181  // Helper methods...
182  int FindWbufHit (sc_uint<30> adr);
183  int FindEmptyWbufEntry ();
184 
185 #ifndef __SYNTHESIS__
186  sc_signal<sc_uint<2> > adr_offset;
187 #endif
188 };
189 
190 
191 #endif
Helpers, Makros and performance measuring Classes used in most ParaNut files.
Definition: lsu.h:86
sc_out< bool > ac_u
Definition: lsu.h:103
sc_in< bool > dcache_enable
Definition: lsu.h:97
sc_in< bool > trap_no_u
Definition: lsu.h:102
void OutputMethod()
Definition: lsu.cpp:139
sc_in< bool > wr
Definition: lsu.h:93
sc_out< bool > ac_w
Definition: lsu.h:105
sc_signal< SWbufEntry > wbuf[CFG_LSU_WBUF_SIZE]
Definition: lsu.h:163
sc_in< bool > lres_scond
Definition: lsu.h:95
sc_in< bool > rd
Definition: lsu.h:93
sc_out< sc_uint< 32 > > rdata
Definition: lsu.h:109
sc_out< bool > ac_r
Definition: lsu.h:104
sc_signal< sc_uint< CFG_LSU_WBUF_SIZE_LD+1 > > sig_wbuf_entry
Definition: lsu.h:177
sc_in< sc_uint< 2 > > width
Definition: lsu.h:100
sc_out< bool > rp_direct
Definition: lsu.h:118
sc_in< bool > wp_ac_w
Definition: lsu.h:132
sc_signal< bool > sig_wbuf_write
Definition: lsu.h:179
MLsu(sc_module_name name)
Definition: lsu.h:138
sc_in< bool > rp_ack
Definition: lsu.h:115
sc_in< sc_uint< 3 > > cache_op
Definition: lsu.h:94
sc_signal< sc_uint< 4 > > sig_wbbsel
Definition: lsu.h:176
sc_in< bool > clk
Definition: lsu.h:89
sc_out< sc_uint< 4 > > wp_bsel
Definition: lsu.h:124
sc_out< bool > ack
Definition: lsu.h:108
sc_out< bool > rp_rd
Definition: lsu.h:112
sc_out< bool > wp_direct
Definition: lsu.h:131
void TransitionMethod()
Definition: lsu.cpp:358
sc_signal< bool > wp_ack_reg
Definition: lsu.h:164
sc_out< sc_uint< 32 > > wp_data
Definition: lsu.h:130
sc_out< sc_uint< 32 > > rp_adr
Definition: lsu.h:116
sc_in< bool > wp_ack
Definition: lsu.h:125
sc_in< bool > trap_u
Definition: lsu.h:101
sc_in< bool > rp_ac_u
Definition: lsu.h:119
sc_in< bool > paging
Definition: lsu.h:106
sc_out< sc_uint< 4 > > rp_bsel
Definition: lsu.h:114
sc_signal< bool > paging_reg
Definition: lsu.h:165
sc_out< bool > wp_paging
Definition: lsu.h:123
sc_in< sc_uint< 32 > > wdata
Definition: lsu.h:99
sc_in< sc_uint< 32 > > adr
Definition: lsu.h:98
sc_out< bool > wp_trap_u
Definition: lsu.h:133
int FindEmptyWbufEntry()
Definition: lsu.cpp:122
sc_out< bool > rp_paging
Definition: lsu.h:113
sc_out< sc_uint< 32 > > wp_adr
Definition: lsu.h:129
sc_out< bool > wp_lres_scond
Definition: lsu.h:126
sc_signal< sc_uint< CFG_LSU_WBUF_SIZE_LD+1 > > sig_wbuf_hit
Definition: lsu.h:177
sc_out< bool > wp_trap_no_u
Definition: lsu.h:133
sc_signal< sc_uint< 2 > > adr_offset
Definition: lsu.h:186
sc_in< bool > wp_scond_ok
Definition: lsu.h:127
void Trace(sc_trace_file *tf, int level=1)
Definition: lsu.cpp:39
sc_in< sc_uint< 32 > > rp_data
Definition: lsu.h:117
sc_out< bool > align_err
Definition: lsu.h:108
sc_out< sc_uint< 3 > > wp_cache_op
Definition: lsu.h:128
sc_in< bool > reset
Definition: lsu.h:89
sc_signal< sc_uint< 32 > > sig_wbdata
Definition: lsu.h:175
sc_signal< bool > sig_wbuf_remove
Definition: lsu.h:178
sc_out< bool > wp_wr
Definition: lsu.h:122
sc_in< bool > flush
Definition: lsu.h:93
sc_signal< sc_uint< CFG_LSU_WBUF_SIZE_LD+1 > > wbuf_hit_reg
Definition: lsu.h:172
sc_in< bool > exts
Definition: lsu.h:96
sc_signal< sc_uint< CFG_LSU_WBUF_SIZE_LD+1 > > sig_wbuf_entry_new
Definition: lsu.h:177
sc_signal< bool > wbuf_dirty0
Definition: lsu.h:171
sc_in< bool > rp_ac_r
Definition: lsu.h:119
sc_out< bool > scond_ok
Definition: lsu.h:108
int FindWbufHit(sc_uint< 30 > adr)
Definition: lsu.cpp:107
#define CFG_LSU_WBUF_SIZE
LSU write buffer size (derived).
Definition: paranut-config.h:291
Configuration Makros used in most ParaNut files.
Definition: lsu.h:48
friend ostream & operator<<(ostream &os, const SWbufEntry &t)
Definition: lsu.h:68
SWbufEntry operator=(const SWbufEntry &t)
Definition: lsu.h:59
sc_uint< 32 > data
Definition: lsu.h:50
sc_uint< 4 > valid
Definition: lsu.h:51
sc_uint< 3 > special
Definition: lsu.h:52
sc_uint< 30 > adr
Definition: lsu.h:49
bool operator==(const SWbufEntry &t) const
Definition: lsu.h:55
friend void sc_trace(sc_trace_file *f, const SWbufEntry &t, const std::string &_s)
Definition: lsu.h:74
sc_trace_file * tf
Definition: tlb_tb.cpp:94