diff mbox

[RFC,v2,14/34] cpu-defs: Allow multiple inclusions

Message ID b9c0ff86c490a6405c8737d8964079acbad339dd.1433052532.git.crosthwaite.peter@gmail.com
State New
Headers show

Commit Message

Peter Crosthwaite May 31, 2015, 6:11 a.m. UTC
Allow subsequent inclusion of cpu-defs.h. This allows including
multiple cpu.h's and each getting the right set of definitions for
its env structure definition. All define symbols are undeffed and
redeffed to the new values.

CPUTLBEntry and CPUIOTLBEntry need to be renamed via #define by
the caller to avoid namespace collisions.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---
 include/exec/cpu-defs.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini June 1, 2015, 7:59 a.m. UTC | #1
On 31/05/2015 08:11, Peter Crosthwaite wrote:
> Allow subsequent inclusion of cpu-defs.h. This allows including
> multiple cpu.h's and each getting the right set of definitions for
> its env structure definition. All define symbols are undeffed and
> redeffed to the new values.
> 
> CPUTLBEntry and CPUIOTLBEntry need to be renamed via #define by
> the caller to avoid namespace collisions.

Please document these things (#undeffing of preprocessor symbols and
what needs to be renamed) in the header.

Also the same is true for include/exec/target-long.h---where
additionally I am not sure about how you'd deal with a redefined
typedef.  Some compilers flag it as an error even if the source type is
the same.

Paolo

> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> ---
>  include/exec/cpu-defs.h | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
> index a1c418f..6b59e58 100644
> --- a/include/exec/cpu-defs.h
> +++ b/include/exec/cpu-defs.h
> @@ -16,8 +16,10 @@
>   * 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/>.
>   */
> -#ifndef CPU_DEFS_H
> -#define CPU_DEFS_H
> +
> +/* No multiple include guard intended. Multi-arch setups may require multiple
> + * cpu.h's included which means this can be and should be reached twice.
> + */
>  
>  #ifndef NEED_CPU_H
>  #error cpu.h included from common code
> @@ -34,12 +36,19 @@
>  
>  #include "exec/target-long.h"
>  
> +#undef CPU_COMMON
> +#undef CPU_COMMON_TLB
> +
>  #if !defined(CONFIG_USER_ONLY)
> +#undef CPU_TLB_BITS
> +#undef CPU_TLB_SIZE
> +#undef CPU_VTLB_SIZE
>  #define CPU_TLB_BITS 8
>  #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
>  /* use a fully associative victim tlb of 8 entries */
>  #define CPU_VTLB_SIZE 8
>  
> +#undef CPU_TLB_ENTRY_BITS
>  #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
>  #define CPU_TLB_ENTRY_BITS 4
>  #else
> @@ -100,4 +109,3 @@ typedef struct CPUIOTLBEntry {
>      /* soft mmu support */                                              \
>      CPU_COMMON_TLB                                                      \
>  
> -#endif
>
Richard Henderson June 1, 2015, 7:29 p.m. UTC | #2
On 06/01/2015 12:59 AM, Paolo Bonzini wrote:
> 
> 
> On 31/05/2015 08:11, Peter Crosthwaite wrote:
>> Allow subsequent inclusion of cpu-defs.h. This allows including
>> multiple cpu.h's and each getting the right set of definitions for
>> its env structure definition. All define symbols are undeffed and
>> redeffed to the new values.
>>
>> CPUTLBEntry and CPUIOTLBEntry need to be renamed via #define by
>> the caller to avoid namespace collisions.
> 
> Please document these things (#undeffing of preprocessor symbols and
> what needs to be renamed) in the header.
> 
> Also the same is true for include/exec/target-long.h---where
> additionally I am not sure about how you'd deal with a redefined
> typedef.  Some compilers flag it as an error even if the source type is
> the same.

Whee, I'm not alone in my curiosity.

Of course, one way around this is to make target_[u]long be defines instead of
typedefs.  Whether that's a sufficient solution, I have no idea.

That said, I think I'm also missing the point of multiple-inclusion.  Perhaps
it'll become clearer in a patch I haven't seen yet.


r~
diff mbox

Patch

diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index a1c418f..6b59e58 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -16,8 +16,10 @@ 
  * 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/>.
  */
-#ifndef CPU_DEFS_H
-#define CPU_DEFS_H
+
+/* No multiple include guard intended. Multi-arch setups may require multiple
+ * cpu.h's included which means this can be and should be reached twice.
+ */
 
 #ifndef NEED_CPU_H
 #error cpu.h included from common code
@@ -34,12 +36,19 @@ 
 
 #include "exec/target-long.h"
 
+#undef CPU_COMMON
+#undef CPU_COMMON_TLB
+
 #if !defined(CONFIG_USER_ONLY)
+#undef CPU_TLB_BITS
+#undef CPU_TLB_SIZE
+#undef CPU_VTLB_SIZE
 #define CPU_TLB_BITS 8
 #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
 /* use a fully associative victim tlb of 8 entries */
 #define CPU_VTLB_SIZE 8
 
+#undef CPU_TLB_ENTRY_BITS
 #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
 #define CPU_TLB_ENTRY_BITS 4
 #else
@@ -100,4 +109,3 @@  typedef struct CPUIOTLBEntry {
     /* soft mmu support */                                              \
     CPU_COMMON_TLB                                                      \
 
-#endif