Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/arch/i386/i386 Pull up revision 1.159 (requested by...



details:   https://anonhg.NetBSD.org/src/rev/da0a2b9f37e8
branches:  netbsd-1-5
changeset: 491892:da0a2b9f37e8
user:      he <he%NetBSD.org@localhost>
date:      Mon Jun 11 20:40:19 2001 +0000

description:
Pull up revision 1.159 (requested by sommerfeld):
  Replace magic numbers in trap code with offsetof().
  Deal better with traps during register restore.
  Explain a bit more about what is going on here.

diffstat:

 sys/arch/i386/i386/trap.c |  26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diffs (53 lines):

diff -r bf5b73eab3a6 -r da0a2b9f37e8 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Mon Jun 11 20:34:18 2001 +0000
+++ b/sys/arch/i386/i386/trap.c Mon Jun 11 20:40:19 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.139 2000/06/06 18:52:36 soren Exp $ */
+/*     $NetBSD: trap.c,v 1.139.2.1 2001/06/11 20:40:19 he Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -326,6 +326,21 @@
                 * specific instructions we recognize only happen when
                 * returning from a trap, syscall, or interrupt.
                 *
+                * At this point, there are (at least) two trap frames on
+                * the kernel stack; we presume here that we faulted while
+                * loading our registers out of the outer one.
+                *
+                * The inner frame does not involve a ring crossing, so it
+                * ends right before &frame.tf_esp.  The outer frame has
+                * been partially consumed by the INTRFASTEXIT; exactly
+                * how much depends which register we were popping when we
+                * faulted, so we compute the outer frame address based on
+                * register-dependant offsets computed from &frame.tf_esp
+                * below.  To decide whether this was a kernel-mode or
+                * user-mode error, we look at this outer frame's tf_cs
+                * and tf_eflags, which are (fortunately) not consumed until
+                * the final instruction of INTRFASTEXIT.
+                *
                 * XXX
                 * The heuristic used here will currently fail for the case of
                 * one of the 2 pop instructions faulting when returning from a
@@ -336,15 +351,18 @@
                 */
                switch (*(u_char *)frame.tf_eip) {
                case 0xcf:      /* iret */
-                       vframe = (void *)((int)&frame.tf_esp - 44);
+                       vframe = (void *)((int)&frame.tf_esp -
+                           offsetof(struct trapframe, tf_eip));
                        resume = (int)resume_iret;
                        break;
                case 0x1f:      /* popl %ds */
-                       vframe = (void *)((int)&frame.tf_esp - 4);
+                       vframe = (void *)((int)&frame.tf_esp -
+                           offsetof(struct trapframe, tf_ds));
                        resume = (int)resume_pop_ds;
                        break;
                case 0x07:      /* popl %es */
-                       vframe = (void *)((int)&frame.tf_esp - 0);
+                       vframe = (void *)((int)&frame.tf_esp -
+                           offsetof(struct trapframe, tf_es));
                        resume = (int)resume_pop_es;
                        break;
                default:



Home | Main Index | Thread Index | Old Index