Skip to contentSkip to conversation

Alpha system emulation, v2

PATCH In review Richard Henderson 3 participants 35 messages Apr 19, 2011 – Apr 21, 2011 Kbuild

lore
Share & tools
lore
#21 lore raw

PATCH 21/24 target-alpha: Include the PCC_OFS in the RPCC return value.

In reply to Richard Henderson
---
 target-alpha/op_helper.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
target-alpha/op_helper.c +2 -1
index cc8a33d..5902cd6 100644
@@ -44,7 +44,8 @@ static void QEMU_NORETURN arith_excp(int exc, uint64_t mask)
 uint64_t helper_load_pcc (void)
 {
     /* ??? This isn't a timer for which we have any rate info.  */
-    return (uint32_t)cpu_get_real_ticks();
+    uint64_t ret = env->pcc_ofs;
+    return ret << 32 | (uint32_t)cpu_get_real_ticks();
 }
 
 uint64_t helper_load_fpcr (void)
Signature · 1 line
1.7.3.4
#9 lore raw

PATCH 9/24 target-alpha: Add IPRs to be used by the emulation PALcode.

In reply to Richard Henderson

These aren't actually used yet, but we can at least access them via the HW_MFPR and HW_MTPR instructions.

---
 target-alpha/cpu.h       |   13 +++++++
 target-alpha/translate.c |   87 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 2 deletions(-)
target-alpha/cpu.h +13 -0
index 1c848bd..dec8b26 100644
@@ -247,6 +247,7 @@ struct CPUAlphaState {
     uint8_t intr_flag;
     uint8_t fen;
     uint8_t pal_mode;
+    uint32_t pcc_ofs;
 
     /* These pass data from the exception logic in the translator and
        helpers to the OS entry point.  This is used for both system
@@ -255,6 +256,18 @@ struct CPUAlphaState {
     uint64_t trap_arg1;
     uint64_t trap_arg2;
 
+#if !defined(CONFIG_USER_ONLY)
+    /* The internal data required by our emulation of the Unix PALcode.  */
+    uint64_t exc_addr;
+    uint64_t palbr;
+    uint64_t ptbr;
+    uint64_t vptptr;
+    uint64_t sysval;
+    uint64_t usp;
+    uint64_t shadow[8];
+    uint64_t scratch[24];
+#endif
+
 #if TARGET_LONG_BITS > HOST_LONG_BITS
     /* temporary fixed-point registers
      * used to emulate 64 bits target on 32 bits hosts
target-alpha/translate.c +85 -2

105 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#10 lore raw

PATCH 10/24 target-alpha: Tidy up arithmetic exceptions.

In reply to Richard Henderson

Introduce and use arith_excp, filling in the trap_arg[01] IPRs.

---
 target-alpha/op_helper.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)
target-alpha/op_helper.c +21 -13
index bbf89fe..9c19c96 100644
@@ -32,6 +32,15 @@ void QEMU_NORETURN helper_excp (int excp, int error)
     cpu_loop_exit();
 }
 
+static void QEMU_NORETURN arith_excp(int exc, uint64_t mask)
+{
+    env->exception_index = EXCP_ARITH;
+    env->error_code = 0;
+    env->trap_arg0 = exc;
+    env->trap_arg1 = mask;
+    cpu_loop_exit();
+}
+
 uint64_t helper_load_pcc (void)
 {
     /* ??? This isn't a timer for which we have any rate info.  */
@@ -53,7 +62,7 @@ uint64_t helper_addqv (uint64_t op1, uint64_t op2)
     uint64_t tmp = op1;
     op1 += op2;
     if (unlikely((tmp ^ op2 ^ (-1ULL)) & (tmp ^ op1) & (1ULL << 63))) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return op1;
 }
@@ -63,7 +72,7 @@ uint64_t helper_addlv (uint64_t op1, uint64_t op2)
     uint64_t tmp = op1;
     op1 = (uint32_t)(op1 + op2);
     if (unlikely((tmp ^ op2 ^ (-1UL)) & (tmp ^ op1) & (1UL << 31))) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return op1;
 }
@@ -73,7 +82,7 @@ uint64_t helper_subqv (uint64_t op1, uint64_t op2)
     uint64_t res;
     res = op1 - op2;
     if (unlikely((op1 ^ op2) & (res ^ op1) & (1ULL << 63))) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return res;
 }
@@ -83,7 +92,7 @@ uint64_t helper_sublv (uint64_t op1, uint64_t op2)
     uint32_t res;
     res = op1 - op2;
     if (unlikely((op1 ^ op2) & (res ^ op1) & (1UL << 31))) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return res;
 }
@@ -93,7 +102,7 @@ uint64_t helper_mullv (uint64_t op1, uint64_t op2)
     int64_t res = (int64_t)op1 * (int64_t)op2;
 
     if (unlikely((int32_t)res != res)) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return (int64_t)((int32_t)res);
 }
@@ -105,7 +114,7 @@ uint64_t helper_mulqv (uint64_t op1, uint64_t op2)
     muls64(&tl, &th, op1, op2);
     /* If th != 0 && th != -1, then we had an overflow */
     if (unlikely((th + 1) > 1)) {
-        helper_excp(EXCP_ARITH, EXC_M_IOV);
+        arith_excp(EXC_M_IOV, 0);
     }
     return tl;
 }
@@ -373,8 +382,6 @@ void helper_fp_exc_raise(uint32_t exc, uint32_t regno)
     if (exc) {
         uint32_t hw_exc = 0;
 
-        env->trap_arg1 = 1ull << regno;
-
         if (exc & float_flag_invalid) {
             hw_exc |= EXC_M_INV;
         }
@@ -390,7 +397,8 @@ void helper_fp_exc_raise(uint32_t exc, uint32_t regno)
         if (exc & float_flag_inexact) {
             hw_exc |= EXC_M_INE;
         }
-        helper_excp(EXCP_ARITH, hw_exc);
+
+        arith_excp(hw_exc, 1ull << regno);
     }
 }
 
@@ -420,7 +428,7 @@ uint64_t helper_ieee_input(uint64_t val)
             if (env->fpcr_dnz) {
                 val &= 1ull << 63;
             } else {
-                helper_excp(EXCP_ARITH, EXC_M_UNF);
+                arith_excp(EXC_M_UNF, 0);
             }
         }
     } else if (exp == 0x7ff) {
@@ -428,7 +436,7 @@ uint64_t helper_ieee_input(uint64_t val)
         /* ??? I'm not sure these exception bit flags are correct.  I do
            know that the Linux kernel, at least, doesn't rely on them and
            just emulates the insn to figure out what exception to use.  */
-        helper_excp(EXCP_ARITH, frac ? EXC_M_INV : EXC_M_FOV);
+        arith_excp(frac ? EXC_M_INV : EXC_M_FOV, 0);
     }
     return val;
 }
@@ -445,12 +453,12 @@ uint64_t helper_ieee_input_cmp(uint64_t val)
             if (env->fpcr_dnz) {
                 val &= 1ull << 63;
             } else {
-                helper_excp(EXCP_ARITH, EXC_M_UNF);
+                arith_excp(EXC_M_UNF, 0);
             }
         }
     } else if (exp == 0x7ff && frac) {
         /* NaN.  */
-        helper_excp(EXCP_ARITH, EXC_M_INV);
+        arith_excp(EXC_M_INV, 0);
     }
     return val;
 }
Signature · 1 line
1.7.3.4
#22 lore raw

PATCH 22/24 target-alpha: Implement TLB flush primitives.

In reply to Richard Henderson

Expose these via MTPR, more or less like the real HW does.

---
 target-alpha/helper.h    |    3 +++
 target-alpha/op_helper.c |   11 ++++++++++-
 target-alpha/translate.c |   32 +++++++++++++++++++++-----------
 3 files changed, 34 insertions(+), 12 deletions(-)
target-alpha/helper.h +3 -0
index 9ffc372..2dec57e 100644
@@ -110,6 +110,9 @@ DEF_HELPER_2(stl_phys, void, i64, i64)
 DEF_HELPER_2(stq_phys, void, i64, i64)
 DEF_HELPER_2(stl_c_phys, i64, i64, i64)
 DEF_HELPER_2(stq_c_phys, i64, i64, i64)
+
+DEF_HELPER_FLAGS_0(tbia, TCG_CALL_CONST, void)
+DEF_HELPER_FLAGS_1(tbis, TCG_CALL_CONST, void, i64)
 #endif
 
 #include "def-helper.h"
target-alpha/op_helper.c +10 -1
index 5902cd6..718f87d 100644
@@ -1174,6 +1174,16 @@ void helper_hw_ret (uint64_t a)
         swap_shadow_regs(env);
     }
 }
+
+void helper_tbia(void)
+{
+    tlb_flush(env, 1);
+}
+
+void helper_tbis(uint64_t p)
+{
+    tlb_flush_page(env, p);
+}
 #endif
 
 /*****************************************************************************/
@@ -1326,5 +1336,4 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
     }
     env = saved_env;
 }
-
 #endif
