Use target_words_bigendian() for generic-loader
v2 cover Use target_words_bigendian() for generic-loader
Provide a proper prototype for target_words_bigendian(), and use this function in the generic-loader to be able to move it to common-obj.
v2:
- Split up the single patch into two
- Add a proper comment in front of the prototype in the header
Thomas Huth (2):
cpu: Provide a proper prototype for target_words_bigendian() in a
header
hw/core/generic-loader: Compile only once, not for each target
exec.c | 5 ----- hw/core/Makefile.objs | 2 +- hw/core/generic-loader.c | 6 +----- hw/virtio/virtio.c | 1 - include/qom/cpu.h | 11 +++++++++++ qom/cpu.c | 1 - 6 files changed, 13 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/2 cpu: Provide a proper prototype for target_words_bigendian() in a header
We've got three places already that provide a prototype for this function in a .c file - that's ugly. Let's provide a proper prototype in a header instead, with a proper description why this function should not be used in most cases.
---
NB: I've tried to replace the "utterly broken" comment with something better, as suggested by Laszlo... not sure whether I've really got the message right here, so feel free to provide some better wording if you like!
exec.c | 5 ----- hw/virtio/virtio.c | 1 - include/qom/cpu.h | 11 +++++++++++ qom/cpu.c | 1 - 4 files changed, 11 insertions(+), 7 deletions(-)
exec.c +0 -5
@@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void) }#endif -/* -* A helper function for the _utterly broken_ virtio device model to find out if -* it's running on a big endian machine. Don't do this at home kids! -*/ -bool target_words_bigendian (void );bool target_words_bigendian (void ) {#if defined(TARGET_WORDS_BIGENDIAN )
hw/virtio/virtio.c +0 -1
@@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)return 0 ; } -bool target_words_bigendian (void );static enum virtio_device_endian virtio_default_endian (void ) {if (target_words_bigendian ()) {
include/qom/cpu.h +11 -0
@@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);void cpu_exec_realizefn (CPUState *cpu,Error **errp);void cpu_exec_unrealizefn (CPUState *cpu); +/** +* target_words_bigendian: +* Returns true if the (default) endianness of the target is big endian, +* false otherwise. Note that in target-specifc code, you can use +* TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common +* code should normally never need to know about the endianness of the +* target, so please do *not* use this function unless you know very well +* what you are doing! +*/ +bool target_words_bigendian (void ); +#ifdef NEED_CPU_H #ifdef CONFIG_SOFTMMU
qom/cpu.c +0 -1
@@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)return true; } -bool target_words_bigendian (void );static bool cpu_common_virtio_is_big_endian (CPUState *cpu) {return target_words_bigendian ();
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 1/2] cpu: Provide a proper prototype for target_words_bigendian() in a header
Quoted 53 lines · Thomas Huth
We've got three places already that provide a prototype for this function in a .c file - that's ugly. Let's provide a proper prototype in a header instead, with a proper description why this function should not be used in most cases.
Signed-off-by Thomas Huth <[email protected]>---
NB: I've tried to replace the "utterly broken" comment with something better, as suggested by Laszlo... not sure whether I've really got the message right here, so feel free to provide some better wording if you like!exec.c | 5 ----- hw/virtio/virtio.c | 1 - include/qom/cpu.h | 11 +++++++++++ qom/cpu.c | 1 - 4 files changed, 11 insertions(+), 7 deletions(-)exec.c +0
-5@@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void) }#endif -/* -* A helper function for the _utterly broken_ virtio device model to find out if -* it's running on a big endian machine. Don't do this at home kids! -*/ -bool target_words_bigendian (void );bool target_words_bigendian (void ) {#if defined(TARGET_WORDS_BIGENDIAN )hw/virtio/virtio.c +0
-1@@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)return 0 ; } -bool target_words_bigendian (void );static enum virtio_device_endian virtio_default_endian (void ) {if (target_words_bigendian ()) {include/qom/cpu.h +0
-0@@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);void cpu_exec_realizefn (CPUState *cpu,Error **errp);void cpu_exec_unrealizefn (CPUState *cpu);
include/qom/cpu.h void cpu_exec_initfn(CPUState *cpu); · line 1096
Quoted 10 lines
include/qom/cpu.h +9
-0+/** +* target_words_bigendian: +* Returns true if the (default) endianness of the target is big endian, +* false otherwise. Note that in target-specifc code, you can use +* TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common +* code should normally never need to know about the endianness of the +* target, so please do *not* use this function unless you know very well +* what you are doing! +*/
Thanks for this cleanup!
Quoted 18 lines
include/qom/cpu.h +2
-0+bool target_words_bigendian (void ); +#ifdef NEED_CPU_H #ifdef CONFIG_SOFTMMU qom/cpu.c +0
-1@@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)return true; } -bool target_words_bigendian (void );static bool cpu_common_virtio_is_big_endian (CPUState *cpu) {return target_words_bigendian ();
Re: [Qemu-devel] [PATCH v2 1/2] cpu: Provide a proper prototype for target_words_bigendian() in a header
In reply to Thomas HuthQuoted 74 lines · Thomas Huth
We've got three places already that provide a prototype for this function in a .c file - that's ugly. Let's provide a proper prototype in a header instead, with a proper description why this function should not be used in most cases.
Signed-off-by Thomas Huth <[email protected]>---
NB: I've tried to replace the "utterly broken" comment with something better, as suggested by Laszlo... not sure whether I've really got the message right here, so feel free to provide some better wording if you like!exec.c | 5 ----- hw/virtio/virtio.c | 1 - include/qom/cpu.h | 11 +++++++++++ qom/cpu.c | 1 - 4 files changed, 11 insertions(+), 7 deletions(-)exec.c +0
-5@@ -3906,11 +3906,6 @@ int qemu_target_page_bits_min(void) }#endif -/* -* A helper function for the _utterly broken_ virtio device model to find out if -* it's running on a big endian machine. Don't do this at home kids! -*/ -bool target_words_bigendian (void );bool target_words_bigendian (void ) {#if defined(TARGET_WORDS_BIGENDIAN )hw/virtio/virtio.c +0
-1@@ -1169,7 +1169,6 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)return 0 ; } -bool target_words_bigendian (void );static enum virtio_device_endian virtio_default_endian (void ) {if (target_words_bigendian ()) {include/qom/cpu.h +11
-0@@ -1085,6 +1085,17 @@ void cpu_exec_initfn(CPUState *cpu);void cpu_exec_realizefn (CPUState *cpu,Error **errp);void cpu_exec_unrealizefn (CPUState *cpu); +/** +* target_words_bigendian: +* Returns true if the (default) endianness of the target is big endian, +* false otherwise. Note that in target-specifc code, you can use +* TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common +* code should normally never need to know about the endianness of the +* target, so please do *not* use this function unless you know very well +* what you are doing! +*/ +bool target_words_bigendian (void ); +#ifdef NEED_CPU_H #ifdef CONFIG_SOFTMMU qom/cpu.c +0
-0
qom/cpu.c static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp) · line 199
Quoted 7 lines
qom/cpu.c +0
-1@@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)return true; } -bool target_words_bigendian (void );static bool cpu_common_virtio_is_big_endian (CPUState *cpu) {return target_words_bigendian ();
This makes sense to me. First I wasn't convinced, because I didn't immediately get "target-specifc code". However, after looking at the 2nd patch, I think I understand better (= the obj-XXX vs. common-obj-XXX distinction). I also think that distinction is clear to any practicing QEMU developers.
So, for what it's worth (which is admittedly not too much), for the series:
Thanks
Laszlo
Re: [Qemu-devel] [PATCH v2 1/2] cpu: Provide a proper prototype for target_words_bigendian() in a header
Quoted 6 lines · Laszlo Ersek
Quoted 5 lines · Thomas Huth
We've got three places already that provide a prototype for this function in a .c file - that's ugly. Let's provide a proper prototype in a header instead, with a proper description why this function should not be used in most cases.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Thomas Huth <[email protected]>---
+/**
+ *target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specifc code, you can use
"specific"
Quoted 18 lines
Quoted 18 lines
+ *
TARGET_WORDS_BIGENDIANdirectly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */include/qom/cpu.h +2
-0+bool target_words_bigendian (void ); +#ifdef NEED_CPU_H #ifdef CONFIG_SOFTMMU qom/cpu.c +0
-0@@ -194,7 +194,6 @@ static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)return true; }
Quoted 11 lines
qom/cpu.c static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp) · line 199
Quoted 5 lines
qom/cpu.c +0
-1-bool target_words_bigendian (void );static bool cpu_common_virtio_is_big_endian (CPUState *cpu) {return target_words_bigendian ();This makes sense to me. First I wasn't convinced, because I didn't immediately get "target-specifc code". However, after looking at the 2nd patch, I think I understand better (= the obj-XXX vs. common-obj-XXX distinction). I also think that distinction is clear to any practicing QEMU developers.
Yes; target-specific code is compiled for each qemu-system-* executable (and has access to #defines and so on that relate specifically to that target); common code is built just once and the same .o linked into each executable.
thanks
-- PMM
PATCH v2 2/2 hw/core/generic-loader: Compile only once, not for each target
In reply to Thomas HuthThe generic-loader is currently compiled target specific due to one single "#ifdef TARGET_WORDS_BIGENDIAN" in the file. We have already a function called target_words_bigendian() for this instead, so we can put the generic-loader into common-obj to save some compilation time.
--- hw/core/Makefile.objs | 2 +- hw/core/generic-loader.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)
hw/core/Makefile.objs +1 -1
@@ -20,6 +20,6 @@ common-obj-$(CONFIG_SOFTMMU) += register.o common-obj-$(CONFIG_SOFTMMU) += or-irq.o common-obj-$(CONFIG_SOFTMMU) += split-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o +common-obj-$(CONFIG_SOFTMMU) += generic-loader.o -obj-$(CONFIG_SOFTMMU) += generic-loader.o obj-$(CONFIG_SOFTMMU) += null-machine.o
hw/core/generic-loader.c +1 -5
@@ -130,11 +130,7 @@ static void generic_loader_realize(DeviceState *dev, Error **errp) s->cpu = first_cpu; } -#ifdef TARGET_WORDS_BIGENDIAN - big_endian =1 ; -#else - big_endian =0 ; -#endif + big_endian =target_words_bigendian ();if (s->file) {AddressSpace *as = s->cpu ? s->cpu->as :NULL ;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 2/2] hw/core/generic-loader: Compile only once, not for each target
Quoted 6 lines · Thomas Huth
The generic-loader is currently compiled target specific due to one single "#ifdef
TARGET_WORDS_BIGENDIAN" in the file. We have already a function calledtarget_words_bigendian()for this instead, so we can put the generic-loader into common-obj to save some compilation time.Signed-off-by Thomas Huth <[email protected]>
Quoted 35 lines
--- hw/core/Makefile.objs | 2 +- hw/core/generic-loader.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)hw/core/Makefile.objs +1
-1@@ -20,6 +20,6 @@ common-obj-$(CONFIG_SOFTMMU) += register.o common-obj-$(CONFIG_SOFTMMU) += or-irq.o common-obj-$(CONFIG_SOFTMMU) += split-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o +common-obj-$(CONFIG_SOFTMMU) += generic-loader.o -obj-$(CONFIG_SOFTMMU) += generic-loader.o obj-$(CONFIG_SOFTMMU) += null-machine.ohw/core/generic-loader.c +1
-5@@ -130,11 +130,7 @@ static void generic_loader_realize(DeviceState *dev, Error **errp) s->cpu = first_cpu; } -#ifdef TARGET_WORDS_BIGENDIAN - big_endian =1 ; -#else - big_endian =0 ; -#endif + big_endian =target_words_bigendian ();if (s->file) {AddressSpace *as = s->cpu ? s->cpu->as :NULL ;
Re: [Qemu-devel] [PATCH v2 2/2] hw/core/generic-loader: Compile only once, not for each target
In reply to Thomas HuthQuoted 7 lines · Thomas Huth
The generic-loader is currently compiled target specific due to one single "#ifdef
TARGET_WORDS_BIGENDIAN" in the file. We have already a function calledtarget_words_bigendian()for this instead, so we can put the generic-loader into common-obj to save some compilation time.Signed-off-by Thomas Huth <[email protected]>
Alistair
Quoted 38 lines
--- hw/core/Makefile.objs | 2 +- hw/core/generic-loader.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)hw/core/Makefile.objs +1
-1@@ -20,6 +20,6 @@ common-obj-$(CONFIG_SOFTMMU) += register.o common-obj-$(CONFIG_SOFTMMU) += or-irq.o common-obj-$(CONFIG_SOFTMMU) += split-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o +common-obj-$(CONFIG_SOFTMMU) += generic-loader.o -obj-$(CONFIG_SOFTMMU) += generic-loader.o obj-$(CONFIG_SOFTMMU) += null-machine.ohw/core/generic-loader.c +1
-6@@ -130,11 +130,7 @@ static void generic_loader_realize(DeviceState *dev, Error **errp) s->cpu = first_cpu; } -#ifdef TARGET_WORDS_BIGENDIAN - big_endian =1 ; -#else - big_endian =0 ; -#endif + big_endian =target_words_bigendian ();if (s->file) {AddressSpace *as = s->cpu ? s->cpu->as :NULL ; --1.8.3.1