ruby: style pass
[gem5.git] / src / mem / ruby / libruby.hh
1 /*
2 * Copyright (c) 2009 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __MEM_RUBY_LIBRUBY_HH__
30 #define __MEM_RUBY_LIBRUBY_HH__
31
32 #include <ostream>
33
34 #include "base/types.hh"
35 #include "mem/packet.hh"
36
37 typedef void* RubyPortHandle;
38 enum RubyRequestType {
39 RubyRequestType_NULL,
40 RubyRequestType_IFETCH,
41 RubyRequestType_LD,
42 RubyRequestType_ST,
43 RubyRequestType_Locked_Read,
44 RubyRequestType_Locked_Write,
45 RubyRequestType_RMW_Read,
46 RubyRequestType_RMW_Write,
47 RubyRequestType_NUM
48 };
49
50 enum RubyAccessMode {
51 RubyAccessMode_User,
52 RubyAccessMode_Supervisor,
53 RubyAccessMode_Device
54 };
55
56 struct RubyRequest
57 {
58 uint64_t paddr;
59 uint8_t* data;
60 int len;
61 uint64_t pc;
62 RubyRequestType type;
63 RubyAccessMode access_mode;
64 PacketPtr pkt;
65 unsigned proc_id;
66
67 RubyRequest() {}
68 RubyRequest(uint64_t _paddr,
69 uint8_t* _data,
70 int _len,
71 uint64_t _pc,
72 RubyRequestType _type,
73 RubyAccessMode _access_mode,
74 PacketPtr _pkt,
75 unsigned _proc_id = 100)
76 : paddr(_paddr),
77 data(_data),
78 len(_len),
79 pc(_pc),
80 type(_type),
81 access_mode(_access_mode),
82 pkt(_pkt),
83 proc_id(_proc_id)
84 {}
85 };
86
87 std::ostream& operator<<(std::ostream& out, const RubyRequest& obj);
88
89 /**
90 * Initialize the system. cfg_file is a Ruby-lang configuration script
91 */
92 void libruby_init(const char* cfg_file);
93
94 /**
95 * Tear down a configured system. Must be invoked after a call to
96 * libruby_init.
97 */
98 void libruby_destroy();
99
100 /**
101 * Print the last error encountered by ruby. Currently unimplemented.
102 */
103 const char* libruby_last_error();
104
105 /**
106 * Retrieve a handle to a RubyPort object, identified by name in the
107 * configuration. You also pass in the callback function you want
108 * this port to use when a request completes. Only one handle to a
109 * port is allowed at a time.
110 */
111 RubyPortHandle libruby_get_port(const char* name,
112 void (*hit_callback)(int64_t access_id));
113
114 /**
115 * Retrieve a handle to a RubyPort object, identified by name in the
116 * configuration.
117 */
118 RubyPortHandle libruby_get_port_by_name(const char* name);
119
120 /**
121 * issue_request returns a unique access_id to identify the ruby
122 * transaction. This access_id is later returned to the caller via
123 * hit_callback (passed to libruby_get_port)
124 */
125 int64_t libruby_issue_request(RubyPortHandle p, struct RubyRequest request);
126
127 /**
128 * writes data directly into Ruby's data array. Note that this
129 * ignores caches, and should be considered incoherent after
130 * simulation starts.
131 */
132 void libruby_write_ram(uint64_t paddr, uint8_t *data, int len);
133
134 /**
135 * reads data directory from Ruby's data array. Note that this
136 * ignores caches, and should be considered incoherent after
137 * simulation starts
138 */
139 void libruby_read_ram(uint64_t paddr, uint8_t *data, int len);
140
141 /**
142 * tick the system n cycles. Eventually, will return the number of
143 * cycles until the next event, but for now it always returns 0
144 */
145 int libruby_tick(int n);
146
147 /**
148 * self explainitory
149 */
150 void libruby_print_config(std::ostream &out);
151
152 /**
153 * self explainitory
154 */
155 void libruby_print_stats(std::ostream &out);
156
157 /**
158 * does not return until done
159 */
160 void libruby_playback_trace(char *trace_filename);
161
162 /*
163 * enables the tracer and opens the trace file
164 */
165 void libruby_start_tracing(char *record_filename);
166
167 /*
168 * closes the trace file
169 */
170 void libruby_stop_tracing();
171
172 /**
173 * get time
174 */
175 uint64_t libruby_get_time();
176
177 #endif // __MEM_RUBY_LIBRUBY_HH__