target-alpha/translate.c +21 -11
index c2db1ae..fa0cb09 100644
@@ -1620,7 +1620,6 @@ static void gen_mfpr(int ra, int regno)
 static void gen_mtpr(int rb, int regno)
 {
     TCGv tmp;
-    int data;
 
     if (rb == 31) {
         tmp = tcg_const_i64(0);
@@ -1628,16 +1627,27 @@ static void gen_mtpr(int rb, int regno)
         tmp = cpu_ir[rb];
     }
 
-    /* The basic registers are data only, and unknown registers
-       are read-zero, write-ignore.  */
-    data = cpu_pr_data(regno);
-    if (data != 0) {
-        if (data & PR_BYTE) {
-            tcg_gen_st8_i64(tmp, cpu_env, data & ~PR_BYTE);
-        } else if (data & PR_LONG) {
-            tcg_gen_st32_i64(tmp, cpu_env, data & ~PR_LONG);
-        } else {
-            tcg_gen_st_i64(tmp, cpu_env, data);
+    /* These two register numbers perform a TLB cache flush.  Thankfully we
+       can only do this inside PALmode, which means that the current basic
+       block cannot be affected by the change in mappings.  */
+    if (regno == 255) {
+        /* TBIA */
+        gen_helper_tbia();
+    } else if (regno == 254) {
+        /* TBIS */
+        gen_helper_tbis(tmp);
+    } else {
+        /* The basic registers are data only, and unknown registers
+           are read-zero, write-ignore.  */
+        int data = cpu_pr_data(regno);
+        if (data != 0) {
+            if (data & PR_BYTE) {
+                tcg_gen_st8_i64(tmp, cpu_env, data & ~PR_BYTE);
+            } else if (data & PR_LONG) {
+                tcg_gen_st32_i64(tmp, cpu_env, data & ~PR_LONG);
+            } else {
+                tcg_gen_st_i64(tmp, cpu_env, data);
+            }
         }
     }
 
Signature · 1 line
1.7.3.4
#5 lore raw

PATCH 5/24 target-alpha: Tidy exception constants.

In reply to Richard Henderson

There's no need to attempt to match EXCP_* values with PALcode entry point offsets. Instead, compress all the values to make for more efficient switch statements within QEMU.

We will be doing TLB fill within QEMU proper, not within the PALcode, so all of the ITB/DTB miss, double fault, and access exceptions can be compressed to EXCP_MMFAULT.

Compress all of the EXCP_CALL_PAL exceptions into one. Use env->error_code to store the specific entry point.

---
 linux-user/main.c        |   43 +++++++++++++------------------------------
 target-alpha/cpu.h       |   33 +++++++++++++--------------------
 target-alpha/helper.c    |    6 +-----
 target-alpha/translate.c |    4 ++--
 4 files changed, 29 insertions(+), 57 deletions(-)
linux-user/main.c +13 -30
index a1e37e4..5b25736 100644
@@ -2526,19 +2526,12 @@ void cpu_loop (CPUState *env)
             fprintf(stderr, "Machine check exception. Exit\n");
             exit(1);
             break;
-        case EXCP_ARITH:
-            env->lock_addr = -1;
-            info.si_signo = TARGET_SIGFPE;
-            info.si_errno = 0;
-            info.si_code = TARGET_FPE_FLTINV;
-            info._sifields._sigfault._addr = env->pc;
-            queue_signal(env, info.si_signo, &info);
-            break;
-        case EXCP_HW_INTERRUPT:
+        case EXCP_CLK_INTERRUPT:
+        case EXCP_DEV_INTERRUPT:
             fprintf(stderr, "External interrupt. Exit\n");
             exit(1);
             break;
-        case EXCP_DFAULT:
+        case EXCP_MMFAULT:
             env->lock_addr = -1;
             info.si_signo = TARGET_SIGSEGV;
             info.si_errno = 0;
@@ -2547,22 +2540,6 @@ void cpu_loop (CPUState *env)
             info._sifields._sigfault._addr = env->ipr[IPR_EXC_ADDR];
             queue_signal(env, info.si_signo, &info);
             break;
-        case EXCP_DTB_MISS_PAL:
-            fprintf(stderr, "MMU data TLB miss in PALcode\n");
-            exit(1);
-            break;
-        case EXCP_ITB_MISS:
-            fprintf(stderr, "MMU instruction TLB miss\n");
-            exit(1);
-            break;
-        case EXCP_ITB_ACV:
-            fprintf(stderr, "MMU instruction access violation\n");
-            exit(1);
-            break;
-        case EXCP_DTB_MISS_NATIVE:
-            fprintf(stderr, "MMU data TLB miss\n");
-            exit(1);
-            break;
         case EXCP_UNALIGN:
             env->lock_addr = -1;
             info.si_signo = TARGET_SIGBUS;
@@ -2580,12 +2557,20 @@ void cpu_loop (CPUState *env)
             info._sifields._sigfault._addr = env->pc;
             queue_signal(env, info.si_signo, &info);
             break;
+        case EXCP_ARITH:
+            env->lock_addr = -1;
+            info.si_signo = TARGET_SIGFPE;
+            info.si_errno = 0;
+            info.si_code = TARGET_FPE_FLTINV;
+            info._sifields._sigfault._addr = env->pc;
+            queue_signal(env, info.si_signo, &info);
+            break;
         case EXCP_FEN:
             /* No-op.  Linux simply re-enables the FPU.  */
             break;
-        case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1):
+        case EXCP_CALL_PAL:
             env->lock_addr = -1;
-            switch ((trapnr >> 6) | 0x80) {
+            switch (env->error_code) {
             case 0x80:
                 /* BPT */
                 info.si_signo = TARGET_SIGTRAP;
@@ -2676,8 +2661,6 @@ void cpu_loop (CPUState *env)
                 goto do_sigill;
             }
             break;
-        case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1):
-            goto do_sigill;
         case EXCP_DEBUG:
             info.si_signo = gdb_handlesig (env, TARGET_SIGTRAP);
             if (info.si_signo) {
target-alpha/cpu.h +13 -20
index 0daa556..f3e939b 100644
@@ -391,26 +391,19 @@ enum {
 };
 
 enum {
-    EXCP_RESET            = 0x0000,
-    EXCP_MCHK             = 0x0020,
-    EXCP_ARITH            = 0x0060,
-    EXCP_HW_INTERRUPT     = 0x00E0,
-    EXCP_DFAULT           = 0x01E0,
-    EXCP_DTB_MISS_PAL     = 0x09E0,
-    EXCP_ITB_MISS         = 0x03E0,
-    EXCP_ITB_ACV          = 0x07E0,
-    EXCP_DTB_MISS_NATIVE  = 0x08E0,
-    EXCP_UNALIGN          = 0x11E0,
-    EXCP_OPCDEC           = 0x13E0,
-    EXCP_FEN              = 0x17E0,
-    EXCP_CALL_PAL         = 0x2000,
-    EXCP_CALL_PALP        = 0x3000,
-    EXCP_CALL_PALE        = 0x4000,
-    /* Pseudo exception for console */
-    EXCP_CONSOLE_DISPATCH = 0x4001,
-    EXCP_CONSOLE_FIXUP    = 0x4002,
-    EXCP_STL_C            = 0x4003,
-    EXCP_STQ_C            = 0x4004,
+    EXCP_RESET,
+    EXCP_MCHK,
+    EXCP_CLK_INTERRUPT,
+    EXCP_DEV_INTERRUPT,
+    EXCP_MMFAULT,
+    EXCP_UNALIGN,
+    EXCP_OPCDEC,
+    EXCP_ARITH,
+    EXCP_FEN,
+    EXCP_CALL_PAL,
+    /* For Usermode emulation.  */
+    EXCP_STL_C,
+    EXCP_STQ_C,
 };
 
 /* Arithmetic exception */
target-alpha/helper.c +1 -5
index f7cf4ee..676c870 100644
@@ -164,12 +164,8 @@ void cpu_alpha_store_fpcr (CPUState *env, uint64_t val)
 int cpu_alpha_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
                                 int mmu_idx, int is_softmmu)
 {
-    if (rw == 2)
-        env->exception_index = EXCP_ITB_MISS;
-    else
-        env->exception_index = EXCP_DFAULT;
+    env->exception_index = EXCP_MMFAULT;
     env->ipr[IPR_EXC_ADDR] = address;
-
     return 1;
 }
 
target-alpha/translate.c +2 -2
index 699c70d..3a023a5 100644
@@ -1512,7 +1512,7 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
 #endif
         if (palcode >= 0x80 && palcode < 0xC0) {
             /* Unprivileged PAL call */
-            ret = gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x3F) << 6), 0);
+            ret = gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xBF);
             break;
         }
 #ifndef CONFIG_USER_ONLY
@@ -1520,7 +1520,7 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
             /* Privileged PAL code */
             if (ctx->mem_idx & 1)
                 goto invalid_opc;
-            ret = gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x3F) << 6), 0);
+            ret = gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3F);
         }
 #endif
         /* Invalid PAL call */
Signature · 1 line
1.7.3.4
#19 lore raw

PATCH 19/24 target-alpha: Implement cpu_alpha_handle_mmu_fault for system mode.

In reply to Richard Henderson

Reads the page table how PALcode would, except that the virtual page table base register is not used.

---
 target-alpha/cpu.h    |   12 +++++
 target-alpha/helper.c |  129 +++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 137 insertions(+), 4 deletions(-)
target-alpha/cpu.h +12 -0
index d4edaf8..d133cc6 100644
@@ -315,6 +315,18 @@ enum {
     EXCP_STQ_C,
 };
 
+enum {
+    PTE_VALID = 0x0001,
+    PTE_FOR   = 0x0002,  /* used for page protection (fault on read) */
+    PTE_FOW   = 0x0004,  /* used for page protection (fault on write) */
+    PTE_FOE   = 0x0008,  /* used for page protection (fault on exec) */
+    PTE_ASM   = 0x0010,
+    PTE_KRE   = 0x0100,
+    PTE_URE   = 0x0200,
+    PTE_KWE   = 0x1000,
+    PTE_UWE   = 0x2000
+};
+
 /* Hardware interrupt (entInt) constants.  */
 enum {
     INT_K_IP,
target-alpha/helper.c +125 -4

139 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#11 lore raw

PATCH 11/24 target-alpha: Merge HW_REI and HW_RET implementations.

In reply to Richard Henderson
---
 target-alpha/translate.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
target-alpha/translate.c +13 -3
index 7c90ad9..c8ef31d 100644
@@ -2939,14 +2939,24 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
         break;
 #endif
     case 0x1E:
-        /* HW_REI (PALcode) */
+        /* HW_RET (PALcode) */
 #if defined (CONFIG_USER_ONLY)
         goto invalid_opc;
 #else
         if (!ctx->pal_mode)
             goto invalid_opc;
-        gen_helper_hw_ret(cpu_ir[rb]);
-        break;
+        if (rb == 31) {
+            /* Pre-EV6 CPUs interpreted this as HW_REI, loading the return
+               address from EXC_ADDR.  This turns out to be useful for our
+               emulation PALcode, so continue to accept it.  */
+            TCGv tmp = tcg_temp_new();
+            tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUState, exc_addr));
+            gen_helper_hw_ret(tmp);
+            tcg_temp_free(tmp);
+        } else {
+            gen_helper_hw_ret(cpu_ir[rb]);
+        }
+        return EXIT_PC_UPDATED;
 #endif
     case 0x1F:
         /* HW_ST (PALcode) */
Signature · 1 line
1.7.3.4
#17 lore raw

PATCH 17/24 target-alpha: Implement more CALL_PAL values inline.

In reply to Richard Henderson

In particular, SWPIPL is used quite a lot by the Linux kernel. Doing this inline makes it significantly easier to step through without the debugger getting confused by the mode switch.

---
 target-alpha/translate.c |  141 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 110 insertions(+), 31 deletions(-)
target-alpha/translate.c +110 -31
index 47fb4fb..c2db1ae 100644
@@ -85,8 +85,10 @@ static TCGv cpu_pc;
 static TCGv cpu_lock_addr;
 static TCGv cpu_lock_st_addr;
 static TCGv cpu_lock_value;
-#ifdef CONFIG_USER_ONLY
-static TCGv cpu_uniq;
+static TCGv cpu_unique;
+#ifndef CONFIG_USER_ONLY
+static TCGv cpu_sysval;
+static TCGv cpu_usp;
 #endif
 
 /* register names */
@@ -131,9 +133,13 @@ static void alpha_translate_init(void)
 					    offsetof(CPUState, lock_value),
 					    "lock_value");
 
-#ifdef CONFIG_USER_ONLY
-    cpu_uniq = tcg_global_mem_new_i64(TCG_AREG0,
-                                      offsetof(CPUState, unique), "uniq");
+    cpu_unique = tcg_global_mem_new_i64(TCG_AREG0,
+                                        offsetof(CPUState, unique), "unique");
+#ifndef CONFIG_USER_ONLY
+    cpu_sysval = tcg_global_mem_new_i64(TCG_AREG0,
+                                        offsetof(CPUState, sysval), "sysval");
+    cpu_usp = tcg_global_mem_new_i64(TCG_AREG0,
+                                     offsetof(CPUState, usp), "usp");
 #endif
 
     /* register helpers */
@@ -1460,6 +1466,104 @@ static void gen_rx(int ra, int set)
     tcg_temp_free_i32(tmp);
 }
 
+static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)
+{
+    /* We're emulating OSF/1 PALcode.  Many of these are trivial access
+       to internal cpu registers.  */
+
+    /* Unprivileged PAL call */
+    if (palcode >= 0x80 && palcode < 0xC0) {
+        switch (palcode) {
+        case 0x86:
+            /* IMB */
+            /* No-op inside QEMU.  */
+            break;
+        case 0x9E:
+            /* RDUNIQUE */
+            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_unique);
+            break;
+        case 0x9F:
+            /* WRUNIQUE */
+            tcg_gen_mov_i64(cpu_unique, cpu_ir[IR_A0]);
+            break;
+        default:
+            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xbf);
+        }
+        return NO_EXIT;
+    }
+
+#ifndef CONFIG_USER_ONLY
+    /* Privileged PAL code */
+    if (palcode < 0x40 && (ctx->tb->flags & TB_FLAGS_USER_MODE) == 0) {
+        switch (palcode) {
+        case 0x01:
+            /* CFLUSH */
+            /* No-op inside QEMU.  */
+            break;
+        case 0x02:
+            /* DRAINA */
+            /* No-op inside QEMU.  */
+            break;
+        case 0x2D:
+            /* WRVPTPTR */
+            tcg_gen_st_i64(cpu_ir[IR_A0], cpu_env, offsetof(CPUState, vptptr));
+            break;
+        case 0x31:
+            /* WRVAL */
+            tcg_gen_mov_i64(cpu_sysval, cpu_ir[IR_A0]);
+            break;
+        case 0x32:
+            /* RDVAL */
+            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_sysval);
+            break;
+
+        case 0x35: {
+            /* SWPIPL */
+            TCGv tmp;
+
+            /* Note that we already know we're in kernel mode, so we know
+               that PS only contains the 3 IPL bits.  */
+            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUState, ps));
+
+            /* But make sure and store only the 3 IPL bits from the user.  */
+            tmp = tcg_temp_new();
+            tcg_gen_andi_i64(tmp, cpu_ir[IR_A0], PS_INT_MASK);
+            tcg_gen_st8_i64(tmp, cpu_env, offsetof(CPUState, ps));
+            tcg_temp_free(tmp);
+            break;
+        }
+
+        case 0x36:
+            /* RDPS */
+            tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env,
+                             offsetof(CPUAlphaState, ps));
+            break;
+        case 0x38:
+            /* WRUSP */
+            tcg_gen_mov_i64(cpu_usp, cpu_ir[IR_A0]);
+            break;
+        case 0x3A:
+            /* RDUSP */
+            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_usp);
+            break;
+
+        /* TODO:
+             0x3C Whami
+            These merely need more cooperation in designation of
+            internal processor registers w/ palcode.  These are
+            currently stored in palcode scratch registers and
+            should be treated like UNIQUE.  */
+
+        default:
+            return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3f);
+        }
+        return NO_EXIT;
+    }
+#endif
+
+    return gen_invalid(ctx);
+}
+
 #ifndef CONFIG_USER_ONLY
 
 #define PR_BYTE         0x100000
@@ -1578,32 +1682,7 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
     switch (opc) {
     case 0x00:
         /* CALL_PAL */
-#ifdef CONFIG_USER_ONLY
-        if (palcode == 0x9E) {
-            /* RDUNIQUE */
-            tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_uniq);
-            break;
-        } else if (palcode == 0x9F) {
-            /* WRUNIQUE */
-            tcg_gen_mov_i64(cpu_uniq, cpu_ir[IR_A0]);
-            break;
-        }
-#endif
-        if (palcode >= 0x80 && palcode < 0xC0) {
-            /* Unprivileged PAL call */
-            ret = gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xBF);
-            break;
-        }
-#ifndef CONFIG_USER_ONLY
-        if (palcode < 0x40) {
-            /* Privileged PAL code */
-            if (ctx->mem_idx & 1)
-                goto invalid_opc;
-            ret = gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3F);
-        }
-#endif
-        /* Invalid PAL call */
-        goto invalid_opc;
+        return gen_call_pal(ctx, palcode);
     case 0x01:
         /* OPC01 */
         goto invalid_opc;
Signature · 1 line
1.7.3.4
#24 lore raw

PATCH 24/24 target-alpha: Add SX164 emulation.

In reply to Richard Henderson
---
 Makefile.target  |    1 +
 hw/alpha_pci.c   |  327 +++++++++++++++++
 hw/alpha_pyxis.c | 1057 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/alpha_sx164.c |  195 ++++++++++
 hw/alpha_sys.h   |   41 +++
 5 files changed, 1621 insertions(+), 0 deletions(-)
 create mode 100644 hw/alpha_pci.c
 create mode 100644 hw/alpha_pyxis.c
 create mode 100644 hw/alpha_sx164.c
 create mode 100644 hw/alpha_sys.h
Makefile.target +1 -0
index 443679b..f702780 100644
@@ -364,6 +364,7 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o
 
 obj-alpha-y += i8259.o mc146818rtc.o
 obj-alpha-y += vga.o cirrus_vga.o
+obj-alpha-y += alpha_pci.o alpha_sx164.o alpha_pyxis.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
hw/alpha_pci.c new file +327 -0

327 lines not on this page · raw message

hw/alpha_pyxis.c new file +1057 -0

1,057 lines not on this page · raw message

hw/alpha_sx164.c new file +195 -0

195 lines not on this page · raw message

hw/alpha_sys.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#15 lore raw

PATCH 15/24 target-alpha: All ISA checks to use TB->FLAGS.

In reply to Richard Henderson

We had two different methods in use, both of which referenced ENV, and neither of which indicated to the generic code when different compilation modes are not compatible.

---
 target-alpha/cpu.h       |   32 ++++-
 target-alpha/translate.c |  396 ++++++++++++++++++++++++----------------------
 2 files changed, 239 insertions(+), 189 deletions(-)
target-alpha/cpu.h +30 -2
index d8f2514..d4edaf8 100644
@@ -412,12 +412,40 @@ uint64_t cpu_alpha_load_fpcr (CPUState *env);
 void cpu_alpha_store_fpcr (CPUState *env, uint64_t val);
 extern void swap_shadow_regs(CPUState *env);
 
+/* Bits in TB->FLAGS that control how translation is processed.  */
+enum {
+    TB_FLAGS_PAL_MODE = 1,
+    TB_FLAGS_FEN = 2,
+    TB_FLAGS_USER_MODE = 8,
+
+    TB_FLAGS_AMASK_SHIFT = 4,
+    TB_FLAGS_AMASK_BWX = AMASK_BWX << TB_FLAGS_AMASK_SHIFT,
+    TB_FLAGS_AMASK_FIX = AMASK_FIX << TB_FLAGS_AMASK_SHIFT,
+    TB_FLAGS_AMASK_CIX = AMASK_CIX << TB_FLAGS_AMASK_SHIFT,
+    TB_FLAGS_AMASK_MVI = AMASK_MVI << TB_FLAGS_AMASK_SHIFT,
+    TB_FLAGS_AMASK_TRAP = AMASK_TRAP << TB_FLAGS_AMASK_SHIFT,
+    TB_FLAGS_AMASK_PREFETCH = AMASK_PREFETCH << TB_FLAGS_AMASK_SHIFT,
+};
+
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
-                                        target_ulong *cs_base, int *flags)
+                                        target_ulong *cs_base, int *pflags)
 {
+    int flags = 0;
+
     *pc = env->pc;
     *cs_base = 0;
-    *flags = env->ps;
+
+    if (env->pal_mode) {
+        flags = TB_FLAGS_PAL_MODE;
+    } else {
+        flags = env->ps & PS_USER_MODE;
+    }
+    if (env->fen) {
+        flags |= TB_FLAGS_FEN;
+    }
+    flags |= env->amask << TB_FLAGS_AMASK_SHIFT;
+
+    *pflags = flags;
 }
 
 #if defined(CONFIG_USER_ONLY)
target-alpha/translate.c +209 -187

558 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 3/24 pci: Export pci_to_cpu_addr.

In reply to Richard Henderson

This is, more or less, the read accessor to pci_bus_set_mem_base as a write accessor. It will be needed for implementing sparse memory spaces for Alpha.

---
 hw/pci.c |    3 +--
 hw/pci.h |    1 +
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/pci.c +1 -2
index 6b577e1..8c7f52a 100644
@@ -793,8 +793,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
     return pci_dev;
 }
 
-static target_phys_addr_t pci_to_cpu_addr(PCIBus *bus,
-                                          target_phys_addr_t addr)
+target_phys_addr_t pci_to_cpu_addr(PCIBus *bus, target_phys_addr_t addr)
 {
     return addr + bus->mem_base;
 }
hw/pci.h +1 -0
index 52ee8c9..cb0f738 100644
@@ -242,6 +242,7 @@ void pci_device_reset(PCIDevice *dev);
 void pci_bus_reset(PCIBus *bus);
 
 void pci_bus_set_mem_base(PCIBus *bus, target_phys_addr_t base);
+target_phys_addr_t pci_to_cpu_addr(PCIBus *bus, target_phys_addr_t addr);
 
 PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr);
Signature · 1 line
1.7.3.4
#14 lore raw

PATCH 14/24 target-alpha: Add various symbolic constants.

In reply to Richard Henderson

The EXC_M_* constants were being set for the EV6, not as set for the Unix kernel entry point.

Use PS_USER_MODE instead of hard-coding access to the PS register.

---
 target-alpha/cpu.h       |   56 +++++++++++++++++++++++++++++++++++----------
 target-alpha/translate.c |    2 +-
 2 files changed, 44 insertions(+), 14 deletions(-)
