diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-11-26 00:00:11 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-11-28 19:38:02 +0100 |
commit | e99c036ed1b96abf0c4b196e5f58ef93b7effdfe (patch) | |
tree | 0d5f487d19ece13a815e7fae12a91abfaaa11221 /utils | |
parent | 9439635aa27e7604d01dddb30a505a3402f3b4df (diff) | |
download | rockbox-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>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 24 | ||||
-rw-r--r-- | utils/hwstub/tools/init.lua | 2 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/hwlib.lua | 27 | ||||
-rw-r--r-- | utils/hwstub/tools/lua/load.lua | 1 |
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 | ||
209 | int 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 | |||
219 | int 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 | |||
209 | int my_lua_printlog(lua_State *state) | 229 | int 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 @@ | |||
1 | HWLIB = {} | ||
2 | |||
3 | local h = HELP:create_topic("HWLIB") | ||
4 | h:add("This table contains helper functions for use inside hwstub_shell") | ||
5 | |||
6 | local hh = h:create_topic("load_blob") | ||
7 | hh:add("load_blob(filename, address) -- this function loads raw binary blob from the file filename") | ||
8 | hh:add(" at specified address in memory. No cache coherency is") | ||
9 | hh:add(" guaranteed") | ||
10 | |||
11 | hh = h:create_topic("printf") | ||
12 | hh:add("printf(s,...) -- this function is simple wrapper around string.format to emulate") | ||
13 | hh:add(" C printf() function") | ||
14 | |||
15 | function 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) | ||
23 | end | ||
24 | |||
25 | function HWLIB.printf(s,...) | ||
26 | return io.write(s:format(...)) | ||
27 | 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 | |||
10 | require "atj" | 10 | require "atj" |
11 | end | 11 | end |
12 | 12 | ||
13 | require "hwlib" | ||
13 | require "dumper" | 14 | require "dumper" |