Several cleanups

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-26 19:10:52 +01:00
parent 515e8007fc
commit 1948a3b714
7 changed files with 17 additions and 58 deletions

View file

@ -1755,7 +1755,8 @@ module = {
module = {
name = backtrace;
common = lib/i386/backtrace.c;
x86 = lib/i386/backtrace.c;
common = lib/backtrace.c;
enable = x86;
};

View file

@ -21,6 +21,7 @@
#include <grub/cpu/gdb.h>
#include <grub/gdb.h>
#include <grub/serial.h>
#include <grub/backtrace.h>
static const char hexchars[] = "0123456789abcdef";
int grub_gdb_regs[GRUB_MACHINE_NR_REGS];
@ -140,9 +141,9 @@ grub_gdb_putpacket (char *buffer)
/* Convert the memory pointed to by mem into hex, placing result in buf.
Return a pointer to the last char put in buf (NULL). */
static char *
grub_gdb_mem2hex (char *mem, char *buf, int count)
grub_gdb_mem2hex (char *mem, char *buf, grub_size_t count)
{
int i;
grub_size_t i;
unsigned char ch;
for (i = 0; i < count; i++)
@ -175,7 +176,7 @@ grub_gdb_hex2mem (char *buf, char *mem, int count)
/* Convert hex characters to int and return the number of characters
processed. */
static int
grub_gdb_hex2int (char **ptr, int *int_value)
grub_gdb_hex2int (char **ptr, grub_uint64_t *int_value)
{
int num_chars = 0;
int hex_value;
@ -205,17 +206,16 @@ grub_gdb_trap (int trap_no)
{
int sig_no;
int stepping;
int addr;
int length;
grub_uint64_t addr;
grub_uint64_t length;
char *ptr;
int newPC;
if (!grub_gdb_port)
{
grub_printf ("Unhandled exception 0x%x at ", trap_no);
grub_backtrace_print_address (grub_gdb_regs[PC]);
grub_backtrace_print_address ((void *) grub_gdb_regs[PC]);
grub_printf ("\n");
grub_backtrace_pointer (grub_gdb_regs[EBP]);
grub_backtrace_pointer ((void *) grub_gdb_regs[EBP]);
grub_abort ();
}
@ -284,10 +284,10 @@ grub_gdb_trap (int trap_no)
/* Set the value of a single CPU register -- return OK. */
case 'P':
{
int regno;
grub_uint64_t regno;
if (grub_gdb_hex2int (&ptr, &regno) && *ptr++ == '=')
if (regno >= 0 && regno < GRUB_MACHINE_NR_REGS)
if (regno < GRUB_MACHINE_NR_REGS)
{
grub_gdb_hex2mem (ptr, (char *) &grub_gdb_regs[regno], 4);
grub_strcpy (grub_gdb_outbuf, "OK");
@ -308,7 +308,8 @@ grub_gdb_trap (int trap_no)
if (grub_gdb_hex2int (&ptr, &length))
{
ptr = 0;
grub_gdb_mem2hex ((char *) addr, grub_gdb_outbuf, length);
grub_gdb_mem2hex ((char *) (grub_addr_t) addr,
grub_gdb_outbuf, length);
}
if (ptr)
grub_strcpy (grub_gdb_outbuf, "E01");
@ -322,7 +323,7 @@ grub_gdb_trap (int trap_no)
if (grub_gdb_hex2int (&ptr, &length))
if (*(ptr++) == ':')
{
grub_gdb_hex2mem (ptr, (char *) addr, length);
grub_gdb_hex2mem (ptr, (char *) (grub_addr_t) addr, length);
grub_strcpy (grub_gdb_outbuf, "OK");
ptr = 0;
}
@ -342,8 +343,6 @@ grub_gdb_trap (int trap_no)
if (grub_gdb_hex2int (&ptr, &addr))
grub_gdb_regs[PC] = addr;
newPC = grub_gdb_regs[PC];
/* Clear the trace bit. */
grub_gdb_regs[PS] &= 0xfffffeff;

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define ASM 1
#include <grub/cpu/gdb.h>
#define EC_PRESENT 1

View file

@ -19,9 +19,6 @@
FUNCTION(grub_bios_interrupt)
pushf
cli
#ifndef GRUB_MACHINE_PCBIOS
sidt protidt
#endif
popf
pushl %ebp
pushl %ecx
@ -51,9 +48,6 @@ FUNCTION(grub_bios_interrupt)
.code16
pushf
cli
#ifndef GRUB_MACHINE_PCBIOS
lidt realidt
#endif
mov %ds, %ax
push %ax
@ -126,15 +120,4 @@ intno:
popl %eax
popl %ecx
popl %ebp
#ifndef GRUB_MACHINE_PCBIOS
lidt protidt
#endif
ret
#ifndef GRUB_MACHINE_PCBIOS
realidt:
.word 0x100
.long 0
protidt:
.word 0
.long 0
#endif

View file

@ -26,29 +26,6 @@
#define MAX_STACK_FRAME 102400
GRUB_MOD_LICENSE ("GPLv3+");
void
grub_backtrace_print_address (void *addr)
{
grub_dl_t mod;
FOR_DL_MODULES (mod)
{
grub_dl_segment_t segment;
for (segment = mod->segment; segment; segment = segment->next)
if (segment->addr <= addr && (grub_uint8_t *) segment->addr
+ segment->size > (grub_uint8_t *) addr)
{
grub_printf ("%s.%x+%" PRIxGRUB_SIZE, mod->name, segment->section,
(grub_uint8_t *) addr - (grub_uint8_t *) segment->addr);
return;
}
}
grub_printf ("%p", addr);
}
void
grub_backtrace_pointer (void *ebp)
{

View file

@ -21,5 +21,6 @@
void grub_backtrace (void);
void grub_backtrace_pointer (void *ptr);
void grub_backtrace_print_address (void *addr);
#endif

View file

@ -47,7 +47,7 @@
#define SP ESP
#define PS EFLAGS
#ifndef ASM
#ifndef ASM_FILE
#include <grub/gdb.h>
@ -69,7 +69,6 @@ struct grub_cpu_idt_descriptor
} __attribute__ ((packed));
extern void (*grub_gdb_trapvec[]) (void);
void grub_gdb_breakpoint (void);
void grub_gdb_idtinit (void);
void grub_gdb_idtrestore (void);
void grub_gdb_trap (int trap_no);