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