Path: blob/master/arch/cris/arch-v32/kernel/kgdb.c
15125 views
/*1* arch/cris/arch-v32/kernel/kgdb.c2*3* CRIS v32 version by Orjan Friberg, Axis Communications AB.4*5* S390 version6* Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation7* Author(s): Denis Joseph Barrow ([email protected],[email protected]),8*9* Originally written by Glenn Engel, Lake Stevens Instrument Division10*11* Contributed by HP Systems12*13* Modified for SPARC by Stu Grossman, Cygnus Support.14*15* Modified for Linux/MIPS (and MIPS in general) by Andreas Busse16* Send complaints, suggestions etc. to <[email protected]>17*18* Copyright (C) 1995 Andreas Busse19*/2021/* FIXME: Check the documentation. */2223/*24* kgdb usage notes:25* -----------------26*27* If you select CONFIG_ETRAX_KGDB in the configuration, the kernel will be28* built with different gcc flags: "-g" is added to get debug infos, and29* "-fomit-frame-pointer" is omitted to make debugging easier. Since the30* resulting kernel will be quite big (approx. > 7 MB), it will be stripped31* before compresion. Such a kernel will behave just as usually, except if32* given a "debug=<device>" command line option. (Only serial devices are33* allowed for <device>, i.e. no printers or the like; possible values are34* machine depedend and are the same as for the usual debug device, the one35* for logging kernel messages.) If that option is given and the device can be36* initialized, the kernel will connect to the remote gdb in trap_init(). The37* serial parameters are fixed to 8N1 and 115200 bps, for easyness of38* implementation.39*40* To start a debugging session, start that gdb with the debugging kernel41* image (the one with the symbols, vmlinux.debug) named on the command line.42* This file will be used by gdb to get symbol and debugging infos about the43* kernel. Next, select remote debug mode by44* target remote <device>45* where <device> is the name of the serial device over which the debugged46* machine is connected. Maybe you have to adjust the baud rate by47* set remotebaud <rate>48* or also other parameters with stty:49* shell stty ... </dev/...50* If the kernel to debug has already booted, it waited for gdb and now51* connects, and you'll see a breakpoint being reported. If the kernel isn't52* running yet, start it now. The order of gdb and the kernel doesn't matter.53* Another thing worth knowing about in the getting-started phase is how to54* debug the remote protocol itself. This is activated with55* set remotedebug 156* gdb will then print out each packet sent or received. You'll also get some57* messages about the gdb stub on the console of the debugged machine.58*59* If all that works, you can use lots of the usual debugging techniques on60* the kernel, e.g. inspecting and changing variables/memory, setting61* breakpoints, single stepping and so on. It's also possible to interrupt the62* debugged kernel by pressing C-c in gdb. Have fun! :-)63*64* The gdb stub is entered (and thus the remote gdb gets control) in the65* following situations:66*67* - If breakpoint() is called. This is just after kgdb initialization, or if68* a breakpoint() call has been put somewhere into the kernel source.69* (Breakpoints can of course also be set the usual way in gdb.)70* In eLinux, we call breakpoint() in init/main.c after IRQ initialization.71*72* - If there is a kernel exception, i.e. bad_super_trap() or die_if_kernel()73* are entered. All the CPU exceptions are mapped to (more or less..., see74* the hard_trap_info array below) appropriate signal, which are reported75* to gdb. die_if_kernel() is usually called after some kind of access76* error and thus is reported as SIGSEGV.77*78* - When panic() is called. This is reported as SIGABRT.79*80* - If C-c is received over the serial line, which is treated as81* SIGINT.82*83* Of course, all these signals are just faked for gdb, since there is no84* signal concept as such for the kernel. It also isn't possible --obviously--85* to set signal handlers from inside gdb, or restart the kernel with a86* signal.87*88* Current limitations:89*90* - While the kernel is stopped, interrupts are disabled for safety reasons91* (i.e., variables not changing magically or the like). But this also92* means that the clock isn't running anymore, and that interrupts from the93* hardware may get lost/not be served in time. This can cause some device94* errors...95*96* - When single-stepping, only one instruction of the current thread is97* executed, but interrupts are allowed for that time and will be serviced98* if pending. Be prepared for that.99*100* - All debugging happens in kernel virtual address space. There's no way to101* access physical memory not mapped in kernel space, or to access user102* space. A way to work around this is using get_user_long & Co. in gdb103* expressions, but only for the current process.104*105* - Interrupting the kernel only works if interrupts are currently allowed,106* and the interrupt of the serial line isn't blocked by some other means107* (IPL too high, disabled, ...)108*109* - The gdb stub is currently not reentrant, i.e. errors that happen therein110* (e.g. accessing invalid memory) may not be caught correctly. This could111* be removed in future by introducing a stack of struct registers.112*113*/114115/*116* To enable debugger support, two things need to happen. One, a117* call to kgdb_init() is necessary in order to allow any breakpoints118* or error conditions to be properly intercepted and reported to gdb.119* Two, a breakpoint needs to be generated to begin communication. This120* is most easily accomplished by a call to breakpoint().121*122* The following gdb commands are supported:123*124* command function Return value125*126* g return the value of the CPU registers hex data or ENN127* G set the value of the CPU registers OK or ENN128*129* mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN130* MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN131*132* c Resume at current address SNN ( signal NN)133* cAA..AA Continue at address AA..AA SNN134*135* s Step one instruction SNN136* sAA..AA Step one instruction from AA..AA SNN137*138* k kill139*140* ? What was the last sigval ? SNN (signal NN)141*142* bBB..BB Set baud rate to BB..BB OK or BNN, then sets143* baud rate144*145* All commands and responses are sent with a packet which includes a146* checksum. A packet consists of147*148* $<packet info>#<checksum>.149*150* where151* <packet info> :: <characters representing the command or response>152* <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>153*154* When a packet is received, it is first acknowledged with either '+' or '-'.155* '+' indicates a successful transfer. '-' indicates a failed transfer.156*157* Example:158*159* Host: Reply:160* $m0,10#2a +$00010203040506070809101112131415#42161*162*/163164165#include <linux/string.h>166#include <linux/signal.h>167#include <linux/kernel.h>168#include <linux/delay.h>169#include <linux/linkage.h>170#include <linux/reboot.h>171172#include <asm/setup.h>173#include <asm/ptrace.h>174175#include <asm/irq.h>176#include <hwregs/reg_map.h>177#include <hwregs/reg_rdwr.h>178#include <hwregs/intr_vect_defs.h>179#include <hwregs/ser_defs.h>180181/* From entry.S. */182extern void gdb_handle_exception(void);183/* From kgdb_asm.S. */184extern void kgdb_handle_exception(void);185186static int kgdb_started = 0;187188/********************************* Register image ****************************/189190typedef191struct register_image192{193/* Offset */194unsigned int r0; /* 0x00 */195unsigned int r1; /* 0x04 */196unsigned int r2; /* 0x08 */197unsigned int r3; /* 0x0C */198unsigned int r4; /* 0x10 */199unsigned int r5; /* 0x14 */200unsigned int r6; /* 0x18 */201unsigned int r7; /* 0x1C */202unsigned int r8; /* 0x20; Frame pointer (if any) */203unsigned int r9; /* 0x24 */204unsigned int r10; /* 0x28 */205unsigned int r11; /* 0x2C */206unsigned int r12; /* 0x30 */207unsigned int r13; /* 0x34 */208unsigned int sp; /* 0x38; R14, Stack pointer */209unsigned int acr; /* 0x3C; R15, Address calculation register. */210211unsigned char bz; /* 0x40; P0, 8-bit zero register */212unsigned char vr; /* 0x41; P1, Version register (8-bit) */213unsigned int pid; /* 0x42; P2, Process ID */214unsigned char srs; /* 0x46; P3, Support register select (8-bit) */215unsigned short wz; /* 0x47; P4, 16-bit zero register */216unsigned int exs; /* 0x49; P5, Exception status */217unsigned int eda; /* 0x4D; P6, Exception data address */218unsigned int mof; /* 0x51; P7, Multiply overflow register */219unsigned int dz; /* 0x55; P8, 32-bit zero register */220unsigned int ebp; /* 0x59; P9, Exception base pointer */221unsigned int erp; /* 0x5D; P10, Exception return pointer. Contains the PC we are interested in. */222unsigned int srp; /* 0x61; P11, Subroutine return pointer */223unsigned int nrp; /* 0x65; P12, NMI return pointer */224unsigned int ccs; /* 0x69; P13, Condition code stack */225unsigned int usp; /* 0x6D; P14, User mode stack pointer */226unsigned int spc; /* 0x71; P15, Single step PC */227unsigned int pc; /* 0x75; Pseudo register (for the most part set to ERP). */228229} registers;230231typedef232struct bp_register_image233{234/* Support register bank 0. */235unsigned int s0_0;236unsigned int s1_0;237unsigned int s2_0;238unsigned int s3_0;239unsigned int s4_0;240unsigned int s5_0;241unsigned int s6_0;242unsigned int s7_0;243unsigned int s8_0;244unsigned int s9_0;245unsigned int s10_0;246unsigned int s11_0;247unsigned int s12_0;248unsigned int s13_0;249unsigned int s14_0;250unsigned int s15_0;251252/* Support register bank 1. */253unsigned int s0_1;254unsigned int s1_1;255unsigned int s2_1;256unsigned int s3_1;257unsigned int s4_1;258unsigned int s5_1;259unsigned int s6_1;260unsigned int s7_1;261unsigned int s8_1;262unsigned int s9_1;263unsigned int s10_1;264unsigned int s11_1;265unsigned int s12_1;266unsigned int s13_1;267unsigned int s14_1;268unsigned int s15_1;269270/* Support register bank 2. */271unsigned int s0_2;272unsigned int s1_2;273unsigned int s2_2;274unsigned int s3_2;275unsigned int s4_2;276unsigned int s5_2;277unsigned int s6_2;278unsigned int s7_2;279unsigned int s8_2;280unsigned int s9_2;281unsigned int s10_2;282unsigned int s11_2;283unsigned int s12_2;284unsigned int s13_2;285unsigned int s14_2;286unsigned int s15_2;287288/* Support register bank 3. */289unsigned int s0_3; /* BP_CTRL */290unsigned int s1_3; /* BP_I0_START */291unsigned int s2_3; /* BP_I0_END */292unsigned int s3_3; /* BP_D0_START */293unsigned int s4_3; /* BP_D0_END */294unsigned int s5_3; /* BP_D1_START */295unsigned int s6_3; /* BP_D1_END */296unsigned int s7_3; /* BP_D2_START */297unsigned int s8_3; /* BP_D2_END */298unsigned int s9_3; /* BP_D3_START */299unsigned int s10_3; /* BP_D3_END */300unsigned int s11_3; /* BP_D4_START */301unsigned int s12_3; /* BP_D4_END */302unsigned int s13_3; /* BP_D5_START */303unsigned int s14_3; /* BP_D5_END */304unsigned int s15_3; /* BP_RESERVED */305306} support_registers;307308enum register_name309{310R0, R1, R2, R3,311R4, R5, R6, R7,312R8, R9, R10, R11,313R12, R13, SP, ACR,314315BZ, VR, PID, SRS,316WZ, EXS, EDA, MOF,317DZ, EBP, ERP, SRP,318NRP, CCS, USP, SPC,319PC,320321S0, S1, S2, S3,322S4, S5, S6, S7,323S8, S9, S10, S11,324S12, S13, S14, S15325326};327328/* The register sizes of the registers in register_name. An unimplemented register329is designated by size 0 in this array. */330static int register_size[] =331{3324, 4, 4, 4,3334, 4, 4, 4,3344, 4, 4, 4,3354, 4, 4, 4,3363371, 1, 4, 1,3382, 4, 4, 4,3394, 4, 4, 4,3404, 4, 4, 4,3413424,3433444, 4, 4, 4,3454, 4, 4, 4,3464, 4, 4, 4,3474, 4, 4348349};350351/* Contains the register image of the kernel.352(Global so that they can be reached from assembler code.) */353registers reg;354support_registers sreg;355356/************** Prototypes for local library functions ***********************/357358/* Copy of strcpy from libc. */359static char *gdb_cris_strcpy(char *s1, const char *s2);360361/* Copy of strlen from libc. */362static int gdb_cris_strlen(const char *s);363364/* Copy of memchr from libc. */365static void *gdb_cris_memchr(const void *s, int c, int n);366367/* Copy of strtol from libc. Does only support base 16. */368static int gdb_cris_strtol(const char *s, char **endptr, int base);369370/********************** Prototypes for local functions. **********************/371372/* Write a value to a specified register regno in the register image373of the current thread. */374static int write_register(int regno, char *val);375376/* Read a value from a specified register in the register image. Returns the377status of the read operation. The register value is returned in valptr. */378static int read_register(char regno, unsigned int *valptr);379380/* Serial port, reads one character. ETRAX 100 specific. from debugport.c */381int getDebugChar(void);382383#ifdef CONFIG_ETRAX_VCS_SIM384int getDebugChar(void)385{386return socketread();387}388#endif389390/* Serial port, writes one character. ETRAX 100 specific. from debugport.c */391void putDebugChar(int val);392393#ifdef CONFIG_ETRAX_VCS_SIM394void putDebugChar(int val)395{396socketwrite((char *)&val, 1);397}398#endif399400/* Returns the integer equivalent of a hexadecimal character. */401static int hex(char ch);402403/* Convert the memory, pointed to by mem into hexadecimal representation.404Put the result in buf, and return a pointer to the last character405in buf (null). */406static char *mem2hex(char *buf, unsigned char *mem, int count);407408/* Convert the array, in hexadecimal representation, pointed to by buf into409binary representation. Put the result in mem, and return a pointer to410the character after the last byte written. */411static unsigned char *hex2mem(unsigned char *mem, char *buf, int count);412413/* Put the content of the array, in binary representation, pointed to by buf414into memory pointed to by mem, and return a pointer to415the character after the last byte written. */416static unsigned char *bin2mem(unsigned char *mem, unsigned char *buf, int count);417418/* Await the sequence $<data>#<checksum> and store <data> in the array buffer419returned. */420static void getpacket(char *buffer);421422/* Send $<data>#<checksum> from the <data> in the array buffer. */423static void putpacket(char *buffer);424425/* Build and send a response packet in order to inform the host the426stub is stopped. */427static void stub_is_stopped(int sigval);428429/* All expected commands are sent from remote.c. Send a response according430to the description in remote.c. Not static since it needs to be reached431from assembler code. */432void handle_exception(int sigval);433434/* Performs a complete re-start from scratch. ETRAX specific. */435static void kill_restart(void);436437/******************** Prototypes for global functions. ***********************/438439/* The string str is prepended with the GDB printout token and sent. */440void putDebugString(const unsigned char *str, int len);441442/* A static breakpoint to be used at startup. */443void breakpoint(void);444445/* Avoid warning as the internal_stack is not used in the C-code. */446#define USEDVAR(name) { if (name) { ; } }447#define USEDFUN(name) { void (*pf)(void) = (void *)name; USEDVAR(pf) }448449/********************************** Packet I/O ******************************/450/* BUFMAX defines the maximum number of characters in451inbound/outbound buffers */452/* FIXME: How do we know it's enough? */453#define BUFMAX 512454455/* Run-length encoding maximum length. Send 64 at most. */456#define RUNLENMAX 64457458/* The inbound/outbound buffers used in packet I/O */459static char input_buffer[BUFMAX];460static char output_buffer[BUFMAX];461462/* Error and warning messages. */463enum error_type464{465SUCCESS, E01, E02, E03, E04, E05, E06,466};467468static char *error_message[] =469{470"",471"E01 Set current or general thread - H[c,g] - internal error.",472"E02 Change register content - P - cannot change read-only register.",473"E03 Thread is not alive.", /* T, not used. */474"E04 The command is not supported - [s,C,S,!,R,d,r] - internal error.",475"E05 Change register content - P - the register is not implemented..",476"E06 Change memory content - M - internal error.",477};478479/********************************** Breakpoint *******************************/480/* Use an internal stack in the breakpoint and interrupt response routines.481FIXME: How do we know the size of this stack is enough?482Global so it can be reached from assembler code. */483#define INTERNAL_STACK_SIZE 1024484char internal_stack[INTERNAL_STACK_SIZE];485486/* Due to the breakpoint return pointer, a state variable is needed to keep487track of whether it is a static (compiled) or dynamic (gdb-invoked)488breakpoint to be handled. A static breakpoint uses the content of register489ERP as it is whereas a dynamic breakpoint requires subtraction with 2490in order to execute the instruction. The first breakpoint is static; all491following are assumed to be dynamic. */492static int dynamic_bp = 0;493494/********************************* String library ****************************/495/* Single-step over library functions creates trap loops. */496497/* Copy char s2[] to s1[]. */498static char*499gdb_cris_strcpy(char *s1, const char *s2)500{501char *s = s1;502503for (s = s1; (*s++ = *s2++) != '\0'; )504;505return s1;506}507508/* Find length of s[]. */509static int510gdb_cris_strlen(const char *s)511{512const char *sc;513514for (sc = s; *sc != '\0'; sc++)515;516return (sc - s);517}518519/* Find first occurrence of c in s[n]. */520static void*521gdb_cris_memchr(const void *s, int c, int n)522{523const unsigned char uc = c;524const unsigned char *su;525526for (su = s; 0 < n; ++su, --n)527if (*su == uc)528return (void *)su;529return NULL;530}531/******************************* Standard library ****************************/532/* Single-step over library functions creates trap loops. */533/* Convert string to long. */534static int535gdb_cris_strtol(const char *s, char **endptr, int base)536{537char *s1;538char *sd;539int x = 0;540541for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)542x = x * base + (sd - hex_asc);543544if (endptr) {545/* Unconverted suffix is stored in endptr unless endptr is NULL. */546*endptr = s1;547}548549return x;550}551552/********************************* Register image ****************************/553554/* Write a value to a specified register in the register image of the current555thread. Returns status code SUCCESS, E02 or E05. */556static int557write_register(int regno, char *val)558{559int status = SUCCESS;560561if (regno >= R0 && regno <= ACR) {562/* Consecutive 32-bit registers. */563hex2mem((unsigned char *)®.r0 + (regno - R0) * sizeof(unsigned int),564val, sizeof(unsigned int));565566} else if (regno == BZ || regno == VR || regno == WZ || regno == DZ) {567/* Read-only registers. */568status = E02;569570} else if (regno == PID) {571/* 32-bit register. (Even though we already checked SRS and WZ, we cannot572combine this with the EXS - SPC write since SRS and WZ have different size.) */573hex2mem((unsigned char *)®.pid, val, sizeof(unsigned int));574575} else if (regno == SRS) {576/* 8-bit register. */577hex2mem((unsigned char *)®.srs, val, sizeof(unsigned char));578579} else if (regno >= EXS && regno <= SPC) {580/* Consecutive 32-bit registers. */581hex2mem((unsigned char *)®.exs + (regno - EXS) * sizeof(unsigned int),582val, sizeof(unsigned int));583584} else if (regno == PC) {585/* Pseudo-register. Treat as read-only. */586status = E02;587588} else if (regno >= S0 && regno <= S15) {589/* 32-bit registers. */590hex2mem((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), val, sizeof(unsigned int));591} else {592/* Non-existing register. */593status = E05;594}595return status;596}597598/* Read a value from a specified register in the register image. Returns the599value in the register or -1 for non-implemented registers. */600static int601read_register(char regno, unsigned int *valptr)602{603int status = SUCCESS;604605/* We read the zero registers from the register struct (instead of just returning 0)606to catch errors. */607608if (regno >= R0 && regno <= ACR) {609/* Consecutive 32-bit registers. */610*valptr = *(unsigned int *)((char *)®.r0 + (regno - R0) * sizeof(unsigned int));611612} else if (regno == BZ || regno == VR) {613/* Consecutive 8-bit registers. */614*valptr = (unsigned int)(*(unsigned char *)615((char *)®.bz + (regno - BZ) * sizeof(char)));616617} else if (regno == PID) {618/* 32-bit register. */619*valptr = *(unsigned int *)((char *)®.pid);620621} else if (regno == SRS) {622/* 8-bit register. */623*valptr = (unsigned int)(*(unsigned char *)((char *)®.srs));624625} else if (regno == WZ) {626/* 16-bit register. */627*valptr = (unsigned int)(*(unsigned short *)(char *)®.wz);628629} else if (regno >= EXS && regno <= PC) {630/* Consecutive 32-bit registers. */631*valptr = *(unsigned int *)((char *)®.exs + (regno - EXS) * sizeof(unsigned int));632633} else if (regno >= S0 && regno <= S15) {634/* Consecutive 32-bit registers, located elsewhere. */635*valptr = *(unsigned int *)((char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int));636637} else {638/* Non-existing register. */639status = E05;640}641return status;642643}644645/********************************** Packet I/O ******************************/646/* Returns the integer equivalent of a hexadecimal character. */647static int648hex(char ch)649{650if ((ch >= 'a') && (ch <= 'f'))651return (ch - 'a' + 10);652if ((ch >= '0') && (ch <= '9'))653return (ch - '0');654if ((ch >= 'A') && (ch <= 'F'))655return (ch - 'A' + 10);656return -1;657}658659/* Convert the memory, pointed to by mem into hexadecimal representation.660Put the result in buf, and return a pointer to the last character661in buf (null). */662663static char *664mem2hex(char *buf, unsigned char *mem, int count)665{666int i;667int ch;668669if (mem == NULL) {670/* Invalid address, caught by 'm' packet handler. */671for (i = 0; i < count; i++) {672*buf++ = '0';673*buf++ = '0';674}675} else {676/* Valid mem address. */677for (i = 0; i < count; i++) {678ch = *mem++;679buf = pack_hex_byte(buf, ch);680}681}682/* Terminate properly. */683*buf = '\0';684return buf;685}686687/* Same as mem2hex, but puts it in network byte order. */688static char *689mem2hex_nbo(char *buf, unsigned char *mem, int count)690{691int i;692int ch;693694mem += count - 1;695for (i = 0; i < count; i++) {696ch = *mem--;697buf = pack_hex_byte(buf, ch);698}699700/* Terminate properly. */701*buf = '\0';702return buf;703}704705/* Convert the array, in hexadecimal representation, pointed to by buf into706binary representation. Put the result in mem, and return a pointer to707the character after the last byte written. */708static unsigned char*709hex2mem(unsigned char *mem, char *buf, int count)710{711int i;712unsigned char ch;713for (i = 0; i < count; i++) {714ch = hex (*buf++) << 4;715ch = ch + hex (*buf++);716*mem++ = ch;717}718return mem;719}720721/* Put the content of the array, in binary representation, pointed to by buf722into memory pointed to by mem, and return a pointer to the character after723the last byte written.724Gdb will escape $, #, and the escape char (0x7d). */725static unsigned char*726bin2mem(unsigned char *mem, unsigned char *buf, int count)727{728int i;729unsigned char *next;730for (i = 0; i < count; i++) {731/* Check for any escaped characters. Be paranoid and732only unescape chars that should be escaped. */733if (*buf == 0x7d) {734next = buf + 1;735if (*next == 0x3 || *next == 0x4 || *next == 0x5D) {736/* #, $, ESC */737buf++;738*buf += 0x20;739}740}741*mem++ = *buf++;742}743return mem;744}745746/* Await the sequence $<data>#<checksum> and store <data> in the array buffer747returned. */748static void749getpacket(char *buffer)750{751unsigned char checksum;752unsigned char xmitcsum;753int i;754int count;755char ch;756757do {758while((ch = getDebugChar ()) != '$')759/* Wait for the start character $ and ignore all other characters */;760checksum = 0;761xmitcsum = -1;762count = 0;763/* Read until a # or the end of the buffer is reached */764while (count < BUFMAX) {765ch = getDebugChar();766if (ch == '#')767break;768checksum = checksum + ch;769buffer[count] = ch;770count = count + 1;771}772773if (count >= BUFMAX)774continue;775776buffer[count] = 0;777778if (ch == '#') {779xmitcsum = hex(getDebugChar()) << 4;780xmitcsum += hex(getDebugChar());781if (checksum != xmitcsum) {782/* Wrong checksum */783putDebugChar('-');784} else {785/* Correct checksum */786putDebugChar('+');787/* If sequence characters are received, reply with them */788if (buffer[2] == ':') {789putDebugChar(buffer[0]);790putDebugChar(buffer[1]);791/* Remove the sequence characters from the buffer */792count = gdb_cris_strlen(buffer);793for (i = 3; i <= count; i++)794buffer[i - 3] = buffer[i];795}796}797}798} while (checksum != xmitcsum);799}800801/* Send $<data>#<checksum> from the <data> in the array buffer. */802803static void804putpacket(char *buffer)805{806int checksum;807int runlen;808int encode;809810do {811char *src = buffer;812putDebugChar('$');813checksum = 0;814while (*src) {815/* Do run length encoding */816putDebugChar(*src);817checksum += *src;818runlen = 0;819while (runlen < RUNLENMAX && *src == src[runlen]) {820runlen++;821}822if (runlen > 3) {823/* Got a useful amount */824putDebugChar ('*');825checksum += '*';826encode = runlen + ' ' - 4;827putDebugChar(encode);828checksum += encode;829src += runlen;830} else {831src++;832}833}834putDebugChar('#');835putDebugChar(hex_asc_hi(checksum));836putDebugChar(hex_asc_lo(checksum));837} while(kgdb_started && (getDebugChar() != '+'));838}839840/* The string str is prepended with the GDB printout token and sent. Required841in traditional implementations. */842void843putDebugString(const unsigned char *str, int len)844{845/* Move SPC forward if we are single-stepping. */846asm("spchere:");847asm("move $spc, $r10");848asm("cmp.d spchere, $r10");849asm("bne nosstep");850asm("nop");851asm("move.d spccont, $r10");852asm("move $r10, $spc");853asm("nosstep:");854855output_buffer[0] = 'O';856mem2hex(&output_buffer[1], (unsigned char *)str, len);857putpacket(output_buffer);858859asm("spccont:");860}861862/********************************** Handle exceptions ************************/863/* Build and send a response packet in order to inform the host the864stub is stopped. TAAn...:r...;n...:r...;n...:r...;865AA = signal number866n... = register number (hex)867r... = register contents868n... = `thread'869r... = thread process ID. This is a hex integer.870n... = other string not starting with valid hex digit.871gdb should ignore this n,r pair and go on to the next.872This way we can extend the protocol. */873static void874stub_is_stopped(int sigval)875{876char *ptr = output_buffer;877unsigned int reg_cont;878879/* Send trap type (converted to signal) */880881*ptr++ = 'T';882ptr = pack_hex_byte(ptr, sigval);883884if (((reg.exs & 0xff00) >> 8) == 0xc) {885886/* Some kind of hardware watchpoint triggered. Find which one887and determine its type (read/write/access). */888int S, bp, trig_bits = 0, rw_bits = 0;889int trig_mask = 0;890unsigned int *bp_d_regs = &sreg.s3_3;891/* In a lot of cases, the stopped data address will simply be EDA.892In some cases, we adjust it to match the watched data range.893(We don't want to change the actual EDA though). */894unsigned int stopped_data_address;895/* The S field of EXS. */896S = (reg.exs & 0xffff0000) >> 16;897898if (S & 1) {899/* Instruction watchpoint. */900/* FIXME: Check against, and possibly adjust reported EDA. */901} else {902/* Data watchpoint. Find the one that triggered. */903for (bp = 0; bp < 6; bp++) {904905/* Dx_RD, Dx_WR in the S field of EXS for this BP. */906int bitpos_trig = 1 + bp * 2;907/* Dx_BPRD, Dx_BPWR in BP_CTRL for this BP. */908int bitpos_config = 2 + bp * 4;909910/* Get read/write trig bits for this BP. */911trig_bits = (S & (3 << bitpos_trig)) >> bitpos_trig;912913/* Read/write config bits for this BP. */914rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;915if (trig_bits) {916/* Sanity check: the BP shouldn't trigger for accesses917that it isn't configured for. */918if ((rw_bits == 0x1 && trig_bits != 0x1) ||919(rw_bits == 0x2 && trig_bits != 0x2))920panic("Invalid r/w trigging for this BP");921922/* Mark this BP as trigged for future reference. */923trig_mask |= (1 << bp);924925if (reg.eda >= bp_d_regs[bp * 2] &&926reg.eda <= bp_d_regs[bp * 2 + 1]) {927/* EDA within range for this BP; it must be the one928we're looking for. */929stopped_data_address = reg.eda;930break;931}932}933}934if (bp < 6) {935/* Found a trigged BP with EDA within its configured data range. */936} else if (trig_mask) {937/* Something triggered, but EDA doesn't match any BP's range. */938for (bp = 0; bp < 6; bp++) {939/* Dx_BPRD, Dx_BPWR in BP_CTRL for this BP. */940int bitpos_config = 2 + bp * 4;941942/* Read/write config bits for this BP (needed later). */943rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;944945if (trig_mask & (1 << bp)) {946/* EDA within 31 bytes of the configured start address? */947if (reg.eda + 31 >= bp_d_regs[bp * 2]) {948/* Changing the reported address to match949the start address of the first applicable BP. */950stopped_data_address = bp_d_regs[bp * 2];951break;952} else {953/* We continue since we might find another useful BP. */954printk("EDA doesn't match trigged BP's range");955}956}957}958}959960/* No match yet? */961BUG_ON(bp >= 6);962/* Note that we report the type according to what the BP is configured963for (otherwise we'd never report an 'awatch'), not according to how964it trigged. We did check that the trigged bits match what the BP is965configured for though. */966if (rw_bits == 0x1) {967/* read */968strncpy(ptr, "rwatch", 6);969ptr += 6;970} else if (rw_bits == 0x2) {971/* write */972strncpy(ptr, "watch", 5);973ptr += 5;974} else if (rw_bits == 0x3) {975/* access */976strncpy(ptr, "awatch", 6);977ptr += 6;978} else {979panic("Invalid r/w bits for this BP.");980}981982*ptr++ = ':';983/* Note that we don't read_register(EDA, ...) */984ptr = mem2hex_nbo(ptr, (unsigned char *)&stopped_data_address, register_size[EDA]);985*ptr++ = ';';986}987}988/* Only send PC, frame and stack pointer. */989read_register(PC, ®_cont);990ptr = pack_hex_byte(ptr, PC);991*ptr++ = ':';992ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[PC]);993*ptr++ = ';';994995read_register(R8, ®_cont);996ptr = pack_hex_byte(ptr, R8);997*ptr++ = ':';998ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[R8]);999*ptr++ = ';';10001001read_register(SP, ®_cont);1002ptr = pack_hex_byte(ptr, SP);1003*ptr++ = ':';1004ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[SP]);1005*ptr++ = ';';10061007/* Send ERP as well; this will save us an entire register fetch in some cases. */1008read_register(ERP, ®_cont);1009ptr = pack_hex_byte(ptr, ERP);1010*ptr++ = ':';1011ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[ERP]);1012*ptr++ = ';';10131014/* null-terminate and send it off */1015*ptr = 0;1016putpacket(output_buffer);1017}10181019/* Returns the size of an instruction that has a delay slot. */10201021int insn_size(unsigned long pc)1022{1023unsigned short opcode = *(unsigned short *)pc;1024int size = 0;10251026switch ((opcode & 0x0f00) >> 8) {1027case 0x0:1028case 0x9:1029case 0xb:1030size = 2;1031break;1032case 0xe:1033case 0xf:1034size = 6;1035break;1036case 0xd:1037/* Could be 4 or 6; check more bits. */1038if ((opcode & 0xff) == 0xff)1039size = 4;1040else1041size = 6;1042break;1043default:1044panic("Couldn't find size of opcode 0x%x at 0x%lx\n", opcode, pc);1045}10461047return size;1048}10491050void register_fixup(int sigval)1051{1052/* Compensate for ACR push at the beginning of exception handler. */1053reg.sp += 4;10541055/* Standard case. */1056reg.pc = reg.erp;1057if (reg.erp & 0x1) {1058/* Delay slot bit set. Report as stopped on proper instruction. */1059if (reg.spc) {1060/* Rely on SPC if set. */1061reg.pc = reg.spc;1062} else {1063/* Calculate the PC from the size of the instruction1064that the delay slot we're in belongs to. */1065reg.pc += insn_size(reg.erp & ~1) - 1 ;1066}1067}10681069if ((reg.exs & 0x3) == 0x0) {1070/* Bits 1 - 0 indicate the type of memory operation performed1071by the interrupted instruction. 0 means no memory operation,1072and EDA is undefined in that case. We zero it to avoid confusion. */1073reg.eda = 0;1074}10751076if (sigval == SIGTRAP) {1077/* Break 8, single step or hardware breakpoint exception. */10781079/* Check IDX field of EXS. */1080if (((reg.exs & 0xff00) >> 8) == 0x18) {10811082/* Break 8. */10831084/* Static (compiled) breakpoints must return to the next instruction1085in order to avoid infinite loops (default value of ERP). Dynamic1086(gdb-invoked) must subtract the size of the break instruction from1087the ERP so that the instruction that was originally in the break1088instruction's place will be run when we return from the exception. */1089if (!dynamic_bp) {1090/* Assuming that all breakpoints are dynamic from now on. */1091dynamic_bp = 1;1092} else {10931094/* Only if not in a delay slot. */1095if (!(reg.erp & 0x1)) {1096reg.erp -= 2;1097reg.pc -= 2;1098}1099}11001101} else if (((reg.exs & 0xff00) >> 8) == 0x3) {1102/* Single step. */1103/* Don't fiddle with S1. */11041105} else if (((reg.exs & 0xff00) >> 8) == 0xc) {11061107/* Hardware watchpoint exception. */11081109/* SPC has been updated so that we will get a single step exception1110when we return, but we don't want that. */1111reg.spc = 0;11121113/* Don't fiddle with S1. */1114}11151116} else if (sigval == SIGINT) {1117/* Nothing special. */1118}1119}11201121static void insert_watchpoint(char type, int addr, int len)1122{1123/* Breakpoint/watchpoint types (GDB terminology):11240 = memory breakpoint for instructions1125(not supported; done via memory write instead)11261 = hardware breakpoint for instructions (supported)11272 = write watchpoint (supported)11283 = read watchpoint (supported)11294 = access watchpoint (supported) */11301131if (type < '1' || type > '4') {1132output_buffer[0] = 0;1133return;1134}11351136/* Read watchpoints are set as access watchpoints, because of GDB's1137inability to deal with pure read watchpoints. */1138if (type == '3')1139type = '4';11401141if (type == '1') {1142/* Hardware (instruction) breakpoint. */1143/* Bit 0 in BP_CTRL holds the configuration for I0. */1144if (sreg.s0_3 & 0x1) {1145/* Already in use. */1146gdb_cris_strcpy(output_buffer, error_message[E04]);1147return;1148}1149/* Configure. */1150sreg.s1_3 = addr;1151sreg.s2_3 = (addr + len - 1);1152sreg.s0_3 |= 1;1153} else {1154int bp;1155unsigned int *bp_d_regs = &sreg.s3_3;11561157/* The watchpoint allocation scheme is the simplest possible.1158For example, if a region is watched for read and1159a write watch is requested, a new watchpoint will1160be used. Also, if a watch for a region that is already1161covered by one or more existing watchpoints, a new1162watchpoint will be used. */11631164/* First, find a free data watchpoint. */1165for (bp = 0; bp < 6; bp++) {1166/* Each data watchpoint's control registers occupy 2 bits1167(hence the 3), starting at bit 2 for D0 (hence the 2)1168with 4 bits between for each watchpoint (yes, the 4). */1169if (!(sreg.s0_3 & (0x3 << (2 + (bp * 4))))) {1170break;1171}1172}11731174if (bp > 5) {1175/* We're out of watchpoints. */1176gdb_cris_strcpy(output_buffer, error_message[E04]);1177return;1178}11791180/* Configure the control register first. */1181if (type == '3' || type == '4') {1182/* Trigger on read. */1183sreg.s0_3 |= (1 << (2 + bp * 4));1184}1185if (type == '2' || type == '4') {1186/* Trigger on write. */1187sreg.s0_3 |= (2 << (2 + bp * 4));1188}11891190/* Ugly pointer arithmetics to configure the watched range. */1191bp_d_regs[bp * 2] = addr;1192bp_d_regs[bp * 2 + 1] = (addr + len - 1);1193}11941195/* Set the S1 flag to enable watchpoints. */1196reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));1197gdb_cris_strcpy(output_buffer, "OK");1198}11991200static void remove_watchpoint(char type, int addr, int len)1201{1202/* Breakpoint/watchpoint types:12030 = memory breakpoint for instructions1204(not supported; done via memory write instead)12051 = hardware breakpoint for instructions (supported)12062 = write watchpoint (supported)12073 = read watchpoint (supported)12084 = access watchpoint (supported) */1209if (type < '1' || type > '4') {1210output_buffer[0] = 0;1211return;1212}12131214/* Read watchpoints are set as access watchpoints, because of GDB's1215inability to deal with pure read watchpoints. */1216if (type == '3')1217type = '4';12181219if (type == '1') {1220/* Hardware breakpoint. */1221/* Bit 0 in BP_CTRL holds the configuration for I0. */1222if (!(sreg.s0_3 & 0x1)) {1223/* Not in use. */1224gdb_cris_strcpy(output_buffer, error_message[E04]);1225return;1226}1227/* Deconfigure. */1228sreg.s1_3 = 0;1229sreg.s2_3 = 0;1230sreg.s0_3 &= ~1;1231} else {1232int bp;1233unsigned int *bp_d_regs = &sreg.s3_3;1234/* Try to find a watchpoint that is configured for the1235specified range, then check that read/write also matches. */12361237/* Ugly pointer arithmetic, since I cannot rely on a1238single switch (addr) as there may be several watchpoints with1239the same start address for example. */12401241for (bp = 0; bp < 6; bp++) {1242if (bp_d_regs[bp * 2] == addr &&1243bp_d_regs[bp * 2 + 1] == (addr + len - 1)) {1244/* Matching range. */1245int bitpos = 2 + bp * 4;1246int rw_bits;12471248/* Read/write bits for this BP. */1249rw_bits = (sreg.s0_3 & (0x3 << bitpos)) >> bitpos;12501251if ((type == '3' && rw_bits == 0x1) ||1252(type == '2' && rw_bits == 0x2) ||1253(type == '4' && rw_bits == 0x3)) {1254/* Read/write matched. */1255break;1256}1257}1258}12591260if (bp > 5) {1261/* No watchpoint matched. */1262gdb_cris_strcpy(output_buffer, error_message[E04]);1263return;1264}12651266/* Found a matching watchpoint. Now, deconfigure it by1267both disabling read/write in bp_ctrl and zeroing its1268start/end addresses. */1269sreg.s0_3 &= ~(3 << (2 + (bp * 4)));1270bp_d_regs[bp * 2] = 0;1271bp_d_regs[bp * 2 + 1] = 0;1272}12731274/* Note that we don't clear the S1 flag here. It's done when continuing. */1275gdb_cris_strcpy(output_buffer, "OK");1276}1277127812791280/* All expected commands are sent from remote.c. Send a response according1281to the description in remote.c. */1282void1283handle_exception(int sigval)1284{1285/* Avoid warning of not used. */12861287USEDFUN(handle_exception);1288USEDVAR(internal_stack[0]);12891290register_fixup(sigval);12911292/* Send response. */1293stub_is_stopped(sigval);12941295for (;;) {1296output_buffer[0] = '\0';1297getpacket(input_buffer);1298switch (input_buffer[0]) {1299case 'g':1300/* Read registers: g1301Success: Each byte of register data is described by two hex digits.1302Registers are in the internal order for GDB, and the bytes1303in a register are in the same order the machine uses.1304Failure: void. */1305{1306char *buf;1307/* General and special registers. */1308buf = mem2hex(output_buffer, (char *)®, sizeof(registers));1309/* Support registers. */1310/* -1 because of the null termination that mem2hex adds. */1311mem2hex(buf,1312(char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),131316 * sizeof(unsigned int));1314break;1315}1316case 'G':1317/* Write registers. GXX..XX1318Each byte of register data is described by two hex digits.1319Success: OK1320Failure: void. */1321/* General and special registers. */1322hex2mem((char *)®, &input_buffer[1], sizeof(registers));1323/* Support registers. */1324hex2mem((char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),1325&input_buffer[1] + sizeof(registers),132616 * sizeof(unsigned int));1327gdb_cris_strcpy(output_buffer, "OK");1328break;13291330case 'P':1331/* Write register. Pn...=r...1332Write register n..., hex value without 0x, with value r...,1333which contains a hex value without 0x and two hex digits1334for each byte in the register (target byte order). P1f=11223344 means1335set register 31 to 44332211.1336Success: OK1337Failure: E02, E05 */1338{1339char *suffix;1340int regno = gdb_cris_strtol(&input_buffer[1], &suffix, 16);1341int status;13421343status = write_register(regno, suffix+1);13441345switch (status) {1346case E02:1347/* Do not support read-only registers. */1348gdb_cris_strcpy(output_buffer, error_message[E02]);1349break;1350case E05:1351/* Do not support non-existing registers. */1352gdb_cris_strcpy(output_buffer, error_message[E05]);1353break;1354default:1355/* Valid register number. */1356gdb_cris_strcpy(output_buffer, "OK");1357break;1358}1359}1360break;13611362case 'm':1363/* Read from memory. mAA..AA,LLLL1364AA..AA is the address and LLLL is the length.1365Success: XX..XX is the memory content. Can be fewer bytes than1366requested if only part of the data may be read. m6000120a,6c means1367retrieve 108 byte from base address 6000120a.1368Failure: void. */1369{1370char *suffix;1371unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],1372&suffix, 16);1373int len = gdb_cris_strtol(suffix+1, 0, 16);13741375/* Bogus read (i.e. outside the kernel's1376segment)? . */1377if (!((unsigned int)addr >= 0xc0000000 &&1378(unsigned int)addr < 0xd0000000))1379addr = NULL;13801381mem2hex(output_buffer, addr, len);1382}1383break;13841385case 'X':1386/* Write to memory. XAA..AA,LLLL:XX..XX1387AA..AA is the start address, LLLL is the number of bytes, and1388XX..XX is the binary data.1389Success: OK1390Failure: void. */1391case 'M':1392/* Write to memory. MAA..AA,LLLL:XX..XX1393AA..AA is the start address, LLLL is the number of bytes, and1394XX..XX is the hexadecimal data.1395Success: OK1396Failure: void. */1397{1398char *lenptr;1399char *dataptr;1400unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],1401&lenptr, 16);1402int len = gdb_cris_strtol(lenptr+1, &dataptr, 16);1403if (*lenptr == ',' && *dataptr == ':') {1404if (input_buffer[0] == 'M') {1405hex2mem(addr, dataptr + 1, len);1406} else /* X */ {1407bin2mem(addr, dataptr + 1, len);1408}1409gdb_cris_strcpy(output_buffer, "OK");1410}1411else {1412gdb_cris_strcpy(output_buffer, error_message[E06]);1413}1414}1415break;14161417case 'c':1418/* Continue execution. cAA..AA1419AA..AA is the address where execution is resumed. If AA..AA is1420omitted, resume at the present address.1421Success: return to the executing thread.1422Failure: will never know. */14231424if (input_buffer[1] != '\0') {1425/* FIXME: Doesn't handle address argument. */1426gdb_cris_strcpy(output_buffer, error_message[E04]);1427break;1428}14291430/* Before continuing, make sure everything is set up correctly. */14311432/* Set the SPC to some unlikely value. */1433reg.spc = 0;1434/* Set the S1 flag to 0 unless some watchpoint is enabled (since setting1435S1 to 0 would also disable watchpoints). (Note that bits 26-31 in BP_CTRL1436are reserved, so don't check against those). */1437if ((sreg.s0_3 & 0x3fff) == 0) {1438reg.ccs &= ~(1 << (S_CCS_BITNR + CCS_SHIFT));1439}14401441return;14421443case 's':1444/* Step. sAA..AA1445AA..AA is the address where execution is resumed. If AA..AA is1446omitted, resume at the present address. Success: return to the1447executing thread. Failure: will never know. */14481449if (input_buffer[1] != '\0') {1450/* FIXME: Doesn't handle address argument. */1451gdb_cris_strcpy(output_buffer, error_message[E04]);1452break;1453}14541455/* Set the SPC to PC, which is where we'll return1456(deduced previously). */1457reg.spc = reg.pc;14581459/* Set the S1 (first stacked, not current) flag, which will1460kick into action when we rfe. */1461reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));1462return;14631464case 'Z':14651466/* Insert breakpoint or watchpoint, Ztype,addr,length.1467Remote protocol says: A remote target shall return an empty string1468for an unrecognized breakpoint or watchpoint packet type. */1469{1470char *lenptr;1471char *dataptr;1472int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);1473int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);1474char type = input_buffer[1];14751476insert_watchpoint(type, addr, len);1477break;1478}14791480case 'z':1481/* Remove breakpoint or watchpoint, Ztype,addr,length.1482Remote protocol says: A remote target shall return an empty string1483for an unrecognized breakpoint or watchpoint packet type. */1484{1485char *lenptr;1486char *dataptr;1487int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);1488int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);1489char type = input_buffer[1];14901491remove_watchpoint(type, addr, len);1492break;1493}149414951496case '?':1497/* The last signal which caused a stop. ?1498Success: SAA, where AA is the signal number.1499Failure: void. */1500output_buffer[0] = 'S';1501output_buffer[1] = hex_asc_hi(sigval);1502output_buffer[2] = hex_asc_lo(sigval);1503output_buffer[3] = 0;1504break;15051506case 'D':1507/* Detach from host. D1508Success: OK, and return to the executing thread.1509Failure: will never know */1510putpacket("OK");1511return;15121513case 'k':1514case 'r':1515/* kill request or reset request.1516Success: restart of target.1517Failure: will never know. */1518kill_restart();1519break;15201521case 'C':1522case 'S':1523case '!':1524case 'R':1525case 'd':1526/* Continue with signal sig. Csig;AA..AA1527Step with signal sig. Ssig;AA..AA1528Use the extended remote protocol. !1529Restart the target system. R01530Toggle debug flag. d1531Search backwards. tAA:PP,MM1532Not supported: E04 */15331534/* FIXME: What's the difference between not supported1535and ignored (below)? */1536gdb_cris_strcpy(output_buffer, error_message[E04]);1537break;15381539default:1540/* The stub should ignore other request and send an empty1541response ($#<checksum>). This way we can extend the protocol and GDB1542can tell whether the stub it is talking to uses the old or the new. */1543output_buffer[0] = 0;1544break;1545}1546putpacket(output_buffer);1547}1548}15491550void1551kgdb_init(void)1552{1553reg_intr_vect_rw_mask intr_mask;1554reg_ser_rw_intr_mask ser_intr_mask;15551556/* Configure the kgdb serial port. */1557#if defined(CONFIG_ETRAX_KGDB_PORT0)1558/* Note: no shortcut registered (not handled by multiple_interrupt).1559See entry.S. */1560set_exception_vector(SER0_INTR_VECT, kgdb_handle_exception);1561/* Enable the ser irq in the global config. */1562intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);1563intr_mask.ser0 = 1;1564REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);15651566ser_intr_mask = REG_RD(ser, regi_ser0, rw_intr_mask);1567ser_intr_mask.dav = regk_ser_yes;1568REG_WR(ser, regi_ser0, rw_intr_mask, ser_intr_mask);1569#elif defined(CONFIG_ETRAX_KGDB_PORT1)1570/* Note: no shortcut registered (not handled by multiple_interrupt).1571See entry.S. */1572set_exception_vector(SER1_INTR_VECT, kgdb_handle_exception);1573/* Enable the ser irq in the global config. */1574intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);1575intr_mask.ser1 = 1;1576REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);15771578ser_intr_mask = REG_RD(ser, regi_ser1, rw_intr_mask);1579ser_intr_mask.dav = regk_ser_yes;1580REG_WR(ser, regi_ser1, rw_intr_mask, ser_intr_mask);1581#elif defined(CONFIG_ETRAX_KGDB_PORT2)1582/* Note: no shortcut registered (not handled by multiple_interrupt).1583See entry.S. */1584set_exception_vector(SER2_INTR_VECT, kgdb_handle_exception);1585/* Enable the ser irq in the global config. */1586intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);1587intr_mask.ser2 = 1;1588REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);15891590ser_intr_mask = REG_RD(ser, regi_ser2, rw_intr_mask);1591ser_intr_mask.dav = regk_ser_yes;1592REG_WR(ser, regi_ser2, rw_intr_mask, ser_intr_mask);1593#elif defined(CONFIG_ETRAX_KGDB_PORT3)1594/* Note: no shortcut registered (not handled by multiple_interrupt).1595See entry.S. */1596set_exception_vector(SER3_INTR_VECT, kgdb_handle_exception);1597/* Enable the ser irq in the global config. */1598intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);1599intr_mask.ser3 = 1;1600REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);16011602ser_intr_mask = REG_RD(ser, regi_ser3, rw_intr_mask);1603ser_intr_mask.dav = regk_ser_yes;1604REG_WR(ser, regi_ser3, rw_intr_mask, ser_intr_mask);1605#endif16061607}1608/* Performs a complete re-start from scratch. */1609static void1610kill_restart(void)1611{1612machine_restart("");1613}16141615/* Use this static breakpoint in the start-up only. */16161617void1618breakpoint(void)1619{1620kgdb_started = 1;1621dynamic_bp = 0; /* This is a static, not a dynamic breakpoint. */1622__asm__ volatile ("break 8"); /* Jump to kgdb_handle_breakpoint. */1623}16241625/****************************** End of file **********************************/162616271628