forked from len0rd/rockbox
hwstub/qeditor: add support for atomic read/writes
The current code assumed that READ/WRITE would produce atomic read/writes for 8/16/32-bit words, which in turned put assumption on the memcpy function. Since some memcpy implementation do not always guarantee such strong assumption, introduce two new operation READ/WRITE_ATOMIC which provide the necessary tools to do correct read and write to register in a single memory access. Change-Id: I37451bd5057bb0dcaf5a800d8aef8791c792a090
This commit is contained in:
parent
794169a18f
commit
cd04a5f1aa
12 changed files with 254 additions and 24 deletions
|
|
@ -144,7 +144,7 @@ typedef void (*hw_writen_fn_t)(lua_State *state, soc_addr_t addr, soc_word_t val
|
|||
soc_word_t hw_read8(lua_State *state, soc_addr_t addr)
|
||||
{
|
||||
uint8_t u;
|
||||
if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to read8 @ %p", addr);
|
||||
return u;
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ soc_word_t hw_read8(lua_State *state, soc_addr_t addr)
|
|||
soc_word_t hw_read16(lua_State *state, soc_addr_t addr)
|
||||
{
|
||||
uint16_t u;
|
||||
if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to read16 @ %p", addr);
|
||||
return u;
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ soc_word_t hw_read16(lua_State *state, soc_addr_t addr)
|
|||
soc_word_t hw_read32(lua_State *state, soc_addr_t addr)
|
||||
{
|
||||
uint32_t u;
|
||||
if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to read32 @ %p", addr);
|
||||
return u;
|
||||
}
|
||||
|
|
@ -168,21 +168,21 @@ soc_word_t hw_read32(lua_State *state, soc_addr_t addr)
|
|||
void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val)
|
||||
{
|
||||
uint8_t u = val;
|
||||
if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to write8 @ %p", addr);
|
||||
}
|
||||
|
||||
void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val)
|
||||
{
|
||||
uint16_t u = val;
|
||||
if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to write16 @ %p", addr);
|
||||
}
|
||||
|
||||
void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val)
|
||||
{
|
||||
uint32_t u = val;
|
||||
if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u))
|
||||
luaL_error(state, "fail to write32 @ %p", addr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ do
|
|||
h = HELP:create_topic("DEV");
|
||||
h:add("This variable redirects to hwstub.dev and provides direct access to the device.");
|
||||
h:add("It contains some information about the device and the following methods.");
|
||||
h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a");
|
||||
h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a");
|
||||
h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically");
|
||||
h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically");
|
||||
h:add("* print_log() prints the device log");
|
||||
|
||||
h = HELP:create_topic("HW");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue