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