diff mbox

[v3,15/35] include/exec: Split target_long def to new header

Message ID d8cd6b1bb36705f1b76d64e9f25af1cf44e60cbc.1437212383.git.crosthwaite.peter@gmail.com
State New
Headers show

Commit Message

Peter Crosthwaite July 18, 2015, 9:40 a.m. UTC
This is currently provided by cpu-defs and is a target specific
definition. However, to prepare for multi-arch only the bare minimum
content from cpu-defs.h should be exported to core code. And this is
all we need. So split it to a new header that the target_multi cpu.h
can include to save on having to include the ill-defined cpu-defs.h.

Allow multiple inclusion for multi-arch where multiple cpu.h's need
to be included and target_long will vary for each. This means that
target_[u]long needs to be changed from a typedef to a #define to
allow for redefinition.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---
Changed since RFC v2:
Convert target_[u]long to #define
---
 include/exec/cpu-defs.h    | 23 +-------------------
 include/exec/target-long.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 22 deletions(-)
 create mode 100644 include/exec/target-long.h

Comments

Paolo Bonzini July 18, 2015, 12:16 p.m. UTC | #1
On 18/07/2015 11:40, Peter Crosthwaite wrote:
> +/* target_ulong is the type of a virtual address */
> +#if TARGET_LONG_SIZE == 4
> +#define target_long int32_t
> +#define target_ulong uint32_t
> +#define TARGET_FMT_lx "%08x"
> +#define TARGET_FMT_ld "%d"
> +#define TARGET_FMT_lu "%u"
> +#elif TARGET_LONG_SIZE == 8
> +#define target_long int64_t
> +#define target_ulong uint64_t
> +#define TARGET_FMT_lx "%016" PRIx64
> +#define TARGET_FMT_ld "%" PRId64
> +#define TARGET_FMT_lu "%" PRIu64
> +#else
> +#error TARGET_LONG_SIZE undefined
> +#endif

Would it be possible, or make sense, to do

#define target_long arm_target_long
#define target_ulong arm_target_ulong

instead?  This makes prototypes nicer when printed in the debugger with
ptype.  Where could this be done?

And can we assert that TARGET_FMT_l* is not used outside arch-obj-y?

Paolo
Paolo Bonzini July 18, 2015, 12:37 p.m. UTC | #2
On 18/07/2015 14:16, Paolo Bonzini wrote:
>> > +/* target_ulong is the type of a virtual address */
>> > +#if TARGET_LONG_SIZE == 4
>> > +#define target_long int32_t
>> > +#define target_ulong uint32_t
>> > +#define TARGET_FMT_lx "%08x"
>> > +#define TARGET_FMT_ld "%d"
>> > +#define TARGET_FMT_lu "%u"
>> > +#elif TARGET_LONG_SIZE == 8
>> > +#define target_long int64_t
>> > +#define target_ulong uint64_t
>> > +#define TARGET_FMT_lx "%016" PRIx64
>> > +#define TARGET_FMT_ld "%" PRId64
>> > +#define TARGET_FMT_lu "%" PRIu64
>> > +#else
>> > +#error TARGET_LONG_SIZE undefined
>> > +#endif
> Would it be possible, or make sense, to do
> 
> #define target_long arm_target_long
> #define target_ulong arm_target_ulong
> 
> instead?  This makes prototypes nicer when printed in the debugger with
> ptype.  Where could this be done?

Hmm, ISTR that this was more or less what v2 was like, so I guess you
made the change for a reason. :)  So ignore this.

Paolo
Peter A. G. Crosthwaite July 18, 2015, 3:37 p.m. UTC | #3
On Sat, Jul 18, 2015 at 5:37 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 18/07/2015 14:16, Paolo Bonzini wrote:
>>> > +/* target_ulong is the type of a virtual address */
>>> > +#if TARGET_LONG_SIZE == 4
>>> > +#define target_long int32_t
>>> > +#define target_ulong uint32_t
>>> > +#define TARGET_FMT_lx "%08x"
>>> > +#define TARGET_FMT_ld "%d"
>>> > +#define TARGET_FMT_lu "%u"
>>> > +#elif TARGET_LONG_SIZE == 8
>>> > +#define target_long int64_t
>>> > +#define target_ulong uint64_t
>>> > +#define TARGET_FMT_lx "%016" PRIx64
>>> > +#define TARGET_FMT_ld "%" PRId64
>>> > +#define TARGET_FMT_lu "%" PRIu64
>>> > +#else
>>> > +#error TARGET_LONG_SIZE undefined
>>> > +#endif
>> Would it be possible, or make sense, to do
>>
>> #define target_long arm_target_long
>> #define target_ulong arm_target_ulong
>>
>> instead?  This makes prototypes nicer when printed in the debugger with
>> ptype.  Where could this be done?
>
> Hmm, ISTR that this was more or less what v2 was like, so I guess you
> made the change for a reason. :)  So ignore this.
>

