Patchwork Fill in unassigned mem read/write callbacks.

login
register
mail settings
Submitter Richard Henderson
Date May 7, 2010, 4:52 p.m.
Message ID <1273251171-25338-1-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/51936/
State New
Headers show

Comments

Richard Henderson - May 7, 2010, 4:52 p.m.
Implement the "functions may be omitted with NULL pointer"
interface mentioned in the function block comment by transforming
NULL entries in the read/write arrays into calls to the
unassigned_mem family of functions.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 exec.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
Blue Swirl - May 7, 2010, 5:02 p.m.
Thanks, applied.

On 5/7/10, Richard Henderson <rth@twiddle.net> wrote:
> Implement the "functions may be omitted with NULL pointer"
>  interface mentioned in the function block comment by transforming
>  NULL entries in the read/write arrays into calls to the
>  unassigned_mem family of functions.
>
>  Signed-off-by: Richard Henderson <rth@twiddle.net>
>  ---
>   exec.c |   12 ++++++++++--
>   1 files changed, 10 insertions(+), 2 deletions(-)
>
>  diff --git a/exec.c b/exec.c
>  index e980788..3416aed 100644
>  --- a/exec.c
>  +++ b/exec.c
>  @@ -3262,6 +3262,8 @@ static int cpu_register_io_memory_fixed(int io_index,
>                                          CPUWriteMemoryFunc * const *mem_write,
>                                          void *opaque)
>   {
>  +    int i;
>  +
>      if (io_index <= 0) {
>          io_index = get_free_io_mem_idx();
>          if (io_index == -1)
>  @@ -3272,8 +3274,14 @@ static int cpu_register_io_memory_fixed(int io_index,
>              return -1;
>      }
>
>  -    memcpy(io_mem_read[io_index], mem_read, 3 * sizeof(CPUReadMemoryFunc*));
>  -    memcpy(io_mem_write[io_index], mem_write, 3 * sizeof(CPUWriteMemoryFunc*));
>  +    for (i = 0; i < 3; ++i) {
>  +        io_mem_read[io_index][i]
>  +            = (mem_read[i] ? mem_read[i] : unassigned_mem_read[i]);
>  +    }
>  +    for (i = 0; i < 3; ++i) {
>  +        io_mem_write[io_index][i]
>  +            = (mem_write[i] ? mem_write[i] : unassigned_mem_write[i]);
>  +    }
>      io_mem_opaque[io_index] = opaque;
>
>      return (io_index << IO_MEM_SHIFT);
>
> --
>  1.6.6.1
>
>

Patch

diff --git a/exec.c b/exec.c
index e980788..3416aed 100644
--- a/exec.c
+++ b/exec.c
@@ -3262,6 +3262,8 @@  static int cpu_register_io_memory_fixed(int io_index,
                                         CPUWriteMemoryFunc * const *mem_write,
                                         void *opaque)
 {
+    int i;
+
     if (io_index <= 0) {
         io_index = get_free_io_mem_idx();
         if (io_index == -1)
@@ -3272,8 +3274,14 @@  static int cpu_register_io_memory_fixed(int io_index,
             return -1;
     }
 
-    memcpy(io_mem_read[io_index], mem_read, 3 * sizeof(CPUReadMemoryFunc*));
-    memcpy(io_mem_write[io_index], mem_write, 3 * sizeof(CPUWriteMemoryFunc*));
+    for (i = 0; i < 3; ++i) {
+        io_mem_read[io_index][i]
+            = (mem_read[i] ? mem_read[i] : unassigned_mem_read[i]);
+    }
+    for (i = 0; i < 3; ++i) {
+        io_mem_write[io_index][i]
+            = (mem_write[i] ? mem_write[i] : unassigned_mem_write[i]);
+    }
     io_mem_opaque[io_index] = opaque;
 
     return (io_index << IO_MEM_SHIFT);