blob: 6d3d049f2c44a8cd98121ca9d5ba795134fd9209 [file] [log] [blame]
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +02001#include <stdbool.h>
David Millere2c3fb02022-02-23 17:31:16 -05002#include <stdint.h>
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +02003#include <stdlib.h>
David Millere2c3fb02022-02-23 17:31:16 -05004#include <string.h>
5
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +02006static void mvcrl(const char *dst, const char *src, size_t len)
David Millere2c3fb02022-02-23 17:31:16 -05007{
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +02008 register long r0 asm("r0") = len;
9
David Millere2c3fb02022-02-23 17:31:16 -050010 asm volatile (
David Miller8b398292022-03-01 16:43:05 -050011 ".insn sse, 0xE50A00000000, 0(%[dst]), 0(%[src])"
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +020012 : : [dst] "d" (dst), [src] "d" (src), "r" (r0)
13 : "memory");
David Millere2c3fb02022-02-23 17:31:16 -050014}
15
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +020016static bool test(void)
David Millere2c3fb02022-02-23 17:31:16 -050017{
18 const char *alpha = "abcdefghijklmnop";
19
20 /* array missing 'i' */
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +020021 char tstr[17] = "abcdefghjklmnop\0";
David Millere2c3fb02022-02-23 17:31:16 -050022
23 /* mvcrl reference use: 'open a hole in an array' */
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +020024 mvcrl(tstr + 9, tstr + 8, 8);
David Millere2c3fb02022-02-23 17:31:16 -050025
26 /* place missing 'i' */
27 tstr[8] = 'i';
28
Ilya Leoshkevichbfde1be2023-07-04 10:12:36 +020029 return strncmp(alpha, tstr, 16ul) == 0;
30}
31
32static bool test_bad_r0(void)
33{
34 char src[256] = { 0 };
35
36 /*
37 * PoP says: Bits 32-55 of general register 0 should contain zeros;
38 * otherwise, the program may not operate compatibly in the future.
39 *
40 * Try it anyway in order to check whether this would crash QEMU itself.
41 */
42 mvcrl(src, src, (size_t)-1);
43
44 return true;
45}
46
47int main(void)
48{
49 bool ok = true;
50
51 ok &= test();
52 ok &= test_bad_r0();
53
54 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
David Millere2c3fb02022-02-23 17:31:16 -050055}