1139778Simp/*-
2131899Smarcel * Copyright (c) 2004 Marcel Moolenaar
3131899Smarcel * All rights reserved.
4131899Smarcel *
5131899Smarcel * Redistribution and use in source and binary forms, with or without
6131899Smarcel * modification, are permitted provided that the following conditions
7131899Smarcel * are met:
8131899Smarcel *
9131899Smarcel * 1. Redistributions of source code must retain the above copyright
10131899Smarcel *    notice, this list of conditions and the following disclaimer.
11131899Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12131899Smarcel *    notice, this list of conditions and the following disclaimer in the
13131899Smarcel *    documentation and/or other materials provided with the distribution.
14131899Smarcel *
15131899Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16131899Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17131899Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18131899Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19131899Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20131899Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21131899Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22131899Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23131899Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24131899Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25131899Smarcel *
26131899Smarcel * $FreeBSD: releng/10.2/sys/gdb/gdb_int.h 157059 2006-03-23 23:06:14Z sam $
27131899Smarcel */
28131899Smarcel
29131899Smarcel#ifndef _GDB_GDB_INT_H_
30131899Smarcel#define	_GDB_GDB_INT_H_
31131899Smarcel
32131899Smarcelextern struct gdb_dbgport *gdb_cur;
33131899Smarcel
34157059Ssamextern int gdb_listening;
35157059Ssamvoid gdb_consinit(void);
36157059Ssam
37131899Smarcelextern char *gdb_rxp;
38131899Smarcelextern size_t gdb_rxsz;
39131899Smarcelextern char *gdb_txp;
40131899Smarcel
41131899Smarcelint gdb_rx_begin(void);
42131899Smarcelint gdb_rx_equal(const char *);
43131899Smarcelint gdb_rx_mem(unsigned char *, size_t);
44131899Smarcelint gdb_rx_varhex(uintmax_t *);
45131899Smarcel
46131899Smarcelstatic __inline int
47131899Smarcelgdb_rx_char(void)
48131899Smarcel{
49131899Smarcel	int c;
50131899Smarcel
51131899Smarcel	if (gdb_rxsz > 0) {
52131899Smarcel		c = *gdb_rxp++;
53131899Smarcel		gdb_rxsz--;
54131899Smarcel	} else
55131899Smarcel		c = -1;
56131899Smarcel	return (c);
57131899Smarcel}
58131899Smarcel
59131899Smarcelvoid gdb_tx_begin(char);
60131899Smarcelint gdb_tx_end(void);
61131899Smarcelint gdb_tx_mem(const unsigned char *, size_t);
62131899Smarcelvoid gdb_tx_reg(int);
63131899Smarcel
64131899Smarcelstatic __inline void
65131899Smarcelgdb_tx_char(char c)
66131899Smarcel{
67131899Smarcel	*gdb_txp++ = c;
68131899Smarcel}
69131899Smarcel
70131899Smarcelstatic __inline int
71131899Smarcelgdb_tx_empty(void)
72131899Smarcel{
73131899Smarcel	gdb_tx_begin('\0');
74131899Smarcel	return (gdb_tx_end());
75131899Smarcel}
76131899Smarcel
77131899Smarcelstatic __inline void
78131899Smarcelgdb_tx_hex(uintmax_t n, int sz)
79131899Smarcel{
80131899Smarcel	gdb_txp += sprintf(gdb_txp, "%0*jx", sz, n);
81131899Smarcel}
82131899Smarcel
83131899Smarcelstatic __inline int
84131899Smarcelgdb_tx_err(int err)
85131899Smarcel{
86131899Smarcel	gdb_tx_begin('E');
87131899Smarcel	gdb_tx_hex(err, 2);
88131899Smarcel	return (gdb_tx_end());
89131899Smarcel}
90131899Smarcel
91131899Smarcelstatic __inline int
92131899Smarcelgdb_tx_ok(void)
93131899Smarcel{
94131899Smarcel	gdb_tx_begin('O');
95131899Smarcel	gdb_tx_char('K');
96131899Smarcel	return (gdb_tx_end());
97131899Smarcel}
98131899Smarcel
99131899Smarcelstatic __inline void
100131899Smarcelgdb_tx_str(const char *s)
101131899Smarcel{
102131899Smarcel	while (*s)
103131899Smarcel		*gdb_txp++ = *s++;
104131899Smarcel}
105131899Smarcel
106131899Smarcelstatic __inline void
107131899Smarcelgdb_tx_varhex(uintmax_t n)
108131899Smarcel{
109131899Smarcel	gdb_txp += sprintf(gdb_txp, "%jx", n);
110131899Smarcel}
111131899Smarcel
112131899Smarcel#endif /* !_GDB_GDB_INT_H_ */
113