target-alpha/cpu.h +43 -13
index f6549f9..d8f2514 100644
@@ -290,11 +290,6 @@ struct CPUAlphaState {
 #define cpu_gen_code cpu_alpha_gen_code
 #define cpu_signal_handler cpu_alpha_signal_handler
 
-static inline int cpu_mmu_index (CPUState *env)
-{
-    return (env->ps >> 3) & 1;
-}
-
 #include "cpu-all.h"
 
 enum {
@@ -320,14 +315,49 @@ enum {
     EXCP_STQ_C,
 };
 
-/* Arithmetic exception */
-#define EXC_M_IOV       (1<<16)         /* Integer Overflow */
-#define EXC_M_INE       (1<<15)         /* Inexact result */
-#define EXC_M_UNF       (1<<14)         /* Underflow */
-#define EXC_M_FOV       (1<<13)         /* Overflow */
-#define EXC_M_DZE       (1<<12)         /* Division by zero */
-#define EXC_M_INV       (1<<11)         /* Invalid operation */
-#define EXC_M_SWC       (1<<10)         /* Software completion */
+/* Hardware interrupt (entInt) constants.  */
+enum {
+    INT_K_IP,
+    INT_K_CLK,
+    INT_K_MCHK,
+    INT_K_DEV,
+    INT_K_PERF,
+};
+
+/* Memory management (entMM) constants.  */
+enum {
+    MM_K_TNV,
+    MM_K_ACV,
+    MM_K_FOR,
+    MM_K_FOE,
+    MM_K_FOW
+};
+
+/* Arithmetic exception (entArith) constants.  */
+enum {
+    EXC_M_SWC = 1,      /* Software completion */
+    EXC_M_INV = 2,      /* Invalid operation */
+    EXC_M_DZE = 4,      /* Division by zero */
+    EXC_M_FOV = 8,      /* Overflow */
+    EXC_M_UNF = 16,     /* Underflow */
+    EXC_M_INE = 32,     /* Inexact result */
+    EXC_M_IOV = 64      /* Integer Overflow */
+};
+
+/* Processor status constants.  */
+enum {
+    /* Low 3 bits are interrupt mask level.  */
+    PS_INT_MASK = 7,
+
+    /* Bits 4 and 5 are the mmu mode.  The VMS PALcode uses all 4 modes;
+       The Unix PALcode only uses bit 4.  */
+    PS_USER_MODE = 8
+};
+
+static inline int cpu_mmu_index (CPUState *env)
+{
+    return (env->ps & PS_USER_MODE) != 0;
+}
 
 enum {
     IR_V0   = 0,
target-alpha/translate.c +1 -1
index c8ef31d..2c622b9 100644
@@ -3354,7 +3354,7 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
     env->amask = amask;
 
 #if defined (CONFIG_USER_ONLY)
-    env->ps = 1 << 3;
+    env->ps = PS_USER_MODE;
     cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
                                | FPCR_UNFD | FPCR_INED | FPCR_DNOD));
 #else
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/24 Export the unassigned_mem read/write functions.

In reply to Richard Henderson
---
 cpu-common.h |    7 +++++++
 exec.c       |   12 ++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)
cpu-common.h +7 -0
index 96c02ae..e17020b 100644
@@ -45,6 +45,13 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
     cpu_register_physical_memory_offset(start_addr, size, phys_offset, 0);
 }
 
+extern CPUReadMemoryFunc unassigned_mem_readb;
+extern CPUReadMemoryFunc unassigned_mem_readw;
+extern CPUReadMemoryFunc unassigned_mem_readl;
+extern CPUWriteMemoryFunc unassigned_mem_writeb;
+extern CPUWriteMemoryFunc unassigned_mem_writew;
+extern CPUWriteMemoryFunc unassigned_mem_writel;
+
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
                         ram_addr_t size, void *host);
exec.c +6 -6
index b1ee52a..994d51b 100644
@@ -3090,7 +3090,7 @@ ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr)
     return ram_addr;
 }
 
-static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)
+uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
@@ -3101,7 +3101,7 @@ static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)
     return 0;
 }
 
-static uint32_t unassigned_mem_readw(void *opaque, target_phys_addr_t addr)
+uint32_t unassigned_mem_readw(void *opaque, target_phys_addr_t addr)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
@@ -3112,7 +3112,7 @@ static uint32_t unassigned_mem_readw(void *opaque, target_phys_addr_t addr)
     return 0;
 }
 
-static uint32_t unassigned_mem_readl(void *opaque, target_phys_addr_t addr)
+uint32_t unassigned_mem_readl(void *opaque, target_phys_addr_t addr)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
@@ -3123,7 +3123,7 @@ static uint32_t unassigned_mem_readl(void *opaque, target_phys_addr_t addr)
     return 0;
 }
 
-static void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
+void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
@@ -3133,7 +3133,7 @@ static void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_
 #endif
 }
 
-static void unassigned_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
+void unassigned_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
@@ -3143,7 +3143,7 @@ static void unassigned_mem_writew(void *opaque, target_phys_addr_t addr, uint32_
 #endif
 }
 
-static void unassigned_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
+void unassigned_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
Signature · 1 line
1.7.3.4
#12 lore raw

PATCH 12/24 target-alpha: Implement do_interrupt for system mode.

In reply to Richard Henderson
---
 target-alpha/helper.c |  115 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 105 insertions(+), 10 deletions(-)
target-alpha/helper.c +105 -10
index c5479fd..d5923e0 100644
@@ -160,7 +160,6 @@ void cpu_alpha_store_fpcr (CPUState *env, uint64_t val)
 }
 
 #if defined(CONFIG_USER_ONLY)
-
 int cpu_alpha_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
                                 int mmu_idx, int is_softmmu)
 {
@@ -168,14 +167,7 @@ int cpu_alpha_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
     env->trap_arg0 = address;
     return 1;
 }
-
-void do_interrupt (CPUState *env)
-{
-    env->exception_index = -1;
-}
-
 #else
-
 target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr)
 {
     return -1;
@@ -186,12 +178,115 @@ int cpu_alpha_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
 {
     return 0;
 }
+#endif /* USER_ONLY */
 
 void do_interrupt (CPUState *env)
 {
-    abort();
+    int i = env->exception_index;
+
+    if (qemu_loglevel_mask(CPU_LOG_INT)) {
+        static int count;
+        const char *name = "<unknown>";
+
+        switch (i) {
+        case EXCP_RESET:
+            name = "reset";
+            break;
+        case EXCP_MCHK:
+            name = "mchk";
+            break;
+        case EXCP_CLK_INTERRUPT:
+            name = "clk_interrupt";
+            break;
+        case EXCP_DEV_INTERRUPT:
+            name = "dev_interrupt";
+            break;
+        case EXCP_MMFAULT:
+            name = "mmfault";
+            break;
+        case EXCP_UNALIGN:
+            name = "unalign";
+            break;
+        case EXCP_OPCDEC:
+            name = "opcdec";
+            break;
+        case EXCP_ARITH:
+            name = "arith";
+            break;
+        case EXCP_FEN:
+            name = "fen";
+            break;
+        case EXCP_CALL_PAL:
+            name = "call_pal";
+            break;
+        case EXCP_STL_C:
+            name = "stl_c";
+            break;
+        case EXCP_STQ_C:
+            name = "stq_c";
+            break;
+        }
+        qemu_log("INT %6d: %s(%#x) pc=%016" PRIx64 " sp=%016" PRIx64 "\n",
+                 ++count, name, env->error_code, env->pc, env->ir[IR_SP]);
+    }
+
+    env->exception_index = -1;
+
+#if !defined(CONFIG_USER_ONLY)
+    switch (i) {
+    case EXCP_RESET:
+        i = 0x0000;
+        break;
+    case EXCP_MCHK:
+        i = 0x0080;
+        break;
+    case EXCP_CLK_INTERRUPT:
+        i = 0x0100;
+        break;
+    case EXCP_DEV_INTERRUPT:
+        i = 0x0180;
+        break;
+    case EXCP_MMFAULT:
+        i = 0x0200;
+        break;
+    case EXCP_UNALIGN:
+        i = 0x0280;
+        break;
+    case EXCP_OPCDEC:
+        i = 0x0300;
+        break;
+    case EXCP_ARITH:
+        i = 0x0380;
+        break;
+    case EXCP_FEN:
+        i = 0x0400;
+        break;
+    case EXCP_CALL_PAL:
+        i = env->error_code;
+        /* There are 64 entry points for both privilaged and unprivlaged,
+           with bit 0x80 indicating unprivlaged.  Each entry point gets
+           64 bytes to do its job.  */
+        if (i & 0x80) {
+            i = 0x2000 + (i - 0x80) * 64;
+        } else {
+            i = 0x1000 + i * 64;
+        }
+        break;
+    default:
+        cpu_abort(env, "Unhandled CPU exception");
+    }
+
+    /* Remember where the exception happened.  Emulate real hardware in
+       that the low bit of the PC indicates PALmode.  */
+    env->exc_addr = env->pc | env->pal_mode;
+
+    /* Continue execution at the PALcode entry point.  */
+    env->pc = env->palbr + i;
+
+    /* Switch to PALmode.  */
+    env->pal_mode = 1;
+#endif /* !USER_ONLY */
 }
-#endif
 
 void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
                      int flags)
Signature · 1 line
1.7.3.4
#16 lore raw

PATCH 16/24 target-alpha: Disable interrupts properly.

In reply to Richard Henderson

Interrupts are disabled in PALmode, and when the PS IL is high enough. We don't actually get the interrupt levels correct yet; settle for interrupts enabled only at IL0.

---
 cpu-exec.c          |   16 +++++++++++++---
 target-alpha/exec.h |    7 ++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)
cpu-exec.c +13 -3
index 5d6c9a8..68c3d1d 100644
@@ -529,9 +529,19 @@ int cpu_exec(CPUState *env1)
                         next_tb = 0;
                     }
 #elif defined(TARGET_ALPHA)
