]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/gdb_stub/connection
update
[l4.git] / l4 / pkg / plr / server / src / gdb_stub / connection
1 // vim: ft=cpp
2
3 /*
4  * gdb_stub/connection --
5  *
6  *     Definition of external connectivity for the GDB server stub
7  *
8  * (c) 2011-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
9  *     economic rights: Technische Universität Dresden (Germany)
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  */
14
15 #pragma once
16
17 #include <l4/sys/compiler.h>
18
19 EXTERN_C_BEGIN
20 #include <l4/ankh/client-c.h>
21 #include <l4/ankh/lwip-ankh.h>
22
23 #include "arch/cc.h"
24 #include "netif/etharp.h"
25 #include "lwip/tcpip.h"
26 #include "lwip/inet.h"
27 #include "lwip/sockets.h"
28 #include "lwip/netdb.h"
29
30 #include <semaphore.h>
31 EXTERN_C_END
32
33 class Uart_x86
34 {
35         private:
36                 unsigned long _base;
37
38         public:
39                 Uart_x86();
40                 bool startup(unsigned long base);
41                 void shutdown_uart();
42                 int get_char(bool blocking = true) const;
43                 int char_avail() const;
44                 void out_char(char c) const;
45                 int write_uart(char const* s, unsigned long count) const;
46 };
47
48 namespace Romain {
49         class Connection
50         {
51                 public:
52                         virtual ~Connection() { }
53
54                         virtual void setup_and_wait() = 0;
55                         virtual void disconnect() = 0;
56                         virtual int wait_for_cmd(char * const buf, unsigned bufsize) = 0;
57                         virtual int senddata(char const * const buf, unsigned bufsize) = 0;
58         };
59
60
61         class TCPConnection : public Connection
62         {
63                 private:
64                         unsigned  _port;                 // local port to listen on
65                         struct sockaddr_in _inet, _clnt; // connection info - mine and the client's
66                         int       _socket;               // socket id
67                         int       _socket_fd;            // socket fd
68
69                 public:
70
71                         TCPConnection(unsigned port)
72                                 : Connection(),
73                                   _port(port),
74                                   _inet(),
75                                   _clnt(),
76                                   _socket(-1), 
77                                   _socket_fd(-1)
78                         { }
79
80                         unsigned port() const { return _port; }
81
82                         /*
83                          * remote connection handling
84                          */
85                         virtual void setup_and_wait();
86                         virtual void disconnect();
87                         virtual int wait_for_cmd(char * const packetbuf, unsigned bufsize);
88                         virtual int senddata(char const * const buf, unsigned size);
89         };
90
91
92         class SerialConnection : public Connection
93         {
94                 Uart_x86 _uart;
95
96                 void get_vbus_resources();
97
98                 public:
99                         SerialConnection()
100                                 : _uart()
101                         {
102                                 get_vbus_resources();
103                         }
104
105                         virtual void setup_and_wait();
106                         virtual void disconnect();
107                         virtual int wait_for_cmd(char * const buf, unsigned bufsize);
108                         virtual int senddata(char const * const buf, unsigned bufsize);
109         };
110 }
111