summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2014-11-26 00:00:11 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-11-28 19:38:02 +0100
commite99c036ed1b96abf0c4b196e5f58ef93b7effdfe (patch)
tree0d5f487d19ece13a815e7fae12a91abfaaa11221
parent9439635aa27e7604d01dddb30a505a3402f3b4df (diff)
downloadrockbox-e99c036ed1b96abf0c4b196e5f58ef93b7effdfe.tar.gz
rockbox-e99c036ed1b96abf0c4b196e5f58ef93b7effdfe.zip
hwstub_shell: add support for call and jump
Change-Id: Ie09d0db21831b79255da858bada7382a08ff4eef Reviewed-on: http://gerrit.rockbox.org/1052 Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com> Tested: Marcin Bukat <marcin.bukat@gmail.com>
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp24
-rw-r--r--utils/hwstub/tools/init.lua2
-rw-r--r--utils/hwstub/tools/lua/hwlib.lua27
-rw-r--r--utils/hwstub/tools/lua/load.lua1
4 files changed, 54 insertions, 0 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp
index 30d1ac3b3f..8b7a8b9e80 100644
--- a/utils/hwstub/tools/hwstub_shell.cpp
+++ b/utils/hwstub/tools/hwstub_shell.cpp
@@ -206,6 +206,26 @@ int my_lua_writen(lua_State *state)
206 return 0; 206 return 0;
207} 207}
208 208
209int my_lua_call(lua_State *state)
210{
211 int n = lua_gettop(state);
212 if(n != 1)
213 luaL_error(state, "call takes target address argument");
214
215 hwstub_call(g_hwdev, luaL_checkunsigned(state, 1));
216 return 0;
217}
218
219int my_lua_jump(lua_State *state)
220{
221 int n = lua_gettop(state);
222 if(n != 1)
223 luaL_error(state, "jump takes target address argument");
224
225 hwstub_jump(g_hwdev, luaL_checkunsigned(state, 1));
226 return 0;
227}
228
209int my_lua_printlog(lua_State *state) 229int my_lua_printlog(lua_State *state)
210{ 230{
211 print_log(g_hwdev); 231 print_log(g_hwdev);
@@ -329,6 +349,10 @@ bool my_lua_import_hwstub()
329 lua_setfield(g_lua, -2, "write32"); 349 lua_setfield(g_lua, -2, "write32");
330 lua_pushcclosure(g_lua, my_lua_printlog, 0); 350 lua_pushcclosure(g_lua, my_lua_printlog, 0);
331 lua_setfield(g_lua, -2, "print_log"); 351 lua_setfield(g_lua, -2, "print_log");
352 lua_pushcclosure(g_lua, my_lua_call, 0);
353 lua_setfield(g_lua, -2, "call");
354 lua_pushcclosure(g_lua, my_lua_jump, 0);
355 lua_setfield(g_lua, -2, "jump");
332 356
333 lua_setfield(g_lua, -2, "dev"); 357 lua_setfield(g_lua, -2, "dev");
334 358
diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua
index aaca8b6c82..323f36957d 100644
--- a/utils/hwstub/tools/init.lua
+++ b/utils/hwstub/tools/init.lua
@@ -40,6 +40,8 @@ do
40 h:add("It contains some information about the device and the following methods."); 40 h:add("It contains some information about the device and the following methods.");
41 h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically"); 41 h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically");
42 h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically"); 42 h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically");
43 h:add("* jump(a) jump to specified address");
44 h:add("* call(a) call function at specified address and return to hwstub");
43 h:add("* print_log() prints the device log"); 45 h:add("* print_log() prints the device log");
44 46
45 h = HELP:create_topic("HW"); 47 h = HELP:create_topic("HW");
diff --git a/utils/hwstub/tools/lua/hwlib.lua b/utils/hwstub/tools/lua/hwlib.lua
new file mode 100644
index 0000000000..5bbd1e2668
--- /dev/null
+++ b/utils/hwstub/tools/lua/hwlib.lua
@@ -0,0 +1,27 @@
1HWLIB = {}
2
3local h = HELP:create_topic("HWLIB")
4h:add("This table contains helper functions for use inside hwstub_shell")
5
6local hh = h:create_topic("load_blob")
7hh:add("load_blob(filename, address) -- this function loads raw binary blob from the file filename")
8hh:add(" at specified address in memory. No cache coherency is")
9hh:add(" guaranteed")
10
11hh = h:create_topic("printf")
12hh:add("printf(s,...) -- this function is simple wrapper around string.format to emulate")
13hh:add(" C printf() function")
14
15function HWLIB.load_blob(filename, address)
16 local f = assert(io.open(filename, "rb"))
17 local bytes = f:read("*all")
18 for b in string.gmatch(bytes, ".") do
19 DEV.write8(address, string.byte(b))
20 address = address + 1
21 end
22 io.close(f)
23end
24
25function HWLIB.printf(s,...)
26 return io.write(s:format(...))
27end
diff --git a/utils/hwstub/tools/lua/load.lua b/utils/hwstub/tools/lua/load.lua
index 86f01f7f0c..f636360c4c 100644
--- a/utils/hwstub/tools/lua/load.lua
+++ b/utils/hwstub/tools/lua/load.lua
@@ -10,4 +10,5 @@ elseif hwstub.dev.target.id == hwstub.dev.target.ATJ then
10 require "atj" 10 require "atj"
11end 11end
12 12
13require "hwlib"
13require "dumper" 14require "dumper"