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 CPUState
*cs
= env_cpu(env
);
27 uint32_t which
= env
->gr
[20];
28 abi_ulong addr
= env
->gr
[26];
29 abi_ulong old
= env
->gr
[25];
30 abi_ulong
new = env
->gr
[24];
35 return -TARGET_ENOSYS
;
37 case 0: /* elf32 atomic 32bit cmpxchg */
38 if ((addr
& 3) || !access_ok(cs
, VERIFY_WRITE
, addr
, 4)) {
39 return -TARGET_EFAULT
;
43 ret
= qatomic_cmpxchg((uint32_t *)g2h(cs
, addr
), old
, new);
47 case 2: /* elf32 atomic "new" cmpxchg */
50 return -TARGET_ENOSYS
;
52 if (((addr
| old
| new) & ((1 << size
) - 1))
53 || !access_ok(cs
, VERIFY_WRITE
, addr
, 1 << size
)
54 || !access_ok(cs
, VERIFY_READ
, old
, 1 << size
)
55 || !access_ok(cs
, VERIFY_READ
, new, 1 << size
)) {
56 return -TARGET_EFAULT
;
58 /* Note that below we use host-endian loads so that the cmpxchg
59 can be host-endian as well. */
62 old
= *(uint8_t *)g2h(cs
, old
);
63 new = *(uint8_t *)g2h(cs
, new);
64 ret
= qatomic_cmpxchg((uint8_t *)g2h(cs
, addr
), old
, new);
68 old
= *(uint16_t *)g2h(cs
, old
);
69 new = *(uint16_t *)g2h(cs
, new);
70 ret
= qatomic_cmpxchg((uint16_t *)g2h(cs
, addr
), old
, new);
74 old
= *(uint32_t *)g2h(cs
, old
);
75 new = *(uint32_t *)g2h(cs
, new);
76 ret
= qatomic_cmpxchg((uint32_t *)g2h(cs
, addr
), old
, new);
81 uint64_t o64
, n64
, r64
;
82 o64
= *(uint64_t *)g2h(cs
, old
);
83 n64
= *(uint64_t *)g2h(cs
, new);
84 #ifdef CONFIG_ATOMIC64
85 r64
= qatomic_cmpxchg__nocheck((uint64_t *)g2h(cs
, addr
),
90 r64
= *(uint64_t *)g2h(cs
, addr
);
93 *(uint64_t *)g2h(cs
, addr
) = n64
;
108 void cpu_loop(CPUHPPAState
*env
)
110 CPUState
*cs
= env_cpu(env
);
111 target_siginfo_t info
;
117 trapnr
= cpu_exec(cs
);
119 process_queued_cpu_work(cs
);
123 ret
= do_syscall(env
, env
->gr
[20],
124 env
->gr
[26], env
->gr
[25],
125 env
->gr
[24], env
->gr
[23],
126 env
->gr
[22], env
->gr
[21], 0, 0);
130 /* We arrived here by faking the gateway page. Return. */
131 env
->iaoq_f
= env
->gr
[31];
132 env
->iaoq_b
= env
->gr
[31] + 4;
134 case -TARGET_ERESTARTSYS
:
135 case -TARGET_QEMU_ESIGRETURN
:
139 case EXCP_SYSCALL_LWS
:
140 env
->gr
[21] = hppa_lws(env
);
141 /* We arrived here by faking the gateway page. Return. */
142 env
->iaoq_f
= env
->gr
[31];
143 env
->iaoq_b
= env
->gr
[31] + 4;
147 case EXCP_NA_ITLB_MISS
:
148 case EXCP_NA_DTLB_MISS
:
155 info
.si_signo
= TARGET_SIGSEGV
;
157 info
.si_code
= TARGET_SEGV_ACCERR
;
158 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
159 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
162 info
.si_signo
= TARGET_SIGBUS
;
165 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
166 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
171 info
.si_signo
= TARGET_SIGILL
;
173 info
.si_code
= TARGET_ILL_ILLOPN
;
174 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
175 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
180 info
.si_signo
= TARGET_SIGFPE
;
183 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
184 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
187 info
.si_signo
= TARGET_SIGTRAP
;
189 info
.si_code
= TARGET_TRAP_BRKPT
;
190 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
193 /* just indicate that signals should be handled asap */
196 g_assert_not_reached();
198 process_pending_signals(env
);
202 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
205 for (i
= 1; i
< 32; i
++) {
206 env
->gr
[i
] = regs
->gr
[i
];
208 env
->iaoq_f
= regs
->iaoq
[0];
209 env
->iaoq_b
= regs
->iaoq
[1];