mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: Andi Kleen <ak@suse.de>
Cc: Marcelo Tosatti <marcelo.tosatti@cyclades.com>,
	Linus Torvalds <torvalds@osdl.org>, Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@osdl.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [patch 2.6.13-rc6] i386: fix incorrect FP signal delivery
Date: Tue, 23 Aug 2005 13:54:56 -0400	[thread overview]
Message-ID: <200508231357_MC3-1-A810-1891@compuserve.com> (raw)

On Tue, 23 Aug 2005 02:20:07 +0200, Andi Kleen wrote:

> every reviewer has to look up all the bits in the manual?

 I fixed the test program too:

 Before patch:

$ ./fpsig
handler: signum = 8, errno = 0, code = 0 [unknown]
handler: fpu cwd = 0xb40, fpu swd = 0xbaa0
handler: i387 unmasked precision exception, rounded up

 After:

$ ./fpsig
handler: signum = 8, errno = 0, code = 6 [inexact result]
handler: fpu cwd = 0xb40, fpu swd = 0xbaa0
handler: i387 unmasked precision exception, rounded up

/* i387 fp signal test */

#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>

__attribute__ ((aligned(4096))) unsigned char altstack[4096];
unsigned short cw = 0x0b40; /* unmask all exceptions, round up */
struct sigaction sa;
stack_t ss = {
	.ss_sp   = &altstack[2047],
	.ss_size = sizeof(altstack)/2,
};

static void handler(int nr, siginfo_t *si, void *uc)
{
	char *decode;
	int code = si->si_code;
	unsigned short cwd = *(unsigned short *)&altstack[0xd84];
	unsigned short swd = *(unsigned short *)&altstack[0xd88];

	switch (code) {
		case FPE_INTDIV:
			decode = "divide by zero";
			break;
		case FPE_FLTRES:
			decode = "inexact result";
			break;
		case FPE_FLTINV:
			decode = "invalid operation";
			break;
		default:
			decode = "unknown";
			break;
	}
	printf("handler: signum = %d, errno = %d, code = %d [%s]\n",
		si->si_signo, si->si_errno, code, decode);
	printf("handler: fpu cwd = 0x%hx, fpu swd = 0x%hx\n", cwd, swd);
	if (swd & 0x20 & ~cwd)
		printf("handler: i387 unmasked precision exception, rounded %s\n",
			swd & 0x200 ? "up" : "down");
	exit(1);
}

int main(int argc, char * const argv[])
{
	sa.sa_sigaction = handler;
	sa.sa_flags     = SA_ONSTACK | SA_SIGINFO;

	if (sigaltstack(&ss, 0))
		perror("sigaltstack");
	if (sigaction(SIGFPE, &sa, NULL))
		perror("sigaction");

	asm volatile ("fnclex ; fldcw %0" : : "m" (cw));
	asm volatile ( /*  st(1) = 3.0, st = 1.0  */
	    "fld1 ; fld1 ; faddp ; fld1 ; faddp ; fld1");
	asm volatile (
	    "fdivp ; fwait");  /*  1.0 / 3.0  */

	return 0;
}
__
Chuck

             reply	other threads:[~2005-08-23 17:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-23 17:54 Chuck Ebbert [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-08-24  1:36 Chuck Ebbert
2005-08-23  2:47 Chuck Ebbert
2005-08-23 18:55 ` Linus Torvalds
2005-08-22 23:43 Chuck Ebbert
2005-08-23  0:20 ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200508231357_MC3-1-A810-1891@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.tosatti@cyclades.com \
    --cc=mingo@elte.hu \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome