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
);
31 target_siginfo_t info
;
35 bool arch_interrupt
= true;
38 trapnr
= cpu_exec(cs
);
40 process_queued_cpu_work(cs
);
44 fprintf(stderr
, "Reset requested. Exit\n");
48 fprintf(stderr
, "Machine check exception. Exit\n");
51 case EXCP_SMP_INTERRUPT
:
52 case EXCP_CLK_INTERRUPT
:
53 case EXCP_DEV_INTERRUPT
:
54 fprintf(stderr
, "External interrupt. Exit\n");
59 info
.si_signo
= TARGET_SIGILL
;
61 info
.si_code
= TARGET_ILL_ILLOPC
;
62 info
._sifields
._sigfault
._addr
= env
->pc
;
63 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
66 info
.si_signo
= TARGET_SIGFPE
;
68 info
.si_code
= TARGET_FPE_FLTINV
;
69 info
._sifields
._sigfault
._addr
= env
->pc
;
70 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
73 /* No-op. Linux simply re-enables the FPU. */
76 switch (env
->error_code
) {
79 info
.si_signo
= TARGET_SIGTRAP
;
81 info
.si_code
= TARGET_TRAP_BRKPT
;
82 info
._sifields
._sigfault
._addr
= env
->pc
;
83 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
87 info
.si_signo
= TARGET_SIGTRAP
;
90 info
._sifields
._sigfault
._addr
= env
->pc
;
91 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
95 trapnr
= env
->ir
[IR_V0
];
96 sysret
= do_syscall(env
, trapnr
,
97 env
->ir
[IR_A0
], env
->ir
[IR_A1
],
98 env
->ir
[IR_A2
], env
->ir
[IR_A3
],
99 env
->ir
[IR_A4
], env
->ir
[IR_A5
],
101 if (sysret
== -TARGET_ERESTARTSYS
) {
105 if (sysret
== -TARGET_QEMU_ESIGRETURN
) {
108 /* Syscall writes 0 to V0 to bypass error check, similar
109 to how this is handled internal to Linux kernel.
110 (Ab)use trapnr temporarily as boolean indicating error. */
111 trapnr
= (env
->ir
[IR_V0
] != 0 && sysret
< 0);
112 env
->ir
[IR_V0
] = (trapnr
? -sysret
: sysret
);
113 env
->ir
[IR_A3
] = trapnr
;
117 /* ??? We can probably elide the code using page_unprotect
118 that is checking for self-modifying code. Instead we
119 could simply call tb_flush here. Until we work out the
120 changes required to turn off the extra write protection,
121 this can be a no-op. */
125 /* Handled in the translator for usermode. */
129 /* Handled in the translator for usermode. */
133 info
.si_signo
= TARGET_SIGFPE
;
134 switch (env
->ir
[IR_A0
]) {
135 case TARGET_GEN_INTOVF
:
136 info
.si_code
= TARGET_FPE_INTOVF
;
138 case TARGET_GEN_INTDIV
:
139 info
.si_code
= TARGET_FPE_INTDIV
;
141 case TARGET_GEN_FLTOVF
:
142 info
.si_code
= TARGET_FPE_FLTOVF
;
144 case TARGET_GEN_FLTUND
:
145 info
.si_code
= TARGET_FPE_FLTUND
;
147 case TARGET_GEN_FLTINV
:
148 info
.si_code
= TARGET_FPE_FLTINV
;
150 case TARGET_GEN_FLTINE
:
151 info
.si_code
= TARGET_FPE_FLTRES
;
153 case TARGET_GEN_ROPRAND
:
157 info
.si_signo
= TARGET_SIGTRAP
;
162 info
._sifields
._sigfault
._addr
= env
->pc
;
163 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
170 info
.si_signo
= TARGET_SIGTRAP
;
172 info
.si_code
= TARGET_TRAP_BRKPT
;
173 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
176 /* Just indicate that signals should be handled asap. */
179 cpu_exec_step_atomic(cs
);
180 arch_interrupt
= false;
183 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
184 cpu_dump_state(cs
, stderr
, 0);
187 process_pending_signals (env
);
189 /* Most of the traps imply a transition through PALcode, which
190 implies an REI instruction has been executed. Which means
191 that RX and LOCK_ADDR should be cleared. But there are a
192 few exceptions for traps internal to QEMU. */
193 if (arch_interrupt
) {
194 env
->flags
&= ~ENV_FLAG_RX_FLAG
;
200 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
204 for(i
= 0; i
< 28; i
++) {
205 env
->ir
[i
] = ((abi_ulong
*)regs
)[i
];
207 env
->ir
[IR_SP
] = regs
->usp
;