Path: blob/master/arch/mn10300/kernel/gdb-io-serial.c
10817 views
/* 16550 serial driver for gdbstub I/O1*2* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public Licence7* as published by the Free Software Foundation; either version8* 2 of the Licence, or (at your option) any later version.9*/10#include <linux/string.h>11#include <linux/kernel.h>12#include <linux/signal.h>13#include <linux/sched.h>14#include <linux/mm.h>15#include <linux/console.h>16#include <linux/init.h>17#include <linux/nmi.h>1819#include <asm/pgtable.h>20#include <asm/system.h>21#include <asm/gdb-stub.h>22#include <asm/exceptions.h>23#include <asm/serial-regs.h>24#include <unit/serial.h>25#include <asm/smp.h>2627/*28* initialise the GDB stub29*/30void gdbstub_io_init(void)31{32u16 tmp;3334/* set up the serial port */35GDBPORT_SERIAL_LCR = UART_LCR_WLEN8; /* 1N8 */36GDBPORT_SERIAL_FCR = (UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |37UART_FCR_CLEAR_XMIT);3839FLOWCTL_CLEAR(DTR);40FLOWCTL_SET(RTS);4142gdbstub_io_set_baud(115200);4344/* we want to get serial receive interrupts */45XIRQxICR(GDBPORT_SERIAL_IRQ) = 0;46tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);4748#if CONFIG_GDBSTUB_IRQ_LEVEL == 049IVAR0 = EXCEP_IRQ_LEVEL0;50#elif CONFIG_GDBSTUB_IRQ_LEVEL == 151IVAR1 = EXCEP_IRQ_LEVEL1;52#elif CONFIG_GDBSTUB_IRQ_LEVEL == 253IVAR2 = EXCEP_IRQ_LEVEL2;54#elif CONFIG_GDBSTUB_IRQ_LEVEL == 355IVAR3 = EXCEP_IRQ_LEVEL3;56#elif CONFIG_GDBSTUB_IRQ_LEVEL == 457IVAR4 = EXCEP_IRQ_LEVEL4;58#elif CONFIG_GDBSTUB_IRQ_LEVEL == 559IVAR5 = EXCEP_IRQ_LEVEL5;60#else61#error "Unknown irq level for gdbstub."62#endif6364set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL),65gdbstub_io_rx_handler);6667XIRQxICR(GDBPORT_SERIAL_IRQ) &= ~GxICR_REQUEST;68XIRQxICR(GDBPORT_SERIAL_IRQ) =69GxICR_ENABLE | NUM2GxICR_LEVEL(CONFIG_GDBSTUB_IRQ_LEVEL);70tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);7172GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;7374/* permit level 0 IRQs to take place */75arch_local_change_intr_mask_level(76NUM2EPSW_IM(CONFIG_GDBSTUB_IRQ_LEVEL + 1));77}7879/*80* set up the GDB stub serial port baud rate timers81*/82void gdbstub_io_set_baud(unsigned baud)83{84unsigned value;85u8 lcr;8687value = 18432000 / 16 / baud;8889lcr = GDBPORT_SERIAL_LCR;90GDBPORT_SERIAL_LCR |= UART_LCR_DLAB;91GDBPORT_SERIAL_DLL = value & 0xff;92GDBPORT_SERIAL_DLM = (value >> 8) & 0xff;93GDBPORT_SERIAL_LCR = lcr;94}9596/*97* wait for a character to come from the debugger98*/99int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)100{101unsigned ix;102u8 ch, st;103#if defined(CONFIG_MN10300_WD_TIMER)104int cpu;105#endif106107*_ch = 0xff;108109if (gdbstub_rx_unget) {110*_ch = gdbstub_rx_unget;111gdbstub_rx_unget = 0;112return 0;113}114115try_again:116/* pull chars out of the buffer */117ix = gdbstub_rx_outp;118barrier();119if (ix == gdbstub_rx_inp) {120if (nonblock)121return -EAGAIN;122#ifdef CONFIG_MN10300_WD_TIMER123for (cpu = 0; cpu < NR_CPUS; cpu++)124watchdog_alert_counter[cpu] = 0;125#endif126goto try_again;127}128129ch = gdbstub_rx_buffer[ix++];130st = gdbstub_rx_buffer[ix++];131barrier();132gdbstub_rx_outp = ix & 0x00000fff;133134if (st & UART_LSR_BI) {135gdbstub_proto("### GDB Rx Break Detected ###\n");136return -EINTR;137} else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {138gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);139return -EIO;140} else {141gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);142*_ch = ch & 0x7f;143return 0;144}145}146147/*148* send a character to the debugger149*/150void gdbstub_io_tx_char(unsigned char ch)151{152FLOWCTL_SET(DTR);153LSR_WAIT_FOR(THRE);154/* FLOWCTL_WAIT_FOR(CTS); */155156if (ch == 0x0a) {157GDBPORT_SERIAL_TX = 0x0d;158LSR_WAIT_FOR(THRE);159/* FLOWCTL_WAIT_FOR(CTS); */160}161GDBPORT_SERIAL_TX = ch;162163FLOWCTL_CLEAR(DTR);164}165166/*167* send a character to the debugger168*/169void gdbstub_io_tx_flush(void)170{171LSR_WAIT_FOR(TEMT);172LSR_WAIT_FOR(THRE);173FLOWCTL_CLEAR(DTR);174}175176177