Skip to contentSkip to conversation

target/avr: Use explicit little-endian LD/ST API

PATCH In review Philippe Mathieu-Daudé 2 participants 7 messages Dec 24, 2025 – Dec 29, 2025

lore
Share & tools
lore
#0 lore raw

cover target/avr: Use explicit little-endian LD/ST API

AVR is little-endian. Use the explicit 'little'
endianness instead of the 'native' one.
Forbid further uses of legacy APIs.

tag: https://gitlab.com/philmd/qemu/-/tags/endian_avr-v1
CI: https://gitlab.com/philmd/qemu/-/pipelines/2231223066

Philippe Mathieu-Daudé (3):
hw/avr: Mark AVR-specific peripherals as little-endian target/avr: Inline translator_lduw()
configs/targets: Forbid AVR to use legacy native endianness API

 configs/targets/avr-softmmu.mak | 1 +
 hw/char/avr_usart.c             | 2 +-
 hw/misc/avr_power.c             | 2 +-
 hw/timer/avr_timer16.c          | 6 +++---
 target/avr/helper.c             | 4 ++--
 target/avr/translate.c          | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/3 hw/avr: Mark AVR-specific peripherals as little-endian

These devices are only used by the AVR target, which is only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---
 hw/char/avr_usart.c    | 2 +-
 hw/misc/avr_power.c    | 2 +-
 hw/timer/avr_timer16.c | 6 +++---
 target/avr/helper.c    | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
hw/char/avr_usart.c +1 -1
index fae15217e9f..5510dd3f487 100644
@@ -255,7 +255,7 @@ static void avr_usart_write(void *opaque, hwaddr addr, uint64_t value,
 static const MemoryRegionOps avr_usart_ops = {
     .read = avr_usart_read,
     .write = avr_usart_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.min_access_size = 1, .max_access_size = 1}
 };
 
