summaryrefslogtreecommitdiff
path: root/utils/hwstub/tools/hwstub_shell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/tools/hwstub_shell.cpp')
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp72
1 files changed, 68 insertions, 4 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp
index b2cf2cec60..336b7fed6b 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)
310{ 310{
311 int n = lua_gettop(state); 311 int n = lua_gettop(state);
312 if(n != 1) 312 if(n != 1)
313 luaL_error(state, "call takes target address argument"); 313 luaL_error(state, "call takes one argument: target address");
314 314
315 g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_CALL); 315 error ret = g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_CALL);
316 if(ret != error::SUCCESS)
317 luaL_error(state, "call failed");
316 return 0; 318 return 0;
317} 319}
318 320
@@ -320,9 +322,67 @@ int my_lua_jump(lua_State *state)
320{ 322{
321 int n = lua_gettop(state); 323 int n = lua_gettop(state);
322 if(n != 1) 324 if(n != 1)
323 luaL_error(state, "jump takes target address argument"); 325 luaL_error(state, "jump takes one argument: target address");
326
327 error ret = g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_JUMP);
328 if(ret != error::SUCCESS)
329 luaL_error(state, "jump failed");
330 return 0;
331}
332
333int my_lua_read32_cop(lua_State *state)
334{
335 int n = lua_gettop(state);
336 if(n != 1)
337 luaL_error(state, "read32_cop takes one argument: arguments (array)");
338 uint8_t args[HWSTUB_COP_ARGS] = {0};
339 /* parse array */
340 luaL_checktype(state, 1, LUA_TTABLE);
341 size_t sz = lua_rawlen(state, 1);
342 if(sz > HWSTUB_COP_ARGS)
343 luaL_error(state, "coprocessor operation take at most %d arguments", HWSTUB_COP_ARGS);
344 for(size_t i = 0; i < sz; i++)
345 {
346 lua_pushinteger(state, i + 1); /* index start at 1 */
347 lua_gettable(state, 1);
348 /* check it is an integer */
349 args[i] = luaL_checkunsigned(state, -1);
350 /* pop it */
351 lua_pop(state, 1);
352 }
324 353
325 g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_JUMP); 354 uint32_t val;
355 error ret = g_hwdev->read32_cop(args, val);
356 if(ret != error::SUCCESS)
357 luaL_error(state, "coprocessor read failed");
358 lua_pushunsigned(state, val);
359 return 1;
360}
361
362int my_lua_write32_cop(lua_State *state)
363{
364 int n = lua_gettop(state);
365 if(n != 2)
366 luaL_error(state, "write32_cop takes two arguments: arguments (array) and value");
367 uint8_t args[HWSTUB_COP_ARGS] = {0};
368 /* parse array */
369 luaL_checktype(state, 1, LUA_TTABLE);
370 size_t sz = lua_rawlen(state, 1);
371 if(sz > HWSTUB_COP_ARGS)
372 luaL_error(state, "coprocessor operation take at most %d arguments", HWSTUB_COP_ARGS);
373 for(size_t i = 0; i < sz; i++)
374 {
375 lua_pushinteger(state, i + 1); /* index start at 1 */
376 lua_gettable(state, 1);
377 /* check it is an integer */
378 args[i] = luaL_checkunsigned(state, -1);
379 /* pop it */
380 lua_pop(state, 1);
381 }
382
383 error ret = g_hwdev->write32_cop(args, luaL_checkunsigned(state, 2));
384 if(ret != error::SUCCESS)
385 luaL_error(state, "coprocessor write failed");
326 return 0; 386 return 0;
327} 387}
328 388
@@ -753,6 +813,10 @@ bool my_lua_import_hwstub()
753 lua_setfield(g_lua, -2, "call"); 813 lua_setfield(g_lua, -2, "call");
754 lua_pushcclosure(g_lua, my_lua_jump, 0); 814 lua_pushcclosure(g_lua, my_lua_jump, 0);
755 lua_setfield(g_lua, -2, "jump"); 815 lua_setfield(g_lua, -2, "jump");
816 lua_pushcclosure(g_lua, my_lua_read32_cop, 0);
817 lua_setfield(g_lua, -2, "read32_cop");
818 lua_pushcclosure(g_lua, my_lua_write32_cop, 0);
819 lua_setfield(g_lua, -2, "write32_cop");
756 820
757 lua_setfield(g_lua, -2, "dev"); 821 lua_setfield(g_lua, -2, "dev");
758 822