-                    if (interrupt_request & CPU_INTERRUPT_HARD) {
-                        do_interrupt(env);
-                        next_tb = 0;
+                    if (env->pal_mode == 0 && (env->ps & PS_INT_MASK) == 0) {
+                        int idx = -1;
+                        if (interrupt_request & CPU_INTERRUPT_HARD) {
+                            idx = EXCP_DEV_INTERRUPT;
+                        }
+                        if (interrupt_request & CPU_INTERRUPT_TIMER) {
+                            idx = EXCP_CLK_INTERRUPT;
+                        }
+                        if (idx >= 0) {
+                            env->exception_index = idx;
+                            do_interrupt(env);
+                            next_tb = 0;
+                        }
                     }
 #elif defined(TARGET_CRIS)
                     if (interrupt_request & CPU_INTERRUPT_HARD
target-alpha/exec.h +6 -1
index 6ae96d1..a504758 100644
@@ -39,7 +39,12 @@ register struct CPUAlphaState *env asm(AREG0);
 
 static inline int cpu_has_work(CPUState *env)
 {
-    return (env->interrupt_request & CPU_INTERRUPT_HARD);
+    /* ??? There's a model-specific mapping between external hardware
+       interrupt numbers and the Unix PALcode interrupt levels.  */
+    int req = CPU_INTERRUPT_HARD | CPU_INTERRUPT_TIMER;
+    return ((env->interrupt_request & req)
+            && env->pal_mode == 0
+            && (env->ps & PS_INT_MASK) == 0);
 }
 
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
Signature · 1 line
1.7.3.4
#23 lore raw

PATCH 23/24 target-alpha: Enable the alpha-softmmu target.

In reply to Richard Henderson

Compiles, but no machine defined yet, so this will crash on startup.

---
 Makefile.target                   |    3 +-
 configure                         |    1 +
 default-configs/alpha-softmmu.mak |    9 ++++
 target-alpha/machine.c            |   87 +++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 1 deletions(-)
 create mode 100644 default-configs/alpha-softmmu.mak
 create mode 100644 target-alpha/machine.c
Makefile.target +2 -1
index 5ea7ce1..443679b 100644
@@ -362,7 +362,8 @@ obj-m68k-y += m68k-semi.o dummy_m68k.o
 
 obj-s390x-y = s390-virtio-bus.o s390-virtio.o
 
-obj-alpha-y = 
+obj-alpha-y += i8259.o mc146818rtc.o
+obj-alpha-y += vga.o cirrus_vga.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
configure +1 -0
index 4a93972..872747f 100755
@@ -1011,6 +1011,7 @@ if test -z "$target_list" ; then
         target_list="\
 i386-softmmu \
 x86_64-softmmu \
+alpha-softmmu \
 arm-softmmu \
 cris-softmmu \
 lm32-softmmu \
default-configs/alpha-softmmu.mak new file +9 -0
new file mode 100644
index 0000000..abadcff
@@ -0,0 +1,9 @@
+# Default configuration for alpha-softmmu
+
+include pci.mak
+CONFIG_SERIAL=y
+CONFIG_I8254=y
+CONFIG_VGA_PCI=y
+CONFIG_IDE_CORE=y
+CONFIG_IDE_QDEV=y
+CONFIG_VMWARE_VGA=y
target-alpha/machine.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#6 lore raw

PATCH 6/24 target-alpha: Rationalize internal processor registers.

In reply to Richard Henderson

Delete all the code that tried to emulate the real IPRs of some unnamed CPU. Replace those with just 3 slots that we can use to communicate trap information between the helper functions that signal exceptions and the OS trap handler.

---
 linux-user/main.c        |    6 +-
 target-alpha/cpu.h       |  147 ++------------------
 target-alpha/helper.c    |  348 +---------------------------------------------
 target-alpha/helper.h    |    2 -
 target-alpha/op_helper.c |   17 +--
 target-alpha/translate.c |   31 +----
 6 files changed, 20 insertions(+), 531 deletions(-)
linux-user/main.c +3 -3
index 5b25736..503d7b8 100644
@@ -2535,9 +2535,9 @@ void cpu_loop (CPUState *env)
             env->lock_addr = -1;
             info.si_signo = TARGET_SIGSEGV;
             info.si_errno = 0;
-            info.si_code = (page_get_flags(env->ipr[IPR_EXC_ADDR]) & PAGE_VALID
+            info.si_code = (page_get_flags(env->trap_arg0) & PAGE_VALID
                             ? TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR);
-            info._sifields._sigfault._addr = env->ipr[IPR_EXC_ADDR];
+            info._sifields._sigfault._addr = env->trap_arg0;
             queue_signal(env, info.si_signo, &info);
             break;
         case EXCP_UNALIGN:
@@ -2545,7 +2545,7 @@ void cpu_loop (CPUState *env)
             info.si_signo = TARGET_SIGBUS;
             info.si_errno = 0;
             info.si_code = TARGET_BUS_ADRALN;
-            info._sifields._sigfault._addr = env->ipr[IPR_EXC_ADDR];
+            info._sifields._sigfault._addr = env->trap_arg0;
             queue_signal(env, info.si_signo, &info);
             break;
         case EXCP_OPCDEC:
target-alpha/cpu.h +11 -136

185 lines not on this page · raw message

target-alpha/helper.c +4 -344

370 lines not on this page · raw message

target-alpha/helper.h +0 -2
index ccf6a2a..7435c61 100644
@@ -102,8 +102,6 @@ DEF_HELPER_1(ieee_input_s, i64, i64)
 #if !defined (CONFIG_USER_ONLY)
 DEF_HELPER_0(hw_rei, void)
 DEF_HELPER_1(hw_ret, void, i64)
-DEF_HELPER_2(mfpr, i64, int, i64)
-DEF_HELPER_2(mtpr, void, int, i64)
 DEF_HELPER_0(set_alt_mode, void)
 DEF_HELPER_0(restore_mode, void)
 
target-alpha/op_helper.c +1 -16
index 6c2ae20..5b3f12d 100644
@@ -373,7 +373,7 @@ void helper_fp_exc_raise(uint32_t exc, uint32_t regno)
     if (exc) {
         uint32_t hw_exc = 0;
 
-        env->ipr[IPR_EXC_MASK] |= 1ull << regno;
+        env->trap_arg1 = 1ull << regno;
 
         if (exc & float_flag_invalid) {
             hw_exc |= EXC_M_INV;
@@ -1173,21 +1173,6 @@ void helper_hw_ret (uint64_t a)
     /* XXX: re-enable interrupts and memory mapping */
 }
 
-uint64_t helper_mfpr (int iprn, uint64_t val)
-{
-    uint64_t tmp;
-
-    if (cpu_alpha_mfpr(env, iprn, &tmp) == 0)
-        val = tmp;
-
-    return val;
-}
-
-void helper_mtpr (int iprn, uint64_t val)
-{
-    cpu_alpha_mtpr(env, iprn, val, NULL);
-}
-
 void helper_set_alt_mode (void)
 {
     env->saved_mode = env->ps & 0xC;
target-alpha/translate.c +1 -30
index 3a023a5..e52fa0a 100644
@@ -3325,42 +3325,13 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
     env->implver = implver;
     env->amask = amask;
 
-    env->ps = 0x1F00;
 #if defined (CONFIG_USER_ONLY)
-    env->ps |= 1 << 3;
+    env->ps = 1 << 3;
     cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
                                | FPCR_UNFD | FPCR_INED | FPCR_DNOD));
 #endif
     env->lock_addr = -1;
 
-    /* Initialize IPR */
-#if defined (CONFIG_USER_ONLY)
-    env->ipr[IPR_EXC_ADDR] = 0;
-    env->ipr[IPR_EXC_SUM] = 0;
-    env->ipr[IPR_EXC_MASK] = 0;
-#else
-    {
-        // uint64_t hwpcb;
-        // hwpcb = env->ipr[IPR_PCBB];
-        env->ipr[IPR_ASN] = 0;
-        env->ipr[IPR_ASTEN] = 0;
-        env->ipr[IPR_ASTSR] = 0;
-        env->ipr[IPR_DATFX] = 0;
-        /* XXX: fix this */
-        //    env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
-        //    env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
-        //    env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
-        //    env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
-        env->ipr[IPR_FEN] = 0;
-        env->ipr[IPR_IPL] = 31;
-        env->ipr[IPR_MCES] = 0;
-        env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
-        //    env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
-        env->ipr[IPR_SISR] = 0;
-        env->ipr[IPR_VIRBND] = -1ULL;
-    }
-#endif
-
     qemu_init_vcpu(env);
     return env;
 }
Signature · 1 line
1.7.3.4
#8 lore raw

PATCH 8/24 target-alpha: Fixup translation of PALmode instructions.

In reply to Richard Henderson

All of the "raw" memory accesses should be "phys" instead. Fix some confusion about argument ordering of the store routines. Fix the implementation of store-conditional.

Delete the "alt-mode" helpers. Because we only implement two mmu modes, let /a imply user-mode unconditionally.

For the moment, stub out HW_MTPR and HW_MFPR.

Merge hw_rei with hw_ret.

---
 target-alpha/cpu.h       |    4 +
 target-alpha/helper.h    |   27 +++-----
 target-alpha/op_helper.c |  159 ++++++++++------------------------------------
 target-alpha/translate.c |  130 ++++++++++----------------------------
 4 files changed, 82 insertions(+), 238 deletions(-)
target-alpha/cpu.h +4 -0
index 4737b83..1c848bd 100644
@@ -192,6 +192,8 @@ enum {
 
 #define SWCR_MASK  (SWCR_TRAP_ENABLE_MASK | SWCR_MAP_MASK | SWCR_STATUS_MASK)
 
+#define CPU_SAVE_VERSION        1
+
 /* MMU modes definitions */
 
 /* Alpha has 5 MMU modes: PALcode, kernel, executive, supervisor, and user.
@@ -243,6 +245,8 @@ struct CPUAlphaState {
        exist for use in user-mode.  */
     uint8_t ps;
     uint8_t intr_flag;
+    uint8_t fen;
+    uint8_t pal_mode;
 
     /* These pass data from the exception logic in the translator and
        helpers to the OS entry point.  This is used for both system
target-alpha/helper.h +9 -18
index 7435c61..9ffc372 100644
@@ -100,25 +100,16 @@ DEF_HELPER_1(ieee_input_cmp, i64, i64)
 DEF_HELPER_1(ieee_input_s, i64, i64)
 
 #if !defined (CONFIG_USER_ONLY)
-DEF_HELPER_0(hw_rei, void)
 DEF_HELPER_1(hw_ret, void, i64)
-DEF_HELPER_0(set_alt_mode, void)
-DEF_HELPER_0(restore_mode, void)
-
-DEF_HELPER_1(ld_virt_to_phys, i64, i64)
-DEF_HELPER_1(st_virt_to_phys, i64, i64)
-DEF_HELPER_2(ldl_raw, void, i64, i64)
-DEF_HELPER_2(ldq_raw, void, i64, i64)
-DEF_HELPER_2(ldl_l_raw, void, i64, i64)
-DEF_HELPER_2(ldq_l_raw, void, i64, i64)
-DEF_HELPER_2(ldl_kernel, void, i64, i64)
-DEF_HELPER_2(ldq_kernel, void, i64, i64)
-DEF_HELPER_2(ldl_data, void, i64, i64)
-DEF_HELPER_2(ldq_data, void, i64, i64)
-DEF_HELPER_2(stl_raw, void, i64, i64)
-DEF_HELPER_2(stq_raw, void, i64, i64)
-DEF_HELPER_2(stl_c_raw, i64, i64, i64)
-DEF_HELPER_2(stq_c_raw, i64, i64, i64)
+
+DEF_HELPER_1(ldl_phys, i64, i64)
+DEF_HELPER_1(ldq_phys, i64, i64)
+DEF_HELPER_1(ldl_l_phys, i64, i64)
+DEF_HELPER_1(ldq_l_phys, i64, i64)
+DEF_HELPER_2(stl_phys, void, i64, i64)
+DEF_HELPER_2(stq_phys, void, i64, i64)
+DEF_HELPER_2(stl_c_phys, i64, i64, i64)
+DEF_HELPER_2(stq_c_phys, i64, i64, i64)
 #endif
 
 #include "def-helper.h"
target-alpha/op_helper.c +35 -124

202 lines not on this page · raw message

target-alpha/translate.c +34 -96

251 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#0 lore raw

cover Alpha system emulation, v2

Changes from v1 to v2:
- Split patch 5 up into little pieces. These pieces were compile tested by applying patch 23 (Enable alpha-softmmu) out of sequence so that both softmmu and linux-user targets were built. But in the end I chickened out and re-ordered the enable patch to last.

- The TB->FLAGS patch is more comprehensive. In doing the split I noticed that we were doing funny things with AMASK that really ought to have belonged in the TB in the first place.

- The patch for unassigned addresses is more comprehensive. I had previously failed to do the if-deffing dance in the generic part of QEMU.

- The PALcode source is added as a submodule.

r~

Richard Henderson (24):
Export the unassigned_mem read/write functions.
target-alpha: Disassemble EV6 PALcode instructions.
pci: Export pci_to_cpu_addr.
target-alpha: Remove partial support for palcode emulation.
target-alpha: Tidy exception constants.
target-alpha: Rationalize internal processor registers.
target-alpha: Cleanup MMU modes.
target-alpha: Fixup translation of PALmode instructions.
target-alpha: Add IPRs to be used by the emulation PALcode.
target-alpha: Tidy up arithmetic exceptions.
target-alpha: Merge HW_REI and HW_RET implementations.
target-alpha: Implement do_interrupt for system mode.
target-alpha: Swap shadow registers moving to/from PALmode.
target-alpha: Add various symbolic constants.
target-alpha: All ISA checks to use TB->FLAGS.
target-alpha: Disable interrupts properly.
target-alpha: Implement more CALL_PAL values inline.
target-alpha: Add custom PALcode image for SX164 emulation.
target-alpha: Implement cpu_alpha_handle_mmu_fault for system mode.
target-alpha: Trap for unassigned and unaligned addresses.
target-alpha: Include the PCC_OFS in the RPCC return value.
target-alpha: Implement TLB flush primitives.
target-alpha: Enable the alpha-softmmu target.
target-alpha: Add SX164 emulation.

 .gitmodules                       |    3 +
 Makefile                          |    3 +-
 Makefile.target                   |    4 +-
 alpha-dis.c                       |    4 -
 configure                         |    3 +-
 cpu-common.h                      |    7 +
 cpu-exec.c                        |   16 +-
 default-configs/alpha-softmmu.mak |    9 +
 dis-asm.h                         |    3 +
 disas.c                           |    2 +-
 exec-all.h                        |    2 +-
 exec.c                            |   24 +-
 hw/alpha_palcode.c                | 1048 ------------------------------------
 hw/alpha_pci.c                    |  327 ++++++++++++
 hw/alpha_pyxis.c                  | 1057 +++++++++++++++++++++++++++++++++++++
 hw/alpha_sx164.c                  |  195 +++++++
 hw/alpha_sys.h                    |   41 ++
 hw/pci.c                          |    3 +-
 hw/pci.h                          |    1 +
 linux-user/main.c                 |   49 +--
 pc-bios/palcode-sx164             |  Bin 0 -> 107621 bytes
 roms/qemu-palcode                 |    1 +
 target-alpha/cpu.h                |  363 ++++++--------
 target-alpha/exec.h               |    7 +-
 target-alpha/helper.c             |  581 +++++++++------------
 target-alpha/helper.h             |   32 +-
 target-alpha/machine.c            |   87 +++
 target-alpha/op_helper.c          |  236 ++++-----
 target-alpha/translate.c          |  771 ++++++++++++++++------------
 29 files changed, 2734 insertions(+), 2145 deletions(-)
 create mode 100644 default-configs/alpha-softmmu.mak
 delete mode 100644 hw/alpha_palcode.c
 create mode 100644 hw/alpha_pci.c
 create mode 100644 hw/alpha_pyxis.c
 create mode 100644 hw/alpha_sx164.c
 create mode 100644 hw/alpha_sys.h
 create mode 100644 pc-bios/palcode-sx164
 create mode 160000 roms/qemu-palcode
 create mode 100644 target-alpha/machine.c
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 2/24 target-alpha: Disassemble EV6 PALcode instructions.

The QEMU emulation PALcode will use EV6 PALcode insns regardless of the "real" cpu instruction set being emulated.

---
 alpha-dis.c |    4 ----
 dis-asm.h   |    3 +++
 disas.c     |    2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)
alpha-dis.c +0 -4
index 8a2411e..ae331b3 100644
@@ -238,10 +238,6 @@ extern const unsigned alpha_num_operands;
 #define AXP_REG_SP	30
 #define AXP_REG_ZERO	31
 
-#define bfd_mach_alpha_ev4  0x10
-#define bfd_mach_alpha_ev5  0x20
-#define bfd_mach_alpha_ev6  0x30
-
 enum bfd_reloc_code_real {
     BFD_RELOC_23_PCREL_S2,
     BFD_RELOC_ALPHA_HINT
dis-asm.h +3 -0
index 296537a..5b07d7f 100644
@@ -184,6 +184,9 @@ enum bfd_architecture
 #define bfd_mach_sh5        0x50
   bfd_arch_alpha,      /* Dec Alpha */
 #define bfd_mach_alpha 1
+#define bfd_mach_alpha_ev4  0x10
+#define bfd_mach_alpha_ev5  0x20
+#define bfd_mach_alpha_ev6  0x30
   bfd_arch_arm,        /* Advanced Risc Machines ARM */
 #define bfd_mach_arm_unknown	0
 #define bfd_mach_arm_2		1
disas.c +1 -1
index 223606c..d208c52 100644
@@ -205,7 +205,7 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
     disasm_info.mach = bfd_mach_sh4;
     print_insn = print_insn_sh;
 #elif defined(TARGET_ALPHA)
-    disasm_info.mach = bfd_mach_alpha;
+    disasm_info.mach = bfd_mach_alpha_ev6;
     print_insn = print_insn_alpha;
 #elif defined(TARGET_CRIS)
     if (flags != 32) {
Signature · 1 line
1.7.3.4
#13 lore raw

PATCH 13/24 target-alpha: Swap shadow registers moving to/from PALmode.

In reply to Richard Henderson
---
 target-alpha/cpu.h       |    1 +
 target-alpha/helper.c    |   37 ++++++++++++++++++++++++++++++++++++-
 target-alpha/op_helper.c |    5 ++++-
 3 files changed, 41 insertions(+), 2 deletions(-)
target-alpha/cpu.h +1 -0
index dec8b26..f6549f9 100644
@@ -380,6 +380,7 @@ void do_interrupt (CPUState *env);
 
 uint64_t cpu_alpha_load_fpcr (CPUState *env);
 void cpu_alpha_store_fpcr (CPUState *env, uint64_t val);
+extern void swap_shadow_regs(CPUState *env);
 
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
                                         target_ulong *cs_base, int *flags)
target-alpha/helper.c +36 -1
index d5923e0..ce5f257 100644
@@ -168,6 +168,38 @@ int cpu_alpha_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
     return 1;
 }
 #else
+void swap_shadow_regs(CPUState *env)
+{
+    uint64_t i0, i1, i2, i3, i4, i5, i6, i7;
+
+    i0 = env->ir[8];
+    i1 = env->ir[9];
+    i2 = env->ir[10];
+    i3 = env->ir[11];
+    i4 = env->ir[12];
+    i5 = env->ir[13];
+    i6 = env->ir[14];
+    i7 = env->ir[25];
+
+    env->ir[8]  = env->shadow[0];
+    env->ir[9]  = env->shadow[1];
+    env->ir[10] = env->shadow[2];
+    env->ir[11] = env->shadow[3];
+    env->ir[12] = env->shadow[4];
+    env->ir[13] = env->shadow[5];
+    env->ir[14] = env->shadow[6];
+    env->ir[25] = env->shadow[7];
+
+    env->shadow[0] = i0;
+    env->shadow[1] = i1;
+    env->shadow[2] = i2;
+    env->shadow[3] = i3;
+    env->shadow[4] = i4;
+    env->shadow[5] = i5;
+    env->shadow[6] = i6;
+    env->shadow[7] = i7;
+}
+
 target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr)
 {
     return -1;
@@ -284,7 +316,10 @@ void do_interrupt (CPUState *env)
     env->pc = env->palbr + i;
 
     /* Switch to PALmode.  */
-    env->pal_mode = 1;
+    if (!env->pal_mode) {
+        env->pal_mode = 1;
+        swap_shadow_regs(env);
+    }
 #endif /* !USER_ONLY */
 }
 
target-alpha/op_helper.c +4 -1
index 9c19c96..d502bca 100644
@@ -1166,9 +1166,12 @@ uint64_t helper_cvtqg (uint64_t a)
 void helper_hw_ret (uint64_t a)
 {
     env->pc = a & ~3;
-    env->pal_mode = a & 1;
     env->intr_flag = 0;
     env->lock_addr = -1;
+    if ((a & 1) == 0) {
+        env->pal_mode = 0;
+        swap_shadow_regs(env);
+    }
 }
 #endif
 
Signature · 1 line
1.7.3.4
#20 lore raw

PATCH 20/24 target-alpha: Trap for unassigned and unaligned addresses.

In reply to Richard Henderson
---
 exec-all.h               |    2 +-
 exec.c                   |   12 ++++++------
 target-alpha/cpu.h       |    6 +++++-
 target-alpha/op_helper.c |   39 ++++++++++++++++++++++++++++++++++++++-
 4 files changed, 50 insertions(+), 9 deletions(-)
exec-all.h +1 -1
index 496c001..e525662 100644
@@ -323,7 +323,7 @@ static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong add
     }
     pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK;
     if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
