1 | /* |
---|
2 | ************************************************************************** |
---|
3 | * |
---|
4 | * Component = |
---|
5 | * |
---|
6 | * Synopsis = rdbg.c |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | ************************************************************************** |
---|
11 | */ |
---|
12 | |
---|
13 | #include <assert.h> |
---|
14 | #include <errno.h> |
---|
15 | #include <rtems.h> |
---|
16 | #include <rtems/error.h> |
---|
17 | #include <rdbg/rdbg.h> |
---|
18 | #include <rdbg/servrpc.h> |
---|
19 | #include <rtems/rtems_bsdnet.h> |
---|
20 | #include <rpc/pmap_clnt.h> |
---|
21 | #include <sys/socket.h> |
---|
22 | #include <netinet/in.h> |
---|
23 | #include <rtems/bspIo.h> |
---|
24 | |
---|
25 | u_short rtemsPort = RTEMS_PORT; |
---|
26 | int BackPort = RTEMS_BACK_PORT; |
---|
27 | int rtemsActive = 0; |
---|
28 | SVCXPRT *rtemsXprt; |
---|
29 | int rtemsSock; |
---|
30 | char taskName[] = "RTEMS rdbg daemon"; |
---|
31 | volatile int ExitForSingleStep = 0; |
---|
32 | volatile int Continue; |
---|
33 | volatile int justSaveContext; |
---|
34 | volatile Objects_Id currentTargetThread; |
---|
35 | volatile int CannotRestart = 0; |
---|
36 | volatile int TotalReboot = 0; |
---|
37 | int CONN_LIST_INC = 3; |
---|
38 | int PID_LIST_INC = 1; |
---|
39 | int TSP_RETRIES = 10; |
---|
40 | |
---|
41 | int |
---|
42 | getId () |
---|
43 | { |
---|
44 | rtems_id id; |
---|
45 | |
---|
46 | rtems_task_ident (RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &id); |
---|
47 | return (int) (id); |
---|
48 | } |
---|
49 | |
---|
50 | static int |
---|
51 | rdbgInit (void) |
---|
52 | { |
---|
53 | int sock; |
---|
54 | struct sockaddr_in addr; |
---|
55 | |
---|
56 | sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
---|
57 | if (sock == -1) { |
---|
58 | printf ("%s: rdbgInit: cannot allocate socket\n", taskName); |
---|
59 | return -1; |
---|
60 | } |
---|
61 | |
---|
62 | memset ((void *) &addr, 0, sizeof (struct sockaddr_in)); |
---|
63 | addr.sin_port = htons (rtemsPort); |
---|
64 | if ((bind (sock, (struct sockaddr *) &addr, sizeof (addr))) == -1) { |
---|
65 | printf ("%s: rdbgInit: cannot bind socket\n", taskName); |
---|
66 | return -2; |
---|
67 | } |
---|
68 | rtemsXprt = svcudp_create (sock); |
---|
69 | if (svcudp_enablecache (rtemsXprt, 1) == 0) { |
---|
70 | printf ("%s: rdbgInit: cannot enable rpc cache\n", taskName); |
---|
71 | return -3; |
---|
72 | } |
---|
73 | rtemsSock = sock; |
---|
74 | if (!svc_register (rtemsXprt, REMOTEDEB, REMOTEVERS, remotedeb_2, 0)) { |
---|
75 | fprintf (stderr, "unable to register (REMOTEDEB, REMOTEVERS, udp)."); |
---|
76 | return -4; |
---|
77 | } |
---|
78 | connect_rdbg_exception (); |
---|
79 | |
---|
80 | return 0; |
---|
81 | } |
---|
82 | |
---|
83 | rtems_task |
---|
84 | rdbgDaemon (rtems_task_argument argument) |
---|
85 | { |
---|
86 | svc_run (); |
---|
87 | } |
---|
88 | |
---|
89 | void |
---|
90 | rtems_rdbg_initialize (void) |
---|
91 | { |
---|
92 | rtems_name task_name; |
---|
93 | rtems_id tid; |
---|
94 | rtems_status_code status; |
---|
95 | |
---|
96 | #ifdef DDEBUG |
---|
97 | rdb_debug = 1; /* DPRINTF now will display */ |
---|
98 | #endif |
---|
99 | |
---|
100 | DPRINTF (("%s init starting\n", taskName)); |
---|
101 | |
---|
102 | /* |
---|
103 | * Print version string |
---|
104 | */ |
---|
105 | #ifdef DDEBUG |
---|
106 | printk ("RDBG v.%d built on [%s %s]\n", SERVER_VERS, __DATE__, __TIME__); |
---|
107 | #else |
---|
108 | printk ("RDBG v.%d\n", SERVER_VERS); |
---|
109 | #endif |
---|
110 | |
---|
111 | /* |
---|
112 | * Create socket and init UDP RPC server |
---|
113 | */ |
---|
114 | if (rdbgInit () != 0) |
---|
115 | goto error; |
---|
116 | |
---|
117 | Continue = 1; |
---|
118 | justSaveContext = 0; |
---|
119 | currentTargetThread = 0; |
---|
120 | |
---|
121 | task_name = rtems_build_name ('R', 'D', 'B', 'G'); |
---|
122 | if ((status = rtems_task_create (task_name, 5, 24576, |
---|
123 | RTEMS_INTERRUPT_LEVEL (0), |
---|
124 | RTEMS_DEFAULT_ATTRIBUTES | |
---|
125 | RTEMS_SYSTEM_TASK, &tid)) |
---|
126 | != RTEMS_SUCCESSFUL) { |
---|
127 | printf ("status = %d\n", status); |
---|
128 | rtems_panic ("Can't create task.\n"); |
---|
129 | } |
---|
130 | |
---|
131 | status = rtems_task_start (tid, rdbgDaemon, 0); |
---|
132 | |
---|
133 | return; |
---|
134 | |
---|
135 | error: |
---|
136 | printf ("initialization failed.\n"); |
---|
137 | } |
---|
138 | |
---|
139 | void |
---|
140 | setErrno (int error) |
---|
141 | { |
---|
142 | errno = error; |
---|
143 | } |
---|
144 | |
---|
145 | int |
---|
146 | getErrno () |
---|
147 | { |
---|
148 | return errno; |
---|
149 | } |
---|