Statistics
| Branch: | Revision:

root / target-m68k / op_helper.c @ eb173de6

History | View | Annotate | Download (4.2 kB)

1 0633879f pbrook
/*
2 0633879f pbrook
 *  M68K helper routines
3 5fafdf24 ths
 *
4 0633879f pbrook
 *  Copyright (c) 2007 CodeSourcery
5 0633879f pbrook
 *
6 0633879f pbrook
 * This library is free software; you can redistribute it and/or
7 0633879f pbrook
 * modify it under the terms of the GNU Lesser General Public
8 0633879f pbrook
 * License as published by the Free Software Foundation; either
9 0633879f pbrook
 * version 2 of the License, or (at your option) any later version.
10 0633879f pbrook
 *
11 0633879f pbrook
 * This library is distributed in the hope that it will be useful,
12 0633879f pbrook
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 0633879f pbrook
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 0633879f pbrook
 * Lesser General Public License for more details.
15 0633879f pbrook
 *
16 0633879f pbrook
 * You should have received a copy of the GNU Lesser General Public
17 0633879f pbrook
 * License along with this library; if not, write to the Free Software
18 0633879f pbrook
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 0633879f pbrook
 */
20 0633879f pbrook
#include "exec.h"
21 0633879f pbrook
22 0633879f pbrook
#if defined(CONFIG_USER_ONLY)
23 0633879f pbrook
24 0633879f pbrook
void do_interrupt(int is_hw)
25 0633879f pbrook
{
26 0633879f pbrook
    env->exception_index = -1;
27 0633879f pbrook
}
28 0633879f pbrook
29 0633879f pbrook
#else
30 0633879f pbrook
31 a87295e8 pbrook
extern int semihosting_enabled;
32 a87295e8 pbrook
33 0633879f pbrook
#define MMUSUFFIX _mmu
34 273af660 ths
#ifdef __s390__
35 273af660 ths
# define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
36 273af660 ths
#else
37 273af660 ths
# define GETPC() (__builtin_return_address(0))
38 273af660 ths
#endif
39 0633879f pbrook
40 0633879f pbrook
#define SHIFT 0
41 0633879f pbrook
#include "softmmu_template.h"
42 0633879f pbrook
43 0633879f pbrook
#define SHIFT 1
44 0633879f pbrook
#include "softmmu_template.h"
45 0633879f pbrook
46 0633879f pbrook
#define SHIFT 2
47 0633879f pbrook
#include "softmmu_template.h"
48 0633879f pbrook
49 0633879f pbrook
#define SHIFT 3
50 0633879f pbrook
#include "softmmu_template.h"
51 0633879f pbrook
52 0633879f pbrook
/* Try to fill the TLB and return an exception if error. If retaddr is
53 0633879f pbrook
   NULL, it means that the function was called in C code (i.e. not
54 0633879f pbrook
   from generated code or from helper.c) */
