Revision 10ec5117

b/cpu-exec.c
249 249
#elif defined(TARGET_MIPS)
250 250
#elif defined(TARGET_SH4)
251 251
#elif defined(TARGET_CRIS)
252
#elif defined(TARGET_S390X)
252 253
    /* XXXXX */
253 254
#else
254 255
#error unsupported target CPU
......
673 674
#elif defined(TARGET_SH4)
674 675
#elif defined(TARGET_ALPHA)
675 676
#elif defined(TARGET_CRIS)
677
#elif defined(TARGET_S390X)
676 678
    /* XXXXX */
677 679
#else
678 680
#error unsupported target CPU
b/target-s390x/cpu.h
1
/*
2
 * S/390 virtual CPU header
3
 *
4
 *  Copyright (c) 2009 Ulrich Hecht
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19
 */
20
#ifndef CPU_S390X_H
21
#define CPU_S390X_H
22

  
23
#define TARGET_LONG_BITS 64
24

  
25
#define ELF_MACHINE	EM_S390
26

  
27
#define CPUState struct CPUS390XState
28

  
29
#include "cpu-defs.h"
30

  
31
#include "softfloat.h"
32

  
33
#define NB_MMU_MODES 2 // guess
34
#define MMU_USER_IDX 0 // guess
35

  
36
typedef union FPReg {
37
    struct {
38
#ifdef WORDS_BIGENDIAN
39
        float32 e;
40
        int32_t __pad;
41
#else
42
        int32_t __pad;
43
        float32 e;
44
#endif
45
    };
46
    float64 d;
47
    uint64_t i;
48
} FPReg;
49

  
50
typedef struct CPUS390XState {
51
    uint64_t regs[16];	/* GP registers */
52

  
53
    uint32_t aregs[16];	/* access registers */
54

  
55
    uint32_t fpc;	/* floating-point control register */
56
    FPReg fregs[16]; /* FP registers */
57
    float_status fpu_status; /* passed to softfloat lib */
58

  
59
    struct {
60
        uint64_t mask;
61
        uint64_t addr;
62
    } psw;
63

  
64
    int cc; /* condition code (0-3) */
65

  
66
    uint64_t __excp_addr;
67

  
68
    CPU_COMMON
69
} CPUS390XState;
70

  
71
#if defined(CONFIG_USER_ONLY)
72
static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
73
{
74
    if (newsp)
75
        env->regs[15] = newsp;
76
    env->regs[0] = 0;
77
}
78
#endif
79

  
80
CPUS390XState *cpu_s390x_init(const char *cpu_model);
81
int cpu_s390x_exec(CPUS390XState *s);
82
void cpu_s390x_close(CPUS390XState *s);
83

  
84
/* you can call this signal handler from your SIGBUS and SIGSEGV
85
   signal handlers to inform the virtual CPU of exceptions. non zero
86
   is returned if the signal was handled by the virtual CPU.  */
87
int cpu_s390x_signal_handler(int host_signum, void *pinfo,
88
                           void *puc);
89
int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw,
90
                              int mmu_idx, int is_softmuu);
91
#define cpu_handle_mmu_fault cpu_s390x_handle_mmu_fault
92

  
93
#define TARGET_PAGE_BITS 12
94

  
95
#define cpu_init cpu_s390x_init
96
#define cpu_exec cpu_s390x_exec
97
#define cpu_gen_code cpu_s390x_gen_code
98

  
99
#include "cpu-all.h"
100
#include "exec-all.h"
101

  
102
#define EXCP_OPEX 1 /* operation exception (sigill) */
103
#define EXCP_SVC 2 /* supervisor call (syscall) */
104
#define EXCP_ADDR 5 /* addressing exception */
105
#define EXCP_EXECUTE_SVC 0xff00000 /* supervisor call via execute insn */
106

  
107
static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock* tb)
108
{
109
    env->psw.addr = tb->pc;
110
}
111

  
112
static inline void cpu_get_tb_cpu_state(CPUState* env, target_ulong *pc,
113
                                        target_ulong *cs_base, int *flags)
114
{
115
    *pc = env->psw.addr;
116
    /* XXX this is correct for user-mode emulation, but needs
117
     *     the asce register information as well when softmmu
118
     *     is implemented in the future */
119
    *cs_base = 0;
120
    *flags = env->psw.mask;
121
}
122
#endif
b/target-s390x/exec.h
1
/*
2
 *  S/390 execution defines
3
 *
4
 *  Copyright (c) 2009 Ulrich Hecht
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19
 */
20

  
21
#include "dyngen-exec.h"
22

  
23
register struct CPUS390XState *env asm(AREG0);
24

  
25
#include "cpu.h"
26
#include "exec-all.h"
27

  
28
static inline int cpu_has_work(CPUState *env)
29
{
30
    return env->interrupt_request & CPU_INTERRUPT_HARD; // guess
31
}
32

  
33
static inline void regs_to_env(void)
34
{
35
}
36

  
37
static inline void env_to_regs(void)
38
{
39
}
40

  
41
static inline int cpu_halted(CPUState *env)
42
{
43
    if (!env->halted) {
44
       return 0;
45
    }
46
    if (cpu_has_work(env)) {
47
        env->halted = 0;
48
        return 0;
49
    }
50
    return EXCP_HALTED;
51
}
b/target-s390x/helper.c
1
/*
2
 *  S/390 helpers
3
 *
4
 *  Copyright (c) 2009 Ulrich Hecht
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19
 */