I made this change to reduce the cpu.h boiler-plate change pattern and
it makes the undeffery system consistent with other defs. We could go
back to the other way to get this debugability if you think it is
preferrable? Code simplicity vs utility ultimately.

Regards,
Peter

> Paolo
>
Paolo Bonzini July 18, 2015, 4:01 p.m. UTC | #4
On 18/07/2015 17:37, Peter Crosthwaite wrote:
> > > Would it be possible, or make sense, to do
> > >
> > > #define target_long arm_target_long
> > > #define target_ulong arm_target_ulong
> > >
> > > instead?  This makes prototypes nicer when printed in the debugger with
> > > ptype.  Where could this be done?
> >
> > Hmm, ISTR that this was more or less what v2 was like, so I guess you
> > made the change for a reason. :)  So ignore this.
>
> I made this change to reduce the cpu.h boiler-plate change pattern and
> it makes the undeffery system consistent with other defs. We could go
> back to the other way to get this debugability if you think it is
> preferrable? Code simplicity vs utility ultimately.

Unless someone else complains, this version is okay with me.

Paolo
diff mbox

Patch

diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index c6828cc..3889eb7 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -33,28 +33,7 @@ 
 #endif
 #include "exec/memattrs.h"
 
-#ifndef TARGET_LONG_BITS
-#error TARGET_LONG_BITS must be defined before including this header
-#endif
-
-#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
-
-/* target_ulong is the type of a virtual address */
-#if TARGET_LONG_SIZE == 4
-typedef int32_t target_long;
-typedef uint32_t target_ulong;
-#define TARGET_FMT_lx "%08x"
-#define TARGET_FMT_ld "%d"
-#define TARGET_FMT_lu "%u"
-#elif TARGET_LONG_SIZE == 8
-typedef int64_t target_long;
-typedef uint64_t target_ulong;
-#define TARGET_FMT_lx "%016" PRIx64
-#define TARGET_FMT_ld "%" PRId64
-#define TARGET_FMT_lu "%" PRIu64
-#else
-#error TARGET_LONG_SIZE undefined
-#endif
+#include "exec/target-long.h"
 
 #if !defined(CONFIG_USER_ONLY)
 /* use a fully associative victim tlb of 8 entries */
diff --git a/include/exec/target-long.h b/include/exec/target-long.h
new file mode 100644
index 0000000..a10830c
--- /dev/null
+++ b/include/exec/target-long.h
@@ -0,0 +1,54 @@ 
+/*
+ * definition for the target_long type and friends.
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* No multiple included guard intended. Multi-arch setups may require multiple
+ * cpu.h's included which means this can be and should be reached twice.
+ */
+
+#include <stdint.h>
+
+#ifndef TARGET_LONG_BITS
+#error TARGET_LONG_BITS must be defined before including this header
+#endif
+
+#undef TARGET_LONG_SIZE
+#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
+
+#undef target_long
+#undef target_ulong
+#undef TARGET_FMT_lx
+#undef TARGET_FMT_ld
+#undef TARGET_FMT_lu
+
+/* target_ulong is the type of a virtual address */
+#if TARGET_LONG_SIZE == 4
+#define target_long int32_t
+#define target_ulong uint32_t
+#define TARGET_FMT_lx "%08x"
+#define TARGET_FMT_ld "%d"
+#define TARGET_FMT_lu "%u"
+#elif TARGET_LONG_SIZE == 8
+#define target_long int64_t
+#define target_ulong uint64_t
+#define TARGET_FMT_lx "%016" PRIx64
+#define TARGET_FMT_ld "%" PRId64
+#define TARGET_FMT_lu "%" PRIu64
+#else
+#error TARGET_LONG_SIZE undefined
+#endif