📄 i386-lite.patch
字号:
+}++void kgdb_disable_hw_debug(struct pt_regs *regs)+{+ /* Disable hardware debugging while we are in kgdb */+ asm volatile ("movl %0,%%db7": /* no output */ :"r" (0));+}++void kgdb_post_master_code(struct pt_regs *regs, int e_vector, int err_code)+{+ /* Master processor is completely in the debugger */+ gdb_i386vector = e_vector;+ gdb_i386errcode = err_code;+}++void kgdb_roundup_cpus(unsigned long flags)+{+ send_IPI_allbutself(APIC_DM_NMI);+}++int kgdb_arch_handle_exception(int e_vector, int signo,+ int err_code, char *remcom_in_buffer,+ char *remcom_out_buffer,+ struct pt_regs *linux_regs)+{+ long addr;+ char *ptr;+ int newPC, dr6;++ switch (remcom_in_buffer[0]) {+ case 'c':+ case 's':+ /* try to read optional parameter, pc unchanged if no parm */+ ptr = &remcom_in_buffer[1];+ if (kgdb_hex2long(&ptr, &addr))+ linux_regs->eip = addr;+ newPC = linux_regs->eip;++ /* clear the trace bit */+ linux_regs->eflags &= ~TF_MASK;+ atomic_set(&cpu_doing_single_step, -1);++ /* set the trace bit if we're stepping */+ if (remcom_in_buffer[0] == 's') {+ linux_regs->eflags |= TF_MASK;+ debugger_step = 1;+ atomic_set(&cpu_doing_single_step,smp_processor_id());+ }++ asm volatile ("movl %%db6, %0\n":"=r" (dr6));+ if (!(dr6 & 0x4000)) {+ long breakno;+ for (breakno = 0; breakno < 4; ++breakno) {+ if (dr6 & (1 << breakno) &&+ breakinfo[breakno].type == 0) {+ /* Set restore flag */+ linux_regs->eflags |= X86_EFLAGS_RF;+ break;+ }+ }+ }+ kgdb_correct_hw_break();+ asm volatile ("movl %0, %%db6\n"::"r" (0));++ return (0);+ } /* switch */+ /* this means that we do not want to exit from the handler */+ return -1;+}++/* Register KGDB with the i386die_chain so that we hook into all of the right+ * spots. */+static int kgdb_notify(struct notifier_block *self, unsigned long cmd,+ void *ptr)+{+ struct die_args *args = ptr;+ struct pt_regs *regs = args->regs;++ /* Bad memory access? */+ if (cmd == DIE_PAGE_FAULT_NO_CONTEXT && atomic_read(&debugger_active)+ && kgdb_may_fault) {+ kgdb_fault_longjmp(kgdb_fault_jmp_regs);+ return NOTIFY_STOP;+ } else if (cmd == DIE_PAGE_FAULT)+ /* A normal page fault, ignore. */+ return NOTIFY_DONE;+ else if ((cmd == DIE_NMI || cmd == DIE_NMI_IPI ||+ cmd == DIE_NMIWATCHDOG) && atomic_read(&debugger_active)) {+ /* CPU roundup */+ kgdb_nmihook(smp_processor_id(), regs);+ return NOTIFY_STOP;+ } else if (cmd == DIE_NMI_IPI || cmd == DIE_NMI || user_mode(regs) ||+ (cmd == DIE_DEBUG && atomic_read(&debugger_active)))+ /* Normal watchdog event or userspace debugging, or spurious+ * debug exception, ignore. */+ return NOTIFY_DONE;++ kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);++ return NOTIFY_STOP;+}++static struct notifier_block kgdb_notifier = {+ .notifier_call = kgdb_notify,+};++int kgdb_arch_init(void)+{+ notifier_chain_register(&i386die_chain, &kgdb_notifier);+ return 0;+}++/*+ * Skip an int3 exception when it occurs after a breakpoint has been+ * removed. Backtrack eip by 1 since the int3 would have caused it to+ * increment by 1.+ */++int kgdb_skipexception(int exception, struct pt_regs *regs)+{+ if (exception == 3 && kgdb_isremovedbreak(regs->eip - 1)) {+ regs->eip -= 1;+ return 1;+ }+ return 0;+}++struct kgdb_arch arch_kgdb_ops = {+ .gdb_bpt_instr = {0xcc},+};Index: linux-2.6.16/arch/i386/kernel/traps.c===================================================================--- linux-2.6.16.orig/arch/i386/kernel/traps.c 2006-03-20 11:23:29.000000000 +0530+++ linux-2.6.16/arch/i386/kernel/traps.c 2006-04-25 11:30:14.000000000 +0530@@ -365,7 +365,7 @@ #endif if (nl) printk("\n");- notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);+ notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV); show_registers(regs); } else printk(KERN_EMERG "Recursive die() failure, output suppressed\n");@@ -787,6 +787,7 @@ */ clear_dr7: set_debugreg(0, 7);+ notify_die(DIE_DEBUG, "debug2", regs, condition, error_code, SIGTRAP); return; debug_vm86:@@ -1091,6 +1092,12 @@ _set_gate(idt_table+n,5,0,0,(gdt_entry<<3)); } +/* Some traps need to be set early. */+void __init early_trap_init(void) {+ set_intr_gate(1,&debug);+ set_system_intr_gate(3, &int3); /* int3 can be called from all */+ set_intr_gate(14,&page_fault);+} void __init trap_init(void) {@@ -1107,10 +1114,8 @@ #endif set_trap_gate(0,÷_error);- set_intr_gate(1,&debug); set_intr_gate(2,&nmi);- set_system_intr_gate(3, &int3); /* int3/4 can be called from all */- set_system_gate(4,&overflow);+ set_system_gate(4,&overflow); /* int4/5 can be called from all */ set_trap_gate(5,&bounds); set_trap_gate(6,&invalid_op); set_trap_gate(7,&device_not_available);@@ -1120,7 +1125,6 @@ set_trap_gate(11,&segment_not_present); set_trap_gate(12,&stack_segment); set_trap_gate(13,&general_protection);- set_intr_gate(14,&page_fault); set_trap_gate(15,&spurious_interrupt_bug); set_trap_gate(16,&coprocessor_error); set_trap_gate(17,&alignment_check);Index: linux-2.6.16/arch/i386/kernel/Makefile===================================================================--- linux-2.6.16.orig/arch/i386/kernel/Makefile 2006-03-20 11:23:29.000000000 +0530+++ linux-2.6.16/arch/i386/kernel/Makefile 2006-04-25 11:28:55.000000000 +0530@@ -37,6 +37,7 @@ obj-$(CONFIG_DOUBLEFAULT) += doublefault.o obj-$(CONFIG_VM86) += vm86.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o+obj-$(CONFIG_KGDB) += kgdb.o kgdb-jmp.o EXTRA_AFLAGS := -traditional Index: linux-2.6.16/arch/i386/kernel/setup.c===================================================================--- linux-2.6.16.orig/arch/i386/kernel/setup.c 2006-03-20 11:23:29.000000000 +0530+++ linux-2.6.16/arch/i386/kernel/setup.c 2006-04-25 11:30:39.000000000 +0530@@ -147,6 +147,7 @@ struct e820map e820; extern void early_cpu_init(void);+extern void early_trap_init(void); extern void generic_apic_probe(char *); extern int root_mountflags; @@ -1497,6 +1498,7 @@ memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); pre_setup_arch_hook(); early_cpu_init();+ early_trap_init(); /* * FIXME: This isn't an official loader_type right@@ -1553,6 +1555,7 @@ data_resource.end = virt_to_phys(_edata)-1; parse_cmdline_early(cmdline_p);+ parse_early_param(); max_low_pfn = setup_memory(); Index: linux-2.6.16/lib/Kconfig.debug===================================================================--- linux-2.6.16.orig/lib/Kconfig.debug 2006-04-25 11:28:52.000000000 +0530+++ linux-2.6.16/lib/Kconfig.debug 2006-04-25 11:28:55.000000000 +0530@@ -232,7 +232,7 @@ config KGDB bool "KGDB: kernel debugging with remote gdb" select WANT_EXTRA_DEBUG_INFORMATION- depends on DEBUG_KERNEL+ depends on DEBUG_KERNEL && (X86) help If you say Y here, it will be possible to remotely debug the kernel using gdb. It is strongly suggested that you enableIndex: linux-2.6.16/include/asm-i386/kgdb.h===================================================================--- linux-2.6.16.orig/include/asm-i386/kgdb.h 2006-04-25 10:59:23.506518750 +0530+++ linux-2.6.16/include/asm-i386/kgdb.h 2006-04-25 11:28:55.000000000 +0530@@ -0,0 +1,49 @@+#ifdef __KERNEL__+#ifndef _ASM_KGDB_H_+#define _ASM_KGDB_H_++/*+ * Copyright (C) 2001-2004 Amit S. Kale+ */++/************************************************************************/+/* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/+/* at least NUMREGBYTES*2 are needed for register packets */+/* Longer buffer is needed to list all threads */+#define BUFMAX 1024++/* Number of bytes of registers. */+#define NUMREGBYTES 64+/* Number of bytes of registers we need to save for a setjmp/longjmp. */+#define NUMCRITREGBYTES 24++/*+ * Note that this register image is in a different order than+ * the register image that Linux produces at interrupt time.+ *+ * Linux's register image is defined by struct pt_regs in ptrace.h.+ * Just why GDB uses a different order is a historical mystery.+ */+enum regnames { _EAX, /* 0 */+ _ECX, /* 1 */+ _EDX, /* 2 */+ _EBX, /* 3 */+ _ESP, /* 4 */+ _EBP, /* 5 */+ _ESI, /* 6 */+ _EDI, /* 7 */+ _PC, /* 8 also known as eip */+ _PS, /* 9 also known as eflags */+ _CS, /* 10 */+ _SS, /* 11 */+ _DS, /* 12 */+ _ES, /* 13 */+ _FS, /* 14 */+ _GS /* 15 */+};++#define BREAKPOINT() asm(" int $3");+#define BREAK_INSTR_SIZE 1+#define CACHE_FLUSH_IS_SAFE 1+#endif /* _ASM_KGDB_H_ */+#endif /* __KERNEL__ */Index: linux-2.6.16/include/asm-i386/kdebug.h===================================================================--- linux-2.6.16.orig/include/asm-i386/kdebug.h 2006-03-20 11:23:29.000000000 +0530+++ linux-2.6.16/include/asm-i386/kdebug.h 2006-04-25 11:28:55.000000000 +0530@@ -39,6 +39,7 @@ DIE_CALL, DIE_NMI_IPI, DIE_PAGE_FAULT,+ DIE_PAGE_FAULT_NO_CONTEXT, }; static inline int notify_die(enum die_val val, const char *str,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -