1 /* debug-stub.c: debug-mode stub
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/string.h>
13 #include <linux/kernel.h>
14 #include <linux/signal.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
17 #include <linux/serial_reg.h>
19 #include <asm/system.h>
20 #include <asm/serial-regs.h>
21 #include <asm/timer-regs.h>
22 #include <asm/irc-regs.h>
23 #include <asm/gdb-stub.h>
27 #define __UART0(X) (*(volatile uint8_t *)(UART0_BASE + (UART_##X)))
29 #define LSR_WAIT_FOR0(STATE) \
31 } while (!(__UART0(LSR) & UART_LSR_##STATE))
33 #define FLOWCTL_QUERY0(LINE) ({ __UART0(MSR) & UART_MSR_##LINE; })
34 #define FLOWCTL_CLEAR0(LINE) do { __UART0(MCR) &= ~UART_MCR_##LINE; } while (0)
35 #define FLOWCTL_SET0(LINE) do { __UART0(MCR) |= UART_MCR_##LINE; } while (0)
37 #define FLOWCTL_WAIT_FOR0(LINE) \
40 } while(!FLOWCTL_QUERY(LINE))
42 struct frv_debug_status __debug_status;
44 static void __init debug_stub_init(void);
46 /*****************************************************************************/
48 * debug mode handler stub
49 * - we come here with the CPU in debug mode and with exceptions disabled
50 * - handle debugging services for userspace
52 asmlinkage void debug_stub(void)
66 __set_HSR(0, hsr0 & ~HSR0_ETMD);
68 /* disable single stepping */
69 __debug_status.dcr &= ~DCR_SE;
71 /* kernel mode can propose an exception be handled in debug mode by jumping to a special
73 if (__debug_frame->pc == (unsigned long) __break_hijack_kernel_event_breaks_here) {
74 /* replace the debug frame with the kernel frame and discard
75 * the top kernel context */
76 *__debug_frame = *__frame;
77 __frame = __debug_frame->next_frame;
78 __debug_status.brr = (__debug_frame->tbr & TBR_TT) << 12;
79 __debug_status.brr |= BRR_EB;
82 if (__debug_frame->pc == (unsigned long) __debug_bug_trap + 4) {
83 __debug_frame->pc = __debug_frame->lr;
84 type = __debug_frame->gr8;
92 __set_HSR(0, __get_HSR(0) | HSR0_ETMD);
94 } /* end debug_stub() */
96 /*****************************************************************************/
98 * debug stub initialisation
100 static void __init debug_stub_init(void)
102 __set_IRR(6, 0xff000000); /* map ERRs to NMI */
103 __set_IITMR(1, 0x20000000); /* ERR0/1, UART0/1 IRQ detect levels */
105 asm volatile(" movgs gr0,ibar0 \n"
106 " movgs gr0,ibar1 \n"
107 " movgs gr0,ibar2 \n"
108 " movgs gr0,ibar3 \n"
109 " movgs gr0,dbar0 \n"
110 " movgs gr0,dbmr00 \n"
111 " movgs gr0,dbmr01 \n"
112 " movgs gr0,dbdr00 \n"
113 " movgs gr0,dbdr01 \n"
114 " movgs gr0,dbar1 \n"
115 " movgs gr0,dbmr10 \n"
116 " movgs gr0,dbmr11 \n"
117 " movgs gr0,dbdr10 \n"
118 " movgs gr0,dbdr11 \n"
121 /* deal with debugging stub initialisation and initial pause */
122 if (__debug_frame->pc == (unsigned long) __debug_stub_init_break)
123 __debug_frame->pc = (unsigned long) start_kernel;
125 /* enable the debug events we want to trap */
126 __debug_status.dcr = DCR_EBE;
128 #ifdef CONFIG_GDBSTUB
136 } /* end debug_stub_init() */
138 /*****************************************************************************/
140 * kernel "exit" trap for gdb stub
142 void debug_stub_exit(int status)
145 #ifdef CONFIG_GDBSTUB
146 gdbstub_exit(status);
149 } /* end debug_stub_exit() */
151 /*****************************************************************************/
153 * send string to serial port
155 void debug_to_serial(const char *p, int n)
163 // FLOWCTL_WAIT_FOR(CTS);
169 // FLOWCTL_WAIT_FOR(CTS);
177 } /* end debug_to_serial() */
179 /*****************************************************************************/
181 * send string to serial port
183 void debug_to_serial2(const char *fmt, ...)
190 n = vsprintf(buf, fmt, va);
193 debug_to_serial(buf, n);
195 } /* end debug_to_serial2() */
197 /*****************************************************************************/
199 * set up the ttyS0 serial port baud rate timers
201 void __init console_set_baud(unsigned baud)
203 unsigned value, high, low;
206 /* work out the divisor to give us the nearest higher baud rate */
207 value = __serial_clock_speed_HZ / 16 / baud;
209 /* determine the baud rate range */
210 high = __serial_clock_speed_HZ / 16 / value;
211 low = __serial_clock_speed_HZ / 16 / (value + 1);
213 /* pick the nearest bound */
214 if (low + (high - low) / 2 > baud)
218 __UART0(LCR) |= UART_LCR_DLAB;
220 __UART0(DLL) = value & 0xff;
221 __UART0(DLM) = (value >> 8) & 0xff;
226 } /* end console_set_baud() */
228 /*****************************************************************************/
232 int __init console_get_baud(void)
238 __UART0(LCR) |= UART_LCR_DLAB;
240 value = __UART0(DLM) << 8;
241 value |= __UART0(DLL);
246 } /* end console_get_baud() */
248 /*****************************************************************************/
252 #ifndef CONFIG_NO_KERNEL_MSG
253 void __debug_bug_printk(const char *file, unsigned line)
255 printk("kernel BUG at %s:%d!\n", file, line);
257 } /* end __debug_bug_printk() */