qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tristan Gingold <gingold@adacore.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 17/19] Move linux-user pal emulation to linux-user/
Date: Mon, 30 Mar 2009 16:36:32 +0200	[thread overview]
Message-ID: <1238423794-25455-18-git-send-email-gingold@adacore.com> (raw)
In-Reply-To: <1238423794-25455-17-git-send-email-gingold@adacore.com>

Move pal emulation for user emulation from alpha_palcode.c to linux-user/mai
Add generic exception names.
Fix offset for PAL calls.

Signed-off-by: Tristan Gingold <gingold@adacore.com>
---
 Makefile.target          |    5 +--
 hw/alpha_palcode.c       |   44 ---------------------
 linux-user/main.c        |   96 +++++++++++++++++++++++++---------------------
 target-alpha/cpu.h       |   39 +++++++++++++++---
 target-alpha/helper.c    |    4 +-
 target-alpha/translate.c |    1 -
 6 files changed, 87 insertions(+), 102 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 68937fe..de6f7eb 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -157,10 +157,6 @@ ifeq ($(TARGET_BASE_ARCH), arm)
 LIBOBJS+= neon_helper.o iwmmxt_helper.o
 endif
 
-ifeq ($(TARGET_BASE_ARCH), alpha)
-LIBOBJS+= alpha_palcode.o
-endif
-
 ifeq ($(TARGET_BASE_ARCH), cris)
 LIBOBJS+= cris-dis.o
 
@@ -686,6 +682,7 @@ endif
 ifeq ($(TARGET_BASE_ARCH), alpha)
 OBJS+= es40.o 21272.o serial.o i8259.o mc146818rtc.o i8254.o pcspk.o dma.o
 OBJS+= ali1543.o
+#OBJS+= alpha_palcode.o # Not currently used until pal is virtualized
 endif
 ifdef CONFIG_GDBSTUB
 OBJS+=gdbstub.o gdbstub-xml.o
diff --git a/hw/alpha_palcode.c b/hw/alpha_palcode.c
index bfffb5d..189033c 100644
--- a/hw/alpha_palcode.c
+++ b/hw/alpha_palcode.c
@@ -26,7 +26,6 @@
 #include "cpu.h"
 #include "exec-all.h"
 
-#if !defined (CONFIG_USER_ONLY)
 /* Shared handlers */
 static void pal_reset (CPUState *env);
 /* Console handlers */
@@ -1051,46 +1050,3 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
     return ret;
 }
 #endif
-
-#else /* !defined (CONFIG_USER_ONLY) */
-void pal_init (CPUState *env)
-{
-}
-
-void call_pal (CPUState *env, int palcode)
-{
-    target_long ret;
-
-    qemu_log("%s: palcode %02x\n", __func__, palcode);
-    switch (palcode) {
-    case 0x83:
-        /* CALLSYS */
-        qemu_log("CALLSYS n " TARGET_FMT_ld "\n", env->ir[0]);
-        ret = do_syscall(env, env->ir[IR_V0], env->ir[IR_A0], env->ir[IR_A1],
-                         env->ir[IR_A2], env->ir[IR_A3], env->ir[IR_A4],
-                         env->ir[IR_A5]);
-        if (ret >= 0) {
-            env->ir[IR_A3] = 0;
-            env->ir[IR_V0] = ret;
-        } else {
-            env->ir[IR_A3] = 1;
-            env->ir[IR_V0] = -ret;
-        }
-        break;
-    case 0x9E:
-        /* RDUNIQUE */
-        env->ir[IR_V0] = env->unique;
-        qemu_log("RDUNIQUE: " TARGET_FMT_lx "\n", env->unique);
-        break;
-    case 0x9F:
-        /* WRUNIQUE */
-        env->unique = env->ir[IR_A0];
-        qemu_log("WRUNIQUE: " TARGET_FMT_lx "\n", env->unique);
-        break;
-    default:
-        qemu_log("%s: unhandled palcode %02x\n",
-                    __func__, palcode);
-        exit(1);
-    }
-}
-#endif
diff --git a/linux-user/main.c b/linux-user/main.c
index feb3036..5a1e98b 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2110,6 +2110,43 @@ void cpu_loop(CPUM68KState *env)
 #endif /* TARGET_M68K */
 
 #ifdef TARGET_ALPHA
