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(CPUNios2State
*env
)
28 CPUState
*cs
= env_cpu(env
);
29 target_siginfo_t info
;
34 trapnr
= cpu_exec(cs
);
39 /* just indicate that signals should be handled asap */
43 switch (env
->error_code
) {
45 qemu_log_mask(CPU_LOG_INT
, "\nSyscall\n");
47 ret
= do_syscall(env
, env
->regs
[2],
48 env
->regs
[4], env
->regs
[5], env
->regs
[6],
49 env
->regs
[7], env
->regs
[8], env
->regs
[9],
52 if (env
->regs
[2] == 0) { /* FIXME: syscall 0 workaround */
56 env
->regs
[2] = abs(ret
);
57 /* Return value is 0..4096 */
58 env
->regs
[7] = ret
> 0xfffff000u
;
63 qemu_log_mask(CPU_LOG_INT
, "\nTrap 1\n");
64 force_sig_fault(TARGET_SIGUSR1
, 0, env
->regs
[R_PC
]);
67 qemu_log_mask(CPU_LOG_INT
, "\nTrap 2\n");
68 force_sig_fault(TARGET_SIGUSR2
, 0, env
->regs
[R_PC
]);
71 qemu_log_mask(CPU_LOG_INT
, "\nTrap 31\n");
72 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->regs
[R_PC
]);
75 qemu_log_mask(CPU_LOG_INT
, "\nTrap %d\n", env
->error_code
);
76 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLTRP
,
80 case 16: /* QEMU specific, for __kuser_cmpxchg */
82 abi_ptr g
= env
->regs
[4];
86 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
, g
);
89 ret
= page_get_flags(g
);
90 if (!(ret
& PAGE_VALID
)) {
91 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_MAPERR
, g
);
94 if (!(ret
& PAGE_READ
) || !(ret
& PAGE_WRITE
)) {
95 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_ACCERR
, g
);
101 env
->regs
[2] = qatomic_cmpxchg(h
, o
, n
) - o
;
102 env
->regs
[R_PC
] += 4;
109 info
.si_signo
= TARGET_SIGTRAP
;
111 info
.si_code
= TARGET_TRAP_BRKPT
;
112 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
116 info
.si_signo
= TARGET_SIGSEGV
;
118 /* TODO: check env->error_code */
119 info
.si_code
= TARGET_SEGV_MAPERR
;
120 info
._sifields
._sigfault
._addr
= env
->regs
[R_PC
];
121 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
125 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
130 process_pending_signals(env
);
134 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
137 env
->regs
[1] = regs
->r1
;
138 env
->regs
[2] = regs
->r2
;
139 env
->regs
[3] = regs
->r3
;
140 env
->regs
[4] = regs
->r4
;
141 env
->regs
[5] = regs
->r5
;
142 env
->regs
[6] = regs
->r6
;
143 env
->regs
[7] = regs
->r7
;
144 env
->regs
[8] = regs
->r8
;
145 env
->regs
[9] = regs
->r9
;
146 env
->regs
[10] = regs
->r10
;
147 env
->regs
[11] = regs
->r11
;
148 env
->regs
[12] = regs
->r12
;
149 env
->regs
[13] = regs
->r13
;
150 env
->regs
[14] = regs
->r14
;
151 env
->regs
[15] = regs
->r15
;
152 /* TODO: unsigned long orig_r2; */
153 env
->regs
[R_RA
] = regs
->ra
;
154 env
->regs
[R_FP
] = regs
->fp
;
155 env
->regs
[R_SP
] = regs
->sp
;
156 env
->regs
[R_GP
] = regs
->gp
;
157 env
->regs
[CR_ESTATUS
] = regs
->estatus
;
158 env
->regs
[R_PC
] = regs
->ea
;
159 /* TODO: unsigned long orig_r7; */