4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
23 #include "user-internals.h"
24 #include "cpu_loop-common.h"
25 #include "signal-common.h"
27 void cpu_loop(CPUAlphaState
*env
)
29 CPUState
*cs
= env_cpu(env
);
34 bool arch_interrupt
= true;
37 trapnr
= cpu_exec(cs
);
39 process_queued_cpu_work(cs
);
43 fprintf(stderr
, "Reset requested. Exit\n");
47 fprintf(stderr
, "Machine check exception. Exit\n");
50 case EXCP_SMP_INTERRUPT
:
51 case EXCP_CLK_INTERRUPT
:
52 case EXCP_DEV_INTERRUPT
:
53 fprintf(stderr
, "External interrupt. Exit\n");
58 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLOPC
, env
->pc
);
61 force_sig_fault(TARGET_SIGFPE
, TARGET_FPE_FLTINV
, env
->pc
);
64 /* No-op. Linux simply re-enables the FPU. */
67 switch (env
->error_code
) {
70 goto do_sigtrap_brkpt
;
76 trapnr
= env
->ir
[IR_V0
];
77 sysret
= do_syscall(env
, trapnr
,
78 env
->ir
[IR_A0
], env
->ir
[IR_A1
],
79 env
->ir
[IR_A2
], env
->ir
[IR_A3
],
80 env
->ir
[IR_A4
], env
->ir
[IR_A5
],
82 if (sysret
== -QEMU_ERESTARTSYS
) {
86 if (sysret
== -QEMU_ESIGRETURN
) {
89 /* Syscall writes 0 to V0 to bypass error check, similar
90 to how this is handled internal to Linux kernel.
91 (Ab)use trapnr temporarily as boolean indicating error. */
92 trapnr
= (env
->ir
[IR_V0
] != 0 && sysret
< 0);
93 env
->ir
[IR_V0
] = (trapnr
? -sysret
: sysret
);
94 env
->ir
[IR_A3
] = trapnr
;
98 /* ??? We can probably elide the code using page_unprotect
99 that is checking for self-modifying code. Instead we
100 could simply call tb_flush here. Until we work out the
101 changes required to turn off the extra write protection,
102 this can be a no-op. */
106 /* Handled in the translator for usermode. */
110 /* Handled in the translator for usermode. */
114 switch (env
->ir
[IR_A0
]) {
115 case TARGET_GEN_INTOVF
:
116 si_code
= TARGET_FPE_INTOVF
;
118 case TARGET_GEN_INTDIV
:
119 si_code
= TARGET_FPE_INTDIV
;
121 case TARGET_GEN_FLTOVF
:
122 si_code
= TARGET_FPE_FLTOVF
;
124 case TARGET_GEN_FLTUND
:
125 si_code
= TARGET_FPE_FLTUND
;
127 case TARGET_GEN_FLTINV
:
128 si_code
= TARGET_FPE_FLTINV
;
130 case TARGET_GEN_FLTINE
:
131 si_code
= TARGET_FPE_FLTRES
;
133 case TARGET_GEN_ROPRAND
:
134 si_code
= TARGET_FPE_FLTUNK
;
139 force_sig_fault(TARGET_SIGFPE
, si_code
, env
->pc
);
147 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
150 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_UNK
, env
->pc
);
153 /* Just indicate that signals should be handled asap. */
156 cpu_exec_step_atomic(cs
);
157 arch_interrupt
= false;
160 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
161 cpu_dump_state(cs
, stderr
, 0);
164 process_pending_signals (env
);
166 /* Most of the traps imply a transition through PALcode, which
167 implies an REI instruction has been executed. Which means
168 that RX and LOCK_ADDR should be cleared. But there are a
169 few exceptions for traps internal to QEMU. */
170 if (arch_interrupt
) {
171 env
->flags
&= ~ENV_FLAG_RX_FLAG
;
177 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
181 for(i
= 0; i
< 28; i
++) {
182 env
->ir
[i
] = ((abi_ulong
*)regs
)[i
];
184 env
->ir
[IR_SP
] = regs
->usp
;