root / target-m68k / op_helper.c @ a7037b29
History | View | Annotate | Download (4 kB)
1 | 0633879f | pbrook | /*
|
---|---|---|---|
2 | 0633879f | pbrook | * M68K helper routines
|
3 | 0633879f | pbrook | *
|
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 | 0633879f | pbrook | #define GETPC() (__builtin_return_address(0)) |
35 | 0633879f | pbrook | |
36 | 0633879f | pbrook | #define SHIFT 0 |
37 | 0633879f | pbrook | #include "softmmu_template.h" |
38 | 0633879f | pbrook | |
39 | 0633879f | pbrook | #define SHIFT 1 |
40 | 0633879f | pbrook | #include "softmmu_template.h" |
41 | 0633879f | pbrook | |
42 | 0633879f | pbrook | #define SHIFT 2 |
43 | 0633879f | pbrook | #include "softmmu_template.h" |
44 | 0633879f | pbrook | |
45 | 0633879f | pbrook | #define SHIFT 3 |
46 | 0633879f | pbrook | #include "softmmu_template.h" |
47 | 0633879f | pbrook | |
48 | 0633879f | pbrook | /* Try to fill the TLB and return an exception if error. If retaddr is
|
49 | 0633879f | pbrook | NULL, it means that the function was called in C code (i.e. not
|
50 | 0633879f | pbrook | from generated code or from helper.c) */
|
51 | 0633879f | pbrook | /* XXX: fix it to restore all registers */
|
52 | 0633879f | pbrook | void tlb_fill (target_ulong addr, int is_write, int is_user, void *retaddr) |
53 | 0633879f | pbrook | { |
54 | 0633879f | pbrook | TranslationBlock *tb; |
55 | 0633879f | pbrook | CPUState *saved_env; |
56 | 0633879f | pbrook | target_phys_addr_t pc; |
57 | 0633879f | pbrook | int ret;
|
58 | 0633879f | pbrook | |
59 | 0633879f | pbrook | /* XXX: hack to restore env in all cases, even if not called from
|
60 | 0633879f | pbrook | generated code */
|
61 | 0633879f | pbrook | saved_env = env; |
62 | 0633879f | pbrook | env = cpu_single_env; |
63 | 0633879f | pbrook | ret = cpu_m68k_handle_mmu_fault(env, addr, is_write, is_user, 1);
|
64 | 0633879f | pbrook | if (__builtin_expect(ret, 0)) { |
65 | 0633879f | pbrook | if (retaddr) {
|
66 | 0633879f | pbrook | /* now we have a real cpu fault */
|
67 | 0633879f | pbrook | pc = (target_phys_addr_t)retaddr; |
68 | 0633879f | pbrook | tb = tb_find_pc(pc); |
69 | 0633879f | pbrook | if (tb) {
|
70 | 0633879f | pbrook | /* the PC is inside the translated code. It means that we have
|
71 | 0633879f | pbrook | a virtual CPU fault */
|
72 | 0633879f | pbrook | cpu_restore_state(tb, env, pc, NULL);
|
73 | 0633879f | pbrook | } |
74 | 0633879f | pbrook | } |
75 | 0633879f | pbrook | cpu_loop_exit(); |
76 | 0633879f | pbrook | } |
77 | 0633879f | pbrook | env = saved_env; |
78 | 0633879f | pbrook | } |
79 | 0633879f | pbrook | |
80 | 0633879f | pbrook | static void do_rte(void) |
81 | 0633879f | pbrook | { |
82 | 0633879f | pbrook | uint32_t sp; |
83 | 0633879f | pbrook | uint32_t fmt; |
84 | 0633879f | pbrook | |
85 | 0633879f | pbrook | sp = env->aregs[7];
|
86 | 0633879f | pbrook | fmt = ldl_kernel(sp); |
87 | 0633879f | pbrook | env->pc = ldl_kernel(sp + 4);
|
88 | 0633879f | pbrook | sp |= (fmt >> 28) & 3; |
89 | 0633879f | pbrook | env->sr = fmt & 0xffff;
|
90 | 0633879f | pbrook | env->aregs[7] = sp + 8; |
91 | 0633879f | pbrook | } |
92 | 0633879f | pbrook | |
93 | 0633879f | pbrook | void do_interrupt(int is_hw) |
94 | 0633879f | pbrook | { |
95 | 0633879f | pbrook | uint32_t sp; |
96 | 0633879f | pbrook | uint32_t fmt; |
97 | 0633879f | pbrook | uint32_t retaddr; |
98 | 0633879f | pbrook | uint32_t vector; |
99 | 0633879f | pbrook | |
100 | 0633879f | pbrook | fmt = 0;
|
101 | 0633879f | pbrook | retaddr = env->pc; |
102 | 0633879f | pbrook | |
103 | 0633879f | pbrook | if (!is_hw) {
|
104 | 0633879f | pbrook | switch (env->exception_index) {
|
105 | 0633879f | pbrook | case EXCP_RTE:
|
106 | 0633879f | pbrook | /* Return from an exception. */
|
107 | 0633879f | pbrook | do_rte(); |
108 | 0633879f | pbrook | return;
|
109 | a87295e8 | pbrook | case EXCP_HALT_INSN:
|
110 | a87295e8 | pbrook | if (semihosting_enabled
|
111 | a87295e8 | pbrook | && (env->sr & SR_S) != 0
|
112 | a87295e8 | pbrook | && (env->pc & 3) == 0 |
113 | a87295e8 | pbrook | && lduw_code(env->pc - 4) == 0x4e71 |
114 | a87295e8 | pbrook | && ldl_code(env->pc) == 0x4e7bf000) {
|
115 | a87295e8 | pbrook | env->pc += 4;
|
116 | a87295e8 | pbrook | do_m68k_semihosting(env, env->dregs[0]);
|
117 | a87295e8 | pbrook | return;
|
118 | a87295e8 | pbrook | } |
119 | a87295e8 | pbrook | env->halted = 1;
|
120 | a87295e8 | pbrook | env->exception_index = EXCP_HLT; |
121 | a87295e8 | pbrook | cpu_loop_exit(); |
122 | a87295e8 | pbrook | return;
|
123 | 0633879f | pbrook | } |
124 | 0633879f | pbrook | if (env->exception_index >= EXCP_TRAP0
|
125 | 0633879f | pbrook | && env->exception_index <= EXCP_TRAP15) { |
126 | 0633879f | pbrook | /* Move the PC after the trap instruction. */
|
127 | 0633879f | pbrook | retaddr += 2;
|
128 | 0633879f | pbrook | } |
129 | 0633879f | pbrook | } |
130 | 0633879f | pbrook | |
131 | 0633879f | pbrook | /* TODO: Implement USP. */
|
132 | 0633879f | pbrook | sp = env->aregs[7];
|
133 | 0633879f | pbrook | |
134 | 0633879f | pbrook | vector = env->exception_index << 2;
|
135 | 0633879f | pbrook | |
136 | 0633879f | pbrook | fmt |= 0x40000000;
|
137 | 0633879f | pbrook | fmt |= (sp & 3) << 28; |
138 | 0633879f | pbrook | fmt |= vector << 16;
|
139 | 0633879f | pbrook | fmt |= env->sr; |
140 | 0633879f | pbrook | |
141 | 0633879f | pbrook | /* ??? This could cause MMU faults. */
|
142 | 0633879f | pbrook | sp &= ~3;
|
143 | 0633879f | pbrook | sp -= 4;
|
144 | 0633879f | pbrook | stl_kernel(sp, retaddr); |
145 | 0633879f | pbrook | sp -= 4;
|
146 | 0633879f | pbrook | stl_kernel(sp, fmt); |
147 | 0633879f | pbrook | env->aregs[7] = sp;
|
148 | 0633879f | pbrook | env->sr |= SR_S; |
149 | 0633879f | pbrook | if (is_hw) {
|
150 | 0633879f | pbrook | env->sr = (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT); |
151 | 0633879f | pbrook | } |
152 | 0633879f | pbrook | /* Jump to vector. */
|
153 | 0633879f | pbrook | env->pc = ldl_kernel(env->vbr + vector); |
154 | 0633879f | pbrook | } |
155 | 0633879f | pbrook | |
156 | 0633879f | pbrook | #endif |