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 static abi_ulong
hppa_lws(CPUHPPAState
*env
)
28 CPUState
*cs
= env_cpu(env
);
29 uint32_t which
= env
->gr
[20];
30 abi_ulong addr
= env
->gr
[26];
31 abi_ulong old
= env
->gr
[25];
32 abi_ulong
new = env
->gr
[24];
37 return -TARGET_ENOSYS
;
39 case 0: /* elf32 atomic 32bit cmpxchg */
40 if ((addr
& 3) || !access_ok(cs
, VERIFY_WRITE
, addr
, 4)) {
41 return -TARGET_EFAULT
;
45 ret
= qatomic_cmpxchg((uint32_t *)g2h(cs
, addr
), old
, new);
49 case 2: /* elf32 atomic "new" cmpxchg */
52 return -TARGET_ENOSYS
;
54 if (((addr
| old
| new) & ((1 << size
) - 1))
55 || !access_ok(cs
, VERIFY_WRITE
, addr
, 1 << size
)
56 || !access_ok(cs
, VERIFY_READ
, old
, 1 << size
)
57 || !access_ok(cs
, VERIFY_READ
, new, 1 << size
)) {
58 return -TARGET_EFAULT
;
60 /* Note that below we use host-endian loads so that the cmpxchg
61 can be host-endian as well. */
64 old
= *(uint8_t *)g2h(cs
, old
);
65 new = *(uint8_t *)g2h(cs
, new);
66 ret
= qatomic_cmpxchg((uint8_t *)g2h(cs
, addr
), old
, new);
70 old
= *(uint16_t *)g2h(cs
, old
);
71 new = *(uint16_t *)g2h(cs
, new);
72 ret
= qatomic_cmpxchg((uint16_t *)g2h(cs
, addr
), old
, new);
76 old
= *(uint32_t *)g2h(cs
, old
);
77 new = *(uint32_t *)g2h(cs
, new);
78 ret
= qatomic_cmpxchg((uint32_t *)g2h(cs
, addr
), old
, new);
83 uint64_t o64
, n64
, r64
;
84 o64
= *(uint64_t *)g2h(cs
, old
);
85 n64
= *(uint64_t *)g2h(cs
, new);
86 #ifdef CONFIG_ATOMIC64
87 r64
= qatomic_cmpxchg__nocheck((aligned_uint64_t
*)g2h(cs
, addr
),
92 r64
= *(uint64_t *)g2h(cs
, addr
);
95 *(uint64_t *)g2h(cs
, addr
) = n64
;
110 void cpu_loop(CPUHPPAState
*env
)
112 CPUState
*cs
= env_cpu(env
);
113 target_siginfo_t info
;
119 trapnr
= cpu_exec(cs
);
121 process_queued_cpu_work(cs
);
125 ret
= do_syscall(env
, env
->gr
[20],
126 env
->gr
[26], env
->gr
[25],
127 env
->gr
[24], env
->gr
[23],
128 env
->gr
[22], env
->gr
[21], 0, 0);
132 /* We arrived here by faking the gateway page. Return. */
133 env
->iaoq_f
= env
->gr
[31];
134 env
->iaoq_b
= env
->gr
[31] + 4;
136 case -TARGET_ERESTARTSYS
:
137 case -TARGET_QEMU_ESIGRETURN
:
141 case EXCP_SYSCALL_LWS
:
142 env
->gr
[21] = hppa_lws(env
);
143 /* We arrived here by faking the gateway page. Return. */
144 env
->iaoq_f
= env
->gr
[31];
145 env
->iaoq_b
= env
->gr
[31] + 4;
150 info
.si_signo
= TARGET_SIGILL
;
152 info
.si_code
= TARGET_ILL_ILLOPN
;
153 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
154 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
159 info
.si_signo
= TARGET_SIGFPE
;
162 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
163 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
166 info
.si_signo
= TARGET_SIGTRAP
;
168 info
.si_code
= TARGET_TRAP_BRKPT
;
169 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
172 /* just indicate that signals should be handled asap */
175 g_assert_not_reached();
177 process_pending_signals(env
);
181 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
184 for (i
= 1; i
< 32; i
++) {
185 env
->gr
[i
] = regs
->gr
[i
];
187 env
->iaoq_f
= regs
->iaoq
[0];
188 env
->iaoq_b
= regs
->iaoq
[1];