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