20

  
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <string.h>
24

  
25
#include "cpu.h"
26
#include "exec-all.h"
27
#include "gdbstub.h"
28
#include "qemu-common.h"
29

  
30
CPUS390XState *cpu_s390x_init(const char *cpu_model)
31
{
32
    CPUS390XState *env;
33
    static int inited = 0;
34

  
35
    env = qemu_mallocz(sizeof(CPUS390XState));
36
    cpu_exec_init(env);
37
    if (!inited) {
38
        inited = 1;
39
    }
40

  
41
    env->cpu_model_str = cpu_model;
42
    cpu_reset(env);
43
    qemu_init_vcpu(env);
44
    return env;
45
}
46

  
47
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
48
{
49
    return addr;
50
}
51

  
52
void cpu_reset(CPUS390XState *env)
53
{
54
    if (qemu_loglevel_mask(CPU_LOG_RESET)) {
55
        qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
56
        log_cpu_state(env, 0);
57
    }
58

  
59
    memset(env, 0, offsetof(CPUS390XState, breakpoints));
60
    /* FIXME: reset vector? */
61
    tlb_flush(env, 1);
62
}
b/target-s390x/op_helper.c
1
/*
2
 *  S/390 helper routines
3
 *
4
 *  Copyright (c) 2009 Alexander Graf
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19
 */
20

  
21
#include "exec.h"
22

  
23
/*****************************************************************************/
24
/* Softmmu support */
25
#if !defined (CONFIG_USER_ONLY)
26

  
27
#define MMUSUFFIX _mmu
28

  
29
#define SHIFT 0
30
#include "softmmu_template.h"
31

  
32
#define SHIFT 1
33
#include "softmmu_template.h"
34

  
35
#define SHIFT 2
36
#include "softmmu_template.h"
37

  
38
#define SHIFT 3
39
#include "softmmu_template.h"
40

  
41
/* try to fill the TLB and return an exception if error. If retaddr is
42
   NULL, it means that the function was called in C code (i.e. not
43
   from generated code or from helper.c) */
44
/* XXX: fix it to restore all registers */
45
void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
46
{
47
    TranslationBlock *tb;
48
    CPUState *saved_env;
49
    unsigned long pc;
50
    int ret;
51

  
52
    /* XXX: hack to restore env in all cases, even if not called from
53
       generated code */
54
    saved_env = env;
55
    env = cpu_single_env;
56
    ret = cpu_s390x_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
57
    if (unlikely(ret != 0)) {
58
        if (likely(retaddr)) {
59
            /* now we have a real cpu fault */
60
            pc = (unsigned long)retaddr;
61
            tb = tb_find_pc(pc);
62
            if (likely(tb)) {
63
                /* the PC is inside the translated code. It means that we have
64
                   a virtual CPU fault */
65
                cpu_restore_state(tb, env, pc, NULL);
66
            }
67
        }
68
        /* XXX */
69
        /* helper_raise_exception_err(env->exception_index, env->error_code); */
70
    }
71
    env = saved_env;
72
}
73

  
74
#endif
b/target-s390x/translate.c
1
/*
2
 *  S/390 translation
3
 *
4
 *  Copyright (c) 2009 Ulrich Hecht
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19
 */
20

  
21
#include "cpu.h"
22
#include "exec-all.h"
23
#include "disas.h"
24
#include "tcg-op.h"
25
#include "qemu-log.h"
26

  
27
void cpu_dump_state(CPUState *env, FILE *f,
28
                    int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
29
                    int flags)
30
{
31
    int i;
32
    for (i = 0; i < 16; i++) {
33
        cpu_fprintf(f, "R%02d=%016lx", i, env->regs[i]);
34
        if ((i % 4) == 3) {
35
            cpu_fprintf(f, "\n");
36
        } else {
37
            cpu_fprintf(f, " ");
38
        }
39
    }
40
    for (i = 0; i < 16; i++) {
41
        cpu_fprintf(f, "F%02d=%016lx", i, env->fregs[i]);
42
        if ((i % 4) == 3) {
43
            cpu_fprintf(f, "\n");
44
        } else {
45
            cpu_fprintf(f, " ");
46
        }
47
    }
48
    cpu_fprintf(f, "PSW=mask %016lx addr %016lx cc %02x\n", env->psw.mask, env->psw.addr, env->cc);
49
}
50

  
51
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
52
{
53
}
54

  
55
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
56
{
57
}
58

  
59
void gen_pc_load(CPUState *env, TranslationBlock *tb,
60
                unsigned long searched_pc, int pc_pos, void *puc)
61
{
62
    env->psw.addr = gen_opc_pc[pc_pos];
63
}

Also available in: Unified diff