-#if defined(TARGET_SPARC) || defined(TARGET_MIPS)
+#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SPARC)
         do_unassigned_access(addr, 0, 1, 0, 4);
 #else
         cpu_abort(env1, "Trying to execute code outside RAM or ROM at 0x" TARGET_FMT_lx "\n", addr);
exec.c +6 -6
index 994d51b..c3c2809 100644
@@ -3095,7 +3095,7 @@ uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 0, 0, 0, 1);
 #endif
     return 0;
@@ -3106,7 +3106,7 @@ uint32_t unassigned_mem_readw(void *opaque, target_phys_addr_t addr)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 0, 0, 0, 2);
 #endif
     return 0;
@@ -3117,7 +3117,7 @@ uint32_t unassigned_mem_readl(void *opaque, target_phys_addr_t addr)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 0, 0, 0, 4);
 #endif
     return 0;
@@ -3128,7 +3128,7 @@ void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 1, 0, 0, 1);
 #endif
 }
@@ -3138,7 +3138,7 @@ void unassigned_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 1, 0, 0, 2);
 #endif
 }
@@ -3148,7 +3148,7 @@ void unassigned_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
-#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
     do_unassigned_access(addr, 1, 0, 0, 4);
 #endif
 }
target-alpha/cpu.h +5 -1
index d133cc6..f64dcd1 100644
@@ -422,7 +422,11 @@ void do_interrupt (CPUState *env);
 
 uint64_t cpu_alpha_load_fpcr (CPUState *env);
 void cpu_alpha_store_fpcr (CPUState *env, uint64_t val);
