1 | /* |
---|
2 | * GDB Support Routines for the Mongoose-V |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2002. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include <rtems/bspIo.h> |
---|
16 | #include <libcpu/mongoose-v.h> |
---|
17 | #include "gdb_if.h" |
---|
18 | |
---|
19 | #include <rtems/libio.h> |
---|
20 | |
---|
21 | #include <stdio.h> |
---|
22 | #include <string.h> |
---|
23 | |
---|
24 | |
---|
25 | /* |
---|
26 | |
---|
27 | We're going to call right down into the uart driver because we're |
---|
28 | operating within an exception. if things are broken because something |
---|
29 | bad happened, this may be our last chance to debug before RTEMS goes |
---|
30 | mad, so we won't rely on the I/O subsystem to be operating. This is a |
---|
31 | little messy, but at least we're not talking right to the hardware. |
---|
32 | |
---|
33 | */ |
---|
34 | |
---|
35 | extern int mg5uart_set_attributes(int minor,const struct termios *t); |
---|
36 | extern int mg5uart_open(int major,int minor, void *arg); |
---|
37 | extern int mg5uart_close(int major,int minor, void *arg); |
---|
38 | extern void mg5uart_write_polled(int minor, char c ); |
---|
39 | extern int mg5uart_inbyte_nonblocking_polled(int minor); |
---|
40 | |
---|
41 | |
---|
42 | static int debugUartEnabled = 0; |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | int mg5rdbgOpenGDBuart(int breakoninit) |
---|
49 | { |
---|
50 | struct termios t; |
---|
51 | memset(&t,0,sizeof(struct termios)); |
---|
52 | |
---|
53 | if( mg5uart_open(0,1,NULL) != RTEMS_SUCCESSFUL ) |
---|
54 | { |
---|
55 | printf("gdbstub: Failed to open UART port 2\n"); |
---|
56 | return -1; |
---|
57 | } |
---|
58 | |
---|
59 | t.c_cflag |= B19200; |
---|
60 | t.c_cflag |= CS8; |
---|
61 | if( mg5uart_set_attributes(1,&t) != 0 ) |
---|
62 | { |
---|
63 | printf("gdbstub: Failed to configure UART 2 for 19200N82\n"); |
---|
64 | return -1; |
---|
65 | } |
---|
66 | printf("gdbstub: UART 2 configured for 19200N82\n"); |
---|
67 | |
---|
68 | debugUartEnabled = -1; |
---|
69 | |
---|
70 | /* set up vectoring for gdb */ |
---|
71 | mips_gdb_stub_install(-1); |
---|
72 | |
---|
73 | /* |
---|
74 | this is a rough approximation of our memory map. Yours is |
---|
75 | probably different. It only needs to be sufficient for the stub |
---|
76 | to know what it can and can't do and where. |
---|
77 | */ |
---|
78 | gdbstub_add_memsegment(0 , 0x8001ffff, MEMOPT_READABLE ); |
---|
79 | gdbstub_add_memsegment(0x80020000, 0x80afffff, MEMOPT_READABLE | MEMOPT_WRITEABLE ); |
---|
80 | gdbstub_add_memsegment(0x80b00000, 0x814fffff, MEMOPT_READABLE ); |
---|
81 | gdbstub_add_memsegment(0x81500000, 0x81ffffff, MEMOPT_READABLE | MEMOPT_WRITEABLE ); |
---|
82 | |
---|
83 | |
---|
84 | if( breakoninit ) |
---|
85 | { |
---|
86 | printf("gdbstub: GDB stub entered, connect host debugger now\n"); |
---|
87 | /* |
---|
88 | break to gdb. We'll wait there for the operator to get their gdb |
---|
89 | going, then they can 'continue' or do whatever. |
---|
90 | */ |
---|
91 | mips_break(0); |
---|
92 | printf("gdbstub: User code running\n"); |
---|
93 | } |
---|
94 | else |
---|
95 | printf("gdbstub: GDB stub ready for exceptions\n"); |
---|
96 | |
---|
97 | return RTEMS_SUCCESSFUL; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | void mg5rdbgCloseGDBuart(void) |
---|
102 | { |
---|
103 | mg5uart_close(0,1,NULL); |
---|
104 | debugUartEnabled = 0; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | char getDebugChar (void) |
---|
111 | { |
---|
112 | if( debugUartEnabled ) |
---|
113 | { |
---|
114 | int rv; |
---|
115 | |
---|
116 | while( (rv = mg5uart_inbyte_nonblocking_polled(1)) < 0 ); |
---|
117 | return (char)rv; |
---|
118 | } |
---|
119 | |
---|
120 | return 0; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | void putDebugChar (char c) |
---|
125 | { |
---|
126 | if( debugUartEnabled ) |
---|
127 | return mg5uart_write_polled(1,c); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | /* |
---|
134 | { |
---|
135 | * initialize hardware pc and data breakpoints to quiet state* |
---|
136 | unsigned32 dcic, reg, mask; |
---|
137 | |
---|
138 | reg = 0xffffffff; |
---|
139 | mask = 0xffffffff; |
---|
140 | |
---|
141 | mips_set_bpcrm( reg, mask ); |
---|
142 | mips_set_bdarm( reg, mask ); |
---|
143 | |
---|
144 | mips_get_dcic( dcic ); |
---|
145 | * configure dcic for trapping, user & kernel mode, PC traps and enable it * |
---|
146 | dcic = DCIC_TR | DCIC_UD | DCIC_KD | DCIC_PCE | DCIC_DE; |
---|
147 | * dcic = DCIC_UD | DCIC_KD | DCIC_PCE | DCIC_DE; * |
---|
148 | mips_set_dcic( dcic ); |
---|
149 | |
---|
150 | mips_get_bpcrm( reg, mask ); |
---|
151 | mips_get_dcic( dcic ); |
---|
152 | * printf("bpc is %08X, bpc_mask is %08X, dcic is now %08X\n", reg, mask, dcic ); * |
---|
153 | } |
---|
154 | */ |
---|
155 | |
---|