diff options
| author | Amaury Pouly <amaury.pouly@gmail.com> | 2016-08-04 17:06:11 +0100 |
|---|---|---|
| committer | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-24 15:25:14 +0100 |
| commit | 8fabbb008c1a31c809a3d97f22351f141a2bd02d (patch) | |
| tree | 6e16386a7348197920a5ce1d99f623d0e10b6c3c /utils/hwstub/tools/hwstub_shell.cpp | |
| parent | d91d9f6851bba401650912c5cabcfe4c5f1150df (diff) | |
| download | rockbox-8fabbb008c1a31c809a3d97f22351f141a2bd02d.zip rockbox-8fabbb008c1a31c809a3d97f22351f141a2bd02d.tar.gz rockbox-8fabbb008c1a31c809a3d97f22351f141a2bd02d.tar.bz2 rockbox-8fabbb008c1a31c809a3d97f22351f141a2bd02d.tar.xz | |
hwstub: add support for coprocessor operations
At the moment the stub only implement them for MIPS.
Change-Id: Ica835a0e9c70fa5675c3d655eae986e812a47de8
Diffstat (limited to 'utils/hwstub/tools/hwstub_shell.cpp')
| -rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index b2cf2ce..336b7fe 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp @@ -310,9 +310,11 @@ int my_lua_call(lua_State *state) { int n = lua_gettop(state); if(n != 1) - luaL_error(state, "call takes target address argument"); + luaL_error(state, "call takes one argument: target address"); - g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_CALL); + error ret = g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_CALL); + if(ret != error::SUCCESS) + luaL_error(state, "call failed"); return 0; } @@ -320,9 +322,67 @@ int my_lua_jump(lua_State *state) { int n = lua_gettop(state); if(n != 1) - luaL_error(state, "jump takes target address argument"); + luaL_error(state, "jump takes one argument: target address"); + + error ret = g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_JUMP); + if(ret != error::SUCCESS) + luaL_error(state, "jump failed"); + return 0; +} + +int my_lua_read32_cop(lua_State *state) +{ + int n = lua_gettop(state); + if(n != 1) + luaL_error(state, "read32_cop takes one argument: arguments (array)"); + uint8_t args[HWSTUB_COP_ARGS] = {0}; + /* parse array */ + luaL_checktype(state, 1, LUA_TTABLE); + size_t sz = lua_rawlen(state, 1); + if(sz > HWSTUB_COP_ARGS) + luaL_error(state, "coprocessor operation take at most %d arguments", HWSTUB_COP_ARGS); + for(size_t i = 0; i < sz; i++) + { + lua_pushinteger(state, i + 1); /* index start at 1 */ + lua_gettable(state, 1); + /* check it is an integer */ + args[i] = luaL_checkunsigned(state, -1); + /* pop it */ + lua_pop(state, 1); + } - g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_JUMP); + uint32_t val; + error ret = g_hwdev->read32_cop(args, val); + if(ret != error::SUCCESS) + luaL_error(state, "coprocessor read failed"); + lua_pushunsigned(state, val); + return 1; +} + +int my_lua_write32_cop(lua_State *state) +{ + int n = lua_gettop(state); + if(n != 2) + luaL_error(state, "write32_cop takes two arguments: arguments (array) and value"); + uint8_t args[HWSTUB_COP_ARGS] = {0}; + /* parse array */ + luaL_checktype(state, 1, LUA_TTABLE); + size_t sz = lua_rawlen(state, 1); + if(sz > HWSTUB_COP_ARGS) + luaL_error(state, "coprocessor operation take at most %d arguments", HWSTUB_COP_ARGS); + for(size_t i = 0; i < sz; i++) + { + lua_pushinteger(state, i + 1); /* index start at 1 */ + lua_gettable(state, 1); + /* check it is an integer */ + args[i] = luaL_checkunsigned(state, -1); + /* pop it */ + lua_pop(state, 1); + } + + error ret = g_hwdev->write32_cop(args, luaL_checkunsigned(state, 2)); + if(ret != error::SUCCESS) + luaL_error(state, "coprocessor write failed"); return 0; } @@ -753,6 +813,10 @@ bool my_lua_import_hwstub() lua_setfield(g_lua, -2, "call"); lua_pushcclosure(g_lua, my_lua_jump, 0); lua_setfield(g_lua, -2, "jump"); + lua_pushcclosure(g_lua, my_lua_read32_cop, 0); + lua_setfield(g_lua, -2, "read32_cop"); + lua_pushcclosure(g_lua, my_lua_write32_cop, 0); + lua_setfield(g_lua, -2, "write32_cop"); lua_setfield(g_lua, -2, "dev"); |