@@ -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
@@ -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)
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(-)