hw/misc/avr_power.c +1 -1
index 411f016c997..d8e0d918519 100644
@@ -69,7 +69,7 @@ static void avr_mask_write(void *opaque, hwaddr offset,
 static const MemoryRegionOps avr_mask_ops = {
     .read = avr_mask_read,
     .write = avr_mask_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {
         .max_access_size = 1,
     },
hw/timer/avr_timer16.c +3 -3
index 012d8290018..110bcd58163 100644
@@ -524,21 +524,21 @@ static void avr_timer16_ifr_write(void *opaque, hwaddr offset,
 static const MemoryRegionOps avr_timer16_ops = {
     .read = avr_timer16_read,
     .write = avr_timer16_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
 static const MemoryRegionOps avr_timer16_imsk_ops = {
     .read = avr_timer16_imsk_read,
     .write = avr_timer16_imsk_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
 static const MemoryRegionOps avr_timer16_ifr_ops = {
     .read = avr_timer16_ifr_read,
     .write = avr_timer16_ifr_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
target/avr/helper.c +2 -2
index 365c8c60e19..9ee0a558ea7 100644
@@ -256,7 +256,7 @@ static void avr_cpu_trap_write(void *opaque, hwaddr addr,
 const MemoryRegionOps avr_cpu_reg1 = {
     .read = avr_cpu_reg1_read,
     .write = avr_cpu_trap_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .valid.min_access_size = 1,
     .valid.max_access_size = 1,
 };
@@ -264,7 +264,7 @@ const MemoryRegionOps avr_cpu_reg1 = {
 const MemoryRegionOps avr_cpu_reg2 = {
     .read = avr_cpu_reg2_read,
     .write = avr_cpu_trap_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .valid.min_access_size = 1,
     .valid.max_access_size = 1,
 };
Signature · 1 line
2.52.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] hw/avr: Mark AVR-specific peripherals as little-endian

Quoted 9 lines · Philippe Mathieu-Daudé

These devices are only used by the AVR target, which is only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---

Quoted 86 lines
 hw/char/avr_usart.c    | 2 +-
 hw/misc/avr_power.c    | 2 +-
 hw/timer/avr_timer16.c | 6 +++---
 target/avr/helper.c    | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
hw/char/avr_usart.c +1 -1
index fae15217e9f..5510dd3f487 100644
@@ -255,7 +255,7 @@ static void avr_usart_write(void *opaque, hwaddr addr, uint64_t value,
 static const MemoryRegionOps avr_usart_ops = {
     .read = avr_usart_read,
     .write = avr_usart_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.min_access_size = 1, .max_access_size = 1}
 };
 
hw/misc/avr_power.c +1 -1
index 411f016c997..d8e0d918519 100644
@@ -69,7 +69,7 @@ static void avr_mask_write(void *opaque, hwaddr offset,
 static const MemoryRegionOps avr_mask_ops = {
     .read = avr_mask_read,
     .write = avr_mask_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {
         .max_access_size = 1,
     },
hw/timer/avr_timer16.c +3 -3
index 012d8290018..110bcd58163 100644
@@ -524,21 +524,21 @@ static void avr_timer16_ifr_write(void *opaque, hwaddr offset,
 static const MemoryRegionOps avr_timer16_ops = {
     .read = avr_timer16_read,
     .write = avr_timer16_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
 static const MemoryRegionOps avr_timer16_imsk_ops = {
     .read = avr_timer16_imsk_read,
     .write = avr_timer16_imsk_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
 static const MemoryRegionOps avr_timer16_ifr_ops = {
     .read = avr_timer16_ifr_read,
     .write = avr_timer16_ifr_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {.max_access_size = 1}
 };
 
target/avr/helper.c +2 -3
index 365c8c60e19..9ee0a558ea7 100644
@@ -256,7 +256,7 @@ static void avr_cpu_trap_write(void *opaque, hwaddr addr,
 const MemoryRegionOps avr_cpu_reg1 = {
     .read = avr_cpu_reg1_read,
     .write = avr_cpu_trap_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .valid.min_access_size = 1,
     .valid.max_access_size = 1,
 };
@@ -264,7 +264,7 @@ const MemoryRegionOps avr_cpu_reg1 = {
 const MemoryRegionOps avr_cpu_reg2 = {
     .read = avr_cpu_reg2_read,
     .write = avr_cpu_trap_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .valid.min_access_size = 1,
     .valid.max_access_size = 1,
 };
--

2.52.0

#3 lore raw

PATCH 2/3 target/avr: Inline translator_lduw()

In reply to Philippe Mathieu-Daudé

translator_lduw() is defined in "exec/translator.h" as:

192 static inline uint16_t
193 translator_lduw(CPUArchState *env, DisasContextBase *db, vaddr pc) 194 {
195 return translator_lduw_end(env, db, pc, MO_TE);
196 }

Directly use the inlined form, expanding MO_TE -> MO_LE since AVR only exists in little-endian.

---
 target/avr/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/translate.c +1 -1
index ef6f655a458..78ae83df219 100644
@@ -173,7 +173,7 @@ static int to_regs_00_30_by_two(DisasContext *ctx, int indx)
 
 static uint16_t next_word(DisasContext *ctx)
 {
-    return translator_lduw(ctx->env, &ctx->base, ctx->npc++ * 2);
+    return translator_lduw_end(ctx->env, &ctx->base, ctx->npc++ * 2, MO_LE);
 }
 
 static int append_16(DisasContext *ctx, int x)
Signature · 1 line
2.52.0
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] target/avr: Inline translator_lduw()

Quoted 9 lines · Philippe Mathieu-Daudé

translator_lduw() is defined in "exec/translator.h" as:

192 static inline uint16_t
193 translator_lduw(CPUArchState *env, DisasContextBase *db, vaddr pc) 194 {
195 return translator_lduw_end(env, db, pc, MO_TE);
196 }

Quoted 5 lines

Directly use the inlined form, expanding MO_TE -> MO_LE since AVR only exists in little-endian.

---

Quoted 19 lines
 target/avr/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/translate.c +1 -2
index ef6f655a458..78ae83df219 100644
@@ -173,7 +173,7 @@ static int to_regs_00_30_by_two(DisasContext *ctx, int indx)
 
 static uint16_t next_word(DisasContext *ctx)
 {
-    return translator_lduw(ctx->env, &ctx->base, ctx->npc++ * 2);
+    return translator_lduw_end(ctx->env, &ctx->base, ctx->npc++ * 2, MO_LE);
 }
 
 static int append_16(DisasContext *ctx, int x)
--

2.52.0

#5 lore raw

PATCH 3/3 configs/targets: Forbid AVR to use legacy native endianness API

In reply to Philippe Mathieu-Daudé

The qemu-system-avr binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

---
 configs/targets/avr-softmmu.mak | 1 +
 1 file changed, 1 insertion(+)
configs/targets/avr-softmmu.mak +1 -0
index baf20fb7f2f..154f58448ae 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=avr
 TARGET_XML_FILES= gdb-xml/avr-cpu.xml
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] configs/targets: Forbid AVR to use legacy native endianness API

Quoted 8 lines · Philippe Mathieu-Daudé

The qemu-system-avr binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

---

Quoted 15 lines
 configs/targets/avr-softmmu.mak | 1 +
 1 file changed, 1 insertion(+)
configs/targets/avr-softmmu.mak +1 -1
index baf20fb7f2f..154f58448ae 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=avr
 TARGET_XML_FILES= gdb-xml/avr-cpu.xml
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
--

2.52.0