diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-11-18 23:27:26 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-11-18 23:30:44 +0100 |
commit | cd04a5f1aadc8e2ec4e787f5ba4cc8c38a579314 (patch) | |
tree | 63e9f095451aeba0139152c8742d0af67413690a /utils/hwstub/tools | |
parent | 794169a18f644eea32de20b26646381137545e2d (diff) | |
download | rockbox-cd04a5f1aadc8e2ec4e787f5ba4cc8c38a579314.tar.gz rockbox-cd04a5f1aadc8e2ec4e787f5ba4cc8c38a579314.zip |
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
Diffstat (limited to 'utils/hwstub/tools')
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 12 | ||||
-rw-r--r-- | utils/hwstub/tools/init.lua | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index b2838ebed0..30d1ac3b3f 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp | |||
@@ -144,7 +144,7 @@ typedef void (*hw_writen_fn_t)(lua_State *state, soc_addr_t addr, soc_word_t val | |||
144 | soc_word_t hw_read8(lua_State *state, soc_addr_t addr) | 144 | soc_word_t hw_read8(lua_State *state, soc_addr_t addr) |
145 | { | 145 | { |
146 | uint8_t u; | 146 | uint8_t u; |
147 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 147 | if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
148 | luaL_error(state, "fail to read8 @ %p", addr); | 148 | luaL_error(state, "fail to read8 @ %p", addr); |
149 | return u; | 149 | return u; |
150 | } | 150 | } |
@@ -152,7 +152,7 @@ soc_word_t hw_read8(lua_State *state, soc_addr_t addr) | |||
152 | soc_word_t hw_read16(lua_State *state, soc_addr_t addr) | 152 | soc_word_t hw_read16(lua_State *state, soc_addr_t addr) |
153 | { | 153 | { |
154 | uint16_t u; | 154 | uint16_t u; |
155 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 155 | if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
156 | luaL_error(state, "fail to read16 @ %p", addr); | 156 | luaL_error(state, "fail to read16 @ %p", addr); |
157 | return u; | 157 | return u; |
158 | } | 158 | } |
@@ -160,7 +160,7 @@ soc_word_t hw_read16(lua_State *state, soc_addr_t addr) | |||
160 | soc_word_t hw_read32(lua_State *state, soc_addr_t addr) | 160 | soc_word_t hw_read32(lua_State *state, soc_addr_t addr) |
161 | { | 161 | { |
162 | uint32_t u; | 162 | uint32_t u; |
163 | if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) | 163 | if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) |
164 | luaL_error(state, "fail to read32 @ %p", addr); | 164 | luaL_error(state, "fail to read32 @ %p", addr); |
165 | return u; | 165 | return u; |
166 | } | 166 | } |
@@ -168,21 +168,21 @@ soc_word_t hw_read32(lua_State *state, soc_addr_t addr) | |||
168 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) | 168 | void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) |
169 | { | 169 | { |
170 | uint8_t u = val; | 170 | uint8_t u = val; |
171 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 171 | if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
172 | luaL_error(state, "fail to write8 @ %p", addr); | 172 | luaL_error(state, "fail to write8 @ %p", addr); |
173 | } | 173 | } |
174 | 174 | ||
175 | void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val) | 175 | void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val) |
176 | { | 176 | { |
177 | uint16_t u = val; | 177 | uint16_t u = val; |
178 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 178 | if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
179 | luaL_error(state, "fail to write16 @ %p", addr); | 179 | luaL_error(state, "fail to write16 @ %p", addr); |
180 | } | 180 | } |
181 | 181 | ||
182 | void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val) | 182 | void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val) |
183 | { | 183 | { |
184 | uint32_t u = val; | 184 | uint32_t u = val; |
185 | if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) | 185 | if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) |
186 | luaL_error(state, "fail to write32 @ %p", addr); | 186 | luaL_error(state, "fail to write32 @ %p", addr); |
187 | } | 187 | } |
188 | 188 | ||
diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua index 1fe0e0d734..aaca8b6c82 100644 --- a/utils/hwstub/tools/init.lua +++ b/utils/hwstub/tools/init.lua | |||
@@ -38,8 +38,8 @@ do | |||
38 | h = HELP:create_topic("DEV"); | 38 | h = HELP:create_topic("DEV"); |
39 | h:add("This variable redirects to hwstub.dev and provides direct access to the device."); | 39 | h:add("This variable redirects to hwstub.dev and provides direct access to the device."); |
40 | h:add("It contains some information about the device and the following methods."); | 40 | h:add("It contains some information about the device and the following methods."); |
41 | h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a"); | 41 | h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically"); |
42 | h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a"); | 42 | h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically"); |
43 | h:add("* print_log() prints the device log"); | 43 | h:add("* print_log() prints the device log"); |
44 | 44 | ||
45 | h = HELP:create_topic("HW"); | 45 | h = HELP:create_topic("HW"); |