From joel Wed Jan 20 09:53:07 1988 Received: by isc.intel.com (4.12/2.0.iSC) id AA26230; Wed, 20 Jan 88 09:53:02 pst Received: by isc.intel.com (4.12/2.0.iSC) id AA28307; Wed, 9 Dec 87 02:04:30 pst Posted-Date: Wed, 9 Dec 87 02:04:30 pst Received-Date: Wed, 9 Dec 87 02:04:30 pst To: chao, intsc!inthap!siac!al, intsc!inthap!siac!art, lau, lin, dgr@littlei.UUCP, littlei!intelisc!joel, littlei!omepd!radix!jimv Subject: Note UN0013 installed NOTE NUMBER: UN0013 *** use 'vi' to edit *** RELEASE: System V HARDWARE: 386 AT/MB1 SUBMITTED BY: Joseph Lin COMPANY: Intel CSE PHONE: 408-496-8030 DATE: 12/08/87 SUMMARY: (limit to 3 lines) | User stack layout of a signal handler. DESCRIPTION: 1. The user stack of the signal handler is : Low -------------------------- | | | | -*-*-*-*-*-*-*-*-*-*-*-*- | | | Stack frame pushed by | | kernel just before | | entering the user | | signal handler | | | -*-*-*-*-*-*-*-*-*-*-*-*- | | | Original user stack | | | High ------------------------- Two data structures are associated with the stack frame pushed by the kernel: /* stackframe is defined in machdep.c */ struct stackframe { void (*retadr)(); /* return address for user signal handler */ unsigned int signo; /* 1st argument passed to user signal handler */ unsigned int reg[SS+1]; /* all registers, see sys/reg.h */ int *fpoffset; /* address of pushed fp state on the stack */ } /* fpstate is defined in sys/user.h */ struct user { .. struct fpstate { int state[27]; /* 287/387 saved state, see 287/387 programmer * manual. */ int status; /* status word saved at exception */ } u_fpstate; .. } Therefore, the stack frame pushed by kernel looks like: ------------------------- | | | struct stackframe | | | | fpoffset |----- ------------------------- | | |<---- | struct fpstate | | | ------------------------- Finally, the type (e.g. zero devide, overflow, ... etc) of a floating point exception (SIGFPE) can be determined by looking at the status field of the fpstate in the user stack. 2. The scenario of a floating point exception is: floating point exception | | ERROR pin is on | | INT 16 is triggered | | trap handler for INT 16 (fpexterrflt) -- | | | save the co-processor status register in | u_fpstate.status, clear the exception bits in | the co-processor's status register, then issue | a SIGFPE signal. | kernel detects a pending signal (SIGFPE), signal handling in kernel (sendsig), ------- call user signal handler, if any. | | | | FNSAVE to save the fp state in u area; | (FNSAVE also puts 387 to the initial state, | including "clear the status register", "empty | all numeric registers", "set the control | register to its default value 037H"); | push a stack frame on top of the user stack | save the 386 registers and co-processor state | from u area into the user stack; user signal handler. Since the exception bits in the co-processor's status register are already cleared by the trap handler (fpexterrflt), there is no need for the user program to explictly clear them.