| /** |
| * Functions for generating pseudo-random CPER platform memory error sections. |
| * |
| * Author: Lawrence.Tang@arm.com |
| **/ |
| |
| #include <stdlib.h> |
| #include "../../edk/BaseTypes.h" |
| #include "../gen-utils.h" |
| #include "gen-sections.h" |
| |
| //Generates a single pseudo-random platform memory error section, saving the resulting address to the given |
| //location. Returns the size of the newly created section. |
| size_t generate_section_memory(void** location) |
| { |
| //Create random bytes. |
| int size = 80; |
| UINT8* bytes = generate_random_bytes(size); |
| |
| //Set reserved areas to zero. |
| UINT64* validation = (UINT64*)bytes; |
| *validation &= 0x2FFFFF; //Validation 22-63 |
| *(bytes + 73) &= ~0b11100; //Extended bits 2-4 |
| |
| //Fix values that could be above range. |
| *(bytes + 72) = rand() % 16; //Memory error type |
| |
| //Fix error status. |
| create_valid_error_section(bytes + 8); |
| |
| //Set return values, exit. |
| *location = bytes; |
| return size; |
| } |
| |
| //Generates a single pseudo-random memory 2 error section, saving the resulting address to the given |
| //location. Returns the size of the newly created section. |
| size_t generate_section_memory2(void** location) |
| { |
| //Create random bytes. |
| int size = 96; |
| UINT8* bytes = generate_random_bytes(size); |
| |
| //Set reserved areas to zero. |
| UINT64* validation = (UINT64*)bytes; |
| *validation &= 0x2FFFFF; //Validation 22-63 |
| *(bytes + 63) = 0; //Reserved byte 63 |
| |
| //Fix values that could be above range. |
| *(bytes + 61) = rand() % 16; //Memory error type |
| *(bytes + 62) = rand() % 2; //Status |
| |
| //Fix error status. |
| create_valid_error_section(bytes + 8); |
| |
| //Set return values, exit. |
| *location = bytes; |
| return size; |
| } |