CORE: Support swl and swr
[yari.git] / gdbstub / gdb-support.c.clio
blob712160a7ef4db6bff42a1514e9158790dff0e696
1 /*
2  *   These are the low-level serial IO routines for the GDB stub
3  *   This is platform-specific, since it deals with the serial registers directly
4  */
6 #include <linux/serial_reg.h>
8 #define NEC41XX_SIU_BASE  (0x0c000000 + 0xa0000000)
10 #define NEC41XX_UART_RX  (UART_RX  + NEC41XX_SIU_BASE)
11 #define NEC41XX_UART_TX  (UART_TX  + NEC41XX_SIU_BASE)
12 #define NEC41XX_UART_DLL (UART_DLL + NEC41XX_SIU_BASE)
13 #define NEC41XX_UART_DLM (UART_DLM + NEC41XX_SIU_BASE)
14 #define NEC41XX_UART_IER (UART_IER + NEC41XX_SIU_BASE)
15 #define NEC41XX_UART_IIR (UART_IIR + NEC41XX_SIU_BASE)
16 #define NEC41XX_UART_FCR (UART_FCR + NEC41XX_SIU_BASE)
17 #define NEC41XX_UART_LCR (UART_LCR + NEC41XX_SIU_BASE)
18 #define NEC41XX_UART_MCR (UART_MCR + NEC41XX_SIU_BASE)
19 #define NEC41XX_UART_LSR (UART_LSR + NEC41XX_SIU_BASE)
20 #define NEC41XX_UART_MSR (UART_MSR + NEC41XX_SIU_BASE)
21 #define NEC41XX_UART_IRSEL      (8 + NEC41XX_SIU_BASE)
23 #define NEC41XX_CMU_CLKMSK  (0x0b000060 + 0xa0000000)
24 #define NEC41XX_CMU_CLKMSK_MSKFFIR  0x0400
25 #define NEC41XX_CMU_CLKMSK_MSKSHSP  0x0200
26 #define NEC41XX_CMU_CLKMSK_MSKSSIU  0x0100
27 #define NEC41XX_CMU_CLKMSK_MSKDSIU  0x0020
28 #define NEC41XX_CMU_CLKMSK_MSKFIR   0x0010
29 #define NEC41XX_CMU_CLKMSK_MSKKIU   0x0008
30 #define NEC41XX_CMU_CLKMSK_MSKAIU   0x0004
31 #define NEC41XX_CMU_CLKMSK_MSKSIU   0x0002
32 #define NEC41XX_CMU_CLKMSK_MSKPIU   0x0001
34 #define NEC41XX_GIU_PODATL  (0x0b00011c + 0xa0000000)
35 #define NEC41XX_GIU_PODATL_GPIO47  0x8000
36 #define NEC41XX_GIU_PODATL_GPIO46  0x4000
37 #define NEC41XX_GIU_PODATL_GPIO45  0x2000
38 #define NEC41XX_GIU_PODATL_GPIO44  0x1000
39 #define NEC41XX_GIU_PODATL_GPIO43  0x0800
40 #define NEC41XX_GIU_PODATL_GPIO42  0x0400
41 #define NEC41XX_GIU_PODATL_GPIO41  0x0200
42 #define NEC41XX_GIU_PODATL_GPIO40  0x0100
43 #define NEC41XX_GIU_PODATL_GPIO39  0x0080
44 #define NEC41XX_GIU_PODATL_GPIO38  0x0040
45 #define NEC41XX_GIU_PODATL_GPIO37  0x0020
46 #define NEC41XX_GIU_PODATL_GPIO36  0x0010
47 #define NEC41XX_GIU_PODATL_GPIO35  0x0008
48 #define NEC41XX_GIU_PODATL_GPIO34  0x0004
49 #define NEC41XX_GIU_PODATL_GPIO33  0x0002
50 #define NEC41XX_GIU_PODATL_GPIO32  0x0001
52 void DbgInitSerial(void);
54 static int initialized = 0;
56 void DbgInitSerial(void)
58         unsigned char dummy;
60                 /* turn on GPIO42, probably controls power to external serial transceiver */
61         *(unsigned short*)NEC41XX_GIU_PODATL |= NEC41XX_GIU_PODATL_GPIO42;
63                 /* turn on the clocks to the serial port */
64         *(unsigned short*)NEC41XX_CMU_CLKMSK |= NEC41XX_CMU_CLKMSK_MSKSSIU |
65                                                                  NEC41XX_CMU_CLKMSK_MSKSIU;
67         *(unsigned char*)NEC41XX_UART_IRSEL = 0;        /* set for RS232C, not IrDA */
69         *(unsigned char*)NEC41XX_UART_LCR = UART_LCR_DLAB;      /* prepare to set baud rate */
70         *(unsigned char*)NEC41XX_UART_DLL = 10;
71         *(unsigned char*)NEC41XX_UART_DLM = 0;                  /* hardcoded: set to 115200 */
72         *(unsigned char*)NEC41XX_UART_LCR = UART_LCR_WLEN8;     /* clear DLAB, set up for 8N1 */
74         *(unsigned char*)NEC41XX_UART_IER = 0;                  /* disable interrupts */
76         *(unsigned char*)NEC41XX_UART_FCR = UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT;
77         *(unsigned char*)NEC41XX_UART_FCR = 0;                  /* clear FIFO and disable it */
79         *(unsigned char*)NEC41XX_UART_MCR = UART_MCR_RTS | UART_MCR_DTR;  /* set RTS and DTR */
81         dummy = *(unsigned char *)NEC41XX_UART_RX;              /* clear any pending ints */
82         dummy = *(unsigned char *)NEC41XX_UART_MSR;
83         dummy = *(unsigned char *)NEC41XX_UART_IIR;
85         while ( *(unsigned char*)NEC41XX_UART_LSR & UART_LSR_DR ) /* clear the receive buffer */
86                 dummy = *(unsigned char *)NEC41XX_UART_RX;      /* (and finish clearing ints) */
90 int putDebugChar(unsigned char c)
92         if (!initialized) {             /* need to init device first */
93                 DbgInitSerial();
94                 initialized = 1;
95         }
97         while ( !(*(unsigned char*)NEC41XX_UART_LSR & UART_LSR_THRE) ) ;
99         *(unsigned char *)NEC41XX_UART_TX = c;
101         return 1;
105 char getDebugChar(void)
107         if (!initialized) {             /* need to init device first */
108                 DbgInitSerial();
109                 initialized = 1;
110         }
112         while ( !(*(unsigned char*)NEC41XX_UART_LSR & UART_LSR_DR) ) ;
114         return(*(char *)NEC41XX_UART_RX);