2023-07-04 11:12:36 +03:00
|
|
|
#include <stdbool.h>
|
2022-02-24 01:31:16 +03:00
|
|
|
#include <stdint.h>
|
2023-07-04 11:12:36 +03:00
|
|
|
#include <stdlib.h>
|
2022-02-24 01:31:16 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2023-07-04 11:12:36 +03:00
|
|
|
static void mvcrl(const char *dst, const char *src, size_t len)
|
2022-02-24 01:31:16 +03:00
|
|
|
{
|
2023-07-04 11:12:36 +03:00
|
|
|
register long r0 asm("r0") = len;
|
|
|
|
|
2022-02-24 01:31:16 +03:00
|
|
|
asm volatile (
|
2022-03-02 00:43:05 +03:00
|
|
|
".insn sse, 0xE50A00000000, 0(%[dst]), 0(%[src])"
|
2023-07-04 11:12:36 +03:00
|
|
|
: : [dst] "d" (dst), [src] "d" (src), "r" (r0)
|
|
|
|
: "memory");
|
2022-02-24 01:31:16 +03:00
|
|
|
}
|
|
|
|
|
2023-07-04 11:12:36 +03:00
|
|
|
static bool test(void)
|
2022-02-24 01:31:16 +03:00
|
|
|
{
|
|
|
|
const char *alpha = "abcdefghijklmnop";
|
|
|
|
|
|
|
|
/* array missing 'i' */
|
2023-07-04 11:12:36 +03:00
|
|
|
char tstr[17] = "abcdefghjklmnop\0";
|
2022-02-24 01:31:16 +03:00
|
|
|
|
|
|
|
/* mvcrl reference use: 'open a hole in an array' */
|
2023-07-04 11:12:36 +03:00
|
|
|
mvcrl(tstr + 9, tstr + 8, 8);
|
2022-02-24 01:31:16 +03:00
|
|
|
|
|
|
|
/* place missing 'i' */
|
|
|
|
tstr[8] = 'i';
|
|
|
|
|
2023-07-04 11:12:36 +03:00
|
|
|
return strncmp(alpha, tstr, 16ul) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool test_bad_r0(void)
|
|
|
|
{
|
|
|
|
char src[256] = { 0 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PoP says: Bits 32-55 of general register 0 should contain zeros;
|
|
|
|
* otherwise, the program may not operate compatibly in the future.
|
|
|
|
*
|
|
|
|
* Try it anyway in order to check whether this would crash QEMU itself.
|
|
|
|
*/
|
|
|
|
mvcrl(src, src, (size_t)-1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
ok &= test();
|
|
|
|
ok &= test_bad_r0();
|
|
|
|
|
|
|
|
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
|
2022-02-24 01:31:16 +03:00
|
|
|
}
|