From patchwork Sun Sep 9 21:04:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 182752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 029242C008E for ; Mon, 10 Sep 2012 09:23:19 +1000 (EST) Received: from localhost ([::1]:57722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAold-0003DN-Jc for incoming@patchwork.ozlabs.org; Sun, 09 Sep 2012 17:10:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAoia-0007H5-Su for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAoiZ-0005y7-Lp for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:07:00 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:63059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAoiZ-0005pO-FO for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:06:59 -0400 Received: by mail-pz0-f45.google.com with SMTP id n15so968311dad.4 for ; Sun, 09 Sep 2012 14:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=5tqiZb/E5SP+LB/khEVNM4qo2Bnin51M167Fdo8KLMw=; b=b4L1MYY2SRn1IWEaEb1UHYaRhu6Sr1E99E464+fx4N+z8tYKFXIsc8wCYmNmo3Lh/N DyvPwANwPuEdqglFrtooWp6T71z5WihFdlJyxXbTdrtkmRbGT7EuTH/8P1dXuSyczFIl WZCCUBzwBL0tmZorlGi6xrkwDHrwfQPLmK/ifbKP1SLm+iNdSmhgCab3Cbcpi6jaN0vz S13EPjovjy2OvFpIvUHVI9L9wdZN4B78OC7iPaQgdbPIGXB4Y9APnPeLiOp1oz7lbx90 /Yo7hZFGksnifccVotfrnsCytIhmqP7d5O1ZwTnygBZWoSfLSrkq8Y1F2pFt1zgzBxYW XCYg== Received: by 10.68.242.97 with SMTP id wp1mr2060265pbc.159.1347224819209; Sun, 09 Sep 2012 14:06:59 -0700 (PDT) Received: from anchor.twiddle.home ([173.160.232.49]) by mx.google.com with ESMTPS id tw5sm662053pbc.48.2012.09.09.14.06.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 14:06:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 9 Sep 2012 14:04:48 -0700 Message-Id: <1347224784-19472-31-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1347224784-19472-1-git-send-email-rth@twiddle.net> References: <1347224784-19472-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: Alexander Graf Subject: [Qemu-devel] [PATCH 030/126] target-s390: Send signals for divide X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Richard Henderson --- target-s390x/cpu.h | 2 ++ target-s390x/int_helper.c | 51 ++++++++++++++++++++++++++++++++++++++++------ target-s390x/misc_helper.c | 22 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 52ab5ea..7d89a6f 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -934,5 +934,7 @@ uint32_t set_cc_nz_f64(float64 v); /* misc_helper.c */ void program_interrupt(CPUS390XState *env, uint32_t code, int ilc); +void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp, + uintptr_t retaddr); #endif diff --git a/target-s390x/int_helper.c b/target-s390x/int_helper.c index fe1cb87..f2f420c 100644 --- a/target-s390x/int_helper.c +++ b/target-s390x/int_helper.c @@ -38,22 +38,54 @@ uint64_t HELPER(mul128)(CPUS390XState *env, uint64_t v1, uint64_t v2) } /* 64/32 -> 32 signed division */ -int64_t HELPER(divs32)(CPUS390XState *env, int64_t a, int64_t b) +int64_t HELPER(divs32)(CPUS390XState *env, int64_t a, int64_t b64) { - env->retxl = a % (int32_t)b; - return a / (int32_t)b; + int32_t ret, b = b64; + int64_t q; + + if (b == 0) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } + + ret = q = a / b; + env->retxl = a % b; + + /* Catch non-representable quotient. */ + if (ret != q) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } + + return ret; } /* 64/32 -> 32 unsigned division */ -uint64_t HELPER(divu32)(CPUS390XState *env, uint64_t a, uint64_t b) +uint64_t HELPER(divu32)(CPUS390XState *env, uint64_t a, uint64_t b64) { - env->retxl = a % (uint32_t)b; - return a / (uint32_t)b; + uint32_t ret, b = b64; + uint64_t q; + + if (b == 0) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } + + ret = q = a / b; + env->retxl = a % b; + + /* Catch non-representable quotient. */ + if (ret != q) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } + + return ret; } /* 64/64 -> 64 signed division */ int64_t HELPER(divs64)(CPUS390XState *env, int64_t a, int64_t b) { + /* Catch divide by zero, and non-representable quotient (MIN / -1). */ + if (b == 0 || (b == -1 && a == (1ll << 63))) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } env->retxl = a % b; return a / b; } @@ -63,6 +95,10 @@ uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al, uint64_t b) { uint64_t ret; + /* Signal divide by zero. */ + if (b == 0) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } if (ah == 0) { /* 64 -> 64/64 case */ env->retxl = al % b; @@ -75,6 +111,9 @@ uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al, __uint128_t q = a / b; env->retxl = a % b; ret = q; + if (ret != q) { + runtime_exception(env, PGM_FIXPT_DIVIDE, GETPC()); + } #else /* 32-bit hosts would need special wrapper functionality - just abort if we encounter such a case; it's very unlikely anyways. */ diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c index 1502f15..32b75f2 100644 --- a/target-s390x/misc_helper.c +++ b/target-s390x/misc_helper.c @@ -69,6 +69,28 @@ do { } while (0) #endif +void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp, + uintptr_t retaddr) +{ + TranslationBlock *tb; + int t; + + env->exception_index = EXCP_PGM; + env->int_pgm_code = excp; + + /* Use the (ultimate) callers address to find the insn that trapped. */ + tb = tb_find_pc(retaddr); + assert(tb != NULL); + cpu_restore_state(tb, env, retaddr); + + /* Advance past the insn. */ + t = cpu_ldub_code(env, env->psw.addr); + env->int_pgm_ilc = t = get_ilc(t); + env->psw.addr += 2 * t; + + cpu_loop_exit(env); +} + void HELPER(exception)(CPUS390XState *env, uint32_t excp) { HELPER_LOG("%s: exception %d\n", __func__, excp);