summaryrefslogtreecommitdiff
path: root/target-ppc
diff options
context:
space:
mode:
authorj_mayer <j_mayer@c046a42c-6fe2-441c-8c8c-71466251a162>2007-11-12 00:04:48 +0000
committerj_mayer <j_mayer@c046a42c-6fe2-441c-8c8c-71466251a162>2007-11-12 00:04:48 +0000
commit6f2d8978728c48ca46f5c01835438508aace5c64 (patch)
tree73172710b5af52a2d988a58fb24945a24d42da84 /target-ppc
parent8582a53a34b2d3fe811d29703eed7519efdf8f2e (diff)
downloadqemu-6f2d8978728c48ca46f5c01835438508aace5c64.zip
Fix usage of the -1 constant in the PowerPC target code:
fix invalid size casts and/or sign-extensions. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3626 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'target-ppc')
-rw-r--r--target-ppc/helper.c16
-rw-r--r--target-ppc/op.c20
-rw-r--r--target-ppc/op_helper.c59
-rw-r--r--target-ppc/translate.c10
4 files changed, 54 insertions, 51 deletions
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index f7df19e1c0..4937a75482 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -199,7 +199,7 @@ static always_inline int _pte_check (mmu_ctx_t *ctx, int is_64b,
pp = pte1 & 0x00000003;
}
if (ptem == ctx->ptem) {
- if (ctx->raddr != (target_ulong)-1) {
+ if (ctx->raddr != (target_phys_addr_t)-1ULL) {
/* all matches should have equal RPN, WIMG & PP */
if ((ctx->raddr & mmask) != (pte1 & mmask)) {
if (loglevel != 0)
@@ -900,7 +900,7 @@ static always_inline target_phys_addr_t get_pgaddr (target_phys_addr_t sdr1,
target_phys_addr_t hash,
target_phys_addr_t mask)
{
- return (sdr1 & ((target_ulong)(-1ULL) << sdr_sh)) | (hash & mask);
+ return (sdr1 & ((target_phys_addr_t)(-1ULL) << sdr_sh)) | (hash & mask);
}
static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
@@ -1011,7 +1011,7 @@ static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
ctx->ptem = (vsid << 7) | (pgidx >> 10);
}
/* Initialize real address with an invalid value */
- ctx->raddr = (target_ulong)-1;
+ ctx->raddr = (target_phys_addr_t)-1ULL;
if (unlikely(env->mmu_model == POWERPC_MMU_SOFT_6xx ||
env->mmu_model == POWERPC_MMU_SOFT_74xx)) {
/* Software TLB search */
@@ -1223,7 +1223,7 @@ int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
int i, ret, zsel, zpr, pr;
ret = -1;
- raddr = -1;
+ raddr = (target_phys_addr_t)-1ULL;
pr = msr_pr;
for (i = 0; i < env->nb_tlb; i++) {
tlb = &env->tlb[i].tlbe;
@@ -1306,7 +1306,7 @@ int mmubooke_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
int i, prot, ret;
ret = -1;
- raddr = -1;
+ raddr = (target_phys_addr_t)-1ULL;
for (i = 0; i < env->nb_tlb; i++) {
tlb = &env->tlb[i].tlbe;
if (ppcemb_tlb_check(env, tlb, &raddr, address,
@@ -1975,7 +1975,7 @@ void ppc_tlb_invalidate_one (CPUPPCState *env, target_ulong addr)
case POWERPC_MMU_32B:
case POWERPC_MMU_601:
/* tlbie invalidate TLBs for all segments */
- addr &= ~((target_ulong)-1 << 28);
+ addr &= ~((target_ulong)-1ULL << 28);
/* XXX: this case should be optimized,
* giving a mask to tlb_flush_page
*/
@@ -2730,7 +2730,7 @@ static always_inline void powerpc_excp (CPUState *env,
new_msr &= ~((target_ulong)1 << MSR_LE);
/* Jump to handler */
vector = env->excp_vectors[excp];
- if (vector == (target_ulong)-1) {
+ if (vector == (target_ulong)-1ULL) {
cpu_abort(env, "Raised an exception without defined vector %d\n",
excp);
}
@@ -2961,7 +2961,7 @@ void cpu_ppc_reset (void *opaque)
#endif
env->msr = msr;
hreg_compute_hflags(env);
- env->reserve = -1;
+ env->reserve = (target_ulong)-1ULL;
/* Be sure no exception or interrupt is pending */
env->pending_interrupts = 0;
env->exception_index = POWERPC_EXCP_NONE;
diff --git a/target-ppc/op.c b/target-ppc/op.c
index 81c426c1a7..621b975502 100644
--- a/target-ppc/op.c
+++ b/target-ppc/op.c
@@ -959,9 +959,9 @@ void OPPROTO op_add_ze (void)
/* divide word */
void OPPROTO op_divw (void)
{
- if (unlikely(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) ||
+ if (unlikely(((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
(int32_t)T1 == 0)) {
- T0 = (int32_t)((-1) * ((uint32_t)T0 >> 31));
+ T0 = (int32_t)(UINT32_MAX * ((uint32_t)T0 >> 31));
} else {
T0 = (int32_t)T0 / (int32_t)T1;
}
@@ -971,9 +971,9 @@ void OPPROTO op_divw (void)
#if defined(TARGET_PPC64)
void OPPROTO op_divd (void)
{
- if (unlikely(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1) ||
+ if (unlikely(((int64_t)T0 == INT64_MIN && (int64_t)T1 == (int64_t)-1LL) ||
(int64_t)T1 == 0)) {
- T0 = (int64_t)((-1ULL) * ((uint64_t)T0 >> 63));
+ T0 = (int64_t)(UINT64_MAX * ((uint64_t)T0 >> 63));
} else {
T0 = (int64_t)T0 / (int64_t)T1;
}
@@ -2006,7 +2006,7 @@ void OPPROTO op_check_reservation (void)
void OPPROTO op_check_reservation_64 (void)
{
if ((uint64_t)env->reserve == (uint64_t)(T0 & ~0x00000003))
- env->reserve = -1;
+ env->reserve = (target_ulong)-1ULL;
RETURN();
}
#endif
@@ -2344,7 +2344,7 @@ void OPPROTO op_POWER_sleq (void)
void OPPROTO op_POWER_sllq (void)
{
- uint32_t msk = -1;
+ uint32_t msk = UINT32_MAX;
msk = msk << (T1 & 0x1FUL);
if (T1 & 0x20UL)
@@ -2357,7 +2357,7 @@ void OPPROTO op_POWER_sllq (void)
void OPPROTO op_POWER_slq (void)
{
- uint32_t msk = -1, tmp;
+ uint32_t msk = UINT32_MAX, tmp;
msk = msk << (T1 & 0x1FUL);
if (T1 & 0x20UL)
@@ -2373,7 +2373,7 @@ void OPPROTO op_POWER_sraq (void)
{
env->spr[SPR_MQ] = rotl32(T0, 32 - (T1 & 0x1FUL));
if (T1 & 0x20UL)
- T0 = -1L;
+ T0 = UINT32_MAX;
else
T0 = (int32_t)T0 >> T1;
RETURN();
@@ -2529,7 +2529,7 @@ void OPPROTO op_405_check_satu (void)
{
if (unlikely(T0 < T2)) {
/* Saturate result */
- T0 = -1;
+ T0 = UINT32_MAX;
}
RETURN();
}
@@ -2602,7 +2602,7 @@ void OPPROTO op_4xx_tlbsx_check (void)
int tmp;
tmp = xer_so;
- if (T0 != -1)
+ if ((int)T0 != -1)
tmp |= 0x02;
env->crf[0] = tmp;
RETURN();
diff --git a/target-ppc/op_helper.c b/target-ppc/op_helper.c
index 2c6cef1271..68e90ceb57 100644
--- a/target-ppc/op_helper.c
+++ b/target-ppc/op_helper.c
@@ -175,29 +175,29 @@ void do_addmeo_64 (void)
void do_divwo (void)
{
- if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) ||
+ if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
(int32_t)T1 == 0))) {
xer_ov = 0;
T0 = (int32_t)T0 / (int32_t)T1;
} else {
xer_ov = 1;
- xer_so = 1;
- T0 = (-1) * ((uint32_t)T0 >> 31);
+ T0 = UINT32_MAX * ((uint32_t)T0 >> 31);
}
+ xer_so |= xer_ov;
}
#if defined(TARGET_PPC64)
void do_divdo (void)
{
- if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1ULL) ||
+ if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == (int64_t)-1LL) ||
(int64_t)T1 == 0))) {
xer_ov = 0;
T0 = (int64_t)T0 / (int64_t)T1;
} else {
xer_ov = 1;
- xer_so = 1;
- T0 = (-1ULL) * ((uint64_t)T0 >> 63);
+ T0 = UINT64_MAX * ((uint64_t)T0 >> 63);
}
+ xer_so |= xer_ov;
}
#endif
@@ -247,14 +247,14 @@ void do_mulldo (void)
uint64_t tl;
muls64(&tl, &th, T0, T1);
+ T0 = (int64_t)tl;
/* If th != 0 && th != -1, then we had an overflow */
- if (likely((th + 1) <= 1)) {
+ if (likely((uint64_t)(th + 1) <= 1)) {
xer_ov = 0;
} else {
xer_ov = 1;
- xer_so = 1;
}
- T0 = (int64_t)tl;
+ xer_so |= xer_ov;
}
#endif
@@ -392,7 +392,7 @@ void do_sraw (void)
xer_ca = 0;
}
} else {
- ret = (-1) * ((uint32_t)T0 >> 31);
+ ret = UINT32_MAX * ((uint32_t)T0 >> 31);
if (likely(ret >= 0 || ((uint32_t)T0 & ~0x80000000UL) == 0)) {
xer_ca = 0;
} else {
@@ -420,7 +420,7 @@ void do_srad (void)
xer_ca = 0;
}
} else {
- ret = (-1) * ((uint64_t)T0 >> 63);
+ ret = UINT64_MAX * ((uint64_t)T0 >> 63);
if (likely(ret >= 0 || ((uint64_t)T0 & ~0x8000000000000000ULL) == 0)) {
xer_ca = 0;
} else {
@@ -609,7 +609,7 @@ static always_inline void fload_invalid_op_excp (int op)
env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));
if (ve == 0) {
/* Set the result to quiet NaN */
- FT0 = (uint64_t)-1;
+ FT0 = UINT64_MAX;
env->fpscr &= ~(0xF << FPSCR_FPCC);
env->fpscr |= 0x11 << FPSCR_FPCC;
}
@@ -620,7 +620,7 @@ static always_inline void fload_invalid_op_excp (int op)
env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));
if (ve == 0) {
/* Set the result to quiet NaN */
- FT0 = (uint64_t)-1;
+ FT0 = UINT64_MAX;
env->fpscr &= ~(0xF << FPSCR_FPCC);
env->fpscr |= 0x11 << FPSCR_FPCC;
}
@@ -1555,8 +1555,9 @@ void do_POWER_div (void)
{
uint64_t tmp;
- if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
- T0 = (long)((-1) * (T0 >> 31));
+ if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
+ (int32_t)T1 == 0) {
+ T0 = UINT32_MAX * ((uint32_t)T0 >> 31);
env->spr[SPR_MQ] = 0;
} else {
tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
@@ -1569,29 +1570,30 @@ void do_POWER_divo (void)
{
int64_t tmp;
- if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
- T0 = (long)((-1) * (T0 >> 31));
+ if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
+ (int32_t)T1 == 0) {
+ T0 = UINT32_MAX * ((uint32_t)T0 >> 31);
env->spr[SPR_MQ] = 0;
xer_ov = 1;
- xer_so = 1;
} else {
tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
env->spr[SPR_MQ] = tmp % T1;
tmp /= (int32_t)T1;
if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) {
xer_ov = 1;
- xer_so = 1;
} else {
xer_ov = 0;
}
T0 = tmp;
}
+ xer_so |= xer_ov;
}
void do_POWER_divs (void)
{
- if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
- T0 = (long)((-1) * (T0 >> 31));
+ if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
+ (int32_t)T1 == 0) {
+ T0 = UINT32_MAX * ((uint32_t)T0 >> 31);
env->spr[SPR_MQ] = 0;
} else {
env->spr[SPR_MQ] = T0 % T1;
@@ -1601,16 +1603,17 @@ void do_POWER_divs (void)
void do_POWER_divso (void)
{
- if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
- T0 = (long)((-1) * (T0 >> 31));
+ if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == (int32_t)-1) ||
+ (int32_t)T1 == 0) {
+ T0 = UINT32_MAX * ((uint32_t)T0 >> 31);
env->spr[SPR_MQ] = 0;
xer_ov = 1;
- xer_so = 1;
} else {
T0 = (int32_t)T0 / (int32_t)T1;
env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1;
xer_ov = 0;
}
+ xer_so |= xer_ov;
}
void do_POWER_dozo (void)
@@ -1636,10 +1639,10 @@ void do_POWER_maskg (void)
uint32_t ret;
if ((uint32_t)T0 == (uint32_t)(T1 + 1)) {
- ret = -1;
+ ret = UINT32_MAX;
} else {
- ret = (((uint32_t)(-1)) >> ((uint32_t)T0)) ^
- (((uint32_t)(-1) >> ((uint32_t)T1)) >> 1);
+ ret = (UINT32_MAX >> ((uint32_t)T0)) ^
+ ((UINT32_MAX >> ((uint32_t)T1)) >> 1);
if ((uint32_t)T0 > (uint32_t)T1)
ret = ~ret;
}
@@ -1874,7 +1877,7 @@ void do_brinc (void)
{
uint32_t a, b, d, mask;
- mask = (uint32_t)(-1UL) >> MASKBITS;
+ mask = UINT32_MAX >> MASKBITS;
b = T1_64 & mask;
a = T0_64 & mask;
d = word_reverse(1 + word_reverse(a | ~mask));
diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index 73b2e2212c..be4ac53909 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -404,15 +404,15 @@ static always_inline target_ulong MASK (uint32_t start, uint32_t end)
#if defined(TARGET_PPC64)
if (likely(start == 0)) {
- ret = (uint64_t)(-1ULL) << (63 - end);
+ ret = UINT64_MAX << (63 - end);
} else if (likely(end == 63)) {
- ret = (uint64_t)(-1ULL) >> start;
+ ret = UINT64_MAX >> start;
}
#else
if (likely(start == 0)) {
- ret = (uint32_t)(-1ULL) << (31 - end);
+ ret = UINT32_MAX << (31 - end);
} else if (likely(end == 31)) {
- ret = (uint32_t)(-1ULL) >> start;
+ ret = UINT32_MAX >> start;
}
#endif
else {
@@ -3517,7 +3517,7 @@ GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
}
#if 1
-#define SPR_NOACCESS ((void *)(-1))
+#define SPR_NOACCESS ((void *)(-1UL))
#else
static void spr_noaccess (void *opaque, int sprn)
{