1 /*
2  * arch/ppc/kernel/gen550_kgdb.c
3  *
4  * Generic 16550 kgdb support intended to be useful on a variety
5  * of platforms.  To enable this support, it is necessary to set
6  * the CONFIG_GEN550 option.  Any virtual mapping of the serial
7  * port(s) to be used can be accomplished by setting
8  * ppc_md.early_serial_map to a platform-specific mapping function.
9  *
10  * Adapted from ppc4xx_kgdb.c.
11  *
12  * Matt Porter <mporter@mvista.com>
13  *
14  * Copyright 2002 MontaVista Software Inc.
15  *
16  * This program is free software; you can redistribute  it and/or modify it
17  * under  the terms of  the GNU General Public License as published by the
18  * Free Software Foundation;  either version 2 of the  License, or (at your
19  * option) any later version.
20  */
21 
22 #include <linux/config.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 
26 #include <asm/machdep.h>
27 
28 extern unsigned long serial_init(int, void *);
29 extern unsigned long serial_getc(unsigned long);
30 extern unsigned long serial_putc(unsigned long, unsigned char);
31 
32 #if defined(CONFIG_KGDB_TTYS0)
33 #define KGDB_PORT 0
34 #elif defined(CONFIG_KGDB_TTYS1)
35 #define KGDB_PORT 1
36 #elif defined(CONFIG_KGDB_TTYS2)
37 #define KGDB_PORT 2
38 #elif defined(CONFIG_KGDB_TTYS3)
39 #define KGDB_PORT 3
40 #else
41 #error "invalid kgdb_tty port"
42 #endif
43 
44 static volatile unsigned int kgdb_debugport;
45 
putDebugChar(unsigned char c)46 void putDebugChar(unsigned char c)
47 {
48 	if (kgdb_debugport == 0)
49 		kgdb_debugport = serial_init(KGDB_PORT, NULL);
50 
51 	serial_putc(kgdb_debugport, c);
52 }
53 
getDebugChar(void)54 int getDebugChar(void)
55 {
56 	if (kgdb_debugport == 0)
57 		kgdb_debugport = serial_init(KGDB_PORT, NULL);
58 
59 	return(serial_getc(kgdb_debugport));
60 }
61 
kgdb_interruptible(int enable)62 void kgdb_interruptible(int enable)
63 {
64 	return;
65 }
66 
putDebugString(char * str)67 void putDebugString(char* str)
68 {
69 	while (*str != '\0') {
70 		putDebugChar(*str);
71 		str++;
72 	}
73 	putDebugChar('\r');
74 	return;
75 }
76 
77 void
kgdb_map_scc(void)78 kgdb_map_scc(void)
79 {
80 	printk("kgdb init\n");
81 	if (ppc_md.early_serial_map)
82 		ppc_md.early_serial_map();
83 	kgdb_debugport = serial_init(KGDB_PORT, NULL);
84 }
85