* Copyright (c) 1991 Regents of the University of California.
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratories.
* %sccs.include.redist.c%
* @(#)kgdb_glue.c 7.4 (Berkeley) %G%
* This file must be compiled with gcc -fno-defer-pop.
#include <machine/frame.h>
"@(#) $Header: /u/donn/c/gdb/kernel/RCS/kgdb_glue.c,v 1.2 91/03/31 16:04:52 donn Exp Locker: donn $ (LBL)";
#define KGDB_STACKSIZE 0x800
#define KGDB_STACKWORDS (KGDB_STACKSIZE / sizeof(u_long))
u_long kgdb_stack
[KGDB_STACKWORDS
];
#define getsp(v) asm volatile ("movl %%esp,%0" : "=r" (v))
#define setsp(v) asm volatile ("movl %0,%%esp" :: "r" (v))
copywords(src
, dst
, nbytes
)
register u_long
*src
, *dst
;
u_long
*limit
= src
+ (nbytes
/ sizeof(u_long
));
*(u_short
*)dst
= *(u_short
*)src
;
* On internal traps, the hardware doesn't push ss and esp.
u_int fsize
= sizeof frame
- 2 * sizeof (int);
pg("kgdb_trap_glue: entered, fsize = %d\n", fsize
);
* After a kernel mode trap, the saved sp doesn't point to the right
* place. The correct value is the top of the frame.
frame
.tf_isp
= (u_long
)(&frame
) + fsize
;
* Copy the interrupt context and frame to the new stack.
* We're throwing away trap()'s frame since we're going to do
nsp
= (u_long
)(&kgdb_stack
[KGDB_STACKWORDS
]) - fsize
;
copywords((u_long
*)&frame
, (u_long
*)nsp
, fsize
);
if (kgdb_trap(frame
.tf_trapno
, (struct frame
*)nsp
) == 0) {
* Get back on kernel stack. This thread of control
* will return back up through trap(). If kgdb_trap()
* returns 0, it didn't handle the trap at all so
* the stack is still intact and everything will
* unwind okay from here up.
* Copy back context, which has possibly changed. Even the
osp
= ((struct trapframe
*)nsp
)->tf_isp
- fsize
;
copywords((u_long
*)nsp
, (u_long
*)osp
, fsize
);
* Restore the possible new context from frame.
asm volatile ("pop %es; pop %ds; popal; nop; addl $8,%esp; iret");