GDB serial and backtrace support.

* grub-core/kern/i386/realmode.S (real_to_prot): Reload IDT.
	(prot_to_real): Likewise.
	* grub-core/kern/i386/int.S (grub_bios_interrupt): Remove IDT reload.
	* grub-core/Makefile.core.def (backtrace): New module.
	(gdb): Likewise.
	* grub-core/gdb/cstub.c: New file.
	* grub-core/gdb/gdb.c: Likewise.
	* grub-core/gdb/i386/idt.c: Likewise.
	* grub-core/gdb/i386/machdep.S: Likewise.
	* grub-core/gdb/i386/signal.c: Likewise.
	* grub-core/lib/i386/backtrace.c: Likewise.
	* include/grub/backtrace.h: Likewise.
	* include/grub/gdb.h: Likewise.
	* include/grub/i386/gdb.h: Likewise.

	Also-By: Vladimir Serbinenko <phcoder@gmail.com>
This commit is contained in:
Lubomir Kundrak 2012-02-26 19:17:37 +01:00 committed by Vladimir 'phcoder' Serbinenko
commit ff27c3dd5d
13 changed files with 1052 additions and 29 deletions

26
include/grub/backtrace.h Normal file
View file

@ -0,0 +1,26 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_BACKTRACE_HEADER
#define GRUB_BACKTRACE_HEADER 1
void grub_backtrace (void);
void grub_backtrace_pointer (void *ptr);
void grub_backtrace_print_address (void *addr);
#endif

39
include/grub/gdb.h Normal file
View file

@ -0,0 +1,39 @@
/* gdb.h - Various definitions for the remote GDB stub */
/*
* Copyright (C) 2006 Lubomir Kundrak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GRUB_GDB_HEADER
#define GRUB_GDB_HEADER 1
#define SIGFPE 8
#define SIGTRAP 5
#define SIGABRT 6
#define SIGSEGV 11
#define SIGILL 4
#define SIGUSR1 30
/* We probably don't need other ones. */
struct grub_serial_port;
extern struct grub_serial_port *grub_gdb_port;
void grub_gdb_breakpoint (void);
int grub_gdb_trap2sig (int);
#endif /* ! GRUB_GDB_HEADER */

78
include/grub/i386/gdb.h Normal file
View file

@ -0,0 +1,78 @@
/* i386/gdb.h - i386 specific definitions for the remote GDB stub */
/*
* Copyright (C) 2006 Lubomir Kundrak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GRUB_GDB_CPU_HEADER
#define GRUB_GDB_CPU_HEADER 1
#define GRUB_GDB_LAST_TRAP 31
/* You may have to edit the bottom of machdep.S when adjusting
GRUB_GDB_LAST_TRAP. */
#define GRUB_MACHINE_NR_REGS 16
#define EAX 0
#define ECX 1
#define EDX 2
#define EBX 3
#define ESP 4
#define EBP 5
#define ESI 6
#define EDI 7
#define EIP 8
#define EFLAGS 9
#define CS 10
#define SS 11
#define DS 12
#define ES 13
#define FS 14
#define GS 15
#define PC EIP
#define FP EBP
#define SP ESP
#define PS EFLAGS
#ifndef ASM_FILE
#include <grub/gdb.h>
#define GRUB_CPU_TRAP_GATE 15
struct grub_cpu_interrupt_gate
{
grub_uint16_t offset_lo;
grub_uint16_t selector;
grub_uint8_t unused;
grub_uint8_t gate;
grub_uint16_t offset_hi;
} __attribute__ ((packed));
struct grub_cpu_idt_descriptor
{
grub_uint16_t limit;
grub_uint32_t base;
} __attribute__ ((packed));
extern void (*grub_gdb_trapvec[]) (void);
void grub_gdb_idtinit (void);
void grub_gdb_idtrestore (void);
void grub_gdb_trap (int trap_no);
#endif /* ! ASM */
#endif /* ! GRUB_GDB_CPU_HEADER */