From 1948a3b714380853791e9dae6eae29e40e3bf5a0 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 26 Feb 2012 19:10:52 +0100 Subject: [PATCH] Several cleanups --- grub-core/Makefile.core.def | 3 ++- grub-core/gdb/cstub.c | 27 +++++++++++++-------------- grub-core/gdb/i386/machdep.S | 1 - grub-core/kern/i386/int.S | 17 ----------------- grub-core/lib/i386/backtrace.c | 23 ----------------------- include/grub/backtrace.h | 1 + include/grub/i386/gdb.h | 3 +-- 7 files changed, 17 insertions(+), 58 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 585567d56..a9d596b0f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1755,7 +1755,8 @@ module = { module = { name = backtrace; - common = lib/i386/backtrace.c; + x86 = lib/i386/backtrace.c; + common = lib/backtrace.c; enable = x86; }; diff --git a/grub-core/gdb/cstub.c b/grub-core/gdb/cstub.c index b7dd2200b..551101de5 100644 --- a/grub-core/gdb/cstub.c +++ b/grub-core/gdb/cstub.c @@ -21,6 +21,7 @@ #include #include #include +#include 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, ®no) && *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; diff --git a/grub-core/gdb/i386/machdep.S b/grub-core/gdb/i386/machdep.S index 01ce0b4d8..62e8b2629 100644 --- a/grub-core/gdb/i386/machdep.S +++ b/grub-core/gdb/i386/machdep.S @@ -17,7 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define ASM 1 #include #define EC_PRESENT 1 diff --git a/grub-core/kern/i386/int.S b/grub-core/kern/i386/int.S index 7a2b7808a..7edace404 100644 --- a/grub-core/kern/i386/int.S +++ b/grub-core/kern/i386/int.S @@ -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 diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c index 27f82a85e..978693396 100644 --- a/grub-core/lib/i386/backtrace.c +++ b/grub-core/lib/i386/backtrace.c @@ -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) { diff --git a/include/grub/backtrace.h b/include/grub/backtrace.h index a0503b8b7..395519762 100644 --- a/include/grub/backtrace.h +++ b/include/grub/backtrace.h @@ -21,5 +21,6 @@ void grub_backtrace (void); void grub_backtrace_pointer (void *ptr); +void grub_backtrace_print_address (void *addr); #endif diff --git a/include/grub/i386/gdb.h b/include/grub/i386/gdb.h index e37a8c74d..174f4dc09 100644 --- a/include/grub/i386/gdb.h +++ b/include/grub/i386/gdb.h @@ -47,7 +47,7 @@ #define SP ESP #define PS EFLAGS -#ifndef ASM +#ifndef ASM_FILE #include @@ -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);