1 /** 2 * Functions for generating pseudo-random CPER platform memory error sections. 3 * 4 * Author: Lawrence.Tang@arm.com 5 **/ 6 7 #include <stdlib.h> 8 #include <libcper/BaseTypes.h> 9 #include <libcper/generator/gen-utils.h> 10 #include <libcper/generator/sections/gen-section.h> 11 12 //Generates a single pseudo-random platform memory error section, saving the resulting address to the given 13 //location. Returns the size of the newly created section. generate_section_memory(void ** location,GEN_VALID_BITS_TEST_TYPE validBitsType)14size_t generate_section_memory(void **location, 15 GEN_VALID_BITS_TEST_TYPE validBitsType) 16 { 17 //Create random bytes. 18 int size = 80; 19 UINT8 *bytes = generate_random_bytes(size); 20 21 //Set reserved areas to zero. 22 UINT64 *validation = (UINT64 *)bytes; 23 //Validation 22-63 reserved. 19/20=0 for bank 24 *validation &= 0x27FFFF; 25 if (validBitsType == ALL_VALID) { 26 *validation = 0x27FFFF; 27 } else if (validBitsType == SOME_VALID) { 28 *validation = 0x275555; 29 } 30 *(bytes + 73) &= ~0x1C; //Extended bits 2-4 31 32 //Fix values that could be above range. 33 *(bytes + 72) = cper_rand() % 16; //Memory error type 34 35 //Fix error status. 36 create_valid_error_section(bytes + 8); 37 38 //Set return values, exit. 39 *location = bytes; 40 return size; 41 } 42 43 //Generates a single pseudo-random memory 2 error section, saving the resulting address to the given 44 //location. Returns the size of the newly created section. generate_section_memory2(void ** location,GEN_VALID_BITS_TEST_TYPE validBitsType)45size_t generate_section_memory2(void **location, 46 GEN_VALID_BITS_TEST_TYPE validBitsType) 47 { 48 //Create random bytes. 49 int size = 96; 50 UINT8 *bytes = generate_random_bytes(size); 51 52 //Set reserved areas to zero. 53 UINT64 *validation = (UINT64 *)bytes; 54 //Validation 22-63, 20/21 is 0 since 6 is valid 55 *validation &= 0xFFFFF; 56 if (validBitsType == ALL_VALID) { 57 *validation = 0xFFFFF; 58 } else if (validBitsType == SOME_VALID) { 59 *validation = 0x55555; 60 } 61 *(bytes + 63) = 0; //Reserved byte 63 62 63 //Fix values that could be above range. 64 *(bytes + 61) = cper_rand() % 16; //Memory error type 65 *(bytes + 62) = cper_rand() % 2; //Status 66 67 //Fix error status. 68 create_valid_error_section(bytes + 8); 69 70 //Set return values, exit. 71 *location = bytes; 72 return size; 73 } 74