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.cpp116
1 files changed, 67 insertions, 49 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp
index 1c39283894..5fb3e13840 100644
--- a/utils/hwstub/tools/hwstub_shell.cpp
+++ b/utils/hwstub/tools/hwstub_shell.cpp
@@ -125,6 +125,24 @@ void print_log(std::shared_ptr<handle> hwdev)
125/** 125/**
126 * Lua specific 126 * Lua specific
127 */ 127 */
128
129/* the lua_*unsigned functions were never really documented and got deprecated in
130 * lua 5.3. There are simply casts anyway so reimplement them with proper typing */
131static void mylua_pushunsigned(lua_State *L, lua_Unsigned n)
132{
133 lua_pushnumber(L, (lua_Number)n);
134}
135
136static lua_Unsigned mylua_checkunsigned(lua_State *L, int arg)
137{
138 return (lua_Unsigned)luaL_checknumber(L, arg);
139}
140
141static lua_Unsigned mylua_tounsigned(lua_State *L, int arg)
142{
143 return (lua_Unsigned)lua_tointeger(L, arg);
144}
145
128int my_lua_help(lua_State *state) 146int my_lua_help(lua_State *state)
129{ 147{
130 bool has_sub = false; 148 bool has_sub = false;
@@ -274,7 +292,7 @@ int my_lua_readn(lua_State *state)
274 int n = lua_gettop(state); 292 int n = lua_gettop(state);
275 if(n != 1) 293 if(n != 1)
276 luaL_error(state, "readn takes a single argument"); 294 luaL_error(state, "readn takes a single argument");
277 lua_pushunsigned(state, fn(state, luaL_checkunsigned(state, 1))); 295 mylua_pushunsigned(state, fn(state, mylua_checkunsigned(state, 1)));
278 return 1; 296 return 1;
279} 297}
280 298
@@ -284,7 +302,7 @@ int my_lua_writen(lua_State *state)
284 int n = lua_gettop(state); 302 int n = lua_gettop(state);
285 if(n != 2) 303 if(n != 2)
286 luaL_error(state, "writen takes two arguments"); 304 luaL_error(state, "writen takes two arguments");
287 fn(state, luaL_checkunsigned(state, 1), luaL_checkunsigned(state, 2)); 305 fn(state, mylua_checkunsigned(state, 1), mylua_checkunsigned(state, 2));
288 return 0; 306 return 0;
289} 307}
290 308
@@ -294,7 +312,7 @@ int my_lua_call(lua_State *state)
294 if(n != 1) 312 if(n != 1)
295 luaL_error(state, "call takes target address argument"); 313 luaL_error(state, "call takes target address argument");
296 314
297 g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_CALL); 315 g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_CALL);
298 return 0; 316 return 0;
299} 317}
300 318
@@ -304,7 +322,7 @@ int my_lua_jump(lua_State *state)
304 if(n != 1) 322 if(n != 1)
305 luaL_error(state, "jump takes target address argument"); 323 luaL_error(state, "jump takes target address argument");
306 324
307 g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_JUMP); 325 g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_JUMP);
308 return 0; 326 return 0;
309} 327}
310 328
@@ -828,9 +846,9 @@ int my_lua_read_reg(lua_State *state)
828 int n = lua_gettop(state); 846 int n = lua_gettop(state);
829 if(n != 0) 847 if(n != 0)
830 luaL_error(state, "read() takes no argument"); 848 luaL_error(state, "read() takes no argument");
831 unsigned width = lua_tounsigned(state, lua_upvalueindex(1)); 849 unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
832 soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2)); 850 soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
833 lua_pushunsigned(state, hw_readn(state, width, addr)); 851 mylua_pushunsigned(state, hw_readn(state, width, addr));
834 return 1; 852 return 1;
835} 853}
836 854
@@ -839,9 +857,9 @@ int my_lua_write_reg(lua_State *state)
839 int n = lua_gettop(state); 857 int n = lua_gettop(state);
840 if(n != 1) 858 if(n != 1)
841 luaL_error(state, "write() takes one argument"); 859 luaL_error(state, "write() takes one argument");
842 soc_word_t val = luaL_checkunsigned(state, 1); 860 soc_word_t val = mylua_checkunsigned(state, 1);
843 unsigned width = lua_tounsigned(state, lua_upvalueindex(1)); 861 unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
844 soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2)); 862 soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
845 hw_writen(state, width, addr, val); 863 hw_writen(state, width, addr, val);
846 return 0; 864 return 0;
847} 865}
@@ -851,11 +869,11 @@ int my_lua_read_field(lua_State *state)
851 int n = lua_gettop(state); 869 int n = lua_gettop(state);
852 if(n != 0) 870 if(n != 0)
853 luaL_error(state, "read() takes no argument"); 871 luaL_error(state, "read() takes no argument");
854 unsigned width = lua_tounsigned(state, lua_upvalueindex(1)); 872 unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
855 soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2)); 873 soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
856 soc_word_t shift = lua_tounsigned(state, lua_upvalueindex(3)); 874 soc_word_t shift = mylua_tounsigned(state, lua_upvalueindex(3));
857 soc_word_t mask = lua_tounsigned(state, lua_upvalueindex(4)); 875 soc_word_t mask = mylua_tounsigned(state, lua_upvalueindex(4));
858 lua_pushunsigned(state, (hw_readn(state, width, addr) >> shift) & mask); 876 mylua_pushunsigned(state, (hw_readn(state, width, addr) >> shift) & mask);
859 return 1; 877 return 1;
860} 878}
861 879
@@ -864,11 +882,11 @@ int my_lua_write_field(lua_State *state)
864 int n = lua_gettop(state); 882 int n = lua_gettop(state);
865 if(n != 0 && n!= 1) 883 if(n != 0 && n!= 1)
866 luaL_error(state, "write() takes one or no argument"); 884 luaL_error(state, "write() takes one or no argument");
867 unsigned width = lua_tounsigned(state, lua_upvalueindex(1)); 885 unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
868 soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2)); 886 soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
869 soc_word_t shift = lua_tounsigned(state, lua_upvalueindex(3)); 887 soc_word_t shift = mylua_tounsigned(state, lua_upvalueindex(3));
870 soc_word_t mask = lua_tounsigned(state, lua_upvalueindex(4)); 888 soc_word_t mask = mylua_tounsigned(state, lua_upvalueindex(4));
871 char op = lua_tounsigned(state, lua_upvalueindex(6)); 889 char op = mylua_tounsigned(state, lua_upvalueindex(6));
872 890
873 soc_word_t value = mask; 891 soc_word_t value = mask;
874 if(n == 1) 892 if(n == 1)
@@ -880,11 +898,11 @@ int my_lua_write_field(lua_State *state)
880 lua_gettable(state, -2); 898 lua_gettable(state, -2);
881 if(lua_isnil(state, -1)) 899 if(lua_isnil(state, -1))
882 luaL_error(state, "field has no value %s", lua_tostring(state, 1)); 900 luaL_error(state, "field has no value %s", lua_tostring(state, 1));
883 value = luaL_checkunsigned(state, -1); 901 value = mylua_checkunsigned(state, -1);
884 lua_pop(state, 2); 902 lua_pop(state, 2);
885 } 903 }
886 else 904 else
887 value = luaL_checkunsigned(state, 1); 905 value = mylua_checkunsigned(state, 1);
888 value &= mask; 906 value &= mask;
889 } 907 }
890 908
@@ -909,11 +927,11 @@ int my_lua_sct_reg(lua_State *state)
909 int n = lua_gettop(state); 927 int n = lua_gettop(state);
910 if(n != 1) 928 if(n != 1)
911 luaL_error(state, "sct() takes one argument"); 929 luaL_error(state, "sct() takes one argument");
912 unsigned width = lua_tounsigned(state, lua_upvalueindex(1)); 930 unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
913 soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2)); 931 soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
914 char op = lua_tounsigned(state, lua_upvalueindex(3)); 932 char op = mylua_tounsigned(state, lua_upvalueindex(3));
915 933
916 soc_word_t mask = luaL_checkunsigned(state, 1); 934 soc_word_t mask = mylua_checkunsigned(state, 1);
917 soc_word_t value = hw_read32(state, addr); 935 soc_word_t value = hw_read32(state, addr);
918 if(op == 's') 936 if(op == 's')
919 value |= mask; 937 value |= mask;
@@ -942,37 +960,37 @@ void my_lua_create_field(soc_addr_t addr, soc_desc::field_ref_t field)
942 lua_setfield(g_lua, -2, "name"); 960 lua_setfield(g_lua, -2, "name");
943 /* lua stack: <field table> ... */ 961 /* lua stack: <field table> ... */
944 962
945 lua_pushunsigned(g_lua, addr); 963 mylua_pushunsigned(g_lua, addr);
946 /* lua stack: <addr> <field table> ... */ 964 /* lua stack: <addr> <field table> ... */
947 lua_setfield(g_lua, -2, "addr"); 965 lua_setfield(g_lua, -2, "addr");
948 /* lua stack: <field table> ... */ 966 /* lua stack: <field table> ... */
949 967
950 lua_pushunsigned(g_lua, f->pos); 968 mylua_pushunsigned(g_lua, f->pos);
951 /* lua stack: <pos> <field table> ... */ 969 /* lua stack: <pos> <field table> ... */
952 lua_setfield(g_lua, -2, "pos"); 970 lua_setfield(g_lua, -2, "pos");
953 /* lua stack: <field table> ... */ 971 /* lua stack: <field table> ... */
954 972
955 lua_pushunsigned(g_lua, f->width); 973 mylua_pushunsigned(g_lua, f->width);
956 /* lua stack: <width> <field table> ... */ 974 /* lua stack: <width> <field table> ... */
957 lua_setfield(g_lua, -2, "width"); 975 lua_setfield(g_lua, -2, "width");
958 /* lua stack: <field table> ... */ 976 /* lua stack: <field table> ... */
959 977
960 lua_pushunsigned(g_lua, f->bitmask()); 978 mylua_pushunsigned(g_lua, f->bitmask());
961 /* lua stack: <bm> <field table> ... */ 979 /* lua stack: <bm> <field table> ... */
962 lua_setfield(g_lua, -2, "bitmask"); 980 lua_setfield(g_lua, -2, "bitmask");
963 /* lua stack: <field table> ... */ 981 /* lua stack: <field table> ... */
964 982
965 soc_word_t local_bitmask = f->bitmask() >> f->pos; 983 soc_word_t local_bitmask = f->bitmask() >> f->pos;
966 lua_pushunsigned(g_lua, local_bitmask); 984 mylua_pushunsigned(g_lua, local_bitmask);
967 /* lua stack: <local_bm> <field table> ... */ 985 /* lua stack: <local_bm> <field table> ... */
968 lua_setfield(g_lua, -2, "local_bitmask"); 986 lua_setfield(g_lua, -2, "local_bitmask");
969 /* lua stack: <field table> ... */ 987 /* lua stack: <field table> ... */
970 988
971 /** create read routine */ 989 /** create read routine */
972 lua_pushunsigned(g_lua, field.reg().get()->width); 990 mylua_pushunsigned(g_lua, field.reg().get()->width);
973 lua_pushunsigned(g_lua, addr); 991 mylua_pushunsigned(g_lua, addr);
974 lua_pushunsigned(g_lua, f->pos); 992 mylua_pushunsigned(g_lua, f->pos);
975 lua_pushunsigned(g_lua, local_bitmask); 993 mylua_pushunsigned(g_lua, local_bitmask);
976 /* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */ 994 /* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */
977 lua_pushcclosure(g_lua, my_lua_read_field, 4); 995 lua_pushcclosure(g_lua, my_lua_read_field, 4);
978 /* lua stack: <my_lua_read_field> <field table> ... */ 996 /* lua stack: <my_lua_read_field> <field table> ... */
@@ -984,14 +1002,14 @@ void my_lua_create_field(soc_addr_t addr, soc_desc::field_ref_t field)
984 static const char arg[] = {'w', 's', 'c', 't'}; 1002 static const char arg[] = {'w', 's', 'c', 't'};
985 for(int i = 0; i < 4; i++) 1003 for(int i = 0; i < 4; i++)
986 { 1004 {
987 lua_pushunsigned(g_lua, field.reg().get()->width); 1005 mylua_pushunsigned(g_lua, field.reg().get()->width);
988 lua_pushunsigned(g_lua, addr); 1006 mylua_pushunsigned(g_lua, addr);
989 lua_pushunsigned(g_lua, f->pos); 1007 mylua_pushunsigned(g_lua, f->pos);
990 lua_pushunsigned(g_lua, local_bitmask); 1008 mylua_pushunsigned(g_lua, local_bitmask);
991 /* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */ 1009 /* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */
992 lua_pushvalue(g_lua, -5); 1010 lua_pushvalue(g_lua, -5);
993 /* lua stack: <field table> <local_bm> <pos> <addr> <width> <field table> ... */ 1011 /* lua stack: <field table> <local_bm> <pos> <addr> <width> <field table> ... */
994 lua_pushunsigned(g_lua, arg[i]); 1012 mylua_pushunsigned(g_lua, arg[i]);
995 /* lua stack: <'wsct'> <field table> <local_bm> <pos> <addr> <width> <field table> ... */ 1013 /* lua stack: <'wsct'> <field table> <local_bm> <pos> <addr> <width> <field table> ... */
996 lua_pushcclosure(g_lua, my_lua_write_field, 6); 1014 lua_pushcclosure(g_lua, my_lua_write_field, 6);
997 /* lua stack: <my_lua_write_field> <field table> ... */ 1015 /* lua stack: <my_lua_write_field> <field table> ... */
@@ -1002,7 +1020,7 @@ void my_lua_create_field(soc_addr_t addr, soc_desc::field_ref_t field)
1002 /** create values */ 1020 /** create values */
1003 for(size_t i = 0; i < f->enum_.size(); i++) 1021 for(size_t i = 0; i < f->enum_.size(); i++)
1004 { 1022 {
1005 lua_pushunsigned(g_lua, f->enum_[i].value); 1023 mylua_pushunsigned(g_lua, f->enum_[i].value);
1006 /* lua stack: <value> <field table> ... */ 1024 /* lua stack: <value> <field table> ... */
1007 lua_setfield(g_lua, -2, f->enum_[i].name.c_str()); 1025 lua_setfield(g_lua, -2, f->enum_[i].name.c_str());
1008 /* lua stack: <field table> ... */ 1026 /* lua stack: <field table> ... */
@@ -1020,16 +1038,16 @@ void my_lua_create_reg(soc_addr_t addr, soc_desc::register_ref_t reg,
1020 if(!reg.valid()) 1038 if(!reg.valid())
1021 return; 1039 return;
1022 /** create read/write routine */ 1040 /** create read/write routine */
1023 lua_pushunsigned(g_lua, reg.get()->width); 1041 mylua_pushunsigned(g_lua, reg.get()->width);
1024 lua_pushunsigned(g_lua, addr); 1042 mylua_pushunsigned(g_lua, addr);
1025 /* lua stack: <addr> <width> <inst table> */ 1043 /* lua stack: <addr> <width> <inst table> */
1026 lua_pushcclosure(g_lua, my_lua_read_reg, 2); 1044 lua_pushcclosure(g_lua, my_lua_read_reg, 2);
1027 /* lua stack: <my_lua_read_reg> <inst table> */ 1045 /* lua stack: <my_lua_read_reg> <inst table> */
1028 lua_setfield(g_lua, -2, "read"); 1046 lua_setfield(g_lua, -2, "read");
1029 /* lua stack: <inst table> */ 1047 /* lua stack: <inst table> */
1030 1048
1031 lua_pushunsigned(g_lua, reg.get()->width); 1049 mylua_pushunsigned(g_lua, reg.get()->width);
1032 lua_pushunsigned(g_lua, addr); 1050 mylua_pushunsigned(g_lua, addr);
1033 /* lua stack: <addr> <width> <inst table> */ 1051 /* lua stack: <addr> <width> <inst table> */
1034 lua_pushcclosure(g_lua, my_lua_write_reg, 2); 1052 lua_pushcclosure(g_lua, my_lua_write_reg, 2);
1035 /* lua stack: <my_lua_write_reg> <inst table> */ 1053 /* lua stack: <my_lua_write_reg> <inst table> */
@@ -1041,10 +1059,10 @@ void my_lua_create_reg(soc_addr_t addr, soc_desc::register_ref_t reg,
1041 static const char arg[] = {'s', 'c', 't'}; 1059 static const char arg[] = {'s', 'c', 't'};
1042 for(int i = 0; i < 3; i++) 1060 for(int i = 0; i < 3; i++)
1043 { 1061 {
1044 lua_pushunsigned(g_lua, reg.get()->width); 1062 mylua_pushunsigned(g_lua, reg.get()->width);
1045 lua_pushunsigned(g_lua, addr); 1063 mylua_pushunsigned(g_lua, addr);
1046 /* lua stack: <addr> <width> <inst table> */ 1064 /* lua stack: <addr> <width> <inst table> */
1047 lua_pushunsigned(g_lua, arg[i]); 1065 mylua_pushunsigned(g_lua, arg[i]);
1048 /* lua stack: <'s'/'c'/'t'> <addr> <width> <inst table> */ 1066 /* lua stack: <'s'/'c'/'t'> <addr> <width> <inst table> */
1049 lua_pushcclosure(g_lua, my_lua_sct_reg, 3); 1067 lua_pushcclosure(g_lua, my_lua_sct_reg, 3);
1050 /* lua stack: <my_lua_sct_reg> <inst table> */ 1068 /* lua stack: <my_lua_sct_reg> <inst table> */
@@ -1122,7 +1140,7 @@ void my_lua_create_instances(const std::vector< soc_desc::node_inst_t >& inst)
1122 lua_setfield(g_lua, -2, "title"); 1140 lua_setfield(g_lua, -2, "title");
1123 /* lua stack: <instance table> ... */ 1141 /* lua stack: <instance table> ... */
1124 1142
1125 lua_pushunsigned(g_lua, inst[i].addr()); 1143 mylua_pushunsigned(g_lua, inst[i].addr());
1126 /* lua stack: <node addr> <instance table> ... */ 1144 /* lua stack: <node addr> <instance table> ... */
1127 lua_setfield(g_lua, -2, "addr"); 1145 lua_setfield(g_lua, -2, "addr");
1128 /* lua stack: <instance table> ... */ 1146 /* lua stack: <instance table> ... */