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
= qatomic_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
= qatomic_cmpxchg((uint8_t *)g2h(addr
), old
, new);
67 old
= *(uint16_t *)g2h(old
);
68 new = *(uint16_t *)g2h(new);
69 ret
= qatomic_cmpxchg((uint16_t *)g2h(addr
), old
, new);
73 old
= *(uint32_t *)g2h(old
);
74 new = *(uint32_t *)g2h(new);
75 ret
= qatomic_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
= qatomic_cmpxchg__nocheck((uint64_t *)g2h(addr
),
89 r64
= *(uint64_t *)g2h(addr
);
92 *(uint64_t *)g2h(addr
) = n64
;
107 void cpu_loop(CPUHPPAState
*env
)
109 CPUState
*cs
= env_cpu(env
);
110 target_siginfo_t info
;
116 trapnr
= cpu_exec(cs
);
118 process_queued_cpu_work(cs
);
122 ret
= do_syscall(env
, env
->gr
[20],
123 env
->gr
[26], env
->gr
[25],
124 env
->gr
[24], env
->gr
[23],
125 env
->gr
[22], env
->gr
[21], 0, 0);
129 /* We arrived here by faking the gateway page. Return. */
130 env
->iaoq_f
= env
->gr
[31];
131 env
->iaoq_b
= env
->gr
[31] + 4;
133 case -TARGET_ERESTARTSYS
:
134 case -TARGET_QEMU_ESIGRETURN
:
138 case EXCP_SYSCALL_LWS
:
139 env
->gr
[21] = hppa_lws(env
);
140 /* We arrived here by faking the gateway page. Return. */
141 env
->iaoq_f
= env
->gr
[31];
142 env
->iaoq_b
= env
->gr
[31] + 4;
146 case EXCP_NA_ITLB_MISS
:
147 case EXCP_NA_DTLB_MISS
:
154 info
.si_signo
= TARGET_SIGSEGV
;
156 info
.si_code
= TARGET_SEGV_ACCERR
;
157 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
158 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
161 info
.si_signo
= TARGET_SIGBUS
;
164 info
._sifields
._sigfault
._addr
= env
->cr
[CR_IOR
];
165 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
170 info
.si_signo
= TARGET_SIGILL
;
172 info
.si_code
= TARGET_ILL_ILLOPN
;
173 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
174 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
179 info
.si_signo
= TARGET_SIGFPE
;
182 info
._sifields
._sigfault
._addr
= env
->iaoq_f
;
183 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
186 info
.si_signo
= TARGET_SIGTRAP
;
188 info
.si_code
= TARGET_TRAP_BRKPT
;
189 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
192 /* just indicate that signals should be handled asap */
195 g_assert_not_reached();
197 process_pending_signals(env
);
201 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
204 for (i
= 1; i
< 32; i
++) {
205 env
->gr
[i
] = regs
->gr
[i
];
207 env
->iaoq_f
= regs
->iaoq
[0];
208 env
->iaoq_b
= regs
->iaoq
[1];