55 0633879f pbrook
/* XXX: fix it to restore all registers */
56 6ebbf390 j_mayer
void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
57 0633879f pbrook
{
58 0633879f pbrook
    TranslationBlock *tb;
59 0633879f pbrook
    CPUState *saved_env;
60 44f8625d bellard
    unsigned long pc;
61 0633879f pbrook
    int ret;
62 0633879f pbrook
63 0633879f pbrook
    /* XXX: hack to restore env in all cases, even if not called from
64 0633879f pbrook
       generated code */
65 0633879f pbrook
    saved_env = env;
66 0633879f pbrook
    env = cpu_single_env;
67 6ebbf390 j_mayer
    ret = cpu_m68k_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
68 0633879f pbrook
    if (__builtin_expect(ret, 0)) {
69 0633879f pbrook
        if (retaddr) {
70 0633879f pbrook
            /* now we have a real cpu fault */
71 44f8625d bellard
            pc = (unsigned long)retaddr;
72 0633879f pbrook
            tb = tb_find_pc(pc);
73 0633879f pbrook
            if (tb) {
74 0633879f pbrook
                /* the PC is inside the translated code. It means that we have
75 0633879f pbrook
                   a virtual CPU fault */
76 0633879f pbrook
                cpu_restore_state(tb, env, pc, NULL);
77 0633879f pbrook
            }
78 0633879f pbrook
        }
79 0633879f pbrook
        cpu_loop_exit();
80 0633879f pbrook
    }
81 0633879f pbrook
    env = saved_env;
82 0633879f pbrook
}
83 0633879f pbrook
84 0633879f pbrook
static void do_rte(void)
85 0633879f pbrook
{
86 0633879f pbrook
    uint32_t sp;
87 0633879f pbrook
    uint32_t fmt;
88 0633879f pbrook
89 0633879f pbrook
    sp = env->aregs[7];
90 0633879f pbrook
    fmt = ldl_kernel(sp);
91 0633879f pbrook
    env->pc = ldl_kernel(sp + 4);
92 0633879f pbrook
    sp |= (fmt >> 28) & 3;
93 0633879f pbrook
    env->sr = fmt & 0xffff;
94 20dcee94 pbrook
    m68k_switch_sp(env);
95 0633879f pbrook
    env->aregs[7] = sp + 8;
96 0633879f pbrook
}
97 0633879f pbrook
98 0633879f pbrook
void do_interrupt(int is_hw)
99 0633879f pbrook
{
100 0633879f pbrook
    uint32_t sp;
101 0633879f pbrook
    uint32_t fmt;
102 0633879f pbrook
    uint32_t retaddr;
103 0633879f pbrook
    uint32_t vector;
104 0633879f pbrook
105 0633879f pbrook
    fmt = 0;
106 0633879f pbrook
    retaddr = env->pc;
107 0633879f pbrook
108 0633879f pbrook
    if (!is_hw) {
109 0633879f pbrook
        switch (env->exception_index) {
110 0633879f pbrook
        case EXCP_RTE:
111 0633879f pbrook
            /* Return from an exception.  */
112 0633879f pbrook
            do_rte();
113 0633879f pbrook
            return;
114 a87295e8 pbrook
        case EXCP_HALT_INSN:
115 a87295e8 pbrook
            if (semihosting_enabled
116 a87295e8 pbrook
                    && (env->sr & SR_S) != 0
117 a87295e8 pbrook
                    && (env->pc & 3) == 0
118 a87295e8 pbrook
                    && lduw_code(env->pc - 4) == 0x4e71
119 a87295e8 pbrook
                    && ldl_code(env->pc) == 0x4e7bf000) {
120 a87295e8 pbrook
                env->pc += 4;
121 a87295e8 pbrook
                do_m68k_semihosting(env, env->dregs[0]);
122 a87295e8 pbrook
                return;
123 a87295e8 pbrook
            }
124 a87295e8 pbrook
            env->halted = 1;
125 a87295e8 pbrook
            env->exception_index = EXCP_HLT;
126 a87295e8 pbrook
            cpu_loop_exit();
127 a87295e8 pbrook
            return;
128 0633879f pbrook
        }
129 0633879f pbrook
        if (env->exception_index >= EXCP_TRAP0
130 0633879f pbrook
            && env->exception_index <= EXCP_TRAP15) {
131 0633879f pbrook
            /* Move the PC after the trap instruction.  */
132 0633879f pbrook
            retaddr += 2;
133 0633879f pbrook
        }
134 0633879f pbrook
    }
135 0633879f pbrook
136 0633879f pbrook
    vector = env->exception_index << 2;
137 0633879f pbrook
138 0cf5c677 pbrook
    sp = env->aregs[7];
139 0cf5c677 pbrook
140 0633879f pbrook
    fmt |= 0x40000000;
141 0633879f pbrook
    fmt |= (sp & 3) << 28;
142 0633879f pbrook
    fmt |= vector << 16;
143 0633879f pbrook
    fmt |= env->sr;
144 0633879f pbrook
145 20dcee94 pbrook
    env->sr |= SR_S;
146 20dcee94 pbrook
    if (is_hw) {
147 20dcee94 pbrook
        env->sr = (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT);
148 20dcee94 pbrook
        env->sr &= ~SR_M;
149 20dcee94 pbrook
    }
150 20dcee94 pbrook
    m68k_switch_sp(env);
151 20dcee94 pbrook
152 0633879f pbrook
    /* ??? This could cause MMU faults.  */
153 0633879f pbrook
    sp &= ~3;
154 0633879f pbrook
    sp -= 4;
155 0633879f pbrook
    stl_kernel(sp, retaddr);
156 0633879f pbrook
    sp -= 4;
157 0633879f pbrook
    stl_kernel(sp, fmt);
158 0633879f pbrook
    env->aregs[7] = sp;
159 0633879f pbrook
    /* Jump to vector.  */
160 0633879f pbrook
    env->pc = ldl_kernel(env->vbr + vector);
161 0633879f pbrook
}
162 0633879f pbrook
163 0633879f pbrook
#endif