1 /* Copyright (c) 2017 Hanhwi Jang
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <gem5/m5ops.h>
43 uint64_t address
= lua_tointeger(L
, 1);
49 do_quiesce(lua_State
*L
)
56 do_quiesce_ns(lua_State
*L
)
58 uint64_t ns
= lua_tointeger(L
, 1);
64 do_quiesce_cycle(lua_State
*L
)
66 uint64_t cycles
= lua_tointeger(L
, 1);
67 m5_quiesce_cycle(cycles
);
72 do_quiesce_time(lua_State
*L
)
74 uint64_t ns
= m5_quiesce_time();
75 lua_pushinteger(L
, ns
);
82 uint64_t ns
= m5_rpns();
83 lua_pushinteger(L
, ns
);
88 do_wake_cpu(lua_State
*L
)
90 uint64_t cpuid
= lua_tointeger(L
, 1);
98 uint64_t ns_delay
= lua_tointeger(L
, 1);
104 do_fail(lua_State
*L
)
106 uint64_t ns_delay
= lua_tointeger(L
, 1);
107 uint64_t code
= lua_tointeger(L
, 2);
108 m5_fail(ns_delay
, code
);
113 do_init_param(lua_State
*L
)
115 uint64_t key_str1
= lua_tointeger(L
, 1);
116 uint64_t key_str2
= lua_tointeger(L
, 2);
117 lua_pushinteger(L
, m5_init_param(key_str1
, key_str2
));
122 do_checkpoint(lua_State
*L
)
124 uint64_t delay
= lua_tointeger(L
, 1);
125 uint64_t period
= lua_tointeger(L
, 2);
126 m5_checkpoint(delay
, period
);
131 do_reset_stats(lua_State
*L
)
133 uint64_t ns_delay
= lua_tointeger(L
, 1);
134 uint64_t ns_period
= lua_tointeger(L
, 2);
135 m5_reset_stats(ns_delay
, ns_period
);
140 do_dump_stats(lua_State
*L
)
142 uint64_t delay
= lua_tointeger(L
, 1);
143 uint64_t period
= lua_tointeger(L
, 2);
144 m5_dump_stats(delay
, period
);
149 do_dump_reset_stats(lua_State
*L
)
151 uint64_t delay
= lua_tointeger(L
, 1);
152 uint64_t period
= lua_tointeger(L
, 2);
153 m5_dump_reset_stats(delay
, period
);
158 do_read_file(lua_State
*L
)
160 uint64_t len
= lua_tointeger(L
, 1);
161 uint64_t offset
= lua_tointeger(L
, 2);
162 char *buf
= (char *)malloc(len
);
163 uint64_t readlen
= m5_read_file(buf
, len
, offset
);
164 lua_pushlstring(L
, buf
, readlen
);
169 do_write_file(lua_State
*L
)
171 const char* buf
= lua_tostring(L
, 1);
172 uint64_t len
= lua_tointeger(L
, 2);
173 assert(len
<= lua_strlen(L
, 1));
174 uint64_t offset
= lua_tointeger(L
, 3);
175 const char *filename
= lua_tostring(L
, 4);
176 uint64_t w_len
= m5_write_file((void *)buf
, len
, offset
, filename
);
177 lua_pushinteger(L
, w_len
);
182 do_debug_break(lua_State
*L
)
189 do_switch_cpu(lua_State
*L
)
196 do_dist_toggle_sync(lua_State
*L
)
198 m5_dist_toggle_sync();
203 do_add_symbol(lua_State
*L
)
205 uint64_t addr
= lua_tointeger(L
, 1);
206 char *string
= (char*) lua_tostring(L
, 2);
207 m5_add_symbol(addr
, string
);
212 do_loadsymbol(lua_State
*L
)
219 do_panic(lua_State
*L
)
226 do_work_begin(lua_State
*L
)
228 uint64_t workid
= lua_tointeger(L
, 1);
229 uint64_t threadid
= lua_tointeger(L
, 2);
230 m5_work_begin(workid
, threadid
);
235 do_work_end(lua_State
*L
)
237 uint64_t workid
= lua_tointeger(L
, 1);
238 uint64_t threadid
= lua_tointeger(L
, 2);
239 m5_work_end(workid
, threadid
);
246 int luaopen_gem5OpLua(lua_State
*);
251 luaopen_gem5OpLua(lua_State
*L
)
254 #define ADD_FUNC(fname) do{ \
255 lua_pushcfunction(L, fname); \
256 lua_setfield(L, -2, #fname); \
261 ADD_FUNC(do_quiesce
);
262 ADD_FUNC(do_quiesce_ns
);
263 ADD_FUNC(do_quiesce_cycle
);
264 ADD_FUNC(do_quiesce_time
);
266 ADD_FUNC(do_wake_cpu
);
269 ADD_FUNC(do_init_param
);
270 ADD_FUNC(do_checkpoint
);
271 ADD_FUNC(do_reset_stats
);
272 ADD_FUNC(do_dump_stats
);
273 ADD_FUNC(do_dump_reset_stats
);
274 ADD_FUNC(do_read_file
);
275 ADD_FUNC(do_write_file
);
276 ADD_FUNC(do_debug_break
);
277 ADD_FUNC(do_switch_cpu
);
278 ADD_FUNC(do_dist_toggle_sync
);
279 ADD_FUNC(do_add_symbol
);
280 ADD_FUNC(do_loadsymbol
);
282 ADD_FUNC(do_work_begin
);
283 ADD_FUNC(do_work_end
);