Skip to contentSkip to conversation

target/avr: Stop using the legacy native-endian APIs

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

lore
Share & tools
lore
#0 lore raw

cover target/avr: Stop using the legacy native-endian APIs

AVR is always little-endian, making the conversion easy.

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, 8 insertions(+), 9 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 6 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 7 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(-)

AVR is all single byte accesses -- it doesn't matter about endianness. :-)

r~

#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 8 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 4 lines

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

r~

#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 deletion(-)
configs/targets/avr-softmmu.mak +0 -1
index 1aba1ccf13b..b6157fc465d 100644
@@ -1,4 +1,3 @@
 TARGET_ARCH=avr
 TARGET_XML_FILES= gdb-xml/avr-cpu.xml
-TARGET_USE_LEGACY_NATIVE_ENDIAN_API=y
 TARGET_LONG_BITS=32
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 15 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.

---
  configs/targets/avr-softmmu.mak | 1 -
  1 file changed, 1 deletion(-)
configs/targets/avr-softmmu.mak +0 -0
index 1aba1ccf13b..b6157fc465d 100644

configs/targets/avr-softmmu.mak line 3

Quoted 4 lines
configs/targets/avr-softmmu.mak +0 -1
@@ -1,4 +1,3 @@
  TARGET_ARCH=avr
  TARGET_XML_FILES= gdb-xml/avr-cpu.xml
-TARGET_USE_LEGACY_NATIVE_ENDIAN_API=y
  TARGET_LONG_BITS=32

r~