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.
35 #include <gem5/m5ops.h>
42 uint64_t address
= lua_tointeger(L
, 1);
48 do_quiesce(lua_State
*L
)
55 do_quiesce_ns(lua_State
*L
)
57 uint64_t ns
= lua_tointeger(L
, 1);
63 do_quiesce_cycle(lua_State
*L
)
65 uint64_t cycles
= lua_tointeger(L
, 1);
66 m5_quiesce_cycle(cycles
);
71 do_quiesce_time(lua_State
*L
)
73 uint64_t ns
= m5_quiesce_time();
74 lua_pushinteger(L
, ns
);
81 uint64_t ns
= m5_rpns();
82 lua_pushinteger(L
, ns
);
87 do_wake_cpu(lua_State
*L
)
89 uint64_t cpuid
= lua_tointeger(L
, 1);
97 uint64_t ns_delay
= lua_tointeger(L
, 1);
103 do_fail(lua_State
*L
)
105 uint64_t ns_delay
= lua_tointeger(L
, 1);
106 uint64_t code
= lua_tointeger(L
, 2);
107 m5_fail(ns_delay
, code
);
112 do_init_param(lua_State
*L
)
114 uint64_t key_str1
= lua_tointeger(L
, 1);
115 uint64_t key_str2
= lua_tointeger(L
, 2);
116 lua_pushinteger(L
, m5_init_param(key_str1
, key_str2
));
121 do_checkpoint(lua_State
*L
)
123 uint64_t delay
= lua_tointeger(L
, 1);
124 uint64_t period
= lua_tointeger(L
, 2);
125 m5_checkpoint(delay
, period
);
130 do_reset_stats(lua_State
*L
)
132 uint64_t ns_delay
= lua_tointeger(L
, 1);
133 uint64_t ns_period
= lua_tointeger(L
, 2);
134 m5_reset_stats(ns_delay
, ns_period
);
139 do_dump_stats(lua_State
*L
)
141 uint64_t delay
= lua_tointeger(L
, 1);
142 uint64_t period
= lua_tointeger(L
, 2);
143 m5_dump_stats(delay
, period
);
148 do_dump_reset_stats(lua_State
*L
)
150 uint64_t delay
= lua_tointeger(L
, 1);
151 uint64_t period
= lua_tointeger(L
, 2);
152 m5_dump_reset_stats(delay
, period
);
157 do_read_file(lua_State
*L
)
159 uint64_t len
= lua_tointeger(L
, 1);
160 uint64_t offset
= lua_tointeger(L
, 2);
161 char *buf
= malloc(len
);
162 uint64_t readlen
= m5_read_file(buf
, len
, offset
);
163 lua_pushlstring(L
, buf
, readlen
);
168 do_write_file(lua_State
*L
)
170 const char* buf
= lua_tostring(L
, 1);
171 uint64_t len
= lua_tointeger(L
, 2);
172 assert(len
<= lua_strlen(L
, 1));
173 uint64_t offset
= lua_tointeger(L
, 3);
174 const char *filename
= lua_tostring(L
, 4);
175 uint64_t w_len
= m5_write_file((void *)buf
, len
, offset
, filename
);
176 lua_pushinteger(L
, w_len
);
181 do_debug_break(lua_State
*L
)
188 do_switch_cpu(lua_State
*L
)
195 do_dist_toggle_sync(lua_State
*L
)
197 m5_dist_toggle_sync();
202 do_add_symbol(lua_State
*L
)
204 uint64_t addr
= lua_tointeger(L
, 1);
205 char *string
= (char*) lua_tostring(L
, 2);
206 m5_add_symbol(addr
, string
);
211 do_loadsymbol(lua_State
*L
)
218 do_panic(lua_State
*L
)
225 do_work_begin(lua_State
*L
)
227 uint64_t workid
= lua_tointeger(L
, 1);
228 uint64_t threadid
= lua_tointeger(L
, 2);
229 m5_work_begin(workid
, threadid
);
234 do_work_end(lua_State
*L
)
236 uint64_t workid
= lua_tointeger(L
, 1);
237 uint64_t threadid
= lua_tointeger(L
, 2);
238 m5_work_end(workid
, threadid
);
243 luaopen_gem5OpLua(lua_State
*L
)
246 #define ADD_FUNC(fname) do{ \
247 lua_pushcfunction(L, fname); \
248 lua_setfield(L, -2, #fname); \
253 ADD_FUNC(do_quiesce
);
254 ADD_FUNC(do_quiesce_ns
);
255 ADD_FUNC(do_quiesce_cycle
);
256 ADD_FUNC(do_quiesce_time
);
258 ADD_FUNC(do_wake_cpu
);
261 ADD_FUNC(do_init_param
);
262 ADD_FUNC(do_checkpoint
);
263 ADD_FUNC(do_reset_stats
);
264 ADD_FUNC(do_dump_stats
);
265 ADD_FUNC(do_dump_reset_stats
);
266 ADD_FUNC(do_read_file
);
267 ADD_FUNC(do_write_file
);
268 ADD_FUNC(do_debug_break
);
269 ADD_FUNC(do_switch_cpu
);
270 ADD_FUNC(do_dist_toggle_sync
);
271 ADD_FUNC(do_add_symbol
);
272 ADD_FUNC(do_loadsymbol
);
274 ADD_FUNC(do_work_begin
);
275 ADD_FUNC(do_work_end
);