hwstub/tools: fix compilation of shell against lua5.3
The unsigned function were deprecated and hidden begind a compat flag. Since they will get removed in the next version, I simply reimplemented them, those are mostly casts anyway. Change-Id: Ie5db81d7c8589b1e5e9b45a2a4ed41919aa07387
This commit is contained in:
parent
06502772a8
commit
ce966d3d28
1 changed files with 67 additions and 49 deletions
|
@ -125,6 +125,24 @@ void print_log(std::shared_ptr<handle> hwdev)
|
|||
/**
|
||||
* Lua specific
|
||||
*/
|
||||
|
||||
/* the lua_*unsigned functions were never really documented and got deprecated in
|
||||
* lua 5.3. There are simply casts anyway so reimplement them with proper typing */
|
||||
static void mylua_pushunsigned(lua_State *L, lua_Unsigned n)
|
||||
{
|
||||
lua_pushnumber(L, (lua_Number)n);
|
||||
}
|
||||
|
||||
static lua_Unsigned mylua_checkunsigned(lua_State *L, int arg)
|
||||
{
|
||||
return (lua_Unsigned)luaL_checknumber(L, arg);
|
||||
}
|
||||
|
||||
static lua_Unsigned mylua_tounsigned(lua_State *L, int arg)
|
||||
{
|
||||
return (lua_Unsigned)lua_tointeger(L, arg);
|
||||
}
|
||||
|
||||
int my_lua_help(lua_State *state)
|
||||
{
|
||||
bool has_sub = false;
|
||||
|
@ -274,7 +292,7 @@ int my_lua_readn(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 1)
|
||||
luaL_error(state, "readn takes a single argument");
|
||||
lua_pushunsigned(state, fn(state, luaL_checkunsigned(state, 1)));
|
||||
mylua_pushunsigned(state, fn(state, mylua_checkunsigned(state, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -284,7 +302,7 @@ int my_lua_writen(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 2)
|
||||
luaL_error(state, "writen takes two arguments");
|
||||
fn(state, luaL_checkunsigned(state, 1), luaL_checkunsigned(state, 2));
|
||||
fn(state, mylua_checkunsigned(state, 1), mylua_checkunsigned(state, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -294,7 +312,7 @@ int my_lua_call(lua_State *state)
|
|||
if(n != 1)
|
||||
luaL_error(state, "call takes target address argument");
|
||||
|
||||
g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_CALL);
|
||||
g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_CALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -304,7 +322,7 @@ int my_lua_jump(lua_State *state)
|
|||
if(n != 1)
|
||||
luaL_error(state, "jump takes target address argument");
|
||||
|
||||
g_hwdev->exec(luaL_checkunsigned(state, 1), HWSTUB_EXEC_JUMP);
|
||||
g_hwdev->exec(mylua_checkunsigned(state, 1), HWSTUB_EXEC_JUMP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -828,9 +846,9 @@ int my_lua_read_reg(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 0)
|
||||
luaL_error(state, "read() takes no argument");
|
||||
unsigned width = lua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2));
|
||||
lua_pushunsigned(state, hw_readn(state, width, addr));
|
||||
unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
|
||||
mylua_pushunsigned(state, hw_readn(state, width, addr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -839,9 +857,9 @@ int my_lua_write_reg(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 1)
|
||||
luaL_error(state, "write() takes one argument");
|
||||
soc_word_t val = luaL_checkunsigned(state, 1);
|
||||
unsigned width = lua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2));
|
||||
soc_word_t val = mylua_checkunsigned(state, 1);
|
||||
unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
|
||||
hw_writen(state, width, addr, val);
|
||||
return 0;
|
||||
}
|
||||
|
@ -851,11 +869,11 @@ int my_lua_read_field(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 0)
|
||||
luaL_error(state, "read() takes no argument");
|
||||
unsigned width = lua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2));
|
||||
soc_word_t shift = lua_tounsigned(state, lua_upvalueindex(3));
|
||||
soc_word_t mask = lua_tounsigned(state, lua_upvalueindex(4));
|
||||
lua_pushunsigned(state, (hw_readn(state, width, addr) >> shift) & mask);
|
||||
unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
|
||||
soc_word_t shift = mylua_tounsigned(state, lua_upvalueindex(3));
|
||||
soc_word_t mask = mylua_tounsigned(state, lua_upvalueindex(4));
|
||||
mylua_pushunsigned(state, (hw_readn(state, width, addr) >> shift) & mask);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -864,11 +882,11 @@ int my_lua_write_field(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 0 && n!= 1)
|
||||
luaL_error(state, "write() takes one or no argument");
|
||||
unsigned width = lua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2));
|
||||
soc_word_t shift = lua_tounsigned(state, lua_upvalueindex(3));
|
||||
soc_word_t mask = lua_tounsigned(state, lua_upvalueindex(4));
|
||||
char op = lua_tounsigned(state, lua_upvalueindex(6));
|
||||
unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
|
||||
soc_word_t shift = mylua_tounsigned(state, lua_upvalueindex(3));
|
||||
soc_word_t mask = mylua_tounsigned(state, lua_upvalueindex(4));
|
||||
char op = mylua_tounsigned(state, lua_upvalueindex(6));
|
||||
|
||||
soc_word_t value = mask;
|
||||
if(n == 1)
|
||||
|
@ -880,11 +898,11 @@ int my_lua_write_field(lua_State *state)
|
|||
lua_gettable(state, -2);
|
||||
if(lua_isnil(state, -1))
|
||||
luaL_error(state, "field has no value %s", lua_tostring(state, 1));
|
||||
value = luaL_checkunsigned(state, -1);
|
||||
value = mylua_checkunsigned(state, -1);
|
||||
lua_pop(state, 2);
|
||||
}
|
||||
else
|
||||
value = luaL_checkunsigned(state, 1);
|
||||
value = mylua_checkunsigned(state, 1);
|
||||
value &= mask;
|
||||
}
|
||||
|
||||
|
@ -909,11 +927,11 @@ int my_lua_sct_reg(lua_State *state)
|
|||
int n = lua_gettop(state);
|
||||
if(n != 1)
|
||||
luaL_error(state, "sct() takes one argument");
|
||||
unsigned width = lua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = lua_tounsigned(state, lua_upvalueindex(2));
|
||||
char op = lua_tounsigned(state, lua_upvalueindex(3));
|
||||
unsigned width = mylua_tounsigned(state, lua_upvalueindex(1));
|
||||
soc_addr_t addr = mylua_tounsigned(state, lua_upvalueindex(2));
|
||||
char op = mylua_tounsigned(state, lua_upvalueindex(3));
|
||||
|
||||
soc_word_t mask = luaL_checkunsigned(state, 1);
|
||||
soc_word_t mask = mylua_checkunsigned(state, 1);
|
||||
soc_word_t value = hw_read32(state, addr);
|
||||
if(op == 's')
|
||||
value |= mask;
|
||||
|
@ -942,37 +960,37 @@ void my_lua_create_field(soc_addr_t addr, soc_desc::field_ref_t field)
|
|||
lua_setfield(g_lua, -2, "name");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
/* lua stack: <addr> <field table> ... */
|
||||
lua_setfield(g_lua, -2, "addr");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
lua_pushunsigned(g_lua, f->pos);
|
||||
mylua_pushunsigned(g_lua, f->pos);
|
||||
/* lua stack: <pos> <field table> ... */
|
||||
lua_setfield(g_lua, -2, "pos");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
lua_pushunsigned(g_lua, f->width);
|
||||
mylua_pushunsigned(g_lua, f->width);
|
||||
/* lua stack: <width> <field table> ... */
|
||||
lua_setfield(g_lua, -2, "width");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
lua_pushunsigned(g_lua, f->bitmask());
|
||||
mylua_pushunsigned(g_lua, f->bitmask());
|
||||
/* lua stack: <bm> <field table> ... */
|
||||
lua_setfield(g_lua, -2, "bitmask");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
soc_word_t local_bitmask = f->bitmask() >> f->pos;
|
||||
lua_pushunsigned(g_lua, local_bitmask);
|
||||
mylua_pushunsigned(g_lua, local_bitmask);
|
||||
/* lua stack: <local_bm> <field table> ... */
|
||||
lua_setfield(g_lua, -2, "local_bitmask");
|
||||
/* lua stack: <field table> ... */
|
||||
|
||||
/** create read routine */
|
||||
lua_pushunsigned(g_lua, field.reg().get()->width);
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
lua_pushunsigned(g_lua, f->pos);
|
||||
lua_pushunsigned(g_lua, local_bitmask);
|
||||
mylua_pushunsigned(g_lua, field.reg().get()->width);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, f->pos);
|
||||
mylua_pushunsigned(g_lua, local_bitmask);
|
||||
/* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */
|
||||
lua_pushcclosure(g_lua, my_lua_read_field, 4);
|
||||
/* 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)
|
|||
static const char arg[] = {'w', 's', 'c', 't'};
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
lua_pushunsigned(g_lua, field.reg().get()->width);
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
lua_pushunsigned(g_lua, f->pos);
|
||||
lua_pushunsigned(g_lua, local_bitmask);
|
||||
mylua_pushunsigned(g_lua, field.reg().get()->width);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, f->pos);
|
||||
mylua_pushunsigned(g_lua, local_bitmask);
|
||||
/* lua stack: <local_bm> <pos> <addr> <width> <field table> ... */
|
||||
lua_pushvalue(g_lua, -5);
|
||||
/* lua stack: <field table> <local_bm> <pos> <addr> <width> <field table> ... */
|
||||
lua_pushunsigned(g_lua, arg[i]);
|
||||
mylua_pushunsigned(g_lua, arg[i]);
|
||||
/* lua stack: <'wsct'> <field table> <local_bm> <pos> <addr> <width> <field table> ... */
|
||||
lua_pushcclosure(g_lua, my_lua_write_field, 6);
|
||||
/* 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)
|
|||
/** create values */
|
||||
for(size_t i = 0; i < f->enum_.size(); i++)
|
||||
{
|
||||
lua_pushunsigned(g_lua, f->enum_[i].value);
|
||||
mylua_pushunsigned(g_lua, f->enum_[i].value);
|
||||
/* lua stack: <value> <field table> ... */
|
||||
lua_setfield(g_lua, -2, f->enum_[i].name.c_str());
|
||||
/* lua stack: <field table> ... */
|
||||
|
@ -1020,16 +1038,16 @@ void my_lua_create_reg(soc_addr_t addr, soc_desc::register_ref_t reg,
|
|||
if(!reg.valid())
|
||||
return;
|
||||
/** create read/write routine */
|
||||
lua_pushunsigned(g_lua, reg.get()->width);
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, reg.get()->width);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
/* lua stack: <addr> <width> <inst table> */
|
||||
lua_pushcclosure(g_lua, my_lua_read_reg, 2);
|
||||
/* lua stack: <my_lua_read_reg> <inst table> */
|
||||
lua_setfield(g_lua, -2, "read");
|
||||
/* lua stack: <inst table> */
|
||||
|
||||
lua_pushunsigned(g_lua, reg.get()->width);
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, reg.get()->width);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
/* lua stack: <addr> <width> <inst table> */
|
||||
lua_pushcclosure(g_lua, my_lua_write_reg, 2);
|
||||
/* 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,
|
|||
static const char arg[] = {'s', 'c', 't'};
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
lua_pushunsigned(g_lua, reg.get()->width);
|
||||
lua_pushunsigned(g_lua, addr);
|
||||
mylua_pushunsigned(g_lua, reg.get()->width);
|
||||
mylua_pushunsigned(g_lua, addr);
|
||||
/* lua stack: <addr> <width> <inst table> */
|
||||
lua_pushunsigned(g_lua, arg[i]);
|
||||
mylua_pushunsigned(g_lua, arg[i]);
|
||||
/* lua stack: <'s'/'c'/'t'> <addr> <width> <inst table> */
|
||||
lua_pushcclosure(g_lua, my_lua_sct_reg, 3);
|
||||
/* 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)
|
|||
lua_setfield(g_lua, -2, "title");
|
||||
/* lua stack: <instance table> ... */
|
||||
|
||||
lua_pushunsigned(g_lua, inst[i].addr());
|
||||
mylua_pushunsigned(g_lua, inst[i].addr());
|
||||
/* lua stack: <node addr> <instance table> ... */
|
||||
lua_setfield(g_lua, -2, "addr");
|
||||
/* lua stack: <instance table> ... */
|
||||
|
|
Loading…
Reference in a new issue