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