2
* Copyright (C) 2009, Mukesh Rathor, Oracle Corp. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public
6
* License v2 as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* General Public License for more details.
13
* You should have received a copy of the GNU General Public
14
* License along with this program; if not, write to the
15
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
* Boston, MA 021110-1307, USA.
27
gxprt(const char *fmt, ...)
33
(void)vsnprintf(buf, sizeof(buf), fmt, args);
35
fprintf(stderr, "%s", buf);
42
if (a >= '0' && a <= '9')
44
else if (a >= 'a' && a <= 'f')
47
gxprt("Reply contains invalid hex digit");
57
return 'a' + nib - 10;
62
gx_convert_int_to_ascii(char *from, char *to, int n)
68
nib = ((ch & 0xf0) >> 4) & 0x0f;
69
*to++ = gx_tohex(nib);
71
*to++ = gx_tohex(nib);
76
/* input: "70676433206431" output: "pgd3 d1" n == 7 */
78
gx_convert_ascii_to_int(char *from, char *to, int n)
82
nib1 = gx_fromhex(*from++);
83
nib2 = gx_fromhex(*from++);
84
*to++ = (((nib1 & 0x0f) << 4) & 0xf0) | (nib2 & 0x0f);
90
gx_decode_zZ_packet(char *from, uint64_t *mem_addr_ptr)
96
while ((ch=from[i++]) != ',') {
97
*mem_addr_ptr = *mem_addr_ptr << 4;
98
*mem_addr_ptr |= gx_fromhex(ch) & 0x0f;
102
/* Eg: mc0267d3a,1\0 : from points to char after 'm' */
104
gx_decode_m_packet(char *from, uint64_t *mem_addr_ptr, int *len_ptr)
108
*mem_addr_ptr = *len_ptr = 0;
110
while ((ch=from[i++]) != ',') {
111
*mem_addr_ptr = *mem_addr_ptr << 4;
112
*mem_addr_ptr |= gx_fromhex(ch) & 0x0f;
114
for (j = 0; j < 4; j++) {
115
if ((ch=from[i++]) == 0)
117
*len_ptr = *len_ptr << 4;
118
*len_ptr |= gx_fromhex(ch) & 0x0f;
123
* Decode M pkt as in: Mc0267d3a,1:cc\0 where c0267d3a is the guest addr
124
* from points to char after 'M'
125
* Returns: address of byte after ":", ie, addr of cc in buf
128
gx_decode_M_packet(char *from, uint64_t *mem_addr_ptr, int *len_ptr)
133
*mem_addr_ptr = *len_ptr = 0;
135
while ((ch=from[i++]) != ',') {
136
*mem_addr_ptr = *mem_addr_ptr << 4;
137
*mem_addr_ptr |= gx_fromhex(ch) & 0x0f;
139
while ((ch = from[i++]) != ':') {
140
*len_ptr = *len_ptr << 4;
141
*len_ptr |= gx_fromhex(ch) & 0x0f;