📄 powerpc-lite.patch
字号:
+{+ if (user_mode(regs))+ return 0;++ kgdb_handle_exception(0, SIGTRAP, 0, regs);++ if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))+ regs->nip += 4;++ return 1;+}++static int kgdb_singlestep(struct pt_regs *regs)+{+ if (user_mode(regs))+ return 0;++ kgdb_handle_exception(0, SIGTRAP, 0, regs);+ return 1;+}++int kgdb_iabr_match(struct pt_regs *regs)+{+ if (user_mode(regs))+ return 0;++ kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);+ return 1;+}++int kgdb_dabr_match(struct pt_regs *regs)+{+ if (user_mode(regs))+ return 0;++ kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);+ return 1;+}++void regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)+{+ int reg;+ unsigned long *ptr = gdb_regs;++ memset(gdb_regs, 0, MAXREG * 4);++ for (reg = 0; reg < 32; reg++)+ *(ptr++) = regs->gpr[reg];++#ifndef CONFIG_E500+ for (reg = 0; reg < 64; reg++)+ *(ptr++) = 0;+#else+ for (reg = 0; reg < 32; reg++)+ *(ptr++) = current->thread.evr[reg];+#endif++ *(ptr++) = regs->nip;+ *(ptr++) = regs->msr;+ *(ptr++) = regs->ccr;+ *(ptr++) = regs->link;+ *(ptr++) = regs->ctr;+ *(ptr++) = regs->xer;++#ifdef CONFIG_SPE+ /* u64 acc */+ *(ptr++) = (current->thread.acc >> 32);+ *(ptr++) = (current->thread.acc & 0xffffffff);+ *(ptr++) = current->thread.spefscr;+#endif+}++void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)+{+ struct pt_regs *regs = (struct pt_regs *)(p->thread.ksp ++ STACK_FRAME_OVERHEAD);+ int reg;+ unsigned long *ptr = gdb_regs;++ memset(gdb_regs, 0, MAXREG * 4);++ /* Regs GPR0-2 */+ for (reg = 0; reg < 3; reg++)+ *(ptr++) = regs->gpr[reg];++ /* Regs GPR3-13 are not saved */+ for (reg = 3; reg < 14; reg++)+ *(ptr++) = 0;++ /* Regs GPR14-31 */+ for (reg = 14; reg < 32; reg++)+ *(ptr++) = regs->gpr[reg];++#ifndef CONFIG_E500+ for (reg = 0; reg < 64; reg++)+ *(ptr++) = 0;+#else+ for (reg = 0; reg < 32; reg++)+ *(ptr++) = current->thread.evr[reg];+#endif++ *(ptr++) = regs->nip;+ *(ptr++) = regs->msr;+ *(ptr++) = regs->ccr;+ *(ptr++) = regs->link;+ *(ptr++) = regs->ctr;+ *(ptr++) = regs->xer;++#ifdef CONFIG_SPE+ /* u64 acc */+ *(ptr++) = (current->thread.acc >> 32);+ *(ptr++) = (current->thread.acc & 0xffffffff);+ *(ptr++) = current->thread.spefscr;+#endif+}++void gdb_regs_to_regs(unsigned long *gdb_regs, struct pt_regs *regs)+{+ int reg;+ unsigned long *ptr = gdb_regs;+#ifdef CONFIG_SPE+ union {+ u32 v32[2];+ u64 v64;+ } u;+#endif++ for (reg = 0; reg < 32; reg++)+ regs->gpr[reg] = *(ptr++);++#ifndef CONFIG_E500+ for (reg = 0; reg < 64; reg++)+ ptr++;+#else+ for (reg = 0; reg < 32; reg++)+ current->thread.evr[reg] = *(ptr++);+#endif++ regs->nip = *(ptr++);+ regs->msr = *(ptr++);+ regs->ccr = *(ptr++);+ regs->link = *(ptr++);+ regs->ctr = *(ptr++);+ regs->xer = *(ptr++);++#ifdef CONFIG_SPE+ /* u64 acc */+ u.v32[0] = *(ptr++);+ u.v32[1] = *(ptr++);+ current->thread.acc = u.v64;+ current->thread.spefscr = *(ptr++);+#endif+}++/*+ * Save/restore state in case a memory access causes a fault.+ */+int kgdb_fault_setjmp(unsigned long *curr_context)+{+ __asm__ __volatile__("mflr 0; stw 0,0(%0);"+ "stw 1,4(%0); stw 2,8(%0);"+ "mfcr 0; stw 0,12(%0);"+ "stmw 13,16(%0)"::"r"(curr_context));+ return 0;+}++void kgdb_fault_longjmp(unsigned long *curr_context)+{+ __asm__ __volatile__("lmw 13,16(%0);"+ "lwz 0,12(%0); mtcrf 0x38,0;"+ "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"+ "mtlr 0; mr 3,1"::"r"(curr_context));+}++/*+ * This function does PoerPC specific procesing for interfacing to gdb.+ */+int kgdb_arch_handle_exception(int vector, int signo, int err_code,+ char *remcom_in_buffer, char *remcom_out_buffer,+ struct pt_regs *linux_regs)+{+ char *ptr = &remcom_in_buffer[1];+ unsigned long addr;++ switch (remcom_in_buffer[0])+ {+ /*+ * sAA..AA Step one instruction from AA..AA+ * This will return an error to gdb ..+ */+ case 's':+ case 'c':+ /* handle the optional parameter */+ if (kgdb_hex2long (&ptr, &addr))+ linux_regs->nip = addr;++ atomic_set(&cpu_doing_single_step, -1);+ /* set the trace bit if we're stepping */+ if (remcom_in_buffer[0] == 's') {+#if defined (CONFIG_40x) || defined(CONFIG_BOOKE)+ mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) |+ DBCR0_IC | DBCR0_IDM);+ linux_regs->msr |= MSR_DE;+#else+ linux_regs->msr |= MSR_SE;+#endif+ debugger_step = 1;+ if (kgdb_contthread)+ atomic_set(&cpu_doing_single_step,+ smp_processor_id());+ }+ return 0;+ }++ return -1;+}++/*+ * Global data+ */+struct kgdb_arch arch_kgdb_ops = {+ .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},+};++int kgdb_arch_init(void)+{+ debugger = kgdb_debugger;+ debugger_bpt = kgdb_breakpoint;+ debugger_sstep = kgdb_singlestep;+ debugger_iabr_match = kgdb_iabr_match;+ debugger_dabr_match = kgdb_dabr_match;++ return 0;+}++arch_initcall(kgdb_arch_init);Index: linux-2.6.16/arch/ppc/kernel/ppc-stub.c===================================================================--- linux-2.6.16.orig/arch/ppc/kernel/ppc-stub.c 2006-03-20 11:23:29.000000000 +0530+++ linux-2.6.16/arch/ppc/kernel/ppc-stub.c 2006-04-25 10:59:23.506518750 +0530@@ -1,867 +0,0 @@-/*- * ppc-stub.c: KGDB support for the Linux kernel.- *- * adapted from arch/sparc/kernel/sparc-stub.c for the PowerPC- * some stuff borrowed from Paul Mackerras' xmon- * Copyright (C) 1998 Michael AK Tesch (tesch@cs.wisc.edu)- *- * Modifications to run under Linux- * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)- *- * This file originally came from the gdb sources, and the- * copyright notices have been retained below.- */--/****************************************************************************-- THIS SOFTWARE IS NOT COPYRIGHTED-- HP offers the following for use in the public domain. HP makes no- warranty with regard to the software or its performance and the- user accepts the software "AS IS" with all faults.-- HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD- TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.--****************************************************************************/--/****************************************************************************- * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $- *- * Module name: remcom.c $- * Revision: 1.34 $- * Date: 91/03/09 12:29:49 $- * Contributor: Lake Stevens Instrument Division$- *- * Description: low level support for gdb debugger. $- *- * Considerations: only works on target hardware $- *- * Written by: Glenn Engel $- * ModuleState: Experimental $- *- * NOTES: See Below $- *- * Modified for SPARC by Stu Grossman, Cygnus Support.- *- * This code has been extensively tested on the Fujitsu SPARClite demo board.- *- * To enable debugger support, two things need to happen. One, a- * call to set_debug_traps() is necessary in order to allow any breakpoints- * or error conditions to be properly intercepted and reported to gdb.- * Two, a breakpoint needs to be generated to begin communication. This- * is most easily accomplished by a call to breakpoint(). Breakpoint()- * simulates a breakpoint by executing a trap #1.- *- *************- *- * The following gdb commands are supported:- *- * command function Return value- *- * g return the value of the CPU registers hex data or ENN- * G set the value of the CPU registers OK or ENN- * qOffsets Get section offsets. Reply is Text=xxx;Data=yyy;Bss=zzz- *- * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN- * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN- *- * c Resume at current address SNN ( signal NN)- * cAA..AA Continue at address AA..AA SNN- *- * s Step one instruction SNN- * sAA..AA Step one instruction from AA..AA SNN- *- * k kill- *- * ? What was the last sigval ? SNN (signal NN)- *- * bBB..BB Set baud rate to BB..BB OK or BNN, then sets- * baud rate- *- * All commands and responses are sent with a packet which includes a- * checksum. A packet consists of- *- * $<packet info>#<checksum>.- *- * where- * <packet info> :: <characters representing the command or response>- * <checksum> :: <two hex digits computed as modulo 256 sum of <packetinfo>>- *- * When a packet is received, it is first acknowledged with either '+' or '-'.- * '+' indicates a successful transfer. '-' indicates a failed transfer.- *- * Example:- *- * Host: Reply:- * $m0,10#2a +$00010203040506070809101112131415#42- *- ****************************************************************************/--#include <linux/config.h>-#include <linux/kernel.h>-#include <linux/string.h>-#include <linux/mm.h>-#include <linux/smp.h>-#include <linux/smp_lock.h>-#include <linux/init.h>-#include <linux/sysrq.h>--#include <asm/cacheflush.h>-#include <asm/system.h>-#include <asm/signal.h>-#include <asm/kgdb.h>-#include <asm/pgtable.h>-#include <asm/ptrace.h>--void breakinst(void);--/*- * BUFMAX defines the maximum number of characters in inbound/outbound buffers- * at least NUMREGBYTES*2 are needed for register packets- */-#define BUFMAX 2048-static char remcomInBuffer[BUFMAX];-static char remcomOutBuffer[BUFMAX];--static int initialized;-static int kgdb_active;-static int kgdb_started;-static u_int fault_jmp_buf[100];-static int kdebug;---static const char hexchars[]="0123456789abcdef";--/* Place where we save old trap entries for restoration - sparc*/-/* struct tt_entry kgdb_savettable[256]; */-/* typedef void (*trapfunc_t)(void); */--static void kgdb_fault_handler(struct pt_regs *regs);-static int handle_exception (struct pt_regs *regs);--#if 0-/* Install an exception handler for kgdb */-static void exceptionHandler(int tnum, unsigned int *tfunc)-{- /* We are dorking with a live trap table, all irqs off */-}-#endif--int-kgdb_setjmp(long *buf)-{- asm ("mflr 0; stw 0,0(%0);"- "stw 1,4(%0); stw 2,8(%0);"- "mfcr 0; stw 0,12(%0);"- "stmw 13,16(%0)"- : : "r" (buf));- /* XXX should save fp regs as well */- return 0;-}-void-kgdb_longjmp(long *buf, int val)-{- if (val == 0)- val = 1;- asm ("lmw 13,16(%0);"- "lwz 0,12(%0); mtcrf 0x38,0;"- "lwz 0,0(%0); lwz 1,4(%0); lwz 2,8(%0);"- "mtlr 0; mr 3,%1"- : : "r" (buf), "r" (val));-}-/* Convert ch from a hex digit to an int */-static int-hex(unsigned char ch)-{- if (ch >= 'a' && ch <= 'f')- return ch-'a'+10;- if (ch >= '0' && ch <= '9')- return ch-'0';- if (ch >= 'A' && ch <= 'F')- return ch-'A'+10;- return -1;-}--/* Convert the memory pointed to by mem into hex, placing result in buf.- * Return a pointer to the last char put in buf (null), in case of mem fault,- * return 0.- */-static unsigned char *-mem2hex(const char *mem, char *buf, int count)-{- unsigned char ch;- unsigned short tmp_s;- unsigned long tmp_l;-- if (kgdb_setjmp((long*)fault_jmp_buf) == 0) {- debugger_fault_handler = kgdb_fault_handler;-- /* Accessing 16 bit and 32 bit objects in a single- ** load instruction is required to avoid bad side- ** effects for some IO registers.- */-- if ((count == 2) && (((long)mem & 1) == 0)) {- tmp_s = *(unsigned short *)mem;- mem += 2;- *buf++ = hexchars[(tmp_s >> 12) & 0xf];- *buf++ = hexchars[(tmp_s >> 8) & 0xf];- *buf++ = hexchars[(tmp_s >> 4) & 0xf];- *buf++ = hexchars[tmp_s & 0xf];-- } else if ((count == 4) && (((long)mem & 3) == 0)) {- tmp_l = *(unsigned int *)mem;- mem += 4;- *buf++ = hexchars[(tmp_l >> 28) & 0xf];- *buf++ = hexchars[(tmp_l >> 24) & 0xf];- *buf++ = hexchars[(tmp_l >> 20) & 0xf];- *buf++ = hexchars[(tm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -