From: Boris Chiu <boris.chiu-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: Ira Weiny <iweiny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] libibmad: To fix big endian problem for both 32-bit & 64-bit SPARC
Date: Tue, 12 Mar 2013 12:36:29 -0700 [thread overview]
Message-ID: <513F83BD.3050302@oracle.com> (raw)
From: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
src/dump.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/src/dump.c b/src/dump.c
index 7f3ef7d..e83c363 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -46,12 +46,24 @@
void mad_dump_int(char *buf, int bufsz, void *val, int valsz)
{
+ /*
+ * the val pointer passed to the dump routines are always 32 bit
+ * integers for valsz <= 4 and 64 bit integer for the rest. It is never
+ * uint8_t or uint16_t. This is because mad_decode_field always returns
+ * the values as 32 bit integer even if they are 8 bit or 16 bit fields.
+ */
switch (valsz) {
case 1:
- snprintf(buf, bufsz, "%d", *(uint32_t *) val & 0xff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint8_t *)val) + 3;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%d", *(uint8_t *) val & 0xff);
break;
case 2:
- snprintf(buf, bufsz, "%d", *(uint32_t *) val & 0xffff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint16_t *)val) + 1;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%d", *(uint16_t *) val & 0xffff);
break;
case 3:
case 4:
@@ -71,12 +83,24 @@ void mad_dump_int(char *buf, int bufsz, void *val, int valsz)
void mad_dump_uint(char *buf, int bufsz, void *val, int valsz)
{
+ /*
+ * the val pointer passed to the dump routines are always 32 bit
+ * integers for valsz <= 4 and 64 bit integer for the rest. It is never
+ * uint8_t or uint16_t. This is because mad_decode_field always returns
+ * the values as 32 bit integer even if they are 8 bit or 16 bit fields.
+ */
switch (valsz) {
case 1:
- snprintf(buf, bufsz, "%u", *(uint32_t *) val & 0xff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint8_t *)val) + 3;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%u", *(uint8_t *) val & 0xff);
break;
case 2:
- snprintf(buf, bufsz, "%u", *(uint32_t *) val & 0xffff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint16_t *)val) + 1;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%u", *(uint16_t *) val & 0xffff);
break;
case 3:
case 4:
@@ -96,15 +120,27 @@ void mad_dump_uint(char *buf, int bufsz, void *val, int valsz)
void mad_dump_hex(char *buf, int bufsz, void *val, int valsz)
{
+ /*
+ * the val pointer passed to the dump routines are always 32 bit
+ * integers for valsz <= 4 and 64 bit integer for the rest. It is never
+ * uint8_t or uint16_t. This is because mad_decode_field always returns
+ * the values as 32 bit integer even if they are 8 bit or 16 bit fields.
+ */
switch (valsz) {
case 1:
- snprintf(buf, bufsz, "0x%02x", *(uint32_t *) val & 0xff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint8_t *)val) + 3;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "0x%02x", *(uint8_t *) val & 0xff);
break;
case 2:
- snprintf(buf, bufsz, "0x%04x", *(uint32_t *) val & 0xffff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint16_t *)val) + 1;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "0x%04x", *(uint16_t *) val & 0xffff);
break;
case 3:
- snprintf(buf, bufsz, "0x%06x", *(uint32_t *) val & 0xffffff);
+ snprintf(buf, bufsz, "0x%x", *(uint32_t *) val & 0xffffff);
break;
case 4:
snprintf(buf, bufsz, "0x%08x", *(uint32_t *) val);
@@ -132,12 +168,24 @@ void mad_dump_hex(char *buf, int bufsz, void *val, int valsz)
void mad_dump_rhex(char *buf, int bufsz, void *val, int valsz)
{
+ /*
+ * the val pointer passed to the dump routines are always 32 bit
+ * integers for valsz <= 4 and 64 bit integer for the rest. It is never
+ * uint8_t or uint16_t. This is because mad_decode_field always returns
+ * the values as 32 bit integer even if they are 8 bit or 16 bit fields.
+ */
switch (valsz) {
case 1:
- snprintf(buf, bufsz, "%02x", *(uint32_t *) val & 0xff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint8_t *)val) + 3;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%02x", *(uint8_t *) val & 0xff);
break;
case 2:
- snprintf(buf, bufsz, "%04x", *(uint32_t *) val & 0xffff);
+#if defined(_BIG_ENDIAN)
+ val = ((uint16_t *)val) + 1;
+#endif /* _BIG_ENDIAN */
+ snprintf(buf, bufsz, "%04x", *(uint16_t *) val & 0xffff);
break;
case 3:
snprintf(buf, bufsz, "%06x", *(uint32_t *) val & 0xffffff);
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2013-03-12 19:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 19:36 Boris Chiu [this message]
[not found] ` <513F83BD.3050302-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-03-13 12:48 ` [PATCH] libibmad: To fix big endian problem for both 32-bit & 64-bit SPARC Hal Rosenstock
[not found] ` <5140759D.1030500-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2013-03-13 12:58 ` Or Gerlitz
[not found] ` <514077DB.9000703-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2013-03-14 16:29 ` Boris Chiu
[not found] ` <5141FAFD.5070109-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-04-18 10:28 ` Pramod Gunjikar
[not found] ` <516FCAE6.3010403-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-04-18 17:52 ` Weiny, Ira
2013-03-13 16:28 ` Weiny, Ira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=513F83BD.3050302@oracle.com \
--to=boris.chiu-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
--cc=iweiny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox