qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
@ 2011-03-26 20:06 Stefan Weil
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed Stefan Weil
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Stefan Weil @ 2011-03-26 20:06 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Blue Swirl

A lot of calls don't operate on bytes but on words or on structured data.
So instead of a pointer to uint8_t, a void pointer is the better choice.

This allows removing many type casts.

(Some very early implementations of memcpy used char pointers
which were replaced by void pointers for the same reason).

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 cpu-common.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index ef4e8da..f44a2b0 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -68,12 +68,12 @@ void cpu_unregister_io_memory(int table_address);
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                             int len, int is_write);
 static inline void cpu_physical_memory_read(target_phys_addr_t addr,
-                                            uint8_t *buf, int len)
+                                            void *buf, int len)
 {
     cpu_physical_memory_rw(addr, buf, len, 0);
 }
 static inline void cpu_physical_memory_write(target_phys_addr_t addr,
-                                             const uint8_t *buf, int len)
+                                             const void *buf, int len)
 {
     cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
 }
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed
  2011-03-26 20:06 [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Stefan Weil
@ 2011-03-26 20:06 ` Stefan Weil
  2011-04-09 22:37   ` Aurelien Jarno
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 3/3] exec: Remove some type casts which are " Stefan Weil
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Stefan Weil @ 2011-03-26 20:06 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Blue Swirl

All other type casts in calls of cpu_physical_memory_write are
used by hardware emulations and will be fixed by separate patches.

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 exec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/exec.c b/exec.c
index 964ce31..d7afe30 100644
--- a/exec.c
+++ b/exec.c
@@ -4249,7 +4249,7 @@ void stw_phys(target_phys_addr_t addr, uint32_t val)
 void stq_phys(target_phys_addr_t addr, uint64_t val)
 {
     val = tswap64(val);
-    cpu_physical_memory_write(addr, (const uint8_t *)&val, 8);
+    cpu_physical_memory_write(addr, &val, 8);
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH 3/3] exec: Remove some type casts which are no longer needed
  2011-03-26 20:06 [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Stefan Weil
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed Stefan Weil
@ 2011-03-26 20:06 ` Stefan Weil
  2011-03-26 20:11   ` [Qemu-devel] [PATCH 3/3] monitor: " Stefan Weil
  2011-04-09 22:37 ` [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Aurelien Jarno
  2011-04-10 12:37 ` [Qemu-devel] [PATCH 1/3] " Artyom Tarasenko
  3 siblings, 1 reply; 11+ messages in thread
From: Stefan Weil @ 2011-03-26 20:06 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Blue Swirl

All other type casts in calls of cpu_physical_memory_read are
used by hardware emulations and will be fixed by separate patches.

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 monitor.c |   48 ++++++++++++++++++------------------------------
 1 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/monitor.c b/monitor.c
index 76a8207..7653e0b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2026,7 +2026,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
 
     pgd = env->cr[3] & ~0xfff;
     for(l1 = 0; l1 < 1024; l1++) {
-        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
+        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
         pde = le32_to_cpu(pde);
         if (pde & PG_PRESENT_MASK) {
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
@@ -2034,8 +2034,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
                 print_pte(mon, (l1 << 22), pde, ~((1 << 21) - 1));
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
-                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
-                                             (uint8_t *)&pte, 4);
+                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
                         print_pte(mon, (l1 << 22) + (l2 << 12),
@@ -2056,13 +2055,12 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
 
     pdp_addr = env->cr[3] & ~0x1f;
     for (l1 = 0; l1 < 4; l1++) {
-        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
+        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
         pdpe = le64_to_cpu(pdpe);
         if (pdpe & PG_PRESENT_MASK) {
             pd_addr = pdpe & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pd_addr + l2 * 8,
-                                         (uint8_t *)&pde, 8);
+                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
                 pde = le64_to_cpu(pde);
                 if (pde & PG_PRESENT_MASK) {
                     if (pde & PG_PSE_MASK) {
@@ -2072,8 +2070,7 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pt_addr + l3 * 8,
-                                                     (uint8_t *)&pte, 8);
+                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             if (pte & PG_PRESENT_MASK) {
                                 print_pte(mon, (l1 << 30 ) + (l2 << 21)
@@ -2098,13 +2095,12 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
 
     pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
+        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
-                                         8);
+                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 if (pdpe & PG_PRESENT_MASK) {
                     if (pdpe & PG_PSE_MASK) {
@@ -2114,8 +2110,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8,
-                                                     (uint8_t *)&pde, 8);
+                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
                             pde = le64_to_cpu(pde);
                             if (pde & PG_PRESENT_MASK) {
                                 if (pde & PG_PSE_MASK) {
@@ -2128,8 +2123,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
                                     for (l4 = 0; l4 < 512; l4++) {
                                         cpu_physical_memory_read(pt_addr
                                                                  + l4 * 8,
-                                                                 (uint8_t *)&pte,
-                                                                 8);
+                                                                 &pte, 8);
                                         pte = le64_to_cpu(pte);
                                         if (pte & PG_PRESENT_MASK) {
                                             print_pte(mon, (l1 << 39) +
@@ -2207,7 +2201,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for(l1 = 0; l1 < 1024; l1++) {
-        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
+        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
         pde = le32_to_cpu(pde);
         end = l1 << 22;
         if (pde & PG_PRESENT_MASK) {
@@ -2216,8 +2210,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
                 mem_print(mon, &start, &last_prot, end, prot);
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
-                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
-                                             (uint8_t *)&pte, 4);
+                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     end = (l1 << 22) + (l2 << 12);
                     if (pte & PG_PRESENT_MASK) {
@@ -2246,14 +2239,13 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for (l1 = 0; l1 < 4; l1++) {
-        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
+        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
         pdpe = le64_to_cpu(pdpe);
         end = l1 << 30;
         if (pdpe & PG_PRESENT_MASK) {
             pd_addr = pdpe & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pd_addr + l2 * 8,
-                                         (uint8_t *)&pde, 8);
+                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
                 pde = le64_to_cpu(pde);
                 end = (l1 << 30) + (l2 << 21);
                 if (pde & PG_PRESENT_MASK) {
@@ -2264,8 +2256,7 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pt_addr + l3 * 8,
-                                                     (uint8_t *)&pte, 8);
+                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             end = (l1 << 30) + (l2 << 21) + (l3 << 12);
                             if (pte & PG_PRESENT_MASK) {
@@ -2302,14 +2293,13 @@ static void mem_info_64(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
+        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         end = l1 << 39;
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
-                                         8);
+                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 end = (l1 << 39) + (l2 << 30);
                 if (pdpe & PG_PRESENT_MASK) {
@@ -2320,8 +2310,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8,
-                                                     (uint8_t *)&pde, 8);
+                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
                             pde = le64_to_cpu(pde);
                             end = (l1 << 39) + (l2 << 30) + (l3 << 21);
                             if (pde & PG_PRESENT_MASK) {
@@ -2334,8 +2323,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
                                     for (l4 = 0; l4 < 512; l4++) {
                                         cpu_physical_memory_read(pt_addr
                                                                  + l4 * 8,
-                                                                 (uint8_t *)&pte,
-                                                                 8);
+                                                                 &pte, 8);
                                         pte = le64_to_cpu(pte);
                                         end = (l1 << 39) + (l2 << 30) +
                                             (l3 << 21) + (l4 << 12);
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH 3/3] monitor: Remove some type casts which are no longer needed
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 3/3] exec: Remove some type casts which are " Stefan Weil
@ 2011-03-26 20:11   ` Stefan Weil
  2011-04-09 22:37     ` Aurelien Jarno
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Weil @ 2011-03-26 20:11 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Blue Swirl

All other type casts in calls of cpu_physical_memory_read are
used by hardware emulations and will be fixed by separate patches.

v2: Fixed subject line

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 monitor.c |   48 ++++++++++++++++++------------------------------
 1 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/monitor.c b/monitor.c
index 76a8207..7653e0b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2026,7 +2026,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
 
     pgd = env->cr[3] & ~0xfff;
     for(l1 = 0; l1 < 1024; l1++) {
-        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
+        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
         pde = le32_to_cpu(pde);
         if (pde & PG_PRESENT_MASK) {
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
@@ -2034,8 +2034,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
                 print_pte(mon, (l1 << 22), pde, ~((1 << 21) - 1));
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
-                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
-                                             (uint8_t *)&pte, 4);
+                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     if (pte & PG_PRESENT_MASK) {
                         print_pte(mon, (l1 << 22) + (l2 << 12),
@@ -2056,13 +2055,12 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
 
     pdp_addr = env->cr[3] & ~0x1f;
     for (l1 = 0; l1 < 4; l1++) {
-        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
+        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
         pdpe = le64_to_cpu(pdpe);
         if (pdpe & PG_PRESENT_MASK) {
             pd_addr = pdpe & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pd_addr + l2 * 8,
-                                         (uint8_t *)&pde, 8);
+                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
                 pde = le64_to_cpu(pde);
                 if (pde & PG_PRESENT_MASK) {
                     if (pde & PG_PSE_MASK) {
@@ -2072,8 +2070,7 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pt_addr + l3 * 8,
-                                                     (uint8_t *)&pte, 8);
+                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             if (pte & PG_PRESENT_MASK) {
                                 print_pte(mon, (l1 << 30 ) + (l2 << 21)
@@ -2098,13 +2095,12 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
 
     pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
+        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
-                                         8);
+                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 if (pdpe & PG_PRESENT_MASK) {
                     if (pdpe & PG_PSE_MASK) {
@@ -2114,8 +2110,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8,
-                                                     (uint8_t *)&pde, 8);
+                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
                             pde = le64_to_cpu(pde);
                             if (pde & PG_PRESENT_MASK) {
                                 if (pde & PG_PSE_MASK) {
@@ -2128,8 +2123,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
                                     for (l4 = 0; l4 < 512; l4++) {
                                         cpu_physical_memory_read(pt_addr
                                                                  + l4 * 8,
-                                                                 (uint8_t *)&pte,
-                                                                 8);
+                                                                 &pte, 8);
                                         pte = le64_to_cpu(pte);
                                         if (pte & PG_PRESENT_MASK) {
                                             print_pte(mon, (l1 << 39) +
@@ -2207,7 +2201,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for(l1 = 0; l1 < 1024; l1++) {
-        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
+        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
         pde = le32_to_cpu(pde);
         end = l1 << 22;
         if (pde & PG_PRESENT_MASK) {
@@ -2216,8 +2210,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
                 mem_print(mon, &start, &last_prot, end, prot);
             } else {
                 for(l2 = 0; l2 < 1024; l2++) {
-                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
-                                             (uint8_t *)&pte, 4);
+                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
                     pte = le32_to_cpu(pte);
                     end = (l1 << 22) + (l2 << 12);
                     if (pte & PG_PRESENT_MASK) {
@@ -2246,14 +2239,13 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for (l1 = 0; l1 < 4; l1++) {
-        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
+        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
         pdpe = le64_to_cpu(pdpe);
         end = l1 << 30;
         if (pdpe & PG_PRESENT_MASK) {
             pd_addr = pdpe & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pd_addr + l2 * 8,
-                                         (uint8_t *)&pde, 8);
+                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
                 pde = le64_to_cpu(pde);
                 end = (l1 << 30) + (l2 << 21);
                 if (pde & PG_PRESENT_MASK) {
@@ -2264,8 +2256,7 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
                     } else {
                         pt_addr = pde & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pt_addr + l3 * 8,
-                                                     (uint8_t *)&pte, 8);
+                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
                             pte = le64_to_cpu(pte);
                             end = (l1 << 30) + (l2 << 21) + (l3 << 12);
                             if (pte & PG_PRESENT_MASK) {
@@ -2302,14 +2293,13 @@ static void mem_info_64(Monitor *mon, CPUState *env)
     last_prot = 0;
     start = -1;
     for (l1 = 0; l1 < 512; l1++) {
-        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
+        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
         pml4e = le64_to_cpu(pml4e);
         end = l1 << 39;
         if (pml4e & PG_PRESENT_MASK) {
             pdp_addr = pml4e & 0x3fffffffff000ULL;
             for (l2 = 0; l2 < 512; l2++) {
-                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
-                                         8);
+                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
                 pdpe = le64_to_cpu(pdpe);
                 end = (l1 << 39) + (l2 << 30);
                 if (pdpe & PG_PRESENT_MASK) {
@@ -2320,8 +2310,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
                     } else {
                         pd_addr = pdpe & 0x3fffffffff000ULL;
                         for (l3 = 0; l3 < 512; l3++) {
-                            cpu_physical_memory_read(pd_addr + l3 * 8,
-                                                     (uint8_t *)&pde, 8);
+                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
                             pde = le64_to_cpu(pde);
                             end = (l1 << 39) + (l2 << 30) + (l3 << 21);
                             if (pde & PG_PRESENT_MASK) {
@@ -2334,8 +2323,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
                                     for (l4 = 0; l4 < 512; l4++) {
                                         cpu_physical_memory_read(pt_addr
                                                                  + l4 * 8,
-                                                                 (uint8_t *)&pte,
-                                                                 8);
+                                                                 &pte, 8);
                                         pte = le64_to_cpu(pte);
                                         end = (l1 << 39) + (l2 << 30) +
                                             (l3 << 21) + (l4 << 12);
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
  2011-03-26 20:06 [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Stefan Weil
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed Stefan Weil
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 3/3] exec: Remove some type casts which are " Stefan Weil
@ 2011-04-09 22:37 ` Aurelien Jarno
  2011-04-10  6:16   ` Stefan Weil
  2011-04-10 12:37 ` [Qemu-devel] [PATCH 1/3] " Artyom Tarasenko
  3 siblings, 1 reply; 11+ messages in thread
From: Aurelien Jarno @ 2011-04-09 22:37 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers

On Sat, Mar 26, 2011 at 09:06:55PM +0100, Stefan Weil wrote:
> A lot of calls don't operate on bytes but on words or on structured data.
> So instead of a pointer to uint8_t, a void pointer is the better choice.
> 
> This allows removing many type casts.
> 
> (Some very early implementations of memcpy used char pointers
> which were replaced by void pointers for the same reason).
> 
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  cpu-common.h |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cpu-common.h b/cpu-common.h
> index ef4e8da..f44a2b0 100644
> --- a/cpu-common.h
> +++ b/cpu-common.h
> @@ -68,12 +68,12 @@ void cpu_unregister_io_memory(int table_address);
>  void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
>                              int len, int is_write);
>  static inline void cpu_physical_memory_read(target_phys_addr_t addr,
> -                                            uint8_t *buf, int len)
> +                                            void *buf, int len)
>  {
>      cpu_physical_memory_rw(addr, buf, len, 0);
>  }
>  static inline void cpu_physical_memory_write(target_phys_addr_t addr,
> -                                             const uint8_t *buf, int len)
> +                                             const void *buf, int len)
>  {
>      cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);

We might want to also do the change here, that is replacing (uint8_t *)
to (void *). Also instead of doing half the job, it would be nice to do
the same changes on cpu_physical_memory_rw().

>  }
 

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed
  2011-03-26 20:06 ` [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed Stefan Weil
@ 2011-04-09 22:37   ` Aurelien Jarno
  0 siblings, 0 replies; 11+ messages in thread
From: Aurelien Jarno @ 2011-04-09 22:37 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers

On Sat, Mar 26, 2011 at 09:06:56PM +0100, Stefan Weil wrote:
> All other type casts in calls of cpu_physical_memory_write are
> used by hardware emulations and will be fixed by separate patches.
> 
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  exec.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 964ce31..d7afe30 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -4249,7 +4249,7 @@ void stw_phys(target_phys_addr_t addr, uint32_t val)
>  void stq_phys(target_phys_addr_t addr, uint64_t val)
>  {
>      val = tswap64(val);
> -    cpu_physical_memory_write(addr, (const uint8_t *)&val, 8);
> +    cpu_physical_memory_write(addr, &val, 8);
>  }
>  
>  /* virtual memory access for debug (includes writing to ROM) */
> -- 
> 1.7.2.5
> 

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] monitor: Remove some type casts which are no longer needed
  2011-03-26 20:11   ` [Qemu-devel] [PATCH 3/3] monitor: " Stefan Weil
@ 2011-04-09 22:37     ` Aurelien Jarno
  0 siblings, 0 replies; 11+ messages in thread
From: Aurelien Jarno @ 2011-04-09 22:37 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers

On Sat, Mar 26, 2011 at 09:11:05PM +0100, Stefan Weil wrote:
> All other type casts in calls of cpu_physical_memory_read are
> used by hardware emulations and will be fixed by separate patches.
> 
> v2: Fixed subject line
> 
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  monitor.c |   48 ++++++++++++++++++------------------------------
>  1 files changed, 18 insertions(+), 30 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 76a8207..7653e0b 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2026,7 +2026,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
>  
>      pgd = env->cr[3] & ~0xfff;
>      for(l1 = 0; l1 < 1024; l1++) {
> -        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
> +        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
>          pde = le32_to_cpu(pde);
>          if (pde & PG_PRESENT_MASK) {
>              if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
> @@ -2034,8 +2034,7 @@ static void tlb_info_32(Monitor *mon, CPUState *env)
>                  print_pte(mon, (l1 << 22), pde, ~((1 << 21) - 1));
>              } else {
>                  for(l2 = 0; l2 < 1024; l2++) {
> -                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
> -                                             (uint8_t *)&pte, 4);
> +                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
>                      pte = le32_to_cpu(pte);
>                      if (pte & PG_PRESENT_MASK) {
>                          print_pte(mon, (l1 << 22) + (l2 << 12),
> @@ -2056,13 +2055,12 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
>  
>      pdp_addr = env->cr[3] & ~0x1f;
>      for (l1 = 0; l1 < 4; l1++) {
> -        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
> +        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
>          pdpe = le64_to_cpu(pdpe);
>          if (pdpe & PG_PRESENT_MASK) {
>              pd_addr = pdpe & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pd_addr + l2 * 8,
> -                                         (uint8_t *)&pde, 8);
> +                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
>                  pde = le64_to_cpu(pde);
>                  if (pde & PG_PRESENT_MASK) {
>                      if (pde & PG_PSE_MASK) {
> @@ -2072,8 +2070,7 @@ static void tlb_info_pae32(Monitor *mon, CPUState *env)
>                      } else {
>                          pt_addr = pde & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pt_addr + l3 * 8,
> -                                                     (uint8_t *)&pte, 8);
> +                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
>                              pte = le64_to_cpu(pte);
>                              if (pte & PG_PRESENT_MASK) {
>                                  print_pte(mon, (l1 << 30 ) + (l2 << 21)
> @@ -2098,13 +2095,12 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
>  
>      pml4_addr = env->cr[3] & 0x3fffffffff000ULL;
>      for (l1 = 0; l1 < 512; l1++) {
> -        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
> +        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
>          pml4e = le64_to_cpu(pml4e);
>          if (pml4e & PG_PRESENT_MASK) {
>              pdp_addr = pml4e & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
> -                                         8);
> +                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
>                  pdpe = le64_to_cpu(pdpe);
>                  if (pdpe & PG_PRESENT_MASK) {
>                      if (pdpe & PG_PSE_MASK) {
> @@ -2114,8 +2110,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
>                      } else {
>                          pd_addr = pdpe & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pd_addr + l3 * 8,
> -                                                     (uint8_t *)&pde, 8);
> +                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
>                              pde = le64_to_cpu(pde);
>                              if (pde & PG_PRESENT_MASK) {
>                                  if (pde & PG_PSE_MASK) {
> @@ -2128,8 +2123,7 @@ static void tlb_info_64(Monitor *mon, CPUState *env)
>                                      for (l4 = 0; l4 < 512; l4++) {
>                                          cpu_physical_memory_read(pt_addr
>                                                                   + l4 * 8,
> -                                                                 (uint8_t *)&pte,
> -                                                                 8);
> +                                                                 &pte, 8);
>                                          pte = le64_to_cpu(pte);
>                                          if (pte & PG_PRESENT_MASK) {
>                                              print_pte(mon, (l1 << 39) +
> @@ -2207,7 +2201,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
>      last_prot = 0;
>      start = -1;
>      for(l1 = 0; l1 < 1024; l1++) {
> -        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
> +        cpu_physical_memory_read(pgd + l1 * 4, &pde, 4);
>          pde = le32_to_cpu(pde);
>          end = l1 << 22;
>          if (pde & PG_PRESENT_MASK) {
> @@ -2216,8 +2210,7 @@ static void mem_info_32(Monitor *mon, CPUState *env)
>                  mem_print(mon, &start, &last_prot, end, prot);
>              } else {
>                  for(l2 = 0; l2 < 1024; l2++) {
> -                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
> -                                             (uint8_t *)&pte, 4);
> +                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte, 4);
>                      pte = le32_to_cpu(pte);
>                      end = (l1 << 22) + (l2 << 12);
>                      if (pte & PG_PRESENT_MASK) {
> @@ -2246,14 +2239,13 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
>      last_prot = 0;
>      start = -1;
>      for (l1 = 0; l1 < 4; l1++) {
> -        cpu_physical_memory_read(pdp_addr + l1 * 8, (uint8_t *)&pdpe, 8);
> +        cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8);
>          pdpe = le64_to_cpu(pdpe);
>          end = l1 << 30;
>          if (pdpe & PG_PRESENT_MASK) {
>              pd_addr = pdpe & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pd_addr + l2 * 8,
> -                                         (uint8_t *)&pde, 8);
> +                cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8);
>                  pde = le64_to_cpu(pde);
>                  end = (l1 << 30) + (l2 << 21);
>                  if (pde & PG_PRESENT_MASK) {
> @@ -2264,8 +2256,7 @@ static void mem_info_pae32(Monitor *mon, CPUState *env)
>                      } else {
>                          pt_addr = pde & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pt_addr + l3 * 8,
> -                                                     (uint8_t *)&pte, 8);
> +                            cpu_physical_memory_read(pt_addr + l3 * 8, &pte, 8);
>                              pte = le64_to_cpu(pte);
>                              end = (l1 << 30) + (l2 << 21) + (l3 << 12);
>                              if (pte & PG_PRESENT_MASK) {
> @@ -2302,14 +2293,13 @@ static void mem_info_64(Monitor *mon, CPUState *env)
>      last_prot = 0;
>      start = -1;
>      for (l1 = 0; l1 < 512; l1++) {
> -        cpu_physical_memory_read(pml4_addr + l1 * 8, (uint8_t *)&pml4e, 8);
> +        cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8);
>          pml4e = le64_to_cpu(pml4e);
>          end = l1 << 39;
>          if (pml4e & PG_PRESENT_MASK) {
>              pdp_addr = pml4e & 0x3fffffffff000ULL;
>              for (l2 = 0; l2 < 512; l2++) {
> -                cpu_physical_memory_read(pdp_addr + l2 * 8, (uint8_t *)&pdpe,
> -                                         8);
> +                cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8);
>                  pdpe = le64_to_cpu(pdpe);
>                  end = (l1 << 39) + (l2 << 30);
>                  if (pdpe & PG_PRESENT_MASK) {
> @@ -2320,8 +2310,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
>                      } else {
>                          pd_addr = pdpe & 0x3fffffffff000ULL;
>                          for (l3 = 0; l3 < 512; l3++) {
> -                            cpu_physical_memory_read(pd_addr + l3 * 8,
> -                                                     (uint8_t *)&pde, 8);
> +                            cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8);
>                              pde = le64_to_cpu(pde);
>                              end = (l1 << 39) + (l2 << 30) + (l3 << 21);
>                              if (pde & PG_PRESENT_MASK) {
> @@ -2334,8 +2323,7 @@ static void mem_info_64(Monitor *mon, CPUState *env)
>                                      for (l4 = 0; l4 < 512; l4++) {
>                                          cpu_physical_memory_read(pt_addr
>                                                                   + l4 * 8,
> -                                                                 (uint8_t *)&pte,
> -                                                                 8);
> +                                                                 &pte, 8);
>                                          pte = le64_to_cpu(pte);
>                                          end = (l1 << 39) + (l2 << 30) +
>                                              (l3 << 21) + (l4 << 12);
> -- 
> 1.7.2.5
> 

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
  2011-04-09 22:37 ` [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Aurelien Jarno
@ 2011-04-10  6:16   ` Stefan Weil
  2011-04-10 12:53     ` Aurelien Jarno
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Weil @ 2011-04-10  6:16 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: Blue Swirl, QEMU Developers

Am 10.04.2011 00:37, schrieb Aurelien Jarno:
> On Sat, Mar 26, 2011 at 09:06:55PM +0100, Stefan Weil wrote:
>> A lot of calls don't operate on bytes but on words or on structured data.
>> So instead of a pointer to uint8_t, a void pointer is the better choice.
>>
>> This allows removing many type casts.
>>
>> (Some very early implementations of memcpy used char pointers
>> which were replaced by void pointers for the same reason).
>>
>> Cc: Blue Swirl <blauwirbel@gmail.com>
>> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
>> ---
>> cpu-common.h | 4 ++--
>> 1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/cpu-common.h b/cpu-common.h
>> index ef4e8da..f44a2b0 100644
>> --- a/cpu-common.h
>> +++ b/cpu-common.h
>> @@ -68,12 +68,12 @@ void cpu_unregister_io_memory(int table_address);
>> void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
>> int len, int is_write);
>> static inline void cpu_physical_memory_read(target_phys_addr_t addr,
>> - uint8_t *buf, int len)
>> + void *buf, int len)
>> {
>> cpu_physical_memory_rw(addr, buf, len, 0);
>> }
>> static inline void cpu_physical_memory_write(target_phys_addr_t addr,
>> - const uint8_t *buf, int len)
>> + const void *buf, int len)
>> {
>> cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
>
> We might want to also do the change here, that is replacing (uint8_t *)
> to (void *). Also instead of doing half the job, it would be nice to do
> the same changes on cpu_physical_memory_rw().

Hello Aurelien,

this type cast removes the const attribute from buf, so it is needed.

And I did not change cpu_physical_memory_rw (and some more
functions) because the gain is small: there are only 10 type casts
used with cpu_physical_memory_rw, and at least some of them
are needed because of const attributes.

I don't like type casts which remove the const attribute, so there
should be additional changes. But I don't think that it would be a
good idea to mix them with this patch.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
  2011-03-26 20:06 [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Stefan Weil
                   ` (2 preceding siblings ...)
  2011-04-09 22:37 ` [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Aurelien Jarno
@ 2011-04-10 12:37 ` Artyom Tarasenko
  3 siblings, 0 replies; 11+ messages in thread
From: Artyom Tarasenko @ 2011-04-10 12:37 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers

On Sat, Mar 26, 2011 at 9:06 PM, Stefan Weil <weil@mail.berlios.de> wrote:
> A lot of calls don't operate on bytes but on words or on structured data.
> So instead of a pointer to uint8_t, a void pointer is the better choice.

Wouldn't it make the endianness conversions more complex? uint8_t[]
has a very obvious byte order,
structured data doesn't.

> This allows removing many type casts.
>
> (Some very early implementations of memcpy used char pointers
> which were replaced by void pointers for the same reason).
>
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  cpu-common.h |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/cpu-common.h b/cpu-common.h
> index ef4e8da..f44a2b0 100644
> --- a/cpu-common.h
> +++ b/cpu-common.h
> @@ -68,12 +68,12 @@ void cpu_unregister_io_memory(int table_address);
>  void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
>                             int len, int is_write);
>  static inline void cpu_physical_memory_read(target_phys_addr_t addr,
> -                                            uint8_t *buf, int len)
> +                                            void *buf, int len)
>  {
>     cpu_physical_memory_rw(addr, buf, len, 0);
>  }
>  static inline void cpu_physical_memory_write(target_phys_addr_t addr,
> -                                             const uint8_t *buf, int len)
> +                                             const void *buf, int len)
>  {
>     cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
>  }
> --
> 1.7.2.5
>
>
>



-- 
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
  2011-04-10  6:16   ` Stefan Weil
@ 2011-04-10 12:53     ` Aurelien Jarno
  2011-04-10 15:28       ` [Qemu-devel] [PATCH 1/3 v2] " Stefan Weil
  0 siblings, 1 reply; 11+ messages in thread
From: Aurelien Jarno @ 2011-04-10 12:53 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers

On Sun, Apr 10, 2011 at 08:16:05AM +0200, Stefan Weil wrote:
> Am 10.04.2011 00:37, schrieb Aurelien Jarno:
> >On Sat, Mar 26, 2011 at 09:06:55PM +0100, Stefan Weil wrote:
> >>A lot of calls don't operate on bytes but on words or on structured data.
> >>So instead of a pointer to uint8_t, a void pointer is the better choice.
> >>
> >>This allows removing many type casts.
> >>
> >>(Some very early implementations of memcpy used char pointers
> >>which were replaced by void pointers for the same reason).
> >>
> >>Cc: Blue Swirl <blauwirbel@gmail.com>
> >>Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> >>---
> >>cpu-common.h | 4 ++--
> >>1 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >>diff --git a/cpu-common.h b/cpu-common.h
> >>index ef4e8da..f44a2b0 100644
> >>--- a/cpu-common.h
> >>+++ b/cpu-common.h
> >>@@ -68,12 +68,12 @@ void cpu_unregister_io_memory(int table_address);
> >>void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
> >>int len, int is_write);
> >>static inline void cpu_physical_memory_read(target_phys_addr_t addr,
> >>- uint8_t *buf, int len)
> >>+ void *buf, int len)
> >>{
> >>cpu_physical_memory_rw(addr, buf, len, 0);
> >>}
> >>static inline void cpu_physical_memory_write(target_phys_addr_t addr,
> >>- const uint8_t *buf, int len)
> >>+ const void *buf, int len)
> >>{
> >>cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
> >
> >We might want to also do the change here, that is replacing (uint8_t *)
> >to (void *). Also instead of doing half the job, it would be nice to do
> >the same changes on cpu_physical_memory_rw().
> 
> Hello Aurelien,
> 
> this type cast removes the const attribute from buf, so it is needed.

Yes, but it can be changed to (void *) as I suggested. After your
changes, what we want is to remove the const part, not change it into an
uint8_t *, so I think the change improves readability.

> And I did not change cpu_physical_memory_rw (and some more
> functions) because the gain is small: there are only 10 type casts
> used with cpu_physical_memory_rw, and at least some of them
> are needed because of const attributes.
> 
> I don't like type casts which remove the const attribute, so there
> should be additional changes. But I don't think that it would be a
> good idea to mix them with this patch.
> 

Ok, that part can go into another patch. Anyway most of the use cases
seems to be an abuse of cpu_physical_memory_rw(). The read or write
version should be used instead of passing a constant as the last
argument.

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH 1/3 v2] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write
  2011-04-10 12:53     ` Aurelien Jarno
@ 2011-04-10 15:28       ` Stefan Weil
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Weil @ 2011-04-10 15:28 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Aurelien Jarno

A lot of calls don't operate on bytes but on words or on structured data.
So instead of a pointer to uint8_t, a void pointer is the better choice.

This allows removing many type casts.

(Some very early implementations of memcpy used char pointers
which were replaced by void pointers for the same reason).

v2:
Change a type cast from (uint8_t *) to (void *) to
improve readability as suggested by Aurelien Jarno.
This type cast is needed to remove the const attribute,
not to change the data type to (uint8_t *).

Cc: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 cpu-common.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index ef4e8da..96c02ae 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -68,14 +68,14 @@ void cpu_unregister_io_memory(int table_address);
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                             int len, int is_write);
 static inline void cpu_physical_memory_read(target_phys_addr_t addr,
-                                            uint8_t *buf, int len)
+                                            void *buf, int len)
 {
     cpu_physical_memory_rw(addr, buf, len, 0);
 }
 static inline void cpu_physical_memory_write(target_phys_addr_t addr,
-                                             const uint8_t *buf, int len)
+                                             const void *buf, int len)
 {
-    cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
+    cpu_physical_memory_rw(addr, (void *)buf, len, 1);
 }
 void *cpu_physical_memory_map(target_phys_addr_t addr,
                               target_phys_addr_t *plen,
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-04-10 15:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-26 20:06 [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Stefan Weil
2011-03-26 20:06 ` [Qemu-devel] [PATCH 2/3] exec: Remove a type cast which is no longer needed Stefan Weil
2011-04-09 22:37   ` Aurelien Jarno
2011-03-26 20:06 ` [Qemu-devel] [PATCH 3/3] exec: Remove some type casts which are " Stefan Weil
2011-03-26 20:11   ` [Qemu-devel] [PATCH 3/3] monitor: " Stefan Weil
2011-04-09 22:37     ` Aurelien Jarno
2011-04-09 22:37 ` [Qemu-devel] [PATCH 1/3] cpu-common: Modify cpu_physical_memory_read and cpu_physical_memory_write Aurelien Jarno
2011-04-10  6:16   ` Stefan Weil
2011-04-10 12:53     ` Aurelien Jarno
2011-04-10 15:28       ` [Qemu-devel] [PATCH 1/3 v2] " Stefan Weil
2011-04-10 12:37 ` [Qemu-devel] [PATCH 1/3] " Artyom Tarasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).