summaryrefslogtreecommitdiffstats
path: root/utils/hwstub
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub')
-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)
return 0;
}
+int my_lua_call(lua_State *state)
+{
+ int n = lua_gettop(state);
+ if(n != 1)
+ luaL_error(state, "call takes target address argument");
+
+ hwstub_call(g_hwdev, luaL_checkunsigned(state, 1));
+ return 0;
+}
+
+int my_lua_jump(lua_State *state)
+{
+ int n = lua_gettop(state);
+ if(n != 1)
+ luaL_error(state, "jump takes target address argument");
+
+ hwstub_jump(g_hwdev, luaL_checkunsigned(state, 1));
+ return 0;
+}
+
int my_lua_printlog(lua_State *state)
{
print_log(g_hwdev);
@@ -329,6 +349,10 @@ bool my_lua_import_hwstub()
lua_setfield(g_lua, -2, "write32");
lua_pushcclosure(g_lua, my_lua_printlog, 0);
lua_setfield(g_lua, -2, "print_log");
+ lua_pushcclosure(g_lua, my_lua_call, 0);
+ lua_setfield(g_lua, -2, "call");
+ lua_pushcclosure(g_lua, my_lua_jump, 0);
+ lua_setfield(g_lua, -2, "jump");
lua_setfield(g_lua, -2, "dev");
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
h:add("It contains some information about the device and the following methods.");
h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically");
h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically");
+ h:add("* jump(a) jump to specified address");
+ h:add("* call(a) call function at specified address and return to hwstub");
h:add("* print_log() prints the device log");
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 @@
+HWLIB = {}
+
+local h = HELP:create_topic("HWLIB")
+h:add("This table contains helper functions for use inside hwstub_shell")
+
+local hh = h:create_topic("load_blob")
+hh:add("load_blob(filename, address) -- this function loads raw binary blob from the file filename")
+hh:add(" at specified address in memory. No cache coherency is")
+hh:add(" guaranteed")
+
+hh = h:create_topic("printf")
+hh:add("printf(s,...) -- this function is simple wrapper around string.format to emulate")
+hh:add(" C printf() function")
+
+function HWLIB.load_blob(filename, address)
+ local f = assert(io.open(filename, "rb"))
+ local bytes = f:read("*all")
+ for b in string.gmatch(bytes, ".") do
+ DEV.write8(address, string.byte(b))
+ address = address + 1
+ end
+ io.close(f)
+end
+
+function HWLIB.printf(s,...)
+ return io.write(s:format(...))
+end
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
require "atj"
end
+require "hwlib"
require "dumper"