diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2017-11-12 14:13:21 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2017-11-12 14:13:21 +0100 |
commit | dd6b8427f9b4e3d1a13ed81005f9020394001d0c (patch) | |
tree | 3c34dde4adf06ac204ac5014e784574f4fb39ca8 /utils/hwstub/tools/hwstub_shell.cpp | |
parent | df0edba18eb53cd109b61da22285503419d5f227 (diff) | |
download | rockbox-dd6b8427f9b4e3d1a13ed81005f9020394001d0c.tar.gz rockbox-dd6b8427f9b4e3d1a13ed81005f9020394001d0c.zip |
hwstub: expose read/write functions
Previously only atomic read/write 8/16/32 were exposed. But it is useful to
be able to read a whole buffer at once, this is more efficient than N times
read8.
Change-Id: I06e331641e1ab1f74c0e16e8c432eafb398e8e6d
Diffstat (limited to 'utils/hwstub/tools/hwstub_shell.cpp')
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index a852e0f515..568bb37f9f 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp | |||
@@ -253,6 +253,21 @@ soc_word_t hw_read32(lua_State *state, soc_addr_t addr) | |||
253 | return u; | 253 | return u; |
254 | } | 254 | } |
255 | 255 | ||
256 | uint8_t *hw_read(lua_State *state, soc_addr_t addr, soc_word_t size) | ||
257 | { | ||
258 | uint8_t *buf = new uint8_t[size]; | ||
259 | size_t sz = size; | ||
260 | error ret = g_hwdev->read(addr, buf, sz, false); | ||
261 | if(ret != error::SUCCESS || sz != size) | ||
262 | { | ||
263 | delete[] buf; | ||
264 | luaL_error(state, "fail to read<%d> @ %p: %d", size, addr, ret); | ||
265 | } | ||
266 | if(g_print_mem_rw) | ||
267 | printf("[read<%lu> @ %#lx = ...]\n", (unsigned long)size, (unsigned long)addr); | ||
268 | return buf; | ||
269 | } | ||
270 | |||
256 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) | 271 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) |
257 | { | 272 | { |
258 | uint8_t u = val; | 273 | uint8_t u = val; |
@@ -296,6 +311,19 @@ int my_lua_readn(lua_State *state) | |||
296 | return 1; | 311 | return 1; |
297 | } | 312 | } |
298 | 313 | ||
314 | int my_lua_read(lua_State *state) | ||
315 | { | ||
316 | int n = lua_gettop(state); | ||
317 | if(n != 2) | ||
318 | luaL_error(state, "read takes a two arguments: address, length"); | ||
319 | unsigned length = mylua_checkunsigned(state, 2); | ||
320 | uint8_t *buf = hw_read(state, mylua_checkunsigned(state, 1), length); | ||
321 | /* lua strings are really byte buffers, they can contain arbitrary bytes including zeroes */ | ||
322 | lua_pushlstring(state, (const char *)buf, length); | ||
323 | delete[] buf; | ||
324 | return 1; | ||
325 | } | ||
326 | |||
299 | int my_lua_writen(lua_State *state) | 327 | int my_lua_writen(lua_State *state) |
300 | { | 328 | { |
301 | hw_writen_fn_t fn = (hw_writen_fn_t)lua_touserdata(state, lua_upvalueindex(1)); | 329 | hw_writen_fn_t fn = (hw_writen_fn_t)lua_touserdata(state, lua_upvalueindex(1)); |
@@ -797,6 +825,8 @@ bool my_lua_import_hwstub() | |||
797 | lua_pushlightuserdata(g_lua, (void *)&hw_read32); | 825 | lua_pushlightuserdata(g_lua, (void *)&hw_read32); |
798 | lua_pushcclosure(g_lua, my_lua_readn, 1); | 826 | lua_pushcclosure(g_lua, my_lua_readn, 1); |
799 | lua_setfield(g_lua, -2, "read32"); | 827 | lua_setfield(g_lua, -2, "read32"); |
828 | lua_pushcclosure(g_lua, my_lua_read, 0); | ||
829 | lua_setfield(g_lua, -2, "read"); | ||
800 | 830 | ||
801 | lua_pushlightuserdata(g_lua, (void *)&hw_write8); | 831 | lua_pushlightuserdata(g_lua, (void *)&hw_write8); |
802 | lua_pushcclosure(g_lua, my_lua_writen, 1); | 832 | lua_pushcclosure(g_lua, my_lua_writen, 1); |