Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 1 | /** |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 2 | * Functions for generating pseudo-random CPER platform memory error sections. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame^] | 3 | * |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | #include "../../edk/BaseTypes.h" |
| 9 | #include "../gen-utils.h" |
Lawrence Tang | 8f97745 | 2022-08-24 14:55:07 +0100 | [diff] [blame] | 10 | #include "gen-section.h" |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 11 | |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 12 | //Generates a single pseudo-random platform memory error section, saving the resulting address to the given |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 13 | //location. Returns the size of the newly created section. |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 14 | size_t generate_section_memory(void **location) |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 15 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 16 | //Create random bytes. |
| 17 | int size = 80; |
| 18 | UINT8 *bytes = generate_random_bytes(size); |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 19 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 20 | //Set reserved areas to zero. |
| 21 | UINT64 *validation = (UINT64 *)bytes; |
| 22 | *validation &= 0x2FFFFF; //Validation 22-63 |
| 23 | *(bytes + 73) &= ~0x1C; //Extended bits 2-4 |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 24 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 25 | //Fix values that could be above range. |
| 26 | *(bytes + 72) = rand() % 16; //Memory error type |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 27 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 28 | //Fix error status. |
| 29 | create_valid_error_section(bytes + 8); |
| 30 | |
| 31 | //Set return values, exit. |
| 32 | *location = bytes; |
| 33 | return size; |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 36 | //Generates a single pseudo-random memory 2 error section, saving the resulting address to the given |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 37 | //location. Returns the size of the newly created section. |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 38 | size_t generate_section_memory2(void **location) |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 39 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 40 | //Create random bytes. |
| 41 | int size = 96; |
| 42 | UINT8 *bytes = generate_random_bytes(size); |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 43 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 44 | //Set reserved areas to zero. |
| 45 | UINT64 *validation = (UINT64 *)bytes; |
| 46 | *validation &= 0x2FFFFF; //Validation 22-63 |
| 47 | *(bytes + 63) = 0; //Reserved byte 63 |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 48 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 49 | //Fix values that could be above range. |
| 50 | *(bytes + 61) = rand() % 16; //Memory error type |
| 51 | *(bytes + 62) = rand() % 2; //Status |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 52 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 53 | //Fix error status. |
| 54 | create_valid_error_section(bytes + 8); |
| 55 | |
| 56 | //Set return values, exit. |
| 57 | *location = bytes; |
| 58 | return size; |
| 59 | } |