Subject: port-next68k/17144: stackframe struct is packed wrong in bootloader
To: None <gnats-bugs@gnats.netbsd.org>
From: None <chris@Pin.LU>
List: netbsd-bugs
Date: 06/02/2002 22:05:13
>Number: 17144
>Category: port-next68k
>Synopsis: stackframe struct is packed wrong in bootloader
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-next68k-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jun 02 13:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Christian Limpach
>Release: current
>Organization:
>Environment:
sys/arch/next68k/stand/boot/machdep.c rev. 1.3
>Description:
The struct trapframe used in sys/arch/next68k/stand/boot/machdep.c
is packed wrong. The shorts get packed as 4 bytes instead of 2.
>How-To-Repeat:
>Fix:
Add __attribute__ ((packed)) to the definition.
The supplied patch also adds some additional debugging output
(stack dump and dump around the pc, there's no ddb or kgdb at
this point) and updates the structure/code to use bitfields.
Index: machdep.c
===================================================================
RCS file: /cvs/netbsd/syssrc/sys/arch/next68k/stand/boot/machdep.c,v
retrieving revision 1.3
retrieving revision 1.3.1724.1
diff -u -r1.3 -r1.3.1724.1
--- machdep.c 12 May 2001 22:35:30 -0000 1.3
+++ machdep.c 2 Jun 2002 20:25:18 -0000 1.3.1724.1
@@ -99,9 +99,10 @@
int aregs[8];
short sr;
int pc;
- short frame;
+ u_short fmt:4,
+ vec:12;
char info[0];
-};
+} __attribute__ ((packed));
int trap __P((struct trapframe *fp));
@@ -114,7 +115,7 @@
return 0;
intrap = 1;
printf("Got unexpected trap: format=%x vector=%x sr=%x pc=%x\n",
- (fp->frame>>12)&0xF, fp->frame&0xFFF, fp->sr, fp->pc);
+ fp->fmt, fp->vec, fp->sr, fp->pc);
printf("dregs: %x %x %x %x %x %x %x %x\n",
fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3],
fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
@@ -122,6 +123,26 @@
fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3],
fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
intrap = 0;
+#ifdef DEBUG
+ if (debug)
+ {
+ int i;
+ int *p;
+ p = (int *)(fp->pc);
+ for (i = 0; i < 64; i++) {
+ if ((i % 8) == 0)
+ printf ("\npc %x: ", (int)&p[i-16]);
+ printf ("%x ", p[i]);
+ }
+ p = (int *)(fp->info);
+ for (i = 0; i < 64; i++) {
+ if ((i % 8) == 0)
+ printf ("\nstk %x: ", (int)&p[i-16]);
+ printf ("%x ", p[i]);
+ }
+ printf ("\n");
+ }
+#endif
printf("Halting.\n");
return 0;
}
>Release-Note:
>Audit-Trail:
>Unformatted: