]> git.proxmox.com Git - qemu.git/blame - target-sparc/helper.c
qemu-nbd: print error messages from the daemon through a pipe
[qemu.git] / target-sparc / helper.c
CommitLineData
e8af50a3 1/*
163fa5ca 2 * Misc Sparc helpers
5fafdf24 3 *
83469015 4 * Copyright (c) 2003-2005 Fabrice Bellard
e8af50a3
FB
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
8167ee88 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
e8af50a3 18 */
ee5bbe38
FB
19
20#include "cpu.h"
2336c1f1
BS
21#include "host-utils.h"
22#include "helper.h"
23#include "sysemu.h"
e8af50a3 24
bc265319
BS
25void helper_raise_exception(CPUState *env, int tt)
26{
27 env->exception_index = tt;
28 cpu_loop_exit(env);
29}
30
31void helper_debug(CPUState *env)
32{
33 env->exception_index = EXCP_DEBUG;
34 cpu_loop_exit(env);
35}
36
2336c1f1
BS
37void helper_shutdown(void)
38{
39#if !defined(CONFIG_USER_ONLY)
40 qemu_system_shutdown_request();
41#endif
42}
43
44#ifdef TARGET_SPARC64
45target_ulong helper_popc(target_ulong val)
46{
47 return ctpop64(val);
48}
49
50void helper_tick_set_count(void *opaque, uint64_t count)
51{
52#if !defined(CONFIG_USER_ONLY)
53 cpu_tick_set_count(opaque, count);
54#endif
55}
56
57uint64_t helper_tick_get_count(void *opaque)
58{
59#if !defined(CONFIG_USER_ONLY)
60 return cpu_tick_get_count(opaque);
61#else
62 return 0;
63#endif
64}
65
66void helper_tick_set_limit(void *opaque, uint64_t limit)
67{
68#if !defined(CONFIG_USER_ONLY)
69 cpu_tick_set_limit(opaque, limit);
70#endif
71}
72#endif
7a5e4488
BS
73
74static target_ulong helper_udiv_common(CPUState *env, target_ulong a,
75 target_ulong b, int cc)
76{
77 int overflow = 0;
78 uint64_t x0;
79 uint32_t x1;
80
81 x0 = (a & 0xffffffff) | ((int64_t) (env->y) << 32);
82 x1 = (b & 0xffffffff);
83
84 if (x1 == 0) {
85 helper_raise_exception(env, TT_DIV_ZERO);
86 }
87
88 x0 = x0 / x1;
89 if (x0 > 0xffffffff) {
90 x0 = 0xffffffff;
91 overflow = 1;
92 }
93
94 if (cc) {
95 env->cc_dst = x0;
96 env->cc_src2 = overflow;
97 env->cc_op = CC_OP_DIV;
98 }
99 return x0;
100}
101
102target_ulong helper_udiv(CPUState *env, target_ulong a, target_ulong b)
103{
104 return helper_udiv_common(env, a, b, 0);
105}
106
107target_ulong helper_udiv_cc(CPUState *env, target_ulong a, target_ulong b)
108{
109 return helper_udiv_common(env, a, b, 1);
110}
111
112static target_ulong helper_sdiv_common(CPUState *env, target_ulong a,
113 target_ulong b, int cc)
114{
115 int overflow = 0;
116 int64_t x0;
117 int32_t x1;
118
119 x0 = (a & 0xffffffff) | ((int64_t) (env->y) << 32);
120 x1 = (b & 0xffffffff);
121
122 if (x1 == 0) {
123 helper_raise_exception(env, TT_DIV_ZERO);
124 }
125
126 x0 = x0 / x1;
127 if ((int32_t) x0 != x0) {
128 x0 = x0 < 0 ? 0x80000000 : 0x7fffffff;
129 overflow = 1;
130 }
131
132 if (cc) {
133 env->cc_dst = x0;
134 env->cc_src2 = overflow;
135 env->cc_op = CC_OP_DIV;
136 }
137 return x0;
138}
139
140target_ulong helper_sdiv(CPUState *env, target_ulong a, target_ulong b)
141{
142 return helper_sdiv_common(env, a, b, 0);
143}
144
145target_ulong helper_sdiv_cc(CPUState *env, target_ulong a, target_ulong b)
146{
147 return helper_sdiv_common(env, a, b, 1);
148}