Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 1 | #include <stdbool.h> |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 2 | #include <stdint.h> |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 3 | #include <stdlib.h> |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 4 | #include <string.h> |
| 5 | |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 6 | static void mvcrl(const char *dst, const char *src, size_t len) |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 7 | { |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 8 | register long r0 asm("r0") = len; |
| 9 | |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 10 | asm volatile ( |
David Miller | 8b39829 | 2022-03-01 16:43:05 -0500 | [diff] [blame] | 11 | ".insn sse, 0xE50A00000000, 0(%[dst]), 0(%[src])" |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 12 | : : [dst] "d" (dst), [src] "d" (src), "r" (r0) |
| 13 | : "memory"); |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 14 | } |
| 15 | |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 16 | static bool test(void) |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 17 | { |
| 18 | const char *alpha = "abcdefghijklmnop"; |
| 19 | |
| 20 | /* array missing 'i' */ |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 21 | char tstr[17] = "abcdefghjklmnop\0"; |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 22 | |
| 23 | /* mvcrl reference use: 'open a hole in an array' */ |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 24 | mvcrl(tstr + 9, tstr + 8, 8); |
David Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 25 | |
| 26 | /* place missing 'i' */ |
| 27 | tstr[8] = 'i'; |
| 28 | |
Ilya Leoshkevich | bfde1be | 2023-07-04 10:12:36 +0200 | [diff] [blame] | 29 | return strncmp(alpha, tstr, 16ul) == 0; |
| 30 | } |
| 31 | |
| 32 | static 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 | |
| 47 | int 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 Miller | e2c3fb0 | 2022-02-23 17:31:16 -0500 | [diff] [blame] | 55 | } |