diff mbox series

[RFC,03/34] exec: [PAGE_VARY] Move TARGET_PAGE_BITS_VARY to common header

Message ID 20240119144024.14289-4-anjo@rev.ng (mailing list archive)
State New, archived
Headers show
Series Compile accel/tcg once (partially) | expand

Commit Message

Anton Johansson Jan. 19, 2024, 2:39 p.m. UTC
We need to be able access the variable TARGET_PAGE_* macros in a
target-independent manner.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 include/exec/cpu-all.h    | 29 ++++++++++-------------------
 include/exec/cpu-common.h | 25 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 19 deletions(-)

Comments

Richard Henderson Jan. 23, 2024, 10:20 p.m. UTC | #1
On 1/20/24 00:39, Anton Johansson wrote:
> We need to be able access the variable TARGET_PAGE_* macros in a
> target-independent manner.
> 
> Signed-off-by: Anton Johansson <anjo@rev.ng>

I think you should pull all of these macros into a separate header.
The split here is a bit confusing.


r~
diff mbox series

Patch

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index a1e4dee6a2..83165b1ce4 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -149,30 +149,21 @@  static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val
 #include "exec/memory_ldst_phys.h.inc"
 #endif
 
-/* page related stuff */
-
-#ifdef TARGET_PAGE_BITS_VARY
-# include "exec/page-vary.h"
-extern const TargetPageBits target_page;
-#ifdef CONFIG_DEBUG_TCG
-#define TARGET_PAGE_BITS_MIN ({ assert(target_page.decided); \
-                                target_page.bits_min; })
-#define TARGET_PAGE_BITS   ({ assert(target_page.decided); target_page.bits; })
-#define TARGET_PAGE_MASK   ({ assert(target_page.decided); \
-                              (target_long)target_page.mask; })
-#else
-#define TARGET_PAGE_BITS_MIN target_page.bits_min
-#define TARGET_PAGE_BITS     target_page.bits
-#define TARGET_PAGE_MASK     ((target_long)target_page.mask)
-#endif
-#define TARGET_PAGE_SIZE   (-(int)TARGET_PAGE_MASK)
-#else
+/* Non-variable page size macros */
+#ifndef TARGET_PAGE_BITS_VARY
 #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS
 #define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
 #define TARGET_PAGE_MASK   ((target_long)-1 << TARGET_PAGE_BITS)
+#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
 #endif
 
-#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
+/*
+ * Check that softmmu targets are using variable page sizes, we need this
+ * for the TARGET_PAGE_* macros to be target independent.
+ */
+#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_PAGE_BITS_VARY)
+# error Need to use TARGET_PAGE_BITS_VARY on system mode
+#endif
 
 /* same as PROT_xxx */
 #define PAGE_READ      0x0001
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 605b160a7e..df53252d51 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -26,6 +26,31 @@  typedef uint64_t vaddr;
 #define VADDR_PRIX PRIX64
 #define VADDR_MAX UINT64_MAX
 
+/**
+ * Variable page size macros
+ *
+ * TARGET_PAGE_BITS_VARY is assumed for softmmu targets so
+ * these macros are target independent.  This is checked in
+ * cpu-all.h.
+ */
+#ifndef CONFIG_USER_ONLY
+# include "exec/page-vary.h"
+extern const TargetPageBits target_page;
+#ifdef CONFIG_DEBUG_TCG
+#define TARGET_PAGE_BITS_MIN ({ assert(target_page.decided); \
+                                target_page.bits_min; })
+#define TARGET_PAGE_BITS   ({ assert(target_page.decided); target_page.bits; })
+#define TARGET_PAGE_MASK   ({ assert(target_page.decided); \
+                              (int)target_page.mask; })
+#else
+#define TARGET_PAGE_BITS_MIN target_page.bits_min
+#define TARGET_PAGE_BITS     target_page.bits
+#define TARGET_PAGE_MASK     ((int)target_page.mask)
+#endif
+#define TARGET_PAGE_SIZE   (-(int)TARGET_PAGE_MASK)
+#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
+#endif
+
 void cpu_exec_init_all(void);
 void cpu_exec_step_atomic(CPUState *cpu);