+static void call_pal (CPUState *env, int palcode)
+{
+    target_long ret;
+
+    qemu_log("%s: palcode %02x\n", __func__, palcode);
+    switch (palcode) {
+    case 0x83:
+        /* CALLSYS */
+        qemu_log("CALLSYS n " TARGET_FMT_ld "\n", env->ir[0]);
+        ret = do_syscall(env, env->ir[IR_V0], env->ir[IR_A0], env->ir[IR_A1],
+                         env->ir[IR_A2], env->ir[IR_A3], env->ir[IR_A4],
+                         env->ir[IR_A5]);
+        if (ret >= 0) {
+            env->ir[IR_A3] = 0;
+            env->ir[IR_V0] = ret;
+        } else {
+            env->ir[IR_A3] = 1;
+            env->ir[IR_V0] = -ret;
+        }
+        break;
+    case 0x9E:
+        /* RDUNIQUE */
+        env->ir[IR_V0] = env->user.unique;
+        qemu_log("RDUNIQUE: " TARGET_FMT_lx "\n", env->user.unique);
+        break;
+    case 0x9F:
+        /* WRUNIQUE */
+        env->user.unique = env->ir[IR_A0];
+        qemu_log("WRUNIQUE: " TARGET_FMT_lx "\n", env->user.unique);
+        break;
+    default:
+        qemu_log("%s: unhandled palcode %02x\n",
+                    __func__, palcode);
+        exit(1);
+    }
+}
+
 void cpu_loop (CPUState *env)
 {
     int trapnr;
@@ -2119,61 +2156,29 @@ void cpu_loop (CPUState *env)
         trapnr = cpu_alpha_exec (env);
 
         switch (trapnr) {
-        case EXCP_RESET:
-            fprintf(stderr, "Reset requested. Exit\n");
-            exit(1);
-            break;
-        case EXCP_MCHK:
-            fprintf(stderr, "Machine check exception. Exit\n");
-            exit(1);
-            break;
-        case EXCP_ARITH:
+        case EXCP_GEN_ARITH:
             fprintf(stderr, "Arithmetic trap.\n");
             exit(1);
             break;
-        case EXCP_HW_INTERRUPT:
-            fprintf(stderr, "External interrupt. Exit\n");
-            exit(1);
-            break;
-        case EXCP_DFAULT:
-            fprintf(stderr, "MMU data fault\n");
+        case EXCP_GEN_INTERRUPT:
+            fprintf(stderr, "Hardware interruption\n");
             exit(1);
             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:
-            fprintf(stderr, "Unaligned access\n");
-            exit(1);
-            break;
-        case EXCP_OPCDEC:
+        case EXCP_GEN_OPCDEC:
             fprintf(stderr, "Invalid instruction\n");
             exit(1);
             break;
-        case EXCP_FEN:
-            fprintf(stderr, "Floating-point not allowed\n");
+        case EXCP_USER_ITB_MISS:
+            fprintf(stderr, "MMU instruction TLB miss\n");
             exit(1);
             break;
-        case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1):
-            call_pal(env, (trapnr >> 6) | 0x80);
-            break;
-        case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1):
+        case EXCP_CALL_PALP ... (EXCP_CALL_PAL - 1):
             fprintf(stderr, "Privileged call to PALcode\n");
             exit(1);
             break;
+        case EXCP_CALL_PAL ... (EXCP_CALL_PALE - 1):
+            call_pal(env, ((trapnr - EXCP_CALL_PAL) >> 6) | 0x80);
+            break;
         case EXCP_DEBUG:
             {
                 int sig;
@@ -2409,6 +2414,9 @@ int main(int argc, char **argv, char **envp)
 #else
         cpu_model = "750";
 #endif
+#elif defined(TARGET_ALPHA)
+        cpu_model = "21264";
+
 #else
         cpu_model = "any";
 #endif
@@ -2665,10 +2673,10 @@ int main(int argc, char **argv, char **envp)
         for(i = 0; i < 28; i++) {
             env->ir[i] = ((abi_ulong *)regs)[i];
         }
-        env->ipr[IPR_USP] = regs->usp;
+        env->user.usp = regs->usp;
         env->ir[30] = regs->usp;
         env->pc = regs->pc;
-        env->unique = regs->unique;
+        env->user.unique = regs->unique;
     }
 #elif defined(TARGET_CRIS)
     {
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index c27e89f..7cd6395 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -291,7 +291,11 @@ struct pal_handler_t {
     void (*call_pal)(CPUAlphaState *env, uint32_t palcode);
 };
 
+#if !defined(CONFIG_USER_ONLY)
 #define NB_MMU_MODES 4
+#else
+#define NB_MMU_MODES 2
+#endif
 
 struct CPUAlphaState {
     uint64_t ir[31];
@@ -318,6 +322,12 @@ struct CPUAlphaState {
     CPU_COMMON
 
     uint32_t hflags;
+#if defined(CONFIG_USER_ONLY)
+    struct {
+        uint64_t usp;
+        uint64_t unique;
+    } user;
+#endif
 
     int error_code;
 
@@ -342,6 +352,8 @@ struct CPUAlphaState {
 #define MMU_KERNEL_IDX 0
 #define MMU_USER_IDX 3
 #define MMU_PAL_IDX 4
+
+#if !defined(CONFIG_USER_ONLY)
 static inline int cpu_mmu_index_data (CPUState *env)
 {
     return env->mmu_data_index;
@@ -351,8 +363,13 @@ static inline int cpu_mmu_index_code (CPUState *env)
 {
     return env->mmu_code_index;
 }
+#else
+#define cpu_mmu_index_data cpu_mmu_index_code
+static inline int cpu_mmu_index_code (CPUState *env)
+{
+    return 0;
+}
 
-#if defined(CONFIG_USER_ONLY)
 static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
 {
     if (newsp)
@@ -384,9 +401,20 @@ enum {
     EXCP_UNALIGN          = 0x11E0,
     EXCP_OPCDEC           = 0x13E0,
     EXCP_FEN              = 0x17E0,
-    EXCP_CALL_PAL         = 0x2000,
-    EXCP_CALL_PALP        = 0x3000,
-    EXCP_CALL_PALE        = 0x4000,
+
+    /* Generic exception - to be mapped to processor.  */
+    EXCP_GEN_OPCDEC             = 1,
+    EXCP_GEN_ARITH              = 2,
+    EXCP_GEN_INTERRUPT          = 3,
+    EXCP_GEN_LAST               = 3,
+
+    /* User linux exception.  */
+    EXCP_USER_DFAULT            = 0x0100,
+    EXCP_USER_ITB_MISS          = 0x0101,
+
+    EXCP_CALL_PALP        = 0x2000,
+    EXCP_CALL_PAL         = 0x3000,
+    EXCP_CALL_PALE        = 0x4000, /* End of Pal */
     /* Pseudo exception for console */
     EXCP_CONSOLE_DISPATCH = 0x4001,
     EXCP_CONSOLE_FIXUP    = 0x4002,
@@ -448,11 +476,8 @@ void do_interrupt (CPUState *env);
 
 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);
-void pal_init (CPUState *env);
 #if !defined (CONFIG_USER_ONLY)
 void call_pal (CPUState *env);
-#else
-void call_pal (CPUState *env, int palcode);
 #endif
 
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
diff --git a/target-alpha/helper.c b/target-alpha/helper.c
index fc68a7e..4046463 100644
--- a/target-alpha/helper.c
+++ b/target-alpha/helper.c
@@ -31,9 +31,9 @@ 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;
+        env->exception_index = EXCP_USER_ITB_MISS;
     else
-        env->exception_index = EXCP_DFAULT;
+        env->exception_index = EXCP_USER_DFAULT;
     env->ipr[IPR_EXC_ADDR] = address;
 
     return 1;
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index dab8d78..061cf5f 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -2510,7 +2510,6 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
 #if defined (CONFIG_USER_ONLY)
     env->ps |= 1 << 3;
 #endif
-    pal_init(env);
     /* Initialize IPR */
     hwpcb = env->ipr[IPR_PCBB];
     env->ipr[IPR_ASN] = 0;
-- 
1.6.2

  reply	other threads:[~2009-03-30 14:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-30 14:36 [Qemu-devel] [PATCH 0/20]: add alpha es40 system emulation (v4) Tristan Gingold
2009-03-30 14:36 ` [Qemu-devel] [PATCH 01/19] Add support for multi-level phys map Tristan Gingold
2009-03-30 14:36   ` [Qemu-devel] [PATCH 02/19] Increase Alpha physical address size to 44 bits Tristan Gingold
2009-03-30 14:36     ` [Qemu-devel] [PATCH 03/19] Alpha: set target page size to 13 bits Tristan Gingold
2009-03-30 14:36       ` [Qemu-devel] [PATCH 04/19] Allow 5 mmu indexes Tristan Gingold
2009-03-30 14:36         ` [Qemu-devel] [PATCH 05/19] Split cpu_mmu_index into cpu_mmu_index_data and cpu_mmu_index_code Tristan Gingold
2009-03-30 14:36           ` [Qemu-devel] [PATCH 06/19] Bug fix alpha: stop translation if too long Tristan Gingold
2009-03-30 14:36             ` [Qemu-devel] [PATCH 07/19] Alpha bug: fix palcode mask for user pal calls Tristan Gingold
2009-03-30 14:36               ` [Qemu-devel] [PATCH 08/19] Alpha: document more registers used by 21264 Tristan Gingold
2009-03-30 14:36                 ` [Qemu-devel] [PATCH 09/19] Add square wave output support Tristan Gingold
2009-03-30 14:36                   ` [Qemu-devel] [PATCH 10/19] Add ali1543 super IO pci device Tristan Gingold
2009-03-30 14:36                     ` [Qemu-devel] [PATCH 11/19] Add 21272 chipset (memory and pci controller for alpha) Tristan Gingold
2009-03-30 14:36                       ` [Qemu-devel] [PATCH 12/19] Add target-alpha/machine.c and hw/es40.c for es40 machine emulation Tristan Gingold
2009-03-30 14:36                         ` [Qemu-devel] [PATCH 13/19] Move softmmu_helper.h from exec.h to op_helper.c on alpha Tristan Gingold
2009-03-30 14:36                           ` [Qemu-devel] [PATCH 14/19] alpha ld helpers now directly return the value Tristan Gingold
2009-03-30 14:36                             ` [Qemu-devel] [PATCH 15/19] Add alpha_cpu_list Tristan Gingold
2009-03-30 14:36                               ` [Qemu-devel] [PATCH 16/19] Alpha: lower parent irq when irq is lowered Tristan Gingold
2009-03-30 14:36                                 ` Tristan Gingold [this message]
2009-03-30 14:36                                   ` [Qemu-devel] [PATCH 18/19] Correctly decode hw_ld/hw_st opcodes for all alpha implementations Tristan Gingold
2009-03-30 14:36                                     ` [Qemu-devel] [PATCH 19/19] Add full emulation for 21264 Tristan Gingold
2009-04-07 21:52                                     ` [Qemu-devel] [PATCH 18/19] Correctly decode hw_ld/hw_st opcodes for all alpha implementations Aurelien Jarno
2009-04-08 12:26                                       ` Tristan Gingold
2009-04-15 14:42                                 ` [Qemu-devel] [PATCH 16/19] Alpha: lower parent irq when irq is lowered Aurelien Jarno
2009-04-07 22:29                   ` [Qemu-devel] [PATCH 09/19] Add square wave output support Aurelien Jarno
2009-04-07 22:32                 ` [Qemu-devel] [PATCH 08/19] Alpha: document more registers used by 21264 Aurelien Jarno
2009-04-07 22:31               ` [Qemu-devel] [PATCH 07/19] Alpha bug: fix palcode mask for user pal calls Aurelien Jarno
2009-04-07 21:44             ` [Qemu-devel] [PATCH 06/19] Bug fix alpha: stop translation if too long Aurelien Jarno
2009-04-15 14:30           ` [Qemu-devel] [PATCH 05/19] Split cpu_mmu_index into cpu_mmu_index_data and cpu_mmu_index_code Aurelien Jarno
2009-04-21 12:10             ` Tristan Gingold
2009-04-07 21:48         ` [Qemu-devel] [PATCH 04/19] Allow 5 mmu indexes Aurelien Jarno
2009-04-07 21:47       ` [Qemu-devel] [PATCH 03/19] Alpha: set target page size to 13 bits Aurelien Jarno
2009-04-15 16:23   ` [Qemu-devel] [PATCH 01/19] Add support for multi-level phys map Aurelien Jarno
2009-04-21 12:11     ` Tristan Gingold
2009-03-30 15:46 ` [Qemu-devel] [PATCH 0/20]: add alpha es40 system emulation (v4) Brian Wheeler
2009-03-30 16:04   ` Tristan Gingold
2009-03-30 16:43     ` Brian Wheeler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1238423794-25455-18-git-send-email-gingold@adacore.com \
    --to=gingold@adacore.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).