Skip to contentSkip to conversation

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

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

lore
Share & tools
lore
#0 lore raw

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

Alpha is little-endian. Use the explicit 'little'
endianness instead of the 'native' one.

Replace legacy ld/st_phys() calls. Forbid further
uses of legacy APIs.

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

Philippe Mathieu-Daudé (6):
hw/alpha: Use explicit little-endian LD/ST API target/alpha: Use explicit little-endian LD/ST API target/alpha: Inline cpu_ldl_code() call in do_unaligned_access() target/alpha: Inline translator_ldl()
configs/targets: Forbid Alpha to use legacy native endianness APIs target/alpha: Replace legacy ld_phys() -> address_space_ld()

 configs/targets/alpha-linux-user.mak |  2 ++
 configs/targets/alpha-softmmu.mak    |  2 ++
 hw/alpha/dp264.c                     | 11 +++++------
 hw/alpha/typhoon.c                   |  4 ++--
 target/alpha/helper.c                | 28 +++++++++++++++++-----------
 target/alpha/mem_helper.c            |  4 +++-
 target/alpha/translate.c             |  4 ++--
 7 files changed, 33 insertions(+), 22 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/6 hw/alpha: Use explicit little-endian LD/ST API

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

  $ for a in uw w l q; do \
      sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
        $(git grep -wlE '(ld|st)u?[wlq]_p' hw/alpha/);
    done
---
 hw/alpha/dp264.c   | 11 +++++------
 hw/alpha/typhoon.c |  4 ++--
 2 files changed, 7 insertions(+), 8 deletions(-)
hw/alpha/dp264.c +5 -6
index b6155646ef7..203b9ce92d7 100644
@@ -194,12 +194,11 @@ static void clipper_init(MachineState *machine)
             load_image_targphys(initrd_filename, initrd_base,
                                 ram_size - initrd_base, NULL);
 
-            address_space_stq(&address_space_memory, param_offset + 0x100,
-                              initrd_base + 0xfffffc0000000000ULL,
-                              MEMTXATTRS_UNSPECIFIED,
-                              NULL);
-            address_space_stq(&address_space_memory, param_offset + 0x108,
-                              initrd_size, MEMTXATTRS_UNSPECIFIED, NULL);
+            address_space_stq_le(&address_space_memory, param_offset + 0x100,
+                                 initrd_base + 0xfffffc0000000000ULL,
+                                 MEMTXATTRS_UNSPECIFIED, NULL);
+            address_space_stq_le(&address_space_memory, param_offset + 0x108,
+                                 initrd_size, MEMTXATTRS_UNSPECIFIED, NULL);
         }
     }
 }
hw/alpha/typhoon.c +2 -2
index 4c56f981d71..0a039dc8a31 100644
@@ -622,8 +622,8 @@ static bool make_iommu_tlbe(hwaddr taddr, hwaddr mask, IOMMUTLBEntry *ret)
    translation, given the address of the PTE.  */
 static bool pte_translate(hwaddr pte_addr, IOMMUTLBEntry *ret)
 {
-    uint64_t pte = address_space_ldq(&address_space_memory, pte_addr,
-                                     MEMTXATTRS_UNSPECIFIED, NULL);
+    uint64_t pte = address_space_ldq_le(&address_space_memory, pte_addr,
+                                        MEMTXATTRS_UNSPECIFIED, NULL);
 
     /* Check valid bit.  */
     if ((pte & 1) == 0) {
Signature · 1 line
2.52.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] hw/alpha: Use explicit little-endian LD/ST API

Quoted 6 lines · Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

Quoted 7 lines
  $ for a in uw w l q; do \
      sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
        $(git grep -wlE '(ld|st)u?[wlq]_p' hw/alpha/);
    done

---

Quoted 44 lines
 hw/alpha/dp264.c   | 11 +++++------
 hw/alpha/typhoon.c |  4 ++--
 2 files changed, 7 insertions(+), 8 deletions(-)
hw/alpha/dp264.c +5 -6
index b6155646ef7..203b9ce92d7 100644
@@ -194,12 +194,11 @@ static void clipper_init(MachineState *machine)
             load_image_targphys(initrd_filename, initrd_base,
                                 ram_size - initrd_base, NULL);
 
-            address_space_stq(&address_space_memory, param_offset + 0x100,
-                              initrd_base + 0xfffffc0000000000ULL,
-                              MEMTXATTRS_UNSPECIFIED,
-                              NULL);
-            address_space_stq(&address_space_memory, param_offset + 0x108,
-                              initrd_size, MEMTXATTRS_UNSPECIFIED, NULL);
+            address_space_stq_le(&address_space_memory, param_offset + 0x100,
+                                 initrd_base + 0xfffffc0000000000ULL,
+                                 MEMTXATTRS_UNSPECIFIED, NULL);
+            address_space_stq_le(&address_space_memory, param_offset + 0x108,
+                                 initrd_size, MEMTXATTRS_UNSPECIFIED, NULL);
         }
     }
 }
