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"
22 #include "user-internals.h"
23 #include "cpu_loop-common.h"
24 #include "signal-common.h"
26 void cpu_loop(CPUAlphaState
*env
)
28 CPUState
*cs
= env_cpu(env
);
33 bool arch_interrupt
= true;
36 trapnr
= cpu_exec(cs
);
38 process_queued_cpu_work(cs
);
42 fprintf(stderr
, "Reset requested. Exit\n");
46 fprintf(stderr
, "Machine check exception. Exit\n");
49 case EXCP_SMP_INTERRUPT
:
50 case EXCP_CLK_INTERRUPT
:
51 case EXCP_DEV_INTERRUPT
:
52 fprintf(stderr
, "External interrupt. Exit\n");
57 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLOPC
, env
->pc
);
60 force_sig_fault(TARGET_SIGFPE
, TARGET_FPE_FLTINV
, env
->pc
);
63 /* No-op. Linux simply re-enables the FPU. */
66 switch (env
->error_code
) {
69 goto do_sigtrap_brkpt
;
75 trapnr
= env
->ir
[IR_V0
];
76 sysret
= do_syscall(env
, trapnr
,
77 env
->ir
[IR_A0
], env
->ir
[IR_A1
],
78 env
->ir
[IR_A2
], env
->ir
[IR_A3
],
79 env
->ir
[IR_A4
], env
->ir
[IR_A5
],
81 if (sysret
== -QEMU_ERESTARTSYS
) {
85 if (sysret
== -QEMU_ESIGRETURN
) {
88 /* Syscall writes 0 to V0 to bypass error check, similar
89 to how this is handled internal to Linux kernel.
90 (Ab)use trapnr temporarily as boolean indicating error. */
91 trapnr
= (env
->ir
[IR_V0
] != 0 && sysret
< 0);
92 env
->ir
[IR_V0
] = (trapnr
? -sysret
: sysret
);
93 env
->ir
[IR_A3
] = trapnr
;
97 /* ??? We can probably elide the code using page_unprotect
98 that is checking for self-modifying code. Instead we
99 could simply call tb_flush here. Until we work out the
100 changes required to turn off the extra write protection,
101 this can be a no-op. */
105 /* Handled in the translator for usermode. */
109 /* Handled in the translator for usermode. */
113 switch (env
->ir
[IR_A0
]) {
114 case TARGET_GEN_INTOVF
:
115 si_code
= TARGET_FPE_INTOVF
;
117 case TARGET_GEN_INTDIV
:
118 si_code
= TARGET_FPE_INTDIV
;
120 case TARGET_GEN_FLTOVF
:
121 si_code
= TARGET_FPE_FLTOVF
;
123 case TARGET_GEN_FLTUND
:
124 si_code
= TARGET_FPE_FLTUND
;
126 case TARGET_GEN_FLTINV
:
127 si_code
= TARGET_FPE_FLTINV
;
129 case TARGET_GEN_FLTINE
:
130 si_code
= TARGET_FPE_FLTRES
;
132 case TARGET_GEN_ROPRAND
:
133 si_code
= TARGET_FPE_FLTUNK
;
138 force_sig_fault(TARGET_SIGFPE
, si_code
, env
->pc
);
146 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
149 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_UNK
, env
->pc
);
152 /* Just indicate that signals should be handled asap. */
155 cpu_exec_step_atomic(cs
);
156 arch_interrupt
= false;
159 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
160 cpu_dump_state(cs
, stderr
, 0);
163 process_pending_signals (env
);
165 /* Most of the traps imply a transition through PALcode, which
166 implies an REI instruction has been executed. Which means
167 that RX and LOCK_ADDR should be cleared. But there are a
168 few exceptions for traps internal to QEMU. */
169 if (arch_interrupt
) {
170 env
->flags
&= ~ENV_FLAG_RX_FLAG
;
176 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
180 for(i
= 0; i
< 28; i
++) {
181 env
->ir
[i
] = ((abi_ulong
*)regs
)[i
];
183 env
->ir
[IR_SP
] = regs
->usp
;