summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/mips/genmongoosev/startup/gdb-support.c
blob: 4c6ee61736be5f060ced65a0808878182e25e6c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 *  GDB Support Routines for the Mongoose-V
 *
 *  COPYRIGHT (c) 1989-2002.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

#include <rtems.h>
#include <rtems/bspIo.h>
#include <libcpu/mongoose-v.h>
#include "gdb_if.h"

#include <rtems/libio.h>

#include <stdio.h>
#include <string.h>


/*

We're going to call right down into the uart driver because we're
operating within an exception.  if things are broken because something
bad happened, this may be our last chance to debug before RTEMS goes
mad, so we won't rely on the I/O subsystem to be operating.  This is a
little messy, but at least we're not talking right to the hardware.

*/

extern int mg5uart_set_attributes(int minor,const struct termios *t);
extern int mg5uart_open(int major,int minor, void *arg);
extern int mg5uart_close(int major,int minor, void *arg);
extern void mg5uart_write_polled(int minor, char c );
extern int mg5uart_inbyte_nonblocking_polled(int minor);


static int debugUartEnabled = 0;





int mg5rdbgOpenGDBuart(int breakoninit)
{
   struct termios t;
   memset(&t,0,sizeof(struct termios));

   if( mg5uart_open(0,1,NULL) != RTEMS_SUCCESSFUL )
   {
      printf("gdbstub: Failed to open UART port 2\n");
      return -1;
   }

   t.c_cflag |= B19200;
   t.c_cflag |= CS8;
   if( mg5uart_set_attributes(1,&t) != 0 )
   {
      printf("gdbstub: Failed to configure UART 2 for 19200N82\n");
      return -1;
   }
   printf("gdbstub: UART 2 configured for 19200N82\n");

   debugUartEnabled  = -1;

   /* set up vectoring for gdb */
   mips_gdb_stub_install(-1);

   /*
      this is a rough approximation of our memory map.  Yours is
      probably different.  It only needs to be sufficient for the stub
      to know what it can and can't do and where.
   */
   gdbstub_add_memsegment(0         , 0x8001ffff, MEMOPT_READABLE );
   gdbstub_add_memsegment(0x80020000, 0x80afffff, MEMOPT_READABLE | MEMOPT_WRITEABLE );
   gdbstub_add_memsegment(0x80b00000, 0x814fffff, MEMOPT_READABLE );
   gdbstub_add_memsegment(0x81500000, 0x81ffffff, MEMOPT_READABLE | MEMOPT_WRITEABLE );


   if( breakoninit )
   {
      printf("gdbstub: GDB stub entered, connect host debugger now\n");
      /*
         break to gdb.  We'll wait there for the operator to get their gdb
         going, then they can 'continue' or do whatever.
      */
      mips_break(0);
      printf("gdbstub: User code running\n");
   }
   else
      printf("gdbstub: GDB stub ready for exceptions\n");

   return RTEMS_SUCCESSFUL;
}


void mg5rdbgCloseGDBuart(void)
{
   mg5uart_close(0,1,NULL);
   debugUartEnabled  = 0;
}




char getDebugChar (void)
{
   if( debugUartEnabled )
   {
      int rv;

      while( (rv = mg5uart_inbyte_nonblocking_polled(1)) < 0 );
      return (char)rv;
   }

   return 0;
}


void putDebugChar (char c)
{
   if( debugUartEnabled )
      return mg5uart_write_polled(1,c);
}




/*
   {
      * initialize hardware pc and data breakpoints to quiet state*
      uint32_t   dcic, reg, mask;

      reg = 0xffffffff;
      mask = 0xffffffff;

      mips_set_bpcrm( reg, mask );
      mips_set_bdarm( reg, mask );

      mips_get_dcic( dcic );
      * configure dcic for trapping, user & kernel mode, PC traps and enable it *
      dcic = DCIC_TR | DCIC_UD | DCIC_KD | DCIC_PCE | DCIC_DE;
      * dcic = DCIC_UD | DCIC_KD | DCIC_PCE | DCIC_DE; *
      mips_set_dcic( dcic );

      mips_get_bpcrm( reg, mask );
      mips_get_dcic( dcic );
      * printf("bpc is %08X, bpc_mask is %08X, dcic is now %08X\n", reg, mask, dcic ); *
   }
*/