diff mbox series

[17/17] target/avr: Enable TARGET_PAGE_BITS_VARY

Message ID 20250323173730.3213964-18-richard.henderson@linaro.org
State New
Headers show
Series target/avr: Increase page size | expand

Commit Message

Richard Henderson March 23, 2025, 5:37 p.m. UTC
Increase TARGET_PHYS_ADDR_SPACE_BITS to allow flexibility in the page
size without triggering an assert.  Select the page size based on the
size of sram.  This leaves sram on exactly one page and minimizes the
number of pages required to span the flash.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/avr/cpu-param.h | 11 +++++++++--
 hw/avr/arduino.c       | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

Comments

Pierrick Bouvier March 25, 2025, 1:24 a.m. UTC | #1
On 3/23/25 10:37, Richard Henderson wrote:
> Increase TARGET_PHYS_ADDR_SPACE_BITS to allow flexibility in the page
> size without triggering an assert.  Select the page size based on the
> size of sram.  This leaves sram on exactly one page and minimizes the
> number of pages required to span the flash.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/avr/cpu-param.h | 11 +++++++++--
>   hw/avr/arduino.c       | 15 +++++++++++++++
>   2 files changed, 24 insertions(+), 2 deletions(-)

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
diff mbox series

Patch

diff --git a/target/avr/cpu-param.h b/target/avr/cpu-param.h
index f5248ce9e7..a18bf39bb9 100644
--- a/target/avr/cpu-param.h
+++ b/target/avr/cpu-param.h
@@ -21,8 +21,15 @@ 
 #ifndef AVR_CPU_PARAM_H
 #define AVR_CPU_PARAM_H
 
-#define TARGET_PAGE_BITS 10
-#define TARGET_PHYS_ADDR_SPACE_BITS 24
+#define TARGET_PAGE_BITS_VARY
+#define TARGET_PAGE_BITS_MIN 10
+
+/*
+ * The real value for TARGET_PHYS_ADDR_SPACE_BITS is 24, but selecting
+ * an overly small value will assert in tb-maint.c when selecting the
+ * shape of the page_table tree.  This allows an 8k page size.
+ */
+#define TARGET_PHYS_ADDR_SPACE_BITS 28
 #define TARGET_VIRT_ADDR_SPACE_BITS 24
 
 #define TCG_GUEST_DEFAULT_MO 0
diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
index 29cb776848..f309aa5597 100644
--- a/hw/avr/arduino.c
+++ b/hw/avr/arduino.c
@@ -71,9 +71,24 @@  static void arduino_machine_class_init(ObjectClass *oc, void *data)
 
 static void arduino_machine_class_base_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
     ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
+    AtmegaMcuClass *acc;
+    int page_bits;
 
     amc->mcu_type = data;
+
+    /* Find the mcu class that we will instantiate. */
+    acc = ATMEGA_MCU_CLASS(object_class_by_name(amc->mcu_type));
+
+    /*
+     * Select a page size based on the size of sram.
+     * This will result in a page size between 1k and 8k
+     * and minimize the number of pages to span flash.
+     */
+    page_bits = ctz32(acc->sram_size);
+    assert(page_bits >= TARGET_PAGE_BITS_MIN && page_bits <= 13);
+    mc->minimum_page_bits = page_bits;
 }
 
 static void arduino_duemilanove_class_init(ObjectClass *oc, void *data)