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 "cpu_loop-common.h"
24 static abi_ulong
hppa_lws(CPUHPPAState
*env
)
26 uint32_t which
= env
->gr
[20];
27 abi_ulong addr
= env
->gr
[26];
28 abi_ulong old
= env
->gr
[25];
29 abi_ulong
new = env
->gr
[24];
34 return -TARGET_ENOSYS
;
36 case 0: /* elf32 atomic 32bit cmpxchg */
37 if ((addr
& 3) || !access_ok(VERIFY_WRITE
, addr
, 4)) {
38 return -TARGET_EFAULT
;
42 ret
= atomic_cmpxchg((uint32_t *)g2h(addr
), old
, new);
46 case 2: /* elf32 atomic "new" cmpxchg */
49 return -TARGET_ENOSYS
;
51 if (((addr
| old
| new) & ((1 << size
) - 1))
52 || !access_ok(VERIFY_WRITE
, addr
, 1 << size
)
53 || !access_ok(VERIFY_READ
, old
, 1 << size
)
54 || !access_ok(VERIFY_READ
, new, 1 << size
)) {
55 return -TARGET_EFAULT
;
57 /* Note that below we use host-endian loads so that the cmpxchg
58 can be host-endian as well. */
61 old
= *(uint8_t *)g2h(old
);
62 new = *(uint8_t *)g2h(new);
63 ret
= atomic_cmpxchg((uint8_t *)g2h(addr
), old
, new);
67 old
= *(uint16_t *)g2h(old
);
68 new = *(uint16_t *)g2h(new);
69 ret
= atomic_cmpxchg((uint16_t *)g2h(addr
), old
, new);
73 old
= *(uint32_t *)g2h(old
);
74 new = *(uint32_t *)g2h(new);
75 ret
= atomic_cmpxchg((uint32_t *)g2h(addr
), old
, new);
80 uint64_t o64
, n64
, r64
;
81 o64
= *(uint64_t *)g2h(old
);
82 n64
= *(uint64_t *)g2h(new);
83 #ifdef CONFIG_ATOMIC64
84 r64
= atomic_cmpxchg__nocheck((uint64_t *)g2h(addr
), o64
, n64
);
88 r64
= *(uint64_t *)g2h(addr
);
91 *(uint64_t *)g2h(addr
) = n64
;
106 void cpu_loop(CPUHPPAState
*env
)
108 CPUState
*cs
= CPU(hppa_env_get_cpu(env
));
109 target_siginfo_t info
;
115 trapnr
= cpu_exec(cs
);
117 process_queued_cpu_work(cs
);
121 ret
= do_syscall(env
, env
->gr
[20],
122 env
->gr
[26], env
->gr
[25],
123 env
->gr
[24], env
->gr
[23],
124 env
->gr
[22], env
->gr
[21], 0, 0);
128 /* We arrived here by faking the gateway page. Return. */
129 env
->iaoq_f
= env
->gr
[31];
130 env
->iaoq_b
= env
->gr
[31] + 4;
132 case -TARGET_ERESTARTSYS
:
133 case -TARGET_QEMU_ESIGRETURN
:
137 case EXCP_SYSCALL_LWS
:
138 env
->gr
[21] = hppa_lws(env
);
139 /* We arrived here by faking the gateway page. Return. */
140 env
->iaoq_f
= env
->gr
[31];
141 env
->iaoq_b
= env
->gr
[31] + 4;
145 case EXCP_NA_ITLB_MISS
:
146 case EXCP_NA_DTLB_MISS
:
153 info
.si_signo
= TARGET_SIGSEGV
;
155 info
.si_code
= TARGET_SEGV_ACCERR
;
156 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
157 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
160 info
.si_signo
= TARGET_SIGBUS
;
163 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
164 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
169 info
.si_signo
= TARGET_SIGILL
;
171 info
.si_code
= TARGET_ILL_ILLOPN
;
172 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
173 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
178 info
.si_signo
= TARGET_SIGFPE
;
181 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
182 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
185 info
.si_signo
= TARGET_SIGTRAP
;
187 info
.si_code
= TARGET_TRAP_BRKPT
;
188 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
191 /* just indicate that signals should be handled asap */
194 g_assert_not_reached();
196 process_pending_signals(env
);
200 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
203 for (i
= 1; i
< 32; i
++) {
204 env
->gr
[i
] = regs
->gr
[i
];
206 env
->iaoq_f
= regs
->iaoq
[0];
207 env
->iaoq_b
= regs
->iaoq
[1];