-extern void swap_shadow_regs(CPUState *env);
+#ifndef CONFIG_USER_ONLY
+void swap_shadow_regs(CPUState *env);
+extern QEMU_NORETURN void do_unassigned_access(target_phys_addr_t addr,
+                                               int, int, int, int);
+#endif
 
 /* Bits in TB->FLAGS that control how translation is processed.  */
 enum {
target-alpha/op_helper.c +38 -1
index d502bca..cc8a33d 100644
@@ -1242,7 +1242,44 @@ uint64_t helper_stq_c_phys(uint64_t p, uint64_t v)
     return ret;
 }
 
+static void do_restore_state(void *pc_ptr)
+{
+    TranslationBlock *tb;
+    unsigned long pc = (unsigned long) pc_ptr;
+
+    tb = tb_find_pc(pc);
+    if (tb) {
+        cpu_restore_state(tb, env, pc, NULL);
+    }
+}
+
+static void QEMU_NORETURN do_unaligned_access(target_ulong addr, int is_write,
+                                              int is_user, void *retaddr)
+{
+    uint64_t pc;
+    uint32_t insn;
+
+    do_restore_state(retaddr);
+
+    pc = env->pc;
+    insn = ldl_code(pc);
+
+    env->trap_arg0 = addr;
+    env->trap_arg1 = insn >> 26;                /* opcode */
+    env->trap_arg2 = (insn >> 21) & 31;         /* dest regno */
+    helper_excp(EXCP_UNALIGN, 0);
+}
+
+void QEMU_NORETURN do_unassigned_access(target_phys_addr_t addr, int is_write,
+                                        int is_exec, int unused, int size)
+{
+    env->trap_arg0 = addr;
+    env->trap_arg1 = is_write;
+    helper_excp(EXCP_MCHK, 0);
+}
+
 #define MMUSUFFIX _mmu
+#define ALIGNED_ONLY
 
 #define SHIFT 0
 #include "softmmu_template.h"
@@ -1272,7 +1309,7 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
     saved_env = env;
     env = cpu_single_env;
     ret = cpu_alpha_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