hw/alpha/typhoon.c +2 -3
index 4c56f981d71..0a039dc8a31 100644
@@ -622,8 +622,8 @@ static bool make_iommu_tlbe(hwaddr taddr, hwaddr mask, IOMMUTLBEntry *ret)
    translation, given the address of the PTE.  */
 static bool pte_translate(hwaddr pte_addr, IOMMUTLBEntry *ret)
 {
-    uint64_t pte = address_space_ldq(&address_space_memory, pte_addr,
-                                     MEMTXATTRS_UNSPECIFIED, NULL);
+    uint64_t pte = address_space_ldq_le(&address_space_memory, pte_addr,
+                                        MEMTXATTRS_UNSPECIFIED, NULL);
 
     /* Check valid bit.  */
     if ((pte & 1) == 0) {
--

2.52.0

Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] hw/alpha: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

   $ for a in uw w l q; do \
       sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
         $(git grep -wlE '(ld|st)u?[wlq]_p' hw/alpha/);
     done
Quoted 5 lines
---
  hw/alpha/dp264.c   | 11 +++++------
  hw/alpha/typhoon.c |  4 ++--
  2 files changed, 7 insertions(+), 8 deletions(-)

r~

#4 lore raw

PATCH 2/6 target/alpha: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

  $ for a in uw w l q; do \
      sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
        $(git grep -wlE '(ld|st)u?[wlq]_p' target/alpha/);
    done
---
 target/alpha/helper.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
target/alpha/helper.c +6 -5
index a9af52a928f..80542cb0665 100644
@@ -214,17 +214,18 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     pt = env->ptbr;
 
-    /* TODO: rather than using ldq_phys() to read the page table we should
+    /*
+     * TODO: rather than using ldq_phys_le() to read the page table we should
      * use address_space_ldq() so that we can handle the case when
      * the page table read gives a bus fault, rather than ignoring it.
-     * For the existing code the zero data that ldq_phys will return for
+     * For the existing code the zero data that ldq_phys_le will return for
      * an access to invalid memory will result in our treating the page
      * table as invalid, which may even be the right behaviour.
      */
 
     /* L1 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 20)) & 0x3ff;
-    L1pte = ldq_phys(cs->as, pt + index*8);
+    L1pte = ldq_phys_le(cs->as, pt + index * 8);
 
     if (unlikely((L1pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -237,7 +238,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L2 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 10)) & 0x3ff;
-    L2pte = ldq_phys(cs->as, pt + index*8);
+    L2pte = ldq_phys_le(cs->as, pt + index * 8);
 
     if (unlikely((L2pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -250,7 +251,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L3 page table read.  */
     index = (addr >> TARGET_PAGE_BITS) & 0x3ff;
-    L3pte = ldq_phys(cs->as, pt + index*8);
+    L3pte = ldq_phys_le(cs->as, pt + index * 8);
 
     phys = L3pte >> 32 << TARGET_PAGE_BITS;
     if (unlikely((L3pte & PTE_VALID) == 0)) {
Signature · 1 line
2.52.0
Reviewed-by on v1 2/6
#5 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

Quoted 7 lines
  $ for a in uw w l q; do \
      sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
        $(git grep -wlE '(ld|st)u?[wlq]_p' target/alpha/);
    done

---

Quoted 50 lines
 target/alpha/helper.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
target/alpha/helper.c +6 -6
index a9af52a928f..80542cb0665 100644
@@ -214,17 +214,18 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     pt = env->ptbr;
 
-    /* TODO: rather than using ldq_phys() to read the page table we should
+    /*
+     * TODO: rather than using ldq_phys_le() to read the page table we should
      * use address_space_ldq() so that we can handle the case when
      * the page table read gives a bus fault, rather than ignoring it.
-     * For the existing code the zero data that ldq_phys will return for
+     * For the existing code the zero data that ldq_phys_le will return for
      * an access to invalid memory will result in our treating the page
      * table as invalid, which may even be the right behaviour.
      */
 
     /* L1 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 20)) & 0x3ff;
-    L1pte = ldq_phys(cs->as, pt + index*8);
+    L1pte = ldq_phys_le(cs->as, pt + index * 8);
 
     if (unlikely((L1pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -237,7 +238,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L2 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 10)) & 0x3ff;
-    L2pte = ldq_phys(cs->as, pt + index*8);
+    L2pte = ldq_phys_le(cs->as, pt + index * 8);
 
     if (unlikely((L2pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -250,7 +251,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L3 page table read.  */
     index = (addr >> TARGET_PAGE_BITS) & 0x3ff;
-    L3pte = ldq_phys(cs->as, pt + index*8);
+    L3pte = ldq_phys_le(cs->as, pt + index * 8);
 
     phys = L3pte >> 32 << TARGET_PAGE_BITS;
     if (unlikely((L3pte & PTE_VALID) == 0)) {
--

2.52.0

Reviewed-by on v1 2/6
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change running:

   $ for a in uw w l q; do \
       sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
         $(git grep -wlE '(ld|st)u?[wlq]_p' target/alpha/);
     done
Quoted 4 lines
---
  target/alpha/helper.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)

r~

#7 lore raw

PATCH 3/6 target/alpha: Inline cpu_ldl_code() call in do_unaligned_access()

In reply to Philippe Mathieu-Daudé

In preparation of removing the cpu_ldl_code wrapper, inline it. Use the return address argument.

Since Alpha instructions are always stored in little-endian order, replace MO_TE -> MO_LE.

---
 target/alpha/mem_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target/alpha/mem_helper.c +3 -1
index 2113fe33ae2..572ea9cb418 100644
@@ -24,13 +24,15 @@
 
 static void do_unaligned_access(CPUAlphaState *env, vaddr addr, uintptr_t retaddr)
 {
+    CPUState *cs = env_cpu(env);
+    MemOpIdx oi = make_memop_idx(MO_LEUL, cpu_mmu_index(cs, true));
     uint64_t pc;
     uint32_t insn;
 
     cpu_restore_state(env_cpu(env), retaddr);
 
     pc = env->pc;
-    insn = cpu_ldl_code(env, pc);
+    insn = cpu_ldl_code_mmu(env, pc, oi, retaddr);
 
     env->trap_arg0 = addr;
     env->trap_arg1 = insn >> 26;                /* opcode */
Signature · 1 line
2.52.0
Reviewed-by on v1 3/6
#8 lore raw

Re: [PATCH 3/6] target/alpha: Inline cpu_ldl_code() call in do_unaligned_access()

Quoted 10 lines · Philippe Mathieu-Daudé

In preparation of removing the cpu_ldl_code wrapper, inline it. Use the return address argument.

Since Alpha instructions are always stored in little-endian order, replace MO_TE -> MO_LE.

---
  target/alpha/mem_helper.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

r~

#9 lore raw

PATCH 4/6 target/alpha: Inline translator_ldl()

In reply to Philippe Mathieu-Daudé

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

  198 static inline uint32_t
  199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
  200 {
  201     return translator_ldl_end(env, db, pc, MO_TE);
  202 }

Directly use the inlined form, expanding MO_TE -> MO_LE since Alpha use little-endian order.

---
 target/alpha/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/alpha/translate.c +2 -2
index b1d8a4eb80a..48ac50a7cdf 100644
@@ -2904,8 +2904,8 @@ static void alpha_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
 static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
 {
     DisasContext *ctx = container_of(dcbase, DisasContext, base);
-    uint32_t insn = translator_ldl(cpu_env(cpu), &ctx->base,
-                                   ctx->base.pc_next);
+    uint32_t insn = translator_ldl_end(cpu_env(cpu), &ctx->base,
+                                       ctx->base.pc_next, MO_LE);
 
     ctx->base.pc_next += 4;
     ctx->base.is_jmp = translate_one(ctx, insn);
Signature · 1 line
2.52.0
Reviewed-by on v1 4/6
#10 lore raw

Re: [PATCH 4/6] target/alpha: Inline translator_ldl()

Quoted 21 lines · Philippe Mathieu-Daudé

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

   198 static inline uint32_t
   199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
   200 {
   201     return translator_ldl_end(env, db, pc, MO_TE);
   202 }

Directly use the inlined form, expanding MO_TE -> MO_LE since Alpha use little-endian order.

---
  target/alpha/translate.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/alpha/translate.c +0 -0
index b1d8a4eb80a..48ac50a7cdf 100644

target/alpha/translate.c static void alpha_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) · line 2911

Quoted 10 lines
target/alpha/translate.c +2 -2
@@ -2904,8 +2904,8 @@ static void alpha_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
  static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
  {
      DisasContext *ctx = container_of(dcbase, DisasContext, base);
-    uint32_t insn = translator_ldl(cpu_env(cpu), &ctx->base,
-                                   ctx->base.pc_next);
+    uint32_t insn = translator_ldl_end(cpu_env(cpu), &ctx->base,
+                                       ctx->base.pc_next, MO_LE);
 
      ctx->base.pc_next += 4;
      ctx->base.is_jmp = translate_one(ctx, insn);

r~

#11 lore raw

PATCH 5/6 configs/targets: Forbid Alpha to use legacy native endianness APIs

In reply to Philippe Mathieu-Daudé

All Alpha-related binaries are 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/alpha-linux-user.mak | 1 +
 configs/targets/alpha-softmmu.mak    | 1 +
 2 files changed, 2 insertions(+)
configs/targets/alpha-linux-user.mak +1 -0
index aa25766236e..ee505e16ef4 100644
@@ -3,3 +3,4 @@ TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
 TARGET_LONG_BITS=64
 TARGET_XML_FILES= gdb-xml/alpha-core.xml
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
configs/targets/alpha-softmmu.mak +1 -0
index e31f059a52d..22fbbf0cb08 100644
@@ -1,3 +1,4 @@
 TARGET_ARCH=alpha
 TARGET_LONG_BITS=64
 TARGET_XML_FILES= gdb-xml/alpha-core.xml
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0
Reviewed-by on v1 5/6
#12 lore raw

Re: [PATCH 5/6] configs/targets: Forbid Alpha to use legacy native endianness APIs

Quoted 25 lines · Philippe Mathieu-Daudé

All Alpha-related binaries are 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/alpha-linux-user.mak | 1 +
  configs/targets/alpha-softmmu.mak    | 1 +
  2 files changed, 2 insertions(+)
configs/targets/alpha-linux-user.mak +1 -0
index aa25766236e..ee505e16ef4 100644
@@ -3,3 +3,4 @@ TARGET_SYSTBL_ABI=common
  TARGET_SYSTBL=syscall.tbl
  TARGET_LONG_BITS=64
  TARGET_XML_FILES= gdb-xml/alpha-core.xml
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
configs/targets/alpha-softmmu.mak +0 -0
index e31f059a52d..22fbbf0cb08 100644

configs/targets/alpha-softmmu.mak line 4

Quoted 4 lines
configs/targets/alpha-softmmu.mak +1 -0
@@ -1,3 +1,4 @@
  TARGET_ARCH=alpha
  TARGET_LONG_BITS=64
  TARGET_XML_FILES= gdb-xml/alpha-core.xml
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y

r~

#13 lore raw

PATCH 6/6 target/alpha: Replace legacy ld_phys() -> address_space_ld()

In reply to Philippe Mathieu-Daudé

Prefer the address_space_ld/st API over the legacy ld_phys() because it allow checking for bus access fault.

Since we removed the last legacy uses of the legacy ldst_phys() API, set the TARGET_NOT_USING_LEGACY_LDST_PHYS_API variable to hide the legacy API to alpha binaries, avoiding further API uses to creep in.

---
 configs/targets/alpha-linux-user.mak |  1 +
 configs/targets/alpha-softmmu.mak    |  1 +
 target/alpha/helper.c                | 29 ++++++++++++++++------------
 3 files changed, 19 insertions(+), 12 deletions(-)
configs/targets/alpha-linux-user.mak +1 -0
index ee505e16ef4..2f1312f0362 100644
@@ -4,3 +4,4 @@ TARGET_SYSTBL=syscall.tbl
 TARGET_LONG_BITS=64
 TARGET_XML_FILES= gdb-xml/alpha-core.xml
 TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
+TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
configs/targets/alpha-softmmu.mak +1 -0
index 22fbbf0cb08..5c6af0eafc1 100644
@@ -2,3 +2,4 @@ TARGET_ARCH=alpha
 TARGET_LONG_BITS=64
 TARGET_XML_FILES= gdb-xml/alpha-core.xml
 TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
+TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
target/alpha/helper.c +17 -12
index 80542cb0665..126a53c829b 100644
@@ -169,6 +169,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
                                 int prot_need, int mmu_idx,
                                 target_ulong *pphys, int *pprot)
 {
+    const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
     CPUState *cs = env_cpu(env);
     target_long saddr = addr;
     target_ulong phys = 0;
@@ -176,6 +177,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
     target_ulong pt, index;
     int prot = 0;
     int ret = MM_K_ACV;
+    MemTxResult txres;
 
     /* Handle physical accesses.  */
     if (mmu_idx == MMU_PHYS_IDX) {
@@ -214,18 +216,13 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     pt = env->ptbr;
 
-    /*
-     * TODO: rather than using ldq_phys_le() to read the page table we should
-     * use address_space_ldq() so that we can handle the case when
-     * the page table read gives a bus fault, rather than ignoring it.
-     * For the existing code the zero data that ldq_phys_le will return for
-     * an access to invalid memory will result in our treating the page
-     * table as invalid, which may even be the right behaviour.
-     */
-
     /* L1 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 20)) & 0x3ff;
-    L1pte = ldq_phys_le(cs->as, pt + index * 8);
+    L1pte = address_space_ldq_le(cs->as, pt + index * 8, attrs, &txres);
+    if (txres != MEMTX_OK) {
+        /* bus fault */
+        goto exit;
+    }
 
     if (unlikely((L1pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -238,7 +235,11 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L2 page table read.  */
     index = (addr >> (TARGET_PAGE_BITS + 10)) & 0x3ff;
-    L2pte = ldq_phys_le(cs->as, pt + index * 8);
+    L2pte = address_space_ldq_le(cs->as, pt + index * 8, attrs, &txres);
+    if (txres != MEMTX_OK) {
+        /* bus fault */
+        goto exit;
+    }
 
     if (unlikely((L2pte & PTE_VALID) == 0)) {
         ret = MM_K_TNV;
@@ -251,7 +252,11 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,
 
     /* L3 page table read.  */
     index = (addr >> TARGET_PAGE_BITS) & 0x3ff;
-    L3pte = ldq_phys_le(cs->as, pt + index * 8);
+    L3pte = address_space_ldq_le(cs->as, pt + index * 8, attrs, &txres);
+    if (txres != MEMTX_OK) {
+        /* bus fault */
+        goto exit;
+    }
 
     phys = L3pte >> 32 << TARGET_PAGE_BITS;
     if (unlikely((L3pte & PTE_VALID) == 0)) {
Signature · 1 line
2.52.0
Reviewed-by on v1 6/6
#14 lore raw

Re: [PATCH 6/6] target/alpha: Replace legacy ld_phys() -> address_space_ld()

Quoted 8 lines · Philippe Mathieu-Daudé

Prefer the address_space_ld/st API over the legacy ld_phys() because it allow checking for bus access fault.

Since we removed the last legacy uses of the legacy ldst_phys() API, set the TARGET_NOT_USING_LEGACY_LDST_PHYS_API variable to hide the legacy API to alpha binaries, avoiding further API uses to creep in.

Quoted 6 lines
---
  configs/targets/alpha-linux-user.mak |  1 +
  configs/targets/alpha-softmmu.mak    |  1 +
  target/alpha/helper.c                | 29 ++++++++++++++++------------
  3 files changed, 19 insertions(+), 12 deletions(-)

r~

#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 2 lines · Philippe Mathieu-Daudé

Alpha is little-endian. Use the explicit 'little'
endianness instead of the 'native' one.

Technically, Alpha can be run in big-endian mode, but we don't bother. This was only ever used for the Cray T3[DE] machines. :-)

r~

Quoted 24 lines

Replace legacy ld/st_phys() calls. Forbid further
uses of legacy APIs.

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

Philippe Mathieu-Daudé (6):
hw/alpha: Use explicit little-endian LD/ST API target/alpha: Use explicit little-endian LD/ST API target/alpha: Inline cpu_ldl_code() call in do_unaligned_access() target/alpha: Inline translator_ldl()
configs/targets: Forbid Alpha to use legacy native endianness APIs target/alpha: Replace legacy ld_phys() -> address_space_ld()

  configs/targets/alpha-linux-user.mak |  2 ++
  configs/targets/alpha-softmmu.mak    |  2 ++
  hw/alpha/dp264.c                     | 11 +++++------
  hw/alpha/typhoon.c                   |  4 ++--
  target/alpha/helper.c                | 28 +++++++++++++++++-----------
  target/alpha/mem_helper.c            |  4 +++-
  target/alpha/translate.c             |  4 ++--
  7 files changed, 33 insertions(+), 22 deletions(-)