From: Ilya Leoshkevich <iii@linux.ibm.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"David Hildenbrand" <david@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
"Thomas Weißschuh" <thomas@t-8ch.de>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Ilya Leoshkevich" <iii@linux.ibm.com>
Subject: [PATCH v2 2/3] tests/tcg/multiarch: Make the system memory test work on big-endian
Date: Mon, 24 Apr 2023 13:45:32 +0200 [thread overview]
Message-ID: <20230424114533.1937153-3-iii@linux.ibm.com> (raw)
In-Reply-To: <20230424114533.1937153-1-iii@linux.ibm.com>
Make sure values are stored in memory as little-endian regardless of
the host endianness.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/multiarch/system/memory.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c
index 214f7d4f54b..3a15f3f494a 100644
--- a/tests/tcg/multiarch/system/memory.c
+++ b/tests/tcg/multiarch/system/memory.c
@@ -12,9 +12,11 @@
* - sign extension when loading
*/
+#include "qemu/testdep.h"
#include <stdint.h>
#include <stdbool.h>
#include <minilib.h>
+#include "qemu/bswap.h"
#ifndef CHECK_UNALIGNED
# error "Target does not specify CHECK_UNALIGNED"
@@ -40,8 +42,7 @@ static void pdot(int count)
}
/*
- * Helper macros for shift/extract so we can keep our endian handling
- * in one place.
+ * Helper macros for shift/extract.
*/
#define BYTE_SHIFT(b, pos) ((uint64_t)b << (pos * 8))
#define BYTE_EXTRACT(b, pos) ((b >> (pos * 8)) & 0xff)
@@ -49,9 +50,8 @@ static void pdot(int count)
/*
* Fill the data with ascending value bytes.
*
- * Currently we only support Little Endian machines so write in
- * ascending address order. When we read higher address bytes should
- * either be zero or higher than the lower bytes.
+ * Store the words in the Little Endian byte order. When we read higher address
+ * bytes should either be zero or higher than the lower bytes.
*/
static void init_test_data_u8(int unused_offset)
@@ -121,7 +121,7 @@ static void init_test_data_u16(int offset)
for (i = 0; i < max; i++) {
uint8_t low = count++, high = count++;
word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
- *ptr++ = word;
+ *ptr++ = cpu_to_le16(word);
pdot(i);
}
ml_printf("done @ %p\n", ptr);
@@ -142,7 +142,7 @@ static void init_test_data_u32(int offset)
uint8_t b4 = count++, b3 = count++;
uint8_t b2 = count++, b1 = count++;
word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | b4;
- *ptr++ = word;
+ *ptr++ = cpu_to_le32(word);
pdot(i);
}
ml_printf("done @ %p\n", ptr);
@@ -167,7 +167,7 @@ static void init_test_data_u64(int offset)
word = BYTE_SHIFT(b1, 7) | BYTE_SHIFT(b2, 6) | BYTE_SHIFT(b3, 5) |
BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) |
BYTE_SHIFT(b7, 1) | b8;
- *ptr++ = word;
+ *ptr++ = cpu_to_le64(word);
pdot(i);
}
ml_printf("done @ %p\n", ptr);
@@ -183,7 +183,7 @@ static bool read_test_data_u16(int offset)
for (i = 0; i < max; i++) {
uint8_t high, low;
- word = *ptr++;
+ word = le16_to_cpu(*ptr++);
high = (word >> 8) & 0xff;
low = word & 0xff;
if (high < low && high != 0) {
@@ -209,7 +209,7 @@ static bool read_test_data_u32(int offset)
for (i = 0; i < max; i++) {
uint8_t b1, b2, b3, b4;
int zeros = 0;
- word = *ptr++;
+ word = le32_to_cpu(*ptr++);
b1 = word >> 24 & 0xff;
b2 = word >> 16 & 0xff;
@@ -250,7 +250,7 @@ static bool read_test_data_u64(int offset)
for (i = 0; i < max; i++) {
uint8_t b1, b2, b3, b4, b5, b6, b7, b8;
int zeros = 0;
- word = *ptr++;
+ word = le64_to_cpu(*ptr++);
b1 = ((uint64_t) (word >> 56)) & 0xff;
b2 = ((uint64_t) (word >> 48)) & 0xff;
@@ -375,7 +375,7 @@ static bool read_test_data_s16(int offset, bool neg_first)
offset, neg_first ? "neg" : "pos");
for (i = 0; i < max; i++) {
- int32_t data = *ptr++;
+ int32_t data = le16_to_cpu(*ptr++);
if (neg_first && data < 0) {
pdot(i);
@@ -400,7 +400,7 @@ static bool read_test_data_s32(int offset, bool neg_first)
ptr, offset, neg_first ? "neg" : "pos");
for (i = 0; i < max; i++) {
- int64_t data = *ptr++;
+ int64_t data = le32_to_cpu(*ptr++);
if (neg_first && data < 0) {
pdot(i);
--
2.39.2
next prev parent reply other threads:[~2023-04-24 11:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 11:45 [PATCH v2 0/3] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-24 11:45 ` [PATCH v2 1/3] tests/tcg: Make the QEMU headers available to the tests Ilya Leoshkevich
2023-04-24 13:00 ` Alex Bennée
2023-04-24 13:10 ` Ilya Leoshkevich
2023-04-25 7:19 ` Thomas Huth
2023-04-25 10:27 ` Ilya Leoshkevich
2023-04-24 11:45 ` Ilya Leoshkevich [this message]
2023-04-24 11:45 ` [PATCH v2 3/3] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
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=20230424114533.1937153-3-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=alex.bennee@linaro.org \
--cc=david@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thomas@t-8ch.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.