-    if (!likely(ret == 0)) {
+    if (unlikely(ret != 0)) {
         if (likely(retaddr)) {
             /* now we have a real cpu fault */
             pc = (unsigned long)retaddr;
Signature · 1 line
1.7.3.4
#4 lore raw

PATCH 4/24 target-alpha: Remove partial support for palcode emulation.

In reply to Richard Henderson

This code does not work, and will be replaced by a bios image.

---
 Makefile.target          |    2 +-
 hw/alpha_palcode.c       | 1048 ----------------------------------------------
 target-alpha/cpu.h       |   35 --
 target-alpha/helper.c    |    2 +-
 target-alpha/translate.c |    2 -
 5 files changed, 2 insertions(+), 1087 deletions(-)
 delete mode 100644 hw/alpha_palcode.c
Makefile.target +1 -1
index d5761b7..5ea7ce1 100644
@@ -362,7 +362,7 @@ obj-m68k-y += m68k-semi.o dummy_m68k.o
 
 obj-s390x-y = s390-virtio-bus.o s390-virtio.o
 
-obj-alpha-y = alpha_palcode.o
+obj-alpha-y = 
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
hw/alpha_palcode.c deleted +0 -1048

1,048 lines not on this page · raw message

target-alpha/cpu.h +0 -35
index 686fb4a..0daa556 100644
@@ -319,36 +319,6 @@ enum {
 
 typedef struct CPUAlphaState CPUAlphaState;
 
-typedef struct pal_handler_t pal_handler_t;
-struct pal_handler_t {
-    /* Reset */
-    void (*reset)(CPUAlphaState *env);
-    /* Uncorrectable hardware error */
-    void (*machine_check)(CPUAlphaState *env);
-    /* Arithmetic exception */
-    void (*arithmetic)(CPUAlphaState *env);
-    /* Interrupt / correctable hardware error */
-    void (*interrupt)(CPUAlphaState *env);
-    /* Data fault */
-    void (*dfault)(CPUAlphaState *env);
-    /* DTB miss pal */
-    void (*dtb_miss_pal)(CPUAlphaState *env);
-    /* DTB miss native */
-    void (*dtb_miss_native)(CPUAlphaState *env);
-    /* Unaligned access */
-    void (*unalign)(CPUAlphaState *env);
-    /* ITB miss */
-    void (*itb_miss)(CPUAlphaState *env);
-    /* Instruction stream access violation */
-    void (*itb_acv)(CPUAlphaState *env);
-    /* Reserved or privileged opcode */
-    void (*opcdec)(CPUAlphaState *env);
-    /* Floating point exception */
-    void (*fen)(CPUAlphaState *env);
-    /* Call pal instruction */
-    void (*call_pal)(CPUAlphaState *env, uint32_t palcode);
-};
-
 #define NB_MMU_MODES 4
 
 struct CPUAlphaState {
@@ -393,7 +363,6 @@ struct CPUAlphaState {
     uint32_t features;
     uint32_t amask;
     int implver;
-    pal_handler_t *pal_handler;
 };
 
 #define cpu_init cpu_alpha_init
@@ -506,10 +475,6 @@ uint64_t cpu_alpha_load_fpcr (CPUState *env);
 void cpu_alpha_store_fpcr (CPUState *env, uint64_t val);
 int cpu_alpha_mfpr (CPUState *env, int iprn, uint64_t *valp);
 int cpu_alpha_mtpr (CPUState *env, int iprn, uint64_t val, uint64_t *oldvalp);
-#if !defined (CONFIG_USER_ONLY)
-void pal_init (CPUState *env);
-void call_pal (CPUState *env);
-#endif
 
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
                                         target_ulong *cs_base, int *flags)
target-alpha/helper.c +1 -1
index 3ba4478..f7cf4ee 100644
@@ -528,7 +528,7 @@ void do_interrupt (CPUState *env)
         env->pc = env->ipr[IPR_PAL_BASE] + excp;
     } else {
         /* We use emulated PALcode */
-        call_pal(env);
+        abort();
         /* Emulate REI */
         env->pc = env->ipr[IPR_EXC_ADDR] & ~7;
         env->ipr[IPR_EXC_ADDR] = env->ipr[IPR_EXC_ADDR] & 1;
target-alpha/translate.c +0 -2
index 96e922b..699c70d 100644
@@ -3330,8 +3330,6 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
     env->ps |= 1 << 3;
     cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
                                | FPCR_UNFD | FPCR_INED | FPCR_DNOD));
-#else
-    pal_init(env);
 #endif
     env->lock_addr = -1;
 
Signature · 1 line
1.7.3.4
#18 lore raw

PATCH 18/24 target-alpha: Add custom PALcode image for SX164 emulation.

In reply to Richard Henderson
---
 .gitmodules           |    3 +++
 Makefile              |    3 ++-
 configure             |    2 +-
 pc-bios/palcode-sx164 |  Bin 0 -> 107621 bytes
 roms/qemu-palcode     |    1 +
 5 files changed, 7 insertions(+), 2 deletions(-)
 create mode 100644 pc-bios/palcode-sx164
 create mode 160000 roms/qemu-palcode
.gitmodules +3 -0
index 44fdd1a..a9a30d4 100644
@@ -7,3 +7,6 @@
 [submodule "roms/SLOF"]
 	path = roms/SLOF
 	url = git://git.qemu.org/SLOF.git
+[submodule "roms/qemu-palcode"]
+	path = roms/qemu-palcode
+	url = git://repo.or.cz/qemu-palcode.git
Makefile +2 -1
index dc39efd..d8a802e 100644
@@ -187,7 +187,8 @@ pxe-rtl8139.bin pxe-virtio.bin \
 bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
 multiboot.bin linuxboot.bin \
 s390-zipl.rom \
-spapr-rtas.bin slof.bin
+spapr-rtas.bin slof.bin \
+palcode-sx164
 else
 BLOBS=
 endif
configure +1 -1
index da2da04..4a93972 100755
@@ -3454,7 +3454,7 @@ FILES="Makefile tests/Makefile"
 FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
 FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
 FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
-for bios_file in $source_path/pc-bios/*.bin $source_path/pc-bios/*.dtb $source_path/pc-bios/openbios-*; do
+for bios_file in $source_path/pc-bios/*.bin $source_path/pc-bios/*.dtb $source_path/pc-bios/openbios-* $source_path/pc-bios/palcode-*; do
     FILES="$FILES pc-bios/`basename $bios_file`"
 done
 mkdir -p $DIRS
pc-bios/palcode-sx164 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..71626214e61173e7cdfdb18dacbfe16f8eba7b3b
GIT binary patch
roms/qemu-palcode new file +1 -0
new file mode 160000
index 0000000..2eec0e4
@@ -0,0 +1 @@
+Subproject commit 2eec0e49ac23330ed8a866a4b3f268be4af09e34
Signature · 1 line
1.7.3.4
#7 lore raw

PATCH 7/24 target-alpha: Cleanup MMU modes.

In reply to Richard Henderson

Don't bother including executive and supervisor modes.

---
 target-alpha/cpu.h |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)
target-alpha/cpu.h +28 -8
index e977705..4737b83 100644
@@ -192,6 +192,33 @@ enum {
 
 #define SWCR_MASK  (SWCR_TRAP_ENABLE_MASK | SWCR_MAP_MASK | SWCR_STATUS_MASK)
 
+/* MMU modes definitions */
+
+/* Alpha has 5 MMU modes: PALcode, kernel, executive, supervisor, and user.
+   The Unix PALcode only exposes the kernel and user modes; presumably
+   executive and supervisor are used by VMS.
+
+   PALcode itself uses physical mode for code and kernel mode for data;
+   there are PALmode instructions that can access data via physical mode
+   or via an os-installed "alternate mode", which is one of the 4 above.
+
+   QEMU does not currently properly distinguish between code/data when
+   looking up addresses.  To avoid having to address this issue, our
+   emulated PALcode will cheat and use the KSEG mapping for its code+data
+   rather than physical addresses.
+
+   Moreover, we're only emulating Unix PALcode, and not attempting VMS.
+
+   All of which allows us to drop all but kernel and user modes.
+   Elide the unused MMU modes to save space.  */
+
+#define NB_MMU_MODES 2
+
+#define MMU_MODE0_SUFFIX _kernel
+#define MMU_MODE1_SUFFIX _user
+#define MMU_KERNEL_IDX   0
+#define MMU_USER_IDX     1
+
 typedef struct CPUAlphaState CPUAlphaState;
 
 struct CPUAlphaState {
@@ -246,16 +273,9 @@ struct CPUAlphaState {
 #define cpu_gen_code cpu_alpha_gen_code
 #define cpu_signal_handler cpu_alpha_signal_handler
 
-/* MMU modes definitions */
-#define NB_MMU_MODES 4
-#define MMU_MODE0_SUFFIX _kernel
-#define MMU_MODE1_SUFFIX _executive
-#define MMU_MODE2_SUFFIX _supervisor
-#define MMU_MODE3_SUFFIX _user
-#define MMU_USER_IDX 3
 static inline int cpu_mmu_index (CPUState *env)
 {
-    return (env->ps >> 3) & 3;
+    return (env->ps >> 3) & 1;
 }
 
 #include "cpu-all.h"
Signature · 1 line
1.7.3.4
#25 lore raw
In reply to Richard Henderson
Quoted 10 lines · Richard Henderson

Changes from v1 to v2:
- Split patch 5 up into little pieces. These pieces were compile tested by applying patch 23 (Enable alpha-softmmu) out of sequence so that both softmmu and linux-user targets were built. But in the end I chickened out and re-ordered the enable patch to last.

- The TB->FLAGS patch is more comprehensive. In doing the split I noticed that we were doing funny things with AMASK that really ought to have belonged in the TB in the first place.

Quoted 5 lines

- The patch for unassigned addresses is more comprehensive. I had previously failed to do the if-deffing dance in the generic part of QEMU.

- The PALcode source is added as a submodule.

Richard,

it looks like I miss the v1. Anyway, some random comments:

* thank you for working on that!

* sx164 is ev56 based, isn't it ? It would be nice if cpu version specific code is clearly marked. In particular (and IIRC), pal mode for ev6 is much closer to ev4 than to ev5. Don't know about ev7. It would be nice if we could easily support both ev5 and ev6.

* Yes, executive and supervisor are used only by VMS (well AFAIK). I'd like to support it. Did you try to also support the windows mmu mode ?

* Again, thank you for working on that.

Tristan.

#26 lore raw

I'd like to second Tristan in saying that I'm glad someone is working on alpha system emulation -- its long overdue!

Brian

Quoted 37 lines · Tristan Gingold
Quoted 10 lines · Richard Henderson

Changes from v1 to v2:
- Split patch 5 up into little pieces. These pieces were compile tested by applying patch 23 (Enable alpha-softmmu) out of sequence so that both softmmu and linux-user targets were built. But in the end I chickened out and re-ordered the enable patch to last.

- The TB->FLAGS patch is more comprehensive. In doing the split I noticed that we were doing funny things with AMASK that really ought to have belonged in the TB in the first place.

Quoted 5 lines

- The patch for unassigned addresses is more comprehensive. I had previously failed to do the if-deffing dance in the generic part of QEMU.

- The PALcode source is added as a submodule.

Richard,

it looks like I miss the v1. Anyway, some random comments:

* thank you for working on that!

* sx164 is ev56 based, isn't it ? It would be nice if cpu version specific code is clearly marked. In particular (and IIRC), pal mode for ev6 is much closer to ev4 than to ev5. Don't know about ev7. It would be nice if we could easily support both ev5 and ev6.

* Yes, executive and supervisor are used only by VMS (well AFAIK). I'd like to support it. Did you try to also support the windows mmu mode ?

* Again, thank you for working on that.

Tristan.

#27 lore raw
In reply to Tristan Gingold
Quoted 1 line · Tristan Gingold

* sx164 is ev56 based, isn't it ? It would be nice if cpu version specific code is clearly marked.

Yes, but most importantly it is the most evolved of the single hose systems. QEMU is nowhere near ready to deal with multiple PCI host controllers, and multiple ISA buses.

I actually planned on emulating an EV67 but using the SX164 HW. I think the Linux kernel will be that forgiving...

Quoted 2 lines

In particular (and IIRC), pal mode for ev6 is much closer to ev4 than to ev5. Don't know about ev7. It would be nice if we could easily support both ev5 and ev6.

Ah, see, here's where there may be some confusion...

I'm not implementing any of the real cpu ISRs. I'm not using any of the real PALcode. I'm implementing my own QEMU-specific ISRs and and writing my own PALcode, starting with MILO's PALcode but I've diverged significantly since.

I'm also cheating a bit and implementing a number of the simple CALL_PALs inline in QEMU. But that really started when I discovered how confused gdb could get attempting to step across a transition to/from PALmode.

Quoted 1 line

* Yes, executive and supervisor are used only by VMS (well AFAIK). I'd like to support it.

Well, if you'd like to help write the PALcode for VMS, sure. It certainly looks like a larger job than the Unix PALcode.

Quoted 1 line

Did you try to also support the windows mmu mode ?

Nope. I can't really imagine that being of interest to anyone.

r~

#28 lore raw
Quoted 6 lines · Richard Henderson
Quoted 1 line · Tristan Gingold

* sx164 is ev56 based, isn't it ? It would be nice if cpu version specific code is clearly marked.

Yes, but most importantly it is the most evolved of the single hose systems. QEMU is nowhere near ready to deal with multiple PCI host controllers, and multiple ISA buses.

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Quoted 11 lines

I actually planned on emulating an EV67 but using the SX164 HW. I think the Linux kernel will be that forgiving...

Quoted 2 lines

In particular (and IIRC), pal mode for ev6 is much closer to ev4 than to ev5. Don't know about ev7. It would be nice if we could easily support both ev5 and ev6.

Ah, see, here's where there may be some confusion...

I'm not implementing any of the real cpu ISRs. I'm not using any of the real PALcode. I'm implementing my own QEMU-specific ISRs and and writing my own PALcode, starting with MILO's PALcode but I've diverged significantly since.

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Tristan.

#29 lore raw
Quoted 2 lines · Tristan Gingold

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Even the lowly ds10 has two hoses.

I'll admit I hadn't considered engineering the second hose to be "present" but always appear empty. It's something to consider.

Quoted 2 lines

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Yes, Linux is the primary goal.

But I suspect that if I implemented enough of CALL_PAL CSERVE, you could boot Tru64, or at least one of the BSDs.

r~

#30 lore raw
Quoted 9 lines · Richard Henderson
Quoted 2 lines · Tristan Gingold

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Even the lowly ds10 has two hoses.

I'll admit I hadn't considered engineering the second hose to be "present" but always appear empty. It's something to consider.

Quoted 7 lines
Quoted 2 lines

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Yes, Linux is the primary goal.

But I suspect that if I implemented enough of CALL_PAL CSERVE, you could boot Tru64, or at least one of the BSDs.

BSD should be doable, but I doubt for Tru64. Do you have technical doc about the SRM ? IIRC, the SRM uses its own palcode and SRM specific pal calls.

Tristan.

#31 lore raw
Quoted 14 lines · Tristan Gingold
Quoted 12 lines · Richard Henderson
Quoted 2 lines · Tristan Gingold

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Even the lowly ds10 has two hoses.

I'll admit I hadn't considered engineering the second hose to be "present" but always appear empty. It's something to consider.

Quoted 2 lines

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Quoted 8 lines
Quoted 4 lines

Yes, Linux is the primary goal.

But I suspect that if I implemented enough of CALL_PAL CSERVE, you could boot Tru64, or at least one of the BSDs.

BSD should be doable, but I doubt for Tru64. Do you have technical doc about the SRM ? IIRC, the SRM uses its own palcode and SRM specific pal calls.

The palcode with milo was a subset of the tru64 palcode, I think. Looking at the arch reference manual and assuming that the calls take the same parameters, the only difference is that tru64 has "urti - return from user mode trap" and linux doesn't.

#32 lore raw
Quoted 20 lines · Brian Wheeler
Quoted 19 lines · Tristan Gingold
Quoted 16 lines · Richard Henderson
Quoted 2 lines · Tristan Gingold

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Even the lowly ds10 has two hoses.

I'll admit I hadn't considered engineering the second hose to be "present" but always appear empty. It's something to consider.

Quoted 2 lines

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Yes, Linux is the primary goal.

But I suspect that if I implemented enough of CALL_PAL CSERVE, you could boot Tru64, or at least one of the BSDs.

Quoted 8 lines
Quoted 3 lines

BSD should be doable, but I doubt for Tru64. Do you have technical doc about the SRM ? IIRC, the SRM uses its own palcode and SRM specific pal calls.

The palcode with milo was a subset of the tru64 palcode, I think. Looking at the arch reference manual and assuming that the calls take the same parameters, the only difference is that tru64 has "urti - return from user mode trap" and linux doesn't.

Yes, Linux runs on Tru64 palcode. But the issue is booting the Tru64 kernel.

Tristan.

#33 lore raw
Quoted 26 lines · Tristan Gingold
Quoted 24 lines · Brian Wheeler
Quoted 22 lines · Tristan Gingold
Quoted 9 lines · Richard Henderson
Quoted 2 lines · Tristan Gingold

Right, but you could create an ev67 machine with a single PCI controller (or put all the devices on the same PCI controller).

Even the lowly ds10 has two hoses.

I'll admit I hadn't considered engineering the second hose to be "present" but always appear empty. It's something to consider.

Quoted 7 lines
Quoted 2 lines

Ah, ok I understand. I fear that if you implement your own ISR, you will only be able to boot linux... which I suppose is your primary target. OTOH, it will be much faster than a native ISR.

Yes, Linux is the primary goal.

But I suspect that if I implemented enough of CALL_PAL CSERVE, you could boot Tru64, or at least one of the BSDs.

BSD should be doable, but I doubt for Tru64. Do you have technical doc about the SRM ? IIRC, the SRM uses its own palcode and SRM specific pal calls.

Quoted 9 lines
Quoted 4 lines

The palcode with milo was a subset of the tru64 palcode, I think. Looking at the arch reference manual and assuming that the calls take the same parameters, the only difference is that tru64 has "urti - return from user mode trap" and linux doesn't.

Yes, Linux runs on Tru64 palcode. But the issue is booting the Tru64 kernel.

Tristan.

Ah, gotcha. It almost seems like the console could actually be implemented in qemu itself, rather than a guest side thing, as long as it looks like part III of the ARM :) It might simplify things quite a
bit: the console callbacks look like they can be translated into qemu calls and the bootstrapping looks like its a read block zero of selected device + other blocks specified, setup hwrpb and start emulation. It looks like its standard across all OSes, with the possible exception of NT.

*shrug* I'm just an innocent bystander, though.

#34 lore raw
Quoted 9 lines · Brian Wheeler
Quoted 8 lines · Tristan Gingold
Quoted 6 lines · Brian Wheeler
Quoted 5 lines · Tristan Gingold
Quoted 1 line · Richard Henderson

On 04/20/2011 08:46 AM, Tristan Gingold wrote:

BSD should be doable, but I doubt for Tru64. Do you have technical doc about the SRM ? IIRC, the SRM uses its own palcode and SRM specific pal calls.

IIRC the main thing that was lacking between SRM and the Evaluation Board PALcode that was used in MILO is the Console Callback (CCB) structure and routines.

Quoted 3 lines

Ah, gotcha. It almost seems like the console could actually be implemented in qemu itself, rather than a guest side thing, as long as it looks like part III of the ARM :)

My first try last year was going down this path. It turned out to be irritatingly difficult to manage the data setup inside QEMU itself. Thus I came to be writing a custom PALcode image that makes a number of simplifying assumptions based on the ability to off-load some work to QEMU.

r~